Esempio n. 1
0
        public static void ClearActivity(FileChangeTable table)
        {
            table.Activity.Clear();

            foreach (var proj in table.ProjectCollection)
            {
                proj.EditCount         = 0;
                proj.SelectedEditCount = 0;
            }
        }
Esempio n. 2
0
        public void Reinitialize()
        {
            Collection.Clear();
            DaysCollection.Clear();
            var t0 = Table.StartTime.Date;
            var t1 = Table.EndTime.Date;

            foreach (DateTime day in FileChangeTable.EachDay(t0, t1))
            {
                DaysCollection.Add(new FileChangeDay(day, this));
            }
        }
Esempio n. 3
0
        internal void ExtractAndApplySetting(List <string> savedProjectSettings)
        {
            try
            {
                // find the right place
                bool  found = false;
                bool  viz   = true;
                Color?color = null;
                foreach (var line in savedProjectSettings)
                {
                    if (!found)
                    {
                        string path = FileChangeTable.Extract(line, "PATH:");
                        if (path != null && path == Path)
                        {
                            found = true;
                        }
                    }
                    else
                    {
                        if (line == "END")
                        {
                            break;
                        }

                        string txt = FileChangeTable.Extract(line, "VISIBLE:");
                        if (txt != null)
                        {
                            viz = bool.Parse(txt);
                        }

                        var txtCol = FileChangeTable.Extract(line, "COLOR:");
                        if (txtCol != null)
                        {
                            color = ColorTranslator.FromHtml(txtCol);
                        }
                    }
                }

                if (found)
                {
                    Visible = viz;
                    if (color != null)
                    {
                        _brush = null; this.Color = (Color)color;
                    }
                }
            }
            catch
            {
                // ignored
            }
        }
Esempio n. 4
0
 public void RemoveEdits(DateTime?start, DateTime?end)
 {
     this.Collection.RemoveAll(fci =>
     {
         bool contains = FileChangeTable.IsInRange(fci.DateTime, start, end);
         if (contains) //also remove from big list
         {
             this.Table.ItemCollection.Remove(fci);
         }
         return(contains);
     });
 }
Esempio n. 5
0
 internal static bool EqualPathAndTime(ActivityItem fci1, ActivityItem fci2)
 {
     if (fci1 == null || fci2 == null)
     {
         return(false);
     }
     if (fci1.Path == null || fci2.Path == null)
     {
         return(false);
     }
     return(
         fci1.Path == fci2.Path &&
         FileChangeTable.Equal(fci1.DateTime, fci2.DateTime, oneSec));
 }
        void _initiateWatcher()
        {
            Table = new FileChangeTable(LogPath);

            if (_watcher != null)
            {
                _watcher.EnableRaisingEvents = false;
                _watcher.Dispose();
            }

            _watcher = null;

            if (WatchPath == null || Directory.Exists(WatchPath) == false)
            {
                return;
            }

            _watcher = new FileSystemWatcher(WatchPath)
            {
                NotifyFilter = NotifyFilters.LastAccess |
                               NotifyFilters.LastWrite |
                               NotifyFilters.FileName |
                               NotifyFilters.DirectoryName |
                               NotifyFilters.Size |
                               NotifyFilters.CreationTime |
                               NotifyFilters.Attributes |
                               NotifyFilters.Security,
                Filter = "*.*",
                IncludeSubdirectories = true
            };

            _watcher.Changed += Watcher_Changed;
            _watcher.Created += Watcher_Created;
            _watcher.Deleted += Watcher_Deleted;
            _watcher.Renamed += Watcher_Renamed;

            _userAct = new UserActivity();
            _userAct.UserIdleEvent += UserAct_UserIdleEvent;
            UserIdleMinutes         = 5;
//#if DEBUG == true
//           UserIdleMinutes = 0.2;
//#endif

            SystemEvents.PowerModeChanged += OnPowerChange;
        }
Esempio n. 7
0
        public bool GenerateTestLog(string path, int length, DateTime from, DateTime to)
        {
            if (files.Count == 0)
            {
                return(false);
            }

            List <ActivityItem> collection = new List <ActivityItem>();

            for (int i = 0; i < length; i++)
            {
                DateTime dt  = FileChangeTable.GetRandomDate(from, to);
                var      fci = GetFileChangeTestItem(dt);
                if (fci != null)
                {
                    collection.Add(fci);
                }
            }
            collection = FileChangeTable.SortAndSanitize(collection);

            FileChangeTable.Write(null, collection, SortBy.Alphabetical, path);

            return(true);
        }
Esempio n. 8
0
        public static void Build(FileChangeTable table)
        {
            ClearActivity(table);

            // 1 . MAKE list of everything selected
            List <ActivityItem> masterList = new List <ActivityItem>();

            foreach (var proj in table.ProjectCollection)
            {
                if (proj.Visible)
                {
                    foreach (var fci in proj.Collection)
                    {
                        bool isEdit =
                            !fci.ChangeType.HasAny(ActionTypes.RESUME | ActionTypes.SUSPEND | ActionTypes.USER_IDLE);

                        if (isEdit)
                        {
                            fci.Project.EditCount++;
                        }

                        if (fci.IsInSelectedRange)
                        {
                            masterList.Add(fci);
                            if (isEdit)
                            {
                                fci.Project.SelectedEditCount++;
                            }
                        }
                    }
                }
            }

            // sort nicely
            masterList.Sort((x, y) => DateTime.Compare(x.DateTime, y.DateTime));


            // apply smoothing
            ActivityItem             s0                 = null;
            DateTime                 endActivity        = DateTime.MinValue;
            List <ActivityBaseBlock> activityBaseBlocks = new List <ActivityBaseBlock>();

            int editCount = 0;

            foreach (var fci in masterList)
            {
                if (fci.ChangeType.HasFlag(ActionTypes.RESUME))
                {
                    continue;
                }
                else if (UseIdleEvents && fci.ChangeType.HasAny(ActionTypes.SUSPEND | ActionTypes.USER_IDLE))
                { // end at the user's idle
                    endActivity = fci.DateTime;
                    AddActivityBlock();
                    s0 = null;
                }
                else
                {
                    editCount++;
                    if (fci.DateTime > endActivity)
                    {
                        AddActivityBlock();
                        s0 = fci;
                    }
                    endActivity = fci.DateTime.AddMinutes(ActivityTraceBuilder.PerEditMinutes);
                }
            }
            AddActivityBlock();

            table.Activity.Collection   = activityBaseBlocks;
            table.Activity.EditCount    = editCount;
            table.Activity.TotalMinutes = activityBaseBlocks.Sum(blk => (blk.EndDate - blk.StartDate).TotalMinutes);

            void AddActivityBlock()
            {
                if (s0 != null)
                {
                    ActivityBaseBlock blk = new ActivityBaseBlock(s0.DateTime, endActivity);
                    activityBaseBlocks.Add(blk);
                }
            }
        }
        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;
            }
        }
Esempio n. 10
0
 public FileChangeProject(string path, FileChangeTable table)
 {
     this.Path  = path;
     this.Table = table;
     Reinitialize();
 }