コード例 #1
0
        public bool Start()
        {
            httpdispatcher = new HTTPDispatcher();
            httpdispatcher.RootNodeTranslation = "/index.html";

            // Serve ICONS from path - order is important
            iconnodes = new EDDIconNodes();
            httpdispatcher.AddPartialPathNode("/journalicons/", iconnodes);    // journal icons come from this dynamic source
            httpdispatcher.AddPartialPathNode("/statusicons/", iconnodes);     // status icons come from this dynamic source

            // Serve files from path
            mainwebsitefiles    = new HTTPFileNode(@"c:\code\html\ASPWEB2\ASPWEB2");
            mainwebsitezipfiles = new HTTPZipNode(@"c:\code\html\ASPWEB2\ASPWEB2\Website.zip");

            // pick one - the zipper or the file server
            httpdispatcher.AddPartialPathNode("/", mainwebsitefiles);
            //httpdispatcher.AddPartialPathNode("/", mainwebsitezipfiles);

            // HTTP server
            //httpws = new Server("http://localhost:8080/");
            httpws           = new Server("http://127.0.0.1:8080/");
            httpws.ServerLog = (s) => { LogIt?.Invoke(s); };

            // add to the server a HTTP responser
            httpws.AddHTTPResponder((lr, lrdata) => { return(httpdispatcher.Response(lr)); }, httpdispatcher);

            // JSON dispatcher..
            jsondispatch = new JSONDispatcher();
            eddif        = new EDDInterface();
            jsondispatch.Add("journal", eddif.jr);          // event journal
            jsondispatch.Add("status", eddif.status);       // event status
            jsondispatch.Add("indicator", eddif.indicator); // indicator
            eddif.presskey.ireq   = eddif.indicator;
            eddif.presskey.httpws = httpws;
            jsondispatch.Add("presskey", eddif.presskey);   // and a key press

            // add for protocol EDDJSON the responder.

            httpws.AddWebSocketsResponder("EDDJSON",
                                          (ctx, ws, wsrr, buf, lrdata) => { jsondispatch.Response(ctx, ws, wsrr, buf, lrdata); },
                                          jsondispatch);

            httpws.Run();

            return(true);
        }
コード例 #2
0
        public bool Start(string servefrom)       // null if okay
        {
            // HTTP server
            httpws           = new Server("http://*:" + port.ToStringInvariant() + "/");
            httpws.ServerLog = (s) => { LogIt?.Invoke(s); };

            httpdispatcher = new HTTPDispatcher();
            httpdispatcher.RootNodeTranslation = "/index.html";

            // Serve ICONS from path - order is important - first gets first dibs at the path
            iconnodes = new EDDIconNodes();
            httpdispatcher.AddPartialPathNode("/journalicons/", iconnodes);    // journal icons come from this dynamic source
            httpdispatcher.AddPartialPathNode("/statusicons/", iconnodes);     // status icons come from this dynamic source
            httpdispatcher.AddPartialPathNode("/images/", iconnodes);          // give full eddicons path

            // scan display
            scandisplay = new EDDScanDisplay(discoveryform, httpws);
            httpdispatcher.AddPartialPathNode("/systemmap/", scandisplay);  // serve a display of this system

            if (servefrom.Contains(".zip"))                                 // fall back, none of the above matching
            {
                mainwebsitezipfiles = new HTTPZipNode(servefrom);
                httpdispatcher.AddPartialPathNode("/", mainwebsitezipfiles);
            }
            else
            {
                mainwebsitefiles = new HTTPFileNode(servefrom);
                httpdispatcher.AddPartialPathNode("/", mainwebsitefiles);
            }

            // add to the server a HTTP responser
            httpws.AddHTTPResponder((lr, lrdata) => { return(httpdispatcher.Response(lr)); }, httpdispatcher);

            // JSON dispatcher..
            jsondispatch = new JSONDispatcher();

            journalsender = new JournalRequest(discoveryform);
            jsondispatch.Add("journal", journalsender);      // event journal

            statussender = new StatusRequest(discoveryform);
            jsondispatch.Add("status", statussender);   // event status

            indicator = new IndicatorRequest();
            jsondispatch.Add("indicator", indicator);   // indicator query

            scandata = new ScanDataRequest(discoveryform);
            jsondispatch.Add("scandata", scandata);   // scan data

            presskey = new PressKeyRequest(discoveryform);
            jsondispatch.Add("presskey", presskey);   // and a key press

            missions = new MissionRequest(discoveryform);
            jsondispatch.Add("missions", missions);   // mission list

            texts = new TextsRequest(discoveryform);
            jsondispatch.Add("texts", texts);   // mission list

            // add for protocol EDDJSON the responder.

            httpws.AddWebSocketsResponder("EDDJSON",
                                          (ctx, ws, wsrr, buf, lrdata) => { jsondispatch.Response(ctx, ws, wsrr, buf, lrdata); },
                                          jsondispatch);

            bool ok = httpws.Run();

            if (ok)
            {
                discoveryform.OnHistoryChange += Discoveryform_OnHistoryChange;
                discoveryform.OnNewUIEvent    += Discoveryform_OnNewUIEvent;
                discoveryform.OnNewEntry      += Discoveryform_OnNewEntry;
            }
            else
            {
                httpws = null;
            }

            return(ok);
        }
