public IHttpActionResult Publish(ImportManifest importManifest) { var settingsManager = ServiceLocator.Current.GetInstance <ISettingsManager>(); var packagesPath = settingsManager.GetValue("VirtoCommerce.ModulesPublishing.AppStoreImport.PackagesPath", String.Empty); importManifest.DefaultCategoryCode = settingsManager.GetValue("VirtoCommerce.ModulesPublishing.AppStoreImport.DefaultCategoryCode", String.Empty); importManifest.PackagesPath = HttpContext.Current.Server.MapPath(packagesPath); var notification = new ModulePublishingPushNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Import applications task", Description = "Task added and will start soon...." }; if (string.IsNullOrEmpty(importManifest.DefaultCategoryCode)) { notification.Errors.Add("Set 'Category code' setting, before import."); } if (string.IsNullOrEmpty(packagesPath)) { notification.Errors.Add("Set 'Packages folder' setting, before import."); } if (!Directory.Exists(importManifest.PackagesPath)) { notification.Errors.Add(string.Format("Path doesn't exists: {0}", importManifest.PackagesPath)); } if (notification.Errors.Count == 0) { BackgroundJob.Enqueue(() => ModulesImportBackground(importManifest, notification)); } _pushNotifier.Upsert(notification); return(Ok(notification)); }
private string CreateImportManifestContent(string provider, string name, string version, string fileName, long fileSize, string fileHash, Tuple <string, string>[] compatibilityIds) { var aduContent = new ImportManifest( new UpdateId(provider, name, version), "microsoft/swupdate:1", "1.2.3.4", new List <ImportManifestCompatibilityInfo>( compatibilityIds.Select(c => new ImportManifestCompatibilityInfo(c.Item1, c.Item2))), DateTime.UtcNow, new Version(2, 0), new List <ImportManifestFile>() { new ImportManifestFile( fileName, fileSize, new Dictionary <HashType, string>() { { HashType.Sha256, fileHash } }) }); string filePath = Path.GetTempFileName(); File.WriteAllText(filePath, JsonConvert.SerializeObject(aduContent, Formatting.Indented)); return(filePath); }
public void ModulesImportBackground(ImportManifest importManifest, ModulePublishingPushNotification pushNotification) { Action <ImportProcessInfo> progressCallback = (x) => { pushNotification.InjectFrom(x); pushNotification.Errors = x.Errors; _pushNotifier.Upsert(pushNotification); }; try { _moduleImporter.DoImport(importManifest, progressCallback); } catch (Exception ex) { pushNotification.Errors.Add(ex.ToString()); } finally { pushNotification.Finished = DateTime.UtcNow; pushNotification.Description = "Import finished"; _pushNotifier.Upsert(pushNotification); } }