Exemplo n.º 1
0
        public async Task <ActionResult> GetData(string name, string propertyName, string urlFilter, string options,
                                                 string filter, string paging, string sort, bool forCopy = false)
        {
            try
            {
                if (!await DWKitRuntime.Security.CheckFormPermissionAsync(name, "View"))
                {
                    throw new Exception("Access denied!");
                }

                var getRequest = CreateGetRequest(name, propertyName, urlFilter, options, filter, paging, sort, forCopy);
                var data       = await DataSource.GetDataForFormAsync(getRequest).ConfigureAwait(false);

                if (data.IsFromUrl && FailResponse.IsFailResponse(data.Entity, out FailResponse fail))
                {
                    return(Json(fail));
                }

                var result = data.Entity != null?data.Entity.ToDictionary(true) : new object();

                return(Json(new ItemSuccessResponse <object>(result)));
            }
            catch (Exception e)
            {
                return(Json(new FailResponse(e)));
            }
        }
Exemplo n.º 2
0
        public static bool CheckResult(RestClient rc)
        {
            if (rc.ResponseHasNoErrors(new ResponseChecker()))
            {
                return(true);
            }
            else if (rc.ResponseHasSuccessStatusCode)
            {
                string response = rc.GetResponseToString;

                FailResponseTemp frt = Deserialize.FromJson <FailResponseTemp>(response);
                FailResponse     fr  = frt.GetResponse();

                throw new FailResponseException("Server was return error response. Check error list for more informations.", fr.Errors);
            }

            FailResponseTemp frt2 = Deserialize.FromJson <FailResponseTemp>(rc.GetResponseToString);

            if (frt2 == null)
            {
                throw new FailResponseException(frt2.Errors[0]);
            }
            else
            {
                throw new FailResponseException();
            }
        }
Exemplo n.º 3
0
        public void DataIsCorrectlyInitialized(object data)
        {
            // Exercise system
            var response = new FailResponse(data);

            // Verify outcome
            response.Data.Should().BeSameAs(data);
        }
        public void Ctor_Arguments_ResponseMessage_AsExpected()
        {
            const string responseMessage = "bad";

            IResponse <string> response = new FailResponse <string>(responseMessage);

            Assert.False(response.IsSuccess);
            Assert.Equal(responseMessage, response.Message);
        }
        public void ResponseIsCorrectlyInitialized(string reason, ApiController controller)
        {
            // Fixture setup
            var expectedResponse = new FailResponse(reason);
            // Exercise system
            var result = new JSendNotFoundResult(reason, controller);

            // Verify outcome
            result.Response.ShouldBeEquivalentTo(expectedResponse);
        }
        public void JSendFail_CreatesNewJSendResult(HttpStatusCode code, string reason, JSendApiController controller)
        {
            // Fixture setup
            var expectedResponse = new FailResponse(reason);
            // Exercise system
            var result = controller.JSendFail(code, reason);

            // Verify outcome
            result.Response.ShouldBeEquivalentTo(expectedResponse);
            result.StatusCode.Should().Be(code);
        }
        public void ResponseIsCorrectlyInitialized(IEnumerable <AuthenticationHeaderValue> challenges,
                                                   ApiController controller)
        {
            // Fixture setup
            var expectedResponse = new FailResponse(StringResources.RequestNotAuthorized);
            // Exercise system
            var result = new JSendUnauthorizedResult(challenges, controller);

            // Verify outcome
            result.Response.ShouldBeEquivalentTo(expectedResponse);
        }
        public void Ctor_Arguments_ResponseObjectAndResponseMessage_AsExpected()
        {
            const string responseObject  = "ThisIsResponseObject";
            const string responseMessage = "good";

            IResponse <string> response = new FailResponse <string>(responseObject, responseMessage);

            Assert.Equal(responseObject, response.ResponseObject);
            Assert.False(response.IsSuccess);
            Assert.Equal(responseMessage, response.Message);
        }
Exemplo n.º 9
0
        public async Task <IActionResult> ExportData(string name, string propertyName, string urlFilter, string options,
                                                     string filter, string paging, string sort, string cols, string fileName, string pagerType, bool forCopy = false, bool mobile = false)
        {
            if (!await DWKitRuntime.Security.CheckFormPermissionAsync(name, "View"))
            {
                return(new JsonResult(new FailResponse("Access denied!"))
                {
                    StatusCode = 401
                });
            }

            bool isServerPager = pagerType == "server";

            GetDataRequest getRequest;

            if (isServerPager)
            {
                getRequest = CreateGetRequest(name, propertyName, urlFilter, options, filter, paging, sort, forCopy, mobile);
            }
            else
            {
                getRequest = CreateGetRequest(name, propertyName, urlFilter, options, filter, paging, null, forCopy, mobile);
            }

            var data = await DataSource.GetDataForFormAsync(getRequest).ConfigureAwait(false);


            if (data.IsFromUrl && FailResponse.IsFailResponse(data.Entity, out FailResponse fail))
            {
                return(Json(fail));
            }

            var resultFileName = string.Format("{0}.xlsx", propertyName);

            if (NotNullOrEmpty(fileName))
            {
                resultFileName = fileName;
            }

            List <ClienSortItem> extraSort = null;

            if (!isServerPager && NotNullOrEmpty(sort))
            {
                extraSort = JsonConvert.DeserializeObject <List <ClienSortItem> >(sort);
            }

            var stream   = DataSource.ExportToExcel(CreateColsFilter(cols), propertyName, data.Entity, extraSort);
            var mimeType = "application/vnd.ms-excel";

            return(File(stream, mimeType, resultFileName));
        }
