Beispiel #1
0
        static public ParamValueCollection GetObjectProperties(object obj, string prefix = "")
        {
            var result = new ParamValueCollection(prefix);

            if (obj == null)
            {
                return(result);
            }

            var properties = obj.GetType().GetProperties();

            foreach (var p in properties)
            {
                string name  = p.Name;
                var    value = p.GetValue(obj, null);

                if (value == null)
                {
                    continue;
                }

                result.Add(GetParamValues(name, value));
            }

            return(result);
        }
Beispiel #2
0
        protected virtual void ParseConnectionStringParams(ParamValueCollection parametres)
        {
            if (parametres == null)
            {
                return;
            }

            this.Server = parametres.GetValue("Server") ?? "";

            if (parametres.Contains("SSL"))
            {
                var value = parametres.GetText("SSL");
                this.SSL = !String.IsNullOrWhiteSpace(value) && value.Equals("true", CommonService.StringComparison);
            }

            if (parametres.Contains("Port"))
            {
                var value = parametres.GetText("Port");
                this.Port = String.IsNullOrWhiteSpace(value) ? this.DefaultPort : Convert.ToInt32(value);
            }

            this.Login = parametres.GetValue("Login") ?? "";

            this.Password = parametres.GetValue("Password") ?? "";
        }
Beispiel #3
0
        public ParamValueCollection GetParamValues(string prefix = "")
        {
            var collection = new ParamValueCollection(prefix);

            collection.Add("First", this.First);
            collection.Add("Last", this.Last);
            collection.Add("Second", this.Second);

            return(collection);
        }
Beispiel #4
0
        public Message FillTemplate(ParamValueCollection collection)
        {
            return(new Message()
            {
                Subject = collection?.Replace(this.Subject) ?? this.Subject,
                Text = collection?.Replace(this.Text) ?? this.Text,

                Sender = this.Sender,
                Recipients = new Recipients(this.Recipients),

                Attachments = new List <FileData>(this.Attachments),
                Resources = new List <FileData>(this.Resources)
            });
        }
Beispiel #5
0
        public static ParamValueCollection Split(string text, params char[] separators)
        {
            var result = new ParamValueCollection();

            if (String.IsNullOrWhiteSpace(text))
            {
                return(result);
            }

            var items = text.SplitFormatted(separators);

            foreach (var item in items)
            {
                if (String.IsNullOrWhiteSpace(item))
                {
                    continue;
                }

                var split = item.Split('=');
                if (split == null || split.Length != 2)
                {
                    throw new CustomFormatException("Param's Name and Value should be separated by '='");
                }

                var name = split[0].Trim();
                if (name.Length > 2 && name[0] == name[name.Length - 1] && separators.Contains(name[0]))
                {
                    name = name.Substring(1, name.Length - 2);
                }

                var value = split[1].Trim();
                if (value.Length > 2 && value[0] == value[value.Length - 1] && separators.Contains(value[0]))
                {
                    value = value.Substring(1, value.Length - 2);
                }

                result.Add(name, value);
            }

            return(result);
        }
Beispiel #6
0
        static public ParamValueCollection GetParamValues(string name, object value)
        {
            var result = new ParamValueCollection();

            if (value == null)
            {
                return(result);
            }

            var type = value.GetType();

            if (type == typeof(string))
            {
                result.Add(name, value.ToString());
            }
            else if (type == typeof(DateTime))
            {
                result.Add(name, ((DateTime)value));
            }
            else if (type == typeof(DateTimeOffset))
            {
                result.Add(name, ((DateTimeOffset)value).DateTime);
            }
            else if (type.IsClass)
            {
                if (!typeof(IEnumerable).IsAssignableFrom(type) && !type.IsArray)
                {
                    result.Add(GetObjectProperties(value, name));
                }
            }
            else
            {
                result.Add(name, value.ToString());
            }

            return(result);
        }
Beispiel #7
0
 public static ParamValueCollection Split(string input)
 {
     return(ParamValueCollection.Split(input, ';'));
 }
Beispiel #8
0
        public ServerConfig(string connectionString)
        {
            var connectionParams = ParamValueCollection.Split(connectionString, ';');

            this.ParseConnectionStringParams(connectionParams);
        }