Esempio n. 1
0
        public static IProgressDialog Progress(UIApplication app, UIView view, ProgressConfig config)
        {
            app.SafeInvokeOnMainThread(() =>
            {
                _progressHub = MBProgressHUD.ShowHUD(view, true);
                //_progressHub.Mode = MBProgressHUDMode.DeterminateHorizontalBar;
                _progressHub.Mode                = MBProgressHUDMode.Determinate;
                _progressHub.Label.Text          = config.Text;
                _progressHub.Label.LineBreakMode = UILineBreakMode.WordWrap;
                _progressHub.Label.Lines         = int.MaxValue;
                _progressHub.MinShowTime         = 1; // The minimum time (in seconds) that the HUD is shown.

                if (config.MarkType == MarkType.Black)
                {
                    _progressHub.BackgroundView.Style = MBProgressHUDBackgroundStyle.SolidColor;
                    _progressHub.BackgroundView.Color = UIColor.Black.ColorWithAlpha(0.5f);
                }

                if (config.Cancellable)
                {
                    _progressHub.Button.SetTitle(config.CancelText, UIControlState.Normal);
                    _progressHub.Button.AddTarget((_1, _2) =>
                    {
                        config.CancelAction?.Invoke();
                        _progressHub.Hide(true);
                    }, UIControlEvent.TouchUpInside);
                }

                _progressHub.Show(true);
            });

            return(new DefaultProgressDialog(app, config, _progressHub));
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            MBProgressHUD hud = MBProgressHUD.ShowHUD(View, true);

            hud.Label.Text = "Loading...";

            hud.Show(true);
            hud.Hide(true, 3.0f);
        }
        private void SubmitAndCreate(object sender, EventArgs e)
        {
            var cloudName  = CloudNameBox.Text;
            var deviceName = DeviceNameBox.Text;

            var invalidCharHit = false;

            foreach (var character in PathConsts.InvalidCharacters)
            {
                if (deviceName?.Contains(character) == true)
                {
                    invalidCharHit = true;
                }
            }
            if (string.IsNullOrWhiteSpace(deviceName) || invalidCharHit)
            {
                this.ShowWarning(this.Localize("Settings.BadDeviceName"), this.Localize("Settings.NoSpecialCharacters"));
                return;
            }

            if (string.IsNullOrWhiteSpace(cloudName))
            {
                this.ShowError(this.Localize("Settings.BadCloudName"), this.Localize("Settings.CloudNameCannotBeEmpty"));
                return;
            }

            var hud = MBProgressHUD.ShowHUD(NavigationController.View, true);

            hud.Label.Text = this.Localize("Welcome.Creating");
            Task.Run(async() => {
                try
                {
                    Globals.CloudManager.CreatePersonalCloud(cloudName, deviceName);
                    Globals.Database.SaveSetting(UserSettings.DeviceName, deviceName);
                    InvokeOnMainThread(() => {
                        hud.Hide(true);
                        this.ShowConfirmation(this.Localize("Welcome.Created"),
                                              string.Format(CultureInfo.InvariantCulture, this.Localize("Welcome.CreatedCloud.Formattable"), cloudName), () => {
                            NavigationController.DismissViewController(true, null);
                        });
                    });
                }
                catch
                {
                    InvokeOnMainThread(() => {
                        hud.Hide(true);
                        this.ShowError(this.Localize("Error.CreateCloud"));
                    });
                }
            });
        }
