Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="overseer"></param>
        /// <param name="absolutePath"></param>
        /// <returns>a list of string of files that ends with proper postfix and supported language</returns>
        public static string Delegated_GetApplicableFileWithFeedback(FileReadingOverseer overseer, string absolutePath)
        {
            List <string> qnotefiles = GetQNoteFiles(absolutePath);
            string        fname      = null;
            List <string> vlangfiles = qnotefiles.Where(s => isSupportedLanguage(getFileLang(s))).Select(s => s).ToList();

            // ---------------------File Finding

            if (qnotefiles.Count == 0)
            {// no qnote file
                Instruction i = overseer.onFileNotExist();
                if (i == Instruction.RESTART)
                {
                    return(Delegated_GetApplicableFileWithFeedback(overseer, absolutePath));
                }
                else
                {
                    return(null);
                }
            }
            if (vlangfiles.Count == 0)
            { //no qnote file of supported language
                Instruction i = overseer.onFileLangInvalid();
                // TODO: finish this
            }
            else if (vlangfiles.Count > 1)
            {
                KeyValuePair <Instruction, string> i = overseer.onMultipleFileExist(qnotefiles);
                switch (i.Key)
                {
                case Instruction.RESTART:
                    return(Delegated_GetApplicableFileWithFeedback(overseer, absolutePath));

                case Instruction.CHOOSE:
                    fname = i.Value;
                    break;

                case Instruction.CONTINUE:
                    fname = qnotefiles[0];
                    break;

                default:
                    return(null);
                }
            }
            else if (vlangfiles.Count == 1)
            {
                fname = vlangfiles[0];
            }
            return(fname);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        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);
        }