Example #1
0
        private PerformanceCounter[] CreateDirectoryCounter(WatchedDirectories myDirs)
        {
            CounterCreationDataCollection ccdc = new CounterCreationDataCollection();
            CounterCreationData           ccd;

            for (int i = 0; i < myDirs.Count; i++)
            {
                ccd             = new CounterCreationData();
                ccd.CounterName = myDirs[i].DisplayName + DIR_ADD_FILES;
                ccd.CounterHelp = "Shows the number of files added to the directory since " + myDirs[i].StartTime;
                ccd.CounterType = PerformanceCounterType.NumberOfItems32;
                ccdc.Add(ccd);

                ccd             = new CounterCreationData();
                ccd.CounterName = myDirs[i].DisplayName + DIR_REM_FILES;
                ccd.CounterHelp = "Shows the number of files removed from the directory since " + myDirs[i].StartTime;
                ccd.CounterType = PerformanceCounterType.NumberOfItems32;
                ccdc.Add(ccd);

                ccd             = new CounterCreationData();
                ccd.CounterName = myDirs[i].DisplayName + DIR_CUR_FILES;
                ccd.CounterHelp = "Shows the number of files currently in the directory";
                ccd.CounterType = PerformanceCounterType.NumberOfItems32;
                ccdc.Add(ccd);
            }

            if (PerformanceCounterCategory.Exists(PERF_MON_CAT_DIR_WATCHER))
            {
                PerformanceCounterCategory.Delete(PERF_MON_CAT_DIR_WATCHER);
            }

            PerformanceCounterCategory.Create(PERF_MON_CAT_DIR_WATCHER, "Shows the files moving through the indicated directory",
                                              PerformanceCounterCategoryType.Unknown, ccdc);

            PerformanceCounter[] myCounters = new PerformanceCounter[myDirs.Count * 3];
            int j = 0;

            for (int i = 0; i < myDirs.Count; i++)
            {
                myCounters[j++] = new PerformanceCounter(PERF_MON_CAT_DIR_WATCHER,
                                                         myDirs[i].DisplayName + DIR_ADD_FILES,
                                                         false);
                myCounters[j++] = new PerformanceCounter(PERF_MON_CAT_DIR_WATCHER,
                                                         myDirs[i].DisplayName + DIR_REM_FILES,
                                                         false);
                myCounters[j++] = new PerformanceCounter(PERF_MON_CAT_DIR_WATCHER,
                                                         myDirs[i].DisplayName + DIR_CUR_FILES,
                                                         false);
            }

            return(myCounters);
        }
Example #2
0
        private void StartService()
        {
            ConfigureTimer();

            string configFile = GetConfigFilename();

            m_WatchedDirs   = new WatchedDirectories(configFile);
            m_WatchedQueues = new WatchedMessageQueues(configFile);

            m_DirectoryCounters    = CreateDirectoryCounter(m_WatchedDirs);
            m_MessageQueueCounters = CreateMessageQueueCounter(m_WatchedQueues);

            RefreshDirectoryCounters();
            RefreshMessageQueueCounters();

            m_Timer.Start();
        }
Example #3
0
        private void StopService()
        {
            m_Timer.Stop();

            for (int i = 0; i < m_MessageQueueCounters.Length; i++)
            {
                m_MessageQueueCounters[i].Close();
                m_MessageQueueCounters[i].Dispose();
                m_MessageQueueCounters[i] = null;
            }
            PerformanceCounterCategory.Delete(PERF_MON_CAT_MSQ_WATCHER);
            m_WatchedQueues.Dispose();
            m_WatchedQueues = null;

            for (int i = 0; i < m_DirectoryCounters.Length; i++)
            {
                m_DirectoryCounters[i].Close();
                m_DirectoryCounters[i].Dispose();
                m_DirectoryCounters[i] = null;
            }
            PerformanceCounterCategory.Delete(PERF_MON_CAT_DIR_WATCHER);
            m_WatchedDirs.Dispose();
            m_WatchedDirs = null;
        }