public LoginWindow(IDiskSdkClient sdkClient) : this() { this.sdkClient = sdkClient; this.sdkClient.AuthorizeAsync(new WebBrowserWrapper(browser), CLIENT_ID, RETURN_URL, this.CompleteCallback); }
public LoginWindow(IDiskSdkClient sdkClient) : this() { this.sdkClient = sdkClient; //Добавляем токен this.sdkClient.AccessToken = "AgAAAAACuFN0AAW808LC4Pxn90nevCsZgQSS4Oo"; this.sdkClient.AuthorizeAsync(new WebBrowserWrapper(browser), CLIENT_ID, RETURN_URL, this.CompleteCallback); }
/// <summary> /// Initializes a new instance of the <see cref="MainPage"/> class. /// </summary> public MainPage() { this.InitializeComponent(); this.selectedItems = new Collection <DiskItemInfo>(); this.DataContext = this; this.sdk = new DiskSdkClient(AccessToken); this.AddCompletedHandlers(); }
/// <summary> /// Authorizes the asynchronous. /// </summary> /// <param name="sdkClient">The SDK client.</param> /// <param name="browser">The browser.</param> /// <param name="clientId">The client identifier.</param> /// <param name="returnUrl">The return URL.</param> /// <param name="completeCallback">The complete callback.</param> public static void AuthorizeAsync(this IDiskSdkClient sdkClient, IBrowser browser, string clientId, string returnUrl, EventHandler <GenericSdkEventArgs <string> > completeCallback) { retUrl = returnUrl; completeHandler = completeCallback; var authUrl = string.Format(WebdavResources.AuthBrowserUrlFormat, clientId); browser.Navigating += BrowserOnNavigating; browser.Navigate(authUrl); }
public Game() { InitializeComponent(); this.DataContext = this; this.sdk = (DiskSdkClient)Application.Current.Properties["client"]; this.songList = (List <DiskItemInfo>)Application.Current.Properties["songsList"]; if (Application.Current.Properties.Contains("userName")) { this.userName = Application.Current.Properties["userName"].ToString(); } }
/// <summary> /// Called when a page becomes the active page in a frame. /// </summary> /// <param name="e">An object that contains the event data.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { string path, token; if (this.NavigationContext.QueryString.TryGetValue("token", out token)) { AccessToken = token; this.sdk = new DiskSdkClient(token); this.AddCompletedHandlers(); } this.InitFolder(this.NavigationContext.QueryString.TryGetValue("path", out path) ? path : "/"); }
/// <summary> /// Downloads the file as an asynchronous operation. /// </summary> /// <param name="sdkClient">The SDK client.</param> /// <param name="path">The path to the file.</param> /// <param name="fileStream">The file stream.</param> /// <param name="progress">The progress.</param> /// <param name="completeCallback">The complete callback.</param> public static void DownloadFileAsync(this IDiskSdkClient sdkClient, string path, Stream fileStream, IProgress progress, EventHandler <SdkEventArgs> completeCallback) { var request = HttpUtilities.CreateRequest(sdkClient.AccessToken, path); request.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString(); request.Method = WebdavResources.GetMethod; try { request.BeginGetResponse( getResponseResult => { var getResponseRequest = (HttpWebRequest)getResponseResult.AsyncState; try { using (var response = getResponseRequest.EndGetResponse(getResponseResult)) { using (var responseStream = response.GetResponseStream()) { const int BUFFER_LENGTH = 4096; var total = (ulong)response.ContentLength; ulong current = 0; var buffer = new byte[BUFFER_LENGTH]; var count = responseStream.Read(buffer, 0, BUFFER_LENGTH); while (count > 0) { fileStream.Write(buffer, 0, count); current += (ulong)count; progress.UpdateProgress(current, total); count = responseStream.Read(buffer, 0, BUFFER_LENGTH); } fileStream.Dispose(); } } completeCallback.SafeInvoke(sdkClient, new SdkEventArgs(null)); } catch (Exception ex) { completeCallback.SafeInvoke(sdkClient, new SdkEventArgs(HttpUtilities.ProcessException(ex))); } }, request); } catch (Exception ex) { completeCallback.SafeInvoke(sdkClient, new SdkEventArgs(HttpUtilities.ProcessException(ex))); } }
/// <summary> /// Uploads the file as an asynchronous operation. /// </summary> /// <param name="sdkClient">The SDK client.</param> /// <param name="path">The path to the file.</param> /// <param name="fileStream">The file stream.</param> /// <param name="completeCallback">The complete callback.</param> public static void UploadFileAsync(this IDiskSdkClient sdkClient, string path, Stream fileStream, EventHandler <SdkEventArgs> completeCallback) { var request = HttpUtilities.CreateRequest(sdkClient.AccessToken, path); request.Method = WebdavResources.PutMethod; try { request.BeginGetRequestStream( getRequestStreamResult => { var getRequestStreamRequest = (HttpWebRequest)getRequestStreamResult.AsyncState; try { using (var requestStream = getRequestStreamRequest.EndGetRequestStream(getRequestStreamResult)) { fileStream.CopyTo(requestStream); fileStream.Dispose(); } getRequestStreamRequest.BeginGetResponse( getResponseResult => { var getResponseRequest = (HttpWebRequest)getResponseResult.AsyncState; try { using (getResponseRequest.EndGetResponse(getResponseResult)) { completeCallback.SafeInvoke(sdkClient, new SdkEventArgs(null)); } } catch (Exception ex) { completeCallback.SafeInvoke(sdkClient, new SdkEventArgs(HttpUtilities.ProcessException(ex))); } }, getRequestStreamRequest); } catch (Exception ex) { completeCallback.SafeInvoke(sdkClient, new SdkEventArgs(HttpUtilities.ProcessException(ex))); } }, request); } catch (Exception ex) { completeCallback.SafeInvoke(sdkClient, new SdkEventArgs(HttpUtilities.ProcessException(ex))); } }
/// <summary> /// Starts to upload the file as an asynchronous operation. /// </summary> /// <param name="sdkClient">The SDK client.</param> /// <param name="path">The path to the file.</param> /// <param name="file">The file.</param> /// <param name="progress">The progress.</param> public static async Task StartUploadFileAsync(this IDiskSdkClient sdkClient, string path, IStorageFile file, IProgress progress) { try { var uri = new Uri(WebdavResources.ApiUrl + path); var uploader = new BackgroundUploader { Method = "PUT" }; uploader.SetRequestHeader("Authorization", "OAuth " + sdkClient.AccessToken); uploader.SetRequestHeader("X-Yandex-SDK-Version", "winui, 1.0"); var upload = uploader.CreateUpload(uri, file); await HandleUploadAsync(upload, progress, true); } catch (Exception ex) { throw HttpUtilities.ProcessException(ex); } }
/// <summary> /// Starts the asynchronous authentication operation. /// </summary> /// <param name="sdkClient">The SDK client.</param> /// <param name="clientId">The client identifier.</param> /// <param name="returnUrl">The return URL.</param> /// <returns>The access token</returns> /// <exception cref="SdkException"/> public static async Task <string> AuthorizeAsync(this IDiskSdkClient sdkClient, string clientId, string returnUrl) { var requestUri = new Uri(string.Format(WebdavResources.AuthBrowserUrlFormat, clientId)); var returnUri = new Uri(returnUrl); WebAuthenticationResult authResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, requestUri, returnUri); if (authResult.ResponseStatus == WebAuthenticationStatus.Success) { return(Regex.Match(authResult.ResponseData, WebdavResources.TokenRegexPattern).Value); } if (authResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp) { throw new SdkException(authResult.ResponseErrorDetail.ToString()); } throw new SdkException(authResult.ResponseStatus.ToString()); }
/// <summary> /// Starts to download the file as an asynchronous operation. /// </summary> /// <param name="sdkClient">The SDK client.</param> /// <param name="path">The path to the file.</param> /// <param name="file">The file.</param> /// <param name="progress">The progress handler.</param> public static async Task StartDownloadFileAsync(this IDiskSdkClient sdkClient, string path, IStorageFile file, IProgress progress) { try { var uri = new Uri(WebdavResources.ApiUrl + path); var downloader = new BackgroundDownloader(); downloader.SetRequestHeader("Accept", "*/*"); downloader.SetRequestHeader("TE", "chunked"); downloader.SetRequestHeader("Accept-Encoding", "gzip"); downloader.SetRequestHeader("Authorization", "OAuth " + sdkClient.AccessToken); downloader.SetRequestHeader("X-Yandex-SDK-Version", "winui, 1.0"); var download = downloader.CreateDownload(uri, file); await HandleDownloadAsync(download, progress, true); } catch (Exception ex) { throw HttpUtilities.ProcessException(ex); } }
private async Task Login() { AccessToken = string.Empty; this.Items = null; this.CurrentPath = string.Empty; try { AccessToken = await this.sdk.AuthorizeAsync(CLIENT_ID, RETURN_URL); this.sdk = new DiskSdkClient(AccessToken); this.AddCompletedHandlers(); this.InitFolder("/"); } catch (SdkException ex) { this.ShowMessage(ex.Message, "SDK exception"); } this.OnPropertyChanged("IsLoggedIn"); this.OnPropertyChanged("IsLoggedOut"); }
/// <summary> /// Uploads the file as an asynchronous operation. /// </summary> /// <param name="sdkClient">The SDK client.</param> /// <param name="path">The path to the file.</param> /// <param name="fileStream">The file stream.</param> /// <param name="progress">The progress.</param> /// <param name="completeCallback">The complete callback.</param> public static void UploadFileAsync(this IDiskSdkClient sdkClient, string path, Stream fileStream, IProgress progress, EventHandler <SdkEventArgs> completeCallback) { var request = HttpUtilities.CreateRequest(sdkClient.AccessToken, path); request.Method = WebdavResources.PutMethod; request.AllowWriteStreamBuffering = false; request.SendChunked = true; try { request.BeginGetRequestStream( getRequestStreamResult => { var getRequestStreamRequest = (HttpWebRequest)getRequestStreamResult.AsyncState; try { using (var requestStream = getRequestStreamRequest.EndGetRequestStream(getRequestStreamResult)) { const int BUFFER_LENGTH = 4096; var total = (ulong)fileStream.Length; ulong current = 0; var buffer = new byte[BUFFER_LENGTH]; var count = fileStream.Read(buffer, 0, BUFFER_LENGTH); while (count > 0) { requestStream.Write(buffer, 0, count); current += (ulong)count; progress.UpdateProgress(current, total); count = fileStream.Read(buffer, 0, BUFFER_LENGTH); } fileStream.Dispose(); } getRequestStreamRequest.BeginGetResponse( getResponseResult => { var getResponseRequest = (HttpWebRequest)getResponseResult.AsyncState; try { using (getResponseRequest.EndGetResponse(getResponseResult)) { completeCallback.SafeInvoke(sdkClient, new SdkEventArgs(null)); } } catch (Exception ex) { completeCallback.SafeInvoke(sdkClient, new SdkEventArgs(HttpUtilities.ProcessException(ex))); } }, getRequestStreamRequest); } catch (Exception ex) { completeCallback.SafeInvoke(sdkClient, new SdkEventArgs(HttpUtilities.ProcessException(ex))); } }, request); } catch (Exception ex) { completeCallback.SafeInvoke(sdkClient, new SdkEventArgs(HttpUtilities.ProcessException(ex))); } }
private void CreateSdkClient() { this.sdk = new DiskSdkClient(acctok); this.AddCompletedHandlers(); }
private void CreateSdkClient() { this.sdk = new DiskSdkClient(); sdk.AccessToken = constAccessToken; this.AddCompletedHandlers(); }
private void CreateSdkClient() { this.sdk = new DiskSdkClient(AccessToken); this.AddCompletedHandlers(); }
public LoginPage() { InitializeComponent(); this.sdkClient = new DiskSdkClient(); }
public Settings() { InitializeComponent(); this.sdk = (DiskSdkClient)Application.Current.Properties["client"]; }