public ApplicationMonitor(MonitoredApplication monitoredApplication)
        {
            this.DisplayName = monitoredApplication.DisplayName;
            this.InstalledLocation = monitoredApplication.InstalledLocation;
            this.Executable = monitoredApplication.Executable;
            this.AllUsers = monitoredApplication.AllUsers;
            this.InstalledForUser = monitoredApplication.InstalledForUser;
            this.TotalAllowedMinutes = monitoredApplication.TotalAllowedMinutes;
            this.AllowedIsDefaultValue = monitoredApplication.AllowedIsDefaultValue;
            this.RemainingSecondsToday = monitoredApplication.RemainingSecondsToday;
            this.User = monitoredApplication.User;

            LastTick = DateTime.MinValue;
            this.mWatchedProcesses = new Dictionary<int, Process>(10);
        }
        public MonitoredApplication[] GetMonitoredApplicationsForUser(string userName)
        {
            // first get all the default monitored applications, and seed the results with that list
            MonitoredApplication[] defaultAppMonitors = this.GetDefaultMonitoredApplications();
            List<MonitoredApplication> result = new List<MonitoredApplication>(defaultAppMonitors);

            // build list of all executables being monitored for this user
            List<string> monitoredAppsForUser = new List<string>(20);

            // create the user root or reopen it
            RegistryKey userRootKey = this.mProgramMonitorRoot.CreateSubKey(string.Format(USER_ROOT, userName));

            List<Application> toRemove = new List<Application>();
            foreach (MonitoredApplication defaultAppMonitor in result)
            {
                RegistryKey userAppMonitor = userRootKey.OpenSubKey(defaultAppMonitor.Executable);
                if (userAppMonitor != null)
                {
                    // user has a specific override for this default.  see if it's to set DontMonitor
                    if (this.GetIsDontMonitor(userAppMonitor))
                        toRemove.Add(defaultAppMonitor);
                    else
                    {
                        // there's an entry for this application under the user root, and it's not set to DontMonitor

                        // get the allowed time, using the default time as the default value
                        int dailyMinutes = defaultAppMonitor.TotalAllowedMinutes;
                        bool defaultUsed;
                        dailyMinutes = this.GetTimeAllowed(userAppMonitor, dailyMinutes, out defaultUsed);

                        // get time remaining
                        int timeRemaining = this.GetTimeRemaining(userAppMonitor, dailyMinutes*60);

                        defaultAppMonitor.TotalAllowedMinutes = dailyMinutes;
                        defaultAppMonitor.AllowedIsDefaultValue = defaultUsed;
                        defaultAppMonitor.RemainingSecondsToday = timeRemaining;
                        defaultAppMonitor.User = userName;

                        monitoredAppsForUser.Add(defaultAppMonitor.Executable);
                    }
                }
                else
                {
                    monitoredAppsForUser.Add(defaultAppMonitor.Executable);
                }
            }

            foreach(string executable in userRootKey.GetSubKeyNames())
            {
                if (monitoredAppsForUser.Contains(executable) == false)
                {
                    RegistryKey userAppKey = userRootKey.OpenSubKey(executable);
                    if (this.GetIsDontMonitor(userAppKey) == false)
                    {
                        bool defaultUsed;

                        // it's an entry for the user, and it's not a "don't monitor" entry.  Add it to the results
                        MonitoredApplication userApp = new MonitoredApplication(
                            this.GetDisplayName(userAppKey),
                            this.GetInstalledLocation(userAppKey),
                            executable,
                            this.GetInstalledForUser(userAppKey));

                        userApp.TotalAllowedMinutes = this.GetTimeAllowed(userAppKey, this.GetDefaultDailyMinutesAllowed(),
                                                                          out defaultUsed);
                        userApp.RemainingSecondsToday = this.GetTimeRemaining(userAppKey, userApp.TotalAllowedMinutes * 60);
                        userApp.AllowedIsDefaultValue = false;
                        userApp.User = userName;

                        result.Add(userApp);
                    }
                }
            }

            // remove the ones that we marked as not applicable for this user
            foreach (MonitoredApplication applicationMonitor in toRemove)
                result.Remove(applicationMonitor);

            return result.ToArray();
        }
        public MonitoredApplication[] GetDefaultMonitoredApplications()
        {
            List<MonitoredApplication> result = new List<MonitoredApplication>(20);

            RegistryKey defaultAppMonitor = this.mProgramMonitorRoot.CreateSubKey(DEFAULT_ROOT);
            string[] defaultAppMonitors = defaultAppMonitor.GetSubKeyNames();

            foreach(string application in defaultAppMonitors)
            {
                int dailyMinutes = GetDefaultDailyMinutesAllowed();
                RegistryKey app = defaultAppMonitor.OpenSubKey(application);
                if (app != null)
                {
                    bool defaultUsed;
                    dailyMinutes = this.GetTimeAllowed(app, dailyMinutes, out defaultUsed);

                    string displayName = this.GetDisplayName(app);
                    string installedLocation = this.GetInstalledLocation(app);
                    string installedForUser = this.GetInstalledForUser(app);

                    MonitoredApplication appMonitor = new MonitoredApplication(
                        displayName,
                        installedLocation,
                        application,
                        installedForUser);
                    appMonitor.TotalAllowedMinutes = dailyMinutes;
                    appMonitor.AllowedIsDefaultValue = true;

                    result.Add(appMonitor);
                }
            }

            return result.ToArray();
        }