Example #1
0
        private async Task handleNetworkResponseWithCallAsync(Func <Task <IRestResponse> > call)
        {
            NetworkCallInitialised?.Invoke(this, new EventArgs());
            IRestResponse networkResponse = null;

            try
            {
                networkResponse = await call();

                var networkEventArgs = new NetworkCallEventArgs(
                    networkResponse.StatusCode == System.Net.HttpStatusCode.OK,
                    networkResponse.StatusDescription,
                    networkResponse.Content.StartsWith("{", StringComparison.OrdinalIgnoreCase)
                    );
                if (networkResponse.StatusCode == System.Net.HttpStatusCode.OK && NetworkInteractionSucceeded != null)
                {
                    networkEventArgs.RawBytes = networkResponse.RawBytes;
                    networkEventArgs.NetworkResponseContent = networkResponse.Content;
                    NetworkInteractionSucceeded(this, networkEventArgs);

                    if (_urlExtension != null && _urlExtension.Equals("/Workflow/SaveAnswers/{Answers}", StringComparison.CurrentCultureIgnoreCase))
                    {
                        _urlExtension = null;
                        AnswersUploadSucceeded(this, networkEventArgs);
                    }
                    if (_urlExtension != null && _urlExtension.Equals("/Gallary/{Photo}", StringComparison.CurrentCultureIgnoreCase) && _networkCallType == BaseNetworkAccessEnum.Post)
                    {
                        networkEventArgs.ObjectID = _photoID;
                        _urlExtension             = null;
                        _photoID = 0;
                        PhotoUploadSucceeded(this, networkEventArgs);
                    }
                }
                else
                {
                    networkEventArgs = new NetworkCallEventArgs(false, "Issues connecting to remote server");
                    NetworkInteractionFailed?.Invoke(this, networkEventArgs);
                }
            }
            catch (Exception excp)
            {
                NetworkCallCompleted?.Invoke(this, new EventArgs());
                var networkEventArgs = new NetworkCallEventArgs(false, "Error occured");
                networkEventArgs.Exception = excp;
                NetworkInteractionFailed?.Invoke(this, networkEventArgs);
            }
            finally
            {
                NetworkCallCompleted?.Invoke(this, new EventArgs());
            }
        }
Example #2
0
        async Task <INetworkResponse <T> > HandleNetworkResponseWithCallAsync <T>(Func <Task <INetworkResponse <T> > > call)
            where T : BaseViewModel
        {
            NetworkCallInitialised?.Invoke(this, new EventArgs());
            INetworkResponse <T> networkResponse = null;

            try
            {
                networkResponse = await call();

                var networkEventArgs = new NetworkCallEventArgs(
                    networkResponse.StatusCode == System.Net.HttpStatusCode.OK,
                    networkResponse.StatusDescription,
                    networkResponse.Content.StartsWith("{", StringComparison.OrdinalIgnoreCase)
                    );
                if (networkResponse.StatusCode == System.Net.HttpStatusCode.OK && NetworkInteractionSucceeded != null)
                {
                    networkEventArgs.RawBytes = networkResponse.RawBytes;
                    networkEventArgs.NetworkResponseContent = networkResponse.Content;
                    NetworkInteractionSucceeded(this, networkEventArgs);
                }
                else
                {
                    NetworkInteractionFailed?.Invoke(this, networkEventArgs);
                }
            }
            catch (Exception excp)
            {
                NetworkCallCompleted?.Invoke(this, new EventArgs());
                var networkEventArgs = new NetworkCallEventArgs(false, "Error occured");
                networkEventArgs.Exception = excp;
                NetworkInteractionFailed?.Invoke(this, networkEventArgs);
            }
            finally
            {
                NetworkCallCompleted?.Invoke(this, new EventArgs());
            }
            return(networkResponse);
        }