Example #1
0
        public void GenerateList(ListSettings settings)
        {
            settings.Job.JobStatus = JobStatus.Running;
            settings.Job.Started   = DateTime.Now;
            settings.Job.JobName   = $"Generating new list '{settings.Name}' with '{settings.Recipients}' recipients";

            try
            {
                settings.Job.Status = $"Creating {settings.Recipients} Contacts";
                var contactRepository = new ContactRepository();
                var contacts          = contactRepository.CreateContacts(settings.Job, settings.Recipients);

                var contactListRepository = new ContactListRepository();
                contactListRepository.CreateList(settings.Job, settings.Name, contacts);

                IndexService.RebuildListIndexes(settings.Job);

                settings.Job.JobStatus = JobStatus.Complete;
                settings.Job.Status    = "DONE!";
                Log.Info($"EXMGenerator completed: {settings.Job.CompletedContacts}", this);
            }
            catch
            {
                settings.Job.Status    = "Failed!";
                settings.Job.JobStatus = JobStatus.Failed;
            }
            finally
            {
                settings.Job.Ended = DateTime.Now;
            }
        }
Example #2
0
        public void GenerateList(ListSettings settings)
        {
            settings.Job.JobStatus = JobStatus.Running;
            settings.Job.Started   = DateTime.Now;
            settings.Job.JobName   = $"Generating new list '{settings.Name}' with '{settings.Recipients}' recipients";

            try
            {
                settings.Job.Status = $"Creating {settings.Recipients} Contacts";
                var contactRepository = new ContactRepository();
                var contacts          = contactRepository.CreateContacts(settings.Job, settings.Recipients);

                var contactListRepository = new ContactListRepository();

                using (new SecurityDisabler())
                {
                    contactListRepository.CreateList(settings.Job, settings.Name, contacts);
                }

                settings.Job.JobStatus = JobStatus.Complete;
                settings.Job.Status    = "DONE!";
                Log.Info($"EXMGenerator completed: {settings.Job.CompletedContacts}", this);
            }
            catch (Exception ex)
            {
                settings.Job.Status    = "Failed!";
                settings.Job.JobStatus = JobStatus.Failed;
                Log.Error(string.Format("EXMGenerator failed: {0}", ex.Message), ex, this);
            }
            finally
            {
                settings.Job.Ended = DateTime.Now;
            }
        }
Example #3
0
        public Job StartCreateListJob(ListSettings settings)
        {
            _activeJob   = new Job();
            settings.Job = _activeJob;
            var options = new JobOptions("ExperienceGeneratorExmLists-" + _activeJob.Id, "ExperienceGenerator", Context.Site.Name, this, "GenerateList", new object[] { settings });

            Sitecore.Jobs.JobManager.Start(options);
            return(_activeJob);
        }
Example #4
0
        public void Create_IfIncludeRootsIsSetToTrue_ShouldReturnAResultWithTheRootIncluded()
        {
            var listSettings = new ListSettings
            {
                IncludeRoot = true
            };

            Assert.AreEqual(5, this.GetListFactory().Create(ContentReference.RootPage, listSettings).Items.Count());
        }
Example #5
0
        public void Create_IfThePaginationModeIsNone_ShouldReturnAResultWithAllItems()
        {
            var listSettings = new ListSettings
            {
                Depth      = int.MaxValue,
                Pagination = this.CreatePaginationSettings(null, PaginationModes.None, null)
            };

            Assert.AreEqual(51, this.GetListFactory().Create(ContentReference.RootPage, listSettings).Items.Count());
        }
Example #6
0
        public IHttpActionResult CreateList(ListSettings settings)
        {
            var job = JobManager.Instance.StartCreateListJob(settings);

            job.StatusUrl = Url.Route("ExperienceGeneratorExmJobsApi", new
            {
                action = "Status",
                id     = job.Id
            });
            return(Ok(job));
        }
Example #7
0
        public void Create_IfTheRootsParameterContainsDuplicates_AndIgnoreDuplicatesIsFalse_ShouldReturnAResultWithoutDuplicates()
        {
            var listSettings = new ListSettings
            {
                IgnoreDuplicates = false
            };

            var root = ContentReference.RootPage;

            Assert.AreEqual(4, this.GetListFactory().Create(new[] { root, root, root }, listSettings).Items.Count());
        }
Example #8
0
        public void Create_Generic_IfTheRootIsTheSiteBlockFolderAndDepthIsSetToMaximum_ShouldReturnAResultWithACorrectNumberOfItems()
        {
            var listSettings = new ListSettings
            {
                Depth = int.MaxValue
            };

            var items = this.GetListFactory().Create <IContentMedia>(ContentReference.SiteBlockFolder, listSettings).Items.ToArray();

            Assert.AreEqual(22, items.Length);
        }
Example #9
0
        public void Create_IfThePaginationModeIsNone_ShouldReturnAResultWithAPaginationWithoutPages()
        {
            var listSettings = new ListSettings
            {
                Depth      = int.MaxValue,
                Pagination = this.CreatePaginationSettings(null, PaginationModes.None, null)
            };

            var pagination = this.GetListFactory().Create(ContentReference.RootPage, listSettings).Pagination;

            Assert.IsFalse(pagination.Pages.Any());
        }
Example #10
0
        public void Create_IfTheRootsParameterContainsDuplicates_AndIgnoreDuplicatesIsTrue_ShouldReturnAResultWithDuplicates()
        {
            var listSettings = new ListSettings
            {
                IgnoreDuplicates = true,
                Pagination       = this.CreatePaginationSettings(null, PaginationModes.Bottom, int.MaxValue)
            };

            var root = ContentReference.RootPage;

            Assert.AreEqual(12, this.GetListFactory().Create(new[] { root, root, root }, listSettings).Items.Count());
        }
        public void SaveOrUpdateListSettings(int userId, string viewId, string data)
        {
            if (data == null)
            {
                data = "";
            }

            if (data.Length > viewDataMaxLength)
            {
                log.ErrorFormat("Saving the view settings failed for user {0} and list {1}; the settings length is {2} and exceeds the {3} limit.", userId, viewId, data.Length, viewDataMaxLength);
                throw new InvalidOperationException("The view settings data exceeds the maximum length.");
            }

            using (AngularGridEntities context = new AngularGridEntities())
            {
                ListSettings ls = context.ListSettings.Where(x => x.UserId == userId && x.ViewId == viewId).FirstOrDefault();
                // we don't need a transaction here as there's an unique index in the database

                if (ls != null)
                {
                    // update existing entry
                    ls.Data = data;
                    log.DebugFormat("Updating the view settings for user {0} and list {1}.");
                }
                else
                {
                    // create a new entry

                    // count the existing entries for the user to prevent malicious pollution
                    int existingEntriesCount = context.ListSettings.Where(x => x.UserId == userId).Count();
                    if (existingEntriesCount > maxViewsPerUser)
                    {
                        log.ErrorFormat("Saving the view settings failed for user {0} and list {1}; the current settings count is {2} and exceeds the {3} limit.", userId, viewId, existingEntriesCount, maxViewsPerUser);
                        throw new InvalidOperationException("The limit of view settings entries for the user has been exceeded.");
                    }

                    ListSettings listSettings = new ListSettings();
                    listSettings.UserId = userId;
                    listSettings.ViewId = viewId;
                    listSettings.Data   = data;

                    context.ListSettings.Add(listSettings);

                    log.DebugFormat("Creating a new view settings entry for user {0} and list {1}.");
                }

                context.SaveChanges();
                log.DebugFormat("Changes in settings for user {0} and list {1} have been successfully saved to the database.");
            }
        }
        public string GetListSettings(int userId, string viewId)
        {
            string r = null;

            using (AngularGridEntities context = new AngularGridEntities())
            {
                ListSettings ls = context.ListSettings.Where(x => x.UserId == userId && x.ViewId == viewId).FirstOrDefault();
                if (ls != null)
                {
                    r = ls.Data;
                }
            }

            return(r);
        }