Esempio n. 4
0
        public static IDisposable Loading(UIApplication app, UIView view, LoadingConfig config)
        {
            app.SafeInvokeOnMainThread(() =>
            {
                _loadingHub                     = MBProgressHUD.ShowHUD(view, true);
                _loadingHub.Mode                = MBProgressHUDMode.Indeterminate;
                _loadingHub.Label.Text          = config.Text;
                _loadingHub.Label.LineBreakMode = UILineBreakMode.WordWrap;
                _loadingHub.Label.Lines         = int.MaxValue;
                _loadingHub.MinShowTime         = 1;         // The minimum time (in seconds) that the HUD is shown.

                if (config.MarkType == MarkType.Black)
                {
                    _loadingHub.BackgroundView.Style = MBProgressHUDBackgroundStyle.SolidColor;
                    _loadingHub.BackgroundView.Color = UIColor.Black.ColorWithAlpha(0.5f);
                }

                if (config.Cancellable)
                {
                    _loadingHub.Button.SetTitle(config.CancelText, UIControlState.Normal);
                    _loadingHub.Button.AddTarget((_1, _2) =>
                    {
                        config.CancelAction?.Invoke();
                        _loadingHub.Hide(true);
                    }, UIControlEvent.TouchUpInside);
                }

                _loadingHub.Show(true);

                if (config.Duration.HasValue)
                {
                    _loadingHub.Hide(true, config.Duration.Value.TotalSeconds);
                }

                //_loadingHub.Hide(true, 3);  // seconds
            });

            return(new DisposableAction(() => _loadingHub.Hide(true)));
        }
Esempio n. 5
0
        public static void Build(UIApplication app, UIView view, ToastConfig config)
        {
            app.SafeInvokeOnMainThread(() =>
            {
                _hub                     = MBProgressHUD.ShowHUD(view, true);
                _hub.Mode                = MBProgressHUDMode.Text;
                _hub.Label.Text          = config.Message;
                _hub.Label.LineBreakMode = UILineBreakMode.WordWrap;
                _hub.Label.Lines         = int.MaxValue;
                _hub.MinShowTime         = 1; // The minimum time (in seconds) that the HUD is shown.

                _hub.UserInteractionEnabled = false;

                if (config.TextColor.HasValue)
                {
                    _hub.Label.TextColor = config.TextColor.Value.ToNative();
                }

                if (config.BackgroundColor.HasValue)
                {
                    _hub.BezelView.BackgroundColor = config.BackgroundColor.Value.ToNative();
                }

                if (config.Position == ToastPosition.Top)
                {
                    _hub.Offset = new CoreGraphics.CGPoint(0, 0);
                }
                else if (config.Position == ToastPosition.Bottom || config.Position == ToastPosition.Default)
                {
                    _hub.Offset = new CoreGraphics.CGPoint(0, 10000);
                }

                _hub.Show(true);

                _hub.Hide(true, config.Duration.TotalSeconds);
            });
        }
Esempio n. 6
0
        private void VerifyCredentials(object sender, EventArgs e)
        {
            var name           = ServiceName.Text;
            var invalidCharHit = false;

            foreach (var character in PathConsts.InvalidCharacters)
            {
                if (name?.Contains(character) == true)
                {
                    invalidCharHit = true;
                }
            }
            if (string.IsNullOrEmpty(name) || invalidCharHit)
            {
                this.ShowWarning(this.Localize("Online.BadName"), this.Localize("Online.IllegalName"), () => {
                    ServiceName.BecomeFirstResponder();
                });
                return;
            }

            var endpoint = EndpointSuffix.Text;

            if (string.IsNullOrEmpty(endpoint))
            {
                this.ShowWarning(this.Localize("Online.BadCredential"), this.Localize("Azure.BadEndpoint"), () => {
                    EndpointSuffix.BecomeFirstResponder();
                });
                return;
            }

            var accountName = AccountName.Text;

            var accessKey = AccountKey.Text;

            if (string.IsNullOrEmpty(accessKey))
            {
                this.ShowWarning(this.Localize("Online.BadCredential"), this.Localize("Azure.BadAccountKey"), () => {
                    AccountKey.BecomeFirstResponder();
                });
                return;
            }

            var container = Container.Text;

            if (string.IsNullOrEmpty(container))
            {
                this.ShowWarning(this.Localize("Online.BadCredential"), this.Localize("Azure.BadContainer"), () => {
                    Container.BecomeFirstResponder();
                });
                return;
            }

            if (!Globals.Database.IsStorageNameUnique(name))
            {
                this.ShowWarning(this.Localize("Online.ServiceAlreadyExists"), this.Localize("Online.ChooseADifferentName"), () => {
                    ServiceName.BecomeFirstResponder();
                });
                return;
            }

            string connection;

            if (endpoint.Contains(accountName, StringComparison.Ordinal))
            {
                accountName = null;
            }
            if (endpoint.StartsWith("http://", StringComparison.Ordinal))
            {
                endpoint = 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.ShowError(this.Localize("Azure.BadAccount"), this.Localize("Azure.EndpointAndNameMismatch"));
                    return;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(accountName))
                {
                    this.ShowError(this.Localize("Online.BadCredential"), this.Localize("Azure.BadAccountName"));
                    return;
                }
                else
                {
                    connection = $"DefaultEndpointsProtocol=https;AccountName={accountName};AccountKey={accessKey};EndpointSuffix={endpoint}";
                }
            }

            var hud = MBProgressHUD.ShowHUD(NavigationController.View, true);

            hud.Label.Text = this.Localize("Online.Verifying");

            Task.Run(() => {
                var config = new AzureBlobConfig {
                    ConnectionString = connection,
                    BlobName         = container
                };

                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("Azure.CannotAddService"), this.Localize("Error.Internal"));
                        });
                    }
                }
                else
                {
                    InvokeOnMainThread(() => {
                        hud.Hide(true);
                        this.ShowError(this.Localize("Error.Authentication"), this.Localize("Azure.Unauthorized"));
                    });
                }
            });
        }