コード例 #3
0
ファイル: WebServer.cs プロジェクト: Stumpii/EDDiscovery
        public bool Start(string servefrom)       // null if okay
        {
            httpdispatcher = new HTTPDispatcher();
            httpdispatcher.RootNodeTranslation = "/index.html";

            // Serve ICONS from path - order is important
            iconnodes = new EDDIconNodes();
            httpdispatcher.AddPartialPathNode("/journalicons/", iconnodes);    // journal icons come from this dynamic source
            httpdispatcher.AddPartialPathNode("/statusicons/", iconnodes);     // status icons come from this dynamic source

            if (servefrom.Contains(".zip"))
            {
                mainwebsitezipfiles = new HTTPZipNode(servefrom);
                httpdispatcher.AddPartialPathNode("/", mainwebsitezipfiles);
            }
            else
            {
                mainwebsitefiles = new HTTPFileNode(servefrom);
                httpdispatcher.AddPartialPathNode("/", mainwebsitefiles);
            }

            // HTTP server
            httpws           = new Server("http://*:" + port.ToStringInvariant() + "/");
            httpws.ServerLog = (s) => { LogIt?.Invoke(s); };

            // add to the server a HTTP responser
            httpws.AddHTTPResponder((lr, lrdata) => { return(httpdispatcher.Response(lr)); }, httpdispatcher);

            // JSON dispatcher..
            jsondispatch = new JSONDispatcher();

            journalsender = new JournalRequest(discoveryform);
            jsondispatch.Add("journal", journalsender);      // event journal

            statussender = new StatusRequest(discoveryform);
            jsondispatch.Add("status", statussender);   // event status

            indicator = new IndicatorRequest();
            jsondispatch.Add("indicator", indicator);   // indicator query

            presskey = new PressKeyRequest(discoveryform);
            jsondispatch.Add("presskey", presskey);   // and a key press

            // add for protocol EDDJSON the responder.

            httpws.AddWebSocketsResponder("EDDJSON",
                                          (ctx, ws, wsrr, buf, lrdata) => { jsondispatch.Response(ctx, ws, wsrr, buf, lrdata); },
                                          jsondispatch);

            bool ok = httpws.Run();

            if (ok)
            {
                discoveryform.OnHistoryChange += Discoveryform_OnHistoryChange;
                discoveryform.OnNewUIEvent    += Discoveryform_OnNewUIEvent;
                discoveryform.OnNewEntry      += Discoveryform_OnNewEntry;
            }
            else
            {
                httpws = null;
            }

            return(ok);
        }