Beispiel #1
0
        public void Import()
        {
            //var a = Logictracker.Process.Import.Client.Types.Properties.GetAs("Codigo",typeof (Logictracker.Process.Import.Client.Types.Properties.Cliente));

            //var d = new Data();
            //d.Entity = (int)Entities.ReferenciaGeografica;
            //var b = EntityParserFactory.GetEntityParser(d);

            /*
             * var a =
             *  "planta,nro_pedido,nro_viaje,cod_client,nombre_cli,cod_obra,obra,direccion,latitud,longitud,fecha,cod_prod,nro_remito,cod_chofer,nomb_chof,cod_camion,m3viaje,m3sol,m3ajus,m3entre,m3saldo,abm,gmt";
             * var b =
             *  @"0025,100,1,""40002"",""cliente 40002"",10,""Obra 10"",""Uruguay 540, Buenos Aires, Ciudad Autónoma de Buenos Aires, Argentina"",""-34.6023370"","" -58.3866890"",28/05/2011 00:00:00,""ART 1"",58433,999,""Chofer 999"",900,0,0,0,0,0,"" "",-3";
             *
             * var csv = new CsvDataStrategy(new IDataSourceParameter[0]);
             *
             * var a1 = csv.Split(a);
             * var b1 = csv.Split(b);
             */
            var parser = ParserFactory.GetEntityParser(new Entity {
                Type = "Cliente"
            });
        }
Beispiel #2
0
        public void Process()
        {
            if (!Login())
            {
                return;
            }

            var transform = DataTransformFactory.GetDataTransform(-1);

            if (transform == null)
            {
                throw new DataTransformException();
            }

            var connectionError = false;

            foreach (var import in Configuration.Import)
            {
                if (connectionError)
                {
                    break;
                }
                var imported = 0;

                var strategy = import.DataSource.DataStrategy;
                var newData  = strategy.GetNewData();
                if (newData == null || newData.Rows.Count == 0)
                {
                    continue;
                }

                var parsers = import.Entity.Select(ent => ParserFactory.GetEntityParser(ent)).Where(parser => parser != null);

                foreach (var row in newData.Rows)
                {
                    if (connectionError)
                    {
                        break;
                    }
                    try
                    {
                        foreach (var parser in parsers)
                        {
                            var data = parser.Parse(row);

                            if (data.Operation == -1)
                            {
                                continue;
                            }

                            var encodedData = transform.Encode(data);

                            Logger.Info("Importing data with session: " + SessionToken);
                            var result = Server.Import.ImportData(SessionToken, ConfigImportClient.Company, ConfigImportClient.Branch, encodedData, data.Version);

                            if (!result.RespuestaOk && !IsSessionActive())
                            {
                                Logger.Info("Inactive session: " + SessionToken);
                                Login();
                                Logger.Info("Importing data with session: " + SessionToken);
                                result = Server.Import.ImportData(SessionToken, ConfigImportClient.Company, ConfigImportClient.Branch, encodedData, data.Version);
                            }

                            if (!result.RespuestaOk)
                            {
                                throw new ApplicationException(result.Mensaje);
                            }
                            imported++;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.GetType() == typeof(TimeoutException))
                        {
                            Logger.Error("Error de conexión. No se puede acceder al server.");
                            connectionError = true;
                        }
                        else
                        {
                            Logger.Error(ex);
                        }

                        // TODO: Guardar Registro como mal importado en archivo de errores para reprocesar (csv)
                    }
                }

                if (imported == 0 || connectionError)
                {
                    import.DataSource.DataStrategy.Revert();
                }
            }
        }