Example #1
0
        void parser_PageNotFound(object sender, PageNotFoundEventArgs e)
        {
            Url url                 = e.Url;
            var segments            = url.Path.Trim('~', '/').Split('/');
            var applicationSegments = Url.ApplicationPath.Count(c => c == '/');

            for (int i = segments.Length; i >= applicationSegments; i--)
            {
                var partialUrl = "/" + string.Join("/", segments, 0, i);
                foreach (var item in repository.Find(Parameter.Like("DirectUrl", partialUrl).Detail().Take(host.Sites.Count + 1)))
                {
                    if (i >= segments.Length)
                    {
                        // direct hit
                        if (TryApplyFoundItem(url, e, item))
                        {
                            return;
                        }
                    }
                    else
                    {
                        // try to find subpath
                        var remainder = string.Join("/", segments, i, segments.Length - applicationSegments);
                        var child     = item.GetChild(remainder);
                        if (child != null)
                        {
                            if (TryApplyFoundItem(url, e, child))
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        private NewsContainerModel GetNews(string tag, int skip, int take)
        {
            //IList<News> news = finder.Where.Type.Eq(typeof(News))
            //  .And.Parent.Eq(CurrentPage)
            //  .And.Detail("Tags").Like(tag)
            //  .FirstResult(skip)
            //  .MaxResults(take + 1)
            //  .OrderBy.Published.Desc
            //  .Select<News>();
            var query = (Parameter.Below(CurrentPage) & Parameter.Like("Tags", tag).Detail()).Skip(skip).Take(take + 1).OrderBy("Published DESC");
            var news  = finder.Find(query).OfType <News>().ToList();
            var model = CreateModel(skip, take, news);

            model.Tag = tag;
            return(model);
        }
Example #3
0
        public override MigrationResult Migrate(DatabaseStatus preSchemaUpdateStatus)
        {
            int updatedItems = 0;

            using (var tx = repository.BeginTransaction())
            {
                var itemsWithUntrackedLinks = repository.Find(Parameter.Like(null, "%/upload/%").Detail() & Parameter.IsNull("TrackedLinks").Detail());
                foreach (var item in itemsWithUntrackedLinks)
                {
                    tracker.UpdateLinks(item);
                    repository.SaveOrUpdate(item);
                    updatedItems++;
                }
                tx.Commit();
            }

            var path = config.UploadFolders.AllElements.Where(uf => !string.IsNullOrEmpty(uf.UrlPrefix)).Select(uf => uf.Path).FirstOrDefault();

            path = Url.ToAbsolute(path);

            return(new MigrationResult(this)
            {
                UpdatedItems = updatedItems,
                RedirectTo = "{ManagementUrl}/Content/LinkTracker/UpdateReferences.aspx"
                             + "?selectedUrl=" + path
                             + "&previousUrl=" + path
                             + "&location=upgrade"
            });
        }
Example #4
0
        /// <summary>Searches for items below an ancestor that matches the given query.</summary>
        /// <param name="ancestor">The ancestor below which the results should be found.</param>
        /// <param name="query">The query text.</param>
        /// <param name="skip">A number of items to skip.</param>
        /// <param name="take">A number of items to take.</param>
        /// <returns>An enumeration of items matching the search query.</returns>
        public IEnumerable <ContentItem> Search(string ancestor, string query, int skip, int take, bool?onlyPages, string[] types, out int totalRecords)
        {
            var q = new ParameterCollection();

            if (ancestor != null)
            {
                q.Add(Parameter.Like("AncestralTrail", ancestor + "%") & Parameter.IsNotNull("Title"));
            }

            if (!string.IsNullOrEmpty(query))
            {
                var words = query.Split(' ').Where(w => w.Length > 0).Select(w => "%" + w.Trim('*') + "%");
                q.Add(new ParameterCollection(Operator.Or, words.Select(word => (Parameter.Like("Title", word) | Parameter.Like(null, word).Detail()))));
            }

            if (onlyPages.HasValue)
            {
                if (onlyPages.Value)
                {
                    q.Add(Parameter.IsNull("ZoneName"));
                }
                else
                {
                    q.Add(Parameter.IsNotNull("ZoneName"));
                }
            }

            if (types != null)
            {
                q.Add(Parameter.In("class", types));
            }

            totalRecords = (int)repository.Count(q);
            return(repository.Find(q.Skip(skip).Take(take)));

            //var q = finder.Where.AncestralTrail.Like(ancestor + "%")
            //	.And.Title.IsNull(false);

            //var words = query.Split(' ').Where(w => w.Length > 0).Select(w => "%" + w.Trim('*') + "%");
            //foreach (var word in words)
            //{
            //	q = q.And.OpenBracket()
            //		.Title.Like(word)
            //		.Or.Detail().Like(word)
            //	.CloseBracket();
            //}
            //if (onlyPages.HasValue)
            //	q = q.And.OpenBracket()
            //		.ZoneName.IsNull(onlyPages.Value)
            //		.Or.ZoneName.Eq("")
            //	.CloseBracket();
            //if (types != null)
            //	q = q.And.Property("class").In(types);

            //totalRecords = q.Count();
            //return q.FirstResult(skip).MaxResults(take).Select();
        }
Example #5
0
        private IEnumerable <ContentItem> GetItemsWithSameName(string name, ContentItem parentItem)
        {
            var siblings = (parentItem.ID != 0)
                ? repository.Find(Parameter.Equal("Parent", parentItem) & Parameter.Like("Name", name))
                : parentItem.Children;

            foreach (var sibling in siblings)
            {
                if (string.Equals(sibling.Name, name, StringComparison.InvariantCultureIgnoreCase))
                {
                    yield return(sibling);
                }
            }
        }
        public override ActionResult Index()
        {
            var parameters = Parameter.TypeEqual(typeof(Event).Name)
                             & Parameter.GreaterOrEqual("EventDate", N2.Utility.CurrentTime());

            if (CurrentItem.Container != null)
            {
                parameters.Add(Parameter.BelowOrSelf(CurrentItem.Container));
            }

            var hits = repository.Find(parameters.OrderBy("EventDate").Take(5))
                       .OfType <Event>().ToList();

            return(PartialView(new CalendarTeaserModel(CurrentItem, hits)));
        }
        public override MigrationResult Migrate(DatabaseStatus preSchemaUpdateStatus)
        {
            int updatedItems = 0;

            using (var transaction = repository.BeginTransaction())
            {
                foreach (var item in repository.Find("ChildState", Collections.CollectionState.Unknown))
                {
                    item.ChildState = item.Children.CalculateState();
                    repository.SaveOrUpdate(item);
                    updatedItems++;
                }

                transaction.Commit();
            }

            return(new MigrationResult(this)
            {
                UpdatedItems = updatedItems
            });
        }
Example #8
0
        public override MigrationResult Migrate(DatabaseStatus preSchemaUpdateStatus)
        {
            int updatedItems = 0;

            using (var transaction = repository.BeginTransaction())
            {
                var nonNullZoneNameParts = repository.Find(Parameter.IsNull("ZoneName") & Parameter.TypeIn(definitions.GetDefinitions().Where(d => !d.IsPage).Select(d => d.Discriminator).ToArray()));
                foreach (var item in nonNullZoneNameParts)
                {
                    item.ZoneName = "";
                    repository.SaveOrUpdate(item);
                    updatedItems++;
                }

                transaction.Commit();
            }

            return(new MigrationResult(this)
            {
                UpdatedItems = updatedItems
            });
        }
Example #9
0
        public override System.Web.Mvc.ActionResult Index()
        {
            string viewName = CurrentItem.Boxed ? "BoxedList" : "List";

            ContentItem root = CurrentItem.Container ?? N2.Find.Closest <LanguageRoot>(CurrentPage) ?? N2.Find.StartPage;

            if (root == null)
            {
                return(View(viewName, Enumerable.Empty <News>()));
            }

            //var news = N2.Find.Items.Where.Type.Eq(typeof(News))
            //  .And.AncestralTrail.Like(Utility.GetTrail(root) + "%")
            //  .OrderBy.Published.Desc
            //  .Filters(new AccessFilter(), new PublishedFilter())
            //  .MaxResults(CurrentItem.MaxNews)
            //  .Select<News>();
            var parameters = Parameter.Below(root) & Parameter.State(ContentState.Published) & Parameter.TypeEqual(typeof(News).Name);
            var news       = repository.Find(parameters.Take(CurrentItem.MaxNews).OrderBy("Published DESC"))
                             .OfType <News>().ToList();

            return(View(viewName, news.Where(Content.Is.Accessible())));
        }
Example #10
0
 public override bool IsApplicable(DatabaseStatus status)
 {
     return(status.DatabaseVersion < DatabaseStatus.RequiredDatabaseVersion ||
            !status.HasSchema ||
            repository.Find("ChildState", Collections.CollectionState.Unknown).Any());
 }