public IHttpActionResult DoImport(StoreImportConfiguration importConfiguration)
		{
			var notification = new ImportNotification(CurrentPrincipal.GetCurrentUserName())
			{
				Title = "Import store task",
				Description = "starting import...."
			};
			_notifier.Upsert(notification);

            var importJob = new BackupStoreJob();
		    BackgroundJob.Enqueue(() =>
		            importJob.DoImport(importConfiguration, notification));

			return Ok(notification);
		}
Example #2
0
        public IHttpActionResult DoImport(StoreImportConfiguration importConfiguration)
        {
            var notification = new ImportNotification(CurrentPrincipal.GetCurrentUserName())
            {
                Title       = "Import store task",
                Description = "starting import...."
            };

            _notifier.Upsert(notification);

            var importJob = new BackupStoreJob();

            BackgroundJob.Enqueue(() =>
                                  importJob.DoImport(importConfiguration, notification));

            return(Ok(notification));
        }
Example #3
0
        public virtual void DoImport(StoreImportConfiguration importConfiguration, ImportNotification notification)
        {
            if (string.IsNullOrEmpty(importConfiguration.FileUrl))
            {
                throw new Exception("FileUrl is null or empty. Can't import.");
            }
            //Notification
            notification.Description = "loading ...";
            _notifier.Upsert(notification);

            try
            {
                var backup = new Backup(_blobStorageProvider, null);
                backup.OpenBackup(importConfiguration.FileUrl);

                // Extract objects from backup
                var store = backup.LoadObject<Store>(_stopeXmlName);
                if (store != null)
                {
                    store.Languages = backup.LoadObject<string[]>(_storeLanguagesXmlName);
                    store.Currencies = backup.LoadObject<CurrencyCodes[]>(_storeCurrenciesXmlName);
                    store.SeoInfos = backup.LoadObject<SeoInfo[]>(_storeSeoXmlName);
                    store.PaymentMethods = backup.LoadObjectsByMask<PaymentMethod>(_paymentMethodXmlNamePrefix).ToArray();
                    store.ShippingMethods = backup.LoadObjectsByMask<ShippingMethod>(_shippingMethodXmlNamePrefix).ToArray();
                    var settings = backup.LoadObject<SettingEntry[]>(_settingsXmlName);

                    var storeSettings = settings.Where(x => x.ObjectId == store.Id).ToArray();
                    
                    // Clear ids of collections to prevent dublicate ids 
                    //todo check exists or not added payment and shipping modules
                    if (store.PaymentMethods != null)
                    {
                        store.PaymentMethods.ForEach(x => x.Id = null);
                    }
                    if (store.ShippingMethods != null)
                    {
                        store.ShippingMethods.ForEach(x => x.Id = null);
                    }
                    if (store.SeoInfos != null)
                    {
                        store.SeoInfos.ForEach(x => x.Id = null);
                    }


                    if (!string.IsNullOrEmpty(importConfiguration.NewStoreName))
                    {
                        store.Name = importConfiguration.NewStoreName;
                    }
                    if (!string.IsNullOrEmpty(importConfiguration.NewStoreId))
                    {
                        store.Id = importConfiguration.NewStoreId;
                    }
                    if (_storeService.GetById(store.Id) != null)
                    {
                        //todo change generation code
                        store.Id = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture).GenerateSlug();
                    }
                    SaveStore(store);

                    storeSettings.ForEach(x => x.ObjectId = store.Id);
                    _settingsManager.SaveSettings(storeSettings);
                }

                backup.CloseBackup();
            }
            catch (Exception ex)
            {
                notification.Description = "Export error";
                notification.ErrorCount++;
                notification.Errors.Add(ex.ToString());
            }
            finally
            {
                notification.Finished = DateTime.UtcNow;
                notification.Description = "Import finished"
                    + (notification.Errors.Any() ? " with errors" : " successfully");
                _notifier.Upsert(notification);
            }


        }
Example #4
0
        public virtual void DoImport(StoreImportConfiguration importConfiguration, ImportNotification notification)
        {
            if (string.IsNullOrEmpty(importConfiguration.FileUrl))
            {
                throw new Exception("FileUrl is null or empty. Can't import.");
            }
            //Notification
            notification.Description = "loading ...";
            _notifier.Upsert(notification);

            try
            {
                var backup = new Backup(_blobStorageProvider, null);
                backup.OpenBackup(importConfiguration.FileUrl);

                // Extract objects from backup
                var store = backup.LoadObject <Store>(_stopeXmlName);
                if (store != null)
                {
                    store.Languages       = backup.LoadObject <string[]>(_storeLanguagesXmlName);
                    store.Currencies      = backup.LoadObject <CurrencyCodes[]>(_storeCurrenciesXmlName);
                    store.SeoInfos        = backup.LoadObject <SeoInfo[]>(_storeSeoXmlName);
                    store.PaymentMethods  = backup.LoadObjectsByMask <PaymentMethod>(_paymentMethodXmlNamePrefix).ToArray();
                    store.ShippingMethods = backup.LoadObjectsByMask <ShippingMethod>(_shippingMethodXmlNamePrefix).ToArray();
                    var settings = backup.LoadObject <SettingEntry[]>(_settingsXmlName);

                    var storeSettings = settings.Where(x => x.ObjectId == store.Id).ToArray();

                    // Clear ids of collections to prevent dublicate ids
                    //todo check exists or not added payment and shipping modules
                    if (store.PaymentMethods != null)
                    {
                        store.PaymentMethods.ForEach(x => x.Id = null);
                    }
                    if (store.ShippingMethods != null)
                    {
                        store.ShippingMethods.ForEach(x => x.Id = null);
                    }
                    if (store.SeoInfos != null)
                    {
                        store.SeoInfos.ForEach(x => x.Id = null);
                    }


                    if (!string.IsNullOrEmpty(importConfiguration.NewStoreName))
                    {
                        store.Name = importConfiguration.NewStoreName;
                    }
                    if (!string.IsNullOrEmpty(importConfiguration.NewStoreId))
                    {
                        store.Id = importConfiguration.NewStoreId;
                    }
                    if (_storeService.GetById(store.Id) != null)
                    {
                        //todo change generation code
                        store.Id = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture).GenerateSlug();
                    }
                    SaveStore(store);

                    storeSettings.ForEach(x => x.ObjectId = store.Id);
                    _settingsManager.SaveSettings(storeSettings);
                }

                backup.CloseBackup();
            }
            catch (Exception ex)
            {
                notification.Description = "Export error";
                notification.ErrorCount++;
                notification.Errors.Add(ex.ToString());
            }
            finally
            {
                notification.Finished    = DateTime.UtcNow;
                notification.Description = "Import finished"
                                           + (notification.Errors.Any() ? " with errors" : " successfully");
                _notifier.Upsert(notification);
            }
        }