Exemple #1
0
        public SchemaValidationResult Execute(SchemaValidationContion condition)
        {
            SchemaValidationResult result = new SchemaValidationResult
            {
                SchemaUrl = condition.RawSchemaUrl,
                Schema    = "",
                Response  = RESTfulOperation.GetResponse(condition.Request)
            };

            if (!string.IsNullOrEmpty(result.SchemaUrl))
            {
                try
                {
                    using (WebClient client = new WebClient())
                    { result.Schema = client.DownloadString(condition.RawSchemaUrl); }
                }
                catch
                {
                }
            }
            Boolean IsShemaValid = false;

            if (result.Response.StatusCode == 200)
            {
                JObject schemaValidatedJson = result.Response.ResponseArray.Count != 0 ? result.Response.ResponseArray[0] as JObject : null;
                result.SchemaValidatedJson = new JavaScriptSerializer().Deserialize <dynamic>(schemaValidatedJson.ToString());

                IList <string> schemaErrorList;
                SchemaAgainstJSON(result.Schema, schemaValidatedJson, out IsShemaValid, out schemaErrorList);

                result.SchemaErrors = schemaErrorList != null?string.Join(System.Environment.NewLine, schemaErrorList) : null;
            }
            result.Status = IsShemaValid;
            return(result);
        }
Exemple #2
0
        public TotalCountResult Execute(TotalCountCondition condition)
        {
            TotalCountResult result = new TotalCountResult
            {
                Status   = false,
                Response = RESTfulOperation.GetResponse(condition.Request)
            };

            DataAccess DtAcss = new DataAccess();

            DataConnection dtcon = new DataConnection();

            dtcon.HostName    = condition.DBHostName;
            dtcon.PortNumber  = condition.DBPortNumber;
            dtcon.ServiceName = condition.DBServiceName;
            dtcon.UserId      = condition.DBUserId;
            dtcon.Password    = condition.DBPassword;



            if (result.Response.StatusCode == 200)
            {
                result.ApiTotalCount = int.Parse(GetResponseHeaderValue(result.Response.ResponseHeaders, "X-Total-Count"));
                string count = DtAcss.GetTotalCout(condition.TotalCountQuery, dtcon);
                if (count != null)
                {
                    result.DBTotalCount = Int32.Parse(count);
                    result.Status       = result.DBTotalCount == result.ApiTotalCount;
                }
            }
            return(result);
        }
        public ListHeaderMessageResult Execute(ListHeaderMessageCondition condition)
        {
            ListHeaderMessageResult result = new ListHeaderMessageResult
            {
                Status = false,
                ExpectedListHeaderMessage = "List of " + SingularizeEndPoint(condition.Request.EndPoint) + " resources",
                Response = RESTfulOperation.GetResponse(condition.Request)
            };


            if (result.Response.StatusCode == 200)
            {
                result.ListHeaderMessage = GetResponseHeaderValue(result.Response.ResponseHeaders, "X-hedtech-message");
                result.Status            = CheckHeaderMessage(result.ListHeaderMessage, result.ExpectedListHeaderMessage);
            }
            return(result);
        }
Exemple #4
0
        public LatestVersionResult Execute(LatestVersionCondition condition)
        {
            LatestVersionResult result = new LatestVersionResult
            {
                Status   = false,
                Response = RESTfulOperation.GetResponse(condition.Request)
            };


            if (result.Response.StatusCode == 200)
            {
                result.LatestVersion         = GetResponseHeaderValue(result.Response.ResponseHeaders, "X-hedtech-Media-Type");
                result.ExpectedLatestVersion = VersionFormat(condition.Version);
                result.Status = result.LatestVersion.Contains(result.ExpectedLatestVersion);
            }
            return(result);
        }
Exemple #5
0
        public InvalidGuidHeaderMessageResult Execute(InvalidGuidHeaderMessageCondition condition)
        {
            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

            InvalidGuidHeaderMessageResult result = new InvalidGuidHeaderMessageResult
            {
                Status = false,
                ExpectedInvalidGuidHeaderMessage = textInfo.ToTitleCase(SingularizeEndPoint(condition.Request.EndPoint).Replace("-", " ")) + " not found",
                InvalidGuid = "invalid-Guid-0123"
            };

            condition.Request.RequestUrl = condition.Request.RequestUrl + @"/" + result.InvalidGuid;
            result.Response = RESTfulOperation.GetResponse(condition.Request);

            result.InvalidGuidHeaderMessage = GetResponseHeaderValue(result.Response.ResponseHeaders, "X-hedtech-message");
            result.Status = CheckHeaderMessage(result.InvalidGuidHeaderMessage, result.ExpectedInvalidGuidHeaderMessage);
            return(result);
        }
Exemple #6
0
        public CRUDvalidationResult Execute(CRUDvalidationCondition condition)
        {
            DataAccess     DtAcss = new DataAccess();
            DataConnection dtcon  = new DataConnection();

            dtcon.HostName    = condition.DBHostName;
            dtcon.PortNumber  = condition.DBPortNumber;
            dtcon.ServiceName = condition.DBServiceName;
            dtcon.UserId      = condition.DBUserId;
            dtcon.Password    = condition.DBPassword;

            CRUDvalidationResult result = new CRUDvalidationResult
            {
                Status = false
            };

            result.InsertGuidLinkFieldValue = DtAcss.InsertIntoDB(condition.InsertQuery, condition.InsertGuidLinkField, dtcon);
            if (!string.IsNullOrEmpty(result.InsertGuidLinkFieldValue))
            {
                result.DBGuid   = DtAcss.GetGuidInDB(condition.GuidQuery, condition.InsertGuidLinkField, result.InsertGuidLinkFieldValue, dtcon);
                result.Status   = true;
                result.Response = RESTfulOperation.GetResponse(condition.Request);

                //result.Guid = GetResponseFieldValue(requestResponse.Response.ResponseArray, 1, "id");
                //result.Response.ResponseBody
                JArray filteredJArray = FilterFieldValueInJsonArray(result.Response.ResponseArray, "id", result.DBGuid);
                result.NumberOfGuidsFound = filteredJArray.Count;

                result.ObjectList = ToDynamicList(filteredJArray);
                //result.ObjectList = new JavaScriptSerializer().Deserialize<dynamic>(jTokenList);
                //result.ObjectList = jTokenList;
                int deleteReturnValue = DtAcss.DeleteFromDB(condition.DeleteQuery, dtcon);
                result.InsertionDeleted = "No";
                if (deleteReturnValue > -1)
                {
                    result.InsertionDeleted = "Yes";
                }
            }

            return(result);
        }
        public GuidHeaderMessageResult Execute(GuidHeaderMessageCondition condition)
        {
            GuidHeaderMessageResult result = new GuidHeaderMessageResult
            {
                Status = false,
                ExpectedGuidHeaderMessage = "Details for the " + SingularizeEndPoint(condition.Request.EndPoint) + " resource",
                Response = RESTfulOperation.GetResponse(condition.Request)
            };

            if (result.Response.StatusCode == 200)
            {
                result.Guid = GetResponseFieldValue(result.Response.ResponseArray, 1, "id");
                if (!string.IsNullOrEmpty(result.Guid))
                {
                    condition.Request.RequestUrl = condition.Request.RequestUrl + @"/" + result.Guid;
                    result.Response          = RESTfulOperation.GetResponse(condition.Request);
                    result.GuidHeaderMessage = GetResponseHeaderValue(result.Response.ResponseHeaders, "X-hedtech-message");
                    result.Status            = CheckHeaderMessage(result.GuidHeaderMessage, result.ExpectedGuidHeaderMessage);
                }
            }
            return(result);
        }
Exemple #8
0
        public MaxPageSizeResult Execute(MaxPageSizeCondition condition)
        {
            MaxPageSizeResult result = new MaxPageSizeResult
            {
                Status   = false,
                Response = RESTfulOperation.GetResponse(condition.Request)
            };

            if (result.Response.StatusCode == 200)
            {
                result.MaxPageSize = int.Parse(GetResponseHeaderValue(result.Response.ResponseHeaders, "X-hedtech-pageMaxSize"));
                JObject[] PageItems = result.Response.ResponseArray.Select(jv => (JObject)jv).ToArray();
                result.JsonObjectsInPage = PageItems.Length;
                result.Status            = result.JsonObjectsInPage == result.MaxPageSize;
                if (result.JsonObjectsInPage < result.MaxPageSize)
                {
                    result.ApiTotalCount = int.Parse(GetResponseHeaderValue(result.Response.ResponseHeaders, "X-Total-Count"));
                    result.Status        = result.JsonObjectsInPage == result.ApiTotalCount;
                }
            }
            return(result);
        }
Exemple #9
0
        public OffsetValidationResult Execute(OffsetValidationCondition condition)
        {
            OffsetValidationResult result = new OffsetValidationResult
            {
                Status   = false,
                Response = RESTfulOperation.GetResponse(condition.Request)
            };
            List <OffsetInfo> OffsetInfoList = new List <OffsetInfo>();

            if (result.Response.StatusCode == 200)
            {
                int pagemaxsize;
                int.TryParse(GetResponseHeaderValue(result.Response.ResponseHeaders, "X-Max-Page-Size"), out pagemaxsize);
                result.Pagemaxsize = pagemaxsize;

                int totalcount = 0;
                int.TryParse(GetResponseHeaderValue(result.Response.ResponseHeaders, "X-Total-Count"), out totalcount);
                result.Totalcount = totalcount;

                if (result.Totalcount > 0)
                {
                    int offsetCountLowRange = 0;

                    int offsetCountHighRange = pagemaxsize < totalcount ? (1 + (totalcount - 1) / pagemaxsize) : 0;
                    //offsetCountHighRange = 1000;

                    //List<int> offsetCountList = Enumerable.Range(offsetCountLowRange, offsetCountHighRange).Select(i => i * pagemaxsize).ToList();
                    List <RESTfulRequest> requestList = new List <RESTfulRequest>();

                    for (int i = offsetCountLowRange; i < offsetCountHighRange; i++)
                    {
                        requestList.Add(new RESTfulRequest
                        {
                            AuthType         = condition.Request.AuthType,
                            UserName         = condition.Request.UserName,
                            Password         = condition.Request.Password,
                            Accept           = condition.Request.Accept,
                            ContentType      = condition.Request.ContentType,
                            LanguageCode     = condition.Request.LanguageCode,
                            RequestMethod    = condition.Request.RequestMethod,
                            RequestUrl       = condition.Request.RequestUrl + @"?offset=" + i * pagemaxsize,
                            RequestBody      = condition.Request.RequestBody,
                            EndPoint         = condition.Request.EndPoint,
                            EndPointObjectId = condition.Request.EndPointObjectId
                        });
                    }


                    OffsetInfoList = GetOffsetInfo(requestList).ToList();
                }
            }
            int passNoCount = OffsetInfoList.Count(p => p.Pass == "No");

            if (passNoCount == 0)
            {
                result.Status = true;
            }
            result.OffsetInfo    = OffsetInfoList;
            result.NumberOfPages = OffsetInfoList.Count;
            //result.IDFields = idFieldValues.OrderBy(o => o.PageOffset).ToList();

            //Convert the concurrentBag to list and flatten the list of lists
            var idFieldValuesList = idFieldValuesBag.ToList().SelectMany(x => x).ToList();

            result.NumberOfIDFields = idFieldValuesList.Count;
            var DuplicateIDsList = idFieldValuesList.GroupBy(c => c.ID).Where(g => g.Skip(1).Any()).SelectMany(c => c);

            result.DuplicateIDs         = DuplicateIDsList.GroupBy(u => u.ID).Select(grp => grp.ToList()).ToList();
            result.NumberOfDuplicateIDs = result.DuplicateIDs.Count;

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            serializer.MaxJsonLength = int.MaxValue; // The value of this constant is 2,147,483,647
            var requestResponseListJson = serializer.Serialize(ResponseBodyBag.ToList());

            //string path = Server.MapPath("~/App_Data/");

            string path = Path.GetTempPath();

            var fileName = condition.Request.EndPoint + "_OffsetValidationRequestResponse_" + DateTime.Now.ToString("ddMMyyHHmmss") + ".json";

            // Write that JSON to txt file,
            File.WriteAllText(path + fileName, requestResponseListJson);


            return(result);
        }
