Example #1
0
        public PipelineData Process(PipelineData Input)
        {
            //if (((HttpPipelineArguments)Input.SecondaryData).isHandled == true) return Input;
            HttpListenerRoutedContext context = Input.PrimaryData as HttpListenerRoutedContext;

            Trace.WriteLine(Language.Query("LWMS.ErrorResponseUnit.UnhandledRequest", "Unhandled Http Pipeline. Request: {0}", HttpUtility.UrlDecode((context).Request.RawUrl)));


            if (context.Request.HttpMethod == HttpMethod.Get.Method)
            {
                var _404 = GlobalConfiguration.GetPage404(LWMSCoreServer.TrustedInstallerAuth);
                if (File.Exists(_404))
                {
                    Tools00.SendFile(context, new FileInfo(_404), HttpStatusCode.NotFound);
                }
                else
                {
                    Tools00.SendMessage(context, "<html><body><h1>404 File Not Found</h1><hr/><p>Hosted with LWMS.</p></body></html>", HttpStatusCode.NotFound);
                }
            }
            else
            {
                Tools00.SendMessage(context, "<html><body><h1>Error 501</h1><hr/><p>Your request is not support yet by the server.</p></body></html>", HttpStatusCode.NotImplemented);
            }
            (Input.SecondaryData as HttpPipelineArguments).isHandled = true;
            return(Input);
        }
Example #2
0
 public static void ProcessContent(HttpListenerRoutedContext content, string path)
 {
     string Content = File.ReadAllText(path);
     {
         //Process.
         StringBuilder stringBuilder = new StringBuilder(Content);
         stringBuilder = stringBuilder.Replace("{OS.Description}", RuntimeInformation.OSDescription);
         stringBuilder = stringBuilder.Replace("{Runtime.Framework}", RuntimeInformation.FrameworkDescription);
         stringBuilder = stringBuilder.Replace("{LWMS.Core.Version}", Assembly.GetAssembly(typeof(LWMSCoreServer)).GetName().Version.ToString());
         stringBuilder = stringBuilder.Replace("{LWMS.Shell.Version}", Assembly.GetEntryAssembly().GetName().Version.ToString());
         stringBuilder = stringBuilder.Replace("{LWMS.Architect}", RuntimeInformation.ProcessArchitecture.ToString());
         stringBuilder = stringBuilder.Replace("{OS.Architect}", RuntimeInformation.OSArchitecture.ToString());
         stringBuilder = stringBuilder.Replace("{DateTime.Now}", DateTime.Now.ToString());
         foreach (var item in Prefixes)
         {
             stringBuilder = stringBuilder.Replace($"{item.Key}", item.Value);
         }
         Tools00.SendMessage(content, stringBuilder.ToString());
     }
 }
