示例#1
0
        /// <summary>
        /// Returns boolean provider attribute value by name.
        /// </summary>
        /// <param name="name">Name of attribute.</param>
        public bool GetBoolAttributeState(string name)
        {
            MochaProviderAttribute attribute = GetAttribute(name);

            if (attribute != null && attribute.value.Equals("True", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }
            return(false);
        }
示例#2
0
        /// <summary>
        /// Return connection string by attributes.
        /// </summary>
        /// <param name="attributes">Attribtutes of connection string.</param>
        public static string GetConnectionString(IEnumerable <MochaProviderAttribute> attributes)
        {
            string cstring = string.Empty;

            for (int index = 0; index < attributes.Count(); index++)
            {
                MochaProviderAttribute attribtue = attributes.ElementAt(index);
                cstring += attribtue.GetProviderString();
            }
            return(cstring);
        }
示例#3
0
        /// <summary>
        /// Return attribute by name.
        /// </summary>
        /// <param name="name">Name of attribute.</param>
        /// <param name="connectionString">Connection string for connect to MochaDb database.</param>
        public static MochaProviderAttribute GetAttribute(string name, string connectionString)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new MochaException("Attribute name is can not empty or white space!");
            }

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new MochaException("Connection string is can not empty or white space!");
            }

            Regex rgx = new Regex(name + ".?=.?", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);

            IEnumerable <string> result =
                from rvalue in
                from value in connectionString.Split(';')
                select value.TrimStart().TrimEnd()
                    where rgx.IsMatch(rvalue)
                select rvalue;

            int count = result.Count();

            if (count == 0)
            {
                return(null);
            }

            if (count > 1)
            {
                throw new MochaException("An attribute can only be specified once!");
            }

            string sresult                   = result.ElementAt(0);
            string attributeValue            = sresult.Substring(sresult.IndexOf('=') + 1);
            MochaProviderAttribute attribute = new MochaProviderAttribute();

            attribute.name  = name.TrimStart().TrimEnd();
            attribute.Value = attributeValue == null ? string.Empty :
                              string.Equals(attribute.Name, "password") ?
                              attributeValue : attributeValue.TrimStart().TrimEnd();
            return(attribute);
        }