Exemplo n.º 10
0
        public void SerializesCorrectly(object data, FailResponse response)
        {
            // Fixture setup
            var expectedSerializedResponse = new JObject
            {
                { "status", "fail" },
                { "data", JObject.FromObject(data) }
            };
            // Exercise system
            var serializedResponse = JObject.FromObject(response);

            // Verify outcome
            Assert.Equal(expectedSerializedResponse, serializedResponse, JToken.EqualityComparer);
        }
Exemplo n.º 11
0
        public override void OnException(HttpActionExecutedContext context)
        {
            FailResponse response;

            if (context.Exception is ValidationException)
            {
                response = (context.Exception as ValidationException).BuildFailResponse();
            }
            else
            {
                response = new FailResponse(context.Exception.ToString());
            }

            context.Response = context.Request.CreateResponse(HttpStatusCode.InternalServerError, response);
        }
Exemplo n.º 12
0
        public async Task <ActionResult> GetData(string name, string control, string urlFilter, string options,
                                                 string filter, string paging, string sort, bool forCopy = false)
        {
            try
            {
                if (!await DWKitRuntime.Security.CheckFormPermissionAsync(name, "View"))
                {
                    throw new Exception("Access denied!");
                }

                string filterActionName = null;
                string idValue          = null;
                var    filterItems      = new List <ClientFilterItem>();

                if (NotNullOrEmpty(urlFilter))
                {
                    try
                    {
                        filterItems.AddRange(JsonConvert.DeserializeObject <List <ClientFilterItem> >(urlFilter));
                    }
                    catch
                    {
                        var    filterActions = DWKitRuntime.ServerActions.GetFilterNames().Where(n => n.Equals(urlFilter, StringComparison.OrdinalIgnoreCase)).ToList();
                        string filterAction  = null;
                        filterAction = filterActions.Count == 1 ? filterActions.First()
                            : filterActions.FirstOrDefault(n => n.Equals(urlFilter, StringComparison.Ordinal));

                        if (!string.IsNullOrEmpty(filterAction))
                        {
                            filterActionName = filterAction;
                        }
                        else
                        {
                            idValue = urlFilter;
                        }
                    }
                }

                if (NotNullOrEmpty(filter))
                {
                    filterItems.AddRange(JsonConvert.DeserializeObject <List <ClientFilterItem> >(filter, new JsonSerializerSettings
                    {
                        DateParseHandling = DateParseHandling.None
                    }));
                }


                var getRequest = new GetDataRequest(name)
                {
                    RequestingControlName = control,
                    FilterActionName      = filterActionName,
                    IdValue = idValue,
                    Filter  = filterItems,
                    BaseUrl = $"{Request.Scheme}://{Request.Host.Value}",
                    ForCopy = forCopy,
                    GetHeadersForLocalRequest = () =>
                    {
                        var dataUrlParameters = new Dictionary <string, string>
                        {
                            {
                                "Cookie",
                                string.Join(";",
                                            Request.Cookies.Select(c => $"{c.Key}={c.Value}"))
                            }
                        };
                        return(dataUrlParameters);
                    }
                };

                if (NotNullOrEmpty(options))
                {
                    getRequest.OptionsDictionary = JsonConvert.DeserializeObject <Dictionary <string, object> >(options);
                }

                if (NotNullOrEmpty(paging))
                {
                    getRequest.Paging = JsonConvert.DeserializeObject <ClientPaging>(paging);
                }

                if (NotNullOrEmpty(sort))
                {
                    getRequest.Sort = JsonConvert.DeserializeObject <List <ClienSortItem> >(sort);
                }

                var data = await DataSource.GetDataForFormAsync(getRequest).ConfigureAwait(false);

                if (data.IsFromUrl && FailResponse.IsFailResponse(data.Entity, out FailResponse fail))
                {
                    return(Json(fail));
                }

                var result = data.Entity != null?data.Entity.ToDictionary(true) : new object();

                return(Json(new ItemSuccessResponse <object>(result)));
            }
            catch (Exception e)
            {
                return(Json(new FailResponse(e)));
            }
        }
Exemplo n.º 13
0
 public void StatusIsFail(FailResponse response)
 {
     // Exercise system and verify outcome
     response.Status.Should().Be("fail");
 }
Exemplo n.º 14
0
 public void IsJSendResponse(FailResponse response)
 {
     // Exercise system and verify outcome
     response.Should().BeAssignableTo <IJSendResponse>();
 }
