public DynamicGrouping(DynamicPublishedContentList list, string groupBy)
 {
     Inner =
         list
         .Items
         .Select(node =>
     {
         string predicate = groupBy;
         var internalList = new DynamicPublishedContentList(new DynamicPublishedContent[] { node });
         var query        = (IQueryable <object>)internalList.Select(predicate, new object[] { });
         var key          = query.FirstOrDefault();
         return(new
         {
             Key = key,
             Node = node
         });
     })
         .Where(item => item.Key != null)
         .GroupBy(item => item.Key)
         .Select(item => new Grouping <object, DynamicPublishedContent>()
     {
         Key      = item.Key,
         Elements = item.Select(inner => inner.Node)
     });
 }
示例#2
0
        public static DynamicPublishedContentList Random(this DynamicPublishedContentList all, int min, int max)
        {
            //get a random number generator
            Random r = new Random();
            //choose the number of elements to be returned between Min and Max
            int Number = r.Next(min, max);

            //Call the other method
            return(Random(all, Number));
        }
示例#3
0
        ///<summary>Get a list of calendar events from a single node</summary>
        ///<param name="date">Event date</param>
        ///<param name="propertyType">Alias of the property holding the Datatype KS.Umbraco7.Calendar</param>
        ///<param name="nodeId">Id of the event node</param>
        ///<param name="splitNoneRecurring">Optional: Split none recurring events by day, true by default</param>
        ///<returns>An ordered List with CalendarEvents ordered by date</returns>
        public static List <CalendarEvent> getNodeEvents(DateTime date, int nodeId, string propertyType, bool splitNoneRecurring = true)
        {
            List <CalendarEvent> events = new List <CalendarEvent>();

            try
            {
                var node = new DynamicPublishedContent(new UmbracoHelper(UmbracoContext.Current).Content(nodeId));
                DynamicPublishedContentList nodes = new DynamicPublishedContentList();
                nodes.Add(node);
                return(getEventList(date.Date, date.Date.AddDays(1).AddMilliseconds(-1), propertyType, nodes, splitNoneRecurring));
            }
            catch (Exception ex) {
                //LogHelper.Error<CalendarEvent>("getNodeEvents", ex);
            }
            return(events);
        }
示例#4
0
        public static IPublishedContent Down(this IPublishedContent content, int number)
        {
            var children = content.Children;

            if (number == 0)
            {
                return(children.First());
            }
            var working = content;

            while (number-- >= 0)
            {
                working  = children.First();
                children = new DynamicPublishedContentList(working.Children);
            }
            return(working);
        }
示例#5
0
        public static bool Where(this IPublishedContent doc, string predicate)
        {
            if (doc == null)
            {
                throw new ArgumentNullException("doc");
            }
            //Totally gonna cheat here
            var dynamicDocumentList = new DynamicPublishedContentList();

            dynamicDocumentList.Add(doc.AsDynamicPublishedContent());
            var filtered = dynamicDocumentList.Where <DynamicPublishedContent>(predicate);

            if (Queryable.Count(filtered) == 1)
            {
                //this node matches the predicate
                return(true);
            }
            return(false);
        }
示例#6
0
        public static IQueryable <IPublishedContent> Where(this IEnumerable <IPublishedContent> list, string predicate)
        {
            var dList = new DynamicPublishedContentList(list);

            return(dList.Where <DynamicPublishedContent>(predicate));
        }
示例#7
0
 private static IEnumerable <IPublishedContent> OrderByRandom(this DynamicPublishedContentList source)
 {
     return(source.Items.OrderBy(x => Guid.NewGuid()));
 }
		public bool Where(string predicate)
		{
			//Totally gonna cheat here
			var dynamicDocumentList = new DynamicPublishedContentList();
			dynamicDocumentList.Add(this);
			var filtered = dynamicDocumentList.Where<DynamicPublishedContent>(predicate);
			if (Queryable.Count(filtered) == 1)
			{
				//this node matches the predicate
				return true;
			}
			return false;
		}
