Skip to content

Commit b330560

Browse files
committed
Upgraded to .NET Core 5.0
1 parent 0246b7a commit b330560

File tree

6 files changed

+198
-150
lines changed

6 files changed

+198
-150
lines changed

dropbox-sdk-dotnet/Examples/SimpleTest/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</sectionGroup>
77
</configSections>
88
<startup>
9-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
9+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
1010
</startup>
1111
<userSettings>
1212
<SimpleTest.Settings>

dropbox-sdk-dotnet/Examples/SimpleTest/Program.cs

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int Main(string[] args)
5353
catch (Exception e)
5454
{
5555
Console.WriteLine(e);
56-
throw e;
56+
throw;
5757
}
5858
}
5959

@@ -69,7 +69,7 @@ private async Task<int> Run()
6969

7070
// Specify socket level timeout which decides maximum waiting time when no bytes are
7171
// received by the socket.
72-
var httpClient = new HttpClient(new WebRequestHandler { ReadWriteTimeout = 10 * 1000 })
72+
var httpClient = new HttpClient(new HttpClientHandler())
7373
{
7474
// Specify request level timeout which decides maximum time that can be spent on
7575
// download/upload files.
@@ -115,24 +115,30 @@ private async Task<int> Run()
115115
/// <returns>An asynchronous task.</returns>
116116
private async Task RunUserTests(DropboxClient client)
117117
{
118+
118119
await GetCurrentAccount(client);
119120

120121
var path = "/DotNetApi/Help";
121-
var folder = await CreateFolder(client, path);
122-
var list = await ListFolder(client, path);
122+
await DeleteFolder(client, path); // Removes items left older from the previous test run.
123123

124-
var firstFile = list.Entries.FirstOrDefault(i => i.IsFile);
125-
if (firstFile != null)
126-
{
127-
await Download(client, path, firstFile.AsFile);
128-
}
124+
var folder = await CreateFolder(client, path);
129125

130126
var pathInTeamSpace = "/Test";
131127
await ListFolderInTeamSpace(client, pathInTeamSpace);
132128

133129
await Upload(client, path, "Test.txt", "This is a text file");
134130

135131
await ChunkUpload(client, path, "Binary");
132+
133+
ListFolderResult list = await ListFolder(client, path);
134+
135+
Metadata firstFile = list.Entries.FirstOrDefault(i => i.IsFile);
136+
if (firstFile != null)
137+
{
138+
await Download(client, path, firstFile.AsFile);
139+
}
140+
141+
await DeleteFolder(client, path);
136142
}
137143

138144
/// <summary>
@@ -222,11 +228,12 @@ private async Task<string> GetAccessToken()
222228
Console.Write("Reset settings (Y/N) ");
223229
if (Console.ReadKey().Key == ConsoleKey.Y)
224230
{
225-
Settings.Default.Reset();
231+
// Settings.Default.Reset();
226232
}
227233
Console.WriteLine();
228234

229-
var accessToken = Settings.Default.AccessToken;
235+
236+
var accessToken = "";
230237

231238
if (string.IsNullOrEmpty(accessToken))
232239
{
@@ -240,7 +247,12 @@ private async Task<string> GetAccessToken()
240247

241248
http.Start();
242249

243-
System.Diagnostics.Process.Start(authorizeUri.ToString());
250+
// Use StartInfo to ensure default browser launches.
251+
System.Diagnostics.ProcessStartInfo startInfo =
252+
new System.Diagnostics.ProcessStartInfo(authorizeUri.ToString());
253+
startInfo.UseShellExecute = true;
254+
255+
System.Diagnostics.Process.Start(startInfo);
244256

245257
// Handle OAuth redirect and send URL fragment to local server using JS.
246258
await HandleOAuth2Redirect(http);
@@ -263,10 +275,10 @@ private async Task<string> GetAccessToken()
263275
var uid = result.Uid;
264276
Console.WriteLine("Uid: {0}", uid);
265277

266-
Settings.Default.AccessToken = accessToken;
267-
Settings.Default.Uid = uid;
278+
//Settings.Default.AccessToken = accessToken;
279+
//Settings.Default.Uid = uid;
268280

269-
Settings.Default.Save();
281+
//Settings.Default.Save();
270282
}
271283
catch (Exception e)
272284
{
@@ -314,6 +326,43 @@ private async Task GetCurrentAccount(DropboxClient client)
314326
}
315327
}
316328

329+
/// <summary>
330+
/// Delete the specified folder including any files within the folder
331+
/// </summary>
332+
/// <param name="client">The dropbox client object.</param>
333+
/// <param name="path">The path to the target folder to delete.</param>
334+
/// <returns></returns>
335+
private async Task<bool> PathExists(DropboxClient client, string path)
336+
{
337+
try
338+
{
339+
await client.Files.GetMetadataAsync(path);
340+
return true;
341+
}
342+
catch (DropboxException exception) when (exception.Message.StartsWith("path/not_found/"))
343+
{
344+
return false;
345+
}
346+
}
347+
348+
/// <summary>
349+
/// Delete the specified folder including any files within the folder
350+
/// </summary>
351+
/// <param name="client">The dropbox client object.</param>
352+
/// <param name="path">The path to the target folder to delete.</param>
353+
/// <returns></returns>
354+
private async Task<Metadata> DeleteFolder(DropboxClient client, string path)
355+
{
356+
if(await PathExists(client, path))
357+
{
358+
Console.WriteLine("--- Deleting Folder ---");
359+
Metadata metadata = await client.Files.DeleteAsync(path);
360+
Console.WriteLine($"Deleted {metadata.PathLower}");
361+
return metadata;
362+
}
363+
return null;
364+
}
365+
317366
/// <summary>
318367
/// Creates the specified folder.
319368
/// </summary>

