/// <summary>
        /// Initializes the target. Can be used by inheriting classes
        /// to initialize logging.
        /// </summary>
        protected override void InitializeTarget()
        {
            base.InitializeTarget();

            string connectionString = string.Empty;
            string serviceUri       = string.Empty;
            string tenantIdentity   = string.Empty;
            string resourceIdentity = string.Empty;

            Dictionary <string, string> queueMetadata = null;

            var defaultLogEvent = LogEventInfo.CreateNullEvent();

            try
            {
                connectionString = ConnectionString?.Render(defaultLogEvent);
                if (string.IsNullOrEmpty(connectionString))
                {
                    serviceUri       = ServiceUri?.Render(defaultLogEvent);
                    tenantIdentity   = TenantIdentity?.Render(defaultLogEvent);
                    resourceIdentity = ResourceIdentity?.Render(defaultLogEvent);
                }

                if (QueueMetadata?.Count > 0)
                {
                    queueMetadata = new Dictionary <string, string>();
                    foreach (var metadata in QueueMetadata)
                    {
                        if (string.IsNullOrWhiteSpace(metadata.Name))
                        {
                            continue;
                        }

                        var metadataValue = metadata.Layout?.Render(defaultLogEvent);
                        if (string.IsNullOrEmpty(metadataValue))
                        {
                            continue;
                        }

                        queueMetadata[metadata.Name.Trim()] = metadataValue;
                    }
                }

                _cloudQueueService.Connect(connectionString, serviceUri, tenantIdentity, resourceIdentity, queueMetadata);
                InternalLogger.Trace("AzureQueueStorageTarget - Initialized");
            }
            catch (Exception ex)
            {
                if (string.IsNullOrEmpty(connectionString) && !string.IsNullOrEmpty(serviceUri))
                {
                    InternalLogger.Error(ex, "AzureQueueStorageTarget(Name={0}): Failed to create QueueClient with ServiceUri={1}.", Name, serviceUri);
                }
                else
                {
                    InternalLogger.Error(ex, "AzureQueueStorageTarget(Name={0}): Failed to create QueueClient with connectionString={1}.", Name, connectionString);
                }
                throw;
            }
        }
Beispiel #2
0
        public virtual object Clone()
        {
            var result = MemberwiseClone() as NotificationMessage;

            result.TenantIdentity = TenantIdentity?.Clone() as TenantIdentity;

            return(result);
        }
        public async Task <IEnumerable <SeoInfo> > DetectSeoDuplicatesAsync(TenantIdentity tenantIdentity)
        {
            var useSeoDeduplication = _settingsManager.GetValue(ModuleConstants.Settings.General.UseSeoDeduplication.Name, false);
            var retVal = new List <SeoInfo>();

            if (useSeoDeduplication)
            {
                string catalogId  = null;
                var    objectType = tenantIdentity.Type;
                var    objectId   = tenantIdentity.Id;

                if (objectType.EqualsInvariant(typeof(Store).Name))
                {
                    var store = await _storeService.GetByIdAsync(tenantIdentity.Id);

                    if (store != null)
                    {
                        catalogId = store.Catalog;
                    }
                }
                else if (objectType.EqualsInvariant(typeof(Category).Name))
                {
                    var category =
                        (await _categoryService.GetByIdsAsync(new[] { objectId }, CategoryResponseGroup.Info.ToString()))
                        .FirstOrDefault();
                    if (category != null)
                    {
                        catalogId = category.CatalogId;
                    }
                }
                else if (objectType.EqualsInvariant(typeof(CatalogProduct).Name))
                {
                    var product =
                        (await _productService.GetByIdsAsync(new[] { objectId }, ItemResponseGroup.ItemInfo.ToString()))
                        .FirstOrDefault();
                    if (product != null)
                    {
                        catalogId = product.CatalogId;
                    }
                }

                if (!string.IsNullOrEmpty(catalogId))
                {
                    //Get all SEO owners witch related to requested catalog and contains Seo duplicates
                    var objectsWithSeoDuplicates = await GetSeoOwnersContainsDuplicatesAsync(catalogId);

                    //Need select for each seo owner one seo defined for requested container or without it if not exist
                    var seoInfos = objectsWithSeoDuplicates.Select(x =>
                                                                   x.SeoInfos.Where(s => s.StoreId == objectId || string.IsNullOrEmpty(s.StoreId))
                                                                   .OrderByDescending(s => s.StoreId).FirstOrDefault())
                                   .Where(x => x != null);
                    //return only Seo infos with have duplicate slug keyword
                    retVal = seoInfos.GroupBy(x => x.SemanticUrl).Where(x => x.Count() > 1).SelectMany(x => x).ToList();
                }
            }

            return(retVal);
        }
Beispiel #4
0
        public static void SetTenantIdentity(TenantIdentity identity)
        {
            if (_items.Value == null)
            {
                _items.Value = new CoreContext();
            }

            _items.Value.TenantIdentity = identity;
        }
Beispiel #5
0
        public virtual object Clone()
        {
            var result = MemberwiseClone() as Notification;

            result.Templates      = Templates?.Select(x => x.Clone()).OfType <NotificationTemplate>().ToList();
            result.TenantIdentity = TenantIdentity?.Clone() as TenantIdentity;

            return(result);
        }
Beispiel #6
0
        /// <summary>
        ///  中间件初始化对应租户信息
        /// </summary>
        /// <returns></returns>
        public Task <Resp <TenantIdentity> > CheckAndInitialIdentity(HttpContext context, AppIdentity appInfo)
        {
            var tenant = new TenantIdentity()
            {
                id   = "1",
                name = "OSSCore",
                logo = "http://img1.osscore.cn/static/oss_net.png"
            };

            return(Task.FromResult(new Resp <TenantIdentity>(tenant)));
        }
        public Task <IEnumerable <SeoInfo> > DetectSeoDuplicatesAsync(TenantIdentity tenantIdentity)
        {
            //TODO:
            throw new NotImplementedException();
            //var retVal = new List<SeoInfo>();
            //string catalogId = null;
            //if (objectType.EqualsInvariant(typeof(Store).Name))
            //{
            //    var store = await _storeService.GetByIdAsync(objectId);
            //    if (store != null)
            //    {
            //        catalogId = store.Catalog;
            //    }
            //}
            //else if (objectType.EqualsInvariant(typeof(Category).Name))
            //{
            //    var category = (await _categoryService.GetByIdsAsync(new[] { objectId }, CategoryResponseGroup.Info.ToString())).FirstOrDefault();
            //    if (category != null)
            //    {
            //        catalogId = category.CatalogId;
            //    }
            //}
            //else if (objectType.EqualsInvariant(typeof(CatalogProduct).Name))
            //{
            //    var product = (await _productService.GetByIdsAsync(new[] { objectId }, ItemResponseGroup.ItemInfo.ToString())).FirstOrDefault();
            //    if (product != null)
            //    {
            //        catalogId = product.CatalogId;
            //    }
            //}

            //if (!string.IsNullOrEmpty(catalogId))
            //{
            //    //Get all SEO owners witch related to requested catalog and contains Seo duplicates
            //    var objectsWithSeoDuplicates = await GetSeoOwnersContainsDuplicatesAsync(catalogId, allSeoDuplicates);
            //    //Need select for each seo owner one seo defined for requested container or without it if not exist
            //    var seoInfos = objectsWithSeoDuplicates.Select(x => x.SeoInfos.Where(s => s.StoreId == objectId || string.IsNullOrEmpty(s.StoreId)).OrderByDescending(s => s.StoreId).FirstOrDefault())
            //                                           .Where(x => x != null);
            //    //return only Seo infos with have duplicate slug keyword
            //    retVal = seoInfos.GroupBy(x => x.SemanticUrl).Where(x => x.Count() > 1).SelectMany(x => x).ToList();
            //}
            //return retVal;
        }
        public async Task GetNotificationAsync_GetByTenant()
        {
            //Arrange
            var searchTenant   = new TenantIdentity(Guid.NewGuid().ToString(), "Store");
            var searchType     = nameof(RegistrationEmailNotification);
            var searchCriteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance();

            searchCriteria.Take             = 1;
            searchCriteria.Skip             = 0;
            searchCriteria.TenantId         = searchTenant.Id;
            searchCriteria.TenantType       = searchTenant.Type;
            searchCriteria.NotificationType = searchType;
            var notificationEntities = new List <NotificationEntity> {
                new EmailNotificationEntity {
                    Type = searchType, Kind = nameof(EmailNotification), Id = Guid.NewGuid().ToString(), TenantId = null, TenantType = null
                },
                new EmailNotificationEntity {
                    Type = searchType, Kind = nameof(EmailNotification), Id = Guid.NewGuid().ToString(), TenantId = "someId", TenantType = "Store"
                },
                new EmailNotificationEntity {
                    Type = searchType, Kind = nameof(EmailNotification), Id = Guid.NewGuid().ToString(), TenantId = searchTenant.Id, TenantType = searchTenant.Type
                }
            };
            var mockNotifications = notificationEntities.AsQueryable().BuildMock();

            _repositoryMock.Setup(r => r.Notifications).Returns(mockNotifications.Object);
            var notifications = notificationEntities.Select(n => n.ToModel(AbstractTypeFactory <Notification> .TryCreateInstance(n.Type))).ToArray();

            _notificationServiceMock.Setup(ns => ns.GetByIdsAsync(It.IsAny <string[]>(), null))
            .ReturnsAsync(notifications.ToArray());


            //Act
            var result = await NotificationSearchServiceExtensions.GetNotificationAsync <RegistrationEmailNotification>(_notificationSearchService, searchTenant);

            //Assert
            Assert.Equal(searchTenant.Id, result.TenantIdentity.Id);
            Assert.Equal(searchTenant.Type, result.TenantIdentity.Type);
            Assert.Equal(searchType, result.Type);
        }
        /// <summary>
        /// Initializes the target. Can be used by inheriting classes
        /// to initialize logging.
        /// </summary>
        protected override void InitializeTarget()
        {
            base.InitializeTarget();

            _machineName = GetMachineName();

            string connectionString = string.Empty;
            string serviceUri       = string.Empty;
            string tenantIdentity   = string.Empty;
            string resourceIdentity = string.Empty;
            string clientIdentity   = string.Empty;
            string accountName      = string.Empty;
            string accessKey        = string.Empty;

            var defaultLogEvent = LogEventInfo.CreateNullEvent();

            try
            {
                connectionString = ConnectionString?.Render(defaultLogEvent);
                if (string.IsNullOrEmpty(connectionString))
                {
                    serviceUri       = ServiceUri?.Render(defaultLogEvent);
                    tenantIdentity   = TenantIdentity?.Render(defaultLogEvent);
                    resourceIdentity = ResourceIdentity?.Render(defaultLogEvent);
                    clientIdentity   = ClientIdentity?.Render(defaultLogEvent);
                    accountName      = AccountName?.Render(defaultLogEvent);
                    accessKey        = AccessKey?.Render(defaultLogEvent);
                }

                _cloudTableService.Connect(connectionString, serviceUri, tenantIdentity, resourceIdentity, clientIdentity, accountName, accessKey);
                InternalLogger.Trace("AzureDataTablesTarget(Name={0}): Initialized", Name);
            }
            catch (Exception ex)
            {
                InternalLogger.Error(ex, "AzureDataTablesTarget(Name={0}): Failed to create TableClient with connectionString={1}.", Name, connectionString);
                throw;
            }
        }
