Esempio n. 1
0
        public CovidDataManager()
        {
            string path = System.IO.Directory.GetCurrentDirectory() + "\\sources.json";

            externalSources = new List <AddedExternalSource>();
            if (System.IO.File.Exists(path))
            {
                string json = System.IO.File.ReadAllText(path);
                externalSources.AddRange(new List <AddedExternalSource>().FromJson(json));
            }

            CsvConfiguration config = new CsvConfiguration(new CultureInfo("en-US", false));

            config.HasHeaderRecord   = true;
            config.IgnoreQuotes      = false;
            config.IgnoreBlankLines  = true;
            config.HeaderValidated   = null;
            config.MissingFieldFound = null;
            config.BadDataFound      = null;
            config.RegisterClassMap <HopkinsDataClassMap>();
            config.RegisterClassMap <CovidGermanyStateClassMap>();
            config.RegisterClassMap <WhoClassMap>();
            config.AutoMap <CovidBrazilStates>();
            config.AutoMap <CovidUSStates>();
            config.AutoMap <RKIGeneral>();
            config.AutoMap <RKILandkreis>();
            csvConfig = config;
            UpdateData();

            hopkinsData = new List <HopkinsData>();
            UpdateHopkinsAndWHO();
        }
Esempio n. 2
0
        public void Apply(CsvConfiguration config)
        {
            // see http://joshclose.github.io/CsvHelper/

            config.RegisterClassMap <RecordMap>();
            config.RegisterClassMap <MetadataMap>();
        }
Esempio n. 3
0
 public void Apply(CsvConfiguration config)
 {
     config.Delimiter      = "\t";
     config.QuoteAllFields = true;
     config.TrimFields     = true;
     config.RegisterClassMap <RecordMap>();
     config.RegisterClassMap <GeminiMap>();
 }
Esempio n. 4
0
        public void Apply(CsvConfiguration config)
        {
            config.RegisterClassMap<MarineRecorderMapping.RecordMap>();
            config.RegisterClassMap<MarineRecorderMapping.GeminiMap>();

            config.WillThrowOnMissingField = false;
            config.TrimFields = true;
        }
Esempio n. 5
0
        public void Apply(CsvConfiguration config)
        {
            // see http://joshclose.github.io/CsvHelper/

            config.TrimFields = true;
            config.RegisterClassMap <RecordMap>();
            config.RegisterClassMap <GeminiMap>();
        }
Esempio n. 6
0
        public void Apply(CsvConfiguration config)
        {
            config.Delimiter = "\t";
            config.RegisterClassMap <MyRecordMap>();
            config.RegisterClassMap <MyMetadataMap>();

            TypeConverterFactory.AddConverter <List <MetadataKeyword> >(new Exporter.MetadataKeywordConverter());
            TypeConverterFactory.AddConverter <List <Extent> >(new Exporter.ExtentListConverter());
        }
        public void MapMultipleTypesTest()
        {
            var config = new CsvConfiguration();

            config.RegisterClassMap <AMap>();
            config.RegisterClassMap <BMap>();

            Assert.IsNotNull(config.Maps[typeof(A)]);
            Assert.IsNotNull(config.Maps[typeof(B)]);
        }
Esempio n. 8
0
        public void Apply(CsvConfiguration config)
        {
            // see http://joshclose.github.io/CsvHelper/

            config.Delimiter        = "\t";
            config.QuoteAllFields   = true;
            config.TrimFields       = true;
            config.SkipEmptyRecords = true;
            config.RegisterClassMap <RecordMap>();
            config.RegisterClassMap <GeminiMap>();
        }
Esempio n. 9
0
        public void Apply(CsvConfiguration config)
        {
            config.PrefixReferenceHeaders = true;
//            TypeConverterFactory.AddConverter<List<MetadataKeyword>>(new Exporter.MetadataKeywordConverter());
//            TypeConverterFactory.AddConverter<List<Extent>>(new Exporter.ExtentListConverter());

            config.RegisterClassMap <RecordMap>();
            config.RegisterClassMap <GeminiMap>();

            // there's no id field because they deleted it
            config.WillThrowOnMissingField = false;
        }
