Exemplo n.º 1
0
        public static void DeleteApplicationLog(int applicationLogId)
        {
            IDictionary result;
            result = DbHelper.ExecuteGetFirstRow("SELECT TaskLogId FROM ApplicationsLog WHERE Id = " + applicationLogId);
            if (result == null)
                throw new ApplicationException("The application log entry doesn't exists.");
            int logId = Convert.ToInt32(result["TaskLogId"]);
            //if (logId == Logs.CurrentLog.Id)
            //    throw new ApplicationException("Applications log entries from current task can't be deleted.");

            for (int i = 0; i < currentApplicationsLog.Count;i++ )
            {
                ApplicationLog applicationLog = (ApplicationLog) currentApplicationsLog[i];
                if(applicationLog.Id == applicationLogId)
                {
                    currentApplicationsLog.RemoveAt(i);
                    break;
                }
            }

            DbHelper.ExecuteNonQuery("DELETE FROM ApplicationsLog WHERE Id = " + applicationLogId);

            if (ApplicationsLogChanged != null)
            {
                ApplicationLog alog = new ApplicationLog();
                alog.Id = applicationLogId;
                alog.TaskLogId = logId;
                ApplicationsLogChanged(new ApplicationLogChangeEventArgs(alog, DataRowAction.Delete));
            }
        }
