public IHttpActionResult Run(ThumbnailsTaskRunRequest runRequest) { var notification = Enqueue(runRequest); _pushNotifier.Upsert(notification); return(Ok(notification)); }
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)); }
public void ExportBackground(ExportDataRequest request, ExportPushNotification notification, IJobCancellationToken cancellationToken, PerformContext context) { void progressCallback(ExportProgressInfo x) { notification.Patch(x); notification.JobId = context.BackgroundJob.Id; _pushNotificationManager.Upsert(notification); } try { var localTmpFolder = HostingEnvironment.MapPath(_defaultExportFolder); var fileName = Path.Combine(localTmpFolder, string.Format(FileNameTemplate, DateTime.UtcNow)); // Do not like provider creation here to get file extension, maybe need to pass created provider to Exporter. // Create stream inside Exporter is not good as it is not Exporter resposibility to decide where to write. var provider = _exportProviderFactory.CreateProvider(request); if (!string.IsNullOrEmpty(provider.ExportedFileExtension)) { fileName = Path.ChangeExtension(string.Format(FileNameTemplate, DateTime.UtcNow), provider.ExportedFileExtension); } var localTmpPath = Path.Combine(localTmpFolder, fileName); if (!Directory.Exists(localTmpFolder)) { Directory.CreateDirectory(localTmpFolder); } if (File.Exists(localTmpPath)) { File.Delete(localTmpPath); } //Import first to local tmp folder because Azure blob storage doesn't support some special file access mode using (var stream = File.OpenWrite(localTmpPath)) { _dataExporter.Export(stream, request, progressCallback, new JobCancellationTokenWrapper(cancellationToken)); notification.DownloadUrl = $"api/export/download/{fileName}"; } } catch (JobAbortedException) { //do nothing } catch (Exception ex) { notification.Errors.Add(ex.ExpandExceptionMessage()); } finally { notification.Description = "Export finished"; notification.Finished = DateTime.UtcNow; _pushNotificationManager.Upsert(notification); } }
public IHttpActionResult ImportCoupons(ImportRequest request) { var notification = new ImportNotification(_userNameResolver.GetCurrentUserName()) { Title = "Import coupons from CSV", Description = "Starting import..." }; _notifier.Upsert(notification); BackgroundJob.Enqueue(() => BackgroundImport(request, notification)); return(Ok(notification)); }
public void ModuleBackgroundJob(webModel.ModuleBackgroundJobOptions options, webModel.ModulePushNotification notification) { try { notification.Started = DateTime.UtcNow; var moduleInfos = _moduleCatalog.Modules.OfType <ManifestModuleInfo>() .Where(x => options.Modules.Any(y => y.Identity.Equals(x.Identity))) .ToArray(); var reportProgress = new Progress <ProgressMessage>(m => { lock (_lockObject) { notification.ProgressLog.Add(m.ToWebModel()); _pushNotifier.Upsert(notification); } }); switch (options.Action) { case webModel.ModuleAction.Install: _moduleInstaller.Install(moduleInfos, reportProgress); break; case webModel.ModuleAction.Uninstall: _moduleInstaller.Uninstall(moduleInfos, reportProgress); break; } } catch (Exception ex) { notification.ProgressLog.Add(new webModel.ProgressMessage { Level = ProgressMessageLevel.Error.ToString(), Message = ex.ExpandExceptionMessage(), }); } finally { _settingsManager.SetValue(_autoInstallStateSetting, webModel.AutoInstallState.Completed); notification.Finished = DateTime.UtcNow; notification.ProgressLog.Add(new webModel.ProgressMessage { Level = ProgressMessageLevel.Info.ToString(), Message = "Installation finished.", }); _pushNotifier.Upsert(notification); } }
public IHttpActionResult MarkAllAsRead() { var criteria = new PushNotificationSearchCriteria { OnlyNew = true, Start = 0, Count = int.MaxValue }; var retVal = _pushNotifier.SearchNotifies(User.Identity.Name, criteria); foreach (var notifyEvent in retVal.NotifyEvents) { notifyEvent.New = false; _pushNotifier.Upsert(notifyEvent); } return(Ok(retVal)); }
public IHttpActionResult Sync(string store, SyncInfo syncInfo) { var notification = new SyncNotification(_userNameResolver.GetCurrentUserName()) { Title = "Tilda Publishing Sync", Description = "starting syncing ..." }; _notifier.Upsert(notification); BackgroundJob.Enqueue(() => BackgroundSync(store, syncInfo, notification)); return(Ok(notification)); }
public async Task Process(ThumbnailsTaskRunRequest generateRequest, ThumbnailProcessNotification notifyEvent, IJobCancellationToken cancellationToken, PerformContext context) { try { Action <ThumbnailTaskProgress> progressCallback = x => { notifyEvent.Description = x.Message; notifyEvent.Errors = x.Errors; notifyEvent.ErrorCount = notifyEvent.Errors.Count; notifyEvent.TotalCount = x.TotalCount ?? 0; notifyEvent.ProcessedCount = x.ProcessedCount ?? 0; notifyEvent.JobId = context.BackgroundJob.Id; _pushNotifier.Upsert(notifyEvent); }; //wrap token var tasks = _taskService.GetByIds(generateRequest.TaskIds); var cancellationTokenWrapper = new JobCancellationTokenWrapper(cancellationToken); await _thumbnailProcessor.ProcessTasksAsync(tasks, generateRequest.Regenerate, progressCallback, cancellationTokenWrapper); //update tasks in case of successful generation foreach (var task in tasks) { task.LastRun = DateTime.UtcNow; } _taskService.SaveOrUpdate(tasks); } catch (JobAbortedException) { //do nothing } catch (Exception ex) { notifyEvent.Description = "Error"; notifyEvent.ErrorCount++; notifyEvent.Errors.Add(ex.ToString()); } finally { notifyEvent.Finished = DateTime.UtcNow; notifyEvent.Description = "Process finished" + (notifyEvent.Errors.Any() ? " with errors" : " successfully"); _pushNotifier.Upsert(notifyEvent); } }
public IHttpActionResult IndexDocuments([FromBody] IndexingOptions[] options) { var currentUserName = _userNameResolver.GetCurrentUserName(); var notification = IndexingJobs.Enqueue(currentUserName, options); _pushNotifier.Upsert(notification); return(Ok(notification)); }
public void ModuleBackgroundJob(webModel.ModuleBackgroundJobOptions options, webModel.ModulePushNotification notification) { try { notification.Started = DateTime.UtcNow; var reportProgress = new Progress <ProgressMessage>(m => { notification.ProgressLog.Add(m.ToWebModel()); _pushNotifier.Upsert(notification); }); switch (options.Action) { case webModel.ModuleAction.Install: _packageService.Install(options.PackageFilePath, reportProgress); break; case webModel.ModuleAction.Update: _packageService.Update(options.PackageId, options.PackageFilePath, reportProgress); break; case webModel.ModuleAction.Uninstall: _packageService.Uninstall(options.PackageId, reportProgress); break; } } catch (Exception ex) { notification.ProgressLog.Add(new webModel.ProgressMessage { Level = ProgressMessageLevel.Error.ToString(), Message = ex.ExpandExceptionMessage(), }); } finally { notification.Finished = DateTime.UtcNow; _pushNotifier.Upsert(notification); } }
public IHttpActionResult TryToImportSampleData() { lock (_lockObject) { //Sample data initialization var sampleDataPath = ConfigurationManager.AppSettings.GetValue("VirtoCommerce:SampleDataPath", string.Empty); if (!String.IsNullOrEmpty(sampleDataPath) && !_settingsManager.GetValue("VirtoCommerce:SampleDataInstalled", false)) { _settingsManager.SetValue("VirtoCommerce:SampleDataInstalled", true); var pushNotification = new SampleDataImportPushNotification("System"); _pushNotifier.Upsert(pushNotification); BackgroundJob.Enqueue(() => SampleDataImportBackground(HostingEnvironment.MapPath(sampleDataPath), pushNotification)); return(Ok(pushNotification)); } } return(StatusCode(HttpStatusCode.NoContent)); }
private IHttpActionResult DoExport(string notifyType, string notificationDescription, Action <ExportPushNotification> job) { var notification = new ExportPushNotification(_userNameResolver.GetCurrentUserName(), notifyType) { Title = notificationDescription, Description = "Starting export..." }; _pushNotifier.Upsert(notification); job(notification); return(Ok(notification)); }
public IHttpActionResult StartImport(ShopifyImportParams importParams) { var notification = new ShopifyImportNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Import catalog from Shopify", Description = "starting import...." }; _notifier.Upsert(notification); BackgroundJob.Enqueue(() => _shopifyImportService.Import(importParams, notification)); return(Ok(notification)); }
public void Progress(IndexingProgress progress) { _log.Trace(progress.Description); _totalCountMap[progress.DocumentType] = progress.TotalCount ?? 0; _processedCountMap[progress.DocumentType] = progress.ProcessedCount ?? 0; _notification.DocumentType = progress.DocumentType; _notification.Description = progress.Description; if (!progress.Errors.IsNullOrEmpty()) { _notification.Errors.AddRange(progress.Errors); _notification.ErrorCount += _notification.Errors.Count; } _notification.TotalCount = progress.TotalCount ?? 0; _notification.ProcessedCount = progress.ProcessedCount ?? 0; if (!_suppressInsignificantNotifications || progress.TotalCount > 0 || progress.ProcessedCount > 0) { _pushNotificationManager.Upsert(_notification); } }
public IHttpActionResult DoExport(CsvExportInfo exportInfo) { var notification = new ExportNotification(CurrentPrincipal.GetCurrentUserName()) { Title = "Catalog export task", Description = "starting export...." }; _notifier.Upsert(notification); BackgroundJob.Enqueue(() => BackgroundExport(exportInfo, notification)); return(Ok(notification)); }
public IHttpActionResult DoExport(CsvExportInfo exportInfo) { CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Export, exportInfo); var notification = new ExportNotification(_userNameResolver.GetCurrentUserName()) { Title = "Catalog export task", Description = "starting export...." }; _notifier.Upsert(notification); BackgroundJob.Enqueue(() => BackgroundExport(exportInfo, notification)); return(Ok(notification)); }
public IHttpActionResult ImportSampleData([FromUri] string url = null) { lock (_lockObject) { var sampleDataState = EnumUtility.SafeParse(_settingsManager.GetValue(_sampledataStateSetting, SampleDataState.Undefined.ToString()), SampleDataState.Undefined); if (sampleDataState == SampleDataState.Undefined) { //Sample data initialization if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) { _settingsManager.SetValue(_sampledataStateSetting, SampleDataState.Processing); var pushNotification = new SampleDataImportPushNotification("System"); _pushNotifier.Upsert(pushNotification); BackgroundJob.Enqueue(() => SampleDataImportBackground(new Uri(url), HostingEnvironment.MapPath(Startup.VirtualRoot + "/App_Data/Uploads/"), pushNotification)); return(Ok(pushNotification)); } } } return(StatusCode(HttpStatusCode.NoContent)); }
protected void DoExport <TCsvClass, TClass>(string fileName, int chunkSize, string entitiesType, Func <ICollection <TCsvClass> > entityFactory, CsvClassMap <TClass> entityClassMap, ExportPushNotification notification) { Action <ExportImportProgressInfo> progressCallback = x => { notification.Description = x.Description; notification.TotalCount = x.TotalCount; notification.ProcessedCount = x.ProcessedCount; notification.Errors = x.Errors; _pushNotifier.Upsert(notification); }; var progressInfo = new ExportImportProgressInfo { Description = string.Format("Loading {0}...", entitiesType) }; progressCallback(progressInfo); var updateProgress = new Action(() => { progressInfo.Description = string.Format("{0} of {1} {2} processed", progressInfo.ProcessedCount, progressInfo.TotalCount, entitiesType); progressCallback(progressInfo); }); var updateProgressWithThrottling = updateProgress.Throttle(TimeSpan.FromSeconds(1)); var relativeUrl = "temp/" + fileName + ".zip"; using (var blobStream = _blobStorageProvider.OpenWrite(relativeUrl)) { try { // Because of Recommendation API file uploading limit, we need to split our csv file to parts with size no more than this limit using (var archive = new ZipArchive(blobStream, ZipArchiveMode.Create, true, new UTF8Encoding(false))) { var partIndex = 1; using (var stream = new MemoryStream()) { using (var streamWriter = new StreamWriter(stream, new UTF8Encoding(false), 1024, true) { AutoFlush = true }) { using (var csvWriter = new CsvWriter(streamWriter)) { progressCallback(progressInfo); var entities = entityFactory().ToArray(); csvWriter.Configuration.Delimiter = ","; csvWriter.Configuration.RegisterClassMap(entityClassMap); progressInfo.TotalCount = entities.Length; for (var index = 0; index < entities.Length; index++) { try { var previousSize = (int)stream.Length; csvWriter.WriteRecord(entities[index]); if (stream.Length > chunkSize) { WriteEntry(archive, fileName, ref partIndex, x => x.Write(stream.GetBuffer(), 0, previousSize - 2)); stream.SetLength(0); --index; } } catch (Exception ex) { progressInfo.Errors.Add(ex.ToString()); progressCallback(progressInfo); } progressInfo.ProcessedCount = index + 1; updateProgressWithThrottling(); } } } WriteEntry(archive, fileName, ref partIndex, stream.WriteTo, true); } } updateProgress(); notification.DownloadUrl = _blobUrlResolver.GetAbsoluteUrl(relativeUrl); } catch (Exception ex) { notification.Description = "Export failed"; notification.Errors.Add(ex.ExpandExceptionMessage()); } finally { notification.Description = "Export finished"; notification.Finished = DateTime.UtcNow; _pushNotifier.Upsert(notification); } } }
public ShopifyImportNotification Import(ShopifyImportParams importParams, ShopifyImportNotification notification) { try { var shopifyData = ReadData(importParams, notification); UpdateProgresses(importParams, notification, shopifyData); var virtoData = ConvertData(shopifyData, importParams, notification); SaveData(virtoData, importParams, notification); } catch (Exception ex) { notification.Description = "Import 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); } return(notification); }
public IHttpActionResult TryToImportSampleData([FromUri] string url = null) { lock (_lockObject) { if (!_settingsManager.GetValue("VirtoCommerce:SampleDataInstalled", false)) { _settingsManager.SetValue("VirtoCommerce:SampleDataInstalled", true); //Sample data initialization if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) { var pushNotification = new SampleDataImportPushNotification("System"); _pushNotifier.Upsert(pushNotification); BackgroundJob.Enqueue(() => SampleDataImportBackground(new Uri(url), HostingEnvironment.MapPath(Startup.VirtualRoot + "/App_Data/Uploads/"), pushNotification)); return(Ok(pushNotification)); } } } return(StatusCode(HttpStatusCode.NoContent)); }