Example #3
0
        public PipelineData Process(PipelineData Input)
        {
            {
                HttpListenerRoutedContext context = Input.PrimaryData as HttpListenerRoutedContext;
                var path0 = context.Request.Url.LocalPath.Substring(1);
                if (path0.ToUpper().StartsWith("BLOGS"))
                {
                    var         path1 = path0.Substring(path0.IndexOf("/") + 1);
                    StorageFile f;
                    if (path1.ToUpper().EndsWith(".INFO"))
                    {
                    }
                    else
                    {
                        if (SharedResources.Articles.GetFile(path1, out f, false))
                        {
                            Trace.WriteLine("MDBlog>>Article:" + f.Name); if (!f.ItemPath.ToUpper().EndsWith(".MD"))
                            {
                                Tools00.SendFile(context, f);
                                (Input.SecondaryData as HttpPipelineArguments).isHandled = true;
                                return(Input);
                            }
                            var MDContnet = File.ReadAllText(f.ItemPath);
                            if (SharedResources.isMarkdownUnavailable is false)
                            {
                                MDContnet = Markdown.ToHtml(MDContnet);
                                Trace.WriteLine("MDBlog>>Article>>MD");
                            }
                            string      Title = f.Name;
                            StorageFile info;
                            if (SharedResources.Articles.GetFile(path1 + ".info", out info, false))
                            {
                                var infos = File.ReadAllLines(info.ItemPath);
                                if (infos.Length > 0)
                                {
                                    Title = infos[0];
                                }
                            }

                            var FinalContent = SharedResources.ArticleTemplate_.Replace("%Content%", MDContnet).Replace("%Title%", Title);
                            context.Response.OutputStream.Write(Encoding.UTF8.GetBytes(FinalContent));
                            (Input.SecondaryData as HttpPipelineArguments).isHandled = true;
                            return(Input);
                        }
                    }
                    {
                        Trace.WriteLine("MDBlog>>MainPage");
                        var    list         = SharedResources.Articles.GetFiles();
                        var    MainContent  = SharedResources.ArticleListTemplate_;
                        var    ItemTemplate = SharedResources.ArticleListItemTemplate_;
                        var    ItemList     = "";
                        string LinkPrefix   = "./Blogs/";
                        if (path0.ToUpper().StartsWith("BLOGS/"))
                        {
                            LinkPrefix = "./";
                        }
                        foreach (var item in list)
                        {
                            if (item.Name.ToUpper().EndsWith(".INFO"))
                            {
                                var infos = File.ReadAllLines(item.ItemPath);
                                if (infos.Length > 0)
                                {
                                    ItemList += ItemTemplate.Replace("%Title%", infos[0]).Replace("%Link%", LinkPrefix + item.Name.Substring(0, item.Name.Length - 5));
                                }
                            }
                        }
                        var FinalContent = MainContent.Replace("%Content%", ItemList).Replace("%Title%", ApplicationConfiguration.Current.GetValue("BlogTitle", "LWMS Blog"));
                        Tools00.SendMessage(context, FinalContent);
                        (Input.SecondaryData as HttpPipelineArguments).isHandled = true;
                        return(Input);
                    }
                }
                (Input.SecondaryData as HttpPipelineArguments).isHandled = false;
                return(Input);
            }
        }
