コード例 #1
0
        public void GetVisualStudioProjectsTest()
        {
            // dummy data
            var dummyList = new List <ArtifactTest>();

            dummyList.Add(new ArtifactTest("ConsoleApplication1 (Debugging) - Microsoft Visual Studio (Administrator)", "", "ConsoleApplication1"));
            dummyList.Add(new ArtifactTest("ConsoleApplication1 (Running) - Microsoft Visual Studio (Administrator)", "", "ConsoleApplication1"));
            dummyList.Add(new ArtifactTest("ConsoleApplication1 - Microsoft Visual Studio", "", "ConsoleApplication1"));
            dummyList.Add(new ArtifactTest("Add New Item - SchemaGenerator", "", ""));
            dummyList.Add(new ArtifactTest("Add New Item - Query Service Model", "", ""));
            dummyList.Add(new ArtifactTest("sources_dev_transportsync_src_common.dgml - Microsoft Visual Studio", "", "sources_dev_transportsync_src_common.dgml"));
            dummyList.Add(new ArtifactTest("Microsoft Visual Studio", "", ""));

            // run method
            foreach (var row in dummyList)
            {
                var title = WindowTitleCodeExtractor.GetProjectName(row.InputTitle);

                Debug.WriteLine(row.OutputExpected + " - vs - " + title);
                Assert.AreEqual(row.OutputExpected, title);
            }
        }
コード例 #2
0
        /// <summary>
        /// Fetches the activities a developer has on his computer for a given date in an
        /// ordered list according to time.
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        internal static List <WindowsActivity> GetDayTimelineData(DateTimeOffset date)
        {
            var orderedActivityList = new List <WindowsActivity>();

            try
            {
                var query = "SELECT t1.time as 'tsStart', t2.time as 'tsEnd', t1.window, t1.process, (strftime('%s', t2.time) - strftime('%s', t1.time)) as 'durInSec' " //t1.id, t1.time as 'from', t2.time as 'to'
                            + "FROM " + Settings.DbTable + " t1 LEFT JOIN " + Settings.DbTable + " t2 on t1.id + 1 = t2.id "
                            + "WHERE " + Database.GetInstance().GetDateFilteringStringForQuery(VisType.Day, date, "t1.time") + " and " + Database.GetInstance().GetDateFilteringStringForQuery(VisType.Day, date, "t2.time") + " "
                            + "ORDER BY t1.time;";

                var table = Database.GetInstance().ExecuteReadQuery(query);

                WindowsActivity _previousWindowsActivityEntry = null;

                foreach (DataRow row in table.Rows)
                {
                    // fetch items from database
                    var e = new WindowsActivity();
                    e.StartTime         = DateTime.Parse((string)row["tsStart"], CultureInfo.InvariantCulture);
                    e.EndTime           = DateTime.Parse((string)row["tsEnd"], CultureInfo.InvariantCulture);
                    e.DurationInSeconds = row.IsNull("durInSec") ? 0 : Convert.ToInt32(row["durInSec"], CultureInfo.InvariantCulture);
                    var processName = (string)row["process"];

                    // make window titles more readable (TODO: improve!)
                    var windowTitle = (string)row["window"];
                    windowTitle = WindowTitleWebsitesExtractor.GetWebsiteDetails(processName, windowTitle);
                    windowTitle = WindowTitleArtifactExtractor.GetArtifactDetails(processName, windowTitle);
                    windowTitle = WindowTitleCodeExtractor.GetProjectName(windowTitle);

                    // map process and window to activity
                    ProcessToActivityMapper.Map(e, processName, windowTitle);

                    // check if we add a new item, or merge with the previous one
                    if (_previousWindowsActivityEntry != null)
                    {
                        // previous item is same, update it (duration and tsEnd)
                        if (e.ActivityCategory == _previousWindowsActivityEntry.ActivityCategory)
                        {
                            var lastItem = orderedActivityList.Last();
                            lastItem.DurationInSeconds += e.DurationInSeconds;
                            lastItem.EndTime            = e.EndTime;
                            lastItem.WindowProcessList.Add(new WindowProcessItem(processName, windowTitle));
                        }
                        // previous item is different, add it to list
                        else
                        {
                            e.WindowProcessList.Add(new WindowProcessItem(processName, windowTitle));
                            orderedActivityList.Add(e);
                        }
                    }
                    else // first item
                    {
                        orderedActivityList.Add(e);
                    }
                    _previousWindowsActivityEntry = e;
                }
                table.Dispose();
            }
            catch (Exception e)
            {
                Logger.WriteToLogFile(e);
            }

            return(orderedActivityList);
        }