Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public static string[][] GetData()
        {
            var accessToken = AADAuthHelper.EnsureValidAccessToken(HttpContext.Current);

            // Replace the value with your SAP OData endpoint stem and OData query parameters.
            return(DataGetter.GetDataMatrix("https://stem_of_SAP_OData_endpoint/some_data_collection?$top=5&$skip=1", accessToken));
        }
Exemplo n.º 3
0
        public static string[] GetTaskDetails(string taskId)
        {
            var accessToken = AADAuthHelper.EnsureValidAccessToken(HttpContext.Current);
            var dataList    = DataGetter.GetDataMatrix("http://gwmblr.cloudapp.net:8080/TestAppForOffice/sap/opu/odata/iwpgw/TASKPROCESSING;v=0002/TaskCollection('" + taskId + "')", accessToken);

            return(dataList);
        }
        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);
        }