Exemple #1
0
        /// <summary>
        /// Gets the saved external database connection parameters from the project XML file.
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static List <ExternalDBModel> GetDatabaseModel(string filePath)
        {
            List <ExternalDBModel> models = new List <ExternalDBModel>();

            using (XmlReader _Reader = XmlReader.Create(new FileStream(filePath, FileMode.Open), new XmlReaderSettings()
            {
                CloseInput = true
            }))
            {
                while (_Reader.Read()) //while reader can read
                {
                    ExternalDBModel model = new ExternalDBModel();
                    if ((_Reader.NodeType == XmlNodeType.Element) && (_Reader.Name == "Data")) //looks for xml parent node type of "project" (will look like <Data />
                    {
                        if (_Reader.HasAttributes)                                             //if current line has attributes
                        {
                            //read each attribute in the line if it matches the definition

                            model.Type     = _Reader.GetAttribute("Type");
                            model.Server   = _Reader.GetAttribute("Server");
                            model.Database = _Reader.GetAttribute("Database");
                            model.UserID   = _Reader.GetAttribute("UserID");
                            model.PassWord = _Reader.GetAttribute("Password");
                            models.Add(model);
                        }
                    }
                }//end of while
            }
            return(models);
        }
Exemple #2
0
        /// <summary>
        /// Gets the saved external database connection parameters from the project XML file.
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static ExternalDBModel GetExternalProjectDBSettings(string workingFolder, string projectXMLFile)
        {
            var fqFilePath = Path.Combine(workingFolder, projectXMLFile);

            if (File.Exists(fqFilePath))
            {
                using (XmlReader _Reader = XmlReader.Create(new FileStream(fqFilePath, FileMode.Open), new XmlReaderSettings()
                {
                    CloseInput = true
                }))
                {
                    ExternalDBModel model = new ExternalDBModel();
                    while (_Reader.Read())                                                                     //while reader can read
                    {
                        if ((_Reader.NodeType == XmlNodeType.Element) && (_Reader.Name == "ExternalDatabase")) //looks for xml parent node type of "project" (will look like <Data />
                        {
                            if (_Reader.HasAttributes)                                                         //if current line has attributes
                            {
                                //read each attribute in the line if it matches the definition

                                model.Type     = _Reader.GetAttribute("Type");
                                model.Server   = _Reader.GetAttribute("Server");
                                model.Database = _Reader.GetAttribute("Database");
                                model.UserID   = _Reader.GetAttribute("UserID");
                                model.PassWord = _Reader.GetAttribute("Password");
                            }
                        }
                    }//end of while
                    return(model);
                }
            }
            else
            {
                throw new FileNotFoundException("Settings file to read does not exist where you said it would be!");
            }
        }