Пример #1
0
        public void SetValue()
        {
            var          value = new Uri("http://www.baidu.com");
            Result <Uri> r     = new Result <Uri>();

            r.SetValue(value);
            AssertSuccess(r, value.ToString());
            Assert.Throws <InvalidCastException>(() => r.SetValue(""));
        }
 public void Should_call_graphite_using_TCP()
 {
     var result = new Result("name", new DateTime(2012, 11, 10, 9, 8, 7), "path");
     result.SetValue(1);
     var graphiteClient = new GraphiteTcpClient("metrics.london.ttldev.local", 2003);
     graphiteClient.Send(result);
 }
 public void Should_return_a_graphite_message_list()
 {
     var list = new List<IResult>();
     var res = new Result("name", new DateTime(2012, 12, 11, 10, 9, 8), "path");
     res.SetValue(123);
     list.Add(res);
     var graphiteMetrics = new GraphiteMetrics(list);
     var msgList = graphiteMetrics.ToGraphiteMessageList();
     string msg = "path.name 123 1355220548\n";
     Assert.That(msgList, Is.EqualTo(msg));
 }
Пример #4
0
 public void Should_send_list_to_graphite_udp()
 {
     var graphiteUdp = new Graphite.GraphiteUdpClient("metrics.london.ttldev.local");
     var res = new List<IResult>();
     var p1 = new Result("name", DateTime.Now, "test.path1");
     p1.SetValue(20);
     var p2 = new Result("name", DateTime.Now, "test.path2");
     p2.SetValue(20);
     var p3 = new Result("name", DateTime.Now, "test.path3");
     p3.SetValue(30);
     res.Add(p1);
     //res.Add(p2);
     //res.Add(p3);
     graphiteUdp.Send(new GraphiteMetrics(res));
 }
Пример #5
0
        public override IList<IResult> Get()
        {
            var rtn = new List<IResult>();

            try
            {
                foreach (var o in this.GetWmiObject(this.Sql, this.machineName, RootPath))
                {
                    var value = -1;
                    var dateTime = DateTime.Now;
                    var name = string.Empty;

                    foreach (var col in o.Properties)
                    {
                        if (col.Type == CimType.String)
                        {
                            name = Convert.ToString(col.Value);
                        }

                        if (col.Type == CimType.UInt32)
                        {
                            value = Convert.ToInt32(col.Value);
                        }

                        if (col.Type == CimType.UInt64)
                        {
                            value = Convert.ToInt32(col.Value);
                        }

                        if (col.Type == CimType.DateTime)
                        {
                            dateTime = Convert.ToDateTime(col.Value);
                        }
                    }

                    this.Log.Debug(string.Format("Name {0} value {1} datetime {2}", name, value, dateTime));
                    var r = new Result(name, dateTime, this.Path);
                    r.SetValue(value);
                    rtn.Add(r);
                }
            }
            catch (ManagementException e)
            {
                this.Log.Error(string.Format("Error with {0} {1} {2}", this.Type, this.Path, this.Sql));
                this.Log.Error(e.Message);
                this.Log.Error(e.StackTrace);
            }

            return rtn;
        }
        private Result Map(IDataRecord record)
        {
            var value = -1;
            var dateTime = DateTime.Now;
            var name = string.Empty;
            for (int i = 0; i < record.FieldCount; i++)
            {
                if (record[i] is string)
                {
                    name = Convert.ToString(record.GetValue(i));
                }

                if (record[i] is int)
                {
                    value = record.GetInt32(i);
                }

                if (record[i] is DateTime)
                {
                    dateTime = record.GetDateTime(i);
                }
            }

            this.Log.Debug(string.Format("Got [{1}] {0}", value, dateTime));
            var r = new Result(name, dateTime, this.Path);
            r.SetValue(value);
            return r;
        }
Пример #7
0
		/// <summary>
		/// Used by the safe synchronization delegate.
		/// </summary>
		/// <param name="invocation">The invocation.</param>
		/// <param name="result">The result holder.</param>
		private static void InvokeSafely(IInvocation invocation, Result result)
		{
			if (result == null)
			{
				invocation.Proceed();
			}
			else
			{
				try
				{
					invocation.Proceed();
					result.SetValue(false, invocation.ReturnValue);
				}
				catch (Exception exception)
				{
					result.SetException(false, exception);
				}
			}
		}
Пример #8
0
		/// <summary>
		/// Continues the invocation synchronously.
		/// </summary>
		/// <param name="invocation">The invocation.</param>
		/// <param name="result">The result holder.</param>
		private static void InvokeSynchronously(IInvocation invocation, Result result)
		{
			invocation.Proceed();

			result = result ?? CreateResult(invocation);
			if (result != null)
			{
				result.SetValue(true, invocation.ReturnValue);
			}
		}
 private Result TotalFailed(CcTray tray, DateTime now)
 {
     var totalFailed = new Result("TotalFailed", now, this.Path);
     totalFailed.SetValue(tray.FailedPipelines().Count);
     return totalFailed;
 }
Пример #10
0
        public void SetValue()
        {
            Result r = new Result();

            r.SetValue(null);
        }
        private Result Map(DataRow record)
        {
            var value = -1;
            var dateTime = DateTime.Now;
            var name = string.Empty;
            for (int i = 0; i < record.ItemArray.Length; i++)
            {
                if (record[i] is string)
                {
                    name = Convert.ToString(record[i]);
                }

                if (record[i] is int || record[i] is decimal)
                {
                    value = Convert.ToInt32(record[i]);
                }

                if (record[i] is DateTime)
                {
                    dateTime = Convert.ToDateTime(record[i]);
                }
            }

            this.Log.Debug(string.Format("Got [{1}] {0}", value, dateTime));
            var res = new Result(name, dateTime, this.Path);
            res.SetValue(value);
            return res;
        }
        private Result Map(ILogRecord record)
        {
            var value = -1;
            var dateTime = DateTime.Now;
            var name = string.Empty;

            var r = record.getValue(0);
            if ((r is string))
            {
                name = Convert.ToString(r);
            }

            if ((r is int) || (r is decimal))
            {
                value = Convert.ToInt32(r);
            }

            r = record.getValue(1);
            if ((r is string))
            {
                name = Convert.ToString(r);
            }

            if ((r is int) || (r is decimal))
            {
                value = Convert.ToInt32(r);
            }

            //Console.WriteLine(record.getValue(0).GetType());
            //Console.WriteLine(record.getValue(1).GetType());
            try
            {
                //Console.WriteLine(record.getValue(2));
            }
            catch (Exception ex)
            {

                var s = ex.Message;
            }

            //Console.WriteLine(string.Format("{0} {1}", record.getValue(0), record.getValue(1)));

            //for (int i = 0; i < record.; i++)
            //{
            //    if (record[i] is string)
            //    {
            //        name = Convert.ToString(record[i]);
            //    }

            //    if (record[i] is int || record[i] is decimal)
            //    {
            //        value = Convert.ToInt32(record[i]);
            //    }

            //    if (record[i] is DateTime)
            //    {
            //        dateTime = Convert.ToDateTime(record[i]);
            //    }
            //}

            if (this.Name != string.Empty && name == string.Empty)
            {
                name = this.Name;
            }

            this.Log.Debug(string.Format("Got [{1}] {0}", value, dateTime));
            var result = new Result(name, dateTime, this.Path);
            result.SetValue(value);
            return result;
        }