Ejemplo n.º 1
0
        protected SqlDbConfig(XmlReader xmlReader, XPathNavigator nav)
        {
            string         docPath = ".";
            XPathNavigator node    = nav.SelectSingleNode(docPath);

            myID = node.SelectSingleNode("@id").Value;

            this.nav       = nav;
            this.xmlReader = xmlReader;
            XmlSerializer serializer = new XmlSerializer(typeof(Database));

            mDatabase = (Database)serializer.Deserialize(xmlReader);
            mDatabase.postSerialize();



            foreach (LanguageType lang in mDatabase.Languages)
            {
                this.MetaSuffixByLanguage.Add(lang.code, lang.metaSuffix);
            }
            //had to use v2_1 not 2.1 in xsd, the xsd.exe dont like "."
            this.mMetaModel    = mDatabase.metaModel.ToString();
            this.mMainLanguage = mDatabase.MainLanguage;


            this.mUseTemporaryTables = mDatabase.Connection.useTemporaryTables;
            this.setMetatablesSchema();

            //

            this.defaultConnectionString = mDatabase.Connection.ConnectionString;

            if (mDatabase.Connection.ConnectionString.IndexOf("=USER;") == -1)
            {
                this.keyForPassword = mDatabase.Connection.KeyForPassword;
                this.keyForUserName = mDatabase.Connection.KeyForUser;
            }
            else
            {
                bool     passwFound = false;
                string[] keyValues  = mDatabase.Connection.ConnectionString.Split(';');

                foreach (string keyValue in keyValues)
                {
                    if (keyValue.IndexOf("=USER") > 0)
                    {
                        this.keyForUserName = keyValue.Replace("=USER", "").Trim();
                    }
                    else if (keyValue.IndexOf("=PASSWORD") > 0)
                    {
                        this.keyForPassword = keyValue.Replace("=PASSWORD", "").Trim();
                        passwFound          = true;
                    }
                }
                if (!passwFound)
                {
                    throw new ConfigException(40, mDatabase.Connection.ConnectionString);
                }
                if (String.IsNullOrEmpty(mDatabase.Connection.DefaultUser))
                {
                    throw new ConfigException("When user/password is not given in ConnectionString it must be given in DefaultUser and DefaultPassword");
                }
                this.defaultConnectionString = this.GetConnectionString(mDatabase.Connection.DefaultUser, mDatabase.Connection.DefaultPassword);
            }



            if (MetaModel.Equals("2.1") || MetaModel.Equals("2.0"))
            {
                allowConfigDefaults = false;
            }
            else
            {
                allowConfigDefaults = mDatabase.allowConfigDefaults;
            }
        }