public IHttpActionResult DoExport(StoreExportConfiguration exportConfiguration)
		{
			var notification = new ExportNotification(CurrentPrincipal.GetCurrentUserName())
			{
				Title = "Store export task",
				Description = "starting export...."
			};
			_notifier.Upsert(notification);

			var store = _storeService.GetById(exportConfiguration.StoreId);
			if (store == null)
			{
				throw new NullReferenceException("store");
			}

            var backupStoreJob = new BackupStoreJob();
            BackgroundJob.Enqueue(() => backupStoreJob.DoExport(exportConfiguration, notification));

			return Ok(notification);

		}
Ejemplo n.º 2
0
        public virtual void DoExport(StoreExportConfiguration exportConfiguration, ExportNotification notification)
        {
            //Notification
            notification.Description = "loading ...";
            _notifier.Upsert(notification);

            try
            {
                var store = _storeService.GetById(exportConfiguration.StoreId);
                var settings = new List<SettingEntry>();
                var backup = new Backup(_blobStorageProvider, _blobUrlResolver);

                // Add objects to backup
                backup.AddEntry(_stopeXmlName, store);
                
                // Add collections of the same types elements
                if (!exportConfiguration.IsDisableLanguages)
                {
                    backup.AddEntry(_storeLanguagesXmlName, store.Languages.ToArray());
                }
                if (!exportConfiguration.IsDisableCurrencies)
                {
                    backup.AddEntry(_storeCurrenciesXmlName, store.Currencies.ToArray());
                }
                if (!exportConfiguration.IsDisableSeo)
                {
                    backup.AddEntry(_storeSeoXmlName, store.SeoInfos.ToArray());
                }
                
                // Add collections of different types elements
                if (!exportConfiguration.IsDisablePamentMethods)
                {
                    foreach (var paymentMethod in store.PaymentMethods.Where(x => x.IsActive))
                    {
                        //don't export Settings because security
                        backup.AddEntry(string.Format("{0}{1}.xml", _paymentMethodXmlNamePrefix, paymentMethod.Code),
                            paymentMethod);
                    }
                }
                if (!exportConfiguration.IsDisableShipmentMethods)
                {
                    foreach (var shippingMethod in store.ShippingMethods.Where(x => x.IsActive))
                    {
                        backup.AddEntry(string.Format("{0}{1}.xml", _shippingMethodXmlNamePrefix, shippingMethod.Code),
                            shippingMethod);
                        settings.AddRange(shippingMethod.Settings);
                    }
                }

                settings.AddRange(store.Settings);
                backup.AddEntry(_settingsXmlName, settings.ToArray());

                // Create backup file
                var zipUrl = backup.Save("Store-" + (store.Name ?? store.Id) + ".zip");
                
                notification.DownloadUrl = zipUrl;
                notification.Description = "Export finished";
            }
            catch (Exception ex)
            {
                notification.Description = "Export error";
                notification.ErrorCount++;
                notification.Errors.Add(ex.ToString());
            }
            finally
            {
                notification.Finished = DateTime.UtcNow;
                _notifier.Upsert(notification);
            }


        }