Exemplo n.º 1
0
        public RootActivityBulk CreateBulk(RootActivity activities, int requestnumber)
        {
            RootActivityBulk resultbulkactivity = new RootActivityBulk();
            string           bulkactivity       = JsonConvert.SerializeObject(activities, Formatting.None);

            ResponseOFSC result = UtilWebRequest.SendWayAsync("rest/ofscCore/v1/activities/custom-actions/bulkUpdate", enumMethod.POST, bulkactivity, Authorization);

            result.Content = result.Content.Replace("\n", string.Empty);

            // REQUEST OK
            if (result.statusCode >= 200 && result.statusCode < 300)
            {
                attemps           += 0;
                resultbulkactivity = JsonConvert.DeserializeObject <RootActivityBulk>(result.Content);
                // Horario ; status Code http ;Request ; Response ;
                Program.Logger(string.Format("{0};{1};{2};", DateTime.Now, result.statusCode, result.Content), TypeLog.OK_REST_ACTIVITY, requestnumber);

                // Analyzing object
                AnalyzingBulk(resultbulkactivity, activities);
            }

            // REQUEST NETWORK CONNECTION BEING DOWN
            else if (result.statusCode == 0 && attemps < 3)
            {
                attemps += 1;
                Program.Logger(string.Format("|{0}|statusCode:{1}|Content:{2}|ErrorMessage:{3}|activities{4}|", DateTime.Now, result.statusCode, result.Content, result.ErrorMessage, bulkactivity), TypeLog.NSHTTPURLResponse);
                Thread.Sleep(5000);
                CreateBulk(activities, requestnumber);
            }


            return(resultbulkactivity);
        }
Exemplo n.º 2
0
        public static ResponseOFSC SendWayAsync(string endpoint, enumMethod enumMethod, string data, string token)
        {
            var         client  = new RestClient("https://api.etadirect.com/" + endpoint);
            RestRequest request = new RestRequest();

            switch (enumMethod.ToString())
            {
            case "PUT":
                request.Method = Method.PUT;
                break;

            case "POST":
                request.Method = Method.POST;
                break;

            case "PATCH":
                request.Method = Method.PATCH;
                break;

            case "GET":
                request.Method = Method.GET;
                break;

            case "DELETE":
                request.Method = Method.DELETE;
                break;

            default:
                break;
            }

            request.AddHeader("Cache-Control", "no-cache");
            request.AddHeader("Authorization", token);
            request.AddHeader("Content-Type", "application/json");
            if (!string.IsNullOrEmpty(data))
            {
                request.AddParameter("undefined", data, ParameterType.RequestBody);
            }

            IRestResponse response = client.Execute(request);

            ResponseOFSC responseOFSC = new ResponseOFSC();

            responseOFSC.Content      = response.Content;
            responseOFSC.statusCode   = (int)response.StatusCode;
            responseOFSC.ErrorMessage = response.ErrorMessage;
            return(responseOFSC);
        }
Exemplo n.º 3
0
        public Activity Exist(Activity activity)
        {
            Program.Logger(string.Format("|{0}|apptNumber:{1}|resourceId:{2}|", DateTime.Now, activity.apptNumber, activity.resourceId), TypeLog.DEFAULT);
            Activity responseActivity = new Activity();
            string   jsonActivy       = JsonConvert.SerializeObject(activity, Formatting.None);

            ResponseOFSC result = UtilWebRequest.SendWayAsync("rest/ofscCore/v1/activities", enumMethod.POST, jsonActivy, Authorization);

            result.Content = result.Content.Replace("\n", string.Empty);

            if (result.statusCode >= 200 && result.statusCode < 300)
            {
                responseActivity = JsonConvert.DeserializeObject <Activity>(result.Content);
                Program.Logger(string.Format("|{0}|apptNumber:{1},activityId:{2},resource_id:{3}|{4}|", DateTime.Now, responseActivity.apptNumber, responseActivity.activityId, responseActivity.resourceId, result.Content), TypeLog.OK_REST_ACTIVITY);
            }

            else
            {
                Program.Logger(string.Format("|{0}|apptNumber:{1},resource_id:{2}|{3}|", DateTime.Now, activity.apptNumber, activity.resourceId, result.Content), TypeLog.BAD_REST_ACTIVITY);
            }

            return(responseActivity);
        }
Exemplo n.º 4
0
        public Inventory CreateInventory(Inventory inventory)
        {
            Inventory responseInventory = new Inventory();

            string       search = string.Format("rest/ofscCore/v1/activities/{0}/customerInventories", inventory.activityId);
            ResponseOFSC result = UtilWebRequest.SendWayAsync(search, enumMethod.POST,
                                                              JsonConvert.SerializeObject(inventory, Formatting.None),
                                                              Authorization);

            result.Content = result.Content.Replace("\n", string.Empty);

            if (result.statusCode >= 200 && result.statusCode < 300)
            {
                responseInventory = JsonConvert.DeserializeObject <Inventory>(result.Content);
                Program.Logger(string.Format("|{0}|activityId:{1},inventoryId|{2}|{3}", DateTime.Now, responseInventory.activityId, responseInventory.inventoryId, result.Content), TypeLog.OK_REST_ACTIVITY);
            }

            else
            {
                Program.Logger(string.Format("|{0}|activityId:{1},inventoryType|{2}|{3}", DateTime.Now, inventory.activityId, inventory.inventoryType, result.Content), TypeLog.BAD_REST_INVENTORY);
            }

            return(responseInventory);
        }