예제 #1
0
        internal void SetInstanceName(String instanceName)
        {
            PerformanceCounterData[] data = s_DefaultPerformanceCounters;

            if (String.IsNullOrEmpty(instanceName))
            {
                try
                {
                    // The assert is safe here as we never give out the instance name.
                    new System.Security.Permissions.SecurityPermission(System.Security.Permissions.PermissionState.Unrestricted).Assert();
                    Process       process    = Process.GetCurrentProcess();
                    ProcessModule mainModule = process.MainModule;
                    instanceName = mainModule.ModuleName;
                }
                finally
                {
                    System.Security.CodeAccessPermission.RevertAssert();
                }
            }

            this.m_instanceName = instanceName;

            // Build a mapping of PerformanceCounterActions to the actual actions that need
            // to be performed.  If this become a perf issue, we could build the default mapping
            // at build time.

            Dictionary <PerformanceCounterAction, List <PerformanceCounterStatement> > actionStatements = new Dictionary <PerformanceCounterAction, List <PerformanceCounterStatement> >();

            if (PerformanceCounterCategory.Exists(c_PerformanceCounterCategoryName))
            {
                for (int i = 0; i < data.Length; ++i)
                {
                    PerformanceCounterData currentData = data[i];
                    for (int j = 0; j < currentData.Mappings.Length; ++j)
                    {
                        PerformanceCounterActionMapping currentMapping = currentData.Mappings[j];
                        if (!actionStatements.ContainsKey(currentMapping.Action))
                        {
                            actionStatements.Add(currentMapping.Action, new List <PerformanceCounterStatement>());
                        }
                        List <PerformanceCounterStatement> lStatements  = actionStatements[currentMapping.Action];
                        PerformanceCounterStatement        newStatement = new PerformanceCounterStatement(CreateCounters(currentData.Name), currentMapping.Operation);
                        lStatements.Add(newStatement);
                    }
                }
            }

            this.m_actionStatements = actionStatements;
        }
        private void NotifyCounter(PerformanceCounterAction action, PerformanceCounterStatement statement, WorkflowExecutor executor)
        {
            foreach (PerformanceCounter counter in statement.Counters)
            {
                switch (statement.Operation)
                {
                case PerformanceCounterOperation.Increment:
                    counter.Increment();
                    break;

                case PerformanceCounterOperation.Decrement:
                    counter.Decrement();
                    break;
                }
            }
        }