Esempio n. 10
0
 private void config <T>(CsvConfiguration csvConfig, Configuracao config)
 {
     config = config == null ? new Configuracao() : config;
     csvConfig.Delimiter = config.Delimitador;
     csvConfig.IgnoreHeaderWhiteSpace = config.IgnoreEspacoEmBrancoHeader;
     csvConfig.TrimFields             = config.RemoverEspacoEmBrancoCampos;
     if (config.Map.Count > 0)
     {
         var customerMap  = new CsvHelper.Configuration.DefaultCsvClassMap <T>();
         var sampleObject = Activator.CreateInstance <T>();
         foreach (var map in config.Map)
         {
             var propertyInfo = sampleObject.GetType().GetProperty(map.NomeDaPropriedade);
             var newMap       = new CsvPropertyMap(propertyInfo);
             newMap.Name(map.NomeDaColuna);
             if (map.Converter != null)
             {
                 newMap.ConvertUsing(
                     row => map.Converter.Conversao(row.GetField <string>(map.Converter.NomeDaColuna))
                     );
             }
             customerMap.PropertyMaps.Add(newMap);
         }
         csvConfig.RegisterClassMap(customerMap);
     }
 }
        private IEnumerable <ILexOfficeRecord> LexOfficeRecords(IFormFile file, ISettings settings)
        {
            var config = new CsvConfiguration(CultureInfo.DefaultThreadCurrentCulture)
            {
                Delimiter       = ",",
                Encoding        = System.Text.Encoding.UTF8,
                HasHeaderRecord = true
            };

            config.RegisterClassMap(new RevolutMap());

            if (file.Length <= 0)
            {
                yield break;
            }

            var filePath = Path.GetTempFileName();

            using (var stream = System.IO.File.Create(filePath))
            {
                using var reader = new StreamReader(file.OpenReadStream());
                using var csv    = new CsvReader(reader, config);
                var result = csv.GetRecords <RevolutRecord>();
                foreach (var record in result)
                {
                    yield return(new LexOfficeRecordFromRevolutRecord(settings, record));
                }
            }
        }
Esempio n. 12
0
        private static void WriteConvertedFile(CsvConfiguration config, string fileName, Settings settings, string targetFileName)
        {
            var file = File.OpenRead(fileName);

            config.RegisterClassMap(new RevolutMap());

            if (file.Length > 0)
            {
                using (var targetFile = System.IO.File.Create(targetFileName))
                {
                    using (var reader = new StreamReader(file, true))
                        using (var csv = new CsvReader(reader, config))
                        {
                            var result = csv.GetRecords <RevolutRecord>();
                            foreach (var record in result)
                            {
                                targetFile.Write(
                                    System.Text.Encoding.UTF8.GetBytes(
                                        new LexOfficeCsvLine(
                                            new LexOfficeRecordFromRevolutRecord(settings, record)
                                            ).ToString() + "\r\n"
                                        )
                                    );
                            }
                        }
                }
                System.Console.WriteLine($"Wrote to file: {targetFileName}");
            }
        }
Esempio n. 13
0
        private static CsvConfiguration GetCsvConfig()
        {
            var config = new CsvConfiguration();

            config.RegisterClassMap <CsvItemClassMap>();
            return(config);
        }
Esempio n. 14
0
 public static void RegisterClassMapCollection(this CsvConfiguration csvConfiguration, Assembly assembly)
 {
     assembly.GetTypes()
     .Where(t => t.Name.EndsWith("Map") || t.IsSubclassOf(typeof(ClassMap)))
     .ToList()
     .ForEach(t => csvConfiguration.RegisterClassMap(t));
 }
Esempio n. 15
0
        public string WriteRecords(List <T> records, bool hasHeader, ClassMap <T> classMap, string delimiter, bool shouldQuote)
        {
            var contents = string.Empty;

            var config = new CsvConfiguration(CultureInfo.CurrentCulture)
            {
                HasHeaderRecord = hasHeader,
                TrimOptions     = TrimOptions.Trim,
                Delimiter       = delimiter,
                ShouldQuote     = (field, context) => shouldQuote,
            };

            if (classMap != null)
            {
                config.RegisterClassMap(classMap);
            }

            using (var stream = new MemoryStream())
                using (var reader = new StreamReader(stream))
                    using (var writer = new StreamWriter(stream))
                        using (var csv = new CsvWriter(writer, config))
                        {
                            csv.WriteRecords(records);
                            writer.Flush();
                            stream.Position = 0;
                            contents        = reader.ReadToEnd();
                        }

            return(contents);
        }
