Ejemplo n.º 1
0
 private void RemoveDB(DBViewModel db)
 {
     DBs.Remove(db);
     if (DBs.Count > 0)
     {
         ActiveDB = DBs[0];
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds a base item to the project-file manager
 /// </summary>
 /// <param name="theme">The item to add</param>
 /// <returns>true, if successful - false, otherwise</returns>
 public bool AddDB(IDB db)
 {
     if (!DBs.Contains(db))
     {
         DBs.Add(db);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads all databases. UnloadDBs must be called between calls to LoadDBs.
        /// </summary>
        public static void LoadDBs()
        {
            if (!Directory.Exists(FileSystem.DbPath))
            {
                Directory.CreateDirectory(FileSystem.DbPath);
            }

            var alldbs = Program.DatabaseConfig.Databases;

            for (int i = 0; i < alldbs.Count; i++)
            {
                var db = alldbs[i];
                try{
                    string path = db.Filename;
                    if (!Path.IsPathRooted(path))
                    {
                        path = System.IO.Path.Combine(FileSystem.DbPath, path);
                    }

                    if (!File.Exists(path))
                    {
                        MessageBox.Show("The database " + Path.GetFileName(path) + " was not found and can not be loaded.");
                    }
                    else
                    {
                        var loadedDB = ClrMameProParser.ParseDAT(db, File.ReadAllText(path), db.Platforms);
                        loadedDB.AssociatedConfigEntry = db;
                        DBs.Add(loadedDB);

                        for (int j = 0; j < db.MiscPlatforms.Count; j++)
                        {
                            var platformName = db.MiscPlatforms[j];
                            loadedDB.MiscPlatforms.Add(db.MiscPlatforms[j]);

                            // Only add unique strings. Case-insensitive
                            if (_AllMiscPlatforms.Find(s => platformName.Equals(s, StringComparison.OrdinalIgnoreCase)) == null)
                            {
                                _AllMiscPlatforms.Add(platformName);
                            }
                        }
                    }
                }catch (ClrMameProParser.CmpDocumentException ex) {
                    var rslt = MessageBox.Show("A database could not be loaded (" + db.Filename + "). Additional errors will be ignored. Show details?", "Error", MessageBoxButtons.YesNo);
                    if (rslt == DialogResult.Yes)
                    {
                        using (var frm = new frmError()) {
                            frm.SetError(ex);
                            frm.ShowDialog();
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void LoadConf()
        {
            log.WriteFileLog("加载配置文件");
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(conf);

            XmlElement root = xmldoc.DocumentElement;

            // 读取显示属性
            XmlNode xn;

            try
            {
                xn     = root.SelectSingleNode("encry_str");
                keystr = xn.Attributes["key"].InnerText;
            }
            catch (Exception ex)
            {
                keystr = string.Empty;
            }

            // 读取Ssh连接配置
            xn = root.SelectSingleNode("DBBase");
            XmlNodeList xnl = xn.ChildNodes;
            XmlNodeList xll;

            foreach (XmlNode x in xnl)
            {
                // 跳过注释,否则格式不对,会报错
                if (x.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }

                DBConf d = new DBConf(x.Attributes["dbtns"].InnerText,
                                      x.Attributes["note"].InnerText);

                xll = x.ChildNodes;
                foreach (XmlNode xx in xll)
                {
                    DBUser u = new DBUser(xx.Attributes["name"].InnerText,
                                          xx.Attributes["pass"].InnerText,
                                          xx.Attributes["note"].InnerText);

                    u.file = xx.Attributes["file"].InnerText;
                    d.Users.Add(u);
                }
                DBs.Add(d);
            }

            log.WriteFileLog("配置初始化完成");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Set the current item
        /// </summary>
        /// <param name="guid">The guid of the item</param>
        /// <returns>true if the new item is set, false otherwise</returns>
        public bool SetCurrentDB(Guid guid)
        {
            var db = DBs.Where(x => x.Guid == guid);

            if (db.Any())
            {
                IDB newDB = db.First();
                CurrentDB = newDB;

                //ResourceDictionary theme = Application.Current.MainWindow.Resources.MergedDictionaries[0];
                //ResourceDictionary appTheme = Application.Current.Resources.MergedDictionaries.Count > 0
                //                                  ? Application.Current.Resources.MergedDictionaries[0]
                //                                  : null;
                //theme.BeginInit();
                //theme.MergedDictionaries.Clear();
                //if (appTheme != null)
                //{
                //    appTheme.BeginInit();
                //    appTheme.MergedDictionaries.Clear();
                //}
                //else
                //{
                //    appTheme = new ResourceDictionary();
                //    appTheme.BeginInit();
                //    Application.Current.Resources.MergedDictionaries.Add(appTheme);
                //}
                //foreach (Uri uri in newTheme.UriList)
                //{
                //    ResourceDictionary newDict = new ResourceDictionary {Source = uri};
                //    /*AvalonDock and menu style needs to move to the application
                //     * 1. AvalonDock needs global styles as floatable windows can be created
                //     * 2. Menu's need global style as context menu can be created
                //    */
                //    if (uri.ToString().Contains("AvalonDock") ||
                //        uri.ToString().Contains("Wide;component/Interfaces/Styles/VS2012/Menu.xaml"))
                //    {
                //        appTheme.MergedDictionaries.Add(newDict);
                //    }
                //    else
                //    {
                //        theme.MergedDictionaries.Add(newDict);
                //    }
                //}
                //appTheme.EndInit();
                //theme.EndInit();
                _logger.Log("Database item set to " + newDB.DBOptions.Name, LogCategory.Info, LogPriority.None);
                VEFModule.EventAggregator.GetEvent <DALChangeEvent>().Publish(newDB);
            }
            return(false);
        }
Ejemplo n.º 6
0
 static ConnectionManager()
 {
     if (File.Exists("DBConfig.xml"))
     {
         XmlDocument XDoc = new XmlDocument();
         XDoc.Load("DBConfig.xml");
         foreach (XmlNode DBs in XDoc.SelectNodes("DBHandlers"))
         {
             foreach (XmlNode DB in DBs.SelectNodes("DBHandler"))
             {
                 DBHandlers.Add(GetDBHandler(DB.SelectSingleNode("displayname").InnerText, DB.SelectSingleNode("type").InnerText, DB.SelectSingleNode("connectionString").InnerText));
             }
         }
     }
 }
Ejemplo n.º 7
0
        private void AddDB(string name, string path)
        {
            if (name == null || path == null)
            {
                return;
            }
            int count = DBs.Where(db => { return(db.DBPath == path); }).Count();

            if (count != 0)
            {
                return;
            }
            DBViewModel newDB = new DBViewModel(name, path);

            DBs.Add(newDB);
            ActiveDB = newDB;
        }
Ejemplo n.º 8
0
 public static void CreateProvider(DBs type)
 {
     _dbp = new MSSQLProvider();
 }