Ejemplo n.º 1
0
        public static dynamic FileInClass(MemoryStream ms, dynamic @class, GeracaoArquivo _parameters)
        {
            dynamic file = null;

            switch ((ETipoArquivo)_parameters.IdTipoArquivo)
            {
            case ETipoArquivo.CSV:
                file = MappingCSV.CsvToClass(@class, ms, _parameters.Header);
                break;

            case ETipoArquivo.XLS:
                //implementar caso precise
                break;

            case ETipoArquivo.XLSX:
                //implementar caso precise
                break;

            case ETipoArquivo.TXT:
                //implementar caso precise
                break;

            default:
                break;
            }

            return(file);
        }
Ejemplo n.º 2
0
        public async void Startup()
        {
            Stopwatch watch;
            long elapsedMs = 0;

            try
            {
                _logger.LogInformation(string.Format(LogsProcess.InitProcess, Variables.Processum, DateTime.Now.ToString()));

                watch = Stopwatch.StartNew();

                var chromeOptions = new ChromeOptions();

                _parametersProcessum = await GetGeracaoArquivo(Convert.ToInt32(_configuration.GetSection("AppConfiguration")["IdGeracaoArquivo"]));

                @class = _cache.GetOrCreate(_parametersProcessum.Descricao, x =>
                {
                    x.SetPriority(CacheItemPriority.NeverRemove);

                    return ConstructClass.CreateNewObject(_parametersProcessum);
                });

                chromeOptions.AddUserProfilePreference("download.default_directory", _parametersProcessum.CaminhoArquivo);

                expectedFilePath = string.Concat(_parametersProcessum.CaminhoArquivo, @"\", _parametersProcessum.NomeArquivo);

                using (driver = new ChromeDriver(_configuration.GetSection("Selenium")["ChromeDriver"], chromeOptions))
                {
                    driver.Navigate().GoToUrl(_configuration.GetSection("AppConfiguration")["UrlSite"]);

                    LoginSite();
                    GenerateFile();
                    StreamingExchange();

                    var fileExists = DowloadFile();

                    if (fileExists)
                    {
                        TreatFile();
                    }

                    Cancellation();
                }

                watch.Stop();

                elapsedMs = watch.ElapsedMilliseconds;

                _logger.LogInformation(string.Format(LogsProcess.FinishProcess, Variables.Processum, DateTime.Now.ToString()));
                _logger.LogInformation(string.Format(LogsProcess.TimeExecution, Variables.Processum, elapsedMs.ToString()));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Format(LogsProcess.ErrorMethod, Variables.ProcessumServiceStartup));

                throw ex;
            }
        }
        public static dynamic CreateNewObject(GeracaoArquivo @class)
        {
            typeFile = (ETipoArquivo)@class.IdTipoArquivo;

            var myType   = CompileResultType(@class);
            var myObject = (dynamic)Activator.CreateInstance(myType);

            return(myObject);
        }
        public static Type CompileResultType(GeracaoArquivo @class)
        {
            TypeBuilder        tb          = GetTypeBuilder(@class.Descricao);
            ConstructorBuilder constructor = tb.DefineDefaultConstructor(MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);

            foreach (GeracaoArquivoClasse propriedade in @class.GeracaoArquivoClasse)
            {
                CreateProperty(tb, propriedade);
            }

            Type objectType = tb.CreateType();

            return(objectType);
        }
Ejemplo n.º 5
0
        public async static void SetStreamingNotifications(ExchangeService service, ManualResetEvent rEvent, GeracaoArquivo parameters)
        {
            resetEvent  = rEvent;
            _parameters = parameters;

            StreamingSubscription subscription;

            subscription = await service.SubscribeToStreamingNotifications(
                new FolderId[] { WellKnownFolderName.Inbox },
                EventType.NewMail);

            StreamingSubscriptionConnection connection = new StreamingSubscriptionConnection(service, parameters.GeracaoArquivoEmail.TempoStreaming);

            connection.AddSubscription(subscription);
            connection.OnNotificationEvent += OnEvent;
            connection.OnDisconnect        += OnDisconnect;
            connection.Open();

            bool status = connection.IsOpen;
        }
Ejemplo n.º 6
0
        public async void TreatFile(dynamic fileInClass, dynamic @class, GeracaoArquivo _parameters)
        {
            try
            {
                Stopwatch watch;
                long      elapsedMs = 0;

                watch = Stopwatch.StartNew();

                _logger.LogInformation(string.Format(LogsProcess.InitProcess, Variables.ExcelTreatFile, DateTime.Now.ToString()));

                var dynamicExpression = typeof(DynamicExpressions);

                var programInfo = dynamicExpression.GetMethod(Variables.DataGenerateWithExpression);
                var dataGenerateWithExpression = programInfo.MakeGenericMethod((Type)@class.GetType());

                FileStream fileDePara = null;

                var propertyInfos = ((object)@class).GetType().GetProperties();

                var ExcelDeParaProperties = await GetExcelDePara(_parameters.IdGeracaoArquivo);

                if (_parameters.IdGeracaoArquivoDeParaNavigation.IdTemplateArquivoDeParaNavigation != null)
                {
                    //Tem template

                    fileDePara = new FileStream(_parameters.
                                                IdGeracaoArquivoDeParaNavigation.
                                                IdTemplateArquivoDeParaNavigation.
                                                CaminhoArquivo, FileMode.Open, FileAccess.Read);
                }

                using (ExcelPackage package = new ExcelPackage(fileDePara))
                {
                    var ws = package.Workbook.Worksheets.First();

                    if (ExcelDeParaProperties.Where(x => x.IsCollection).Count() > 0)
                    {
                        ws.Cells[2, 1].LoadFromCollection(fileInClass);

                        return;
                    }

                    foreach (var item in ExcelDeParaProperties)
                    {
                        var data = (dynamic)dataGenerateWithExpression.
                                   Invoke(null, new object[] { item.NomePropriedade, fileInClass });

                        ws.Cells[item.ColumnPosition].LoadFromCollection(data);
                    }

                    ws.Cells.AutoFitColumns();

                    var nameFile = Guid.NewGuid().ToString().Replace("-", "");

                    FileInfo excelFile = new FileInfo($@"{_parameters.IdGeracaoArquivoDeParaNavigation.CaminhoSaida}\{nameFile}.xlsx");
                    package.SaveAs(excelFile);
                }

                watch.Stop();

                elapsedMs = watch.ElapsedMilliseconds;

                _logger.LogInformation(string.Format(LogsProcess.FinishProcess, Variables.ExcelTreatFile, DateTime.Now.ToString()));
                _logger.LogInformation(string.Format(LogsProcess.TimeExecution, Variables.ExcelTreatFile, elapsedMs.ToString()));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Format(LogsProcess.ErrorMethod, Variables.ExcelTreatFile));

                throw ex;
            }
        }