Exemplo n.º 1
0
 public JsonResult Invoke(PersonRequest model)
 {
     var response = Parse(model);
     try
     {
         var result = response.Handler.SendRequestFrom(User);
         return Json(result);
     }
     catch (WebException webEx)
     {
         dynamic result = new { error = webEx.Message };
         HttpStatusCode? errorCode = null;
         var httpWebResponse = webEx.Response as HttpWebResponse;
         if (httpWebResponse != null)
             errorCode = httpWebResponse.StatusCode;
         else if (webEx.Status == WebExceptionStatus.SendFailure)
             errorCode = HttpStatusCode.Unauthorized;
         return Json(new
         {
             error = webEx.Message,
             errorCode = errorCode,
         });
     }
     catch (Exception ex)
     {
         return Json(new { error = ex.Message });
     }
 }
Exemplo n.º 2
0
 public JsonResult Analyze(PersonRequest model)
 {
     var response = Parse(model);
     var url = response.Handler.BuildRequestUrl();
     const string jsonAppendage = "?format=json";
     if (url.EndsWith(jsonAppendage))
         url = url.Substring(0, url.IndexOf(jsonAppendage, System.StringComparison.Ordinal));
     return Json(new
         {
             response.Code,
             Url = url,
         });
 }
Exemplo n.º 3
0
        private PersonResponse Parse(PersonRequest model, bool invoke = false)
        {
            var code = new StringBuilder();
            var request = _linkedN.ForResource<Person>();
            code.Append("var person = _linkedN");
            code.AppendLine();
            code.Append("\t.ForResource<Person>()");

            code.Append("\r\n\t.");
            switch (model.Identifier)
            {
                case PersonIdentifier.Myself:
                    request = request.Myself();
                    code.Append("Myself()");
                    break;
                case PersonIdentifier.MemberId:
                    request = request.MemberId(model.MemberId);
                    code.Append(string.Format("MemberId(\"{0}\")", model.MemberId));
                    break;
                case PersonIdentifier.MemberUrl:
                    request = request.MemberUrl((model.MemberUrl));
                    code.Append(string.Format("MemberUrl(\"{0}\")", model.MemberUrl));
                    break;
            }

            if (model.ProfileVersion == ProfileVersion.Public)
            {
                code.AppendLine();
                code.Append("\t.Public()");
                request = request.Public();
            }

            if (model.Fields.Any(f => f.IsChecked))
            {
                var selectedFields = model.Fields.Where(f => f.IsChecked).ToArray();
                request = request.Select(selectedFields.Select(f => f.EnumValue).ToArray());
                var fieldsBuilder = new StringBuilder();
                foreach (var selectedField in selectedFields)
                {
                    if (fieldsBuilder.Length > 0)
                        fieldsBuilder.Append(",");
                    fieldsBuilder.Append(string.Format("\r\n\t\t{0}", selectedField.Value));
                }
                code.Append("\r\n\t.Select(");
                code.Append(fieldsBuilder);
                code.Append("\r\n\t)");
            }

            code.Append(";");
            code.Replace("\t", "    ");

            return new PersonResponse
            {
                Code = code.ToString(),
                Handler = request,
            };
        }