예제 #1
0
        protected virtual void Awake()
        {
            //register interactions:
            Register(_leftIndexStatus);
            Register(_leftIndexMCPStatus);
            Register(_leftMiddleMCPStatus);
            Register(_rightIndexStatus);
            Register(_rightIndexMCPStatus);
            Register(_rightMiddleMCPStatus);
            Register(_colliderStatus);

            //refs:
            _audioSource = GetComponent <AudioSource>();

            //trigger volume:
            _trigger           = gameObject.AddComponent <BoxCollider>();
            _trigger.isTrigger = true;
            _trigger.size      = Vector3.zero;

            //hooks:
            OnPressUpdated.AddListener(HandlePressUpdated);
            OnHoverUpdated.AddListener(HandleHoverUpdated);
            OnPressed.AddListener(HandlePressed);
            OnReleased.AddListener(HandleReleased);
            OnTouchEnd.AddListener(HandleTouchEnd);
            OnHoverEnd.AddListener(HandleHoverEnd);
            OnCanceled.AddListener(HandleCanceled);

            //sets:
            ResetElement();
            ResetFrame();
            ResetColors();
        }
예제 #2
0
 private void RunOnCanceled()
 {
     if (OnCanceled != null)
     {
         OnCanceled.Invoke();
     }
 }
예제 #3
0
 /// <summary>
 /// Cancel the load
 /// </summary>
 /// <returns><c>true</c> if this instance cancel ; otherwise, <c>false</c>.</returns>
 public virtual bool Cancel()
 {
     if (OnCanceled != null)
     {
         OnCanceled.Invoke(this);
     }
     return(true);
 }
예제 #4
0
        private void Canceled()
        {
            btnCancel.Enabled     = false;
            btnCancel.Visible     = false;
            lblTotalProgress.Text = lblCurrent.Text = "canceled";
            progressTotal.Value   = progressCurrentJob.Value = 0;

            OnCanceled?.Invoke();

            if (ddlWhenDone.Text == "Shutdown [On Successfull]")
            {
                new ShutdownForm().ShowDialog();
            }
        }
예제 #5
0
        /// <summary>
        /// Stops the scanning process
        /// </summary>
        /// <returns></returns>
        public async Task StopAsync()
        {
            await Task.Run(() =>
            {
                OnCanceling?.Invoke(this, new EventArgs {
                });

                ScanCancellationTokenSource.Cancel();

                Task.WhenAll(Workers.Select(w => w.Task)).ContinueWith((t) =>
                {
                    OnCanceled?.Invoke(this, new EventArgs {
                    });
                }).Wait();
            });
        }
예제 #6
0
        public UpdateRendererDialogOverlay(CoreGraphics.CGRect frame, nfloat transparency, UIColor color, string stretchType) : base(frame)
        {
            // Store the type of stretch parameters to define.
            _stretchParamsType = stretchType;

            // Create a semi-transparent overlay with the specified background color.
            BackgroundColor = color;
            Alpha           = transparency;

            // Label to describe the type of input.
            var descriptionLabel = new UILabel
            {
                Text          = "Stretch parameters (" + _stretchParamsType + ")",
                TextAlignment = UITextAlignment.Center,
                TextColor     = UIColor.Blue
            };

            // Button to create the stretch parameters and pass it back to the main page.
            UIButton inputStretchParamsButton = new UIButton();

            inputStretchParamsButton.SetTitle("Apply", UIControlState.Normal);
            inputStretchParamsButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            inputStretchParamsButton.TouchUpInside += InputStretchParamsButton_Click;

            // Button to cancel the inputs.
            UIButton cancelButton = new UIButton();

            cancelButton.SetTitle("Cancel", UIControlState.Normal);
            cancelButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            cancelButton.TouchUpInside += (s, e) => { OnCanceled.Invoke(this, null); };

            // Create inputs that are specific for the stretch type.
            switch (_stretchParamsType)
            {
            case "Min Max RGB":
                CreateRgbInputUI(inputStretchParamsButton, cancelButton, descriptionLabel);
                break;

            case "% Clip":
                CreatePercentInputUI(inputStretchParamsButton, cancelButton, descriptionLabel);
                break;

            case "Std Dev":
                CreateStdDevInputUI(inputStretchParamsButton, cancelButton, descriptionLabel);
                break;
            }
        }
예제 #7
0
        /// <summary>
        /// Execute the procedure.
        /// </summary>
        /// <exception cref="OperationCanceledException"></exception>
        /// <returns></returns>
        public bool Execute()
        {
            try
            {
                var task = procedure.Invoke(input, Token);
                Token.ThrowIfCancellationRequested();
                var result = task.Result;
                OnCompleted?.Invoke(this, result);
                return(true);
            }
            catch (OperationCanceledException e)
            {
                OnCanceled?.Invoke(this, new AsyncProcedureEventArgs <TInput>(input, false));
                onError.Invoke(null, e);
            }

            return(false);
        }
        // Constructor that takes a picker for defining new statistics.
        public ChooseStatisticOverlay(UIPickerView statPicker)
        {
            this.TranslatesAutoresizingMaskIntoConstraints = false;
            // Toolbar with "Add" and "Done" buttons.
            UIToolbar toolbar = new UIToolbar();

            toolbar.TranslatesAutoresizingMaskIntoConstraints = false;

            statPicker.TranslatesAutoresizingMaskIntoConstraints = false;

            // Add Button (add the new stat and don't dismiss the UI).
            UIBarButtonItem addButton = new UIBarButtonItem("Add", UIBarButtonItemStyle.Plain, (s, e) =>
            {
                // Get the selected StatisticDefinition.
                StatDefinitionModel statPickerModel   = (StatDefinitionModel)statPicker.Model;
                StatisticDefinition newStatDefinition = statPickerModel.SelectedStatDefinition;
                if (newStatDefinition != null)
                {
                    // Fire the OnMapInfoEntered event and provide the statistic definition.
                    OnStatisticDefined?.Invoke(this, newStatDefinition);
                }
            });

            // Done Button (dismiss the UI, don't use the selected statistic).
            UIBarButtonItem doneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done,
                                                             (s, e) => { OnCanceled?.Invoke(this, null); });

            // Add the buttons to the toolbar.
            toolbar.Items = new[] { addButton, doneButton };

            statPicker.BackgroundColor = UIColor.White;

            // Add the controls.
            AddSubviews(toolbar, statPicker);

            toolbar.BottomAnchor.ConstraintEqualTo(BottomAnchor).Active     = true;
            toolbar.LeadingAnchor.ConstraintEqualTo(LeadingAnchor).Active   = true;
            toolbar.TrailingAnchor.ConstraintEqualTo(TrailingAnchor).Active = true;

            statPicker.TopAnchor.ConstraintEqualTo(TopAnchor).Active            = true;
            statPicker.LeadingAnchor.ConstraintEqualTo(LeadingAnchor).Active    = true;
            statPicker.TrailingAnchor.ConstraintEqualTo(TrailingAnchor).Active  = true;
            statPicker.BottomAnchor.ConstraintEqualTo(toolbar.TopAnchor).Active = true;
        }
