public DateTime?GetDateTime(TRB_KIND kind, TRB_PART part, TRB_PART where, TRB_STATE whereState)
        {
            DateTime?dt = null;

            switch (kind)
            {
            case TRB_KIND.MINIMUM:
                dt = TimeBoxCollection.Where(trb => trb.GetDateTime(where, whereState) != null).Min(trb => trb.GetDateTime(part));
                break;

            case TRB_KIND.MAXIMUM:
                dt = TimeBoxCollection.Where(trb => trb.GetDateTime(where, whereState) != null).Max(trb => trb.GetDateTime(part));
                break;

            case TRB_KIND.FIRST:
            {
                var atrb =
                    TimeBoxCollection.Where(trb => trb.GetDateTime(where, whereState) != null).FirstOrDefault(trb => null != trb.GetDateTime(part));
                dt = atrb != null?atrb.GetDateTime(part) : null;
            }
            break;

            case TRB_KIND.LAST:
            {
                var atrb =
                    TimeBoxCollection.Where(trb => trb.GetDateTime(where, whereState) != null).LastOrDefault(trb => null != trb.GetDateTime(part));
                dt = atrb != null?atrb.GetDateTime(part) : null;
            }
            break;
            }
            return(dt);
        }
        internal TimeBox TimeBoxAdd(DateTime start, DateTime end)
        {
            // add time box
            var trb = new TimeBox(start, end, this);

            TimeBoxCollection.Add(trb);
            TimeBox._sort(TimeBoxCollection);
            TimeBoxMerge();
            return(trb);
        }
 internal void TimeBoxAdd(List <TimeBox> collection)
 {
     foreach (var src in collection)
     {
         var trb = new TimeBox(src.StartDate, src.EndDate, this);
         trb.CopyStates(src);
         TimeBoxCollection.Add(trb);
     }
     TimeBox._sort(TimeBoxCollection);
     TimeBoxMerge();
 }
 internal void TimeBoxClearContainedEdits(TRB_PART part, TRB_STATE state)
 {
     // edits within time boxes
     TimeBoxCollection.ForEach(trb =>
     {
         if (trb.HasState(part, state))
         {
             trb.ClearContainedEdits();
         }
     });
 }
 internal void TimeBoxMerge()
 {
     // carry out on sorted
     for (int i = 0; i < TimeBoxCollection.Count - 1; i++)
     {
         var tbA = TimeBoxCollection[i];
         var tbB = TimeBoxCollection[i + 1];
         if (tbA.IntersectInclusive(tbB))
         {
             tbA.StartState = tbA.StartState | tbB.StartState;
             tbA.EndState   = tbA.EndState | tbB.EndState;
             tbA.WholeState = tbA.WholeState | tbB.WholeState;
             tbA.EndDate    = tbB.EndDate;
             TimeBoxCollection.RemoveAt(i + 1);
             i--;
         }
     }
 }
 internal TimeBox TimeBoxGet(Guid uid)
 {
     return(TimeBoxCollection.FirstOrDefault(trb => trb.UID == uid));
 }
 internal void TimeBoxClear()
 {
     TimeBoxCollection.Clear();
 }
 internal bool HasState(TRB_PART part, TRB_STATE state)
 {
     return(TimeBoxCollection.FirstOrDefault(trb => trb.HasState(part, state)) != null);
 }
 internal bool TimeBoxContains(DateTime dt)
 {
     return(TimeBoxCollection.FirstOrDefault(trb => trb.Contains(dt)) != null);
 }
Esempio n. 10
0
        internal void ExtractAndApplySetting(List <string> savedProjectSettings)
        {
            try
            {
                // find the right place
                bool           found    = false;
                bool           viz      = true;
                bool           gotColor = false;
                Color          color    = Color.Gray;
                List <TimeBox> tboxes   = new List <TimeBox>();
                foreach (var line in savedProjectSettings)
                {
                    string path = _extract("PATH:", line);
                    if (path != null && path == Path)
                    {
                        found = true; continue;
                    }
                    if (!found)
                    {
                        continue;
                    }
                    if (line == "END")
                    {
                        break;
                    }
                    string txt = _extract("VISIBLE:", line);
                    if (txt != null)
                    {
                        viz = bool.Parse(txt); continue;
                    }

                    txt = _extract("COLOR:", line);
                    if (txt != null)
                    {
                        color = ColorTranslator.FromHtml(txt); gotColor = true; continue;
                    }

                    txt = _extract("TIMEBOX:", line);
                    if (txt != null)
                    {
                        TimeBox trb = TimeBox.FromSetting(txt);
                        if (trb != null)
                        {
                            tboxes.Add(trb);
                        }
                    }
                }

                if (found)
                {
                    Visible = viz;
                    if (gotColor)
                    {
                        _color = color; _brush = null;
                    }
                    TimeBoxCollection.Clear();
                    TimeBoxAdd(tboxes);
                }
            }
            catch
            {
                // ignored
            }
        }
Esempio n. 11
0
 internal void DeleteTimeBoxes(TRB_PART part, TRB_STATE state)
 {
     TimeBoxCollection.RemoveAll(trb => trb.HasState(part, state));
 }
Esempio n. 12
0
 internal void ToggleState(TRB_PART part, TRB_PART where, TRB_STATE state)
 {
     TimeBoxCollection.ForEach(trb => trb.ToggleState(part, where, state));
 }
Esempio n. 13
0
 internal void UnsetState(TRB_PART part, TRB_PART where, TRB_STATE whereState, TRB_STATE state)
 {
     TimeBoxCollection.ForEach(trb => trb.UnsetState(part, where, whereState, state));
 }
Esempio n. 14
0
 internal void SetState(TRB_PART part, TRB_STATE state)
 {
     TimeBoxCollection.ForEach(trb => trb.SetState(part, state));
 }
Esempio n. 15
0
 internal void TimeBoxProcess(Action <TimeBox> p)
 {
     TimeBoxCollection.ForEach(trb => trb.Process(p));
 }
Esempio n. 16
0
 internal void SetDateTime(TRB_PART part, TRB_STATE partState, DateTime dt)
 {
     TimeBoxCollection.ForEach(trb => trb.SetDateTime(part, partState, dt));
 }