Пример #1
0
        public IHttpActionResult GetCurrency(string userLogin)
        {
            var syncSettings = _syncSettingsService.GetSettingsByAccountName(userLogin);

            if (syncSettings == null || string.IsNullOrEmpty(syncSettings.ProductsCategoryId))
            {
                return(Ok());
            }
            return(Ok(_commerceService.GetAllCurrencies().FirstOrDefault(x => x.Code == _storeService.GetById(syncSettings.ProductsCategoryId)?.DefaultCurrency)));
        }
Пример #2
0
        // Only public methods can be invoked in the background. (Hangfire)
        public void BackgroundExport(Data.Model.CsvExportInfo exportInfo, ExportNotification notifyEvent)
        {
            var currencies      = _commerceService.GetAllCurrencies();
            var defaultCurrency = currencies.First(x => x.IsPrimary);

            exportInfo.Currency = exportInfo.Currency ?? defaultCurrency.Code;
            var catalog = _catalogService.GetById(exportInfo.CatalogId);

            if (catalog == null)
            {
                throw new NullReferenceException("catalog");
            }

            Action <ExportImportProgressInfo> progressCallback = x =>
            {
                notifyEvent.InjectFrom(x);
                _notifier.Upsert(notifyEvent);
            };

            using (var stream = new MemoryStream())
            {
                try
                {
                    exportInfo.Configuration = Data.Model.CsvProductMappingConfiguration.GetDefaultConfiguration();
                    _csvExporter.DoExport(stream, exportInfo, progressCallback);

                    stream.Position = 0;
                    var fileNameTemplate = _settingsManager.GetValue("CsvCatalogImport.ExportFileNameTemplate", string.Empty);
                    var fileName         = string.Format(fileNameTemplate, DateTime.UtcNow);
                    fileName = Path.ChangeExtension(fileName, ".csv");

                    var blobRelativeUrl = Path.Combine("temp", fileName);

                    //Upload result csv to blob storage
                    using (var blobStream = _blobStorageProvider.OpenWrite(blobRelativeUrl))
                    {
                        stream.CopyTo(blobStream);
                    }
                    //Get a download url
                    notifyEvent.DownloadUrl = _blobUrlResolver.GetAbsoluteUrl(blobRelativeUrl);
                    notifyEvent.Description = "Export finished";
                }
                catch (Exception ex)
                {
                    notifyEvent.Description = "Export failed";
                    notifyEvent.Errors.Add(ex.ExpandExceptionMessage());
                }
                finally
                {
                    notifyEvent.Finished = DateTime.UtcNow;
                    _notifier.Upsert(notifyEvent);
                }
            }
        }
Пример #3
0
        // Only public methods can be invoked in the background. (Hangfire)
        public void BackgroundExport(CsvExportInfo exportInfo, ExportNotification notifyEvent)
        {
            var currencies      = _commerceService.GetAllCurrencies();
            var defaultCurrency = currencies.First(x => x.IsPrimary);

            exportInfo.Currency = exportInfo.Currency ?? defaultCurrency.Code;
            var catalog = _catalogService.GetById(exportInfo.CatalogId);

            if (catalog == null)
            {
                throw new NullReferenceException("catalog");
            }

            Action <ExportImportProgressInfo> progressCallback = (x) =>
            {
                notifyEvent.InjectFrom(x);
                _notifier.Upsert(notifyEvent);
            };

            using (var stream = new MemoryStream())
            {
                try
                {
                    exportInfo.Configuration = CsvProductMappingConfiguration.GetDefaultConfiguration();
                    _csvExporter.DoExport(stream, exportInfo, progressCallback);

                    stream.Position = 0;
                    var blobRelativeUrl = "temp/Catalog-" + catalog.Name + "-export.csv";
                    //Upload result csv to blob storage
                    using (var blobStream = _blobStorageProvider.OpenWrite(blobRelativeUrl))
                    {
                        stream.CopyTo(blobStream);
                    }
                    //Get a download url
                    notifyEvent.DownloadUrl = _blobUrlResolver.GetAbsoluteUrl(blobRelativeUrl);
                    notifyEvent.Description = "Export finished";
                }
                catch (Exception ex)
                {
                    notifyEvent.Description = "Export failed";
                    notifyEvent.Errors.Add(ex.ExpandExceptionMessage());
                }
                finally
                {
                    notifyEvent.Finished = DateTime.UtcNow;
                    _notifier.Upsert(notifyEvent);
                }
            }
        }
Пример #4
0
        private BackupObject GetBackupObject(Action <ExportImportProgressInfo> progressCallback)
        {
            progressCallback(new ExportImportProgressInfo("fulfillmentCenters loading"));
            var fulfillments = _commerceService.GetAllFulfillmentCenters().ToArray();

            progressCallback(new ExportImportProgressInfo(string.Format("fulfillmentCenters loaded: {0}", fulfillments.Count())));

            progressCallback(new ExportImportProgressInfo("currencies loading"));
            var currencies = _commerceService.GetAllCurrencies().ToArray();

            progressCallback(new ExportImportProgressInfo(string.Format("currencies loaded: {0}", currencies.Count())));
            return(new BackupObject()
            {
                FulfillmentCenters = fulfillments,
                Currencies = currencies
            });
        }
        private BackupObject GetBackupObject(Action <ExportImportProgressInfo> progressCallback)
        {
            progressCallback(new ExportImportProgressInfo("currencies loading"));
            var currencies = _commerceService.GetAllCurrencies().ToArray();

            progressCallback(new ExportImportProgressInfo(string.Format("currencies loaded: {0}", currencies.Count())));

            progressCallback(new ExportImportProgressInfo("package types loading"));
            var packageTypes = _commerceService.GetAllPackageTypes().ToArray();

            progressCallback(new ExportImportProgressInfo(string.Format("package types  loaded: {0}", packageTypes.Count())));

            return(new BackupObject()
            {
                Currencies = currencies,
                PackageTypes = packageTypes
            });
        }
        public IHttpActionResult GetAllCurrencies()
        {
            var retVal = _commerceService.GetAllCurrencies().ToArray();

            return(Ok(retVal));
        }
 public IEnumerable <Currency> GetAllCurrencies()
 {
     return(_commerceService.GetAllCurrencies());
 }