Exemplo n.º 2
0
 public ApplicationLogChangeEventArgs(ApplicationLog applicationLog, DataRowAction action)
 {
     this.applicationLog = applicationLog;
     this.action = action;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Updates Current process (Currently Active) Information
        /// If the process is the same as the last Update, increments time stamp.
        /// </summary>
        private static void UpdateActiveProcess()
        {
            IntPtr processId = IntPtr.Zero;
            try
            {
                DateTime initCallTime = DateTime.Now;

                //currentProcess = GetCurrentHWnd();
                IntPtr hwnd = GetCurrentHWnd();
                if (hwnd == IntPtr.Zero)
                {
                    return;
                }

                GetWindowThreadProcessId(hwnd, out processId);
                int processIdInt32 = processId.ToInt32();
                // This is a PTM.Framework.Infos.ApplicationLog
                ApplicationLog applicationLog = FindCurrentApplication(processIdInt32);
                if (applicationLog == null)
                {
                    // First time this application is detected
                    applicationLog = new ApplicationLog();
                    applicationLog.ProcessId = processIdInt32;

                    using(Process proc = Process.GetProcessById(processIdInt32))
                    {
                        applicationLog.ApplicationFullPath = proc.MainModule.FileName;
                        applicationLog.Name = proc.MainModule.ModuleName;
                    }
                    applicationLog.Caption = GetText(hwnd);
                    applicationLog.ActiveTime = Convert.ToInt32((DateTime.Now - initCallTime).TotalSeconds);
                    applicationLog.LastUpdateTime = DateTime.Now;
                    applicationLog.TaskLogId = Logs.CurrentLog.Id;
                    InsertApplicationLog(applicationLog);

                    if (ApplicationsLogChanged != null)
                    {
                        ApplicationsLogChanged(
                            new ApplicationLogChangeEventArgs(applicationLog,
                            DataRowAction.Add));
                    } //if
                }
                else
                {
                    applicationLog.Caption = GetText(hwnd);
                    if (processId == lastProcess)
                    {
                        applicationLog.ActiveTime = Convert.ToInt32(
                            new TimeSpan(0, 0, applicationLog.ActiveTime).Add(DateTime.Now - applicationLog.LastUpdateTime).TotalSeconds);
                    }
                    else
                    {
                        applicationLog.ActiveTime = Convert.ToInt32(
                            new TimeSpan(0, 0, applicationLog.ActiveTime).Add(DateTime.Now - lastCallTime).TotalSeconds);
                    } //if-else
                    applicationLog.LastUpdateTime = DateTime.Now;
                    if (ApplicationsLogChanged != null)
                    {
                        ApplicationsLogChanged(
                            new ApplicationLogChangeEventArgs(applicationLog,
                            DataRowAction.Change));
                    } //if
                } //if-else
                return;

            }
            catch (Win32Exception w32Ex) //Bug 1884407
            {
                Logger.WriteException(w32Ex);
            }
            finally
            {
                lastProcess = processId;
                lastCallTime = DateTime.Now;
            } //try-catch-finally
        }
Exemplo n.º 4
0
 /// <summary>
 /// Inserts Database information with an application log
 /// </summary>
 private static void InsertApplicationLog(ApplicationLog applicationLog)
 {
     string cmd =
         "INSERT INTO ApplicationsLog(ActiveTime, ApplicationFullPath, Name, TaskLogId, Caption) VALUES (?, ?, ?, ?, ?)";
     applicationLog.Id =
         DbHelper.ExecuteInsert(cmd,
                                new string[]
                                    {
                                        "ActiveTime", "ApplicationFullPath", "Name", "TaskLogId", "Caption"
                                    },
                                new object[]
                                    {
                                    applicationLog.ActiveTime,
                                    GetLast255Chars(applicationLog.ApplicationFullPath),
                                     applicationLog.Name,
                                     applicationLog.TaskLogId,
                                     GetLast255Chars(applicationLog.Caption)
                                 });
     currentApplicationsLog.Add(applicationLog);
 }
Exemplo n.º 5
0
 /// <summary>
 /// GetApplicationsLog retrieves each Application log related 
 /// to a Task selected by its TaskLogId
 /// </summary>
 public static ArrayList GetApplicationsLog(int taskLogId)
 {
     ArrayList resultsHT =
         DbHelper.ExecuteGetRows(
         "SELECT Id, Name, Caption, ApplicationFullPath, ActiveTime FROM ApplicationsLog WHERE TaskLogId = " +
         taskLogId);
     ArrayList results = new ArrayList();
     foreach (IDictionary dictionary in resultsHT)
     {
         ApplicationLog applicationLog = new ApplicationLog();
         applicationLog.Id = (int) dictionary["Id"];
         applicationLog.Name = (string) dictionary["Name"];
         if (dictionary["Caption"]==DBNull.Value)
             applicationLog.Caption = String.Empty;
         else
             applicationLog.Caption = (string)dictionary["Caption"];
         applicationLog.ApplicationFullPath = (string) dictionary["ApplicationFullPath"];
         applicationLog.ActiveTime = (int) dictionary["ActiveTime"];
         applicationLog.TaskLogId = taskLogId;
         results.Add(applicationLog);
     } //foreach
     return results;
 }
Exemplo n.º 6
0
        private void UpdateApplicationsList(ApplicationLog applicationLog, DataRowAction action)
        {
            if (applicationLog == null)
            {
                return;
            }

            string activeTime = null;
            string caption = null;

            if(action == DataRowAction.Add || action == DataRowAction.Change)
            {
                TimeSpan active = new TimeSpan(0, 0, applicationLog.ActiveTime);
                activeTime = ViewHelper.TimeSpanToTimeString(active);
                caption = applicationLog.Caption;
            }

            foreach (TreeListViewItem logItem in this.taskList.Items)
            {
                if (((Log) logItem.Tag).Id == applicationLog.TaskLogId)
                {
                    if (action == DataRowAction.Add)
                    {
                        TreeListViewItem lvi = new TreeListViewItem(caption,
                         new string[] { activeTime, "", applicationLog.Id.ToString(CultureInfo.InvariantCulture) });
                        lvi.Tag = applicationLog;
                        lvi.ImageIndex = IconsManager.GetIconFromFile(applicationLog.ApplicationFullPath);
                        logItem.Items.Add(lvi);
                    }
                    else
                    {
                        for (int i = 0; i < logItem.Items.Count; i++)
                        {
                            TreeListViewItem appItem = logItem.Items[i];
                            if (((ApplicationLog)appItem.Tag).Id == applicationLog.Id)
                            {
                                if (action == DataRowAction.Change)
                                {
                                    appItem.Tag = applicationLog;
                                    appItem.SubItems[TaskDescriptionHeader.Index].Text = caption;
                                    appItem.SubItems[DurationTaskHeader.Index].Text = activeTime;
                                    return;
                                }
                                if (action == DataRowAction.Delete)
                                {
                                    logItem.Items.RemoveAt(i);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }