public void Int64Test()
        {
            string key        = "key";
            var    properties = new ExtentionPropertyCollection();

            // проверим GetInt64OrNull когда нет значения
            long?value = properties.GetInt64OrNull(key);

            Assert.Null(value);

            // проверим GetInt64 когда нет значения
            Assert.Throws <KeyNotFoundException>(() => properties.GetInt64(key));

            // проверим GetInt64OrNull когда значение есть
            properties.Set(key, long.MaxValue);
            value = properties.GetInt64OrNull(key);
            Assert.True(value.HasValue);
            Assert.True(value == long.MaxValue);

            // проверим GetInt64 когда значение есть
            value = null;
            value = properties.GetInt64(key);
            Assert.True(value.HasValue);
            Assert.True(value == long.MaxValue);
        }
        public void DateTimeTest()
        {
            string key        = "key";
            var    properties = new ExtentionPropertyCollection();

            // проверим GetDateTimeOrNull когда нет значения
            DateTime?value = properties.GetDateTimeOrNull(key);

            Assert.Null(value);

            // проверим GetDateTime когда нет значения
            Assert.Throws <KeyNotFoundException>(() => properties.GetDateTime(key));

            // проверим GetDateTimeOrNull когда значение есть
            DateTime now = DateTime.Now;

            now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); // потому что милесекунды отбрасываются !
            properties.Set(key, now);
            value = properties.GetDateTimeOrNull(key);
            Assert.True(value.HasValue);
            Assert.True(value == now);

            // проверим GetDateTime когда значение есть
            value = null;
            value = properties.GetDateTime(key);
            Assert.True(value.HasValue);
            Assert.True(value == now);
        }
Esempio n. 3
0
 public static void CheckExtentionProperties(ExtentionPropertyCollection properties1, ExtentionPropertyCollection properties2)
 {
     Assert.Equal(properties1.Count, properties2.Count);
     foreach (var property in properties1)
     {
         var property2 = properties2[property.Name];
         var value1    = property.Value.Value;
         var value2    = property2.Value;
         if (value1 == null)
         {
             Assert.Null(value2);
         }
         else
         {
             if (property.Value.DataType == Api.DataType.DateTime)
             {
                 var date1 = (DateTime)value1;
                 var date2 = (DateTime)value2;
                 Assert.Equal(GetRoundDateTime(date1), GetRoundDateTime(date2));
             }
             else
             {
                 Assert.Equal(property.Value.Value, property2.Value);
             }
         }
         Assert.Equal(property.Value.DataType, property2.DataType);
     }
 }
        public void BooleanTest()
        {
            string key        = "key";
            var    properties = new ExtentionPropertyCollection();

            // проверим GetBooleanOrNull когда нет значения
            bool?value = properties.GetBooleanOrNull(key);

            Assert.Null(value);

            // проверим GetBoolean когда нет значения
            Assert.Throws <KeyNotFoundException>(() => properties.GetBoolean(key));

            // проверим GetBooleanOrNull когда значение есть
            properties.Set(key, true);
            value = properties.GetBooleanOrNull(key);
            Assert.True(value.HasValue);
            Assert.True(value == true);

            // проверим GetBoolean когда значение есть
            value = null;
            value = properties.GetBoolean(key);
            Assert.True(value.HasValue);
            Assert.True(value == true);
        }
        protected void TrimProperties(ExtentionPropertyCollection properties, int maxSize)
        {
            if (properties == null)
            {
                return;
            }
            var allProperties = properties.ToList();

            foreach (var property in allProperties)
            {
                TrimProperty(properties, property);
            }
            int size = properties.GetWebSize();

            while (size > maxSize)
            {
                if (properties.Count == 0)
                {
                    break;
                }

                //удаляем одно самое тяжелое свойство
                var heavyProperty = properties
                                    .ToList()
                                    .OrderByDescending(x => x.GetWebSize())
                                    .First();

                properties.Remove(heavyProperty);
                size = properties.GetWebSize();
            }
        }
        public void DoubleTest()
        {
            string key        = "key";
            var    properties = new ExtentionPropertyCollection();

            // проверим GetDoubleOrNull когда нет значения
            double?value = properties.GetDoubleOrNull(key);

            Assert.Null(value);

            // проверим GetDouble когда нет значения
            Assert.Throws <KeyNotFoundException>(() => properties.GetDouble(key));

            // проверим GetDoubleOrNull когда значение есть
            double setValue = 1121212.2323;

            properties.Set(key, setValue);
            value = properties.GetDoubleOrNull(key);
            Assert.True(value.HasValue);
            Assert.True(value == setValue);

            // проверим GetDouble когда значение есть
            value = null;
            value = properties.GetDouble(key);
            Assert.True(value.HasValue);
            Assert.True(value == setValue);
        }
Esempio n. 7
0
        public static void CheckExtentionProperties(
            Dictionary <string, object> properties1,
            ExtentionPropertyCollection properties2)
        {
            var prop = new ExtentionPropertyCollection(properties1);

            CheckExtentionProperties(prop, properties2);
        }
Esempio n. 8
0
        public static void InitRandomProperties(List <Api.Dto.ExtentionPropertyDto> propertyDtos)
        {
            var properties = new ExtentionPropertyCollection();

            InitRandomProperties(properties);
            var propertiesDto2 = DataConverter.GetExtentionPropertyDtos(properties);

            propertyDtos.AddRange(propertiesDto2);
        }
        public void SetNullTest()
        {
            var    properties = new ExtentionPropertyCollection();
            string value      = null;

            properties.Set("key", value);
            string value2 = properties["key"];

            Assert.Null(value2);
        }
Esempio n. 10
0
 public static List <ExtentionPropertyDto> GetExtentionPropertyDtos(ExtentionPropertyCollection collection)
 {
     if (collection == null)
     {
         return(null);
     }
     return(collection.Select(x => new ExtentionPropertyDto()
     {
         Name = x.Name,
         Value = GetXmlValue(x.Value),
         Type = x.Value.DataType.ToString()
     }).ToList());
 }
Esempio n. 11
0
 private void CheckExtProperties(Dictionary <string, object> from, ExtentionPropertyCollection to)
 {
     foreach (var pair in from)
     {
         var key   = pair.Key;
         var value = pair.Value;
         if (to.HasKey(key) == false)
         {
             throw new Exception("Не удалось найти ключ " + key);
         }
         var value2 = to[key].Value;
         Assert.Equal(value, value2);
     }
 }
Esempio n. 12
0
        protected void TrimProperty(ExtentionPropertyCollection properties, ExtentionProperty property)
        {
            string name = GetGoodString(property.Name, PropertyNameMaxLength);

            if (name == null)
            {
                properties.Remove(property);
                return;
            }
            if (name != property.Name)
            {
                properties.Rename(property, name);
            }
        }
        public void ComplextTest()
        {
            string key        = "key";
            var    properties = new ExtentionPropertyCollection();

            Assert.Equal(0, properties.Count);

            // проверим методы GetXxxOrNull когда значения нет
            Assert.Null(properties.GetBooleanOrNull(key));
            Assert.Null(properties.GetInt32OrNull(key));
            Assert.Null(properties.GetInt64OrNull(key));
            Assert.Null(properties.GetDoubleOrNull(key));
            Assert.Null(properties.GetDateTimeOrNull(key));
            Assert.Null(properties.GetStringOrNull(key));

            // проверим методы Get когда значения есть
            properties.Set(key, true);
            Assert.True(properties.GetBooleanOrNull(key) == true);
            Assert.True(properties.GetBoolean(key) == true);

            properties.Set(key, int.MaxValue);
            Assert.True(properties.GetInt32OrNull(key) == int.MaxValue);
            Assert.True(properties.GetInt32(key) == int.MaxValue);

            properties.Set(key, long.MaxValue);
            Assert.True(properties.GetInt64OrNull(key) == long.MaxValue);
            Assert.True(properties.GetInt64(key) == long.MaxValue);

            properties.Set(key, 1000.05);
            Assert.True(properties.GetDoubleOrNull(key) == 1000.05);
            Assert.True(properties.GetDouble(key) == 1000.05);

            var now = DateTime.Now;

            now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
            properties.Set(key, now);
            Assert.True(properties.GetDateTimeOrNull(key) == now);
            Assert.True(properties.GetDateTime(key) == now);

            properties.Set(key, "value");
            Assert.True(properties.GetStringOrNull(key) == "value");
            Assert.True(properties.GetString(key) == "value");

            Assert.Equal(1, properties.Count);
        }
Esempio n. 14
0
        public static void SetProperties(ExtentionPropertyCollection properties)
        {
            var httpContext = HttpContext.Current;

            if (httpContext == null)
            {
                return;
            }

            // Если событие не связано с запросом, то выход
            HttpRequest request;

            try
            {
                request = httpContext.Request;
            }
            catch
            {
                return;
            }

            var ip = GetClientIp(httpContext);

            properties.Set("IP", ip);
            properties.Set("UserAgent", request.UserAgent);
            properties.Set("Url", request.Url.AbsoluteUri);

            // UrlReferrer
            if (request.UrlReferrer != null)
            {
                properties.Set("UrlReferrer", request.UrlReferrer.AbsoluteUri);
            }

            // Body
            var body = GetBody(httpContext);

            if (!string.IsNullOrEmpty(body))
            {
                properties.Set("Body", body);
            }
        }
