示例#1
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(LogUnhandledException);

            Base.Program.LogInfo();

            #if DEBUG
            var server = new HttpServer(ApplicationInfo.CurrentDirectory + @"..\..\Http\Views\");
            #else
            var server = new HttpServer(ApplicationInfo.CurrentDirectory + @"views\");
            #endif
            Server = server;

            port = server.Port;

            //			foreach (string resource in EmbeddedResource.GetAllResources())
            //			{
            //				System.Diagnostics.Debug.WriteLine(resource);
            //			}

            string root = IO.CheckRoot(@".\");
            root = IO.CheckRoot(@"..\");
            root = IO.CheckRoot(@"..\..\");
            root = IO.CheckRoot(@"\");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Menu());

            Server.Stop();
            System.Threading.Thread.Sleep(500);
            //throw new ApplicationException("testing unhandled exception");
            // Program.Log("shutting down");
            // Application.Exit();
        }
示例#2
0
        public HttpRequest(HttpConnection connection)
        {
            this.encoding = Encoding.ASCII;
            this.parent = connection.Parent;

            this.ReadRequest(connection.Stream, connection.Socket);
        }
示例#3
0
        public HttpConnection(HttpServer parent, TcpClient socket)
        {
            this.Open = true;
            this.Socket = socket;
            this.Stream = socket.GetStream();

            this.Parent = parent;

            this.serviceRequestThread = new Thread(this.ServiceRequests);
            this.serviceRequestThread.IsBackground = true;
            this.serviceRequestThread.Start();

            timeout = new System.Timers.Timer();
            timeout.Interval = (MAX_TIME + 20) * 1000;
            timeout.Start();
            timeout.Elapsed += delegate { this.Open = false; };
        }
示例#4
0
        public HttpCache(HttpServer server)
        {
            this.cache = new Dictionary<string, HttpCachedFile>();
            this.server = server;

            // read all embedded resources
            foreach (var file in EmbeddedResource.GetAllResources())
            {
                var request = file.ToLower();
                cache.Add(request, new HttpCachedEmbeddedFile(file));
            }

            // read all files on root folder
            foreach (var file in IO.GetAllFiles(server.Root))
            {
                var request = file.Substring(server.Root.Length + 1).ToLower();
                cache.Add(request, new HttpCachedFile(file));
            }
        }
示例#5
0
 public static HttpContent Read(HttpServer server, string request)
 {
     return(Read(server, request, new Dictionary <string, HttpContent>()
     {
     }));
 }
示例#6
0
        public static HttpContent Read(HttpServer server, string request, Dictionary<string, HttpContent> baseContent)
        {
            request = request.TrimWhiteSpace().Replace(@"/", @"\").ToLower();
            string filePath = server.Root + @"\" + request;

            if (server.Cache.Contains(request))
            {
                return new HttpContent(server.Cache.Get(request), baseContent);
            }
            else if (File.Exists(filePath))
            {
                return new HttpContent(server.Cache.Get(filePath), baseContent);
            }
            else if (filePath.EndsWith("favicon.ico"))
            {
                return new HttpContent(server.Cache.Get("sar.http.libs.art.favicon.ico"), baseContent);
            }
            else
            {
                throw new FileNotFoundException("did not find " + filePath);
            }
        }
示例#7
0
 public static HttpContent Read(HttpServer server, string request)
 {
     return Read(server, request, new Dictionary<string, HttpContent>() {});
 }