Guest User

Untitled

a guest
Sep 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public class MyHub : Hub
  2. {
  3. public override Task OnConnectedAsync()
  4. {
  5. Observable.Interval(TimeSpan.FromSeconds(0.5)).Subscribe(l =>
  6. {
  7. var alt = CalcAltitude(l);
  8. SendMessage(alt);
  9. });
  10.  
  11. return Task.CompletedTask;
  12. }
  13.  
  14. private void SendMessage(double alt)
  15. {
  16. Clients.All.SendAsync("SendAction", new Status() {Altitude = alt});
  17. }
  18.  
  19. private double CalcAltitude(long l)
  20. {
  21. return 100 * Math.Sin((double) l / 100) + 200;
  22. }
  23. }
  24.  
  25. public class Status
  26. {
  27. public double Altitude { get; set; }
  28. }
  29.  
  30. var hubContext = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
  31. hubContext.Clients.All.SendnewData(Data);
Add Comment
Please, Sign In to add comment