예제 #1
0
        /// <summary>
        /// 新增前
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="item"></param>
        public override void OnBeforeInsert(EntityEntry entry, IHaveUpdatedMeta item)
        {
            base.OnBeforeInsert(entry, item);

            var currentTime = DateTimeOffset.Now;
            var currentUser = _userNameResolver.GetCurrentUserName();

            item.UpdatedOn = item.UpdatedOn == default(DateTimeOffset) ? currentTime : item.UpdatedOn;
            item.UpdatedBy = item.UpdatedBy ?? currentUser;
        }
        public object BuildQuery <T>(string scope, ISearchCriteria criteria) where T : class
        {
            var queryBuilder = _luceneQueryBuilder.BuildQuery <T>(scope, criteria) as QueryBuilder;

            if (criteria is CatalogItemSearchCriteria || criteria is CategorySearchCriteria)
            {
                var query      = queryBuilder.Query as BooleanQuery;
                var innerQuery = new BooleanQuery();
                innerQuery.Add(new TermQuery(new Term("usergroups", "__null__")), Occur.SHOULD);

                var userName    = _userNameResolver.GetCurrentUserName();
                var userAccount = System.Threading.Tasks.Task.Factory.StartNew(s => ((ISecurityService)s).FindByNameAsync(userName, UserDetails.Reduced), _securityService, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();

                if (userAccount != null && !userAccount.MemberId.IsNullOrEmpty())
                {
                    var contact = _memberService.GetByIds(new[] { userAccount.MemberId }).FirstOrDefault();
                    if (contact != null)
                    {
                        if (!contact.Groups.IsNullOrEmpty())
                        {
                            foreach (var userGroup in contact.Groups)
                            {
                                innerQuery.Add(new TermQuery(new Term("usergroups", userGroup.ToLowerInvariant())), Occur.SHOULD);
                            }
                        }
                    }
                }
                query.Add(innerQuery, Occur.MUST);
            }

            return(queryBuilder);
        }
예제 #3
0
        private webModel.ModulePushNotification ScheduleJob(webModel.ModuleBackgroundJobOptions options)
        {
            var notification = new webModel.ModulePushNotification(_userNameResolver.GetCurrentUserName());

            switch (options.Action)
            {
            case webModel.ModuleAction.Install:
                notification.Title = "Install Module";
                break;

            case webModel.ModuleAction.Update:
                notification.Title = "Update Module";
                break;

            case webModel.ModuleAction.Uninstall:
                notification.Title = "Uninstall Module";
                break;
            }

            _pushNotifier.Upsert(notification);

            BackgroundJob.Enqueue(() => ModuleBackgroundJob(options, notification));

            return(notification);
        }
        private ModulePushNotification ScheduleJob(ModuleBackgroundJobOptions options)
        {
            var notification = new ModulePushNotification(_userNameResolver.GetCurrentUserName());

            switch (options.Action)
            {
            case ModuleAction.Install:
                notification.Title = "Install Module";
                notification.ProgressLog.Add(new ProgressMessage {
                    Level = ProgressMessageLevel.Info, Message = "Starting installation..."
                });
                break;

            case ModuleAction.Uninstall:
                notification.Title = "Uninstall Module";
                notification.ProgressLog.Add(new ProgressMessage {
                    Level = ProgressMessageLevel.Info, Message = "Starting uninstall..."
                });
                break;
            }

            _pushNotifier.Send(notification);

            BackgroundJob.Enqueue(() => ModuleBackgroundJob(options, notification));

            return(notification);
        }
        public async Task <ActionResult <PlatformExportPushNotification> > RunExport([FromBody] ExportDataRequest request)
        {
            var authorizationResult = await _authorizationService.AuthorizeAsync(User, request.DataQuery, request.ExportTypeName + "ExportDataPolicy");

            if (!authorizationResult.Succeeded)
            {
                return(Unauthorized());
            }

            var typeTitle = request.ExportTypeName.LastIndexOf('.') > 0 ?
                            request.ExportTypeName.Substring(request.ExportTypeName.LastIndexOf('.') + 1) : request.ExportTypeName;

            var notification = new ExportPushNotification(_userNameResolver.GetCurrentUserName())
            {
                NotifyType  = "PlatformExportPushNotification",
                Title       = $"{typeTitle} export",
                Description = "Starting export task..."
            };

            _pushNotificationManager.Send(notification);

            var jobId = BackgroundJob.Enqueue <ExportJob>(x => x.ExportBackgroundAsync(request, notification, JobCancellationToken.Null, null));

            notification.JobId = jobId;

            return(Ok(notification));
        }
예제 #6
0
        public ActionResult <IndexProgressPushNotification> IndexDocuments([FromBody] IndexingOptions[] options)
        {
            var currentUserName = _userNameResolver.GetCurrentUserName();
            var notification    = IndexingJobs.Enqueue(currentUserName, options);

            _pushNotifier.Send(notification);
            return(Ok(notification));
        }
예제 #7
0
        private string GetCurrentUserName()
        {
            var result = _userNameResolver != null
                ? _userNameResolver.GetCurrentUserName()
                : "unknown";

            return(result);
        }
        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));
        }