Beispiel #10
0
 public static int Insert(Zippy.Data.IDalProvider db, TenantIdentity entity)
 {
     int rtn = db.Insert(entity);
     return rtn;
 }
Beispiel #11
0
 /// <summary>
 /// 表示 [租户编号] 对应的实体
 /// </summary>
 public static Tenant GetTenantIDEntity(Zippy.Data.IDalProvider db, TenantIdentity entity)
 {
     return db.FindUnique<Tenant>("TenantID=@TenantID", db.CreateParameter("TenantID", entity.TenantID));
 }
Beispiel #12
0
 public static int Update(Zippy.Data.IDalProvider db, TenantIdentity entity)
 {
     return db.Update(entity);
 }
Beispiel #13
0
        public IHttpActionResult SearchObjectChangeHistory([FromBody] TenantIdentity tenant)
        {
            var result = _changeLog.FindObjectChangeHistory(tenant.TenantId, tenant.TenantType).ToArray();

            return(Ok(result));
        }
Beispiel #14
0
 public static int Update(Zippy.Data.IDalProvider db, TenantIdentity entity)
 {
     return(db.Update(entity));
 }
Beispiel #15
0
 /// <summary>
 /// 表示 [租户编号] 对应的实体
 /// </summary>
 public static Tenant GetTenantIDEntity(Zippy.Data.IDalProvider db, TenantIdentity entity)
 {
     return(db.FindUnique <Tenant>("TenantID=@TenantID", db.CreateParameter("TenantID", entity.TenantID)));
 }
