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
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(" Procesando actividades ");
            int countactivities = 0;

            Program.Logger(string.Format("************************************************************"), TypeLog.DEFAULT);
            Program.Logger(string.Format(" Inicia proceso {0} ", DateTime.Now), TypeLog.DEFAULT);
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            List <Activity> list = ctrlActivity.GetFromCSV(CurrentFilePath);

            RootActivity activities = new RootActivity();

            activities.activities = new List <Activity>();
            activities.activities = list;

            activities.updateParameters = new UpdateParameters();
            activities.updateParameters.identifyActivityBy  = "apptNumber";
            activities.updateParameters.ifInFinalStatusThen = "createNew";


            int    maxcountrequest = 500;
            double numberrequest   = Math.Floor((double)activities.activities.Count / maxcountrequest);

            numberrequest = numberrequest == 0 ? 1 : numberrequest;

            List <Activity> full = activities.activities.ToList <Activity>();

            for (int i = 0; i < numberrequest; i++)
            {
                List <Activity> tmpactiviti = full.Skip(i * maxcountrequest).Take(maxcountrequest).ToList <Activity>();
                countactivities += tmpactiviti.Count;
                // Activity
                RootActivity activities2 = new RootActivity();
                activities2.activities       = new List <Activity>();
                activities2.activities       = tmpactiviti;
                activities2.updateParameters = new UpdateParameters();
                activities2.updateParameters.identifyActivityBy  = "apptNumber";
                activities2.updateParameters.ifInFinalStatusThen = "createNew";
                ctrlActivity.CreateBulk(activities2, i);
            }
            stopwatch.Stop();
            string sMessageEnd = string.Format(" Se procesaron {0} actividades en {1} segundos, el tiempo estimado por creación de actividad es de {2}", countactivities, stopwatch.Elapsed.TotalSeconds, (stopwatch.Elapsed.TotalSeconds / countactivities));

            Console.WriteLine(sMessageEnd);
            Program.Logger(sMessageEnd, TypeLog.DEFAULT);
            Program.Logger(string.Format(" Fin de proceso {0} ", DateTime.Now), TypeLog.DEFAULT);
            Program.Logger(string.Format("************************************************************"), TypeLog.DEFAULT);
            Console.ReadLine();
        }
Exemplo n.º 3
0
        private void AnalyzingBulk(RootActivityBulk resultbulkactivity, RootActivity activities)
        {
            foreach (var item in resultbulkactivity.results)
            {
                try
                {
                    LayoutOutput layoutOutput = new LayoutOutput();
                    layoutOutput.activityId = item.activityKeys.activityId;
                    layoutOutput.apptNumber = item.activityKeys.apptNumber;
                    var tmpactivity = activities.activities.FirstOrDefault(x => x.apptNumber == item.activityKeys.apptNumber && x.customerNumber == item.activityKeys.customerNumber);
                    layoutOutput.resourceId = tmpactivity.resourceId;

                    if (string.IsNullOrEmpty(tmpactivity.date))
                    {
                        tmpactivity.date = tmpactivity.date;
                    }
                    else
                    {
                        DateTime tmpdateTime;
                        DateTime.TryParse(tmpactivity.date, out tmpdateTime);

                        if (tmpdateTime.Year != 1)
                        {
                            tmpactivity.date = tmpdateTime.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
                        }
                    }
                    layoutOutput.date     = tmpactivity.date;
                    layoutOutput.timeSlot = tmpactivity.timeSlot;
                    string horarioAgendado = string.IsNullOrEmpty(layoutOutput.timeSlot) ? string.Empty : Program.DictionaryTimeSlot[tmpactivity.timeSlot];
                    layoutOutput.horarioAgendado = horarioAgendado;
                    string resultInventory = string.Empty;

                    foreach (Item itemInventory in tmpactivity.inventories.items)
                    {
                        if (item.errors != null)
                        {
                            if (item.errors.Count > 0 && (item.errors[0].operation == "updateInventories" || item.errors[0].operation == "updateProperties"))
                            {
                                string[] tmp2 = item.errors[0].errorDetail.Split(new string[] { "Value:" }, StringSplitOptions.None);
                                string   tmp  = tmp2[1];
                                tmp = tmp.Replace("'", string.Empty);
                                tmp = tmp.Trim();

                                bool flag = false;
                                if (item.errors[0].operation == "updateInventories" && item.activityKeys.activityId > 0)
                                {
                                    resultInventory += itemInventory.inventoryType + ":400|";
                                    Program.Logger(string.Format("|{0}|* Error en la Orden de Servicio:{1}| Detalle: Inventario inexistente {2}|", DateTime.Now, layoutOutput.apptNumber, itemInventory.inventoryType), TypeLog.BAD_IO_ACTIVITY);
                                }
                                else if (item.errors[0].operation == "updateInventories" && item.activityKeys.activityId <= 0)
                                {
                                    flag = tmp == (itemInventory.inventoryType);
                                    if (flag)
                                    {
                                        resultInventory += itemInventory.inventoryType + ":400|";
                                        Program.Logger(string.Format("|{0}|* Error en la Orden de Servicio:{1}| Detalle: Inventario inexistente {2}|", DateTime.Now, layoutOutput.apptNumber, itemInventory.inventoryType), TypeLog.BAD_IO_ACTIVITY);
                                    }
                                    else
                                    {
                                        resultInventory += itemInventory.inventoryType + ":200|";
                                    }
                                }

                                else if (item.errors[0].operation == "updateProperties")
                                {
                                    flag = itemInventory.inventoryType == tmp;


                                    if (flag)
                                    {
                                        resultInventory += itemInventory.inventoryType + ":200|";
                                    }
                                    else
                                    {
                                        resultInventory += itemInventory.inventoryType + ":400|";
                                        Program.Logger(string.Format("|{0}|* Error en la Orden de Servicio:{1}| Detalle: Inventario inexistente {2}|", DateTime.Now, layoutOutput.apptNumber, itemInventory.inventoryType), TypeLog.BAD_IO_ACTIVITY);
                                    }
                                }
                            }
                        }
                        else
                        {
                            resultInventory += itemInventory.inventoryType + ":200|";
                        }
                    }

                    if (item.operationsPerformed == null)
                    {
                        layoutOutput.result = "operationsFailed " + item.errors[0].errorDetail;
                        Program.Logger(string.Format("|{0}|* Error en la Orden de Servicio:{1} | Detalle: {2}|", DateTime.Now, layoutOutput.apptNumber, layoutOutput.result), TypeLog.BAD_IO_ACTIVITY);
                    }
                    else
                    {
                        layoutOutput.result = item.operationsPerformed.FirstOrDefault();
                    }

                    // layoutOutput.result = item.operationsPerformed == null ? "operationsFailed " + item.errors[0].errorDetail : item.operationsPerformed.FirstOrDefault();
                    layoutOutput.result      = layoutOutput.result + "|" + resultInventory;
                    layoutOutput.description = "Appointment id = " + layoutOutput.activityId;
                    if (layoutOutput.activityId > 0)
                    {
                        string lineCSV = string.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};",
                                                       layoutOutput.activityId,
                                                       layoutOutput.apptNumber,
                                                       layoutOutput.typeCommand,
                                                       layoutOutput.resourceId,
                                                       layoutOutput.date,
                                                       layoutOutput.timeSlot,
                                                       layoutOutput.horarioAgendado,
                                                       layoutOutput.result,
                                                       layoutOutput.typeMessage,
                                                       layoutOutput.cod,
                                                       layoutOutput.description);

                        Program.LoggerCSV(lineCSV);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }