コード例 #1
0
ファイル: PrevStopNextFooter.cs プロジェクト: devperson/AQX
        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);
            });
        }
コード例 #2
0
        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);
                            }
                        }
                    }
                }
            });
        }
コード例 #3
0
        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();
                         */
                    }
                }
            });
        }
コード例 #4
0
        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);
            });
        }
コード例 #5
0
        private void HandleUpdatesForStartStations(ProgressResponse response, IEnumerable <PumpViewModel> pumps, int durationMinutes, string[] stationIds)
        {
            MainThreadUtility.InvokeOnMain(() =>
            {
                if (response != null)
                {
                    DataCache.AddCommandProgress(new CommandProgress(CommandType.StartStations, 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("Starting Stations", "Starting Stations");
                            this.RegisterForAsyncUpdate(resetStations, 5000);
                        }
                        else
                        {
                            this.RegisterForAsyncUpdate(resetStations);

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

                        DataCache.TriggerDeviceUpdate(this.DeviceId);
                    }
                }
            });
        }
コード例 #6
0
ファイル: WebSocketsClientIos.cs プロジェクト: devperson/AQX
        /// <summary>
        /// The most important method of this class; makes a server call and then asynchronously waits for the response.
        /// </summary>
        /// <param name="request">The request object</param>
        /// <param name="onConnectionResume">Action to execute if the connection is broken, then resumed, during execution of this call.</param>
        /// <param name="silentMode">If true, will not display any popups or alerts for any reason.</param>
        /// <returns>Task result with the response</returns>
        public async Task <TResponse> DoRequestAsync <TRequest, TResponse>(TRequest request, Action onConnectionResume, bool silentMode = false)
            where TRequest : IApiRequest
            where TResponse : IApiResponse, new()
        {
            TResponse response = default(TResponse);

            try
            {
                bool cancelRequest = false;
                //is connection closed?
                if (_client.ReadyState == ReadyState.Closed || _client.ReadyState == ReadyState.Closing)
                {
                    if (!(request is Aquamonix.Mobile.Lib.Domain.Requests.ConnectionRequest))
                    {
                        this.FireRequestFailureEvent(request, null, RequestFailureReason.Network, onConnectionResume, (!silentMode));
                        cancelRequest = true;
                    }
                    else
                    {
                        _client.Dispose();
                        this.SetUrl(_url);
                    }
                }


                if (!cancelRequest)
                {
                    //attempt to open connection if not already
                    if (_client.ReadyState != ReadyState.Open)
                    {
                        bool opened = await this.Open(request.Header.Channel, silentMode);

                        if (!opened)
                        {
                            //if not a connection request, we want to fire an event
                            if (!(request is Aquamonix.Mobile.Lib.Domain.Requests.ConnectionRequest))
                            {
                                //fire the event
                                this.FireRequestFailureEvent(request, null, RequestFailureReason.Network, onConnectionResume, !(silentMode));
                            }

                            return(ResponseFactory.FabricateConnectionTimeoutResponse <TResponse>(request));
                        }
                        //NEW: this 'else' clause is new
                        else
                        {
                            //if not a connection request, then we want to make a connection request now
                            if (!(request is Aquamonix.Mobile.Lib.Domain.Requests.ConnectionRequest))
                            {
                                // make a request connection, if it fails it doesnt matter as it will be picked up below
                                await ServiceContainer.UserService.RequestConnection(
                                    User.Current.Username,
                                    User.Current.Password,
                                    silentMode : true
                                    );
                            }
                        }
                    }

                    //send the request and wait for response
                    response = await this.Send <TResponse>(request, request.Header.Channel, silentMode);

                    //if response is null or unsuccessful, handle
                    if (response == null || !response.IsSuccessful)
                    {
                        if (response != null && response.IsReconnectResponse)
                        {
                            LogUtility.LogMessage("Received a Reconnect response from server; will reconnect");
                            this.FireRequestFailureEvent(request, response, RequestFailureReason.ServerRequestedReconnect, onConnectionResume, (!silentMode));
                        }
                        else
                        {
                            //if response is a timeout, handle
                            if (response != null && response.IsTimeout)
                            {
                                this.FireRequestFailureEvent(request, response, RequestFailureReason.Timeout, onConnectionResume, (!silentMode));
                            }
                            else
                            {
                                if (response != null)
                                {
                                    //if server is down, handle
                                    if (response.IsServerDownResponse)
                                    {
                                        this.FireRequestFailureEvent(request, response, RequestFailureReason.ServerDown, onConnectionResume, (!silentMode));
                                    }
                                    else if (response.IsAuthFailure)
                                    {
                                        this.FireRequestFailureEvent(request, response, RequestFailureReason.Auth, onConnectionResume, (!silentMode));
                                    }
                                    else
                                    {
                                        this.FireRequestFailureEvent(request, response, RequestFailureReason.Error, onConnectionResume, (!silentMode));

                                        //show error
                                        AlertUtility.ShowAppError(response?.ErrorBody);
                                    }
                                }
                                else
                                {
                                    this.FireRequestSucceededEvent(request, response);
                                }
                            }
                        }
                    }
                    else
                    {
                        this.FireRequestSucceededEvent(request, response);
                    }
                }
            }
            catch (Exception e)
            {
                LogUtility.LogException(e);
            }

            return(response);
        }