Example #4
0
        public bool Handle(HttpListenerRoutedContext context, string HttpPrefix)
        {
            var MappedDirectory = ApplicationConfiguration.Current.GetValue(HttpPrefix, null);

            if (MappedDirectory == null)
            {
                MappedDirectory = ApplicationConfiguration.Current.GetValue("*");
                if (MappedDirectory == null)
                {
                    MappedDirectory = GlobalConfiguration.GetWebSiteContentRoot(context.PipelineAuth);
                }
            }
            string CutPath = context.Request.Url.LocalPath.Substring(1).Substring(HttpPrefix.Length);
            var    path    = Path.Combine(MappedDirectory, CutPath);

            Trace.WriteLine($"Final:{CutPath}");
            if (Directory.Exists(path))
            {
                //Visit Directory
                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                StringBuilder folders       = new StringBuilder();
                StringBuilder files         = new StringBuilder();
                string        Readme        = "";
                {
                    if (CutPath != "")
                    {
                        folders.Append(SharedResources.DirectoryItemFolderTemplate.Replace("%Name%", "..").Replace("%Date%", "")).Replace("%Link%", "./../");
                    }
                    foreach (var item in directoryInfo.EnumerateDirectories())
                    {
                        folders.Append(SharedResources.DirectoryItemFolderTemplate.Replace("%Name%", item.Name).Replace("%Date%", item.LastWriteTimeUtc + "")).Replace("%Link%", "./" + item.Name + "/");
                    }
                    foreach (var item in directoryInfo.EnumerateFiles())
                    {
                        if (item.Name.ToUpper() == "README")
                        {
                            Readme = File.ReadAllText(item.FullName);
                        }
                        files.Append(SharedResources.DirectoryItemFileTemplate.Replace("%Name%", item.Name).Replace("%Date%", item.LastWriteTimeUtc + "").Replace("%Size%", Math.Round(((double)item.Length) / 1024.0) + " KB")).Replace("%Link%", "./" + item.Name);
                    }
                }
                var content = SharedResources.DirectoryTemplate.Replace("%Folders%", folders.ToString()).Replace("%Files%", files.ToString()).Replace("%Address%", ToHTMLString(context.Request.Url.LocalPath)).Replace("%Readme%", Readme);
                Tools00.SendMessage(context, content);
                return(true);
            }
            else
            {
                //Visit File
                if (File.Exists(path))
                {
                    FileInfo fi = new FileInfo(path);
                    if (Tools00.ObtainMimeType(fi.Extension).StartsWith("text"))
                    {
                        var content = SharedResources.TextViewerTemplate.Replace("%Content%", ToHTMLString(File.ReadAllText(fi.FullName))).Replace("%Address%", ToHTMLString(context.Request.Url.LocalPath));
                        Tools00.SendMessage(context, content);
                        return(true);
                    }
                    else
                    {
                        Tools00.SendFile(context, fi);
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #5
0
        public bool Handle(HttpListenerRoutedContext context, string HttpPrefix)
        {
            {
                var path0 = context.Request.Url.LocalPath.Substring(1);
                if (path0.ToUpper().StartsWith(HttpPrefix.ToUpper()))
                {
                    var path1 = path0.Substring(HttpPrefix.Length);
                    //path1 = path1.Substring(path1.IndexOf("/") + 1);
                    StorageFile f;
                    if (path1.ToUpper().EndsWith(".INFO"))
                    {
                    }
                    else
                    {
                        if (SharedResources.Articles.GetFile(path1, out f, false))
                        {
                            Trace.WriteLine("MDBlog>>Article:" + f.Name);
                            if (!f.ItemPath.ToUpper().EndsWith(".MD"))
                            {
                                Tools00.SendFile(context, f);
                                return(true);
                            }
                            var MDContnet = File.ReadAllText(f.ItemPath);
                            if (SharedResources.isMarkdownUnavailable is false)
                            {
                                MDContnet = Markdown.ToHtml(MDContnet);
                            }
                            string      Title = f.Name;
                            StorageFile info;
                            if (SharedResources.Articles.GetFile(path1 + ".info", out info, false))
                            {
                                var infos = File.ReadAllLines(info.ItemPath);
                                if (infos.Length > 0)
                                {
                                    Title = infos[0];
                                }
                            }

                            var FinalContent = SharedResources.ArticleTemplate_.Replace("%Content%", MDContnet).Replace("%Title%", Title);
                            context.Response.OutputStream.Write(Encoding.UTF8.GetBytes(FinalContent));
                            return(true);
                        }
                    }
                    {
                        Trace.WriteLine("MDBlog>>MainPage");
                        try
                        {
                            var list = SharedResources.Articles.GetFiles();

                            var MainContent  = SharedResources.ArticleListTemplate_;
                            var ItemTemplate = SharedResources.ArticleListItemTemplate_;
                            var ItemList     = "";
                            //string LinkPrefix = "./" + (HttpPrefix.Split("/").Last()) + "/";

                            //if (path0.ToUpper().StartsWith(HttpPrefix.ToUpper()))
                            var LinkPrefix = "./";
                            foreach (var item in list)
                            {
                                if (item.Name.ToUpper().EndsWith(".INFO"))
                                {
                                    var infos = File.ReadAllLines(item.ItemPath);
                                    if (infos.Length > 0)
                                    {
                                        ItemList += ItemTemplate.Replace("%Title%", infos[0]).Replace("%Link%", LinkPrefix + item.Name.Substring(0, item.Name.Length - 5));
                                    }
                                }
                            }
                            var FinalContent = MainContent.Replace("%Content%", ItemList).Replace("%Title%", ApplicationConfiguration.Current.GetValue("BlogTitle", "LWMS Blog"));
                            Tools00.SendMessage(context, FinalContent);
                            //context.Response.OutputStream.Write(Encoding.UTF8.GetBytes(FinalContent));

                            return(true);
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine(e);
                        }
                    }
                }
                return(false);
            }
        }