예제 #9
0
        public IHttpActionResult IndexDocuments([FromBody] IndexingOptions[] options)
        {
            var currentUserName = _userNameResolver.GetCurrentUserName();
            var notification    = IndexingJobs.Enqueue(currentUserName, options);

            _pushNotifier.Upsert(notification);
            return(Ok(notification));
        }
예제 #10
0
        public async Task <ActionResult <ExportNotification> > DoExport([FromBody] CsvExportInfo exportInfo)
        {
            var hasPermissions = true;

            if (!exportInfo.ProductIds.IsNullOrEmpty())
            {
                var items = await _itemService.GetByIdsAsync(exportInfo.ProductIds, ItemResponseGroup.ItemInfo.ToString());

                hasPermissions = await CheckCatalogPermission(items, CatalogModuleConstants.Security.Permissions.Read);
            }

            if (hasPermissions && !exportInfo.CategoryIds.IsNullOrEmpty())
            {
                var categories = await _categoryService.GetByIdsAsync(exportInfo.CategoryIds, CategoryResponseGroup.Info.ToString());

                hasPermissions = await CheckCatalogPermission(categories, CatalogModuleConstants.Security.Permissions.Read);
            }

            if (hasPermissions && !exportInfo.CatalogId.IsNullOrEmpty())
            {
                var catalogs = await _catalogService.GetByIdsAsync(new[] { exportInfo.CatalogId }, CategoryResponseGroup.Info.ToString());

                if (!catalogs.IsNullOrEmpty())
                {
                    hasPermissions = await CheckCatalogPermission(catalogs.First(), CatalogModuleConstants.Security.Permissions.Read);
                }
            }

            if (!hasPermissions)
            {
                return(Unauthorized());
            }

            var notification = new ExportNotification(_userNameResolver.GetCurrentUserName())
            {
                Title       = "Catalog export task",
                Description = "starting export...."
            };
            await _notifier.SendAsync(notification);


            BackgroundJob.Enqueue(() => BackgroundExport(exportInfo, notification));

            return(Ok(notification));
        }
예제 #11
0
        public async Task <ActionResult <ImportPushNotification> > RunImport([FromBody] ImportDataRequest request)
        {
            var notification = new ImportPushNotification(_userNameResolver.GetCurrentUserName())
            {
                Title       = "Prices import",
                Description = "Starting import task..."
            };
            await _pushNotificationManager.SendAsync(notification);

            notification.JobId = BackgroundJob.Enqueue <ImportJob>(importJob => importJob.ImportBackgroundAsync(request, notification, JobCancellationToken.Null, null));

            return(Ok(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));
        }
예제 #13
0
        public async Task <IActionResult> DownloadSitemap(string storeId, string baseUrl)
        {
            var notification = new SitemapDownloadNotification(_userNameResolver.GetCurrentUserName())
            {
                Title       = "Download sitemaps",
                Description = "Processing download sitemaps..."
            };

            await _notifier.SendAsync(notification);

            BackgroundJob.Enqueue(() => BackgroundDownload(storeId, baseUrl, notification));

            return(Ok(notification));
        }
        public IHttpActionResult StartImport(ShopifyImportParams importParams)
        {
            var notification = new ShopifyImportNotification(_userNameResolver.GetCurrentUserName())
            {
                Title       = "Import catalog from Shopify",
                Description = "starting import...."
            };

            _notifier.Upsert(notification);

            BackgroundJob.Enqueue(() => _shopifyImportService.Import(importParams, notification));

            return(Ok(notification));
        }
