public void StartHandler(string IdUser) { serviceBusManager = new ServiceBusManager(); try { TimeSpan RenewTimeout = TimeSpan.FromSeconds(1); OnMessageOptions options = new OnMessageOptions { AutoComplete = false, MaxConcurrentCalls = 1, AutoRenewTimeout = RenewTimeout }; serviceBusManager.GetClient().OnMessageAsync(async brokerMessage => { try { if (brokerMessage.SessionId == (IdUser)) { var message = brokerMessage.GetBody <Stream>(); serviceBusManager.Message = JsonConvert.DeserializeObject <KindAds.Common.Models.Notification>(new StreamReader(message, true).ReadToEnd()); notification = serviceBusManager.Message; await brokerMessage.CompleteAsync(); serviceBusManager.Close(); //Send to client SendNotification(notification.Title, notification.Message); } } catch (Exception e) { brokerMessage.Abandon(); } }, options); } catch (Exception e) { var messageException = telemetry.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetry.Critical(messageException); } }
public void StartHandlerConversation(string IdUser) { string serviceBusTopicName = "conversationtopicdev"; //Obtenerlo del web.config serviceBusManager = new ServiceBusManager(serviceBusTopicName); try { TimeSpan RenewTimeout = TimeSpan.FromSeconds(1); OnMessageOptions options = new OnMessageOptions { AutoComplete = false, MaxConcurrentCalls = 1, AutoRenewTimeout = RenewTimeout }; // Create the Observable var collection = new ObservableCollection <string>(); IObservable <BrokeredMessage> notifications = Observable.Create <BrokeredMessage>( observer => { serviceBusManager.GetClient().OnMessage(observer.OnNext, options); return(Disposable.Empty); }).Publish().RefCount(); // Filtro para CampaignValidation IDisposable porposalMessage = notifications.Where( brokerMessage => { return(brokerMessage.Label == NotificationLabels.ConversationMessage); }).Subscribe( x => //OnNext { //split sessionIds var authorizeUsers = x.SessionId.Split('|'); try { if (authorizeUsers[0] == IdUser || authorizeUsers[1] == IdUser) { var message = x.GetBody <Stream>(); serviceBusManager.Message = JsonConvert.DeserializeObject <ConversationMessageNotification>(new StreamReader(message, true).ReadToEnd()); conversationNotification = serviceBusManager.Message; x.CompleteAsync(); serviceBusManager.Close(); //Send to client SendChatMessage(conversationNotification); } } catch (Exception e) { x.Abandon(); } }, x => Console.WriteLine(x.Message), //OnError () => Console.WriteLine("Complete")); //OnComplete } catch (Exception e) { var messageException = telemetry.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetry.Critical(messageException); } }
public void StartHandlerProposal(string IdUser) { serviceBusManager = new ServiceBusManager("proposaltopicdev"); try { TimeSpan RenewTimeout = TimeSpan.FromSeconds(1); OnMessageOptions options = new OnMessageOptions { AutoComplete = false, MaxConcurrentCalls = 1, AutoRenewTimeout = RenewTimeout }; // Create the Observable var collection = new ObservableCollection <string>(); IObservable <BrokeredMessage> notifications = Observable.Create <BrokeredMessage>( observer => { serviceBusManager.GetClient().OnMessage(observer.OnNext, new OnMessageOptions()); return(Disposable.Empty); }).Publish().RefCount(); // Filtro para CampaignValidation IDisposable porposalMessage = notifications.Where( brokerMessage => { return(brokerMessage.SessionId == (IdUser) && brokerMessage.Label == NotificationLabels.Proposal); }).Subscribe( x => //OnNext { try { if (x.SessionId == (IdUser)) { var message = x.GetBody <Stream>(); serviceBusManager.Message = JsonConvert.DeserializeObject <ProposalNotification>(new StreamReader(message, true).ReadToEnd()); var notification = serviceBusManager.Message; x.CompleteAsync(); serviceBusManager.Close(); //Send to client SendNotification(notification.message, notification.message); } } catch (Exception e) { x.Abandon(); } }, x => Console.WriteLine(x.Message), //OnError () => Console.WriteLine("Complete")); //OnComplete } catch (Exception e) { var messageException = telemetry.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetry.Critical(messageException); } }