public static bool TestYandexCloud(CloudDrive value, out string message) { bool result = false; string errMessage = string.Empty; try { System.Threading.Tasks.Task.Run(() => { try { Yawful.Authentication.DiskAuthentication auth = new Yawful.Authentication.DiskAuthentication { ClientId = value.Uid, ClientSecret = value.Password }; try { string tokenUrl = auth.BuildTokenRequestUrl(); Yawful.Authentication.AccessToken token = new Yawful.Authentication.AccessToken() { TokenString = value.Token }; //Yawful.Authentication.AccessToken token = auth.ExchangeCode(value.Token, CancellationToken.None).Result; Yawful.Client.DiskClient client = new Yawful.Client.DiskClient(token); client.GetDiskMeta(CancellationToken.None); } catch (Exception ex) { result = false; errMessage = ex.Message; } result = true; errMessage = string.Empty; } catch (Exception e) { result = false; errMessage = e.Message; } }).GetAwaiter().GetResult(); message = errMessage; return(result); } catch (Exception e) { message = e.Message; return(false); } }
public static bool UploadToYandexCloud(CloudDrive value, string file, out string message) { bool result = false; string uploadLink = string.Empty; string taskMessage = string.Empty; try { System.Threading.Tasks.Task.Run(() => { Yawful.Authentication.DiskAuthentication auth = new Yawful.Authentication.DiskAuthentication { ClientId = value.Uid, ClientSecret = value.Password }; string tokenUrl = auth.BuildTokenRequestUrl(); Yawful.Authentication.AccessToken token = new Yawful.Authentication.AccessToken() { TokenString = value.Token }; //Yawful.Authentication.AccessToken token = auth.ExchangeCode(value.Token, CancellationToken.None).Result; Yawful.Client.DiskClient client = new Yawful.Client.DiskClient(token); System.IO.FileInfo fInf = new FileInfo(file); using (var bFileData = System.IO.File.Open(file, FileMode.Open)) { client.UploadResource(bFileData, "/" + fInf.Name, true, null, CancellationToken.None).GetAwaiter().GetResult(); } result = true; taskMessage = string.Empty; }).GetAwaiter().GetResult(); message = string.Empty; return(result); } catch (Exception e) { message = e.Message; return(false); } }