예제 #1
0
        private static void RunAsync(object mapper)
        {
            try
            {
                ExcelMapper <Circuito> _circuito_excel_mapper = (mapper is ExcelMapper <Circuito>) ?
                                                                (ExcelMapper <Circuito>)mapper : new ExcelMapper <Circuito>();

                ClienteCircuito circuitoClient = new ClienteCircuito();
                ClienteContacto contactoClient = new ClienteContacto(circuitoClient.Token);

                Task <IEnumerable <Circuito> > _task_circuitos = circuitoClient.GetCircuitos();
                Task <IEnumerable <Cliente> >  _task_clientes  = contactoClient.GetContactos();

                Task _task_circuitos_completed = _task_circuitos.ContinueWith(
                    async(_task_completed) =>
                {
                    List <Circuito> circuitos = (_task_completed.Result != null ? _task_completed.Result.ToList() : null);
                    if (circuitos != null && circuitos.Count > 0)
                    {
                        bool exported = await RunExportAndUploadTaskAsync <Circuito>(circuitos);
                    }
                    else
                    {
                        Console.WriteLine($"Service was unable to retrieve data ({nameof(Circuito)})");
                    }
                });

                Task _task_clientes_completed = _task_clientes.ContinueWith(
                    async(_task_completed) =>
                {
                    List <Cliente> clientes = (_task_completed.Result != null ? _task_completed.Result.ToList() : null);
                    if (clientes != null && clientes.Count > 0)
                    {
                        bool exported = await RunExportAndUploadTaskAsync <Cliente>(clientes);
                    }
                    else
                    {
                        Console.WriteLine($"Service was unable to retrieve data ({nameof(Cliente)})");
                    }
                });

                Task.WhenAll(_task_circuitos, _task_clientes).ContinueWith(
                    (done) =>
                {
                    Console.WriteLine(string.Format("Data retrieved successfully"));
                });

                Task.WhenAll(_task_circuitos_completed, _task_clientes_completed).ContinueWith(
                    (done) =>
                {
                    Console.WriteLine($"Files exported and uploaded successfullly");
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.Source);
                Console.WriteLine(ex.StackTrace);
            }
        }
예제 #2
0
        private void RunAsync(object mapper)
        {
            string _methodName = nameof(RunAsync);

            try
            {
                ExcelMapper <Circuito> excelMapper = (mapper is ExcelMapper <Circuito>) ?
                                                     (ExcelMapper <Circuito>)mapper : new ExcelMapper <Circuito>();

                ClienteCircuito circuitoClient = new ClienteCircuito();
                ClienteContacto contactoClient = new ClienteContacto(circuitoClient.Token);

                Task <IEnumerable <Circuito> > _task_circuitos = circuitoClient.GetCircuitos();
                Task <IEnumerable <Cliente> >  _task_clientes  = contactoClient.GetContactos();

                Task _task_circuitos_completed = _task_circuitos.ContinueWith(
                    async(_task_completed) =>
                {
                    List <Circuito> circuitos = (_task_completed.Result != null ? _task_completed.Result.ToList() : null);
                    if (circuitos != null && circuitos.Count > 0)
                    {
                        bool success = await RunExportAndUploadTaskAsync <Circuito>(circuitos);
                        if (success)
                        {
                            this.Logger.WriteEntry($"On {_methodName}: Exporting and Uploading Task ({nameof(Circuito)}) completed successfully", EventLogEntryType.Information);
                        }
                        else
                        {
                            this.Logger.WriteEntry($"On {_methodName}: Service was unable to retrieve data ({nameof(Circuito)})", EventLogEntryType.Information);
                        }
                    }
                });

                Task _task_clientes_completed = _task_clientes.ContinueWith(
                    async(_task_completed) =>
                {
                    List <Cliente> clientes = (_task_completed.Result != null ? _task_completed.Result.ToList() : null);
                    if (clientes != null && clientes.Count > 0)
                    {
                        bool success = await RunExportAndUploadTaskAsync <Cliente>(clientes);
                        if (success)
                        {
                            this.Logger.WriteEntry($"On {_methodName}: Exporting and Uploading Task ({nameof(Cliente)}) completed successfully", EventLogEntryType.Information);
                        }
                        else
                        {
                            this.Logger.WriteEntry($"On {_methodName}: Service was unable to retrieve data ({nameof(Cliente)})", EventLogEntryType.Information);
                        }
                    }
                });

                Task.WhenAll(_task_circuitos, _task_clientes).ContinueWith(
                    (done) =>
                {
                    this.Logger.WriteEntry($"On {_methodName}: Data ({nameof(Cliente)} and {nameof(Circuito)}) retrieved successfully", EventLogEntryType.Information);
                });

                Task.WhenAll(_task_circuitos_completed, _task_clientes_completed).ContinueWith(
                    (done) =>
                {
                    this.Logger.WriteEntry($"On {_methodName}: Files ({nameof(Cliente)} and {nameof(Circuito)}) exported and uploaded successfullly", EventLogEntryType.Information);
                });
            }
            catch (Exception ex)
            {
                this.Logger.WriteEntry(string.Format("On RunAsync: {0}", ex.Message), EventLogEntryType.Error);
                this.Logger.WriteEntry(string.Format("On RunAsync: {0}", ex.Source), EventLogEntryType.Error);
                this.Logger.WriteEntry(string.Format("On RunAsync: {0}", ex.StackTrace), EventLogEntryType.Error);
                this.Logger.WriteEntry(string.Format("On RunAsync: {0}", ex.InnerException.Message), EventLogEntryType.Error);
            }
        }