public static ResponseToClient GetTaskDetails(string id, string coll)
        {
            ResponseToClient responseToClient = new ResponseToClient();
            RootObject customAttrs;
            try
            {
                var accessToken = AADAuthHelper.EnsureValidAccessToken(HttpContext.Current);
                var dataList = DataGetter.GetDataMatrix(serviceUrl + Collection + "('" + id + "')", accessToken);
                var description = DataGetter.GetDescription(serviceUrl + Collection + "('" + id + "')/Description", accessToken);
                customAttrs = DataGetter.GetCustomAttributes(serviceUrl + Collection + "('" + id + "')/CustomAttributeData", accessToken);
                responseToClient.response = new string[dataList.Length + 4];
                Array.Copy(dataList, 0, responseToClient.response, 0, dataList.Length);
                responseToClient.response[6] = description;
                if (dataList[5] == ConfigurationManager.AppSettings["AzureRequestType"])
                {
                    string startDate = "";
                    string endDate = "";
                    string leaveDuration = "";
                    if (customAttrs!= null && customAttrs.results != null && customAttrs.results.Count > 0)
                    {
                        var startObj = customAttrs.results.FirstOrDefault(x => x.Name == "/SWL/ALL/DYNCOL2");
                        startDate = string.Format("{2}-{1}-{0}", startObj.Value.Substring(6, 2), startObj.Value.Substring(4, 2), startObj.Value.Substring(0, 4));
                        DateTime sd = new DateTime();
                        DateTime ed = new DateTime();
                        sd = DateTime.ParseExact(startDate, "yyyy-MM-dd", null);
                        var endObj = customAttrs.results.FirstOrDefault(x => x.Name == "/SWL/ALL/DYNCOL3");
                        endDate = string.Format("{2}-{1}-{0}", endObj.Value.Substring(6, 2), endObj.Value.Substring(4, 2), endObj.Value.Substring(0, 4));
                        ed = DateTime.ParseExact(endDate, "yyyy-MM-dd", null);
                        var lduration = ed.Subtract(sd);
                        string dayText = lduration.Days > 1 ? "Days" : "Day";
                        leaveDuration = lduration.Days.ToString() + " " + dayText;
                    }

                    responseToClient.response[7] = startDate;
                    responseToClient.response[8] = endDate;
                    responseToClient.response[9] = leaveDuration;
                }
                responseToClient.statusMsg = "OK";
            }
            catch (WebException ex)
            {
                HttpWebResponse res = (HttpWebResponse)ex.Response;
                int statusCode = (int)res.StatusCode;

                responseToClient.statusCode = statusCode;
                responseToClient.statusMsg = "Exception";
                responseToClient.response = new string[1];
                responseToClient.response[0] = ex.Message;
            }
            return responseToClient;
        }
        public static ResponseToClient postTaskDecision(string dec_key, string incidentID)
        {
            ResponseToClient resp = new ResponseToClient();
            string XMLResponse = null;
            bool hasOrigin = bool.Parse(ConfigurationManager.AppSettings["HasMultipleSapOrigin"].ToString());
            try
            {
                string resourceUrl = GetResourceUrl("postDescion", incidentID, hasOrigin, " " , dec_key);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(resourceUrl);
                request.AllowAutoRedirect = false;
                request.Method = "POST";
                request.ContentType = "application/json";
                request.Headers.Set("x-requested-with", "JSONHttpRequest");
                request.Accept = "application/json";

                ISSOProvider ssoProvider;
                SystemTypes systemType = SystemTypes.Gateway;
                AuthenticationType authenticationType = (AuthenticationType)Enum.Parse(typeof(AuthenticationType), authType);
                ssoProvider = SSOProviderFactory.Instance.GetSSOProvider(authenticationType, request.Method, "", "", "", true, resourceUrl, systemType);   //requestUrl is string
                switch (authenticationType)
                {
                    case AuthenticationType.BASIC:
                        request.Credentials = new System.Net.NetworkCredential(Constant.SERVICE_USER, Constant.SERVICE_PSWD);
                        break;
                }
                ssoProvider.SAPCredientials(ref request);

                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                using (var sr = new StreamReader(response.GetResponseStream()))
                {
                    XMLResponse = sr.ReadToEnd();
                    resp.postresponse = XMLResponse;
                    resp.statusMsg = "OK";
                }
            }
            catch(WebException ex)
            {
                HttpWebResponse res = (HttpWebResponse)ex.Response;
                int statusCode = (int)res.StatusCode;
                resp.statusCode = statusCode;
                resp.postresponse = ex.Message;
                resp.statusMsg = "Exception";
            }
            return resp;
        }
 public static ResponseToClient GetDecisionOptions(string taskId)
 {
     ResponseToClient responseToClient = new ResponseToClient();
     try
     {
         var accessToken = AADAuthHelper.EnsureValidAccessToken(HttpContext.Current);
         responseToClient.decisionOptions = DataGetter.GetDecisionOptions(ConfigurationManager.AppSettings["AzureServiceUrl"] + "DecisionOptions?InstanceID='" + taskId + "'", accessToken);
         responseToClient.statusMsg = "OK";
     }
     catch (WebException ex)
     {
         HttpWebResponse res = (HttpWebResponse)ex.Response;
         int statusCode = (int)res.StatusCode;
         responseToClient.statusCode = statusCode;
         responseToClient.statusMsg = "Exception";
         responseToClient.response = new string[1];
         responseToClient.response[0] = ex.Message;
     }
     return responseToClient;
 }
        public static ResponseToClient RequestTaskDetails(string id, string coll)
        {
            ResponseToClient responseToClient = new ResponseToClient();
            string[] dataList;
            bool hasOrigin = bool.Parse(ConfigurationManager.AppSettings["HasMultipleSapOrigin"].ToString());
            RootObject customAttributes;
            // The resource URL for NetWeaver Gateway
            string resourceUrl = GetResourceUrl("base",id, hasOrigin, coll);
            string descriptionUrl = GetResourceUrl("description", id, hasOrigin, coll);

            // The specific resource and options we need.
            string urlOptions = "?$format=json";
            resourceUrl = resourceUrl + urlOptions;

            try
            {
            dataList = DataGetter.GetDataMatrix(resourceUrl);
            string ldUrl = GetResourceUrl("custom", id, hasOrigin, coll);//CustomAttributeCollection
                customAttributes = DataGetter.GetCustomAttributes(ldUrl);

                responseToClient.response = new string[dataList.Length + 4];
                Array.Copy(dataList, 0, responseToClient.response, 0, dataList.Length);
                //gets description of the application
                var description = DataGetter.GetDescription(descriptionUrl);
                responseToClient.response[6] = description;

                if (dataList[5] == ConfigurationManager.AppSettings["GatewayRequestType"] && customAttributes != null)
                {
                    var startObj = customAttributes.results.FirstOrDefault(x => x.Name == "/SWL/ALL/DYNCOL2");
                    string startDate = string.Format("{2}-{1}-{0}", startObj.Value.Substring(6, 2), startObj.Value.Substring(4, 2), startObj.Value.Substring(0, 4));
                    DateTime sd = new DateTime();
                    DateTime ed = new DateTime();
                    DateTime.TryParseExact(startDate, "yyyy-MM-dd", new CultureInfo("en-US"),
                              DateTimeStyles.None, out sd);
                    var endObj = customAttributes.results.FirstOrDefault(x => x.Name == "/SWL/ALL/DYNCOL3");
                    string endDate = string.Format("{2}-{1}-{0}", endObj.Value.Substring(6, 2), endObj.Value.Substring(4, 2), endObj.Value.Substring(0, 4));
                    DateTime.TryParseExact(endDate, "yyyy-MM-dd", new CultureInfo("en-US"),
                              DateTimeStyles.None, out ed);
                    var lduration = ed.Subtract(sd);
                    string dayText = lduration.Days > 1 ? "Days" : "Day";
                    string leaveDuration = lduration.Days.ToString() + " " + dayText;
                    responseToClient.response[7] = ReverseDate(startDate);
                    responseToClient.response[8] = ReverseDate(endDate);
                    responseToClient.response[9] = leaveDuration;
                }
                responseToClient.statusMsg = "OK";
            }
            catch (WebException ex)
            {
                HttpWebResponse res = (HttpWebResponse)ex.Response;
                int statusCode = (int)res.StatusCode;
                responseToClient.statusCode = statusCode;
                responseToClient.statusMsg = "Exception";
                responseToClient.response = new string[1];
                responseToClient.response[0] = ex.Message;
            }
            return responseToClient;
        }
 public static ResponseToClient RequestDecisionOptions(string id)
 {
     bool hasOrigin = bool.Parse(ConfigurationManager.AppSettings["HasMultipleSapOrigin"].ToString());
     ResponseToClient responseToClient = new ResponseToClient();
     try
     {
         responseToClient.decisionOptions = DataGetter.GetDecisionOptions(GetResourceUrl("descionOptions", id, hasOrigin));
         responseToClient.statusMsg = "OK";
     }
     catch (WebException ex)
     {
         HttpWebResponse res = (HttpWebResponse)ex.Response;
         int statusCode = (int)res.StatusCode;
         responseToClient.statusCode = statusCode;
         responseToClient.statusMsg = "Exception";
         responseToClient.response = new string[1];
         responseToClient.response[0] = ex.Message;
     }
     return responseToClient;
 }
        public static ResponseToClient PostDecision(string decisionKey, string taskId)
        {
            ResponseToClient responseToClient = new ResponseToClient();
            try
            {
                var accessToken = AADAuthHelper.EnsureValidAccessToken(HttpContext.Current);
                responseToClient.postresponse = DataGetter.PostJsonString(serviceUrl + "Decision?InstanceID='" + taskId + "'&DecisionKey='" + decisionKey + "'", accessToken);
                responseToClient.statusMsg = "OK";
            }
            catch (WebException ex)
            {
                HttpWebResponse res = (HttpWebResponse)ex.Response;
                int statusCode = (int)res.StatusCode;

                responseToClient.statusCode = statusCode;
                responseToClient.statusMsg = "Exception";
                responseToClient.postresponse = ex.Message;
            }
            return responseToClient;
        }