dropbox-sdk-dotnet/Examples/SimpleTest/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

dropbox-sdk-dotnet/Examples/SimpleTest/Settings.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,35 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
43
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{33A16535-A722-4679-BD9F-A78576988519}</ProjectGuid>
84
<OutputType>Exe</OutputType>
9-
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>SimpleTest</RootNamespace>
11-
<AssemblyName>SimpleTest</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13-
<FileAlignment>512</FileAlignment>
14-
<NuGetPackageImportStamp>8bfaafb2</NuGetPackageImportStamp>
15-
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
16-
<TargetFrameworkProfile />
17-
</PropertyGroup>
18-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19-
<PlatformTarget>AnyCPU</PlatformTarget>
20-
<DebugSymbols>true</DebugSymbols>
21-
<DebugType>full</DebugType>
22-
<Optimize>false</Optimize>
23-
<OutputPath>bin\Debug\</OutputPath>
24-
<DefineConstants>DEBUG;TRACE</DefineConstants>
25-
<ErrorReport>prompt</ErrorReport>
26-
<WarningLevel>4</WarningLevel>
27-
</PropertyGroup>
28-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29-
<PlatformTarget>AnyCPU</PlatformTarget>
30-
<DebugType>pdbonly</DebugType>
31-
<Optimize>true</Optimize>
32-
<OutputPath>bin\Release\</OutputPath>
33-
<DefineConstants>TRACE</DefineConstants>
34-
<ErrorReport>prompt</ErrorReport>
35-
<WarningLevel>4</WarningLevel>
5+
<TargetFramework>net5.0</TargetFramework>
366
</PropertyGroup>
7+
378
<ItemGroup>
38-
<Compile Include="Program.cs" />
39-
<Compile Include="Properties\AssemblyInfo.cs" />
40-
<Compile Include="Settings.Designer.cs">
41-
<AutoGen>True</AutoGen>
9+
<PackageReference Include="System.configuration.Configurationmanager" Version="5.0.0" />
10+
<PackageReference Include="System.Net.Http" Version="4.3.4" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\Dropbox.Api\Dropbox.Api.csproj" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<Compile Update="Settings.Designer.cs">
4219
<DesignTimeSharedInput>True</DesignTimeSharedInput>
20+
<AutoGen>True</AutoGen>
4321
<DependentUpon>Settings.settings</DependentUpon>
4422
</Compile>
4523
</ItemGroup>
24+
4625
<ItemGroup>
47-
<None Include="App.config" />
48-
<None Include="packages.config" />
49-
<None Include="Settings.settings">
26+
<None Update="index.html">
27+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
28+
</None>
29+
<None Update="Settings.settings">
5030
<Generator>SettingsSingleFileGenerator</Generator>
5131
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
5232
</None>
5333
</ItemGroup>
54-
<ItemGroup>
55-
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
56-
<SpecificVersion>False</SpecificVersion>
57-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
58-
</Reference>
59-
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
60-
<SpecificVersion>False</SpecificVersion>
61-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
62-
</Reference>
63-
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
64-
<SpecificVersion>False</SpecificVersion>
65-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
66-
</Reference>
67-
<Reference Include="PresentationCore" />
68-
<Reference Include="PresentationFramework" />
69-
<Reference Include="System" />
70-
<Reference Include="System.Net" />
71-
<Reference Include="System.Net.Http" />
72-
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
73-
<SpecificVersion>False</SpecificVersion>
74-
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
75-
</Reference>
76-
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
77-
<SpecificVersion>False</SpecificVersion>
78-
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
79-
</Reference>
80-
<Reference Include="System.Net.Http.WebRequest" />
81-
<Reference Include="System.Xaml" />
82-
<Reference Include="WindowsBase" />
83-
</ItemGroup>
84-
<ItemGroup>
85-
<ProjectReference Include="..\..\Dropbox.Api\Dropbox.Api.csproj">
86-
<Project>{68180b54-4724-4cd1-baa6-ee7bc309797c}</Project>
87-
<Name>Dropbox.Api</Name>
88-
</ProjectReference>
89-
</ItemGroup>
90-
<ItemGroup>
91-
<Content Include="index.html">
92-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
93-
</Content>
94-
</ItemGroup>
95-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
96-
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
97-
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
98-
<Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
99-
<Error Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
100-
</Target>
101-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
102-
Other similar extension points exist, see Microsoft.Common.targets.
103-
<Target Name="BeforeBuild">
104-
</Target>
105-
<Target Name="AfterBuild">
106-
</Target>
107-
-->
108-
</Project>
34+
35+
</Project>

0 commit comments

Comments
 (0)