Esempio n. 15
0
        public static ExtentionPropertyCollection GetExtentionPropertyCollection(List <ExtentionPropertyDto> propertyDtos)
        {
            if (propertyDtos == null)
            {
                return(new ExtentionPropertyCollection());
            }
            var collection = new ExtentionPropertyCollection();

            foreach (var propertyDto in propertyDtos)
            {
                if (propertyDto != null && propertyDto.Name != null)
                {
                    var property = GetExtentionPropertyFromDto(propertyDto);
                    if (property != null)
                    {
                        collection.Add(property);
                    }
                }
            }
            return(collection);
        }
Esempio n. 16
0
        public static string GetLogMessage(
            string template,
            string componentName,
            DateTime date,
            LogLevel?level,
            string tag,
            string message,
            ExtentionPropertyCollection properties)
        {
            var values = new Dictionary <string, Func <string> >()
            {
                { "#tag", () => tag },
                { "#componentName", () => componentName },
                { "#datetime", () => date.ToString("dd.MM.yyyy HH:mm:ss") },
                { "#level", () => (level == null) ? "       " : level.ToString().PadRight(7, ' ') },
                { "#message", () => message },
                { "#properties", () => GetPropertiesText(properties) }
            };

            return(GetResultInternal(template, values));
        }
        public void StringTest()
        {
            string key        = "key";
            var    properties = new ExtentionPropertyCollection();

            // проверим GetStringOrNull когда нет значения
            string value = properties.GetStringOrNull(key);

            Assert.Null(value);

            // проверим GetString когда нет значения
            Assert.Throws <KeyNotFoundException>(() => properties.GetString(key));

            // проверим GetStringOrNull когда значение есть
            properties.Set(key, "value");
            value = properties.GetStringOrNull(key);
            Assert.True(value == "value");

            // проверим GetString когда значение есть
            value = null;
            value = properties.GetString(key);
            Assert.True(value == "value");
        }
Esempio n. 18
0
        private static string GetPropertiesText(ExtentionPropertyCollection properties)
        {
            if (properties == null || properties.Count == 0)
            {
                return("");
            }
            string result = "";

            foreach (var property in properties)
            {
                var bytes = property.Value.Value as byte[];
                if (bytes != null)
                {
                    result += property.Name + "=" + bytes.Length + "bytes; ";
                }
                else
                {
                    result += property.Name + "=" + property.Value + "; ";
                }
            }
            result = result.TrimEnd(';', ' ');
            result = "[" + result + "]";
            return(result);
        }
Esempio n. 19
0
        public static void InitRandomProperties(ExtentionPropertyCollection properties)
        {
            properties.Set("bool", RandomHelper.GetRandomBool());
            properties.Set("int32", RandomHelper.GetRandomInt32(int.MinValue, int.MaxValue));
            properties.Set("int64", RandomHelper.GetRandomInt64(long.MinValue, long.MaxValue));
            var d = RandomHelper.GetRandomInt32(-1000000, 1000000) + 0.54237;

            properties.Set("double", d);
            properties.Set("datetime", DateTime.Now);
            properties.Set("string", "random string " + PasswordHelper.GetRandomPassword(300));
            properties.Set("binary", RandomHelper.GetRandomBytes(300));
            properties.Set("guid", Guid.NewGuid());

            // продублируем
            properties.Set("bool_2", RandomHelper.GetRandomBool());
            properties.Set("int32_2", RandomHelper.GetRandomInt32(int.MinValue, int.MaxValue));
            properties.Set("int64_2", RandomHelper.GetRandomInt64(long.MinValue, long.MaxValue));
            d = RandomHelper.GetRandomInt32(-1000000, 1000000) + 0.54237;
            properties.Set("double_2", d);
            properties.Set("datetime_2", DateTime.Now.AddMinutes(-5));
            properties.Set("string_2", "random string " + PasswordHelper.GetRandomPassword(300));
            properties.Set("binary_2", RandomHelper.GetRandomBytes(300));
            properties.Set("guid_2", Guid.NewGuid());
        }
Esempio n. 20
0
 protected void TrimProperties(ExtentionPropertyCollection properties)
 {
     TrimProperties(properties, AllPropertiesMaxLength);
 }