Esempio n. 7
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"));
                    });
                }
            });
        }
Esempio n. 8
0
        private void VerifyInvite(object sender, EventArgs e)
        {
            var deviceName = DeviceNameBox.Text;
            var inviteCode = InviteCodeBox.Text;

            var invalidCharHit = false;

            foreach (var character in PathConsts.InvalidCharacters)
            {
                if (deviceName?.Contains(character) == true)
                {
                    invalidCharHit = true;
                }
            }
            if (string.IsNullOrWhiteSpace(deviceName) || invalidCharHit)
            {
                this.ShowWarning(this.Localize("Settings.BadDeviceName"), this.Localize("Settings.NoSpecialCharacters"));
                return;
            }

            if (inviteCode?.Length != 4)
            {
                this.ShowError(this.Localize("Settings.BadInvitation"), this.Localize("Settings.EnterValidInvitation"));
                return;
            }

            var hud = MBProgressHUD.ShowHUD(NavigationController.View, true);

            hud.Label.Text = this.Localize("Welcome.Verifying");
            Task.Run(async() => {
                try
                {
                    var result = await Globals.CloudManager.JoinPersonalCloud(int.Parse(inviteCode, CultureInfo.InvariantCulture), deviceName).ConfigureAwait(false);
                    Globals.Database.SaveSetting(UserSettings.DeviceName, deviceName);
                    InvokeOnMainThread(() => {
                        hud.Hide(true);
                        this.ShowConfirmation(this.Localize("Welcome.Accepted"),
                                              string.Format(CultureInfo.InvariantCulture, this.Localize("Welcome.AcceptedByCloud.Formattable"), result.DisplayName), () => {
                            NavigationController.DismissViewController(true, null);
                        });
                    });
                }
                catch (NoDeviceResponseException)
                {
                    InvokeOnMainThread(() => {
                        hud.Hide(true);
                        this.ShowError(this.Localize("Error.EnrollDevice"), this.Localize("Error.NoCloudInNetwork"));
                    });
                }
                catch (InviteNotAcceptedException)
                {
                    InvokeOnMainThread(() => {
                        hud.Hide(true);
                        this.ShowError(this.Localize("Error.EnrollDevice"), this.Localize("Settings.EnterValidInvitation"));
                    });
                }
                catch
                {
                    InvokeOnMainThread(() => {
                        hud.Hide(true);
                        this.ShowError(this.Localize("Error.EnrollDevice"));
                    });
                }
            });
        }