Esempio n. 16
0
        /// <summary>
        /// Builds the product category loader tasks.
        /// </summary>
        /// <returns>A task used to load the product category table.</returns>
        private ITask BuildProductCategoryTask()
        {
            using (var builder = new SimpleDataflowBuilder <ProductCategory>())
            {
                var categoryFile = Path.Combine(Program.Options.SourcePath, "ProductCategory.csv");

                var csvConfiguration = new CsvConfiguration {
                    HasHeaderRecord = false, Delimiter = "\t"
                };
                csvConfiguration.RegisterClassMap <ProductCategoryFileMap>();

                return(builder
                       .CsvSource(categoryFile, csvConfiguration)
                       .BulkLoad(
                           "dbo.DimProductCategory",
                           this.targetFactory,
                           new Dictionary <string, string>()
                {
                    { "AlternateKey", "ProductCategoryAlternateKey" },
                    { "Name", "EnglishProductCategoryName" },
                    { "SpanishName", "SpanishProductCategoryName" },
                    { "FrenchName", "FrenchProductCategoryName" }
                })
                       .Build("Load product category dimension"));
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Builds the product loader tasks.
        /// </summary>
        /// <returns>A task used to load the product subcategory table.</returns>
        private ITask BuildProductTask()
        {
            using (var builder = new SimpleDataflowBuilder <Product>())
            {
                var productFile = Path.Combine(Program.Options.SourcePath, "Product.csv");

                var csvConfiguration = new CsvConfiguration {
                    HasHeaderRecord = false, Delimiter = "\t"
                };
                csvConfiguration.RegisterClassMap <ProductFileMap>();

                return(builder
                       .CsvSource(productFile, csvConfiguration)
                       .Map(x =>
                {
                    x.ProductSubcategoryKey =
                        this.productSubcategoryMapper.Map(
                            x.ProductSubcategoryAlternateKey.ToString(CultureInfo.CurrentCulture));

                    return x;
                })
                       .BulkLoad(
                           "dbo.DimProduct",
                           this.targetFactory,
                           new Dictionary <string, string>()
                {
                    { "ProductSubcategoryKey", "ProductSubcategoryKey" },
                    { "AlternateKey", "ProductAlternateKey" },
                    { "Name", "EnglishProductName" },
                })
                       .Build("Load product dimension"));
            }
        }
Esempio n. 18
0
        public Repository(string musicContractsPath, string distributionContractsPath)
        {
            Check <FileNotFoundException>(File.Exists(Path.GetFullPath(musicContractsPath)), $"File doesn't exist or incorrect path: {musicContractsPath}");
            Check <FileNotFoundException>(File.Exists(Path.GetFullPath(distributionContractsPath)), $"File doesn't exist or incorrect path: {distributionContractsPath}");

            _distributionContractsPath = distributionContractsPath;
            _musicContractsPath        = musicContractsPath;

            _csvConfig = new CsvConfiguration
            {
                Delimiter       = "|",
                HasHeaderRecord = true
            };
            _csvConfig.RegisterClassMap <MusicContractMap>();
            _csvConfig.RegisterClassMap <DistributionContractMap>();
        }
Esempio n. 19
0
        public void WriteFieldTrimTest()
        {
            var record = new TestRecord
            {
                IntColumn     = 1,
                DateColumn    = new DateTime(2012, 10, 1, 12, 12, 12),
                DecimalColumn = 150.99m,
                FirstColumn   = "first column ",
            };

            var config = new CsvConfiguration {
                CultureInfo = new CultureInfo("en-US"), TrimFields = true
            };

            config.RegisterClassMap <TestRecordMap>();

            var stream = new MemoryStream();
            var writer = new StreamWriter(stream)
            {
                AutoFlush = true
            };
            var csv = new CsvWriter(writer, config);

            csv.WriteRecord(record);
            csv.NextRecord();

            stream.Position = 0;
            var reader   = new StreamReader(stream);
            var csvFile  = reader.ReadToEnd();
            var expected = "first column,0001,10/1/2012,$150.99\r\n";

            Assert.AreEqual(expected, csvFile);
        }
Esempio n. 20
0
        /// <summary>
        /// Returns records of a IMDb CSV rating or list file.
        /// </summary>
        /// <typeparam name="T">IMDbListItem or IMDbRateItem</typeparam>
        /// <param name="aFileStreamReader">CSV file stream reader</param>
        /// <returns>Records of type T</returns>
        private List <T> ParseCsvFile <T>(StreamReader aFileStreamReader)
        {
            CsvConfiguration csvConfiguration = new CsvConfiguration
            {
                IsHeaderCaseSensitive = false,

                // IMDb use "." for decimal seperator so set culture to cater for this
                CultureInfo = new System.Globalization.CultureInfo("en-US"),

                // if we're unable parse a row, log the details for analysis
                IgnoreReadingExceptions  = true,
                ReadingExceptionCallback = (ex, row) =>
                {
                    FileLog.Error($"Error reading row '{ex.Data["CsvHelper"]}'");
                }
            };

            csvConfiguration.RegisterClassMap <IMDbListCsvMap>();

            using (var csv = new CsvReader(aFileStreamReader, csvConfiguration))
            {
                List <T> records = csv.GetRecords <T>().ToList();
                aFileStreamReader.Close();

                return(records);
            }
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            var content = File.ReadAllText("..\\..\\..\\kusovkymagic.csv");

            // konfigurace cteni CSV
            var configuration = new CsvConfiguration(CultureInfo.InvariantCulture)
            {
                IncludePrivateMembers = false,
                Delimiter             = ";",
                HasHeaderRecord       = true,
                Escape = '"',
            };

            configuration.RegisterClassMap <KusovkaMapper>();
            configuration.BadDataFound = x =>
            {
                Console.Write($"- bad data: '{x.RawRecord}'");
            };
            configuration.MissingFieldFound = (headerNames, index, x) =>
            {
                Console.Write($"- field at index '{index}' was not found in: '{x.RawRecord}'.");
            };

            using (var textReader = new StringReader(content))
                using (var stringReader = new EscapeToDoubleQuoteReader(textReader))
                    using (var parser = new CsvReader(stringReader, configuration))
                    {
                        var res = parser.GetRecords <ImportKusovka>().ToList();

                        Console.Write($"READ: {res.Count} records of '{typeof(ImportKusovka).Name}'");
                    }
        }
        /// <summary>
        /// The open file.
        /// </summary>
        public void OpenFile()
        {
            try
            {
                var dataStream = new StreamReader(File.Open(this.fileName, FileMode.Open));

                var csvConfiguration = new CsvConfiguration {
                    HasHeaderRecord = true
                };
                csvConfiguration.RegisterClassMap <ValueMap>();

                var csv = new CsvReader(dataStream, csvConfiguration);
                this.data = csv.GetRecords <ValueDataRow>().ToList();

                this.StatNames = this.data.Select(x => x.Statistic).Distinct().Select(
                    x =>
                {
                    var matching = this.Stats.Where(s => s.Description == x).ToList();
                    if (matching.Count() == 1)
                    {
                        return(new ImporterStatisticMapping(matching.First(), x));
                    }

                    return(new ImporterStatisticMapping(x));
                });

                this.Stage = 1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 23
0
        public async Task <List <T> > ReadRecords <T>(IS3Path path, Func <T, bool> predicate, bool isOptional = false)
        {
            _logger.Information("Reading {Type} records from {@S3Path}", typeof(T).Name, path);

            var configuration = new CsvConfiguration
            {
                Delimiter       = "|",
                QuoteNoFields   = true,
                HasHeaderRecord = true
            };

            var customerMap = new DefaultCsvClassMap <T>();

            foreach (var prop in typeof(T).GetProperties())
            {
                var name = prop.Name.ToSnakeCase();
                var map  = new CsvPropertyMap(prop).Name(name);
                customerMap.PropertyMaps.Add(map);
            }
            configuration.RegisterClassMap(customerMap);

            try
            {
                using (var response = await _s3Client.GetObjectAsync(new GetObjectRequest {
                    BucketName = path.BucketName, Key = path.Key
                }))
                {
                    using (var responseStream = response.ResponseStream)
                    {
                        using (var streamReader = new StreamReader(responseStream))
                        {
                            using (var reader = new CsvReader(streamReader, configuration))
                            {
                                var results = reader.GetRecords <T>();
                                if (predicate != null)
                                {
                                    results = results.Where(predicate);
                                }
                                return(results.ToList());
                            }
                        }
                    }
                }
            }
            catch (AmazonS3Exception ex)
            {
                if (ex.ErrorCode == "NoSuchKey" && isOptional)
                {
                    return(new List <T>());
                }

                throw;
            }
            catch (Exception e)
            {
                _logger.Fatal("Exception when trying to read csv file: {@Message}", e.Message);
                throw;
            }
        }
Esempio n. 24
0
        public void RegisterClassMapNonGenericTest()
        {
            var config = new CsvConfiguration();

            Assert.IsNull(config.Maps[typeof(TestClass)]);
            config.RegisterClassMap(typeof(TestClassMappings));
            Assert.IsNotNull(config.Maps[typeof(TestClass)]);
        }
Esempio n. 25
0
        public void AddingMappingsWithInstanceMethodTest()
        {
            var config = new CsvConfiguration();

            config.RegisterClassMap(new TestClassMappings());

            Assert.AreEqual(2, config.Maps[typeof(TestClass)].PropertyMaps.Count);
        }
Esempio n. 26
0
        public void AddingMappingsWithGenericMethod2Test()
        {
            var config = new CsvConfiguration();

            config.RegisterClassMap <TestClassMappings>();

            Assert.AreEqual(2, config.Maps[typeof(TestClass)].PropertyMaps.Count);
        }
Esempio n. 27
0
        public void RegisterClassInstanceTest()
        {
            var config = new CsvConfiguration();

            Assert.IsNull(config.Maps[typeof(TestClass)]);
            config.RegisterClassMap(new TestClassMappings());
            Assert.IsNotNull(config.Maps[typeof(TestClass)]);
        }
        public void PropertyMapAccessTest()
        {
            var config = new CsvConfiguration();

            config.RegisterClassMap <AMap>();
            config.Maps.Find <A>().Map(m => m.AId).Ignore();

            Assert.AreEqual(true, config.Maps[typeof(A)].PropertyMaps[0].Data.Ignore);
        }
Esempio n. 29
0
        public DataImportClient()
        {
            /*
             * groups = fields.GroupBy(
             *  f => f.Substring(
             *      0, f.IndexOf('.')
             *  ), f => f.Remove(
             *      0, f.IndexOf('.') + 1
             *  )
             * ).Select(g => new Group(
             *  g.Key, g.ToArray()
             * )).OrderBy(g => g.prefix).ToArray();*/

            cfg           = new CsvConfiguration();
            cfg.Delimiter = "\t";
            cfg.DetectColumnCountChanges = true;
            cfg.TrimFields = true;
            //cfg.RegisterClassMap(typeof(Group));

            csvMapping = (Lookup <string, Lookup <string, string> >)fields.ToLookup(
                f => f.Substring(0, f.IndexOf('.')),
                f => (Lookup <string, string>)Enumerable
                .Empty <string>().ToLookup(
                    p => f.Remove(
                        0, f.IndexOf('.'))));

            /* var csvMap = new DefaultCsvClassMap<Lookup<string, string>>();
             * foreach(var group in csvMapping)
             * {
             *   foreach(var subgroup in group)
             *   {
             *       foreach(var item in subgroup)
             *       {
             *           var newMap = new CsvPropertyMap(
             *               typeof(IGrouping<string, string>).GetType().GetProperty(item.Key)
             *           );
             *       }
             *   }
             * }*/

            fileFormatMap = new DefaultCsvClassMap <FileFormatSkeleton>();
            Type ffs = typeof(FileFormatSkeleton);

            ffsFields = ffs.GetFields(BindingFlags.SetProperty).ToDictionary(f => f.Name, f => f);

            var fieldNames = fields.Select(f => new KeyValuePair <string, string>(f, f.Replace('.', '_')));

            foreach (var field in fieldNames)
            {
                var newMap = new CsvPropertyMap(
                    ffs.GetProperty(field.Value));
                newMap.Name(field.Key);
                fileFormatMap.PropertyMaps.Add(newMap);
            }

            cfg.RegisterClassMap(fileFormatMap);
        }
 public OpcConfigurationCsvReader(string configFileName)
 {
     this.configFileName = configFileName;
     csvConfiguration    = new CsvConfiguration();
     csvConfiguration.RegisterClassMap <CsvConfigurationRecordMapper>();
     csvConfiguration.IgnoreBlankLines       = true;
     csvConfiguration.IgnoreHeaderWhiteSpace = true;
     csvConfiguration.IsHeaderCaseSensitive  = false;
 }
Esempio n. 31
0
        public Fact[] Read(string message)
        {
            var csvConfig = new CsvConfiguration
            {
                Delimiter = "|",
                Encoding = Encoding.UTF8,
                HasHeaderRecord = true,
            };
            csvConfig.RegisterClassMap<FactMap>();
            csvConfig.CultureInfo = CultureInfo.InvariantCulture;

            using (var reader = new StringReader(message))
            using (var parser = new CsvHelper.CsvReader(reader, csvConfig))
            {
                return parser.GetRecords<Fact>().ToArray();
            }
        }
Esempio n. 32
0
        /// <summary>
        /// Builds a task to load the currency dimension.
        /// </summary>
        /// <returns>A task for loading the currency dimension.</returns>
        public ITask Build()
        {
            using (var builder = new SimpleDataflowBuilder<Currency>())
            {
                var currencyFile = Path.Combine(Program.Options.SourcePath, "currency.csv");

                var csvConfiguration = new CsvConfiguration { HasHeaderRecord = false, Delimiter = "\t" };
                csvConfiguration.RegisterClassMap<CurrencyFileMap>();

                return builder
                    .CsvSource(currencyFile, csvConfiguration)
                    .BulkLoad(
                        "dbo.DimCurrency",
                        this.targetFactory,
                        new Dictionary<string, string>()
                        {
                            { "AlternateKey", "CurrencyAlternateKey" },
                            { "Name", "CurrencyName" }
                        })
                    .Build("Load currency dimension");
            }
        }
Esempio n. 33
0
        /// <summary>
        /// Builds the product category loader tasks.
        /// </summary>
        /// <returns>A task used to load the product category table.</returns>
        private ITask BuildProductCategoryTask()
        {
            using (var builder = new SimpleDataflowBuilder<ProductCategory>())
            {
                var categoryFile = Path.Combine(Program.Options.SourcePath, "ProductCategory.csv");

                var csvConfiguration = new CsvConfiguration { HasHeaderRecord = false, Delimiter = "\t" };
                csvConfiguration.RegisterClassMap<ProductCategoryFileMap>();

                return builder
                    .CsvSource(categoryFile, csvConfiguration)
                    .BulkLoad(
                        "dbo.DimProductCategory",
                        this.targetFactory,
                        new Dictionary<string, string>()
                        {
                            { "AlternateKey", "ProductCategoryAlternateKey" },
                            { "Name", "EnglishProductCategoryName" },
                            { "SpanishName", "SpanishProductCategoryName" },
                            { "FrenchName", "FrenchProductCategoryName" }
                        })
                    .Build("Load product category dimension");
            }
        }
Esempio n. 34
0
        // Import des raws
        private ICollection<OperationRawSG> ExtraireRaws(StreamReader streamReader, IList<string> _erreurs)
        {
            /* A new configuration instance that you can change at will */
            CsvConfiguration config = new CsvConfiguration();
            config.Delimiter = ";";
            config.RegisterClassMap<SGOperationRawMapClass>();

            /* Give it to your CsvReader */
            CsvReader csvReader = new CsvReader(streamReader, config);
            IEnumerable<OperationRawSG> _raws = new List<OperationRawSG>();
            try
            {
                _raws = csvReader.GetRecords<OperationRawSG>().Reverse().ToList();
                foreach (var item in _raws)
                {
                    item.Etat = EtatOperationRaw.CREEE;
                    item.Libelle = this.Egaliser(item.Libelle);
                    item.Detail = this.Egaliser(item.Detail);
                }
            }
            catch (Exception e)
            {
                var message = "Les écritures du fichier importé ne semblent pas correctement formattées. Etês-vous certain de charger un fichier Société générale ?";
                _erreurs.Add(message);
                var message2 = e.Message;
                _erreurs.Add(message2);
            }

            // return
            return _raws.ToList();
        }
Esempio n. 35
0
        /// <summary>
        /// Builds the product loader tasks.
        /// </summary>
        /// <returns>A task used to load the product subcategory table.</returns>
        private ITask BuildProductTask()
        {
            using (var builder = new SimpleDataflowBuilder<Product>())
            {
                var productFile = Path.Combine(Program.Options.SourcePath, "Product.csv");

                var csvConfiguration = new CsvConfiguration { HasHeaderRecord = false, Delimiter = "\t" };
                csvConfiguration.RegisterClassMap<ProductFileMap>();

                return builder
                    .CsvSource(productFile, csvConfiguration)
                    .Map(x =>
                    {
                        x.ProductSubcategoryKey =
                            this.productSubcategoryMapper.Map(
                                x.ProductSubcategoryAlternateKey.ToString(CultureInfo.CurrentCulture));

                        return x;
                    })
                    .BulkLoad(
                        "dbo.DimProduct",
                        this.targetFactory,
                        new Dictionary<string, string>()
                        {
                            { "ProductSubcategoryKey", "ProductSubcategoryKey" },
                            { "AlternateKey", "ProductAlternateKey" },
                            { "Name", "EnglishProductName" },
                        })
                    .Build("Load product dimension");
            }
        }
        private void OnCommandExportContent(object sender, EventArgs e) {
            // Export to CSV
            IDataMigrationView view = base._view as IDataMigrationView;
            IDataMigrationModel model = base._model as IDataMigrationModel;
            PresenterBase.SetModelPropertiesFromView<IDataMigrationModel, IDataMigrationView>(
                ref model, view
            );
            IMainPresenter presenter = SimpleResolver.Instance.Get<IMainPresenter>();
            try {
                if (SyncContext != null) {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(false);
                        presenter.ActivateSpinner(true);
                        presenter.UpdateProgressInfo("Preparing Report...");
                    }, null);
                }

                FileInfo fileInfo = new FileInfo(model.OutputFileName);
                if (Directory.Exists(fileInfo.DirectoryName)) {
                    Thread writeReport = new Thread(() => {
                        CsvConfiguration config = new CsvConfiguration() {
                            HasHeaderRecord = true,
                            Delimiter = ",",
                            Encoding = System.Text.Encoding.UTF8
                        };
                        config.RegisterClassMap(new DataMigrationHeaderMap());
                        int total = model.Contents.Count;
                        using (CsvWriter writer = new CsvWriter(new StreamWriter(model.OutputFileName), config)) {
                            writer.WriteHeader<DataMigrationHeaderRecord>();
                            for (int i = 0; i < model.Contents.Count; i++) {
                                ContentDisplayListViewItemModel lvItem = model.Contents[i];
                                writer.WriteField<string>(!string.IsNullOrEmpty(lvItem.OwnerName) ? lvItem.OwnerName : "");
                                writer.WriteField<string>(lvItem.Email);
                                writer.WriteField<string>(lvItem.ItemPathDisplay);
                                writer.WriteField<string>(!string.IsNullOrEmpty(lvItem.ItemPathId) ? lvItem.ItemPathId : "");
                                writer.WriteField<string>(lvItem.ItemName);
                                writer.WriteField<string>(!string.IsNullOrEmpty(lvItem.ItemId) ? lvItem.ItemId : "");
                                writer.WriteField<string>(lvItem.ItemType);
                                writer.WriteField<string>(!string.IsNullOrEmpty(lvItem.ItemSize) ? lvItem.ItemSize : "");
                                writer.WriteField<string>(!string.IsNullOrEmpty(lvItem.Created) ? lvItem.Created : "");
                                writer.WriteField<string>(!string.IsNullOrEmpty(lvItem.LastModified) ? lvItem.LastModified : "");
                                writer.WriteField<string>(!string.IsNullOrEmpty(lvItem.Uploaded) ? lvItem.Uploaded : "");
                                writer.NextRecord();

                                if (SyncContext != null) {
                                    SyncContext.Post(delegate {
                                        presenter.UpdateProgressInfo(string.Format("Writing Record: {0}/{1}", (i + 1), total));
                                    }, null);
                                }
                            }
                        }

                        if (SyncContext != null) {
                            SyncContext.Post(delegate {
                                presenter.EnableControl(true);
                                presenter.ActivateSpinner(false);
                                presenter.UpdateProgressInfo("Completed");
                            }, null);
                        }
                    });
                    writeReport.Start();
                } else {
                    throw new InvalidDataException(ErrorMessages.INVALID_EXPORT_FOLDER);
                }
            } catch (Exception ex) {
                if (SyncContext != null) {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(true);
                        presenter.ActivateSpinner(false);
                        presenter.UpdateProgressInfo("Completed with exception: " + ex.Message);
                    }, null);
                }
            }
        }