示例#1
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);
        }
示例#2
0
        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);
        }