Example #13
0
        public void Create_IfTheRootIsTheSiteBlockFolderAndDepthIsSetToMaximum_ShouldReturnAResultWithACorrectNumberOfItems()
        {
            var listSettings = new ListSettings
            {
                Depth = int.MaxValue
            };

            var items = this.GetListFactory().Create(ContentReference.SiteBlockFolder, listSettings).Items.ToArray();

            Assert.AreEqual(32, items.Length);
            Assert.AreEqual(7, items.OfType <ContentFolder>().Count());
            Assert.AreEqual(22, items.OfType <IContentMedia>().Count());
            // ReSharper disable SuspiciousTypeConversion.Global
            Assert.AreEqual(3, items.OfType <BlockData>().Count());
            // ReSharper restore SuspiciousTypeConversion.Global
        }
Example #14
0
    public async Task <IActionResult> Cities([FromRoute] string code, CancellationToken token)
    {
        token.ThrowIfCancellationRequested();
        if (string.IsNullOrWhiteSpace(code))
        {
            return(NotFound());
        }
        ListSettings listSettings = new ListSettings
        {
            PageSize         = int.MaxValue,
            OrderBy          = new[] { new SortField(nameof(City.Name)) },
            FilterExpression = $"{nameof(City.CountryCode)} == \"{code.ToUpperInvariant()}\""
        };

        IQueryable <City>   queryable = _cityRepository.List(listSettings);
        IList <CityForList> cities    = await queryable.ProjectTo <CityForList>(_mapper.ConfigurationProvider)
                                        .ToListAsync(token);

        token.ThrowIfCancellationRequested();
        return(Ok(cities));
    }
Example #15
0
 public UserTicketListSetting GetUserListSettingByName(string listName)
 {
     return(ListSettings.FirstOrDefault(us => us.ListName.Equals(listName, StringComparison.InvariantCultureIgnoreCase)));
 }
Example #16
0
        public void Create_IfTheRootIsTheSiteBlockFolder_ShouldReturnAResultWithACorrectNumberOfItems()
        {
            var listSettings = new ListSettings();

            Assert.AreEqual(3, this.GetListFactory().Create(ContentReference.SiteBlockFolder, listSettings).Items.Count());
        }
Example #17
0
    public async Task <IActionResult> List([FromQuery] UserList pagination, CancellationToken token)
    {
        token.ThrowIfCancellationRequested();

        string userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

        if (string.IsNullOrEmpty(userId))
        {
            return(Unauthorized());
        }
        pagination ??= new UserList();

        ListSettings listSettings = _mapper.Map <ListSettings>(pagination);

        listSettings.Include = new List <string>
        {
            nameof(Model.User.Photos),
            nameof(Model.User.Likers),
            nameof(Model.User.Likees)
        };

        listSettings.FilterExpression = BuildFilter(userId, User, pagination);

        if (listSettings.OrderBy == null || listSettings.OrderBy.Count == 0)
        {
            listSettings.OrderBy = new[]
            {
                new SortField($"{nameof(Model.User.Likers)}.Count", SortType.Descending),
                new SortField(nameof(Model.User.LastActive), SortType.Descending),
                new SortField(nameof(Model.User.FirstName)),
                new SortField(nameof(Model.User.LastName))
            };
        }

        IQueryable <User> queryable = _repository.List(listSettings);

        listSettings.Count = await queryable.CountAsync(token);

        token.ThrowIfCancellationRequested();

        IList <UserForList> users = await queryable.Paginate(pagination)
                                    .ProjectTo <UserForList>(_mapper.ConfigurationProvider)
                                    .ToListAsync(token);

        if (users.Count > 0)
        {
            ISet <string> likees = await _repository.LikeesFromListAsync(userId, users.Select(e => e.Id), token);

            token.ThrowIfCancellationRequested();

            foreach (UserForList user in users)
            {
                bool isLikee = likees.Contains(user.Id);
                user.CanBeLiked    = !isLikee;
                user.CanBeDisliked = isLikee;
                user.PhotoUrl      = _repository.ImageBuilder.Build(user.Id, user.PhotoUrl).String();
            }
        }

        pagination = _mapper.Map(listSettings, pagination);
        return(Ok(new Paginated <UserForList>(users, pagination)));
Example #18
0
 public UriComposer(ListSettings listSettings) => _listSettings = listSettings;