| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 | namespace Comal.Classes{}//public class Step//{//	public Guid SectionID { get; set; }//	public TimeSpan Duration { get; set; }//	public DateTime EstimatedStartDate { get; set; }//	public SequenceType Sequence { get; set; }//	public Step(Guid sectionid, double minutes, SequenceType sequence)//	{//		SectionID = sectionid;//		long ticks = Convert.ToInt64(minutes * 60F * 1000F * 1000F * 1000F / 100F);//		Duration = new TimeSpan(ticks);//		Sequence = sequence;//	}//	protected Step()//	{//	}//}//public class Widget//{//	public String Name { get; set; }//	public DateTime DueDate { get; set; }//	public Step[] Steps { get; private set; }//	public string JobName { get; set; }//	public string SetoutName { get; set; }//	public Guid PacketID { get; set; }//	public Widget(Guid packetid, String name, String jobname, String setoutname, DateTime duedate, Step[] steps) : base()//	{//		PacketID = packetid;//		Name = name;//		DueDate = duedate;//		JobName = jobname;//		SetoutName = setoutname;//		Steps = steps;//	}//}//public class Booking//{//	public Widget Widget { get; set; }//	public String Name { get; set; }//	public DateTime Start { get; set; }//	public TimeSpan Duration { get; set; }//	public Boolean Shared { get; set; }//	public DateTime End//	{//		get//		{//			return Start.Add(Duration);//		}//		set//		{//			Duration = value.Subtract(Start);//		}//	}//	public Booking(Widget widget, String name, DateTime start, TimeSpan duration, Boolean shared) : base()//	{//		Widget = widget;//		Start = start;//		Name = name;//		Duration = duration;//		Shared = shared;//	}//}//public class Station//{//	public Guid ID { get; set; }//	public int Sequence { get; set; }//	public List<Booking> Bookings { get; private set; }//	public Station(Guid id, int sequence) : base()//	{//		ID = id;//		Sequence = sequence;//		Bookings = new List<Booking>();//	}//	public bool SplitBooking(List<Booking> Bookings, DateTime StartOfBreak, TimeSpan LengthOfBreak)//	{//		Booking booking = Bookings.Last();//		if (booking.Start == StartOfBreak)//		{//			booking.Start = booking.Start.Add(LengthOfBreak);//			return false;//		}//		else if ((booking.Start <= StartOfBreak) && (booking.End > StartOfBreak))//		{//			TimeSpan balance = booking.Duration.Subtract(StartOfBreak.Subtract(booking.Start));//			Booking newbooking = new Booking(booking.Widget, booking.Name, StartOfBreak.Add(LengthOfBreak), balance, booking.Shared);//			Bookings.Add(newbooking);//			booking.End = StartOfBreak;//			return true;//		}//		return false;//	}//	public void SplitBookings(List<Booking> Bookings, TimeSpan StartOfDay, TimeSpan StartOfLunch, int LunchMinutes, TimeSpan EndOfDay)//	{//		bool bSplit = true;//		while (bSplit)//		{//			Booking booking = Bookings.Last();//			bSplit = SplitBooking(Bookings, booking.Start.Date.Add(StartOfLunch), new TimeSpan(0, LunchMinutes, 0));//			if (!bSplit)//			{//				TimeSpan overnight = new TimeSpan(24, 0, 0).Subtract(EndOfDay).Add(StartOfDay);//				bSplit = SplitBooking(Bookings, booking.Start.Date.Add(EndOfDay), overnight);//			}//		}//	}//	private List<Booking> CreateBookings(Widget widget, String name, DateTime start, TimeSpan duration, Boolean shared)//	{//		List<Booking> Bookings = new List<Booking>()//		{//			new Booking(widget, name, start, duration, shared)//		};//		SplitBookings(Bookings, new TimeSpan(7, 0, 0), new TimeSpan(12, 0, 0), 30, new TimeSpan(16, 0, 0));//		return Bookings;//	}//	public List<Booking> FindSlot(Widget widget, String name, DateTime notbefore, TimeSpan duration, Boolean shared)//	{//		List<Booking> SortedBookings = Bookings.OrderBy(x => x.Start).ToList();//		DateTime curtime = notbefore;//		foreach (Booking booking in SortedBookings)//		{//			List<Booking> bookings = CreateBookings(widget, name, curtime, duration, shared);//			if (booking.Start >= bookings.Last().End)//				return bookings;//			curtime = booking.Start.Add(booking.Duration);//			if (curtime < notbefore)//				curtime = notbefore;//		}//		return CreateBookings(widget, name, curtime > notbefore ? curtime : notbefore, duration, shared);//	}//}//public class Section//{//	public String Name { get; set; }//	public Guid ID { get; private set; }//	public List<Station> Stations { get; private set; }//	public Section(String name, Guid id, int stations) : base()//	{//		Name = name;//		ID = id;//		Stations = new List<Station>();//		for (int i = 0; i < stations; i++)//		{//			Stations.Add(new Station(id, i + 1));//		}//	}//	public DateTime AddWidget(Widget Widget, Step step, String name, DateTime notbefore, StringBuilder debug, Boolean findonly, Boolean shared)//	{//		//Step step = Widget.Steps.Where(x => x.SectionID.Equals(ID)).FirstOrDefault();//		//if (step == null)//		//	return DateTime.MaxValue;//		Station station = null;//		DateTime start = DateTime.MaxValue;//		List<Booking> bookings = null;//		foreach (Station curstation in Stations)//		{//			List<Booking> curbookings = curstation.FindSlot(Widget, name, notbefore, step.Duration, shared);//			if (curbookings.First().Start < start)//			{//				bookings = curbookings;//				station = curstation;//				start = curbookings.First().Start;//			}//		}//		if (!findonly)//		{//			debug.AppendLine(String.Format("- Allocating to {0} #{1} at from {2} to {3} ({4} blocks)", Name, station.ID, bookings.First().Start, bookings.Last().End, bookings.Count));//			station.Bookings.AddRange(bookings);//		}//		return bookings.Last().End;//	}//}////public class SectionConfig////{////	public String Name { get; set; }////	public StepType StepType { get; set; }////	public int Stations { get; set; }////}//public class CalendarFactory//{//	public List<Section> Sections { get; private set; }//	public List<Widget> Widgets { get; private set; }//	public CalendarFactory() : base()//	{//		Sections = new List<Section>();//		Widgets = new List<Widget>();//	}//	public void ProcessWidgets(DateTime StartDate, StringBuilder debug)//	{//		FactorySetup settings = new GlobalConfiguration<FactorySetup>().Load();//		List<Widget> SortedList = Widgets.OrderBy(o => o.DueDate).ToList();//		foreach (Widget Widget in SortedList)//		{//			debug.AppendLine(String.Format("Processing Widget: {0}", Widget.Name));//			DateTime maximumstart = StartDate;//			DateTime currentstart = StartDate;//			foreach (Step step in Widget.Steps)//			{//				// Find the setion that matches the step type//				// or all sections if its a shared step//				List<Section> sections = null;//				FactorySection cfg = settings.Sections.Where(x => x.ID.Equals(step.SectionID)).FirstOrDefault();//				if (cfg.Shared)//					sections = Sections.Where(x => x.ID != cfg.ID).ToList();//				else//					sections = Sections.Where(x => x.ID.Equals(step.SectionID)).ToList();//				DateTime bestfinish = DateTime.MaxValue;//				Section bestsection = null;//				DateTime curfinish = DateTime.MaxValue;//				foreach (Section section in sections)//				{//					switch (step.Sequence)//					{//						case SequenceType.Consolidate://							currentstart = maximumstart;//							break;//						case SequenceType.None://							currentstart = StartDate;//							break;//					}//					curfinish = section.AddWidget(Widget, step, cfg.Name, currentstart, debug, true, cfg.Shared);//					if (curfinish < bestfinish)//					{//						bestfinish = curfinish;//						bestsection = section;//					}//				}//				if (bestsection != null)//				{//					currentstart = bestsection.AddWidget(Widget, step, cfg.Name, currentstart, debug, false, cfg.Shared);//					if (currentstart > maximumstart)//						maximumstart = currentstart;//				}//			}//		}//	}//}
 |