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 Bookings { get; private set; } // public Station(Guid id, int sequence) : base() // { // ID = id; // Sequence = sequence; // Bookings = new List(); // } // public bool SplitBooking(List 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 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 CreateBookings(Widget widget, String name, DateTime start, TimeSpan duration, Boolean shared) // { // List Bookings = new List() // { // 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 FindSlot(Widget widget, String name, DateTime notbefore, TimeSpan duration, Boolean shared) // { // List SortedBookings = Bookings.OrderBy(x => x.Start).ToList(); // DateTime curtime = notbefore; // foreach (Booking booking in SortedBookings) // { // List 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 Stations { get; private set; } // public Section(String name, Guid id, int stations) : base() // { // Name = name; // ID = id; // Stations = new List(); // 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 bookings = null; // foreach (Station curstation in Stations) // { // List 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
Sections { get; private set; } // public List Widgets { get; private set; } // public CalendarFactory() : base() // { // Sections = new List
(); // Widgets = new List(); // } // public void ProcessWidgets(DateTime StartDate, StringBuilder debug) // { // FactorySetup settings = new GlobalConfiguration().Load(); // List 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
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; // } // } // } // } //}