Exemplo n.º 1
0
        /// <summary>
        /// Sets the value of the <c>Log</c> property for the specified control.
        /// </summary>
        /// <param name="counter">The control to set the property for.</param>
        /// <param name="value">The value of the property for the specified control.</param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="counter"/> is <see langword="null"/>.</para>
        /// </exception>
        public void SetLog(INuGenCounter counter, Boolean value)
        {
            if (counter == null)
            {
                throw new ArgumentNullException("counter");
            }

            if (!_logTargets.ContainsKey(counter))
            {
                _logTargets.Add(counter, value);

                if (!base.DesignMode)
                {
                    if (value)
                    {
                        counter.ValueChanged += this.counter_ValueChanged;
                    }
                    else
                    {
                        counter.ValueChanged -= this.counter_ValueChanged;
                    }
                }
            }
            else
            {
                _logTargets[counter] = value;
            }
        }
Exemplo n.º 2
0
 private void SetShouldLog(INuGenCounter counter, bool value)
 {
     if (this.meters.ContainsKey(counter))
     {
         this.meters[counter].ShouldLog = value;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a collection of standard values for the data type this type converter is designed for when provided with a format context.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null.</param>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"/> that holds a standard set of valid values, or null if the data type does not support a standard set of values.
        /// </returns>
        public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            INuGenCounter counter = (context == null) ? null : (context.Instance as INuGenCounter);

            string machineName  = ".";
            string categoryName = string.Empty;

            if (counter != null)
            {
                machineName  = counter.MachineName;
                categoryName = counter.CategoryName;
            }

            try
            {
                PerformanceCounterCategory category = new PerformanceCounterCategory(categoryName, machineName);
                string[] instances = category.GetInstanceNames();
                Array.Sort(instances, Comparer.Default);
                return(new TypeConverter.StandardValuesCollection(instances));
            }
            catch
            {
            }

            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the value indicating whether to log the value changes on the meter.
        /// </summary>
        /// <param name="counter">The control to set the property for.</param>
        /// <param name="value">The value of the property for the specified control.</param>
        public void SetGraphLog(INuGenCounter counter, Boolean value)
        {
            if (_meters.ContainsKey(counter))
            {
                this.SetShouldLog(counter, value);
            }
            else
            {
                GraphLineParams glp = new GraphLineParams(_id, value, this.GetLineColor(counter), this.GetIsBar(counter));
                _PushGraph.SetIsBar(this.GetIndex(counter), this.GetIsBar(counter));
                _PushGraph.Update();

                _meters.Add(counter, glp);
                _id++;
            }

            if (value)
            {
                _PushGraph.AddLine(this.GetIndex(counter), this.GetLineColor(counter));
                counter.Disposed += this.counter_Disposed;
            }
            else
            {
                _PushGraph.RemoveLine(this.GetIndex(counter));
                counter.Disposed -= this.counter_Disposed;
            }
        }
Exemplo n.º 5
0
 private void SetShouldLog(INuGenCounter counter, Boolean value)
 {
     if (_meters.ContainsKey(counter))
     {
         _meters[counter].ShouldLog = value;
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Sets the graph line color used to log the value changes on the meter.
 /// </summary>
 /// <param name="counter">The control to set the property for.</param>
 /// <param name="lineColor">The value of the property for the specified control.</param>
 public void SetLineColor(INuGenCounter counter, Color lineColor)
 {
     if (_meters.ContainsKey(counter))
     {
         _meters[counter].LineColor = lineColor;
         _PushGraph.SetLineColor(this.GetIndex(counter), lineColor);
         _PushGraph.Update();
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Sets the value indicating whether to draw the graph line as a set of bars.
 /// </summary>
 /// <param name="nuGenMeter">The control to set the property for.</param>
 /// <param name="value">The value of the property for the specified control.</param>
 public void SetIsBar(INuGenCounter nuGenMeter, Boolean value)
 {
     if (_meters.ContainsKey(nuGenMeter))
     {
         _meters[nuGenMeter].IsBar = value;
         _PushGraph.SetIsBar(this.GetIndex(nuGenMeter), value);
         _PushGraph.Update();
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Sets the value indicating whether to draw the graph line as a set of bars.
 /// </summary>
 /// <param name="nuGenMeter">The control to set the property for.</param>
 /// <param name="value">The value of the property for the specified control.</param>
 public void SetIsBar(INuGenCounter nuGenMeter, bool value)
 {
     if (this.meters.ContainsKey(nuGenMeter))
     {
         this.meters[nuGenMeter].IsBar = value;
         this.pushGraph.SetIsBar(this.GetIndex(nuGenMeter), value);
         this.pushGraph.Update();
     }
 }
Exemplo n.º 9
0
        private void counter_Disposed(Object sender, EventArgs e)
        {
            if (sender is INuGenCounter)
            {
                INuGenCounter counter = (INuGenCounter)sender;

                _PushGraph.RemoveLine(this.GetIndex(counter));
                _meters.Remove(counter);
            }
        }
Exemplo n.º 10
0
 private Int32 GetIndex(INuGenCounter counter)
 {
     if (_meters.ContainsKey(counter))
     {
         return(_meters[counter].Index);
     }
     else
     {
         return(-1);
     }
 }
Exemplo n.º 11
0
 private Boolean GetShouldLog(INuGenCounter counter)
 {
     if (_meters.ContainsKey(counter))
     {
         return(_meters[counter].ShouldLog);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 12
0
 public Boolean GetIsBar(INuGenCounter counter)
 {
     if (_meters.ContainsKey(counter))
     {
         return(_meters[counter].IsBar);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 13
0
 private bool GetShouldLog(INuGenCounter counter)
 {
     if (this.meters.ContainsKey(counter))
     {
         return(this.meters[counter].ShouldLog);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 14
0
 public Color GetLineColor(INuGenCounter counter)
 {
     if (_meters.ContainsKey(counter))
     {
         return(_meters[counter].LineColor);
     }
     else
     {
         return(Color.Yellow);
     }
 }
Exemplo n.º 15
0
 private int GetIndex(INuGenCounter counter)
 {
     if (this.meters.ContainsKey(counter))
     {
         return(this.meters[counter].Index);
     }
     else
     {
         return(-1);
     }
 }
Exemplo n.º 16
0
 public bool GetIsBar(INuGenCounter counter)
 {
     if (this.meters.ContainsKey(counter))
     {
         return(this.meters[counter].IsBar);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 17
0
        /// <summary>
        /// Returns a collection of standard values for the data type this type converter is designed for when provided with a format context.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null.</param>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"/> that holds a standard set of valid values, or null if the data type does not support a standard set of values.
        /// </returns>
        public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            INuGenCounter counter = (context == null) ? null : (context.Instance as INuGenCounter);

            string machineName  = ".";
            string categoryName = string.Empty;

            if (counter != null)
            {
                machineName  = counter.MachineName;
                categoryName = counter.CategoryName;
            }

            try
            {
                PerformanceCounterCategory category = new PerformanceCounterCategory(categoryName, machineName);

                string[]             instances = category.GetInstanceNames();
                PerformanceCounter[] counters  = null;

                if (instances.Length == 0)
                {
                    counters = category.GetCounters();
                }
                else
                {
                    counters = category.GetCounters(instances[0]);
                }

                string[] names = new string[counters.Length];

                for (int nameIndex = 0; nameIndex < counters.Length; nameIndex++)
                {
                    names[nameIndex] = counters[nameIndex].CounterName;
                }

                Array.Sort(names, Comparer.Default);

                return(new TypeConverter.StandardValuesCollection(names));
            }
            catch
            {
            }

            return(null);
        }
Exemplo n.º 18
0
        /*
         * Log
         */

        private void Log(StreamWriter sw, NuGenTargetEventArgs e)
        {
            Debug.Assert(sw != null, "sw != null");
            Debug.Assert(e.Target is INuGenCounter, "e.Target is INuGenCounter");
            Debug.Assert(e.TargetData is float, "e.TargetData is float");

            if (e.Target is INuGenCounter && e.TargetData is float)
            {
                INuGenCounter counter      = (INuGenCounter)e.Target;
                float         counterValue = (float)e.TargetData;

                sw.WriteLine("\n------------- {0} -------------", counter.Name);
                sw.WriteLine("DATE: {0}", DateTime.Now.ToShortDateString());
                sw.WriteLine("TIME: {0}.{1}", DateTime.Now.ToLongTimeString(), DateTime.Now.Millisecond.ToString());
                sw.WriteLine("MACHINE: {0}", counter.MachineName);
                sw.WriteLine("CATEGORY: {0}", counter.CategoryName);
                sw.WriteLine("NAME: {0}", counter.CounterName);
                sw.WriteLine("INSTANCE: {0}", counter.InstanceName);
                sw.WriteLine("VALUE: {0}{1}", counterValue, counter.CounterFormat);
            }
        }
Exemplo n.º 19
0
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            INuGenCounter counter = (context == null) ? null : (context.Instance as INuGenCounter);

            String machineName = ".";

            if (context != null)
            {
                machineName = counter.MachineName;
            }

            if (machineName != _previousMachineName)
            {
                _previousMachineName = machineName;

                try
                {
                    PerformanceCounter.CloseSharedResources();
                    PerformanceCounterCategory[] categories = PerformanceCounterCategory.GetCategories(machineName);
                    String[] categoryNames = new String[categories.Length];

                    for (Int32 categoryIndex = 0; categoryIndex < categories.Length; categoryIndex++)
                    {
                        categoryNames[categoryIndex] = categories[categoryIndex].CategoryName;
                    }

                    Array.Sort(categoryNames, Comparer.Default);
                    _previousStandardValues = new TypeConverter.StandardValuesCollection(categoryNames);
                }
                catch
                {
                    _previousStandardValues = null;
                }
            }

            return(_previousStandardValues);
        }
Exemplo n.º 20
0
		public bool GetLog(INuGenCounter counter)
		{
			return this.logTargets.ContainsKey(counter);
		}
Exemplo n.º 21
0
		/// <summary>
		/// Sets the graph line color used to log the value changes on the meter.
		/// </summary>
		/// <param name="counter">The control to set the property for.</param>
		/// <param name="lineColor">The value of the property for the specified control.</param>
		public void SetLineColor(INuGenCounter counter, Color lineColor)
		{
			if (_meters.ContainsKey(counter))
			{
				_meters[counter].LineColor = lineColor;
				_PushGraph.SetLineColor(this.GetIndex(counter), lineColor);
				_PushGraph.Update();
			}
		}
Exemplo n.º 22
0
		private void SetShouldLog(INuGenCounter counter, bool value)
		{
			if (this.meters.ContainsKey(counter))
			{
				this.meters[counter].ShouldLog = value;
			}
		}
Exemplo n.º 23
0
 public Boolean GetLog(INuGenCounter counter)
 {
     return(_logTargets.ContainsKey(counter));
 }
Exemplo n.º 24
0
		private bool GetShouldLog(INuGenCounter counter)
		{
			if (this.meters.ContainsKey(counter))
			{
				return this.meters[counter].ShouldLog;
			}
			else
			{
				return false;
			}
		}
Exemplo n.º 25
0
 public Boolean GetGraphLog(INuGenCounter counter)
 {
     return(this.GetShouldLog(counter));
 }
Exemplo n.º 26
0
		/// <summary>
		/// Sets the value indicating whether to log the value changes on the meter.
		/// </summary>
		/// <param name="counter">The control to set the property for.</param>
		/// <param name="value">The value of the property for the specified control.</param>
		public void SetGraphLog(INuGenCounter counter, Boolean value)
		{
			if (_meters.ContainsKey(counter))
			{
				this.SetShouldLog(counter, value);
			}
			else
			{
				GraphLineParams glp = new GraphLineParams(_id, value, this.GetLineColor(counter), this.GetIsBar(counter));
				_PushGraph.SetIsBar(this.GetIndex(counter), this.GetIsBar(counter));
				_PushGraph.Update();

				_meters.Add(counter, glp);
				_id++;
			}

			if (value)
			{
				_PushGraph.AddLine(this.GetIndex(counter), this.GetLineColor(counter));
				counter.Disposed += this.counter_Disposed;
			}
			else
			{
				_PushGraph.RemoveLine(this.GetIndex(counter));
				counter.Disposed -= this.counter_Disposed;
			}
		}
Exemplo n.º 27
0
 public bool GetLog(INuGenCounter counter)
 {
     return(this.logTargets.ContainsKey(counter));
 }
Exemplo n.º 28
0
 public void RemoveGeneric(INuGenCounter item)
 {
     items.Remove(item);
     log.SetLog(item, false);
 }
Exemplo n.º 29
0
 public void LogGeneric(INuGenCounter item)
 {
     items.Add(item);
     log.SetLog(item, true);
 }
Exemplo n.º 30
0
		/// <summary>
		/// Sets the value indicating whether to draw the graph line as a set of bars.
		/// </summary>
		/// <param name="nuGenMeter">The control to set the property for.</param>
		/// <param name="value">The value of the property for the specified control.</param>
		public void SetIsBar(INuGenCounter nuGenMeter, Boolean value)
		{
			if (_meters.ContainsKey(nuGenMeter))
			{
				_meters[nuGenMeter].IsBar = value;
				_PushGraph.SetIsBar(this.GetIndex(nuGenMeter), value);
				_PushGraph.Update();
			}
		}
Exemplo n.º 31
0
		private Boolean GetShouldLog(INuGenCounter counter)
		{
			if (_meters.ContainsKey(counter))
			{
				return _meters[counter].ShouldLog;
			}
			else
			{
				return false;
			}
		}
Exemplo n.º 32
0
 public void RemoveGeneric(INuGenCounter item)
 {
     items.Remove(item);
     log.SetLog(item, false);
 }
Exemplo n.º 33
0
		public Boolean GetGraphLog(INuGenCounter counter)
		{
			return this.GetShouldLog(counter);
		}
Exemplo n.º 34
0
		private int GetIndex(INuGenCounter counter)
		{
			if (this.meters.ContainsKey(counter))
			{
				return this.meters[counter].Index;
			}
			else
			{
				return -1;
			}
		}
Exemplo n.º 35
0
		public Color GetLineColor(INuGenCounter counter)
		{
			if (_meters.ContainsKey(counter))
			{
				return _meters[counter].LineColor;
			}
			else
			{
				return Color.Yellow;
			}
		}
Exemplo n.º 36
0
		/// <summary>
		/// Sets the value of the <c>Log</c> property for the specified control.
		/// </summary>
		/// <param name="counter">The control to set the property for.</param>
		/// <param name="value">The value of the property for the specified control.</param>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="counter"/> is <see langword="null"/>.</para>
		/// </exception>
		public void SetLog(INuGenCounter counter, bool value)
		{
			if (counter == null)
			{
				throw new ArgumentNullException("counter");
			}

			if (!this.logTargets.ContainsKey(counter)) 
			{
				this.logTargets.Add(counter, value);

				if (!base.DesignMode) 
				{
					if (value) 
					{
						counter.ValueChanged += this.counter_ValueChanged;
					}
					else
					{
						counter.ValueChanged -= this.counter_ValueChanged;
					}
				}
			}
			else
			{
				this.logTargets[counter] = value;
			}
		}
Exemplo n.º 37
0
		public Boolean GetIsBar(INuGenCounter counter)
		{
			if (_meters.ContainsKey(counter))
			{
				return _meters[counter].IsBar;
			}
			else
			{
				return false;
			}
		}
Exemplo n.º 38
0
		public bool GetIsBar(INuGenCounter counter)
		{
			if (this.meters.ContainsKey(counter))
			{
				return this.meters[counter].IsBar;
			}
			else
			{
				return false;
			}
		}
Exemplo n.º 39
0
		private Int32 GetIndex(INuGenCounter counter)
		{
			if (_meters.ContainsKey(counter))
			{
				return _meters[counter].Index;
			}
			else
			{
				return -1;
			}
		}
Exemplo n.º 40
0
		/// <summary>
		/// Sets the value indicating whether to draw the graph line as a set of bars.
		/// </summary>
		/// <param name="nuGenMeter">The control to set the property for.</param>
		/// <param name="value">The value of the property for the specified control.</param>
		public void SetIsBar(INuGenCounter nuGenMeter, bool value)
		{
			if (this.meters.ContainsKey(nuGenMeter))
			{
				this.meters[nuGenMeter].IsBar = value;
				this.pushGraph.SetIsBar(this.GetIndex(nuGenMeter), value);
				this.pushGraph.Update();
			}
		}
Exemplo n.º 41
0
		private void SetShouldLog(INuGenCounter counter, Boolean value)
		{
			if (_meters.ContainsKey(counter))
			{
				_meters[counter].ShouldLog = value;
			}
		}
Exemplo n.º 42
0
 public void LogGeneric(INuGenCounter item)
 {
     items.Add(item);
     log.SetLog(item, true);
 }