/// <summary> /// Function set up words, levels and category from folder. This folder named Data and located with exe-file of server. /// The order of folder define how table content will be build. /// <summary> public static void SetUpWordsContent() { int first_space = 0; int sec_space = 0; int first_bracket = 0; string folder_name = null; string transle_path = null; CategoryCache category = new CategoryCache(); LevelCache level = new LevelCache(); WordCache word = new WordCache(); string CurrentDirectory = Directory.GetCurrentDirectory(); string Data_Path = CurrentDirectory + "/Data/"; if (Directory.Exists(Data_Path)) { string[] categories = Directory.GetDirectories(Data_Path); for (int i = 0; i < categories.Length; i++) { folder_name = categories[i].Substring(Data_Path.Length); /// see name first_space = folder_name.IndexOf('_'); /// char '_' category.category_name = folder_name.Substring(first_space + 1); /// get name category.category_id = Int32.Parse(folder_name.Substring(0, first_space)); /// get id Database.category.AddCategory(ref category); string[] levels = Directory.GetDirectories(categories[i]); for (int j = 0; j < levels.Length; j++) { folder_name = levels[j].Substring(categories[i].Length + 1); /// see name first_space = folder_name.IndexOf('_'); /// char '_' sec_space = folder_name.IndexOf('_', first_space + 1); level.level_order = Int16.Parse(folder_name.Substring(0, first_space)); level.level_name = folder_name.Substring(first_space + 1, sec_space - 2); level.level_pronunction = folder_name.Substring(sec_space + 1); level.category_id = category.category_id; Database.level.AddLevel(ref level); string[] words = Directory.GetFiles(levels[j]); foreach (string file in words) { if (file.Contains("translate")) { transle_path = file; } } string[] lines = File.ReadAllLines(transle_path); for (int k = 0; k < words.Length - 1; k++) { first_bracket = lines[k].IndexOf(')'); word.word_order = Int16.Parse(lines[k].Substring(0, first_bracket)); word.category_id = category.category_id; word.level_id = level.level_id; word.word_chars = level.level_pronunction; first_space = lines[k].IndexOf('-'); word.word_name = lines[k].Substring(first_bracket + 1, first_space - (first_bracket + 1)); word.word_translete = lines[k].Substring(first_space + 1); word.word_sound_path = "http://" + Config.Domen + words[k].Remove(0, CurrentDirectory.Length); Database.word.AddWord(ref word); } } } Logger.WriteLog("Sut up game -> categories, levels and words to database from /Data/ folder.", LogLevel.Usual); } else { Logger.WriteLog("Folder /Data doesn't exist in folder:" + CurrentDirectory + " Data will be empty.", LogLevel.Error); } }