Aliendreamer

Untitled

Oct 20th, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.60 KB | None | 0 0
  1. /we have to change the order in Render method or we miss if he have placeholders in the _Layout
  2.   public string Render()
  3.         {
  4.             var fullHtml = this.ReadFile();
  5.        
  6.  
  7.             var layoutWithView = this.AddViewToLayout(fullHtml);
  8.  
  9.             var renderedHtml = this.RenderHtml(layoutWithView);
  10.  
  11.             return renderedHtml;
  12.         }
  13.  
  14. //because of this :
  15.  
  16.   private object ProcessesBindingModelParameter(
  17.             ParameterInfo actionParameter,
  18.             IHttpRequest request)
  19.         {
  20.             var bindingModelType = actionParameter.ParameterType;
  21.  
  22.             var bindingModelInstance = Activator.CreateInstance(bindingModelType);
  23.  
  24.             var bindingModelProperties = bindingModelType.GetProperties();
  25.  
  26.             foreach (var bindingModelProperty in bindingModelProperties)
  27.             {
  28.                 try
  29.                 {
  30.                     //this .ToLower  create problems if you try to match confirmPassword  with confirmPassword in viewModel
  31.                     //confirmpassword != confirmPassword and we get the Exception
  32.                     //it is fixed easily maybe have other posibilities but this was the fastest I found and did work
  33.                     // Also calculated properties cause the exception too but are working fine just because they cant bi bind on
  34.                     // runtime before we actually need them in our code it cause the exception message
  35.                     var value = this.GetParameterFromRequestData(
  36.                         request,
  37.                         bindingModelProperty.Name.ToLower());
  38.  
  39.                     bindingModelProperty.SetValue(
  40.                         bindingModelInstance,
  41.                         Convert.ChangeType(value, bindingModelProperty.PropertyType));
  42.                 }
  43.                 catch (Exception)
  44.                 {
  45.                     Console.WriteLine($"The property {bindingModelProperty.Name} could not be mapped");
  46.                 }
  47.             }
  48.  
  49.             return Convert.ChangeType(bindingModelInstance, bindingModelType);
  50.         }
  51.  
  52. // we have to make small changes to HttpRequest
  53.  
  54.         private void ParseQueryParameters()
  55.         {
  56.             if (!this.Url.Contains('?'))
  57.             {
  58.                 return;
  59.             }
  60.  
  61.             string queryString = this.Url
  62.                 .Split(new[] { '?', '#' }, StringSplitOptions.None)[1];
  63.  
  64.             if (string.IsNullOrWhiteSpace(queryString))
  65.             {
  66.                 return;
  67.             }
  68.  
  69.             string[] queryParameters = queryString.Split('&');
  70.  
  71.             if (!this.IsValidRequestQueryString(queryString, queryParameters))
  72.             {
  73.                 throw new BadRequestException();
  74.             }
  75.  
  76.             foreach (var queryParameter in queryParameters)
  77.             {
  78.                 string[] parameterArguments = queryParameter
  79.                     .Split('=', StringSplitOptions.RemoveEmptyEntries);
  80.  
  81.                 this.QueryData.Add(parameterArguments[0].ToLower(), parameterArguments[1]);
  82.             }
  83.         }
  84.  
  85.         private void ParseFormDataParameters(string formData)
  86.         {
  87.             if (string.IsNullOrEmpty(formData))
  88.             {
  89.                 return;
  90.             }
  91.  
  92.             string[] formDataParams = formData.Split(HttpRequestParameterSeparator);
  93.  
  94.             foreach (var formDataParameter in formDataParams)
  95.             {
  96.                 string[] parameterArguments = formDataParameter
  97.                     .Split(HttpRequestParameterNameValueSeparator, StringSplitOptions.RemoveEmptyEntries);
  98.  
  99.                 this.FormData.Add(parameterArguments[0].ToLower(), parameterArguments[1]);
  100.             }
  101.         }
Advertisement
Add Comment
Please, Sign In to add comment