예제 #1
0
        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));
        }
예제 #2
0
        public void loadCard(string parent, string name)
        {
            string path = Path.Combine(contentDirectory, parent, name);

            if (!loadedCards.ContainsKey(path))
            {
                CardFileData card = CardFileData.readFile(new FileReadingAdapter(), path);
                if (card != null)
                {
                    loadedCards.Add(path, card);
                }
            }
        }
예제 #3
0
        public static string getCardParentFolderName(CardBoxFileData box, CardFileData card)
        {
            switch (box.indexing)
            {
            case BoxIndexing.CATEGORY:
                return(card.category);

            case BoxIndexing.CHAPTERS:
                return(string.Format(IOUtil.inLocalizedEnviroment(box.lang,
                                                                  () => Localization.FileKeywords.FileName_ChapterFolderPrefix +
                                                                  Localization.Settings.Symbol_NameContent_Seperator),
                                     box.chapters.IndexOf(card.chapterName) + 1) + card.chapterName);//cause it starts at 0!

            case BoxIndexing.CHRONOLOGICAL:
                return(card.dateCreated);
            }
            return(null);
        }
예제 #4
0
        public static CardFileData readFile(FileReadingOverseer overseer, string absolutePath)
        {
            string cfname = IOUtil.Delegated_GetApplicableFileWithFeedback(overseer, absolutePath);

            if (cfname == null)
            {
                return(null);
            }
            string flang = IOUtil.getFileLang(cfname);

            CultureInfo stack = Thread.CurrentThread.CurrentUICulture;

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(flang);

            List <KeyValuePair <string, string> > fdata = ZDictionaryFileIO.readFile(Localization.Settings.Symbol_NameContent_Seperator, absolutePath, cfname);

            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);
                return(null);
                // TODO: Process the instruction
            }

            CardFileData cfd = new CardFileData();

            cfd.lang = flang;
            foreach (var entry in fdata)
            {
                string att = entry.Key;
                string val = entry.Value;

                if (att == Localization.FileKeywords.Card_Name)
                {
                    cfd.name = val;
                }
                else if (att == Localization.FileKeywords.Card_Text)
                {
                    cfd.text = val;
                }
                else if (att == Localization.FileKeywords.Card_Creater)
                {
                    cfd.creater = val;
                }
                else if (att == Localization.FileKeywords.Card_DateCreated)
                {
                    cfd.dateCreated = val;
                }
                else if (att == Localization.FileKeywords.Card_Category)
                {
                    cfd.category = val;
                }
                else if (att == Localization.FileKeywords.Card_ChapterName)
                {
                    cfd.chapterName = val;
                }
                else if (att == Localization.FileKeywords.Card_Keywords)
                {
                    cfd.keywords = new HashSet <string>();
                    cfd.keywords.UnionWith(zusp.Split(val, Localization.Settings.Symbol_NameContent_Seperator).ToList());
                }
            }
            cfd.path = absolutePath;
            Thread.CurrentThread.CurrentUICulture = stack;

            return(cfd);
        }