Exemple #1
0
        private void PrevConfirmed()
        {
            ExceptionUtility.Try(() =>
            {
                this._device.Preving = true;
                this.SetButtonMode(this._prevButton, this._prevButtonSpinner, true);
                ProgressUtility.SafeShow(this._prevFeature.ProgressText, () =>
                {
                    if (this._stopNextPrevType == StopNextPrevType.Irrigations)
                    {
                        ServiceContainer.DeviceService.PrevIrrigations(this.Device.Device, this.HandleUpdatesForPrev).ContinueWith((r) =>
                        {
                            MainThreadUtility.InvokeOnMain(() =>
                            {
                                ProgressUtility.Dismiss();
                            });
                        });
                    }
                    else if (this._stopNextPrevType == StopNextPrevType.Circuits)
                    {
                        //Nothing to do here!
                    }

                    if (this.OnStopClicked != null)
                    {
                        this.OnStopClicked();
                    }
                });
            });
        }
Exemple #2
0
 private void OnAlertsCountChanged(NSNotification notification)
 {
     MainThreadUtility.InvokeOnMain(() =>
     {
         this.SetAlertsButtonImage();
     });
 }
Exemple #3
0
        private void HandleUpdatesForPrev(ProgressResponse response)
        {
            MainThreadUtility.InvokeOnMain(() =>
            {
                if (response != null)
                {
                    DataCache.AddCommandProgress(new CommandProgress(CommandType.DevicePrev, response.Body));

                    if (response.IsFinal)
                    {
                        this.Device.Preving = false;
                        this.SetButtonMode(this._prevButton, this._prevButtonSpinner, false);

                        if (response.IsSuccessful)
                        {
                        }
                        else
                        {
                            if ((bool)!response?.IsReconnectResponse && (bool)!response?.IsServerDownResponse)
                            {
                                AlertUtility.ShowAppError(response?.ErrorBody);
                            }
                        }
                    }
                }

                AlertUtility.ShowProgressResponse(this._prevFeature.ProgressText, response);
            });
        }
Exemple #4
0
        public ProgressWidget(int dotCount) : base()
        {
            this._imageViews = new UIImageView[dotCount];

            ExceptionUtility.Try(() =>
            {
                for (int n = 0; n < this._imageViews.Length; n++)
                {
                    this._imageViews[n]             = new UIImageView(GraphicsUtility.CreateColoredCircle(Colors.StandardTextColor, DotSize));
                    this._imageViews[n].ContentMode = UIViewContentMode.Center;
                    this._imageViews[n].MakeRoundedCorners(UIRectCorner.AllCorners, DotSize / 2);
                    this.SetNormalDotState(this._imageViews[n]);
                    this.AddSubview(this._imageViews[n]);
                    this.SetNormalDotState(this._imageViews[n]);
                }

                this._animationTimer.Elapsed += (sender, e) =>
                {
                    if (this._animationRunning)
                    {
                        this._animationTimer.Enabled = false;
                        MainThreadUtility.InvokeOnMain(() =>
                        {
                            this._currentDotIndex = 0;
                            this.AnimateDotLarge();
                        });
                    }
                };

                this._animationTimer.Interval = 2000;
            });
        }
        private void NavigateToDeviceDetails(DeviceViewModel device)
        {
            try
            {
                ProgressUtility.SafeShow("Getting Device Details", async() =>
                {
                    var response = await ServiceContainer.DeviceService.RequestDevice(device.Device, () => { NavigateToDeviceDetails(device); });

                    MainThreadUtility.InvokeOnMain(() =>
                    {
                        if (response != null && response.IsSuccessful)
                        {
                            var d = response.Body.Devices.Items.FirstOrDefault().Value;
                            if (d == null)
                            {
                                ProgressUtility.Dismiss();
                                AlertUtility.ShowErrorAlert(StringLiterals.Error, StringLiterals.DeviceNotFoundErrorTitle);
                            }
                            else
                            {
                                this.Predecessor = null;
                                ProgressUtility.Dismiss();
                                this.NavigateTo(DeviceDetailsViewController.CreateInstance(d.Id));
                            }
                        }
                    });
                });
            }
            catch (Exception e)
            {
                LogUtility.LogException(e);
            }
        }
 private void StopStartProgram(ProgramViewModel program, bool start)
 {
     MainThreadUtility.InvokeOnMain(() =>
     {
         this.NavigateTo(ProgramRepeatSelectViewController.CreateInstance(this.Device?.Id, start, program));
     });
 }
        private void HandleUpdatesForStopStartProgram(ProgressResponse response, ProgramViewModel program, bool start)
        {
            MainThreadUtility.InvokeOnMain(() =>
            {
                if (response != null)
                {
                    DataCache.AddCommandProgress(new CommandProgress(CommandType.StartPrograms, response.Body, new string[] { program.Id }));

                    if (response.IsFinal)
                    {
                        Action resetProgram = () =>
                        {
                            program.Starting = false;
                            //ServiceContainer.DeviceService.RequestDevice(this.Device.Device);
                        };

                        if (response.IsSuccessful)
                        {
                            //AlertUtility.ShowProgressResponse("Stop/Start Program " + program.Id, response);
                            this.RegisterForAsyncUpdate(resetProgram, 5000);
                        }
                        else
                        {
                            this.RegisterForAsyncUpdate(resetProgram);

                            if ((bool)!response?.IsReconnectResponse && (bool)!response?.IsServerDownResponse)
                            {
                                AlertUtility.ShowAppError(response?.ErrorBody);
                            }
                        }
                    }
                }
            });
        }
        private async Task LogoutInternal()
        {
            try
            {
                ConnectionManager.Deinitialize();
                await ServiceContainer.UserService.LogOut();

                Caches.ClearCachesForLogout();

            #if DEBUG
                //User.Current.Password = password;
            #endif
                User.Current.Save();

                MainThreadUtility.InvokeOnMain(() =>
                {
                    ProgressUtility.Dismiss();
                    this.LoadData();
                    LogUtility.Enabled = false;
                });
            }
            catch (Exception e)
            {
                LogUtility.LogException(e);
            }
        }
Exemple #9
0
        private void RetryConnection()
        {
            ProgressUtility.SafeShow("Connecting", () =>
            {
                WebSocketsClient.ResetWebSocketsClientUrl(new WebSocketsClientIos(), User.Current.ServerUri);
                ConnectionManager.Initialize();

                ServiceContainer.UserService.RequestConnection(User.Current.Username, User.Current.Password).ContinueWith((r) =>
                {
                    MainThreadUtility.InvokeOnMain(() =>
                    {
                        ProgressUtility.Dismiss();

                        if (r.Result != null && r.Result.IsSuccessful)
                        {
                            this.NavigateHome();
                        }
                        //else {
                        //	if (r.Result.HasError)
                        //		AlertUtility.ShowAppError(r.Result?.ErrorBody);
                        //}
                    });
                });
            }, true);
        }
 public void ShowError(ConnectionResponse response, bool showError = false)
 {
     if (response != null)
     {
         if (!response.IsSuccessful)
         {
             if (response.HasError)
             {
                 if (showError)
                 {
                     MainThreadUtility.InvokeOnMain(() => {
                         //AlertUtility.ShowAppError(response.ErrorBody);
                     });
                 }
             }
             else
             {
                 this.ShowError(StringLiterals.ConnectionError);
             }
         }
     }
     else
     {
         this.ShowError(StringLiterals.ConnectionError);
     }
 }
 public void SetText(string text)
 {
     MainThreadUtility.InvokeOnMain(() => {
         this._infoLabel.Text = text;
         this._infoLabel.SizeToFit();
     });
 }
Exemple #12
0
        public void SetTextAndMode(string text, DisplayMode displayMode)
        {
            MainThreadUtility.InvokeOnMain(() => {
                //if text null, get default text for mode
                switch (displayMode)
                {
                case DisplayMode.Reconnecting:
                    if (String.IsNullOrEmpty(text))
                    {
                        text = Aquamonix.Mobile.Lib.Domain.StringLiterals.Reconnecting;
                    }
                    break;

                case DisplayMode.ServerDown:
                    if (String.IsNullOrEmpty(text))
                    {
                        text = Aquamonix.Mobile.Lib.Domain.StringLiterals.ServerNotAvailable;
                    }
                    break;

                case DisplayMode.Connected:
                    if (String.IsNullOrEmpty(text))
                    {
                        text = Aquamonix.Mobile.Lib.Domain.StringLiterals.Connected;
                    }
                    break;
                }

                //set background color
                this.BackgroundColor = GraphicsUtility.ColorForReconBar(displayMode);;

                //and set text
                this.SetText(text);
            });
        }
Exemple #13
0
        protected virtual void ShowReconBar(string text = null)
        {
            MainThreadUtility.InvokeOnMain(() =>
            {
                //if reconnecting view has been disposed, take care of it
                if (this.ReconBar.IsDisposed)
                {
                    try { this.ReconBar.RemoveFromSuperview(); }
                    catch (Exception) { }
                    this.ReconBar = new ReconnectingView(this);
                }

                if (String.IsNullOrEmpty(text))
                {
                    text = StringLiterals.Reconnecting;
                }

                ReconnectingView.DisplayMode displayMode = ReconnectingView.DisplayMode.Reconnecting;
                if (ConnectionManager.State.IsDead)
                {
                    displayMode = ReconnectingView.DisplayMode.ServerDown;
                    text        = StringLiterals.ServerNotAvailable;
                }

                this.ReconBar.SetFrameSize(this.PrimeView.Frame.Width, ReconnectingView.Height);
                this.ReconBar.SetFrameLocation(0, this.ReconBarVerticalLocation);
                this.ReconBar.UserInteractionEnabled = false;
                this.PrimeView.AddSubview(this.ReconBar);
                this.ReconBar.SetTextAndMode(text, displayMode);
                this.PrimeView.BringSubviewToFront(this.ReconBar);

                this.AfterShowReconBar();
            });
        }
 private void OnConnectionStateChanged(NSNotification notification)
 {
     MainThreadUtility.InvokeOnMain(() =>
     {
         this.SetText(ConnectionManager.State.ToString());
     });
 }
Exemple #15
0
        public virtual void NavigateAlerts()
        {
            ExceptionUtility.Try(() =>
            {
                LogUtility.LogMessage("Navigating to Alerts");

                if (User.Current != null && User.Current.HasConfig && DataCache.HasDevices)
                {
                    ProgressUtility.SafeShow("Getting Alerts", () =>
                    {
                        var devices = DataCache.GetAllDevicesFromCache();
                        ServiceContainer.AlertService.RequestGlobalAlerts(devices.Select((d) => d.Id), NavigateAlerts).ContinueWith((r) =>
                        {
                            MainThreadUtility.InvokeOnMain(() =>
                            {
                                ProgressUtility.Dismiss();

                                if (r.Result != null && r.Result.IsSuccessful)
                                {
                                    this.NavigateTo(GlobalAlertListViewController.CreateInstance(), inCurrentNavController: false);
                                }
                                //else {
                                //    AlertUtility.ShowAppError(r.Result?.ErrorBody);
                                //}
                            });
                        });
                    }, true);
                }
            });
        }
Exemple #16
0
 public void SetText(string text)
 {
     MainThreadUtility.InvokeOnMain(() => {
         this._messageLabel.Text = text;
         this._messageLabel.SizeToFit();
         this._messageLabel.CenterInParent();
     });
 }
Exemple #17
0
 public void StopAnimation()
 {
     MainThreadUtility.InvokeOnMain(() =>
     {
         this._animationTimer.Stop();
         this._animationTimer.Enabled = false;
         this._animationRunning       = false;
     });
 }
