Beispiel #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();
                    }
                });
            });
        }
Beispiel #2
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);
                }
            });
        }
 private void Logout()
 {
     ProgressUtility.SafeShow("Logging Out", async() =>
     {
         await LogoutInternal();
     });
 }
        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);
            }
        }
Beispiel #5
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);
        }
        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 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();
            });
        }
Beispiel #8
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);
                }
            });
        }
        private void TestSelectedCircuitsConfirmed(int durationMinutes)
        {
            ExceptionUtility.Try(() =>
            {
                this._buttonFooterView.PermaDisabled = true;
                this._selectionHeaderView.Enabled    = false;
                var selectedCircuitIds = this.Device.Circuits.Where((c) => c.Selected).Select((c) => c.Id);

                ProgressUtility.SafeShow("Testing Circuits", () =>
                {
                    var selectedIdsArray = selectedCircuitIds.ToArray();
                    Action <ProgressResponse> callbackHandler = ((p) =>
                    {
                        this.HandleUpdatesForStartCircuits(p, selectedIdsArray, durationMinutes);
                    });

                    ServiceContainer.CircuitService.StartCircuits(
                        this.Device.Device,
                        selectedCircuitIds,
                        durationMinutes,
                        handleUpdates: callbackHandler,
                        onReconnect: () => { this.TestSelectedCircuitsConfirmed(durationMinutes); }).ContinueWith((r) =>
                    {
                        MainThreadUtility.InvokeOnMain(() =>
                        {
                            this._tableViewController.UpdateCircuitCells((c) =>
                            {
                                bool selected = c.Selected;
                                if (selected)
                                {
                                    c.Starting = true;
                                    c.Selected = false;
                                }

                                return(selected);
                            });
                            this._selectionHeaderView.Enabled = true;
                            ProgressUtility.Dismiss();
                        });
                    });
                }, blockUI: true);
            });
        }
        private void StopStartProgramConfirmed(ProgramViewModel program, bool start)
        {
            try
            {
                if (this.Device?.Device != null)
                {
                    program.Starting = true;

                    if (start)
                    {
                        ProgressUtility.SafeShow("Starting Programs", () =>
                        {
                            ServiceContainer.ProgramService.StartPivotProgram(this.Device.Device, _programStart.Id, _selectedRepeats,
                                                                              handleUpdates: (r) => { this.HandleUpdatesForStopStartProgram(r, program, start); },
                                                                              onReconnect: () => { StopStartProgramConfirmed(program, start); }).ContinueWith((r) =>
                            {
                                MainThreadUtility.InvokeOnMain(() =>
                                {
                                    ProgressUtility.Dismiss();
                                    Device.Device.Programs.CurrentProgramId = _programStart.Id;
                                    DataCache.CurrentProgramId = Convert.ToInt32(_programStart.Id);
                                    this.NavigationController?.PopViewController(true);
                                });
                            });
                        }, blockUI: true);
                    }
                }
                else
                {
                    LogUtility.LogMessage("Cannot start pivot program because device is null");
                }
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                ProgressUtility.Dismiss();
                Device.Device.Programs.CurrentProgramId = _programStart.Id;
                this.NavigationController.PopViewController(true);
                System.Diagnostics.Debug.WriteLine("Error " + ex.Message);
                this.NavigationController.PopViewController(true);
            }
        }
        private async void SubmitForm()
        {
            try
            {
                _connectingManually = true;

                if (this._navBarView.DoneButtonEnabled)
                {
                    //var oldUsername = User.Current?.Username;
                    //var oldPassword = User.Current?.Password;
                    //var oldServerUri = User.Current?.ServerUri;

                    var username  = this._tableViewController.Username;
                    var password  = this._tableViewController.Password;
                    var serverUri = this._tableViewController.ServerUri;

                    //set default if no server uri provided
                    if (String.IsNullOrEmpty(serverUri))
                    {
                        serverUri = AppSettings.GetAppSettingValue(AppSettings.DefaultAppServerUriAppSettingName, String.Empty);
                        this._tableViewController.ServerUri = serverUri;
                    }

                    //translate server alias to a uri
                    serverUri = ServerAliases.AliasToUri(serverUri);

                    bool newUser   = false;
                    bool newServer = false;

                    if (User.Current == null)
                    {
                        User.Current = new User();
                    }
                    else
                    {
                        //check if current user is different from prev user
                        newUser   = ((User.Current.Username != null) && User.Current.Username.Trim().ToLower() != username.Trim().ToLower());
                        newServer = ((User.Current.ServerUri != null) && User.Current.ServerUri.Trim().ToLower() != serverUri.Trim().ToLower());
                    }

                    if (newServer || newUser)
                    {
                        await this.LogoutInternal();
                    }

                    User.Current.Username  = username;
                    User.Current.Password  = password;
                    User.Current.ServerUri = serverUri;

                    if (User.Current != null)
                    {
                        await ProgressUtility.SafeShow("Connecting to Server", async() =>
                        {
                            //if reconnect process is running, cancel it
                            if (ConnectionManager.IsReconnecting)
                            {
                                await ConnectionManager.CancelReconnecting();
                            }

                            //here, if we are voluntarily connecting to a new server or new user, we must suppress the automatic reconnect attempt on closing connection
                            if (newUser || newServer)
                            {
                                ConnectionManager.Deinitialize();
                            }

                            WebSocketsClient.ResetWebSocketsClientUrl(new WebSocketsClientIos(), serverUri);
                            ConnectionManager.Initialize();

                            var deviceListVc = DeviceListViewController.CreateInstance();

                            //test connection
                            var response = await ServiceContainer.UserService.RequestConnection(username, password);
                            ProgressUtility.Dismiss();

                            this.ShowError(response);

                            if (response != null && response.IsSuccessful)
                            {
                                //only save the changes after successful login
                                //User.Current.Save();

                                //this.NavigateTo(deviceListVc, inCurrentNavController: false);
                                //PresentViewController(new AquamonixNavController(deviceListVc), true, null);
                                LogUtility.Enabled = true;
                            }
                            else
                            {
                                if (response?.ErrorBody != null && response.ErrorBody.ErrorType == ErrorResponseType.ConnectionTimeout)
                                {
                                    if (DataCache.HasDevices)
                                    {
                                        deviceListVc.ShowConnectionError = true;
                                        this.NavigateTo(deviceListVc, inCurrentNavController: false);
                                    }
                                    else
                                    {
                                        AlertUtility.ShowErrorAlert(StringLiterals.ConnectionError, StringLiterals.UnableToEstablishConnection);
                                        ConnectionManager.CancelReconnecting();
                                    }
                                }
                                // Edited //
                                if (response?.ErrorBody != null && response.ErrorBody.ErrorType == ErrorResponseType.AuthFailure)
                                {
                                    AlertUtility.ShowErrorAlert(StringLiterals.ConnectionError, StringLiterals.AuthFailureMessage);
                                    Caches.ClearCachesForAuthFailure();
                                }

                                this.LoadData();
                            }
                        });
                    }
                }
            }
            catch (Exception e)
            {
                LogUtility.LogException(e);
            }
        }
