示例#1
0
        internal static TimeBox FromSetting(string txt)
        {
            try
            {
                var part = txt.Split(" ".ToCharArray(), StringSplitOptions.None);

                DateTime  dt0        = _deserialize(part[0]);
                DateTime  dt1        = _deserialize(part[1]);
                TRB_STATE startState = (TRB_STATE)Enum.Parse(typeof(TRB_STATE), part[2]);
                TRB_STATE endState   = (TRB_STATE)Enum.Parse(typeof(TRB_STATE), part[3]);
                TRB_STATE wholeState = (TRB_STATE)Enum.Parse(typeof(TRB_STATE), part[4]);

                TimeBox tbox = new TimeBox(dt0, dt1);
                tbox.StartState = startState;
                tbox.EndState   = endState;
                tbox.WholeState = wholeState;
                return(tbox);
            }
            catch
            {
                // ignored
            }

            return(null);
        }
示例#2
0
        private static bool _subtract(List <TimeBox> tbListA, List <TimeBox> tbListB)
        {
            for (int i = 0; i < tbListA.Count; i++)
            {
                var tbA = tbListA[i];

                foreach (var tbB in tbListB)
                {
                    bool change = false;
                    var  res    = _subtract(tbA, tbB, ref change);
                    if (change)
                    {
                        // insert res at i
                        if (res.Count > 0)
                        {
                            tbListA.AddRange(res);
                        }
                        // remove original
                        tbListA.Remove(tbA);
                        TimeBox._sort(tbListA);
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#3
0
        public static List <TimeBox> Subtract(TimeBox tbA, List <TimeBox> tbListB)
        {
            List <TimeBox> tbListA = new List <TimeBox>();

            tbListA.Add(tbA);
            return(Subtract(tbListA, tbListB));
        }
示例#4
0
        static TimeBox _matchingTimeBox(DateTime t0, DateTime t1, TimeBox src)
        {
            var tb = new TimeBox(t0, t1);

            tb.CopyStates(src);
            return(tb);
        }
示例#5
0
        static public void TestSubtract()
        {
            //      BOX: 4 / 06 / 2020 12:00:00 AM - 7 / 06 / 2020 12:00:00 AM
            //     PROJ:
            //9 / 06 / 2020 12:00:00 AM - 15 / 06 / 2020 12:00:00 AM
            //     REM:
            //15 / 06 / 2020 12:00:00 AM - 7 / 06 / 2020 12:00:00 AM
            {
                TimeBox tbFromBox = new TimeBox(new DateTime(2020, 6, 4, 0, 0, 0), new DateTime(2020, 6, 7, 0, 0, 0));
                Console.WriteLine("BOX:" + tbFromBox.ToString());
                Console.WriteLine("PROJ:");
                List <TimeBox> timeBoxes = new List <TimeBox>();
                timeBoxes.Add(new TimeBox(new DateTime(2020, 6, 9, 0, 0, 0), new DateTime(2020, 6, 15, 0, 0, 0)));
                timeBoxes.ForEach(trb => Console.WriteLine("  " + trb.ToString()));
                Console.WriteLine("REM:");
                var remainingTRBs = TimeBox.Subtract(tbFromBox, timeBoxes);
                if (remainingTRBs.Count == 0)
                {
                    Console.WriteLine("  Nothing");
                }
                remainingTRBs.ForEach(trb => Console.WriteLine("  " + trb.ToString()));
            }


            {
                TimeBox tbFromBox = new TimeBox(new DateTime(2020, 6, 13, 0, 0, 0), new DateTime(2020, 6, 17, 0, 0, 0));
                Console.WriteLine("BOX:" + tbFromBox.ToString());
                Console.WriteLine("PROJ:");
                List <TimeBox> timeBoxes = new List <TimeBox>();
                timeBoxes.Add(new TimeBox(new DateTime(2020, 6, 9, 0, 0, 0), new DateTime(2020, 6, 21, 0, 0, 0)));
                timeBoxes.ForEach(trb => Console.WriteLine("  " + trb.ToString()));
                Console.WriteLine("REM:");
                var remainingTRBs = TimeBox.Subtract(tbFromBox, timeBoxes);
                if (remainingTRBs.Count == 0)
                {
                    Console.WriteLine("  Nothing");
                }
                remainingTRBs.ForEach(trb => Console.WriteLine("  " + trb.ToString()));
            }

            {
                TimeBox tbFromBox = new TimeBox(new DateTime(2020, 6, 5, 0, 0, 0), new DateTime(2020, 6, 12, 0, 0, 0));
                Console.WriteLine("BOX:" + tbFromBox.ToString());
                Console.WriteLine("PROJ:");
                List <TimeBox> timeBoxes = new List <TimeBox>();
                timeBoxes.Add(new TimeBox(new DateTime(2020, 6, 9, 0, 0, 0), new DateTime(2020, 6, 19, 0, 0, 0)));
                timeBoxes.ForEach(trb => Console.WriteLine("  " + trb.ToString()));
                Console.WriteLine("REM:");
                var remainingTRBs = TimeBox.Subtract(tbFromBox, timeBoxes);
                if (remainingTRBs.Count == 0)
                {
                    Console.WriteLine("  Nothing");
                }
                remainingTRBs.ForEach(trb => Console.WriteLine("  " + trb.ToString()));
            }
        }
        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();
 }
        private TimeBox _getAdj(TimeBox trb, int dir)
        {
            int idx = trb.Project.TimeBoxCollection.IndexOf(trb);

            if (idx == -1)
            {
                return(null);
            }
            idx += dir;
            if (idx >= 0 && idx < trb.Project.TimeBoxCollection.Count)
            {
                return(trb.Project.TimeBoxCollection[idx]);
            }
            return(null);
        }
示例#9
0
        static void Test()
        {
            TimeBox trA = new TimeBox(new DateTime(2001, 4, 18), new DateTime(2002, 7, 17));
            TimeBox trB = new TimeBox(new DateTime(2002, 7, 17), new DateTime(2002, 8, 17));

            // 1 day overlap expected
            trA.IntersectExclusive(trB);

            trB = new TimeBox(new DateTime(2002, 7, 18), new DateTime(2002, 8, 17));
            // no overlap
            trA.IntersectExclusive(trB);

            trB = new TimeBox(new DateTime(2001, 4, 18), new DateTime(2001, 4, 18));// one day period
            // no overlap
            trA.IntersectExclusive(trB);
        }
示例#10
0
        private bool _snapToUnselectedEdges(ref DateTime dt, TimeSpan snapSpan)
        {
            bool snapped = false;

            UnsetState(TRB_PART.START | TRB_PART.END, TRB_STATE.SNAPPED_TO);

            DateTime myDT_0                = dt - ptrAdjTS_0;
            DateTime myDT_1                = dt - ptrAdjTS_1;
            TimeSpan closeSpan             = TimeSpan.MaxValue;
            TimeBox  trbClose              = null;
            TRB_PART closePart             = TRB_PART.NONE;
            TRB_PART movingPartThatSnapped = TRB_PART.NONE;

            foreach (var proj in EachVisibleProject())
            {
                if (!proj.Visible)
                {
                    continue;
                }
                ;
                foreach (var trb in proj.TimeBoxCollection)
                {
                    if (trb.HasState(TRB_PART.WHOLE, TRB_STATE.NOT | TRB_STATE.SELECTED))
                    {
                        TimeSpan tmpSpan;

                        if (movingPart.HasFlag(TRB_PART.START))
                        {
                            tmpSpan = (trb.StartDate - myDT_0).Duration();
                            if (tmpSpan < closeSpan)
                            {
                                trbClose              = trb;
                                closeSpan             = tmpSpan;
                                closePart             = TRB_PART.START;
                                movingPartThatSnapped = TRB_PART.START;
                            }

                            tmpSpan = (trb.EndDate - myDT_0).Duration();
                            if (tmpSpan < closeSpan)
                            {
                                trbClose              = trb;
                                closeSpan             = tmpSpan;
                                closePart             = TRB_PART.END;
                                movingPartThatSnapped = TRB_PART.START;
                            }
                        }

                        if (movingPart.HasFlag(TRB_PART.END))
                        {
                            tmpSpan = (trb.StartDate - myDT_1).Duration();
                            if (tmpSpan < closeSpan)
                            {
                                trbClose              = trb;
                                closeSpan             = tmpSpan;
                                closePart             = TRB_PART.START;
                                movingPartThatSnapped = TRB_PART.END;
                            }

                            tmpSpan = (trb.EndDate - myDT_1).Duration();
                            if (tmpSpan < closeSpan)
                            {
                                trbClose              = trb;
                                closeSpan             = tmpSpan;
                                closePart             = TRB_PART.END;
                                movingPartThatSnapped = TRB_PART.END;
                            }
                        }
                    }
                }
            }

            if (trbClose != null && closeSpan <= snapSpan)
            {
                snapped = true;
                dt      = (DateTime)trbClose.GetDateTime(closePart);
                dt      = dt + (movingPartThatSnapped == TRB_PART.START ? ptrAdjTS_0 : ptrAdjTS_1);
                trbClose.SetState(closePart, TRB_STATE.SNAPPED_TO);
            }

            return(snapped);
        }
示例#11
0
        public void MoveSelectedEdges(TimeBox trbClicked, TRB_PART partMov, DateTime dt, TimeSpan snapSpan,
                                      TRB_ACTION action)
        {
            // rules..
            // don't move other edges ???
            if (action == TRB_ACTION.BEGIN)
            {
                startDT = dt;

                ptrAdjTS_0 = dt - (DateTime)trbClicked.GetDateTime(TRB_PART.START);
                ptrAdjTS_1 = dt - (DateTime)trbClicked.GetDateTime(TRB_PART.END);

                // 1 unset all edges
                UnsetState(TRB_PART.START | TRB_PART.END, TRB_STATE.SELECTED);
                // 2 set edges accordingly
                SetState(partMov, TRB_PART.WHOLE, TRB_STATE.SELECTED);

                // 3. what edge are we moving, start or end?
                movingPart = partMov;

                TimeBox adj;
                spanL = TimeSpan.MinValue;
                spanR = TimeSpan.MaxValue;

                if (movingPart.HasFlag(TRB_PART.START))
                {
                    // left move
                    // 4. Get the minimum distance to the previous end
                    foreach (var proj in EachVisibleProject())
                    {
                        if (!proj.Visible)
                        {
                            continue;
                        }
                        foreach (var trb in proj.TimeBoxCollection)
                        {
                            if (trb.HasState(movingPart, TRB_STATE.SELECTED))
                            {
                                trb.StoreDates();
                                adj = _getAdj(trb, -1);
                                if (adj != null)
                                {
                                    spanL = _max(spanL, adj.EndDate - trb.StartDate);
                                }
                                if (!movingPart.HasFlag(TRB_PART.END))
                                {
                                    spanR = _min(spanR, trb.EndDate - trb.StartDate);
                                }
                            }
                        }
                    }
                }

                if (movingPart.HasFlag(TRB_PART.END))
                {
                    // right move
                    // 5. Get the MAximuim distance to the next start
                    foreach (var proj in EachVisibleProject())
                    {
                        if (!proj.Visible)
                        {
                            continue;
                        }
                        foreach (var trb in proj.TimeBoxCollection)
                        {
                            if (trb.HasState(movingPart, TRB_STATE.SELECTED))
                            {
                                trb.StoreDates();
                                adj = _getAdj(trb, +1);
                                if (adj != null)
                                {
                                    spanR = _min(spanR, adj.StartDate - trb.EndDate);
                                }
                                if (!movingPart.HasFlag(TRB_PART.START))
                                {
                                    spanL = _max(spanL, trb.StartDate - trb.EndDate);
                                }
                            }
                        }
                    }
                }
            }

            bool snapped = false;

            if (snapSpan.TotalMinutes > 0)
            {
                // snap the active edge only
                snapped = _snapToUnselectedEdges(ref dt, snapSpan);
            }

            TimeSpan spanDT = dt - startDT;

            if (spanDT < spanL)
            {
                spanDT = spanL;
            }
            if (spanDT > spanR)
            {
                spanDT = spanR;
            }

            foreach (var proj in EachVisibleProject())
            {
                if (!proj.Visible)
                {
                    continue;
                }
                foreach (var trb in proj.TimeBoxCollection)
                {
                    if (trb.HasState(movingPart, TRB_STATE.SELECTED))
                    {
                        trb.ShiftDateTime(movingPart, spanDT);
                    }
                }
            }

            if (snapped)
            {
                SetState(TRB_PART.END, TRB_PART.END, TRB_STATE.SELECTED, TRB_STATE.SNAPPED);
            }
            else
            {
                UnsetState(TRB_PART.END, TRB_PART.END, TRB_STATE.SELECTED, TRB_STATE.SNAPPED);
            }


            // finally snap the unsnapped to others nearest day
            if (action == TRB_ACTION.FINISH)
            {
                // condition: Selected but not snapped
                TimeBoxProcess(delegate(TimeBox trb)
                {
                    if (trb.HasState(movingPart, TRB_STATE.SELECTED) &&
                        trb.HasState(movingPart, TRB_STATE.SNAPPED | TRB_STATE.NOT))
                    {
                        // snap to whole day
                        var myDT   = (DateTime)trb.GetDateTime(movingPart);
                        var snapDT = FileChangeTable.Round(myDT, new TimeSpan(1, 0, 0, 0));

                        var thisSpan = snapDT - trb.GetStoredDateTime(movingPart);
                        if (thisSpan < spanL)
                        {
                            thisSpan = spanL;
                        }
                        if (thisSpan > spanR)
                        {
                            thisSpan = spanR;
                        }
                        trb.ShiftDateTime(movingPart, (TimeSpan)thisSpan);
                    }
                });

                foreach (var proj in EachVisibleProject())
                {
                    if (!proj.Visible)
                    {
                        continue;
                    }
                    if (proj.HasState(TRB_PART.WHOLE, TRB_STATE.SELECTED))
                    {
                        proj.TimeBoxSort();
                        proj.TimeBoxMerge();
                    }
                }

                ActivityTraceBuilder.Buildv2(this);
                movingPart = TRB_PART.NONE;
            }
        }
示例#12
0
        public Form1()
        {
            InitializeComponent();



#if DEBUG == true
            for (int i = 0; i < 16; i++)
            {
                ActionTypes at_A = (ActionTypes)i;
                string      s1   = "";
                string      s2   = "";
                string      s3   = "";
                s1 += (at_A.BinaryString(4) + "  :  ");
                s2 += ("ANY   :  ");
                s3 += ("HAS   :  ");
                for (int j = 0; j < 16; j++)
                {
                    ActionTypes at_B = (ActionTypes)j;
                    s1 += (at_B.BinaryString(4) + "  ");
                    s2 += (at_A.HasAny(at_B) ? "TRUE  " : "FALSE ");
                    s3 += (at_A.HasFlag(at_B) ? "TRUE  " : "FALSE ");
                }

                Console.WriteLine(s1);
                Console.WriteLine(s2);
                Console.WriteLine(s3);
                Console.WriteLine();
            }

            TimeBox.TestSubtract();
#endif

            notifyIcon1.BalloonTipClosed += (sender, e) =>
            {
                var thisIcon = (NotifyIcon)sender;
                thisIcon.Visible = false;
                thisIcon.Dispose();
            };

            // watch this file structure
            _fcWatcher            = new FileChangeWatcher();
            _fcWatcher.Extensions = new string[] { ".cs" };
            _fcWatcher.Changed   += FolderChangeWatcher_Changed;
            _fcWatcher.Error     += FolderChangeWatcher_Error;
            //_fcWatcher.AutoSaveMinutesInterval = 3;

            eventScroller1.FileChangeWatcher = _fcWatcher;

            themeController          = new ThemeController();
            themeController.Changed += Themer_Changed;

            mainPanel = new MainPanel(_fcWatcher, doubleBuffer1, themeController.Theme);

            this.Icon = notifyIcon1.Icon;
            BaseForm.ApplicationIcon = notifyIcon1.Icon;

            toolStripTextBoxWithLabelIdleTime.LabelText    = "Idle Time(m)";
            toolStripTextBoxWithLabelTimePerEdit.LabelText = "Per Edit Time(m)";
            toolStripTextBoxWithLabelIdleTime.Set(_fcWatcher.UserIdleMinutes);
            toolStripTextBoxWithLabelTimePerEdit.Set(_fcWatcher.PerEditMinutes);
            toolStripTextBoxWithLabelIdleTime.TextBox.EnterPressed    += TextBox_EnterPressed;
            toolStripTextBoxWithLabelTimePerEdit.TextBox.EnterPressed += TextBox_EnterPressed1;
            useIdleEventsToolStripMenuItem.Checked    = _fcWatcher.UseIdleEvents;
            advancedToolStripMenuItem.DropDownClosed += AdvancedToolStripMenuItem_DropDownClosed;
            Application.Idle += Application_Idle;
        }
 internal void TimeBoxSort()
 {
     TimeBox._sort(TimeBoxCollection);
 }
        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
            }
        }
示例#15
0
        private static List <TimeBox> _subtract(TimeBox tbA, TimeBox tbB, ref bool change)
        {
            List <TimeBox> tmp = new List <TimeBox>();

            change = true;

            // 1: B after A
            // A :      [----]
            // B :             [-----]
            //Res:      [----]
            if (tbB.StartDate >= tbA.EndDate)
            {
                tmp.Add(_matchingTimeBox(tbA.StartDate, tbA.EndDate, tbA));
                change = false;
            }
            // 2: B before A
            // A :         [----]
            // B : [-----]
            //Res:         [----]
            else if (tbA.StartDate >= tbB.EndDate)
            {
                tmp.Add(_matchingTimeBox(tbA.StartDate, tbA.EndDate, tbA));
                change = false;
            }
            // 3: total delete
            // A :      [----]
            // B : [---------------]
            //Res:
            else if (tbB.StartDate <= tbA.StartDate && tbB.EndDate >= tbA.EndDate)
            {
                // do nothing
            }
            // 4: deletes that split..
            // A : [---------------]
            // B :      [----]
            //Res: [---]      [----]
            else if (tbB.StartDate > tbA.StartDate && tbB.EndDate < tbA.EndDate)
            {
                tmp.Add(_matchingTimeBox(tbA.StartDate, tbB.StartDate, tbA));
                tmp.Add(_matchingTimeBox(tbB.EndDate, tbA.EndDate, tbA));
            }
            // 5: deletes that truncate start
            // A :     [---------------]
            // B :   [----]
            //Res:         [-----------]
            else if (tbB.StartDate <= tbA.StartDate && tbB.EndDate > tbA.StartDate)
            {
                tmp.Add(_matchingTimeBox(tbB.EndDate, tbA.EndDate, tbA));
            }
            // 6: deletes that truncate end
            // A :     [---------------]
            // B :                  [----]
            //Res:     [-----------]
            else if (tbB.EndDate >= tbA.EndDate && tbB.StartDate < tbA.EndDate)
            {
                tmp.Add(_matchingTimeBox(tbA.StartDate, tbB.StartDate, tbA));
            }
            //Res:      [----]
            else
            {
                // effectively no change
                tmp.Add(_matchingTimeBox(tbA.StartDate, tbA.EndDate, tbA));
                change = false;
            }

            if (tmp.RemoveAll(trb => trb.StartDate == trb.EndDate) > 0)// remove zeros
            {
                change = true;
            }

            return(tmp);
        }
示例#16
0
 public void CopyStates(TimeBox src)
 {
     StartState = src.StartState;
     EndState   = src.EndState;
     WholeState = src.WholeState;
 }