Exemple #1
0
        static void Main(string[] args)
        {
            try
            {
                if (args != null)
                {
                    if (args.Count() > 0)
                    {
                        Ambiente Ambiente = new Ambiente();
                        DispFile DispFile = new DispFile(Ambiente);

                        DispFile.Open(args[0]);
                    }
                }
            }
            catch (Exception ex)
            {
                DateTime agora = DateTime.Now;

                FileStream   fs1    = new FileStream(string.Format(@"{0}\Log\{1}-{2}-{3}-{4}-{5}-{6}.txt", AppDomain.CurrentDomain.BaseDirectory, agora.Year, agora.Month, agora.Day, agora.Hour, agora.Minute, agora.Millisecond), FileMode.OpenOrCreate, FileAccess.Write);
                StreamWriter writer = new StreamWriter(fs1);
                writer.Write(ex.Message);
                writer.Close();
            }
        }
Exemple #2
0
        public string Exec(string script)
        {
            DispFile file = new DispFile(this.Ambiente);

            return(file.Open(string.Format("{0}\\{1}", this.Ambiente.CurrentFolder, script)));
        }
Exemple #3
0
        static void Main()
        {
            TcpListener listener = new TcpListener(80);

            listener.Start();

            while (true)
            {
                Console.WriteLine("Waiting for connection");

                TcpClient    client = listener.AcceptTcpClient();
                StreamReader sr     = new StreamReader(client.GetStream());
                StreamWriter sw     = new StreamWriter(client.GetStream());

                try
                {
                    String request = sr.ReadLine();

                    Console.WriteLine(request);

                    String[] tokens = request.Split(' ');
                    String   page   = tokens[1].Remove(0, 1);

                    if (Directory.Exists(page))
                    {
                        sw.WriteLine("HTTP/1.0 200 OK\n");

                        string[] fileEntries = Directory.GetFiles(page);
                        foreach (string fileName in fileEntries)
                        {
                            sw.WriteLine(String.Format("<br><a href=\"{0}\">{1}</a>", fileName.Replace(page, String.Empty), fileName.Replace(page, String.Empty)));
                        }
                        string[] subdirectoryEntries = Directory.GetDirectories(page);
                        foreach (string subdirectory in subdirectoryEntries)
                        {
                            sw.WriteLine(String.Format("<br><a href=\"{0}\">{1}</a>", subdirectory.Replace(page, String.Empty), subdirectory.Replace(page, String.Empty)));
                        }

                        sw.Flush();
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(page))
                        {
                            page = "index.html";
                        }

                        if (File.Exists(page))
                        {
                            if (page.EndsWith(".ds"))
                            {
                                Ambiente Ambiente = new Ambiente();
                                DispFile DispFile = new DispFile(Ambiente);

                                sw.WriteLine("HTTP/1.0 200 OK\n");
                                String result = DispFile.Open(page);
                                sw.WriteLine(result);
                                sw.Flush();
                            }
                            else
                            {
                                StreamReader file = new StreamReader(page);
                                sw.WriteLine("HTTP/1.0 200 OK\n");

                                sw.WriteLine("<!-- This page was rendered using RhenServer Beta for Disp -->");

                                String data = file.ReadLine();

                                while (data != null)
                                {
                                    sw.WriteLine(data);
                                    sw.Flush();
                                    data = file.ReadLine();
                                }
                            }
                        }
                        else
                        {
                            sw.WriteLine("HTTP/1.0 404 OK\n");
                            sw.WriteLine("<h1>Page not found</h1>");
                            sw.WriteLine("<p>RhenServer Beta</p>");
                            sw.Flush();
                        }
                    }
                }
                catch (Exception ex)
                {
                    sw.WriteLine("HTTP/1.0 404 OK\n");
                    sw.WriteLine(String.Format("<h1>{0}</h1>", ex.StackTrace));
                    sw.Flush();
                }

                client.Close();
            }
        }