protected override Task <CompilationUnitSyntax> GenerateCompilationUnit(Document sourceDocument) { if (TargetFrameworkName == null) { throw new CodeGeneratorException($"Unable to determine the Target Framework for the project."); } return(EventSourceGenerator.GenerateEventSourceImplementations(sourceDocument, TargetFrameworkName)); }
public /* will not be part of web service itself */ void SensorySync_Handler(WebServiceHandler h) { // X:\jsc.svn\examples\javascript\ServerSideEventExperiment\ServerSideEventExperiment\ApplicationWebService.cs var Accepts = h.Context.Request.Headers["Accept"]; if (Accepts != null) { if (Accepts.Contains(EventSourceGenerator.ContentType)) { var s = new EventSourceGenerator(h); // lets start talking to db new SensorySync().With( SensorySync => { if (s.id == 0) { // ah. first time. // lets ask the database then. var last_ms = SensorySync.Last(); if (last_ms > 0) { s.id = last_ms; // well the database gave as the last id. // for the client // ther will be no data until new events tho } else { // well the client doesnt know // and the database is empty. // tell the client to come back at a later time s.retry = 1000; h.CompleteRequest(); return; } } s.retry = 1000 / 20; var DoNextFrame = true; var RetryCount = 60; Action AtFrame = delegate { // wait for next frame DoNextFrame = false; Thread.Sleep(s.retry); SensorySync.Sum(s.id, reader => { // can we use dynamic xelement here instead? long last_ms = reader.ms, x = reader.x, y = reader.y, goleft = reader.goleft, goup = reader.goup, goright = reader.goright, godown = reader.godown; if (last_ms > 0) { s["status"]("found input!"); var data = new XElement("yield", // can xattribute support long? new XAttribute("last_ms", "" + last_ms), new XAttribute("x", "" + x), new XAttribute("y", "" + y), new XAttribute("goleft", "" + goleft), new XAttribute("goup", "" + goup), new XAttribute("goright", "" + goright), new XAttribute("godown", "" + godown) ); DoNextFrame = true; s.id = last_ms; s.postMessage(data); } else { s["status"]("waiting for new input..."); if (RetryCount > 0) { RetryCount--; DoNextFrame = true; } // try again at the next frame? } } ); }; while (DoNextFrame) { AtFrame(); } //Thread.Sleep(1000); h.CompleteRequest(); } ); return; } } }