示例#1
0
        private static string GetReaderSettings(CollectionSettings currentCollectionSettings)
        {
            var settingsPath = DecodableReaderTool.GetReaderToolsSettingsFilePath(currentCollectionSettings);

            // if file exists, return current settings
            if (RobustFile.Exists(settingsPath))
            {
                var result = RobustFile.ReadAllText(settingsPath, Encoding.UTF8);
                if (!string.IsNullOrWhiteSpace(result))
                {
                    return(result);
                }
            }

            // file does not exist, so make a new one
            // The literal string here defines our default reader settings for a collection.
            var settingsString = "{\"letters\":\"a b c d e f g h i j k l m n o p q r s t u v w x y z\","
                                 + "\"moreWords\":\"\","
                                 + "\"stages\":[{\"letters\":\"\",\"sightWords\":\"\"}],"
                                 + "\"levels\":[{\"maxWordsPerSentence\":2,\"maxWordsPerPage\":2,\"maxWordsPerBook\":20,\"maxUniqueWordsPerBook\":0,\"thingsToRemember\":[]},"
                                 + "{\"maxWordsPerSentence\":5,\"maxWordsPerPage\":5,\"maxWordsPerBook\":23,\"maxUniqueWordsPerBook\":8,\"thingsToRemember\":[]},"
                                 + "{\"maxWordsPerSentence\":7,\"maxWordsPerPage\":10,\"maxWordsPerBook\":72,\"maxUniqueWordsPerBook\":16,\"thingsToRemember\":[]},"
                                 + "{\"maxWordsPerSentence\":8,\"maxWordsPerPage\":18,\"maxWordsPerBook\":206,\"maxUniqueWordsPerBook\":32,\"thingsToRemember\":[]},"
                                 + "{\"maxWordsPerSentence\":12,\"maxWordsPerPage\":25,\"maxWordsPerBook\":500,\"maxUniqueWordsPerBook\":64,\"thingsToRemember\":[]},"
                                 + "{\"maxWordsPerSentence\":20,\"maxWordsPerPage\":50,\"maxWordsPerBook\":1000,\"maxUniqueWordsPerBook\":0,\"thingsToRemember\":[]}]}";

            RobustFile.WriteAllText(settingsPath, settingsString);

            return(settingsString);
        }
示例#2
0
        public void HandleRequest(ApiRequest request)
        {
            if (CurrentBook == null)
            {
                Debug.Fail("BL-836 reproduction?");
                // ReSharper disable once HeuristicUnreachableCode
                request.Failed("CurrentBook is null");
                return;
            }
            if (request.CurrentCollectionSettings == null)
            {
                Debug.Fail("BL-836 reproduction?");
                // ReSharper disable once HeuristicUnreachableCode
                request.Failed("CurrentBook.CollectionSettings is null");
                return;
            }

            var lastSegment = request.LocalPath().Split(new char[] { '/' }).Last();

            switch (lastSegment)
            {
            case "test":
                request.Succeeded();
                break;

            case "readerToolSettings":
                if (request.HttpMethod == HttpMethods.Get)
                {
                    request.ReplyWithJson(GetReaderSettings(request.CurrentCollectionSettings));
                }
                else
                {
                    var path    = DecodableReaderTool.GetReaderToolsSettingsFilePath(request.CurrentCollectionSettings);
                    var content = request.RequiredPostJson();
                    RobustFile.WriteAllText(path, content, Encoding.UTF8);
                    request.Succeeded();
                }
                break;


            //note, this endpoint is confusing because it appears that ultimately we only use the word list out of this file (see "sampleTextsList").
            //This ends up being written to a ReaderToolsWords-xyz.json (matching its use, if not it contents).
            case "synphonyLanguageData":
                //This is the "post". There is no direct "get", but the name of the file is given in the "sampleTextList" reply, below:
                SaveSynphonyLanguageData(request.RequiredPostJson());
                request.Succeeded();
                break;

            case "sampleTextsList":
                //note, as part of this reply, we send the path of the "ReaderToolsWords-xyz.json" which is *written* by the "synphonyLanguageData" endpoint above
                request.ReplyWithText(GetSampleTextsList(request.CurrentCollectionSettings.SettingsFilePath));
                break;

            case "sampleFileContents":
                request.ReplyWithText(GetTextFileContents(request.RequiredParam("fileName"), WordFileType.SampleFile));
                break;

            case "textOfContentPages":
                request.ReplyWithText(GetTextOfContentPagesAsJson());
                break;

            case "makeLetterAndWordList":
                MakeLetterAndWordList(request.RequiredPostValue("settings"), request.RequiredPostValue("allWords"));
                request.Succeeded();
                break;

            case "openTextsFolder":
                OpenTextsFolder();
                request.Succeeded();
                break;

            case "chooseAllowedWordsListFile":
                lock (request)
                {
                    request.ReplyWithText(ShowSelectAllowedWordsFileDialog());
                }
                break;

            case "allowedWordsList":
                switch (request.HttpMethod)
                {
                case HttpMethods.Delete:
                    RecycleAllowedWordListFile(request.RequiredParam("fileName"));
                    request.Succeeded();
                    break;

                case HttpMethods.Get:
                    var fileName = request.RequiredParam("fileName");
                    request.ReplyWithText(RemoveEmptyAndDupes(GetTextFileContents(fileName, WordFileType.AllowedWordsFile)));
                    break;

                default:
                    request.Failed("Http verb not handled");
                    break;
                }
                break;

            default:
                request.Failed("Don't understand '" + lastSegment + "' in " + request.LocalPath());
                break;
            }
        }