Exemple #1
0
        /// <summary>异步调用命令</summary>
        /// <param name="method"></param>
        /// <param name="action"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        protected async Task <TResult> InvokeAsync <TResult>(HttpMethod method, String action, Object args = null)
        {
            var request = ApiHelper.BuildRequest(method, action, args);

            // 资源路径
            var resourcePath = action;

            if (!_bucketName.IsNullOrEmpty())
            {
                resourcePath = "/" + _bucketName + resourcePath;
            }

            // 时间
            request.Headers.Date = DateTimeOffset.UtcNow;
            //request.Headers.Add("Date", DateTime.UtcNow.ToString("ddd, dd MMM yyyy HH:mm:ss \\G\\M\\T"));

            // 签名
            var canonicalString = BuildCanonicalString(method.Method, resourcePath, request);
            var signature       = canonicalString.GetBytes().SHA1(AccessKeySecret.GetBytes()).ToBase64();

            request.Headers.Authorization = new AuthenticationHeaderValue("OSS", AccessKeyId + ":" + signature);

            var http = GetClient();
            var rs   = await http.SendAsync(request);

            return(await ApiHelper.ProcessResponse <TResult>(rs));
        }
        void ReleaseDesignerOutlets()
        {
            if (AccessKeyID != null)
            {
                AccessKeyID.Dispose();
                AccessKeyID = null;
            }

            if (AccessKeySecret != null)
            {
                AccessKeySecret.Dispose();
                AccessKeySecret = null;
            }

            if (BucketName != null)
            {
                BucketName.Dispose();
                BucketName = null;
            }

            if (Endpoint != null)
            {
                Endpoint.Dispose();
                Endpoint = null;
            }

            if (SaveButton != null)
            {
                SaveButton.Dispose();
                SaveButton = null;
            }

            if (ServiceName != null)
            {
                ServiceName.Dispose();
                ServiceName = null;
            }

            if (ShareCredentialsCell != null)
            {
                ShareCredentialsCell.Dispose();
                ShareCredentialsCell = null;
            }

            if (StoreCredentialsCell != null)
            {
                StoreCredentialsCell.Dispose();
                StoreCredentialsCell = null;
            }
        }
Exemple #3
0
        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"));
                            });
                        });
                    }
                });
            });
        }
Exemple #4
0
        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"));
                    });
                }
            });
        }