public WebFontClient(string address, string apikey, OssConfig ossConfig) { if (!string.IsNullOrEmpty(address)) { _address = address; } if (!string.IsNullOrEmpty(apikey)) { _apiKey = apikey; } this._ossConfig = ossConfig; //客户端跨语言调用非tls gRPC这样设置,请求http,非https AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); _channel = GrpcChannel.ForAddress(_address); _client = new GreeterClient(_channel); //日志可去除 var loggerFactory = LoggerFactory.Create(builder => { builder.AddFilter("Microsoft", LogLevel.Warning) .AddFilter("System", LogLevel.Warning) .AddFilter("LoggingConsoleApp.Program", LogLevel.Debug); }); //ILogger logger = loggerFactory.CreateLogger<WebFontClient>(); _logger = loggerFactory.CreateLogger <WebFontClient>(); }
public bool AddStorageProvider(Guid nodeId, string nodeName, OssConfig ossConfig, StorageProviderVisibility visibility) { if (string.IsNullOrWhiteSpace(nodeName)) { throw new ArgumentException("The node name is empty", nameof(nodeName)); } if (ossConfig == null) { throw new ArgumentNullException(nameof(ossConfig)); } lock (StorageProviderInstances) { if (StorageProviderInstances.Any(x => nodeId.Equals(x.RuntimeId) || string.Equals(x.ProviderInfo.Name, nodeName, StringComparison.InvariantCultureIgnoreCase))) { return(false); } var instance = new StorageProviderInstance_AliyunOSS(new StorageProviderInfo { Id = nodeId, Type = StorageProviderInstance.TypeAliYun, Name = nodeName, Visibility = visibility, Settings = JsonConvert.SerializeObject(ossConfig) }); StorageProviderInstances.Add(instance); ResyncClientListToStorageProviderInstances(); return(true); } }
private void UploadOSSUI_Load(object sender, EventArgs e) { logHelper = new Log4netLog(); ossConfig = new OssConfig(); setEnaled(false); GetMemory(); }
public StorageProviderInstance_AliyunOSS(StorageProviderInfo providerInfo) : base(providerInfo) { OssConfig = JsonConvert.DeserializeObject <OssConfig>(ProviderInfo.Settings); if (OssConfig == null || !OssConfig.IsValid()) { throw new Exception("Invalid config for Aliyun OSS"); } }
public static AlibabaOSS ToModel(this OssConfig config, string name) { return(new AlibabaOSS { Name = name, Endpoint = config.OssEndpoint, Bucket = config.BucketName, AccessID = config.AccessKeyId, AccessSecret = config.AccessKeySecret }); }
public ResourceServices(OssConfig ossConfig, IResourceReponsitory resourceReponsitory, ICommentRepository commentRepository, IBookRepository bookRepository, IPraizeRepository praizeRepository) : base(resourceReponsitory) { _ResourceReponsitory = resourceReponsitory; _commentRepository = commentRepository; _praizeRepository = praizeRepository; _bookRepository = bookRepository; _OssConfig = ossConfig; }
public static AlibabaOSS ToModel(this OssConfig config, string serviceName) { if (string.IsNullOrEmpty(serviceName)) { serviceName = UIKitExtensions.Localize("AliYun.Title"); } return(new AlibabaOSS { Name = serviceName, Endpoint = config.OssEndpoint, Bucket = config.BucketName, AccessID = config.AccessKeyId, AccessSecret = config.AccessKeySecret }); }
public IEnumerable <PersonalCloudInfo> LoadCloud() { var deviceName = Globals.Database.LoadSetting(UserSettings.DeviceName) ?? Environment.MachineName; return(Globals.Database.Table <CloudModel>().Select(x => { var alibaba = Globals.Database.Table <AlibabaOSS>().Where(y => y.Cloud == x.Id).Select(y => { var config = new OssConfig { OssEndpoint = y.Endpoint, BucketName = y.Bucket, }; using var cipher = new PasswordCipher(y.Id.ToString("N", CultureInfo.InvariantCulture), x.Key); config.AccessKeyId = cipher.DecryptContinuousText(y.AccessID); config.AccessKeySecret = cipher.DecryptContinuousText(y.AccessSecret); return new StorageProviderInfo { Id = y.Id, Type = StorageProviderInstance.TypeAliYun, Name = y.Name, Visibility = (StorageProviderVisibility)y.Visibility, Settings = JsonConvert.SerializeObject(config) }; }); var azure = Globals.Database.Table <AzureBlob>().Where(y => y.Cloud == x.Id).Select(y => { var config = new AzureBlobConfig { BlobName = y.Container }; using var cipher = new PasswordCipher(y.Id.ToString("N", CultureInfo.InvariantCulture), x.Key); config.ConnectionString = cipher.DecryptTextOnce(y.Parameters); return new StorageProviderInfo { Id = y.Id, Type = StorageProviderInstance.TypeAzure, Name = y.Name, Visibility = (StorageProviderVisibility)y.Visibility, Settings = JsonConvert.SerializeObject(config) }; }); var providers = new List <StorageProviderInfo>(); providers.AddRange(alibaba); providers.AddRange(azure); return new PersonalCloudInfo(providers) { Id = x.Id.ToString("N", CultureInfo.InvariantCulture), DisplayName = x.Name, NodeDisplayName = deviceName, MasterKey = Convert.FromBase64String(x.Key), TimeStamp = x.Version, Apps = new List <AppLauncher>(), }; })); }
public bool AddStorageProvider(string cloudId, Guid nodeId, string nodeName, OssConfig ossConfig, StorageProviderVisibility visibility, bool saveChanges = true) { PersonalCloud personalCloud = null; lock (_PersonalClouds) { personalCloud = _PersonalClouds.FirstOrDefault(x => x.Id == cloudId); } if (personalCloud != null) { bool haveChanges = personalCloud.AddStorageProvider(nodeId, nodeName, ossConfig, visibility); if (haveChanges && saveChanges) { SavePCList(); } return(haveChanges); } else { throw new NoSuchCloudException(); } }
private void VerifyCredentials(object sender, EventArgs e) { var name = ServiceName.Text; var invalidCharHit = false; foreach (var character in VirtualFileSystem.InvalidCharacters) { if (name?.Contains(character) == true) { invalidCharHit = true; } } if (string.IsNullOrEmpty(name) || invalidCharHit) { this.ShowAlert(this.Localize("Online.BadName"), this.Localize("Online.IllegalName"), action => { ServiceName.BecomeFirstResponder(); }); return; } var endpoint = Endpoint.Text; if (string.IsNullOrEmpty(endpoint)) { this.ShowAlert(this.Localize("Online.BadCredential"), this.Localize("AliYun.BadEndpoint"), action => { Endpoint.BecomeFirstResponder(); }); return; } var bucket = BucketName.Text; if (string.IsNullOrEmpty(bucket)) { this.ShowAlert(this.Localize("Online.BadCredential"), this.Localize("AliYun.BadBucket"), action => { BucketName.BecomeFirstResponder(); }); return; } var accessId = AccessKeyID.Text; if (string.IsNullOrEmpty(accessId)) { this.ShowAlert(this.Localize("Online.BadCredential"), this.Localize("AliYun.BadUserID"), action => { AccessKeyID.BecomeFirstResponder(); }); return; } var accessSecret = AccessKeySecret.Text; if (string.IsNullOrEmpty(accessSecret)) { this.ShowAlert(this.Localize("Online.BadCredential"), this.Localize("AliYun.BadUserSecret"), action => { AccessKeySecret.BecomeFirstResponder(); }); return; } if (!Globals.Database.IsStorageNameUnique(name)) { this.ShowAlert(this.Localize("Online.ServiceAlreadyExists"), this.Localize("Online.ChooseADifferentName"), action => { ServiceName.BecomeFirstResponder(); }); return; } var alert = UIAlertController.Create(this.Localize("Online.Verifying"), null, UIAlertControllerStyle.Alert); PresentViewController(alert, true, () => { Task.Run(() => { var config = new OssConfig { OssEndpoint = endpoint, BucketName = bucket, AccessKeyId = accessId, AccessKeySecret = accessSecret }; if (config.Verify()) { try { Globals.CloudManager.AddStorageProvider(Globals.CloudManager.PersonalClouds[0].Id, Guid.NewGuid(), name, config, visibility); InvokeOnMainThread(() => { DismissViewController(true, () => { NavigationController.DismissViewController(true, null); }); }); } catch { InvokeOnMainThread(() => { DismissViewController(true, () => { this.ShowAlert(this.Localize("AliYun.CannotAddService"), this.Localize("Error.Internal")); }); }); } } else { InvokeOnMainThread(() => { DismissViewController(true, () => { this.ShowAlert(this.Localize("Error.Authentication"), this.Localize("AliYun.Unauthorized")); }); }); } }); }); }
public OssService(OssConfig config) { client = new OssClient(config.EndPoint, config.AccessKeyId, config.AccessKeySecret); this.config = config; }
private void UploadOSSUI_Load(object sender, EventArgs e) { ossConfig = new OssConfig(); }
private void VerifyAlibabaCredentials() { ToggleBusyIndicator(true); var name = ConnectionNameBox.Text; var invalidCharHit = false; foreach (var character in PathConsts.InvalidCharacters) { if (name?.Contains(character) == true) { invalidCharHit = true; } } if (string.IsNullOrEmpty(name) || invalidCharHit) { Dispatcher.ShowAlert(UIStorage.ConnectionBadName, null); ToggleBusyIndicator(false); return; } var endpoint = EndpointBox.Text; if (string.IsNullOrEmpty(endpoint)) { Dispatcher.ShowAlert(UIStorage.ErrorAuthenticating, UIStorage.ErrorAuthenticatingAliYun); ToggleBusyIndicator(false); return; } var bucket = ContainerBox.Text; if (string.IsNullOrEmpty(bucket)) { Dispatcher.ShowAlert(UIStorage.ErrorAuthenticating, UIStorage.ErrorAuthenticatingAliYun); ToggleBusyIndicator(false); return; } var accessId = AccessIDBox.Text; if (string.IsNullOrEmpty(accessId)) { Dispatcher.ShowAlert(UIStorage.ErrorAuthenticating, UIStorage.ErrorAuthenticatingAliYun); ToggleBusyIndicator(false); return; } var accessSecret = AccessSecretBox.Text; if (string.IsNullOrEmpty(accessSecret)) { Dispatcher.ShowAlert(UIStorage.ErrorAuthenticating, UIStorage.ErrorAuthenticatingAliYun); ToggleBusyIndicator(false); return; } var config = new OssConfig { OssEndpoint = endpoint, BucketName = bucket, AccessKeyId = accessId, AccessKeySecret = accessSecret }; var shareScope = ShareCredentialsBox.IsChecked == true ? StorageProviderVisibility.Public : StorageProviderVisibility.Private; Task.Run(async() => { if (config.Verify()) { try { await Globals.CloudManager.InvokeAsync(x => x.ConnectToAlibabaCloud(Globals.PersonalCloud.Value, name, config, shareScope)).ConfigureAwait(false); } finally { await Task.Delay(3000).ConfigureAwait(false); Dispatcher.Invoke(() => { ToggleBusyIndicator(false); DismissDialog?.Invoke(this, EventArgs.Empty); }); } } else { Dispatcher.Invoke(() => { Dispatcher.ShowAlert(UIStorage.ErrorAuthenticating, UIStorage.ErrorAuthenticatingAliYun); ToggleBusyIndicator(false); }); } }); }
public OssConfigController(OssConfig ossConfig) { _ossConfig = ossConfig; }
private void VerifyCredentials(object sender, EventArgs e) { var name = ServiceName.Text; var invalidCharHit = false; foreach (var character in PathConsts.InvalidCharacters) { #pragma warning disable CA1307 // Specify StringComparison if (name?.Contains(character) == true) { invalidCharHit = true; } #pragma warning restore CA1307 // Specify StringComparison } if (string.IsNullOrEmpty(name) || invalidCharHit) { this.ShowWarning(this.Localize("Online.BadName"), this.Localize("Online.IllegalName"), () => { ServiceName.BecomeFirstResponder(); }); return; } var endpoint = Endpoint.Text; if (string.IsNullOrEmpty(endpoint)) { this.ShowWarning(this.Localize("Online.BadCredential"), this.Localize("AliYun.BadEndpoint"), () => { Endpoint.BecomeFirstResponder(); }); return; } var bucket = BucketName.Text; if (string.IsNullOrEmpty(bucket)) { this.ShowWarning(this.Localize("Online.BadCredential"), this.Localize("AliYun.BadBucket"), () => { BucketName.BecomeFirstResponder(); }); return; } var accessId = AccessKeyID.Text; if (string.IsNullOrEmpty(accessId)) { this.ShowWarning(this.Localize("Online.BadCredential"), this.Localize("AliYun.BadUserID"), () => { AccessKeyID.BecomeFirstResponder(); }); return; } var accessSecret = AccessKeySecret.Text; if (string.IsNullOrEmpty(accessSecret)) { this.ShowWarning(this.Localize("Online.BadCredential"), this.Localize("AliYun.BadUserSecret"), () => { AccessKeySecret.BecomeFirstResponder(); }); return; } if (!Globals.Database.IsStorageNameUnique(name)) { this.ShowWarning(this.Localize("Online.ServiceAlreadyExists"), this.Localize("Online.ChooseADifferentName"), () => { ServiceName.BecomeFirstResponder(); }); return; } var hud = MBProgressHUD.ShowHUD(NavigationController.View, true); hud.Label.Text = this.Localize("Online.Verifying"); Task.Run(() => { var config = new OssConfig { OssEndpoint = endpoint, BucketName = bucket, AccessKeyId = accessId, AccessKeySecret = accessSecret }; if (config.Verify()) { try { Globals.CloudManager.AddStorageProvider(Globals.CloudManager.PersonalClouds[0].Id, Guid.NewGuid(), name, config, visibility); InvokeOnMainThread(() => { hud.Hide(true); NavigationController.DismissViewController(true, null); }); } catch { InvokeOnMainThread(() => { hud.Hide(true); this.ShowError(this.Localize("AliYun.CannotAddService"), this.Localize("Error.Internal")); }); } } else { InvokeOnMainThread(() => { hud.Hide(true); this.ShowError(this.Localize("Error.Authentication"), this.Localize("AliYun.Unauthorized")); }); } }); }
public OssService(ILogger <OssService> logger, IOptions <OssConfig> config) { this.logger = logger; this.config = config.Value; }
public void ConnectToAlibabaCloud(Guid cloudId, string name, OssConfig config, StorageProviderVisibility visibility) { Globals.CloudService.AddStorageProvider(cloudId.ToString("N"), Guid.NewGuid(), name, config, visibility); }
private void SaveCredentials(object sender, EventArgs e) { var name = R.connection_name.EditText.Text; var invalidCharHit = false; foreach (var character in Consts.InvalidCharacters) { if (name?.Contains(character) == true) { invalidCharHit = true; } } if (string.IsNullOrEmpty(name) || invalidCharHit) { this.ShowAlert(GetString(Resource.String.connection_bad_name), GetString(Resource.String.connection_name_cannot_be_empty), () => { R.connection_name.EditText.RequestFocus(); }); return; } var selection = R.connection_to_spinner.SelectedItemPosition; OssConfig alibaba = null; AzureBlobConfig azure = null; switch (selection) { case 0: // Alibaba Cloud OSS { var endpoint = R.connection_endpoint.EditText.Text; if (string.IsNullOrEmpty(endpoint)) { this.ShowAlert(GetString(Resource.String.connection_invalid_account), GetString(Resource.String.aliyun_bad_endpoint), () => { R.connection_endpoint.EditText.RequestFocus(); }); return; } var bucket = R.connection_container.EditText.Text; if (string.IsNullOrEmpty(bucket)) { this.ShowAlert(GetString(Resource.String.connection_invalid_account), GetString(Resource.String.aliyun_bad_bucket), () => { R.connection_container.EditText.RequestFocus(); }); return; } var accessId = R.connection_account.EditText.Text; if (string.IsNullOrEmpty(accessId)) { this.ShowAlert(GetString(Resource.String.connection_invalid_account), GetString(Resource.String.aliyun_bad_user_id), () => { R.connection_account.EditText.RequestFocus(); }); return; } var accessSecret = R.connection_secret.EditText.Text; if (string.IsNullOrEmpty(accessSecret)) { this.ShowAlert(GetString(Resource.String.connection_invalid_account), GetString(Resource.String.aliyun_bad_secret), () => { R.connection_secret.EditText.RequestFocus(); }); return; } alibaba = new OssConfig { OssEndpoint = endpoint, BucketName = bucket, AccessKeyId = accessId, AccessKeySecret = accessSecret }; break; } case 1: // Azure Blob Storage { var endpoint = R.connection_endpoint.EditText.Text; if (string.IsNullOrEmpty(endpoint)) { this.ShowAlert(GetString(Resource.String.connection_invalid_account), GetString(Resource.String.connection_bad_azure_endpoint), () => { R.connection_endpoint.EditText.RequestFocus(); }); return; } var accountName = R.connection_account.EditText.Text; var accessKey = R.connection_secret.EditText.Text; if (string.IsNullOrEmpty(accessKey)) { this.ShowAlert(GetString(Resource.String.connection_invalid_account), GetString(Resource.String.connection_bad_azure_secret), () => { R.connection_secret.EditText.RequestFocus(); }); return; } var container = R.connection_container.EditText.Text; if (string.IsNullOrEmpty(container)) { this.ShowAlert(GetString(Resource.String.connection_invalid_account), GetString(Resource.String.connection_bad_azure_container), () => { R.connection_container.RequestFocus(); }); return; } string connection; if (endpoint.Contains(accountName, StringComparison.Ordinal)) { accountName = null; } if (endpoint.StartsWith("http://", StringComparison.Ordinal)) { endpoint.Replace("http://", "https://"); } if (endpoint.StartsWith("https://", StringComparison.Ordinal)) { if (string.IsNullOrEmpty(accountName)) { if (string.IsNullOrEmpty(accessKey)) { connection = endpoint; } else { connection = $"BlobEndpoint={endpoint};SharedAccessSignature={accessKey}"; } } else { this.ShowAlert(GetString(Resource.String.connection_invalid_account), GetString(Resource.String.connection_mismatch_azure_endpoint)); return; } } else { if (string.IsNullOrEmpty(accountName)) { this.ShowAlert(GetString(Resource.String.connection_invalid_account), GetString(Resource.String.connection_bad_azure_id)); return; } else { connection = $"DefaultEndpointsProtocol=https;AccountName={accountName};AccountKey={accessKey};EndpointSuffix={endpoint}"; } } azure = new AzureBlobConfig { ConnectionString = connection, BlobName = container }; break; } } if (!Globals.Database.IsStorageNameUnique(name)) { this.ShowAlert(GetString(Resource.String.connection_name_exists), GetString(Resource.String.connection_use_different_name), () => { R.connection_name.EditText.RequestFocus(); }); return; } var shareScope = R.connection_share_spinner.SelectedItemPosition switch { 0 => StorageProviderVisibility.Public, 1 => StorageProviderVisibility.Private, _ => throw new IndexOutOfRangeException() }; #pragma warning disable 0618 var progress = new ProgressDialog(this); progress.SetCancelable(false); progress.SetMessage(GetString(Resource.String.connection_verifying)); progress.Show(); #pragma warning restore 0618 Task.Run(() => { switch (selection) { case 0: { if (alibaba.Verify()) { Globals.CloudManager.AddStorageProvider(Globals.CloudManager.PersonalClouds[0].Id, Guid.NewGuid(), name, alibaba, shareScope); RunOnUiThread(() => { progress.Dismiss(); Finish(); }); } else { RunOnUiThread(() => { progress.Dismiss(); this.ShowAlert(GetString(Resource.String.connection_bad_account), GetString(Resource.String.connection_bad_aliyun_account)); }); } return; } case 1: { if (azure.Verify()) { Globals.CloudManager.AddStorageProvider(Globals.CloudManager.PersonalClouds[0].Id, Guid.NewGuid(), name, azure, shareScope); RunOnUiThread(() => { progress.Dismiss(); Finish(); }); } else { RunOnUiThread(() => { progress.Dismiss(); this.ShowAlert(GetString(Resource.String.connection_bad_account), GetString(Resource.String.connection_bad_azure_account)); }); } return; } } }); } }