public static List <string> GetTreeViewDecriptiveColumnsNames(EDBTable value) { List <string> output = new List <string>(); string[] strColumnsNames = GetColumnsNames(value); foreach (int nColumnIndex in GetTreeViewDecriptiveColumnsPositions(value)) { output.Add(strColumnsNames[nColumnIndex]); } return(output); }
public static string GetSqlCreation(string table_name_sufix) { string output = null; object oDBTable = Parse(table_name_sufix); if (oDBTable != null) { EDBTable eDBTable = (EDBTable)oDBTable; output = GetSqlCreation(eDBTable); } return(output); }
private void LoadTreeItemsWoker_DoWork(object sender, DoWorkEventArgs e) { _treeItemsList = new List <ViewerTreeItemDescriptor>(); for (int nModIndex = 0; nModIndex < App.I.ModsPrefix.Count; nModIndex++) { for (int nTableIndex = 0; nTableIndex < (int)EDBTable.eTotal; nTableIndex++) { EDBTable eDBTable = (EDBTable)nTableIndex; string strTableNamePrefix = App.I.ModsPrefix[nModIndex]; string strTableNameSufix = DBTableAttributtesFetcher.GetNameSufix(eDBTable); string strTableName = string.Format("{0}_{1}", strTableNamePrefix, strTableNameSufix); List <string> strColumnsList = DBTableAttributtesFetcher.GetTreeViewDecriptiveColumnsNames(eDBTable); //Get items from mem DB List <object[]> listColumnsValuesTable = App.DB.GetAllTableDataOfSpecificColumnsFromMemory(strTableName, strColumnsList); if (listColumnsValuesTable.Count > 0) { //Now check if the collection already have the type int nByTypeTypeIndex = GetTier1NodeIndex(ByTypeTreeData, strTableNameSufix); //Now check if the Tier1 collection already have the mod int nByTypeModIndex = GetTier2NodeIndex(ByTypeTreeData[nByTypeTypeIndex].Tier2, strTableNamePrefix); //Now check if the collection already have the mod int nByModModIndex = GetTier1NodeIndex(ByModTreeData, strTableNamePrefix); //Now check if the Tier1 collection already have the type int nByModTypeIndex = GetTier2NodeIndex(ByModTreeData[nByModModIndex].Tier2, strTableNameSufix); //Now for each item we will create a new ViewerTreeItemDescriptor object and add it to the trees listColumnsValuesTable.ForEach(item => { int nByTypeItemIndex = ByTypeTreeData[nByTypeTypeIndex].Tier2[nByTypeModIndex].Items.Count; int nByModItemIndex = ByModTreeData[nByModModIndex].Tier2[nByModTypeIndex].Items.Count; int[] nTreeIndexByType = new int[3] { nByTypeTypeIndex, nByTypeModIndex, nByTypeItemIndex }; int[] nTreeIndexByMod = new int[3] { nByModModIndex, nByModTypeIndex, nByModItemIndex }; ViewerTreeItemDescriptor newItem = new ViewerTreeItemDescriptor(item, eDBTable, nModIndex, nTreeIndexByType, nTreeIndexByMod, strTableName); _treeItemsList.Add(newItem); ByTypeTreeData[nByTypeTypeIndex].Tier2[nByTypeModIndex].Items.Add(newItem); ByModTreeData[nByModModIndex].Tier2[nByModTypeIndex].Items.Add(newItem); }); } } } }
//Type 0 (ones with data folder) private void ParseType0(string str_folder, string str_mod_name, string str_mod_folder_name) { string strType0DataFolder = Path.Combine(str_folder, "data"); IEnumerable <string> enumFiles = Directory.EnumerateFiles(strType0DataFolder); foreach (string file in enumFiles) { string strFileName = Path.GetFileName(file); object oDBTable = DBTableAttributtesFetcher.Parse(Path.GetFileNameWithoutExtension(strFileName).ToLower()); if (oDBTable != null && (string.Compare(Path.GetExtension(strFileName), ".xml") == 0)) //only parse supported xml files { EDBTable eDBTable = (EDBTable)oDBTable; App._splashScreen.UpdateMessage("Parsing " + str_mod_folder_name + ": " + strFileName); //only parse the file if it was changed since last time byte[] fileHash = null; if (CheckSavedFileHash(file, out fileHash) == false) { //Let's do one transaction per file to speed things up SQLiteTransaction sqlTransaction = DbFsConnection.BeginTransaction(); //Create the table if it does not exist already string strTableName = str_mod_name + "_" + str_mod_folder_name + "_" + DBTableAttributtesFetcher.GetNameSufix(eDBTable); SQLiteCommand command = new SQLiteCommand(DBTableAttributtesFetcher.GetSqlCreation(eDBTable), DbFsConnection, sqlTransaction); command.CommandText = string.Format(command.CommandText, strTableName); command.ExecuteNonQuery(); //parse the xml file to DB ParseXMLFile(file, str_mod_name + "_" + str_mod_folder_name, sqlTransaction); //now save file hash to table SaveFileHash(file, fileHash, sqlTransaction); //finally commit the transaction sqlTransaction.Commit(); } } } //After parsing all the data files let's check if there are any getimages.php to parse string strImageFile = Path.Combine(str_folder, "getimages.php"); if (File.Exists(strImageFile)) { App._splashScreen.UpdateMessage("Parsing " + str_mod_folder_name + ": getimages.php"); ParseGetImagesFile(strImageFile, str_mod_name + "_" + str_mod_folder_name + "_" + "images", str_folder); } //If everything went well we will add to the mod list App.I.Mods.Add(str_mod_name + "_" + str_mod_folder_name); }
private void ParseType1(string str_folder, string str_mod_name, string str_mod_folder_name) { string strType1NeogameFile = Path.Combine(str_folder, "neogame.xml").ToLower(); App._splashScreen.UpdateMessage("Parsing " + str_mod_folder_name + ": neogame.xml"); //only parse the file if it was changed since last time byte[] fileHash = null; if (CheckSavedFileHash(strType1NeogameFile, out fileHash) == false) { //Let's do one transaction per file to speed things up SQLiteTransaction sqlTransaction = DbFsConnection.BeginTransaction(); //Create all tables for this mod SQLiteCommand command = new SQLiteCommand(DbFsConnection); command.Transaction = sqlTransaction; for (int nIndex = 0; nIndex < (int)EDBTable.eTotal; nIndex++) { EDBTable eDBTable = (EDBTable)nIndex; command.Reset(); string strTableName = str_mod_name + "_" + str_mod_folder_name + "_" + DBTableAttributtesFetcher.GetNameSufix(eDBTable); string strSqlCreation = DBTableAttributtesFetcher.GetSqlCreation(eDBTable); command.CommandText = string.Format(strSqlCreation, strTableName); command.ExecuteNonQuery(); } //parse the xml file to DB ParseXMLFile(strType1NeogameFile, str_mod_name + "_" + str_mod_folder_name, sqlTransaction); //now save file hash to table SaveFileHash(strType1NeogameFile, fileHash, sqlTransaction); //finally commit the transaction sqlTransaction.Commit(); } //After parsing all the data files let's check if there are any getimages.php to parse string strImageFile = Path.Combine(str_folder, "getimages.php"); if (File.Exists(strImageFile)) { App._splashScreen.UpdateMessage("Parsing " + str_mod_folder_name + ": getimages.php"); ParseGetImagesFile(strImageFile, str_mod_name + "_" + str_mod_folder_name + "_" + "images", str_folder); } //If everything went well we will add to the mod list App.I.Mods.Add(str_mod_name + "_" + str_mod_folder_name); }
public static string[] GetColumnsNames(EDBTable value) { string [] output = null; Type type = typeof(EDBTable); if (_ColumnsNames.ContainsKey(value)) { output = (_ColumnsNames[value] as ColumnsNamesAttribute).Value; } else { //Look for our 'ColumnsNamesAttribute' in the field's custom attributes FieldInfo fi = type.GetField(value.ToString()); ColumnsNamesAttribute[] attrs = fi.GetCustomAttributes(typeof(ColumnsNamesAttribute), false) as ColumnsNamesAttribute[]; if (attrs.Length > 0) { _ColumnsNames.Add(value, attrs[0]); output = attrs[0].Value; } } return(output); }
public static string GetSqlCreation(EDBTable value) { string output = null; Type type = typeof(EDBTable); if (_SqlCreation.ContainsKey(value)) { output = (_SqlCreation[value] as SqlCreationAttribute).Value; } else { //Look for our 'SqlCreationAttribute' in the field's custom attributes FieldInfo fi = type.GetField(value.ToString()); SqlCreationAttribute[] attrs = fi.GetCustomAttributes(typeof(SqlCreationAttribute), false) as SqlCreationAttribute[]; if (attrs.Length > 0) { _SqlCreation.Add(value, attrs[0]); output = attrs[0].Value; } } return(output); }
public static string GetPrimaryKeyName(EDBTable value) { string output = null; Type type = typeof(EDBTable); if (_PrimaryKeyNameValues.ContainsKey(value)) { output = (_PrimaryKeyNameValues[value] as PrimaryKeyNameAttribute).Value; } else { //Look for our 'PrimaryKeyNameAttribute' in the field's custom attributes FieldInfo fi = type.GetField(value.ToString()); PrimaryKeyNameAttribute[] attrs = fi.GetCustomAttributes(typeof(PrimaryKeyNameAttribute), false) as PrimaryKeyNameAttribute[]; if (attrs.Length > 0) { _PrimaryKeyNameValues.Add(value, attrs[0]); output = attrs[0].Value; } } return(output); }
public static int[] GetTreeViewDecriptiveColumnsPositions(EDBTable value) { int[] output = null; Type type = typeof(EDBTable); if (_TreeViewDecriptiveColumnsPositions.ContainsKey(value)) { output = (_TreeViewDecriptiveColumnsPositions[value] as TreeViewDecriptiveColumnsPositionsAttribute).Value; } else { //Look for our 'TreeViewDecriptiveColumnsPositionsAttribute' in the field's custom attributes FieldInfo fi = type.GetField(value.ToString()); TreeViewDecriptiveColumnsPositionsAttribute[] attrs = fi.GetCustomAttributes(typeof(TreeViewDecriptiveColumnsPositionsAttribute), false) as TreeViewDecriptiveColumnsPositionsAttribute[]; if (attrs.Length > 0) { _TreeViewDecriptiveColumnsPositions.Add(value, attrs[0]); output = attrs[0].Value; } } return(output); }
public ViewerTreeItemDescriptor(object [] columns_values, EDBTable type, int n_mod_index, int [] tree_index_type, int[] tree_index_mod, string table_name) { _primaryKeyValue = columns_values[0].ToString(); _primaryKeyName = DBTableAttributtesFetcher.GetPrimaryKeyName(type); switch (columns_values.Length) { case 1: _treeText = _primaryKeyValue; _description = string.Empty; break; case 2: // Most of them _description = columns_values[1].ToString(); _treeText = string.Format("{0}_{1}", _primaryKeyValue, _description); break; case 3: // BarterHexes _description = string.Format("({0}, {1})", columns_values[1], columns_values[2]); _treeText = string.Format("{0}_{1}", _primaryKeyValue, _description); break; case 4: // ForbiddenHexes _description = string.Format("({0}, {1})_{2}", columns_values[1], columns_values[2], columns_values[3]); _treeText = string.Format("{0}_{1}", _primaryKeyValue, _description); break; } _type = type; _modIndex = n_mod_index; _treeIndexByType = tree_index_type; _treeIndexByMod = tree_index_mod; _tableName = table_name; }