예제 #3
0
        private void NotifyCounter(PerformanceCounterAction action, PerformanceCounterStatement statement, WorkflowExecutor executor)
        {
            foreach (PerformanceCounter counter in statement.Counters)
            {
                switch (statement.Operation)
                {
                case PerformanceCounterOperation.Increment:
                    counter.Increment();
                    break;

                case PerformanceCounterOperation.Decrement:
                    counter.Decrement();
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false, "Unknown performance counter operation.");
                    break;
                }
            }
        }
        internal void SetInstanceName(string instanceName)
        {
            PerformanceCounterData[] dataArray = s_DefaultPerformanceCounters;
            if (string.IsNullOrEmpty(instanceName))
            {
                try
                {
                    new SecurityPermission(PermissionState.Unrestricted).Assert();
                    instanceName = Process.GetCurrentProcess().MainModule.ModuleName;
                }
                finally
                {
                    CodeAccessPermission.RevertAssert();
                }
            }
            this.m_instanceName = instanceName;
            Dictionary <PerformanceCounterAction, List <PerformanceCounterStatement> > dictionary = new Dictionary <PerformanceCounterAction, List <PerformanceCounterStatement> >();

            if (PerformanceCounterCategory.Exists(c_PerformanceCounterCategoryName))
            {
                for (int i = 0; i < dataArray.Length; i++)
                {
                    PerformanceCounterData data = dataArray[i];
                    for (int j = 0; j < data.Mappings.Length; j++)
                    {
                        PerformanceCounterActionMapping mapping = data.Mappings[j];
                        if (!dictionary.ContainsKey(mapping.Action))
                        {
                            dictionary.Add(mapping.Action, new List <PerformanceCounterStatement>());
                        }
                        List <PerformanceCounterStatement> list = dictionary[mapping.Action];
                        PerformanceCounterStatement        item = new PerformanceCounterStatement(this.CreateCounters(data.Name), mapping.Operation);
                        list.Add(item);
                    }
                }
            }
            this.m_actionStatements = dictionary;
        }
        private void NotifyCounter(PerformanceCounterAction action, PerformanceCounterStatement statement, WorkflowExecutor executor)
        {
            foreach (PerformanceCounter counter in statement.Counters)
            {
                switch (statement.Operation)
                {
                    case PerformanceCounterOperation.Increment:
                        counter.Increment();
                        break;

                    case PerformanceCounterOperation.Decrement:
                        counter.Decrement();
                        break;

                    default:
                        System.Diagnostics.Debug.Assert(false, "Unknown performance counter operation.");
                        break;
                }
            }
        }
        internal void SetInstanceName(String instanceName)
        {
            PerformanceCounterData[] data = s_DefaultPerformanceCounters;

            if (String.IsNullOrEmpty(instanceName))
            {
                try
                {
                    // The assert is safe here as we never give out the instance name.
                    new System.Security.Permissions.SecurityPermission(System.Security.Permissions.PermissionState.Unrestricted).Assert();
                    Process process = Process.GetCurrentProcess();
                    ProcessModule mainModule = process.MainModule;
                    instanceName = mainModule.ModuleName;
                }
                finally
                {
                    System.Security.CodeAccessPermission.RevertAssert();
                }
            }

            this.m_instanceName = instanceName;

            // Build a mapping of PerformanceCounterActions to the actual actions that need
            // to be performed.  If this become a perf issue, we could build the default mapping
            // at build time.

            Dictionary<PerformanceCounterAction, List<PerformanceCounterStatement>> actionStatements = new Dictionary<PerformanceCounterAction, List<PerformanceCounterStatement>>();

            if (PerformanceCounterCategory.Exists(c_PerformanceCounterCategoryName))
            {
                for (int i = 0; i < data.Length; ++i)
                {
                    PerformanceCounterData currentData = data[i];
                    for (int j = 0; j < currentData.Mappings.Length; ++j)
                    {
                        PerformanceCounterActionMapping currentMapping = currentData.Mappings[j];
                        if (!actionStatements.ContainsKey(currentMapping.Action))
                        {
                            actionStatements.Add(currentMapping.Action, new List<PerformanceCounterStatement>());
                        }
                        List<PerformanceCounterStatement> lStatements = actionStatements[currentMapping.Action];
                        PerformanceCounterStatement newStatement = new PerformanceCounterStatement(CreateCounters(currentData.Name), currentMapping.Operation);
                        lStatements.Add(newStatement);
                    }
                }
            }

            this.m_actionStatements = actionStatements;
        }
        private void NotifyCounter(PerformanceCounterAction action, PerformanceCounterStatement statement, WorkflowExecutor executor)
        {
            foreach (PerformanceCounter counter in statement.Counters)
            {
                switch (statement.Operation)
                {
                    case PerformanceCounterOperation.Increment:
                        counter.Increment();
                        break;

                    case PerformanceCounterOperation.Decrement:
                        counter.Decrement();
                        break;
                }
            }
        }
 internal void SetInstanceName(string instanceName)
 {
     PerformanceCounterData[] dataArray = s_DefaultPerformanceCounters;
     if (string.IsNullOrEmpty(instanceName))
     {
         try
         {
             new SecurityPermission(PermissionState.Unrestricted).Assert();
             instanceName = Process.GetCurrentProcess().MainModule.ModuleName;
         }
         finally
         {
             CodeAccessPermission.RevertAssert();
         }
     }
     this.m_instanceName = instanceName;
     Dictionary<PerformanceCounterAction, List<PerformanceCounterStatement>> dictionary = new Dictionary<PerformanceCounterAction, List<PerformanceCounterStatement>>();
     if (PerformanceCounterCategory.Exists(c_PerformanceCounterCategoryName))
     {
         for (int i = 0; i < dataArray.Length; i++)
         {
             PerformanceCounterData data = dataArray[i];
             for (int j = 0; j < data.Mappings.Length; j++)
             {
                 PerformanceCounterActionMapping mapping = data.Mappings[j];
                 if (!dictionary.ContainsKey(mapping.Action))
                 {
                     dictionary.Add(mapping.Action, new List<PerformanceCounterStatement>());
                 }
                 List<PerformanceCounterStatement> list = dictionary[mapping.Action];
                 PerformanceCounterStatement item = new PerformanceCounterStatement(this.CreateCounters(data.Name), mapping.Operation);
                 list.Add(item);
             }
         }
     }
     this.m_actionStatements = dictionary;
 }