Exemple #18
0
 /// <summary>
 /// Hide the progress spinner
 /// </summary>
 private static void HideProgress()
 {
     if (_showingProgress)
     {
         MainThreadUtility.InvokeOnMain(() => {
             ProgressUtility.Dismiss();
         });
         _showingProgress = false;
     }
 }
Exemple #19
0
 /// <summary>
 /// Display a progress spinner
 /// </summary>
 private static void ShowProgress()
 {
     if (!_showingProgress)
     {
         MainThreadUtility.InvokeOnMain(() => {
             ProgressUtility.Show("Reconnecting...");
         });
         _showingProgress = true;
     }
 }
        private void WaterSelectedStationsConfirmed(IEnumerable <PumpViewModel> pumps, int durationMinutes)
        {
            ExceptionUtility.Try(() =>
            {
                IEnumerable <string> stationNames, stationNumbers;
                this.GetSelectedStationsList(out stationNames, out stationNumbers);
                var selectedStationIds = this.Device.Stations.Where((s) => s.Selected).Select((s) => s.Id);

                var pumpIds = new List <string>();
                if (pumps != null)
                {
                    pumpIds = pumps.Select((p) => p.Id)?.ToList();
                }

                this._buttonFooterView.PermaDisabled = true;
                this._selectionHeaderView.Enabled    = false;

                ProgressUtility.SafeShow("Starting Stations", () =>
                {
                    var selectedIdsArray = selectedStationIds.ToArray();
                    Action <ProgressResponse> callbackHandler = ((p) =>
                    {
                        this.HandleUpdatesForStartStations(p, pumps, durationMinutes, selectedIdsArray);
                    });


                    ServiceContainer.StationService.StartStations(
                        this.Device.Device,
                        selectedStationIds,
                        pumpIds,
                        durationMinutes,
                        handleUpdates: callbackHandler,
                        onReconnect: () => { this.WaterSelectedStationsConfirmed(pumps, durationMinutes); }).ContinueWith((r) =>
                    {
                        MainThreadUtility.InvokeOnMain(() =>
                        {
                            this._tableViewController.UpdateStationCells((s) =>
                            {
                                bool selected = s.Selected;
                                if (selected)
                                {
                                    s.Starting = true;
                                    s.Selected = false;
                                }

                                return(selected);
                            });

                            this._selectionHeaderView.Enabled = true;
                            ProgressUtility.Dismiss();
                        });
                    });
                }, blockUI: true);
            });
        }
        /*
         * protected override void AdjustTableForReconBar(TableViewControllerBase tableVc, bool show)
         * {
         *  if (tableVc.AllRowsVisible.HasValue)
         *  {
         *      if (tableVc.AllRowsVisible.Value)
         *      {
         *          /*
         *          var tableView = tableVc.TableView;
         *          var tableFrame = tableView.Frame;
         *          //_tableViewController.TableView.ContentInset = new UIEdgeInsets(50, 0, 0, 0);
         *          //tableView.Frame = new CoreGraphics.CGRect(tableFrame.Location, new CoreGraphics.CGSize(tableFrame.Width, 900));
         *          if (!tableView.ScrollEnabled)
         *             tableView.ScrollEnabled = true;
         *          if (!tableView.AlwaysBounceVertical)
         *              tableView.AlwaysBounceVertical = true;
         *          //tableView.ContentOffset = new CoreGraphics.CGPoint(0, 50);
         *          tableView.ContentSize = new CoreGraphics.CGSize(tableView.ContentSize.Width,200);
         */
        /*
         * var tableView = tableVc.TableView;
         * //tableView.SetFrameY(200);
         *
         * //TODO: adjust for if it goes past bottom of screen  (1)
         * }
         * else
         * {
         * base.AdjustTableForReconBar(tableVc, show);
         * }
         * }
         * }
         */


        protected override void OnReconnected()
        {
            base.OnReconnected();

            MainThreadUtility.InvokeOnMain(() =>
            {
                if (this.IsShowing)
                {
                    this.DoLoadData(true);
                }
            });
        }
        private void HandleUpdatesForTestStations(ProgressResponse response, string[] stationIds)
        {
            MainThreadUtility.InvokeOnMain(() =>
            {
                if (response != null)
                {
                    DataCache.AddCommandProgress(new CommandProgress(CommandType.TestStations, response.Body, stationIds));

                    if (response.IsFinal)
                    {
                        Action resetStations = () =>
                        {
                            foreach (string id in stationIds)
                            {
                                var station = this.Device?.Device?.Stations.Values.Where((d) => d.Id == id).FirstOrDefault();
                                if (station != null)
                                {
                                    station.Selected = false;
                                    station.Starting = false;
                                }
                            }
                        };

                        if (response.IsSuccessful)
                        {
                            //AlertUtility.ShowAlert("Testing Stations", "Testing Stations");
                            this.RegisterForAsyncUpdate(resetStations, 5000);
                        }
                        else
                        {
                            this.RegisterForAsyncUpdate(resetStations);

                            if ((bool)!response?.IsReconnectResponse && (bool)!response?.IsServerDownResponse)
                            {
                                AlertUtility.ShowAppError(response?.ErrorBody);
                            }
                        }

                        DataCache.TriggerDeviceUpdate(this.DeviceId);

                        int countSelected = Device.Stations.Where((s) => s.Selected).Count();
                        this._buttonFooterView.PermaDisabled = false;
                        this.ShowHideButtonFooter(countSelected);
                        this._selectionHeaderView.Enabled = true;

                        /*
                         *                      this.LoadData();
                         */
                    }
                }
            });
        }