示例#9
0
 public static DynamicPublishedContentList Random(this DynamicPublishedContentList all, int max)
 {
     //Randomly order the items in the set by a Guid, Take the correct number, and return this wrapped in a new DynamicNodeList
     return(new DynamicPublishedContentList(all.Items.OrderBy(x => Guid.NewGuid()).Take(max)));
 }
		public static bool Where(this IPublishedContent doc, string predicate)
		{
			if (doc == null) throw new ArgumentNullException("doc");
			//Totally gonna cheat here
			var dynamicDocumentList = new DynamicPublishedContentList();
			dynamicDocumentList.Add(doc.AsDynamicPublishedContent());
			var filtered = dynamicDocumentList.Where<DynamicPublishedContent>(predicate);
			if (Queryable.Count(filtered) == 1)
			{
				//this node matches the predicate
				return true;
			}
			return false;
		}
		public static IQueryable Select(this IEnumerable<IPublishedContent> list, string predicate, params object[] values)
		{
			var dList = new DynamicPublishedContentList(list);
			return dList.Select(predicate);
		}
		public static IEnumerable<IGrouping<object, IPublishedContent>> GroupBy(this IEnumerable<IPublishedContent> list, string predicate)
		{
			var dList = new DynamicPublishedContentList(list);
			return dList.GroupBy(predicate);
		}
		public static IQueryable<IPublishedContent> Where(this IEnumerable<IPublishedContent> list, string predicate)
		{
			var dList = new DynamicPublishedContentList(list);
			return dList.Where<DynamicPublishedContent>(predicate);
		}
