CalendarClasses.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. namespace Comal.Classes
  2. {
  3. }
  4. //public class Step
  5. //{
  6. // public Guid SectionID { get; set; }
  7. // public TimeSpan Duration { get; set; }
  8. // public DateTime EstimatedStartDate { get; set; }
  9. // public SequenceType Sequence { get; set; }
  10. // public Step(Guid sectionid, double minutes, SequenceType sequence)
  11. // {
  12. // SectionID = sectionid;
  13. // long ticks = Convert.ToInt64(minutes * 60F * 1000F * 1000F * 1000F / 100F);
  14. // Duration = new TimeSpan(ticks);
  15. // Sequence = sequence;
  16. // }
  17. // protected Step()
  18. // {
  19. // }
  20. //}
  21. //public class Widget
  22. //{
  23. // public String Name { get; set; }
  24. // public DateTime DueDate { get; set; }
  25. // public Step[] Steps { get; private set; }
  26. // public string JobName { get; set; }
  27. // public string SetoutName { get; set; }
  28. // public Guid PacketID { get; set; }
  29. // public Widget(Guid packetid, String name, String jobname, String setoutname, DateTime duedate, Step[] steps) : base()
  30. // {
  31. // PacketID = packetid;
  32. // Name = name;
  33. // DueDate = duedate;
  34. // JobName = jobname;
  35. // SetoutName = setoutname;
  36. // Steps = steps;
  37. // }
  38. //}
  39. //public class Booking
  40. //{
  41. // public Widget Widget { get; set; }
  42. // public String Name { get; set; }
  43. // public DateTime Start { get; set; }
  44. // public TimeSpan Duration { get; set; }
  45. // public Boolean Shared { get; set; }
  46. // public DateTime End
  47. // {
  48. // get
  49. // {
  50. // return Start.Add(Duration);
  51. // }
  52. // set
  53. // {
  54. // Duration = value.Subtract(Start);
  55. // }
  56. // }
  57. // public Booking(Widget widget, String name, DateTime start, TimeSpan duration, Boolean shared) : base()
  58. // {
  59. // Widget = widget;
  60. // Start = start;
  61. // Name = name;
  62. // Duration = duration;
  63. // Shared = shared;
  64. // }
  65. //}
  66. //public class Station
  67. //{
  68. // public Guid ID { get; set; }
  69. // public int Sequence { get; set; }
  70. // public List<Booking> Bookings { get; private set; }
  71. // public Station(Guid id, int sequence) : base()
  72. // {
  73. // ID = id;
  74. // Sequence = sequence;
  75. // Bookings = new List<Booking>();
  76. // }
  77. // public bool SplitBooking(List<Booking> Bookings, DateTime StartOfBreak, TimeSpan LengthOfBreak)
  78. // {
  79. // Booking booking = Bookings.Last();
  80. // if (booking.Start == StartOfBreak)
  81. // {
  82. // booking.Start = booking.Start.Add(LengthOfBreak);
  83. // return false;
  84. // }
  85. // else if ((booking.Start <= StartOfBreak) && (booking.End > StartOfBreak))
  86. // {
  87. // TimeSpan balance = booking.Duration.Subtract(StartOfBreak.Subtract(booking.Start));
  88. // Booking newbooking = new Booking(booking.Widget, booking.Name, StartOfBreak.Add(LengthOfBreak), balance, booking.Shared);
  89. // Bookings.Add(newbooking);
  90. // booking.End = StartOfBreak;
  91. // return true;
  92. // }
  93. // return false;
  94. // }
  95. // public void SplitBookings(List<Booking> Bookings, TimeSpan StartOfDay, TimeSpan StartOfLunch, int LunchMinutes, TimeSpan EndOfDay)
  96. // {
  97. // bool bSplit = true;
  98. // while (bSplit)
  99. // {
  100. // Booking booking = Bookings.Last();
  101. // bSplit = SplitBooking(Bookings, booking.Start.Date.Add(StartOfLunch), new TimeSpan(0, LunchMinutes, 0));
  102. // if (!bSplit)
  103. // {
  104. // TimeSpan overnight = new TimeSpan(24, 0, 0).Subtract(EndOfDay).Add(StartOfDay);
  105. // bSplit = SplitBooking(Bookings, booking.Start.Date.Add(EndOfDay), overnight);
  106. // }
  107. // }
  108. // }
  109. // private List<Booking> CreateBookings(Widget widget, String name, DateTime start, TimeSpan duration, Boolean shared)
  110. // {
  111. // List<Booking> Bookings = new List<Booking>()
  112. // {
  113. // new Booking(widget, name, start, duration, shared)
  114. // };
  115. // SplitBookings(Bookings, new TimeSpan(7, 0, 0), new TimeSpan(12, 0, 0), 30, new TimeSpan(16, 0, 0));
  116. // return Bookings;
  117. // }
  118. // public List<Booking> FindSlot(Widget widget, String name, DateTime notbefore, TimeSpan duration, Boolean shared)
  119. // {
  120. // List<Booking> SortedBookings = Bookings.OrderBy(x => x.Start).ToList();
  121. // DateTime curtime = notbefore;
  122. // foreach (Booking booking in SortedBookings)
  123. // {
  124. // List<Booking> bookings = CreateBookings(widget, name, curtime, duration, shared);
  125. // if (booking.Start >= bookings.Last().End)
  126. // return bookings;
  127. // curtime = booking.Start.Add(booking.Duration);
  128. // if (curtime < notbefore)
  129. // curtime = notbefore;
  130. // }
  131. // return CreateBookings(widget, name, curtime > notbefore ? curtime : notbefore, duration, shared);
  132. // }
  133. //}
  134. //public class Section
  135. //{
  136. // public String Name { get; set; }
  137. // public Guid ID { get; private set; }
  138. // public List<Station> Stations { get; private set; }
  139. // public Section(String name, Guid id, int stations) : base()
  140. // {
  141. // Name = name;
  142. // ID = id;
  143. // Stations = new List<Station>();
  144. // for (int i = 0; i < stations; i++)
  145. // {
  146. // Stations.Add(new Station(id, i + 1));
  147. // }
  148. // }
  149. // public DateTime AddWidget(Widget Widget, Step step, String name, DateTime notbefore, StringBuilder debug, Boolean findonly, Boolean shared)
  150. // {
  151. // //Step step = Widget.Steps.Where(x => x.SectionID.Equals(ID)).FirstOrDefault();
  152. // //if (step == null)
  153. // // return DateTime.MaxValue;
  154. // Station station = null;
  155. // DateTime start = DateTime.MaxValue;
  156. // List<Booking> bookings = null;
  157. // foreach (Station curstation in Stations)
  158. // {
  159. // List<Booking> curbookings = curstation.FindSlot(Widget, name, notbefore, step.Duration, shared);
  160. // if (curbookings.First().Start < start)
  161. // {
  162. // bookings = curbookings;
  163. // station = curstation;
  164. // start = curbookings.First().Start;
  165. // }
  166. // }
  167. // if (!findonly)
  168. // {
  169. // 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));
  170. // station.Bookings.AddRange(bookings);
  171. // }
  172. // return bookings.Last().End;
  173. // }
  174. //}
  175. ////public class SectionConfig
  176. ////{
  177. //// public String Name { get; set; }
  178. //// public StepType StepType { get; set; }
  179. //// public int Stations { get; set; }
  180. ////}
  181. //public class CalendarFactory
  182. //{
  183. // public List<Section> Sections { get; private set; }
  184. // public List<Widget> Widgets { get; private set; }
  185. // public CalendarFactory() : base()
  186. // {
  187. // Sections = new List<Section>();
  188. // Widgets = new List<Widget>();
  189. // }
  190. // public void ProcessWidgets(DateTime StartDate, StringBuilder debug)
  191. // {
  192. // FactorySetup settings = new GlobalConfiguration<FactorySetup>().Load();
  193. // List<Widget> SortedList = Widgets.OrderBy(o => o.DueDate).ToList();
  194. // foreach (Widget Widget in SortedList)
  195. // {
  196. // debug.AppendLine(String.Format("Processing Widget: {0}", Widget.Name));
  197. // DateTime maximumstart = StartDate;
  198. // DateTime currentstart = StartDate;
  199. // foreach (Step step in Widget.Steps)
  200. // {
  201. // // Find the setion that matches the step type
  202. // // or all sections if its a shared step
  203. // List<Section> sections = null;
  204. // FactorySection cfg = settings.Sections.Where(x => x.ID.Equals(step.SectionID)).FirstOrDefault();
  205. // if (cfg.Shared)
  206. // sections = Sections.Where(x => x.ID != cfg.ID).ToList();
  207. // else
  208. // sections = Sections.Where(x => x.ID.Equals(step.SectionID)).ToList();
  209. // DateTime bestfinish = DateTime.MaxValue;
  210. // Section bestsection = null;
  211. // DateTime curfinish = DateTime.MaxValue;
  212. // foreach (Section section in sections)
  213. // {
  214. // switch (step.Sequence)
  215. // {
  216. // case SequenceType.Consolidate:
  217. // currentstart = maximumstart;
  218. // break;
  219. // case SequenceType.None:
  220. // currentstart = StartDate;
  221. // break;
  222. // }
  223. // curfinish = section.AddWidget(Widget, step, cfg.Name, currentstart, debug, true, cfg.Shared);
  224. // if (curfinish < bestfinish)
  225. // {
  226. // bestfinish = curfinish;
  227. // bestsection = section;
  228. // }
  229. // }
  230. // if (bestsection != null)
  231. // {
  232. // currentstart = bestsection.AddWidget(Widget, step, cfg.Name, currentstart, debug, false, cfg.Shared);
  233. // if (currentstart > maximumstart)
  234. // maximumstart = currentstart;
  235. // }
  236. // }
  237. // }
  238. // }
  239. //}