Exemple #23
0
        protected virtual void HideReconBar()
        {
            MainThreadUtility.InvokeOnMain(async() =>
            {
                this.ReconBar.SetTextAndMode(null, ReconnectingView.DisplayMode.Connected);

                await Task.Delay(1500);
                MainThreadUtility.InvokeOnMain(() => {
                    this.ReconBar.RemoveFromSuperview();
                    this.AfterHideReconBar();
                });
            });
        }
Exemple #24
0
 public void StartAnimation()
 {
     MainThreadUtility.InvokeOnMain(() =>
     {
         if (!this._animationRunning)
         {
             this._animationRunning = true;
             this.CenterDots();
             this._animationTimer.Enabled = true;
             this._animationTimer.Start();
         }
     });
 }
        private void HandleUpdatesForStartCircuits(ProgressResponse response, string[] circuitIds, int durationMinutes)
        {
            MainThreadUtility.InvokeOnMain(() =>
            {
                if (response != null)
                {
                    DataCache.AddCommandProgress(new CommandProgress(CommandType.StartCircuits, response.Body, circuitIds));

                    if (response.IsFinal)
                    {
                        Action resetCircuits = () =>
                        {
                            foreach (string id in circuitIds)
                            {
                                var circuit = this.Device?.Device?.Circuits.Values.Where((d) => d.Id == id).FirstOrDefault();
                                if (circuit != null)
                                {
                                    circuit.Selected = false;
                                    circuit.Starting = false;
                                }
                            }
                        };

                        if (response.IsSuccessful)
                        {
                            //AlertUtility.ShowAlert("Start Circuits", "Start Circuits");
                            this.RegisterForAsyncUpdate(resetCircuits, 5000);
                        }
                        else
                        {
                            this.RegisterForAsyncUpdate(resetCircuits);

                            if ((bool)!response?.IsReconnectResponse && (bool)!response?.IsServerDownResponse)
                            {
                                AlertUtility.ShowAppError(response?.ErrorBody);
                            }
                        }

                        DataCache.TriggerDeviceUpdate(this.DeviceId);

                        int countSelected = Device.Circuits.Where((s) => s.Selected).Count();
                        this._buttonFooterView.PermaDisabled = false;
                        this.ShowHideButtonFooter(countSelected > 0);
                        this._selectionHeaderView.Enabled = true;
                    }
                }

                AlertUtility.ShowProgressResponse("Start Circuits", response);
            });
        }
        protected override void OnReconnected()
        {
            base.OnReconnected();

            MainThreadUtility.InvokeOnMain(() =>
            {
                if (this.IsShowing)
                {
                    if (this.Device?.Device != null)
                    {
                        ServiceContainer.DeviceService.RequestDevice(this.Device.Device, silentMode: true);
                    }
                }
            });
        }
        protected void DoLoadData(bool reloadFromServer)
        {
            ExceptionUtility.Try(() =>
            {
                this._allDevices = null;
                base.DoLoadData();

                this._navBarView.Refresh();

                if (User.Current != null)
                {
                    Action doLoad = () =>
                    {
                        MainThreadUtility.InvokeOnMain(() =>
                        {
                            if (this._searchBoxView.Text.Length > 0)
                            {
                                this.DoSearch(this._searchBoxView.Text);
                            }
                            else
                            {
                                _tableViewController.LoadData(this.AllDevices);
                            }
                        });
                    };

                    if (this.CallDeviceBriefs || reloadFromServer)
                    {
                        ProgressUtility.SafeShow("Refreshing Device List", () =>
                        {
                            ServiceContainer.DeviceService.RequestDeviceBriefs(this.AllDevices.Select(d => d.Id)).ContinueWith((r) =>
                            {
                                ProgressUtility.Dismiss();
                                this._allDevices = null;
                                doLoad();
                            });
                        });
                    }
                    else
                    {
                        doLoad();
                    }

                    _tableViewController.TableViewSource.NavigateToDeviceDetails = NavigateToDeviceDetails;
                }
                this.HandleViewDidLayoutSubviews();
            });
        }
            public void SetSettingValue(UITableView tableView, ConfigSettingType type, string value)
            {
                for (int n = 0; n < this.Values.Count; n++)
                {
                    if (this.Values[n].Type == type)
                    {
                        this.Values[n].CurrentValue = value;

                        MainThreadUtility.InvokeOnMain(() =>
                        {
                            this.GetCellInternal(tableView, NSIndexPath.FromRowSection(n, 0));
                        });
                        break;
                    }
                }
            }