Exemple #10
0
        public static ConcurrentBag <OffsetInfo> GetOffsetInfo(List <RESTfulRequest> RequestList)
        {
            //ServicePointManager.DefaultConnectionLimit = 20;
            ConcurrentBag <OffsetInfo> infoBag = new ConcurrentBag <OffsetInfo>();

            //var blockOptions = new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 10 };
            Parallel.ForEach(RequestList, new ParallelOptions {
                MaxDegreeOfParallelism = 4
            }, (requestItem) =>
                             //foreach (var requestItem in RequestList)
            {
                var Response = RESTfulOperation.GetResponse(requestItem);

                OffsetInfo info     = new OffsetInfo();
                info.OffsetUrl      = requestItem.RequestUrl;
                info.ResponseStatus = Response.StatusCode + ", " + Response.ResponsePhrase;

                int headerPageoffsetValue;
                int.TryParse(GetResponseHeaderValue(Response.ResponseHeaders, "X-hedtech-pageOffset"), out headerPageoffsetValue);
                if (Response.ResponseArray != null)
                {
                    info.ItemCount = 0;
                    idFieldValuesBag.Add(GetByFieldNameInJsonArray(Response.ResponseArray, "id", headerPageoffsetValue));
                }
                info.TimeTakenInMs = Response.TimeTakenInMs;
                ResponseBodyBag.Add(Response.ResponseBody);

                int urlOffsetNumber = -1;
                var splitArry       = info.OffsetUrl.Split(new[] { "?offset=" }, StringSplitOptions.None);
                if (splitArry.Length > 1)
                {
                    int.TryParse(splitArry[1], out urlOffsetNumber);
                }
                info.Pass = Response.StatusCode == 200 ? "Yes" : "No";
                infoBag.Add(info);
            });
            //};

            //ServicePointManager.DefaultConnectionLimit = 20;
            //var workerBlock = new System.Threading.Tasks.Dataflow.ActionBlock<RESTfulRequest>(requestItem =>
            //{
            //    var Response = RESTfulOperation.GetResponse(requestItem);

            //    OffsetInfo info = new OffsetInfo();
            //    info.OffsetUrl = requestItem.RequestUrl;
            //    info.ResponseStatus = Response.StatusCode + ", " + Response.ResponsePhrase;

            //    int headerPageoffsetValue;
            //    int.TryParse(GetResponseHeaderValue(Response.ResponseHeaders, "X-hedtech-pageOffset"), out headerPageoffsetValue);
            //    if (Response.ResponseArray != null)
            //    {
            //        info.ItemCount = 0;
            //        idFieldValuesBag.Add(GetByFieldNameInJsonArray(Response.ResponseArray, "id", headerPageoffsetValue));
            //    }
            //    info.TimeTakenInMs = Response.TimeTakenInMs;
            //    ResponseBodyBag.Add(Response.ResponseBody);

            //    int urlOffsetNumber = -1;
            //    var splitArry = info.OffsetUrl.Split(new[] { "?offset=" }, StringSplitOptions.None);
            //    if (splitArry.Length > 1)
            //    {
            //        int.TryParse(splitArry[1], out urlOffsetNumber);
            //    }
            //    info.Pass = Response.StatusCode == 200 ? "Yes" : "No";
            //    infoBag.Add(info);
            //}, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 10 });

            //foreach (var item in RequestList)
            //{
            //    workerBlock.Post(item);
            //}
            //workerBlock.Complete();

            return(infoBag);
        }