public static HtmlParametersPage TryLoad(string htmlData, string name) { HtmlParametersPage htmlParametersPage = null; int i; while ((i = CultureInfo.InvariantCulture.CompareInfo.IndexOf(htmlData, ParamTag, CompareOptions.IgnoreCase)) >= 0) { // Find end of parameter definition int iEnd = htmlData.IndexOf("}", i); string ParamDef = (iEnd >= 0 ? htmlData.Substring(i + ParamTag.Length, iEnd - i - ParamTag.Length) : ""); HtmlParameter NewPar = HtmlParameter.TryParam(ParamDef); // We found parameter definition if (NewPar != null) { if (htmlParametersPage == null) { htmlParametersPage = new HtmlParametersPage(name); } Array.Resize(ref htmlParametersPage.m_htmlParameters, htmlParametersPage.m_htmlParameters.Length + 1); htmlParametersPage.m_htmlParameters[htmlParametersPage.m_htmlParameters.Length - 1] = NewPar; htmlData = String.Concat(htmlData.Substring(0, i), NewPar.ID, htmlData.Substring(iEnd + 1)); } } HtmlPage.SetHtmlData(htmlParametersPage, htmlData); return(htmlParametersPage); }
public HtmlPage LoadPage(string newPage, string[] AcceptTypes) { newPage = newPage.Substring(1); HtmlPage htmlPage = FindPage(newPage); if (htmlPage != null) { return(htmlPage); } string FullPath = RootPath + "/" + newPage; // Path.Combine(RootPath, newPage); if (Directory.Exists(FullPath)) // Just a directory, then use default name OpenSkipper.html { FullPath = Path.Combine(RootPath, "OpenSkipper.html"); } if (File.Exists(FullPath)) { string type = ((AcceptTypes.Length > 0)? (AcceptTypes[0].Split(new string[] { "/" }, StringSplitOptions.None)[0]): "text"); // How to do this right? if (type == "image") { htmlPage = new HtmlImagePage(newPage, FullPath); htmlPage.PagePath = FullPath; } else { string htmlData = File.ReadAllText(FullPath); htmlPage = HtmlParametersPage.TryLoad(htmlData, newPage); if (htmlPage == null) { htmlPage = new HtmlPage(newPage, htmlData); } htmlPage.PagePath = FullPath; } } else { htmlPage = new HtmlPage(newPage); // Return default page } m_Pages.Add(htmlPage); return(htmlPage); }
private void feedCallback(IAsyncResult ar) { try { HttpListenerContext httpContext = feedListener.EndGetContext(ar); HttpListenerResponse httpResponse = httpContext.Response; HtmlParametersPage htmlPage = htmlPages.FindParamPage(httpContext.Request.RawUrl); if (htmlPage == null) { htmlPages.LoadPage(httpContext.Request.RawUrl, new string[0]); htmlPage = htmlPages.FindParamPage(httpContext.Request.RawUrl); } //-------------------------------------------------------------------------- CANHandler.ReportHandler.LogInfo("Received web data feed listener request: " + httpContext.Request.RawUrl); if (htmlPage != null) { htmlPage.PostResponse(httpResponse); } else { new HtmlParametersPage("Dummy").PostResponse(httpResponse); } // feedListener.BeginGetContext(feedCallback, null); } catch //(Exception ex) { } // Time to time we got exception something like: // {The given networkname isn't availabe anymore} // by using Lumia explorer, which caused that listener context was not // restarted. So after exception, we try anyway to start context listener. This seem to work. // Try to find solution later.. try { feedListener.BeginGetContext(feedCallback, null); } catch { } }