Exemple #29
0
        public virtual void NavigateTo(UIViewController viewController, bool inCurrentNavController = true, bool animated = true)
        {
            LogUtility.LogMessage("Navigating to " + viewController.GetType().Name);

            MainThreadUtility.InvokeOnMain(() =>
            {
                this.WillNavigateAway(viewController);
                if (inCurrentNavController)
                {
                    this.NavigationController.PushViewController(viewController, animated);
                }
                else
                {
                    PresentViewController(new AquamonixNavController(viewController), animated, null);
                }
            });
        }
Exemple #30
0
        private void StopStartProgramConfirmed(ProgramViewModel program, bool start)
        {
            ExceptionUtility.Try(() =>
            {
                program.Starting = true;
                var c            = this._tableViewController.GetCell(program) as ProgramListTableViewCell;
                c.LoadCellValues(program);

                if (start)
                {
                    ProgressUtility.SafeShow("Starting Programs", () =>
                    {
                        ServiceContainer.ProgramService.StartProgram(
                            this.Device.Device,
                            program.Id,
                            handleUpdates: (r) => { this.HandleUpdatesForStopStartProgram(r, program, start); },
                            onReconnect: () => { StopStartProgramConfirmed(program, start); }).ContinueWith((r) =>
                        {
                            MainThreadUtility.InvokeOnMain(() =>
                            {
                                ProgressUtility.Dismiss();
                            });
                        });
                    }, blockUI: true);
                }
                else
                {
                    ProgressUtility.SafeShow("Stopping Programs", () =>
                    {
                        ServiceContainer.ProgramService.StopProgram(
                            this.Device.Device,
                            program.Id,
                            handleUpdates: (r) => { this.HandleUpdatesForStopStartProgram(r, program, start); },
                            onReconnect: () => { StopStartProgramConfirmed(program, start); }).ContinueWith((r) =>
                        {
                            MainThreadUtility.InvokeOnMain(() =>
                            {
                                ProgressUtility.Dismiss();
                            });
                        });
                    }, blockUI: true);
                }
            });
        }