Skip to content

Commit ae22a6b

Browse files
committed
Added back settings after upgrading.
1 parent b330560 commit ae22a6b

File tree

5 files changed

+51
-127
lines changed

5 files changed

+51
-127
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
<userSettings>
1212
<SimpleTest.Settings>
1313
<setting name="AccessToken" serializeAs="String">
14-
<value/>
14+
<value />
1515
</setting>
1616
<setting name="Uid" serializeAs="String">
17-
<value/>
17+
<value />
18+
</setting>
19+
<setting name="ApiKey" serializeAs="String">
20+
<value />
1821
</setting>
1922
</SimpleTest.Settings>
2023
</userSettings>

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

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ namespace SimpleTest
1515

1616
partial class Program
1717
{
18-
// Add an ApiKey (from https://www.dropbox.com/developers/apps) here
19-
private const string ApiKey = "XXXXXXXXXXXXXXX";
20-
2118
// This loopback host is for demo purpose. If this port is not
2219
// available on your machine you need to update this URL with an unused port.
2320
private const string LoopbackHost = "http://127.0.0.1:52475/";
@@ -225,31 +222,49 @@ private async Task<OAuth2Response> HandleJSRedirect(HttpListener http)
225222
/// <returns>A valid access token or null.</returns>
226223
private async Task<string> GetAccessToken()
227224
{
225+
Settings.Default.Upgrade();
228226
Console.Write("Reset settings (Y/N) ");
229227
if (Console.ReadKey().Key == ConsoleKey.Y)
230228
{
231-
// Settings.Default.Reset();
229+
Settings.Default.Reset();
232230
}
233231
Console.WriteLine();
234232

235-
236-
var accessToken = "";
233+
string apiKey = Settings.Default.ApiKey;
234+
while (string.IsNullOrWhiteSpace(apiKey))
235+
{
236+
Console.WriteLine("Create a Dropbox App at https://www.dropbox.com/developers/apps.");
237+
Console.Write("Enter the API Key (or 'Quit' to exit): ");
238+
apiKey = Console.ReadLine();
239+
if(apiKey.ToLower()=="quit")
240+
{
241+
Console.WriteLine("The API Key is required to connect to Dropbox.");
242+
apiKey = "";
243+
break;
244+
}
245+
else
246+
{
247+
Settings.Default.ApiKey = apiKey;
248+
}
249+
}
237250

238-
if (string.IsNullOrEmpty(accessToken))
251+
var accessToken = Settings.Default.AccessToken;
252+
253+
if (string.IsNullOrEmpty(accessToken) && !string.IsNullOrWhiteSpace(apiKey))
239254
{
240255
try
241256
{
242257
Console.WriteLine("Waiting for credentials.");
243258
var state = Guid.NewGuid().ToString("N");
244-
var authorizeUri = DropboxOAuth2Helper.GetAuthorizeUri(OAuthResponseType.Token, ApiKey, RedirectUri, state: state);
259+
var authorizeUri = DropboxOAuth2Helper.GetAuthorizeUri(
260+
OAuthResponseType.Token, apiKey, RedirectUri, state: state);
245261
var http = new HttpListener();
246262
http.Prefixes.Add(LoopbackHost);
247263

248264
http.Start();
249265

250266
// Use StartInfo to ensure default browser launches.
251-
System.Diagnostics.ProcessStartInfo startInfo =
252-
new System.Diagnostics.ProcessStartInfo(authorizeUri.ToString());
267+
System.Diagnostics.ProcessStartInfo startInfo = new (authorizeUri.ToString());
253268
startInfo.UseShellExecute = true;
254269

255270
System.Diagnostics.Process.Start(startInfo);
@@ -275,18 +290,17 @@ private async Task<string> GetAccessToken()
275290
var uid = result.Uid;
276291
Console.WriteLine("Uid: {0}", uid);
277292

278-
//Settings.Default.AccessToken = accessToken;
279-
//Settings.Default.Uid = uid;
280-
281-
//Settings.Default.Save();
293+
Settings.Default.AccessToken = accessToken;
294+
Settings.Default.Uid = uid;
282295
}
283296
catch (Exception e)
284297
{
285298
Console.WriteLine("Error: {0}", e.Message);
286299
return null;
287300
}
288301
}
289-
302+
Settings.Default.Save();
303+
Settings.Default.Reload();
290304
return accessToken;
291305
}
292306

@@ -332,7 +346,7 @@ private async Task GetCurrentAccount(DropboxClient client)
332346
/// <param name="client">The dropbox client object.</param>
333347
/// <param name="path">The path to the target folder to delete.</param>
334348
/// <returns></returns>
335-
private async Task<bool> PathExists(DropboxClient client, string path)
349+
static private async Task<bool> PathExists(DropboxClient client, string path)
336350
{
337351
try
338352
{
@@ -351,7 +365,7 @@ private async Task<bool> PathExists(DropboxClient client, string path)
351365
/// <param name="client">The dropbox client object.</param>
352366
/// <param name="path">The path to the target folder to delete.</param>
353367
/// <returns></returns>
354-
private async Task<Metadata> DeleteFolder(DropboxClient client, string path)
368+
static private async Task<Metadata> DeleteFolder(DropboxClient client, string path)
355369
{
356370
if(await PathExists(client, path))
357371
{

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

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dropbox-sdk-dotnet/Examples/SimpleTest/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
<Setting Name="Uid" Type="System.String" Scope="User">
99
<Value Profile="(Default)" />
1010
</Setting>
11+
<Setting Name="ApiKey" Type="System.String" Scope="User">
12+
<Value Profile="(Default)" />
13+
</Setting>
1114
</Settings>
1215
</SettingsFile>

dropbox-sdk-dotnet/Examples/SimpleTest/SimpleTest.csproj.old

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

0 commit comments

Comments
 (0)