예제 #9
0
        private void PART_NegativeButton_Click(object sender, RoutedEventArgs e)
        {
            if (WrappedDialog.Dispatcher.CheckAccess())
            {
                IsCanceled = true;
                WrappedDialog.PART_NegativeButton.IsEnabled = false;
            }
            else
            {
                WrappedDialog.Dispatcher.Invoke(() =>
                {
                    IsCanceled = true;
                    WrappedDialog.PART_NegativeButton.IsEnabled = false;
                    OnCanceled?.Invoke(WrappedDialog);
                });
            }

            // Close();
        }
예제 #10
0
        private void ConfigureNavigationBar()
        {
            _navigationItem = NavigationItem;

            if (Comparable == null)
            {
                Title = "Product";
                var cancelButton = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (sender, args) =>
                {
                    OnCanceled.Fire(this, EventArgs.Empty);
                });

                _navigationItem.SetRightBarButtonItem(GetDoneButton(), false);
                _navigationItem.SetLeftBarButtonItem(cancelButton, false);
            }
            else
            {
                NavigationController.SetNavigationBarHidden(false, false);
                NavigationItem.RightBarButtonItem = GetDoneButton();
                Title = string.IsNullOrEmpty(Comparable.Product) ? "Product" : Comparable.Product;
            }
        }
        public ApplyHillshadeRendererDialogOverlay(CGRect frame, nfloat transparency, UIColor color) : base(frame)
        {
            // Create a semi-transparent overlay with the specified background color.
            BackgroundColor = color;
            Alpha           = transparency;

            // Button to create the hillshade parameters and pass them back to the main page.
            UIButton inputHillshadeParamsButton = new UIButton();

            inputHillshadeParamsButton.SetTitle("Apply", UIControlState.Normal);
            inputHillshadeParamsButton.SetTitleColor(TintColor, UIControlState.Normal);
            inputHillshadeParamsButton.TouchUpInside += InputHillshadeParamsButton_Click;

            // Button to cancel the input.
            UIButton cancelButton = new UIButton();

            cancelButton.SetTitle("Cancel", UIControlState.Normal);
            cancelButton.SetTitleColor(UIColor.Red, UIControlState.Normal);
            cancelButton.TouchUpInside += (s, e) => { OnCanceled?.Invoke(this, null); };

            CreateHillshadeInputUi(inputHillshadeParamsButton, cancelButton);
        }
        // Constructor that takes a picker for defining new statistics
        public ChooseStatisticOverlay(CGRect frame, nfloat transparency, UIColor color, UIPickerView statPicker) : base(frame)
        {
            // Store the statistics picker
            _statisticPicker = statPicker;

            // Create a semi-transparent overlay with the specified background color
            BackgroundColor = color;
            Alpha           = transparency;

            // Set the total height and width of the control set
            nfloat totalHeight = 400;
            nfloat totalWidth  = 320;

            // Find the bottom x and y of the view
            nfloat centerX = Frame.Width / 2;
            nfloat centerY = Frame.Bottom - 40;

            // Find the start x and y for the control layout (aligned to the bottom of the view)
            nfloat controlX = centerX - (totalWidth / 2);
            nfloat controlY = centerY - totalHeight;

            // Toolbar with "Add" and "Done" buttons
            UIToolbar toolbar = new UIToolbar();

            toolbar.BarStyle    = UIBarStyle.Black;
            toolbar.Translucent = false;
            toolbar.SizeToFit();

            // Add Button (add the new stat and don't dismiss the UI)
            UIBarButtonItem addButton = new UIBarButtonItem("Add", UIBarButtonItemStyle.Done, (s, e) =>
            {
                // Get the selected StatisticDefinition
                StatDefinitionModel statPickerModel   = _statisticPicker.Model as StatDefinitionModel;
                StatisticDefinition newStatDefinition = statPickerModel.SelectedStatDefinition;
                if (newStatDefinition != null)
                {
                    // Fire the OnMapInfoEntered event and provide the statistic definition
                    if (OnStatisticDefined != null)
                    {
                        // Raise the event
                        OnStatisticDefined(this, newStatDefinition);
                    }
                }
            });

            // Done Button (dismiss the UI, don't use the selected statistic)
            UIBarButtonItem doneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Plain, (s, e) =>
            {
                OnCanceled.Invoke(this, null);
            });

            // Add the buttons to the toolbar
            toolbar.SetItems(new UIBarButtonItem[] { addButton, doneButton }, true);

            // Define the location of the statistic picker
            controlY = controlY + 200;
            _statisticPicker.Frame = new CGRect(controlX, controlY, totalWidth, 200);

            // Set the location for the toolbar
            controlY      = controlY + 220;
            toolbar.Frame = new CGRect(controlX, controlY, totalWidth, 30);

            // Add the controls
            AddSubviews(toolbar, _statisticPicker);
        }
        public SearchMapsDialogOverlay(CoreGraphics.CGRect frame, nfloat transparency, UIColor color) : base(frame)
        {
            // Create a semi-transparent overlay with the specified background color
            BackgroundColor = color;
            Alpha           = transparency;

            // Set size and spacing for controls
            nfloat controlHeight = 25;
            nfloat rowSpace      = 11;
            nfloat buttonSpace   = 15;
            nfloat textViewWidth = Frame.Width - 60;
            nfloat buttonWidth   = 60;

            // Get the total height and width of the control set (three rows of controls, one set of space)
            nfloat totalHeight = (3 * controlHeight) + rowSpace;
            nfloat totalWidth  = textViewWidth;

            // Find the center x and y of the view
            nfloat centerX = Frame.Width / 2;
            nfloat centerY = Frame.Height / 2;

            // Find the start x and y for the control layout
            nfloat controlX = centerX - (totalWidth / 2);
            nfloat controlY = centerY - (totalHeight / 2);

            // Label for inputs
            var description = new UILabel(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight));

            description.Text      = "Search web maps";
            description.TextColor = UIColor.Blue;

            // Adjust the Y position for the next control
            controlY = controlY + controlHeight + rowSpace;

            // Title text input
            _searchTextField                        = new UITextField(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight));
            _searchTextField.Placeholder            = "Search text";
            _searchTextField.AutocapitalizationType = UITextAutocapitalizationType.None;
            _searchTextField.BackgroundColor        = UIColor.LightGray;

            // Adjust the Y position for the next control
            controlY = controlY + controlHeight + rowSpace;

            // Button to pass the text to the search
            UIButton saveButton = new UIButton(new CoreGraphics.CGRect(controlX, controlY, buttonWidth, controlHeight));

            saveButton.SetTitle("Search", UIControlState.Normal);
            saveButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            saveButton.TouchUpInside += SearchButtonClick;

            // Adjust the X position for the next control (space between buttons)
            controlX = controlX + buttonWidth + buttonSpace;

            // Button to cancel the search
            UIButton cancelButton = new UIButton(new CoreGraphics.CGRect(controlX, controlY, buttonWidth, controlHeight));

            cancelButton.SetTitle("Cancel", UIControlState.Normal);
            cancelButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            cancelButton.TouchUpInside += (s, e) => { OnCanceled.Invoke(this, null); };

            // Add the controls
            AddSubviews(description, _searchTextField, saveButton, cancelButton);
        }
        public OAuthPropsDialogOverlay(CoreGraphics.CGRect frame, nfloat transparency, UIColor color, string clientId, string redirectUrl) : base(frame)
        {
            // Create a semi-transparent overlay with the specified background color
            BackgroundColor = color;
            Alpha           = transparency;

            // Set size and spacing for controls
            nfloat controlHeight = 25;
            nfloat rowSpace      = 11;
            nfloat lessRowSpace  = 4;
            nfloat buttonSpace   = 15;
            nfloat textViewWidth = Frame.Width - 60;
            nfloat buttonWidth   = 60;

            // Get the total height and width of the control set (four rows of controls, three sets of space)
            nfloat totalHeight = (6 * controlHeight) + (5 * rowSpace);
            nfloat totalWidth  = textViewWidth;

            // Find the center x and y of the view
            nfloat centerX = Frame.Width / 2;
            nfloat centerY = Frame.Height / 2;

            // Find the start x and y for the control layout
            nfloat controlX = centerX - (totalWidth / 2);
            nfloat controlY = centerY - (totalHeight / 2);

            // Label for inputs
            var description = new UILabel(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight));

            description.Text      = "OAuth Settings";
            description.TextColor = UIColor.Blue;

            // Adjust the Y position for the next control
            controlY = controlY + controlHeight + rowSpace;

            // Client ID text input and label
            var clientIdLabel = new UILabel(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight));

            clientIdLabel.Text = "Client ID";

            controlY = controlY + controlHeight + lessRowSpace;

            _clientIdTextField                        = new UITextField(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight));
            _clientIdTextField.Placeholder            = "Client ID";
            _clientIdTextField.Text                   = clientId;
            _clientIdTextField.AutocapitalizationType = UITextAutocapitalizationType.None;
            _clientIdTextField.BackgroundColor        = UIColor.LightGray;

            // Adjust the Y position for the next control
            controlY = controlY + controlHeight + rowSpace;

            // Redirect Url text input and label
            var redirectLabel = new UILabel(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight));

            redirectLabel.Text = "Redirect URL";

            controlY = controlY + controlHeight + lessRowSpace;

            _redirectUrlTextField                        = new UITextField(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight));
            _redirectUrlTextField.Placeholder            = "Redirect URI";
            _redirectUrlTextField.Text                   = redirectUrl;
            _redirectUrlTextField.AutocapitalizationType = UITextAutocapitalizationType.None;
            _redirectUrlTextField.BackgroundColor        = UIColor.LightGray;

            // Adjust the Y position for the next control
            controlY = controlY + controlHeight + rowSpace;

            // Button to save the values
            UIButton saveButton = new UIButton(new CoreGraphics.CGRect(controlX, controlY, buttonWidth, controlHeight));

            saveButton.SetTitle("Save", UIControlState.Normal);
            saveButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            saveButton.TouchUpInside += SaveButtonClick;

            // Adjust the X position for the next control
            controlX = controlX + buttonWidth + buttonSpace;

            // Button to cancel the save
            UIButton cancelButton = new UIButton(new CoreGraphics.CGRect(controlX, controlY, buttonWidth, controlHeight));

            cancelButton.SetTitle("Cancel", UIControlState.Normal);
            cancelButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            cancelButton.TouchUpInside += (s, e) => { OnCanceled.Invoke(this, null); };

            // Add the controls
            AddSubviews(description, clientIdLabel, _clientIdTextField, redirectLabel, _redirectUrlTextField, saveButton, cancelButton);
        }
        public LoginOverlay(CGRect frame, nfloat transparency, UIColor color) : base(frame)
        {
            // Create a semi-transparent overlay with the specified background color.
            BackgroundColor = color;
            Alpha           = transparency;

            // Set size and spacing for controls.
            nfloat controlHeight = 25;
            nfloat rowSpace      = 11;
            nfloat buttonSpace   = 15;
            nfloat textViewWidth = Frame.Width - 60;
            nfloat buttonWidth   = 60;

            // Get the total height and width of the control set (four rows of controls, three sets of space).
            nfloat totalHeight = (4 * controlHeight) + (3 * rowSpace);
            nfloat totalWidth  = textViewWidth;

            // Find the center x and y of the view.
            nfloat centerX = Frame.Width / 2;
            nfloat centerY = Frame.Height / 2;

            // Find the start x and y for the control layout.
            nfloat controlX = centerX - (totalWidth / 2);
            nfloat controlY = centerY - (totalHeight / 2);

            // Username text input.
            _usernameTextField = new UITextField(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Placeholder            = "Username",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                BackgroundColor        = UIColor.White,
                TextColor = UIColor.Black
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Password text input.
            _passwordTextField = new UITextField(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                SecureTextEntry        = true,
                Placeholder            = "Password",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                BackgroundColor        = UIColor.White,
                TextColor = UIColor.Black
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Domain text input.
            _domainTextField = new UITextField(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Placeholder            = "Domain",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                BackgroundColor        = UIColor.White,
                TextColor = UIColor.Black
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Button to submit the login information.
            UIButton loginButton = new UIButton(new CGRect(controlX, controlY, buttonWidth, controlHeight));

            loginButton.SetTitle("Login", UIControlState.Normal);
            loginButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            loginButton.TouchUpInside += LoginButtonClick;

            // Adjust the X position for the next control.
            controlX = controlX + buttonWidth + buttonSpace;

            // Button to cancel the login.
            UIButton cancelButton = new UIButton(new CGRect(controlX, controlY, buttonWidth, controlHeight));

            cancelButton.SetTitle("Cancel", UIControlState.Normal);
            cancelButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            cancelButton.TouchUpInside += (s, e) => { OnCanceled.Invoke(this, null); };

            // Add the controls.
            AddSubviews(_usernameTextField, _passwordTextField, _domainTextField, loginButton, cancelButton);
        }
예제 #16
0
        public async Task Scann(Uri rootUrl, string searchTxt, int maxThreads, int maxUrls)
        {
            _cancellationSrc = new CancellationTokenSource();

            int urlCounter = 0, level = 0;
            var _nodesQueue = new ConcurrentQueue <Node>();

            _nodesQueue.Enqueue(new Node(rootUrl, 0));

            WriteLine($"begin scanning threadId: {Thread.CurrentThread.ManagedThreadId}");

            try
            {
                while (_nodesQueue.Any())
                {
                    _cancellationSrc.Token.ThrowIfCancellationRequested();

                    //так как мы используем алгоритм поиска в ширину то возможна паралельная загрузка
                    //и сканирование страниц только одного уровня графа

                    //находим и записываем в список все страницы текущего уровня
                    List <Node> nodesOfLevel = GetAllPagesOfTheLevel(_nodesQueue, level);

                    var callThreadContext = SynchronizationContext.Current;
                    if (callThreadContext == null)
                    {
                        throw new NullReferenceException("Current synchronization context is null!");
                    }

                    //var scheduler = TaskScheduler.FromCurrentSynchronizationContext();

                    var scannOperations = nodesOfLevel.Select(node =>
                                                              new Action(() => //download and scann the page
                    {
                        HttpClient http = null;
                        try
                        {
                            node.State = NodeState.Downloading;
                            /*OnNodeStateChanged?.Invoke(node)*/
                            callThreadContext.Send(delegate(object s) { OnNodeStateChanged?.Invoke(node); }, null);

                            //download the page
                            http        = new HttpClient();
                            var pageStr = http.GetStringAsync(node.Url).Result;
                            //Thread.Sleep(1000);
                            //detect the search text on the page
                            node.State = IsSearchTxtFound(searchTxt, pageStr) ? NodeState.Found : NodeState.NotFound;
                            callThreadContext.Send(delegate(object s) { OnNodeStateChanged?.Invoke(node); }, null);

                            WriteLine($"url: {node.Url}; state: {node.State}; level: {level}; threadId: {Thread.CurrentThread.ManagedThreadId}");

                            var urlsOnThePage = GetPageUrls(pageStr);
                            foreach (var urlStr in urlsOnThePage)
                            {
                                if (urlCounter <= maxUrls)
                                {
                                    var newNode = new Node(new Uri(urlStr), level + 1);
                                    _nodesQueue.Enqueue(newNode);
                                    Interlocked.Increment(ref urlCounter); //thread safe increment
                                    //Thread.Sleep(1000);
                                    callThreadContext.Send(delegate(object s) { OnUrlFound?.Invoke(newNode); }, null);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }

                        catch (Exception e)
                        {
                            node.ErrorMsg = e.InnerException?.Message;//TODO: refactor
                            node.State    = NodeState.Error;
                            callThreadContext.Send(delegate(object s) { OnNodeStateChanged?.Invoke(node); }, null);
                            WriteLine($"url: {node.Url}; state: {node.State}; msg: {node.ErrorMsg} level: {level}; threadId: {Thread.CurrentThread.ManagedThreadId}");
                        }
                        finally
                        {
                            http?.Dispose();
                        }
                    }));

                    //запускаем паралельную загрузку и сканирование всех страниц текущего уровня вложености графа
                    await RunAsynchronously(scannOperations, maxThreads);

                    ++level;
                }
            }
            catch (OperationCanceledException ex)
            {
                OnCanceled?.Invoke();
            }
            catch (Exception ex)
            {
                throw;
            }

            _cancellationSrc = null;
        }
        public LoginOverlay(CGRect frame, nfloat transparency, UIColor color, string url) : base(frame)
        {
            // Create a semi-transparent overlay with the specified background color.
            BackgroundColor = color;
            Alpha           = transparency;

            // Set size and spacing for controls.
            nfloat controlHeight = 25;
            nfloat rowSpace      = 11;
            nfloat buttonSpace   = 15;
            nfloat textViewWidth = Frame.Width - 60;
            nfloat buttonWidth   = 60;

            // Get the total height and width of the control set (five rows of controls, four sets of space).
            nfloat totalHeight = (5 * controlHeight) + (4 * rowSpace);
            nfloat totalWidth  = textViewWidth;

            // Find the center x and y of the view.
            nfloat centerX = Frame.Width / 2;
            nfloat centerY = Frame.Height / 2;

            // Find the start x and y for the control layout.
            nfloat controlX = centerX - (totalWidth / 2);
            nfloat controlY = centerY - (totalHeight / 2);

            // Set a title.
            var titleTextBlock = new UILabel(new CGRect(controlX, controlY, textViewWidth, controlHeight));

            titleTextBlock.Text = "Login to:";

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Service URL for which the user is logging in.
            var urlTextBlock = new UILabel(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Text          = url,
                TextColor     = UIColor.Blue,
                Lines         = 2,
                LineBreakMode = UILineBreakMode.CharacterWrap
            };

            urlTextBlock.Font = urlTextBlock.Font.WithSize(10);

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Username text input.
            _usernameTextField = new UITextField(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Placeholder            = "Username = user1",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                BackgroundColor        = UIColor.LightGray
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Password text input
            _passwordTextField = new UITextField(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                SecureTextEntry        = true,
                Placeholder            = "Password = user1",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                BackgroundColor        = UIColor.LightGray
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Button to submit the login information.
            UIButton loginButton = new UIButton(new CGRect(controlX, controlY, buttonWidth, controlHeight));

            loginButton.SetTitle("Login", UIControlState.Normal);
            loginButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            loginButton.TouchUpInside += LoginButtonClick;

            // Adjust the X position for the next control.
            controlX = controlX + buttonWidth + buttonSpace;

            // Button to cancel the login.
            UIButton cancelButton = new UIButton(new CGRect(controlX, controlY, buttonWidth, controlHeight));

            cancelButton.SetTitle("Cancel", UIControlState.Normal);
            cancelButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            cancelButton.TouchUpInside += (s, e) => { OnCanceled.Invoke(this, null); };

            // Add the controls.
            AddSubviews(titleTextBlock, urlTextBlock, _usernameTextField, _passwordTextField, loginButton, cancelButton);
        }
예제 #18
0
        public SaveMapDialogOverlay(CoreGraphics.CGRect frame, nfloat transparency, UIColor color, PortalItem mapItem) : base(frame)
        {
            // Store the current portal item for the map (if any)
            _portalItem = mapItem;

            // Create a semi-transparent overlay with the specified background color
            BackgroundColor = color;
            Alpha           = transparency;

            // Set size and spacing for controls
            nfloat controlHeight = 25;
            nfloat rowSpace      = 11;
            nfloat buttonSpace   = 15;
            nfloat textViewWidth = Frame.Width - 60;
            nfloat buttonWidth   = 60;

            // Get the total height and width of the control set (five rows of controls, four sets of space)
            nfloat totalHeight = (5 * controlHeight) + (4 * rowSpace);
            nfloat totalWidth  = textViewWidth;

            // Find the center x and y of the view
            nfloat centerX = Frame.Width / 2;
            nfloat centerY = Frame.Height / 2;

            // Find the start x and y for the control layout
            nfloat controlX = centerX - (totalWidth / 2);
            nfloat controlY = centerY - (totalHeight / 2);

            // Label for inputs
            var description = new UILabel(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight));

            description.Text      = "Portal item info";
            description.TextColor = UIColor.Blue;

            // Adjust the Y position for the next control
            controlY = controlY + controlHeight + rowSpace;

            // Title text input
            _titleTextField                        = new UITextField(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight));
            _titleTextField.Placeholder            = "Title";
            _titleTextField.AutocapitalizationType = UITextAutocapitalizationType.None;
            _titleTextField.BackgroundColor        = UIColor.LightGray;

            // Adjust the Y position for the next control
            controlY = controlY + controlHeight + rowSpace;

            // Description text input
            _descriptionTextField                        = new UITextField(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight));
            _descriptionTextField.Placeholder            = "Description";
            _descriptionTextField.AutocapitalizationType = UITextAutocapitalizationType.None;
            _descriptionTextField.BackgroundColor        = UIColor.LightGray;

            // Adjust the Y position for the next control
            controlY = controlY + controlHeight + rowSpace;

            // Tags text input
            _tagsTextField      = new UITextField(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight));
            _tagsTextField.Text = "ArcGIS Runtime, Web Map";
            _tagsTextField.AutocapitalizationType = UITextAutocapitalizationType.None;
            _tagsTextField.BackgroundColor        = UIColor.LightGray;

            // Adjust the Y position for the next control
            controlY = controlY + controlHeight + rowSpace;

            // Button to save the map
            UIButton saveButton = new UIButton(new CoreGraphics.CGRect(controlX, controlY, buttonWidth, controlHeight));

            saveButton.SetTitle("Save", UIControlState.Normal);
            saveButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            saveButton.TouchUpInside += SaveButtonClick;

            // Adjust the X position for the next control
            controlX = controlX + buttonWidth + buttonSpace;

            // Button to cancel the save
            UIButton cancelButton = new UIButton(new CoreGraphics.CGRect(controlX, controlY, buttonWidth, controlHeight));

            cancelButton.SetTitle("Cancel", UIControlState.Normal);
            cancelButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            cancelButton.TouchUpInside += (s, e) => { OnCanceled.Invoke(this, null); };

            // Add the controls
            AddSubviews(description, _titleTextField, _descriptionTextField, _tagsTextField, saveButton, cancelButton);

            // If there's an existing portal item, configure the dialog for "update" (read-only entries)
            if (this._portalItem != null)
            {
                _titleTextField.Text    = this._portalItem.Title;
                _titleTextField.Enabled = false;

                _descriptionTextField.Text    = this._portalItem.Description;
                _descriptionTextField.Enabled = false;

                _tagsTextField.Text    = string.Join(",", this._portalItem.Tags);
                _tagsTextField.Enabled = false;

                // Change the button text
                saveButton.SetTitle("Update", UIControlState.Normal);
            }
        }
예제 #19
0
        private async Task DownloadAsync(CancellationToken cancellationToken)
        {
            try
            {
                string workingDir = Properties.Settings.Default.MoviesDirectory;
                if (Properties.Settings.Default.OperationType == OperationType.MovieFile)
                {
                    string file = Properties.Settings.Default.MovieFile;
                    workingDir = new FileInfo(file).Directory.FullName;
                }
                else if (Properties.Settings.Default.OperationType == OperationType.TVSeries)
                {
                    workingDir = Properties.Settings.Default.SeriesTvDirectory;

                    string sDir = Path.Combine(workingDir, _gridDataItems.First().FullTitle);
                    if (!Directory.Exists(sDir))
                    {
                        Directory.CreateDirectory(sDir);
                    }
                }

                int totalIndex = 1;
                foreach (var item in _gridDataItems)
                {
                    ReportTotal(item.FullTitle, totalIndex, _gridDataItems.Count, cancellationToken.IsCancellationRequested);
                    ReportCurrent("Retrieve data from server", 1, 1, cancellationToken.IsCancellationRequested);

                    // TITLE
                    var data = await _apiLib.TitleAsync(item.Id, _clientOptions.PlotLanguage, _clientOptions.ToString());

                    if (!string.IsNullOrEmpty(data.ErrorMessage))
                    {
                        Canceled();
                        MetroMessageBox.Show(this, data.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    ReportTotal(data.FullTitle, totalIndex, _gridDataItems.Count, cancellationToken.IsCancellationRequested);

                    // RENAME
                    string srcDir       = Path.Combine(workingDir, item.Folder);
                    string movieRootDir = Path.Combine(workingDir, Utils.RenameToPhisicalName(data.FullTitle));
                    if (srcDir != movieRootDir)
                    {
                        if (!Directory.Exists(movieRootDir))
                        {
                            Directory.Move(srcDir, movieRootDir);
                        }
                        else
                        {
                            Directory.Delete(srcDir, true);
                        }
                    }
                    ReportCurrent("...", 1, 1, cancellationToken.IsCancellationRequested);

                    // SUBTITLE
                    if (_clientOptions.Subtitles)
                    {
                        int?seasonNumber = null;
                        if (Properties.Settings.Default.OperationType == OperationType.TVSeries &&
                            data.TvSeriesInfo != null &&
                            data.TvSeriesInfo.Seasons != null &&
                            data.TvSeriesInfo.Seasons.Count > 1)
                        {
                            var snForm = new SelectSeasonForm(data.FullTitle, data.TvSeriesInfo.Seasons);
                            if (snForm.ShowDialog() == DialogResult.OK)
                            {
                                seasonNumber = snForm.SeasonNumber;
                            }
                        }

                        ReportCurrent("Subtitles", 1, 1, cancellationToken.IsCancellationRequested);

                        var subtitleData = await _apiLib.SubtitleDataAsync(data.Id, _clientOptions.Subtitles_Language, seasonNumber);

                        await _apiLib.DownloadSubtitleAsync(
                            movieRootDir,
                            subtitleData,
                            new ProgressData(progress => ReportCurrent("Subtitles", progress.Current, progress.Total, cancellationToken.IsCancellationRequested)),
                            cancellationToken);

                        ReportCurrent("...", 1, 1, cancellationToken.IsCancellationRequested);
                    }

                    // REPORTS
                    if (_clientOptions.Report)
                    {
                        ReportCurrent("Report", 1, 1, cancellationToken.IsCancellationRequested);
                        string filePath = Path.Combine(movieRootDir, $"{item.Id}.png");
                        await _apiLib.DownloadReportAsync(
                            item.Id,
                            filePath,
                            _clientOptions.PlotLanguage,
                            _clientOptions.ReportOptionsString,
                            new ProgressData(progress => ReportCurrent("Report", progress.Current, progress.Total, cancellationToken.IsCancellationRequested, true)),
                            cancellationToken
                            );

                        ReportCurrent("...", 1, 1, cancellationToken.IsCancellationRequested);
                    }


                    // POSTERS
                    if (_clientOptions.Posters && data.Posters != null)
                    {
                        int index = 1;
                        if (_clientOptions.Posters_EnglishOnly) // Posters_EnglishOnly
                        {
                            data.Posters.Posters = data.Posters.Posters.Where(px => px.Language == "en").ToList();
                        }

                        int total   = data.Posters.Posters.Count + data.Posters.Backdrops.Count;
                        int current = 1;

                        string dir = Path.Combine(movieRootDir, "Posters");
                        if (!Directory.Exists(dir) && total > 0)
                        {
                            Directory.CreateDirectory(dir);
                        }

                        ReportCurrent("Posters", current, total, cancellationToken.IsCancellationRequested);

                        // if themoviedb.org is filter in your country! (work, but slow)
                        if (!await Utils.PingAsync("themoviedb.org"))
                        {
                            data.Posters.Posters.ForEach(p => p.Link   = p.Link.Replace("/posters/", "/posters-stream/").Replace("/posters/", "/posters-stream/"));
                            data.Posters.Backdrops.ForEach(p => p.Link = p.Link.Replace("/posters/", "/posters-stream/").Replace("/posters/", "/posters-stream/"));
                        }

                        foreach (var p in data.Posters.Posters)
                        {
                            ReportCurrent("Posters", current, total, cancellationToken.IsCancellationRequested);
                            string filePath = Path.Combine(dir, $"{item.Id}-{index.ToString("000")}.jpg");
                            await Utils.DownloadFileAsync(filePath, p.Link, Program.GetWebProxy());

                            current++;
                            index++;
                        }
                        foreach (var p in data.Posters.Backdrops)
                        {
                            ReportCurrent("Posters", current, total, cancellationToken.IsCancellationRequested);
                            string filePath = Path.Combine(dir, $"{item.Id}-{index.ToString("000")}.jpg");
                            await Utils.DownloadFileAsync(filePath, p.Link, Program.GetWebProxy());

                            current++;
                            index++;
                        }
                        ReportCurrent("...", 1, 1, cancellationToken.IsCancellationRequested);
                    }

                    // IMAGES
                    if (_clientOptions.Images)
                    {
                        ReportCurrent("Images", 1, 1, cancellationToken.IsCancellationRequested);
                        var images = new List <ImageDataDetail>();
                        if (data.Images != null && data.Images.Items != null && _clientOptions.Images_Short)
                        {
                            images = data.Images.Items;
                        }
                        else // options.Image_Full
                        {
                            var imageData = await _apiLib.ImagesAsync(item.Id, "Full");

                            if (string.IsNullOrEmpty(imageData.ErrorMessage))
                            {
                                images = imageData.Items;
                            }
                        }

                        int total        = images.Count;
                        int currentIndex = 1;
                        ReportCurrent("Images", currentIndex, total, cancellationToken.IsCancellationRequested);

                        string dir = Path.Combine(movieRootDir, "Images");
                        if (!Directory.Exists(dir) && total > 0)
                        {
                            Directory.CreateDirectory(dir);
                        }
                        foreach (var img in images)
                        {
                            ReportCurrent("Images", currentIndex, total, cancellationToken.IsCancellationRequested);
                            string filePath = Path.Combine(dir, $"{Utils.RenameToPhisicalName(img.Title)}.jpg");
                            string url      = img.Image;
                            await Utils.DownloadImageAsync(filePath, url, Program.GetWebProxy());

                            currentIndex++;
                        }

                        Utils.RemoveDuplicatedFiles(dir);
                        ReportCurrent("...", 1, 1, cancellationToken.IsCancellationRequested);
                    }

                    // TRAILER
                    if (_clientOptions.Trailer)
                    {
                        ReportCurrent("Trailer", 1, 1, cancellationToken.IsCancellationRequested);

                        var youtubeTrailerData = await _apiLib.YouTubeTrailerAsync(item.Id);

                        if (string.IsNullOrEmpty(youtubeTrailerData.ErrorMessage))
                        {
                            var youtubeData = await _apiLib.YouTubeAsync(youtubeTrailerData.VideoId);

                            if (string.IsNullOrEmpty(youtubeData.ErrorMessage))
                            {
                                var video        = youtubeData.Videos.FirstOrDefault();
                                var trailerBytes = await Utils.DownloadDataAsync(
                                    video.Url,
                                    new ProgressData(progress => ReportCurrent($"Trailer", progress.Current, progress.Total, cancellationToken.IsCancellationRequested, true)),
                                    cancellationToken,
                                    Program.GetWebProxy());

                                if (trailerBytes != null)
                                {
                                    string dir = Path.Combine(movieRootDir, "Trailer");
                                    if (!Directory.Exists(dir))
                                    {
                                        Directory.CreateDirectory(dir);
                                    }

                                    string filePath = Path.Combine(dir, $"{Utils.RenameToPhisicalName(youtubeData.Title).Trim()} - {video.Quality}.{video.Extension}");

                                    await Task.Run(() => File.WriteAllBytes(filePath, trailerBytes));
                                }
                            }
                        }

                        ReportCurrent("...", 1, 1, cancellationToken.IsCancellationRequested);
                    }

                    // EXTERNAL SITES
                    if (_clientOptions.ExternalSites)
                    {
                        ReportCurrent("External Sites", 1, 1, cancellationToken.IsCancellationRequested);

                        string dir = Path.Combine(movieRootDir, "External Sites");
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        // IMDb-API
                        {
                            string filePath = Path.Combine(dir, $"{item.Id} on IMDb-API.url");
                            string content  = $"[InternetShortcut]";
                            content += Environment.NewLine;
                            content += $"URL=https://imdb-api.com/title/{item.Id}";
                            File.WriteAllText(filePath, content);
                        }

                        // IMDb
                        {
                            string filePath = Path.Combine(dir, $"{item.Id} on IMDb.url");
                            string content  = $"[InternetShortcut]";
                            content += Environment.NewLine;
                            content += $"URL=https://www.imdb.com/title/{item.Id}";
                            File.WriteAllText(filePath, content);
                        }

                        var externalSiteData = await _apiLib.ExternalSitesAsync(item.Id);

                        if (string.IsNullOrEmpty(externalSiteData.ErrorMessage))
                        {
                            // TheMovieDb
                            Utils.CreateUrlShortcut(dir, $"{item.Id} on TheMovieDb.url", externalSiteData.TheMovieDb?.Url);

                            // RottenTomatoes
                            Utils.CreateUrlShortcut(dir, $"{item.Id} on RottenTomatoes.url", externalSiteData.RottenTomatoes?.Url);

                            // Metacritic
                            Utils.CreateUrlShortcut(dir, $"{item.Id} on Metacritic.url", externalSiteData.Metacritic?.Url);

                            // Netflix
                            Utils.CreateUrlShortcut(dir, $"{item.Id} on Netflix.url", externalSiteData.Netflix?.Url);

                            // BoxOfficeMojo
                            Utils.CreateUrlShortcut(dir, $"{item.Id} on BoxOfficeMojo.url", externalSiteData.BoxOfficeMojo?.Url);

                            // TheTVDB
                            Utils.CreateUrlShortcut(dir, $"{item.Id} on TheTVDB.url", externalSiteData.TheTVDB?.Url);

                            // TV_com
                            Utils.CreateUrlShortcut(dir, $"{item.Id} on TV_com.url", externalSiteData.TV_com?.Url);

                            // FilmAffinity
                            Utils.CreateUrlShortcut(dir, $"{item.Id} on FilmAffinity.url", externalSiteData.FilmAffinity?.Url);

                            // Wikipedia (en)
                            if (externalSiteData.WikipediaUrls != null)
                            {
                                var enWiki = externalSiteData.WikipediaUrls.FirstOrDefault(wx => wx.Language == "en");
                                Utils.CreateUrlShortcut(dir, $"{item.Id} on Wikipedia [en].url", enWiki?.Url);

                                if (_clientOptions.PlotLanguage != Language.en)
                                {
                                    var plotLangWiki = externalSiteData.WikipediaUrls.FirstOrDefault(wx => wx.Language == _clientOptions.PlotLanguage.ToString().ToLower());
                                    Utils.CreateUrlShortcut(dir, $"{item.Id} on Wikipedia [{_clientOptions.PlotLanguage.ToString().ToLower()}].url", plotLangWiki?.Url);
                                }
                            }
                        }

                        // ACTORS
                        string actorDir = Path.Combine(dir, "Actors");
                        if (!Directory.Exists(actorDir))
                        {
                            Directory.CreateDirectory(actorDir);
                        }
                        foreach (var actor in data.ActorList)
                        {
                            string filePath = Path.Combine(actorDir, $"{Utils.RenameToPhisicalName(actor.Name)} [{actor.Id}].url");
                            string content  = $"[InternetShortcut]";
                            content += Environment.NewLine;
                            content += $"URL=https://imdb-api.com/name/{actor.Id}";
                            File.WriteAllText(filePath, content);
                        }
                    }

                    // Progress
                    ReportTotal(data.FullTitle, totalIndex, _gridDataItems.Count, cancellationToken.IsCancellationRequested);
                    totalIndex++;

                    ReportCurrent("...", 1, 1, cancellationToken.IsCancellationRequested);
                }

                btnCancel.Visible     = false;
                lblTotalProgress.Text = lblCurrent.Text = "done";
                progressTotal.Value   = progressCurrentJob.Value = 100;
                OnCanceled?.Invoke();

                if (ddlWhenDone.Text == "Shutdown [On Successfull]" || ddlWhenDone.Text == "Shutdown [Anyway]")
                {
                    new ShutdownForm().ShowDialog();
                }
            }
            catch (TaskCanceledException ex)
            {
                Canceled();
                if (ddlWhenDone.Text == "Shutdown [Anyway]")
                {
                    new ShutdownForm().ShowDialog();
                }
                else
                {
                    MetroMessageBox.Show(this, ex.Message, "Canceled", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                Canceled();
                if (ddlWhenDone.Text == "Shutdown [Anyway]")
                {
                    new ShutdownForm().ShowDialog();
                }
                else
                {
                    MetroMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public OAuthPropsDialogOverlay(CGRect frame, nfloat transparency, UIColor color, string clientId, string redirectUrl) : base(frame)
        {
            // Create a semi-transparent overlay with the specified background color.
            BackgroundColor = color;
            Alpha           = transparency;

            // Set size and spacing for controls.
            nfloat controlHeight = 25;
            nfloat rowSpace      = 7;
            nfloat lessRowSpace  = 4;
            nfloat buttonSpace   = 15;
            nfloat textViewWidth = 200;
            nfloat buttonWidth   = 60;

            // Find the start x and y for the control layout.
            nfloat controlX = 10;
            nfloat controlY = 10;

            // Label for inputs.
            var description = new UILabel(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Text      = "OAuth Settings",
                TextColor = TintColor
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Client ID text input and label.
            var clientIdLabel = new UILabel(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Text = "Client ID"
            };

            controlY = controlY + controlHeight + lessRowSpace;

            _clientIdTextField = new UITextField(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Placeholder            = "Client ID",
                Text                   = clientId,
                AutocapitalizationType = UITextAutocapitalizationType.None,
                BackgroundColor        = UIColor.LightGray,
                LeftView               = new UIView(new CGRect(0, 0, 5, 20)),
                LeftViewMode           = UITextFieldViewMode.Always
            };

            // Allow pressing 'return' to dismiss the keyboard.
            _clientIdTextField.ShouldReturn += textField =>
            {
                textField.ResignFirstResponder();
                return(true);
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Redirect URL text input and label.
            var redirectLabel = new UILabel(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Text = "Redirect URL"
            };

            controlY = controlY + controlHeight + lessRowSpace;

            _redirectUrlTextField = new UITextField(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Placeholder            = "Redirect URI",
                Text                   = redirectUrl,
                AutocapitalizationType = UITextAutocapitalizationType.None,
                BackgroundColor        = UIColor.LightGray,
                LeftView               = new UIView(new CGRect(0, 0, 5, 20)),
                LeftViewMode           = UITextFieldViewMode.Always
            };

            // Allow pressing 'return' to dismiss the keyboard.
            _redirectUrlTextField.ShouldReturn += textField =>
            {
                textField.ResignFirstResponder();
                return(true);
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Button to save the values.
            UIButton saveButton = new UIButton(new CGRect(controlX, controlY, buttonWidth, controlHeight));

            saveButton.SetTitle("Save", UIControlState.Normal);
            saveButton.SetTitleColor(TintColor, UIControlState.Normal);
            saveButton.TouchUpInside += SaveButtonClick;

            // Adjust the X position for the next control.
            controlX = controlX + buttonWidth + buttonSpace;

            // Button to cancel the save.
            UIButton cancelButton = new UIButton(new CGRect(controlX, controlY, buttonWidth, controlHeight));

            cancelButton.SetTitle("Cancel", UIControlState.Normal);
            cancelButton.SetTitleColor(UIColor.Red, UIControlState.Normal);
            cancelButton.TouchUpInside += (s, e) => OnCanceled.Invoke(this, null);

            // Add the controls.
            AddSubviews(description, clientIdLabel, _clientIdTextField, redirectLabel, _redirectUrlTextField, saveButton, cancelButton);
        }
 public void ActionCanceled()
 {
     OnCanceled?.Invoke();
 }
        public SearchMapsDialogOverlay(CGRect frame, nfloat transparency, UIColor color) : base(frame)
        {
            // Create a semi-transparent overlay with the specified background color.
            BackgroundColor = color;
            Alpha           = transparency;

            // Set size and spacing for controls.
            nfloat controlHeight = 25;
            nfloat rowSpace      = 11;
            nfloat buttonSpace   = 15;
            nfloat textViewWidth = Frame.Width - 60;
            nfloat buttonWidth   = 60;

            // Find the start x and y for the control layout.
            nfloat controlX = 5;
            nfloat controlY = 5;

            // Label for inputs.
            var description = new UILabel(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Text      = "Search web maps",
                TextColor = UIColor.Black
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Title text input.
            _searchTextField = new UITextField(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Placeholder            = "Search text",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                BackgroundColor        = UIColor.LightGray,
                LeftView     = new UIView(new CGRect(0, 0, 5, 20)),
                LeftViewMode = UITextFieldViewMode.Always
            };

            // Allow pressing 'return' to dismiss the keyboard.
            _searchTextField.ShouldReturn += textField =>
            {
                textField.ResignFirstResponder();
                return(true);
            };

            // Hide the keyboard when "Enter" is clicked.
            _searchTextField.ShouldReturn += input =>
            {
                input.ResignFirstResponder();
                return(true);
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Button to pass the text to the search.
            UIButton saveButton = new UIButton(new CGRect(controlX, controlY, buttonWidth, controlHeight));

            saveButton.SetTitle("Search", UIControlState.Normal);
            saveButton.SetTitleColor(TintColor, UIControlState.Normal);
            saveButton.TouchUpInside += SearchButtonClick;

            // Adjust the X position for the next control (space between buttons).
            controlX = controlX + buttonWidth + buttonSpace;

            // Button to cancel the search.
            UIButton cancelButton = new UIButton(new CGRect(controlX, controlY, buttonWidth, controlHeight));

            cancelButton.SetTitle("Cancel", UIControlState.Normal);
            cancelButton.SetTitleColor(UIColor.Red, UIControlState.Normal);
            cancelButton.TouchUpInside += (s, e) => { OnCanceled.Invoke(this, null); };

            // Add the controls.
            AddSubviews(description, _searchTextField, saveButton, cancelButton);
        }
        public LoadingMapOverlay(CGRect frame, bool showProgress) : base(frame)
        {
            // Semi-transparent black background.
            BackgroundColor  = UIColor.Black;
            Alpha            = 0.8f;
            AutoresizingMask = UIViewAutoresizing.All;

            // Find the center for positioning UI elements.
            nfloat centerX = Frame.Width / 2;
            nfloat centerY = Frame.Height / 2;

            // If showing progress, add a progress bar.
            if (showProgress)
            {
                _progress = new UIProgressView(UIProgressViewStyle.Bar);

                _progress.Frame = new CGRect(
                    centerX - _progress.Frame.Width / 2,
                    centerY - _progress.Frame.Height - 20,
                    _progress.Frame.Width,
                    _progress.Frame.Height);

                _progress.AutoresizingMask = UIViewAutoresizing.All;
                AddSubview(_progress);
                _progress.Progress = 0.0f;
            }
            else
            {
                // Otherwise, show an activity indicator (spinner).
                UIActivityIndicatorView activitySpinner = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge);
                activitySpinner.Frame = new CGRect(
                    centerX - activitySpinner.Frame.Width / 2,
                    centerY - activitySpinner.Frame.Height - 20,
                    activitySpinner.Frame.Width,
                    activitySpinner.Frame.Height);
                activitySpinner.AutoresizingMask = UIViewAutoresizing.All;
                AddSubview(activitySpinner);
                activitySpinner.StartAnimating();
            }

            // Add a label to describe what's loading.
            _label = new UILabel(new CGRect(
                                     centerX - (Frame.Width - 20) / 2,
                                     centerY + 20,
                                     Frame.Width - 20,
                                     22
                                     ))
            {
                BackgroundColor  = UIColor.Clear,
                TextColor        = UIColor.White,
                Text             = "--",
                TextAlignment    = UITextAlignment.Center,
                AutoresizingMask = UIViewAutoresizing.All
            };
            AddSubview(_label);

            // Add a button that allows the user to cancel the task.
            UIButton cancelButton = new UIButton(UIButtonType.Plain);

            cancelButton.SetTitle("Cancel", UIControlState.Normal);
            cancelButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            cancelButton.Frame = new CGRect(
                centerX - (Frame.Width - 20) / 2,
                centerY + 50,
                Frame.Width - 20,
                30);
            cancelButton.TouchUpInside += (s, e) =>
            {
                // Raise the OnCanceled event so the task can be canceled.
                OnCanceled?.Invoke(this, null);
            };
            AddSubview(cancelButton);
        }
        public SaveMapDialogOverlay(CGRect frame, nfloat transparency, UIColor color, PortalItem mapItem) : base(frame)
        {
            // Store any existing portal item (for "update" versus "save", e.g.).
            var portalItem = mapItem;

            // Create a semi-transparent overlay with the specified background color.
            BackgroundColor = color;
            Alpha           = transparency;

            // Set size and spacing for controls.
            nfloat controlHeight = 25;
            nfloat rowSpace      = 11;
            nfloat buttonSpace   = 15;
            nfloat textViewWidth = Frame.Width - 60;
            nfloat buttonWidth   = 60;

            // Get the total height and width of the control set (five rows of controls, four sets of space).
            nfloat totalHeight = 5 * controlHeight + 4 * rowSpace;
            nfloat totalWidth  = textViewWidth;

            // Find the center x and y of the view.
            nfloat centerX = Frame.Width / 2;
            nfloat centerY = Frame.Height / 2;

            // Find the start x and y for the control layout.
            nfloat controlX = centerX - totalWidth / 2;
            nfloat controlY = centerY - totalHeight / 2;

            // Label for inputs.
            var description = new UILabel(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Text      = "Portal item info",
                TextColor = UIColor.Black
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Title text input.
            _titleTextField = new UITextField(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Placeholder            = "Title",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                BackgroundColor        = UIColor.LightGray,
                LeftView     = new UIView(new CGRect(0, 0, 5, 20)),
                LeftViewMode = UITextFieldViewMode.Always
            };
            // Allow pressing 'return' to dismiss the keyboard.
            _titleTextField.ShouldReturn += textField =>
            {
                textField.ResignFirstResponder();
                return(true);
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Description text input.
            _descriptionTextField = new UITextField(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Placeholder            = "Description",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                BackgroundColor        = UIColor.LightGray,
                LeftView     = new UIView(new CGRect(0, 0, 5, 20)),
                LeftViewMode = UITextFieldViewMode.Always
            };

            // Allow pressing 'return' to dismiss the keyboard.
            _descriptionTextField.ShouldReturn += textField =>
            {
                textField.ResignFirstResponder();
                return(true);
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Tags text input.
            _tagsTextField = new UITextField(new CGRect(controlX, controlY, textViewWidth, controlHeight))
            {
                Text = "ArcGIS Runtime, Web Map",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                BackgroundColor        = UIColor.LightGray,
                LeftView     = new UIView(new CGRect(0, 0, 5, 20)),
                LeftViewMode = UITextFieldViewMode.Always
            };

            // Allow pressing 'return' to dismiss the keyboard.
            _tagsTextField.ShouldReturn += textField =>
            {
                textField.ResignFirstResponder();
                return(true);
            };

            // Adjust the Y position for the next control.
            controlY = controlY + controlHeight + rowSpace;

            // Button to save the map.
            UIButton saveButton = new UIButton(new CGRect(controlX, controlY, buttonWidth, controlHeight));

            saveButton.SetTitle("Save", UIControlState.Normal);
            saveButton.SetTitleColor(TintColor, UIControlState.Normal);
            saveButton.TouchUpInside += SaveButtonClick;

            // Adjust the X position for the next control.
            controlX = controlX + buttonWidth + buttonSpace;

            // Button to cancel the save.
            UIButton cancelButton = new UIButton(new CGRect(controlX, controlY, buttonWidth, controlHeight));

            cancelButton.SetTitle("Cancel", UIControlState.Normal);
            cancelButton.SetTitleColor(UIColor.Red, UIControlState.Normal);
            cancelButton.TouchUpInside += (s, e) => { OnCanceled.Invoke(this, null); };

            // Add the controls.
            AddSubviews(description, _titleTextField, _descriptionTextField, _tagsTextField, saveButton, cancelButton);

            // If there's an existing portal item, configure the dialog for "update" (read-only entries).
            if (portalItem != null)
            {
                _titleTextField.Text    = portalItem.Title;
                _titleTextField.Enabled = false;

                _descriptionTextField.Text    = portalItem.Description;
                _descriptionTextField.Enabled = false;

                _tagsTextField.Text    = string.Join(",", portalItem.Tags);
                _tagsTextField.Enabled = false;

                // Change the button text.
                saveButton.SetTitle("Update", UIControlState.Normal);
            }
        }
 private void Cancel()
 {
     OnCanceled?.Invoke(this, EventArgs.Empty);
 }