protected override void ExecuteConnectorTask() { Monitoring.Notify(Name, 0); var destination = new DirectoryInfo(Destination); if (!destination.FullName.EndsWith("$") && !destination.Exists) { TraceError("{0}: The directory '{1}' does not exists!", Context.Name, destination.FullName); } else if (!destination.FullName.EndsWith("$") && !destination.HasAccess(FileSystemRights.FullControl)) { TraceError("{0}: The user '{1}' has insufficient access over the directory '{2}'!" , Context.Name , WindowsIdentity.GetCurrent().Name , destination.FullName); } else { PriceRules = Context.ContentPrices .OrderByDescending(priceRule => priceRule.ContentPriceRuleIndex) .ToArray(); var differentialProvider = new DifferentialProvider(Path.Combine(Constants.Directories.History, Context.Name)); var articles = GetArticles() .Select(UpdateArticlePricing) .ToArray(); articles = differentialProvider .GetDifferential(articles, ArticleCommercialComparer.Default) .ToArray(); if (articles.Any()) { var articleFile = Path.Combine(destination.FullName, String.Format("{0}_{1:yyyyMMddHHmmss}.csv", MultiMagCode, DateTime.Now)); TraceVerbose("{0}: Writing {1} articles to file '{2}'...", Context.Name, articles.Length, Path.GetFileName(articleFile)); using (var streamWriter = new StreamWriter(articleFile)) using (var csvWriter = new CsvWriter(streamWriter)) { csvWriter.Configuration.Delimiter = ";"; csvWriter.Configuration.RegisterClassMap <ExportArticleMapping>(); csvWriter.WriteHeader <Article>(); csvWriter.WriteRecords(articles); TraceInformation("{0}: {1} articles written to file '{2}'!", Context.Name, articles.Length, Path.GetFileName(articleFile)); } } else { TraceWarning("{0}: There are no articles generated for export...", Context.Name); } } Monitoring.Notify(Name, 1); }
protected override void ExecuteConnectorTask() { Monitoring.Notify(Name, 0); var destination = new DirectoryInfo(Destination); if (!destination.Exists) { TraceError("{0}: The directory '{1}' does not exists!", Context.Name, destination.FullName); } else { var consolidateConnectors = Unit.Scope .Repository <ConnectorSystem>() .Include(connectorSystem => connectorSystem.Connectors) .GetAll(connectorSystem => connectorSystem.Name == Constants.Connector.System.Magento /* || connectorSystem.Name == Constants.Connector.System.MultiMag */) .SelectMany(connectorSystem => connectorSystem.Connectors) .ToArray(); var repositoryDirectory = new DirectoryInfo(Constants.Directories.Repository); if (!repositoryDirectory.Exists) { repositoryDirectory.Create(); } var differentialProvider = new DifferentialProvider(Path.Combine(Constants.Directories.History, Context.Name)); foreach (var fileGrouping in repositoryDirectory .GetFiles("??_???_*" + Constants.Extensions.CSV) .OrderByDescending(fileInfo => fileInfo.LastWriteTime) .GroupBy(fileInfo => fileInfo.Name.Substring(0, 2).ToUpper())) { var destinationFileName = String.Format("{0}_{1:yyyyMMdd_HHmmss}" + Constants.Extensions.CSV, fileGrouping.Key, DateTime.Now); var destinationFileInfo = new FileInfo(Path.Combine(destination.FullName, destinationFileName)); try { switch (fileGrouping.Key) { case Constants.Prefixes.Customer: var customers = fileGrouping .SelectMany(Import <Customer, CustomerMapping>) .ToArray(); customers = GetCustomers().Concat(customers).Distinct().ToArray(); customers = differentialProvider.GetDifferential(customers).ToArray(); Export <Customer, CustomerMapping>(destinationFileInfo, customers); break; case Constants.Prefixes.Items: var items = fileGrouping .SelectMany(Import <Item, ItemMapping>) .Distinct() .ToArray(); items = differentialProvider .GetDifferential(items) .ToArray(); Export <Item, ItemMapping>(destinationFileInfo, items); break; case Constants.Prefixes.Movements: var movements = fileGrouping .SelectMany(Import <Movement, MovementMapping>) .Distinct() .ToArray(); movements = differentialProvider .GetDifferential(movements) .ToArray(); Export <Movement, MovementMapping>(destinationFileInfo, movements); break; case Constants.Prefixes.Statistics: var statistics = fileGrouping .SelectMany(Import <Statistic, StatisticMapping>) .Distinct() .ToArray(); statistics = differentialProvider .GetDifferential(statistics) .ToArray(); Export <Statistic, StatisticMapping>(destinationFileInfo, statistics); break; case Constants.Prefixes.Stock: var stock = fileGrouping .SelectMany(Import <Stock, StockMapping>) .Distinct() .ToArray(); stock = differentialProvider .GetDifferential(stock) .ToArray(); Export <Stock, StockMapping>(destinationFileInfo, stock); break; case Constants.Prefixes.Transaction: var orders = fileGrouping .SelectMany(Import <Order, OrderMapping>) .ToArray(); orders = GetOrders(consolidateConnectors) .Concat(orders) .Distinct() .ToArray(); orders = differentialProvider .GetDifferential(orders) .ToArray(); Export <Order, OrderMapping>(destinationFileInfo, orders); break; default: break; } } catch (Exception exception) { TraceCritical(exception); } } } Monitoring.Notify(Name, 1); }