Ejemplo n.º 1
0
        public static bool HandleRequest(string localPath, IRequestInfo info, CollectionSettings currentCollectionSettings)
        {
            var lastSep     = localPath.IndexOf("/", StringComparison.Ordinal);
            var lastSegment = (lastSep > -1) ? localPath.Substring(lastSep + 1) : localPath;

            switch (lastSegment)
            {
            case "loadReaderToolSettings":
                info.ContentType = "application/json";
                info.WriteCompleteOutput(GetDefaultReaderSettings(currentCollectionSettings));
                return(true);

            case "saveReaderToolSettings":
                var path    = currentCollectionSettings.DecodableLevelPathName;
                var content = info.GetPostData()["data"];
                File.WriteAllText(path, content, Encoding.UTF8);
                info.ContentType = "text/plain";
                info.WriteCompleteOutput("OK");
                return(true);

            case "getDefaultFont":
                var bookFontName = currentCollectionSettings.DefaultLanguage1FontName;
                if (string.IsNullOrEmpty(bookFontName))
                {
                    bookFontName = "sans-serif";
                }
                info.ContentType = "text/plain";
                info.WriteCompleteOutput(bookFontName);
                return(true);

            case "getSampleTextsList":
                info.ContentType = "text/plain";
                info.WriteCompleteOutput(GetSampleTextsList(currentCollectionSettings.SettingsFilePath));
                return(true);

            case "getSampleFileContents":
                var fileName = info.GetQueryString()["data"];
                info.ContentType = "text/plain";
                info.WriteCompleteOutput(GetSampleFileContents(fileName, currentCollectionSettings.SettingsFilePath));
                return(true);

            case "getTextOfPages":
                info.ContentType = "text/plain";
                info.WriteCompleteOutput(GetTextOfPages());
                return(true);

            case "saveReaderToolsWords":
                info.ContentType = "text/plain";
                info.WriteCompleteOutput(SaveReaderToolsWordsFile(info.GetPostData()["data"]));
                return(true);

            case "makeLetterAndWordList":
                MakeLetterAndWordList(info.GetPostData()["settings"], info.GetPostData()["allWords"]);
                info.ContentType = "text/plain";
                info.WriteCompleteOutput("OK");
                return(true);

            case "openTextsFolder":
                OpenTextsFolder();
                info.ContentType = "text/plain";
                info.WriteCompleteOutput("OK");
                return(true);
            }

            return(false);
        }