示例#1
0
        public ApplicationItem GetOrCreateApplicationItemFromDB(string appName, Process proc)
        {
            string          selectSql = "SELECT * FROM Application WHERE Name = @Name;";
            ApplicationItem app       = _DBConnection.QueryFirstOrDefault <ApplicationItem>(selectSql, new { Name = appName });

            if (app == null)
            {
                // Get the executable
                string exe = ProcessHelper.GetProcessFileName(proc);

                string insertSql = "INSERT INTO Application (Name, Executable) VALUES (@Name, @Executable);";
                _DBConnection.Execute(insertSql, new { Name = appName, Executable = exe });

                app = _DBConnection.QueryFirst <ApplicationItem>(selectSql, new { Name = appName });
            }

            return(app);
        }
        private void UpdateAndSaveForegroundItems(ParsedWindow parsedWindow)
        {
            if (parsedWindow.ApplicationName != null)
            {
                _foregroundAppItem = _DBGateway.GetOrCreateApplicationItemFromDB(parsedWindow.ApplicationName, _foregroundProcess);

                if (parsedWindow.FileName != null)
                {
                    _foregroundFileItem = _DBGateway.GetOrCreateFileItemFromDB(parsedWindow.FileName, parsedWindow.FilePath, _foregroundAppItem.ApplicationId);
                }
            }

            int?   appId      = _foregroundAppItem != null ? _foregroundAppItem.ApplicationId : (int?)null;
            int?   fileId     = _foregroundFileItem != null ? _foregroundFileItem.FileId : (int?)null;
            string windowText = parsedWindow.WindowTitle;

            _foregroundWindowItem = _DBGateway.GetOrCreateWindowItemFromDB(appId, fileId, windowText);

            _DBGateway.InsertWindowHistoryItem(_lastUpdateTime, _foregroundWindowItem.WindowId);
        }