Beispiel #16
0
        public static async Task <Notification> GetNotificationAsync(this INotificationSearchService service, string notificationType, TenantIdentity tenant = null)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            var criteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance();

            criteria.NotificationType = notificationType;
            criteria.Take             = int.MaxValue;
            var searchResult = await service.SearchNotificationsAsync(criteria);

            //Find first global notification (without tenant)
            var result = searchResult.Results.Where(x => x.TenantIdentity.IsEmpty).FirstOrDefault();

            if (tenant != null)
            {
                //If tenant is specified try to find a notification belongs to concrete tenant or use default as fallback
                result = searchResult.Results.Where(x => x.TenantIdentity == tenant).FirstOrDefault() ?? result;
            }
            return(result);
        }
Beispiel #17
0
        public static async Task <T> GetNotificationAsync <T>(this INotificationSearchService service, TenantIdentity tenant = null) where T : Notification
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            var result = await service.GetNotificationAsync(typeof(T).Name, tenant);

            return(result as T);
        }
Beispiel #18
0
        public static TenantIdentity Create(Zippy.Data.IDalProvider db, Int64 _IdentityID)
        {
            TenantIdentity rtn = db.FindUnique <TenantIdentity>(_IdentityID);

            return(rtn);
        }
 public Task <IEnumerable <SeoInfo> > DetectSeoDuplicatesAsync(TenantIdentity tenantIdentity)
 {
     return(Task.FromResult(Enumerable.Empty <SeoInfo>()));
 }
        public static async Task <Notification> GetNotificationAsync(this INotificationSearchService service, string notificationType, TenantIdentity tenant = null, string responseGroup = null)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            var criteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance();

            criteria.NotificationType = notificationType;

            //try to get with the Tenant
            criteria.Take          = 1;
            criteria.ResponseGroup = responseGroup;
            if (tenant != null && !tenant.IsEmpty)
            {
                criteria.TenantId   = tenant.Id;
                criteria.TenantType = tenant.Type;
            }
            var searchResult = await service.SearchNotificationsAsync(criteria);

            var result = searchResult?.Results.FirstOrDefault(x => x.TenantIdentity == tenant);

            if (result == null)
            {
                //Find first global notification (without tenant)
                criteria.TenantId   = null;
                criteria.TenantType = null;
                searchResult        = await service.SearchNotificationsAsync(criteria);

                result = searchResult?.Results.FirstOrDefault(x => x.TenantIdentity.IsEmpty);
            }

            return(result);
        }
Beispiel #21
0
        public static int Insert(Zippy.Data.IDalProvider db, TenantIdentity entity)
        {
            int rtn = db.Insert(entity);

            return(rtn);
        }