Beispiel #12
0
        protected override void HandleViewDidAppear(bool animated)
        {
            base.HandleViewDidAppear(animated);

            //UIApplication.SharedApplication.KeyWindow.AddSubview(ReconnectingOverlay.Instance);

            //LocationUtility.DistanceInMetersFrom(13.736717, 100.523186);

            if (_attemptAutoLogin)
            {
                var deviceListVc = DeviceListViewController.CreateInstance();

                if (User.Current == null || !User.Current.HasConfig)
                {
                    //redirect to Config VC
                    //this.NavigationController.PushViewController(ViewControllerFactory.GetViewController<UserConfigViewController>(), true);
                    NavigateUserConfig();
                }
                else
                {
                    ProgressUtility.SafeShow("Connecting", async() =>
                    {
                        var userConfigVc = UserConfigViewController.CreateInstance();

                        var response = await ServiceContainer.UserService.RequestConnection(
                            User.Current.Username,
                            User.Current.Password);

                        MainThreadUtility.InvokeOnMain(() =>
                        {
                            ProgressUtility.Dismiss();

                            //on connection error, redirect to config
                            if (response != null && response.IsSuccessful)
                            {
                                //redirect to device list
                                this.NavigateTo(deviceListVc, inCurrentNavController: false);
                                //this.PresentViewController(new AquamonixNavController(deviceListVc), true, null);
                            }
                            else
                            {
                                //this.NavigateTo(userConfigVc, inCurrentNavController: false);

                                if (response?.ErrorBody != null && response.ErrorBody.ErrorType == Aquamonix.Mobile.Lib.Domain.Responses.ErrorResponseType.AuthFailure)
                                {
                                    Caches.ClearCachesForAuthFailure();
                                }

                                //is device cache valid?
                                if (DataCache.HasDevices)
                                {
                                    //redirect to device list
                                    deviceListVc.ShowConnectionError = true;
                                    this.NavigateTo(deviceListVc, inCurrentNavController: false);
                                }
                                else
                                {
                                    //redirect to user config
                                    userConfigVc.ShowConnectionError = true;
                                    this.NavigateTo(userConfigVc, inCurrentNavController: false);
                                }
                            }
                        });
                    });
                }
            }
            else
            {
                this.PresentViewController(new StartViewController(true), false, null);
            }
        }