コード例 #1
0
        /// <summary>
        /// Gets a page from disk and applies ASP tags interpreter to it.
        /// </summary>
        /// <param name="localPath"></param>
        /// <returns></returns>
        protected override async Task <string> GetPageContent(string localPath, string postData)
        {
            // it is either a command or a local page or file.
            localPath = await TryParseCommand(localPath, postData);

            if (String.IsNullOrWhiteSpace(localPath))
            {
                localPath = deviceOpener.IsDeviceOpen ? "/Default.html" : "/OpenConnection.html";
            }
            else if (localPath.StartsWith("##")) // command interpreter prepared content for us
            {
                return(localPath.Substring(2));
            }

            string pageContent = string.Empty;
            string pagePath    = getPagePath(localPath);

            if (File.Exists(pagePath))
            {
                // have ASP.cs produce content, by reading the file and interpreting tags:
                pageContent = asp.InterpretAspTags(File.ReadAllText(pagePath));
            }
            else
            {
                // produce error message:
                pageContent = string.Format(HtmlErrorStringFormat, localPath);
            }
            return(pageContent);
        }