private static T Do <T>(string file, Window owner, Func <DiskSdkClient, string, T> action) { if (file.IsEmpty()) { throw new ArgumentNullException(nameof(file)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } if (!File.Exists(file)) { throw new FileNotFoundException(LocalizedStrings.Str1575, file); } Exception error = null; var result = default(T); var loginWindow = new YandexLoginWindow(); loginWindow.AuthCompleted += (s, e) => { if (e.Error == null) { var client = new DiskSdkClient(e.Result); var remotePath = RootPath + "/" + Path.GetFileName(file); try { result = action(client, remotePath); } catch (Exception excp) { error = excp; } } else { error = e.Error; } }; loginWindow.ShowModal(owner); if (error != null) { error.Throw(); } return(result); }
/// <summary> /// Поделиться файлом. /// </summary> /// <param name="file">Файл.</param> /// <returns>Ссылка на файл.</returns> public static string Publish(string file) { if (file == null) { throw new ArgumentNullException("file"); } if (!File.Exists(file)) { throw new FileNotFoundException(LocalizedStrings.Str1575, file); } Exception error = null; String result = null; var loginWindow = new YandexLoginWindow(); loginWindow.AuthCompleted += (s, e) => { if (e.Error == null) { var client = new DiskSdkClient(e.Result); var remoteDir = RootPath; var remotePath = remoteDir + "/" + Path.GetFileName(file); try { TryCreateDirectory(client, remoteDir); UploadFile(client, remotePath, file); result = Publish(client, remotePath); } catch (Exception excp) { error = excp; } } else { error = e.Error; } }; loginWindow.ShowDialog(); if (error != null) { throw error; } return(result); }
/// <summary> /// To share a file. /// </summary> /// <param name="file">File.</param> /// <returns>The link to a file.</returns> public static string Publish(string file) { if (file == null) throw new ArgumentNullException("file"); if (!File.Exists(file)) throw new FileNotFoundException(LocalizedStrings.Str1575, file); Exception error = null; String result = null; var loginWindow = new YandexLoginWindow(); loginWindow.AuthCompleted += (s, e) => { if (e.Error == null) { var client = new DiskSdkClient(e.Result); var remoteDir = RootPath; var remotePath = remoteDir + "/" + Path.GetFileName(file); try { TryCreateDirectory(client, remoteDir); UploadFile(client, remotePath, file); result = Publish(client, remotePath); } catch (Exception excp) { error = excp; } } else error = e.Error; }; loginWindow.ShowDialog(); if (error != null) throw error; return result; }