Exemplo n.º 15
0
        private void loginBtn_Clicked(object sender, EventArgs e)
        {
            indicator.IsVisible = true;
            indicator.IsRunning = true;
            //Task.Run(() => {
            try{
                if (!client.Connected)
                {
                    client    = Connection.Connect(hostname, defaultPort, ref writer, ref reader);
                    sessionID = (long)reader.Read();
                }
                var username = usernameEntry.Text.Trim().ToUsername();
                var password = passwordEntry.Text.ToPassword();

                SignInRequest req = new SignInRequest(username, password, sessionID);
                writer.Write(req);
                //req.Send(writer);

                Response resp = (Response)reader.Read();
                if (resp.SessionID == sessionID)
                {
                    //switch ((ResponseType)Enum.Parse(typeof(ResponseType), (string)reader.Read()))
                    switch (resp.Type)
                    {
                    case ResponseType.AccountInfo:
                        AccountInfoResponse AIResp = (AccountInfoResponse)resp;                                 //.Read(reader, sessionID);
                        var homePage = new NavigationPage(new HomePage(app, username, writer, reader, AIResp, sessionID));
                        //Device.BeginInvokeOnMainThread(() => {
                        //indicator.IsVisible = false;
                        //indicator.IsRunning = false;
                        app.MainPage = homePage;
                        //});
                        break;

                    case ResponseType.Fail:
                        FailResponse FResp = (FailResponse)resp;                                         //.Read(reader, sessionID);
                        DisplayAlert(SignInFailTitle, FResp.Reason, DefaultCancel);
                        break;

                    default:
                        throw new InvalidResponseException();
                    }
                }
                else
                {
                    Connection.Disconnect(ref client, ref reader, ref writer);
                }
            }
            catch (SocketException)
            {
                DisplayAlert(ConnectionErrorTitle, ConnectionErrorMessage, DefaultCancel);
            }
            catch (InvalidResponseException)
            {
                //Task.Run( () =>
                DisplayAlert(ResponseErrorTitle, ResponseErrorMessage, DefaultCancel);
                //);
            }
            finally
            {
                indicator.IsVisible = false;
                indicator.IsRunning = false;
            }
            //});
        }
Exemplo n.º 16
0
        private void createAccountBtn_Clicked(object sender, EventArgs e)
        {
            indicator.IsVisible = true;
            indicator.IsRunning = true;
            //Task.Run(() => {
            try{
                if (!client.Connected)
                {
                    client    = Connection.Connect(hostname, defaultPort, ref writer, ref reader);
                    sessionID = (long)reader.Read();
                }
                NewAccountRequest req = default;
                var email             = emailEntry.Text.Trim();
                var username          = usernameEntry.Text.Trim();
                var passwd            = passwordEntry.Text;
                //if (username.Length <= 7)
                //{
                //	DisplayAlert(FormatErrorTitle, UsernameFormatErrorMessage, ConnectionErrorCancel);
                //	return;
                //}
                //if (passwd.Length <= 7)
                //{
                //	DisplayAlert(FormatErrorTitle, PasswordFormatErrorMessage, ConnectionErrorCancel);
                //	return;
                //}
                req = new NewAccountRequest(email.ToEmail(),
                                            username.ToUsername(), passwd.ToPassword(), sessionID);
                writer.Write(req);
                //req.Send(writer);

                Response resp = (Response)reader.Read();
                if (resp.SessionID == sessionID)
                {
                    //switch ((ResponseType)Enum.Parse(typeof(ResponseType), (string)reader.Read()))
                    switch (resp.Type)
                    {
                    case ResponseType.Success:
                        loginBtn.IsVisible   = true;
                        emailEntry.IsVisible = false;
                        emailLabel.IsVisible = false;
                        btnGrid.IsVisible    = true;
                        btnStack.IsVisible   = false;

                        emailEntry.Text    = "";
                        usernameEntry.Text = "";
                        passwordEntry.Text = "";
                        DisplayAlert(AccountCreateSuccessTitle, AccountCreateSuccessMessage, DefaultCancel);
                        break;

                    case ResponseType.Fail:
                        FailResponse FResp = (FailResponse)resp;                                         //.Read(reader, sessionID);
                        DisplayAlert(AccountCreateFailTitle, FResp.Reason, DefaultCancel);
                        break;
                    }
                }
                else
                {
                    Connection.Disconnect(ref client, ref reader, ref writer);
                }
            }
            catch (SocketException)
            {
                DisplayAlert(ConnectionErrorTitle, ConnectionErrorMessage, DefaultCancel);
            }
            catch (FormatException)
            {
                DisplayAlert(FormatErrorTitle, EmailFormatErrorMessage, DefaultCancel);
            }
            //catch (InvalidSessionIDException)
            //{
            //	DisplayAlert(FormatErrorTitle, EmailFormatErrorMessage, EmailFormatErrorCancel);
            //}
            finally
            {
                indicator.IsVisible = false;
                indicator.IsRunning = false;
            }
            //});
        }