示例#14
0
        ///<summary>Get a list of calendar events</summary>
        ///<param name="startDate">Start date for event list</param>
        ///<param name="endDate">End date for event list</param>
        ///<param name="propertyType">Alias of the property holding the Datatype KS.Umbraco7.Calendar</param>
        ///<param name="nodes">DynamicPublishedContentlist holding the nodes where we will be looking for events</param>
        ///
        ///<returns>An ordered List with CalendarEvents ordered by startDate</returns>
        private static List <CalendarEvent> getEventList(DateTime startDate, DateTime endDate, string propertyType, DynamicPublishedContentList nodes, bool splitNoneRecurring = true)
        {
            List <CalendarEvent> events = new List <CalendarEvent>();

            foreach (var node in nodes)
            {
                if (node.HasValue(propertyType))
                {
                    CalendarEvent e = Newtonsoft.Json.JsonConvert.DeserializeObject <CalendarEvent>(node.GetPropertyValue(propertyType).ToString());
                    if (e.exceptDates == null)
                    {
                        e.exceptDates = new List <DateTime>();
                    }
                    if (e.days == null)
                    {
                        e.days = new int?[0];
                    }
                    if (e.months == null)
                    {
                        e.months = new int?[0];
                    }

                    if ((startDate <= e.startDate || (e.recurrence > 1 && (e.recurUntil.HasValue && startDate <= e.recurUntil.Value)) || (e.recurrence > 1 && !e.recurUntil.HasValue) || (e.endDate.HasValue && startDate <= e.endDate.Value)) && e.startDate <= endDate)
                    {
                        int durationMinutes = 0;
                        if (e.endDate.HasValue)
                        {
                            durationMinutes = (int)e.endDate.Value.Subtract(e.startDate).TotalMinutes;
                        }

                        DateTime eEndDate = (!e.recurUntil.HasValue ? endDate : (e.recurUntil.Value < endDate ? e.recurUntil.Value.AddDays(1).AddSeconds(-1) : endDate));
                        e.content = node;
                        switch (e.recurrence)
                        {
                        case 1:
                            //no recurrence
                            if (e.endDate.HasValue && e.startDate.Date < e.endDate.Value.Date && splitNoneRecurring)
                            {
                                //event spanning several days
                                DateTime dSDate = startDate.Date <= e.startDate.Date ? e.startDate.Date : startDate.Date;
                                for (DateTime d = dSDate; d <= e.endDate.Value.Date; d = d.AddDays(1))
                                {
                                    CalendarEvent ce = new CalendarEvent();
                                    if (e.startDate.Date < d.Date)
                                    {
                                        ce.startDate = d.Date;
                                    }
                                    else
                                    {
                                        //TimeSpan ts = d.Date - e.startDate;
                                        //ce.startDate = e.startDate.AddDays(ts.Days *-1);
                                        ce.startDate = e.startDate;
                                    }
                                    if (d.Date < e.endDate.Value.Date)
                                    {
                                        ce.endDate = d.Date.AddDays(1).AddSeconds(-1);
                                    }
                                    else
                                    {
                                        ce.endDate = e.endDate.Value;
                                    }
                                    ce.recurrence = e.recurrence;
                                    ce.content    = e.content;
                                    if (ce.startDate <= endDate)
                                    {
                                        events.Add(ce);
                                    }
                                }
                            }
                            else
                            {
                                events.Add(e);
                            }
                            break;

                        case 2:
                            //repeat daily
                            DateTime dStartDate = startDate.Date <= e.startDate.Date ? e.startDate.Date : startDate.Date;
                            //loop through all days from startdate to enddate
                            for (DateTime d = dStartDate; d <= eEndDate; d = d.AddDays(1))
                            {
                                //if the event is selected for the actual day, add it to the list
                                if (e.days.Contains((int)d.DayOfWeek))
                                {
                                    CalendarEvent ce = new CalendarEvent();
                                    ce.recurrence = e.recurrence;
                                    ce.startDate  = e.startDate.AddDays(d.Date.Subtract(e.startDate.Date).Days);
                                    ce.endDate    = (e.endDate.HasValue ? ce.startDate.AddMinutes(durationMinutes) : e.endDate);
                                    ce.content    = e.content;
                                    //ce.Debug = "Enddate: " + eEndDate.ToString("dd.MM.yyyy HH:mm");
                                    if (!e.exceptDates.Contains(ce.startDate.Date) && ce.startDate <= endDate)
                                    {
                                        events.Add(ce);
                                    }
                                }
                            }
                            break;

                        case 3:
                            //repeat weekl
                            //DateTime wStartDate = startDate.Date <= e.startDate.Date ? e.startDate.Date : startDate.Date;
                            //loop through all weeks from startdate to enddate, e.weekInterval tell if event sould occure every week, every other week, every thrid week etc.
                            //for (DateTime w = wStartDate; w <= eEndDate; w = w.AddDays(7 * e.weekInterval))
                            if (e.startDate < endDate)
                            {
                                for (DateTime w = e.startDate.Date; w <= eEndDate; w = w.AddDays(7 * e.weekInterval))
                                {
                                    DateTime wEndDate = (eEndDate < w.AddDays(7) ? eEndDate : w.AddDays(6));
                                    //looping each day in the actual week and adding the event to the list on the correct day
                                    for (DateTime d = w; d <= wEndDate; d = d.AddDays(1))
                                    {
                                        if ((e.days.Contains((int)d.DayOfWeek) && (startDate <= d && d <= endDate)))
                                        {
                                            CalendarEvent ce = new CalendarEvent();
                                            ce.recurrence = e.recurrence;
                                            ce.startDate  = e.startDate.AddDays(d.Date.Subtract(e.startDate.Date).Days);
                                            ce.endDate    = (e.endDate.HasValue ? ce.startDate.AddMinutes(durationMinutes) : e.endDate);
                                            ce.content    = e.content;
                                            //ce.Debug = "Her";
                                            if (!e.exceptDates.Contains(ce.startDate.Date) && ce.startDate <= endDate)
                                            {
                                                events.Add(ce);
                                            }
                                        }
                                    }
                                }
                            }
                            break;

                        case 4:
                            //repeat monthly
                            DateTime mStartDate;

                            if (e.monthYearOption == 1)
                            {
                                //use startdate every month
                                if (startDate < e.startDate)
                                {
                                    //bruk e.startdate
                                    mStartDate = e.startDate;
                                }
                                else
                                {
                                    if (e.startDate.Day < startDate.Day)
                                    {
                                        mStartDate = startDate.AddMonths(1).AddDays(((startDate.Day - e.startDate.Day) * -1) + 1);
                                    }
                                    else
                                    {
                                        mStartDate = startDate.AddDays(e.startDate.Day - startDate.Day);
                                    }
                                }

                                for (DateTime d = mStartDate; d <= eEndDate; d = d.AddMonths(1))
                                {
                                    if (e.monthOption.Value != 2 || (e.monthOption.Value == 2 && e.months.Contains(d.Month)))
                                    {
                                        CalendarEvent ce = new CalendarEvent();
                                        ce.recurrence = e.recurrence;
                                        ce.startDate  = e.startDate.AddDays(d.Date.Subtract(e.startDate.Date).Days);
                                        ce.endDate    = (e.endDate.HasValue ? ce.startDate.AddMinutes(durationMinutes) : e.endDate);
                                        ce.content    = e.content;
                                        if (!e.exceptDates.Contains(ce.startDate.Date) && ce.startDate <= endDate)
                                        {
                                            events.Add(ce);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                //specify
                                //looping every month from startdate to enddate

                                mStartDate = startDate < e.startDate ? e.startDate : startDate;
                                for (DateTime d = mStartDate; d <= eEndDate; d = d.AddMonths(1))
                                {
                                    if (e.interval < 6)
                                    {
                                        //1st - 5th weekday this month
                                        DateTime ed = d.GetNthWeekofMonth(e.interval, (DayOfWeek)e.weekDay);
                                        //c.Debug += " " + ed.ToString("dd.MM.yyyy hh:mm");
                                        //adding the event to the list
                                        if (startDate.Date <= ed.Date && d.Month == ed.Month && (e.monthOption.Value != 2 || (e.monthOption.Value == 2 && e.months.Contains(ed.Month))))
                                        {
                                            CalendarEvent ce = new CalendarEvent();
                                            ce.recurrence = e.recurrence;
                                            ce.startDate  = e.startDate.AddDays(ed.Date.Subtract(e.startDate.Date).Days);
                                            ce.endDate    = (e.endDate.HasValue ? ce.startDate.AddMinutes(durationMinutes) : e.endDate);
                                            ce.content    = e.content;
                                            //ce.Debug = "d: " + d.ToString("dd.MM.yyyy hh:mm") + "  -  " + "ed.month: " + ed.Month + "  d.month: " + d.Month + "  ";
                                            if (!e.exceptDates.Contains(ce.startDate.Date) && ce.startDate <= endDate)
                                            {
                                                events.Add(ce);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //last weekDay of month
                                        DateTime lwd = d.Last((DayOfWeek)e.weekDay);
                                        //adding event to list
                                        if (lwd <= eEndDate && (e.monthOption.Value != 2 || (e.monthOption.Value == 2 && e.months.Contains(d.Month))))
                                        {
                                            CalendarEvent ce = new CalendarEvent();
                                            ce.recurrence = e.recurrence;
                                            ce.startDate  = e.startDate.AddDays(lwd.Date.Subtract(e.startDate.Date).Days);
                                            ce.endDate    = (e.endDate.HasValue ? ce.startDate.AddMinutes(durationMinutes) : e.endDate);
                                            ce.content    = e.content;
                                            //ce.Debug = "Siste " + (DayOfWeek)e.weekDay + " i måneden";
                                            //ce.Debug = "d: " + d.ToString("dd.MM.yyyy hh:mm") + "  -  " + "ed.month: " + ed.Month + "  d.month: " + d.Month + "  ";
                                            if (!e.exceptDates.Contains(ce.startDate.Date) && ce.startDate <= endDate)
                                            {
                                                events.Add(ce);
                                            }
                                        }
                                    }
                                }
                            }

                            break;

                        case 5:
                            //repeat yearly
                            DateTime yStartDate;
                            if (startDate < e.startDate)
                            {
                                //bruk e.startdate
                                yStartDate = e.startDate;
                            }
                            else
                            {
                                if (e.startDate.Day < startDate.Day)
                                {
                                    yStartDate = startDate.AddMonths(1).AddDays(((startDate.Day - e.startDate.Day) * -1) + 1);
                                }
                                else
                                {
                                    yStartDate = startDate.AddDays(e.startDate.Day - startDate.Day);
                                }
                            }
                            if (e.monthYearOption == 1)
                            {
                                //use startdate

                                for (DateTime d = yStartDate; d <= eEndDate; d = d.AddYears(1))
                                {
                                    CalendarEvent ce = new CalendarEvent();
                                    ce.recurrence = e.recurrence;
                                    ce.startDate  = e.startDate.AddYears(d.Year - e.startDate.Year);
                                    ce.endDate    = (e.endDate.HasValue ? ce.startDate.AddMinutes(durationMinutes) : e.endDate);
                                    ce.content    = e.content;
                                    if (startDate <= ce.startDate && ce.startDate <= endDate && !e.exceptDates.Contains(ce.startDate.Date))
                                    {
                                        events.Add(ce);
                                    }
                                }
                            }
                            else
                            {
                                //specify
                                for (DateTime d = yStartDate.AddDays((startDate.Day - 1) * -1); d <= eEndDate; d = d.AddYears(1))
                                {
                                    d = d.AddMonths((d.Month - 1) * -1).AddDays((d.Day - 1) * -1).AddMonths(e.month - 1);

                                    if (e.interval < 6)
                                    {
                                        //1st - 5th weekday in month
                                        DateTime ed = d.GetNthWeekofMonth(e.interval, (DayOfWeek)e.weekDay);
                                        //c.Debug += " " + ed.ToString("dd.MM.yyyy hh:mm");
                                        if (startDate.Date <= ed.Date && ed <= endDate && d.Month == ed.Month)
                                        {
                                            CalendarEvent ce = new CalendarEvent();
                                            ce.recurrence = e.recurrence;
                                            ce.startDate  = e.startDate.AddDays(ed.Date.Subtract(e.startDate.Date).Days);
                                            ce.endDate    = (e.endDate.HasValue ? ce.startDate.AddMinutes(durationMinutes) : e.endDate);
                                            ce.content    = e.content;
                                            //ce.Debug = "d: " + d.ToString("dd.MM.yyyy hh:mm") + "  -  " + "ed.month: " + ed.Month + "  d.month: " + d.Month + "  ";
                                            if (!e.exceptDates.Contains(ce.startDate.Date) && ce.startDate <= endDate)
                                            {
                                                events.Add(ce);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //last weekDay in month
                                        DateTime      lwd = d.Last((DayOfWeek)e.weekDay);
                                        CalendarEvent ce  = new CalendarEvent();
                                        ce.recurrence = e.recurrence;
                                        ce.startDate  = e.startDate.AddDays(lwd.Date.Subtract(e.startDate.Date).Days);
                                        ce.endDate    = (e.endDate.HasValue ? ce.startDate.AddMinutes(durationMinutes) : e.endDate);
                                        ce.content    = e.content;
                                        //ce.Debug = "Siste " + (DayOfWeek)e.weekDay + " i måneden";
                                        //ce.Debug = "d: " + d.ToString("dd.MM.yyyy hh:mm") + "  -  " + "ed.month: " + ed.Month + "  d.month: " + d.Month + "  ";
                                        if (startDate <= ce.startDate && ce.startDate <= endDate && !e.exceptDates.Contains(ce.startDate.Date))
                                        {
                                            events.Add(ce);
                                        }
                                    }
                                }
                            }
                            break;

                        default: break;
                        }
                    }
                }
            }
            //order event list and return
            return(events.OrderBy(x => x.startDate).ToList());
        }
示例#15
0
        public IEnumerator <T> GetEnumerator()
        {
            var temp = new DynamicPublishedContentList(Elements.Cast <DynamicPublishedContent>());

            return((IEnumerator <T>)temp.GetEnumerator());
        }
示例#16
0
        public static IEnumerable <IGrouping <object, IPublishedContent> > GroupBy(this IEnumerable <IPublishedContent> list, string predicate)
        {
            var dList = new DynamicPublishedContentList(list);

            return(dList.GroupBy(predicate));
        }
示例#17
0
        public static IQueryable Select(this IEnumerable <IPublishedContent> list, string predicate, params object[] values)
        {
            var dList = new DynamicPublishedContentList(list);

            return(dList.Select(predicate));
        }
		public static IPublishedContent Down(this IPublishedContent content, int number)
		{
			var children = content.Children;
			if (number == 0)
			{
				return children.First();
			}
			var working = content;
			while (number-- >= 0)
			{
				working = children.First();
				children = new DynamicPublishedContentList(working.Children);
			}
			return working;
		}
示例#19
0
 public static DynamicPublishedContentList Random(this DynamicPublishedContentList source, int min, int max)
 {
     return(Random(source, new Random().Next(min, max)));
 }
示例#20
0
 public static DynamicPublishedContentList Random(this DynamicPublishedContentList source, int max)
 {
     return(new DynamicPublishedContentList(source.OrderByRandom().Take(max)));
 }
示例#21
0
 public static DynamicPublishedContent Random(this DynamicPublishedContentList all)
 {
     return(all.Items.OrderBy(x => Guid.NewGuid()).First());
 }
示例#22
0
 public static DynamicPublishedContent Random(this DynamicPublishedContentList source)
 {
     return(new DynamicPublishedContent(source.OrderByRandom().First()));
 }
 public static string DynamicDocumentListMultiParam(this DynamicPublishedContentList doc, string custom, int i, bool b)
 {
     return(custom + i + b);
 }
		private object ExecuteExtensionMethod(object[] args, string name)
		{
			object result = null;
			
			var methodTypesToFind = new[]
        		{
					typeof(DynamicPublishedContent)
        		};

			//find known extension methods that match the first type in the list
			MethodInfo toExecute = null;
			foreach (var t in methodTypesToFind)
			{
				toExecute = ExtensionMethodFinder.FindExtensionMethod(t, args, name, false);
				if (toExecute != null)
					break;
			}

			if (toExecute != null)
			{
				var genericArgs = (new[] { this }).Concat(args);
				result = toExecute.Invoke(null, genericArgs.ToArray());
			}
			else
			{
				throw new MissingMethodException();
			}
			if (result != null)
			{
				if (result is IPublishedContent)
				{
					result = new DynamicPublishedContent((IPublishedContent)result);
				}				
				if (result is IEnumerable<IPublishedContent>)
				{
					result = new DynamicPublishedContentList((IEnumerable<IPublishedContent>)result);
				}
				if (result is IEnumerable<DynamicPublishedContent>)
				{
					result = new DynamicPublishedContentList((IEnumerable<DynamicPublishedContent>)result);
				}				
			}
			return result;
		}