public void addNewCard(CardFileData card) { //update box first if (!boxData.categories.Contains(card.category)) { boxData.categories.Add(card.category); } if (!boxData.chapters.Contains(card.chapterName)) { boxData.chapters.Add(card.chapterName); } foreach (var keyword in card.keywords) { if (!boxData.keywords.Contains(keyword)) { boxData.keywords.Add(keyword); } } boxData.writeFile(boxDirectory); //then process card string folderName = BoxIndexingHandler.getCardParentFolderName(boxData, card); folderName = Path.Combine(contentDirectory, folderName); if (!Directory.Exists(folderName)) { Directory.CreateDirectory(folderName); } folderName = Path.Combine(folderName, card.name); Directory.CreateDirectory(folderName); card.writeFile(folderName); Directory.CreateDirectory(Path.Combine(folderName, Localization.FileKeywords.Filename_Directory_Attachment)); }
public static CardBoxFileData readFile(FileReadingOverseer overseer, string absolutePath) { string bfname = IOUtil.Delegated_GetApplicableFileWithFeedback(overseer, absolutePath); string flang = IOUtil.getFileLang(bfname); CultureInfo stack = Thread.CurrentThread.CurrentUICulture; Thread.CurrentThread.CurrentUICulture = new CultureInfo(flang); List <KeyValuePair <string, string> > fdata = ZDictionaryFileIO.readFile(Localization.Settings.Symbol_NameContent_Seperator, absolutePath, bfname); //construct a set of file attributes that we want to ensure they are there and cross them off so its linear time to number of lines HashSet <string> missingfields = IOUtil.CheckFDataHaveAllDefaults(fdata, getDefaults(flang)); if (missingfields.Count > 0) { Thread.CurrentThread.CurrentUICulture = stack; Instruction i = overseer.onFileInvalid(Localization.Messages.FileIO_FieldMissing, missingfields.ToArray()); Thread.CurrentThread.CurrentUICulture = new CultureInfo(flang); // TODO: Process the instruction } //now the file should have all nesscairy properties. CardBoxFileData cbd = new CardBoxFileData(); cbd.lang = flang; foreach (var entry in fdata) { string att = entry.Key; string val = entry.Value; if (att == Localization.FileKeywords.CardBox_Title) { cbd.title = val; } else if (att == Localization.FileKeywords.CardBox_Description) { cbd.description = val; } else if (att == Localization.FileKeywords.CardBox_Creater) { cbd.creator = val; } else if (att == Localization.FileKeywords.CardBox_DateCreated) { cbd.dateCreated = val; } else if (att == Localization.FileKeywords.CardBox_Index) { cbd.indexing = BoxIndexingHandler.getIndexingEnum(val); } else if (att == Localization.FileKeywords.CardBox_CategoryNames) { cbd.categories = new SortedSet <string>(); cbd.categories.UnionWith(zusp.Split(val, Localization.Settings.Symbol_NameContent_Seperator).ToList()); } else if (att == Localization.FileKeywords.CardBox_ChapterNames) { cbd.chapters = zusp.Split(val, Localization.Settings.Symbol_NameContent_Seperator).ToList(); } else if (att == Localization.FileKeywords.CardBox_KeywordNames) { cbd.keywords = new HashSet <string>(); cbd.keywords.UnionWith(zusp.Split(val, Localization.Settings.Symbol_NameContent_Seperator).ToList()); } } if (cbd.indexing == BoxIndexing.INVALID) { string flindex = Localization.FileKeywords.CardBox_Index; Thread.CurrentThread.CurrentUICulture = stack; Instruction i = overseer.onFileInvalid(Localization.Messages.FileIO_FieldValueNotValid, flindex); Thread.CurrentThread.CurrentUICulture = new CultureInfo(flang); } Thread.CurrentThread.CurrentCulture = stack; return(cbd); }
public void writeFile(string absolutePath, CultureInfo lang) { IOUtil.inLocalizedEnviroment(lang, () => { string sep = Localization.Settings.Symbol_NameContent_Seperator; string fname = Localization.FileKeywords.FileName_CardBoxInfo + "." + lang.Name + "." + SystemResources.Postfix_File; List <KeyValuePair <string, string> > odata = new List <KeyValuePair <string, string> >(); odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_Title, title)); odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_Creater, creator)); odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_DateCreated, dateCreated)); odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_Index, zu.OtherIfNull(BoxIndexingHandler.getIndexingText(indexing), getDefaults(lang.Name)[Localization.FileKeywords.CardBox_Index]))); string schapters = ""; for (int i = 0; i < chapters.Count; i++) { schapters += chapters[i] + sep; } odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_ChapterNames, schapters)); string scategories = ""; foreach (string s in categories) { scategories += s + sep; } odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_CategoryNames, scategories)); string skeywords = ""; foreach (string s in keywords) { skeywords += s + sep; } odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_KeywordNames, skeywords)); odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_Description, description)); //first deal with file's date, if the file is newly created. Else leave it to default handling if (dateCreated.Trim() == "" && !File.Exists(Path.Combine(absolutePath, fname))) { dateCreated = IOUtil.formatNow(); } //ensures there's a default for this language getDefaults(lang.Name); for (int i = 0; i < odata.Count; i++) {//add defaults to empy attributes KeyValuePair <string, string> p = odata[i]; if (langDefaults[lang.Name].ContainsKey(p.Key) && p.Value == "") { odata[i] = new KeyValuePair <string, string>(p.Key, langDefaults[lang.Name][p.Key]); } } ZDictionaryFileIO.writeFile(odata, sep, absolutePath, fname); }); }