// GET: Stream/Details/5 public async Task <ActionResult> Details(WhatsHappeningModel strInfo) { var context = GlobalHost.ConnectionManager.GetHubContext <StreamHub>(); //if (MvcApplication._subscriptions.ContainsKey(strInfo)) //{ // //uh we have it? //} //else //{ // var streamProv = await this._factory.GetStreamProviderAsync(strInfo.ProviderName); // var stream = streamProv.GetStream<object>(strInfo.StreamId, strInfo.NameSpace); // var streamHandle = await stream.SubscribeAsync((o, token) => // { // dynamic newDynamicObject = o; // //Console.ForegroundColor = ConsoleColor.Yellow; // //Console.Write($"[{DateTime.Now.ToString("yyyy-M-d HH:mm:ss.FF")}] "); // //Console.ForegroundColor = ConsoleColor.White; // //Console.WriteLine(newDynamicObject.ToString()); // //Console.WriteLine(o.ToString()); //var context = GlobalHost.ConnectionManager.GetHubContext<StreamHub>(); // context.Clients.All.UpdateData(strInfo, o.ToString()); // return TaskDone.Done; // }, exception => // { //var context = GlobalHost.ConnectionManager.GetHubContext<StreamHub>(); // context.Clients.All.UpdateData(strInfo, exception.ToString()); // //Console.WriteLine(exception); // return TaskDone.Done; // }, // () => TaskDone.Done); // MvcApplication._subscriptions.Add(strInfo, streamHandle); //} return(View(strInfo)); }
public async Task SubscribeToStream(string guid, string provider, string nameSpace) { WhatsHappeningModel strInfo = new WhatsHappeningModel() { StreamId = Guid.Parse(guid), ProviderName = provider, NameSpace = nameSpace }; var streamProv = await this._factory.GetStreamProviderAsync(strInfo.ProviderName); var stream = streamProv.GetStream <object>(strInfo.StreamId, strInfo.NameSpace); this.handles.Add(await stream.SubscribeAsync((o, token) => { dynamic newDynamicObject = o; //Console.ForegroundColor = ConsoleColor.Yellow; //Console.Write($"[{DateTime.Now.ToString("yyyy-M-d HH:mm:ss.FF")}] "); //Console.ForegroundColor = ConsoleColor.White; //Console.WriteLine(newDynamicObject.ToString()); //Console.WriteLine(o.ToString()); UpdateData(strInfo, o.ToString()); return(TaskDone.Done); }, exception => { UpdateData(strInfo, exception.ToString()); //Console.WriteLine(exception); return(TaskDone.Done); }, () => TaskDone.Done) ); }
public void UpdateData(WhatsHappeningModel streamInfo, string msg) { // Call the addNewMessageToPage method to update clients. Clients.All.addNewMessageToPage(streamInfo, msg); }
public void UpdateData(WhatsHappeningModel streamInfo, string msg) { // Call the addNewMessageToPage method to update clients. Clients.All.addNewMessageToPage($"{streamInfo.StreamId}-{streamInfo.ProviderName}-{streamInfo.NameSpace}", msg); }