예제 #15
0
        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 async Task <ActionResult <ImportNotification> > ImportCouponsAsync([FromBody] ImportRequest request)
        {
            var notification = new ImportNotification(_userNameResolver.GetCurrentUserName())
            {
                Title       = "Import coupons from CSV",
                Description = "Starting import..."
            };

            await _notifier.SendAsync(notification);

            BackgroundJob.Enqueue(() => BackgroundImportAsync(request, notification));

            return(Ok(notification));
        }
        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));
        }
예제 #18
0
        private async Task <OrdersSynchronizationPushNotification> Enqueue(OrdersSynchronizationRequest request)
        {
            var notification = new OrdersSynchronizationPushNotification(_userNameResolver.GetCurrentUserName())
            {
                Title       = "Sending orders to AvaTax",
                Description = "Starting process..."
            };
            await _pushNotificationManager.SendAsync(notification);

            var jobId = BackgroundJob.Enqueue <OrdersSynchronizationJob>(x => x.RunManually(request.OrderIds, notification, JobCancellationToken.Null, null));

            notification.JobId = jobId;

            return(notification);
        }
        private ThumbnailProcessNotification Enqueue(ThumbnailsTaskRunRequest runRequest)
        {
            var notification = new ThumbnailProcessNotification(_userNameResolver.GetCurrentUserName())
            {
                Title       = "Process images",
                Description = "starting process...."
            };

            _pushNotifier.Upsert(notification);

            var jobId = BackgroundJob.Enqueue <ThumbnailProcessJob>(x => x.Process(runRequest, notification, JobCancellationToken.Null, null));

            notification.JobId = jobId;

            return(notification);
        }
예제 #20
0
        //[ResponseType(typeof(PlatformExportPushNotification))]
        public IHttpActionResult RunExport([FromBody] ExportDataRequest request)
        {
            if (_exportSecurityHandlerRegistrar.GetHandler(request.ExportTypeName + "ExportDataPolicy")?.Authorize(User.Identity.Name, request) != true)
            {
                return(Unauthorized());
            }

            var notification = new ExportPushNotification(_userNameResolver.GetCurrentUserName())
            {
                Title       = $"{request.ExportTypeName} export task",
                Description = "starting export...."
            };
            //_pushNotificationManager.Send(notification);

            var jobId = BackgroundJob.Enqueue <ExportJob>(x => x.ExportBackground(request, notification, JobCancellationToken.Null, null));

            notification.JobId = jobId;

            return(Ok(notification));
        }
예제 #21
0
        public async Task <ActionResult <BulkActionPushNotification> > Run([FromBody] BulkActionContext context)
        {
            ValidateContext(context);

            var actionProvider = _bulkActionProviderStorage.Get(context.ActionName);

            if (!await IsAuthorizedUserHasPermissionsAsync(actionProvider.Permissions))
            {
                return(Unauthorized());
            }

            var creator      = _userNameResolver.GetCurrentUserName();
            var notification = new BulkActionPushNotification(creator)
            {
                Title       = $"{context.ActionName}",
                Description = "Starting…"
            };

            notification.JobId = _backgroundJobExecutor.Enqueue <BulkActionJob>(job => job.ExecuteAsync(context, notification, JobCancellationToken.Null, null));

            return(Ok(notification));
        }
 public IHttpActionResult GetNewExportManifest()
 {
     return(Ok(_platformExportManager.GetNewExportManifest(_userNameResolver.GetCurrentUserName())));
 }
예제 #23
0
        /// <summary>
        ///  获取当前用户名
        /// </summary>
        /// <param name="userNameResolver"></param>
        /// <returns></returns>
        public static string GetCurrentUserName(this IUserNameResolver userNameResolver)
        {
            var result = userNameResolver != null?userNameResolver.GetCurrentUserName() : "unknown";

            return(result);
        }