示例#1
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"));
                            });
                        });
                    }
                });
            });
        }
示例#2
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"));
                    });
                }
            });
        }