public override void GetFullState() { try { List <SIPAccount> sipAccounts = null; if (ResourceURI.User == m_wildcardUser) { //sipAccounts = m_sipAccountPersistor.Get(s => s.Owner == SubscriptionDialogue.Owner, "SIPUsername", 0, MAX_SIPACCOUNTS_TO_RETRIEVE); sipAccounts = GetSIPAccountsForOwner_External(SubscriptionDialogue.Owner, 0, MAX_SIPACCOUNTS_TO_RETRIEVE); } else { //sipAccounts = m_sipAccountPersistor.Get(s => s.SIPUsername == CanonicalResourceURI.User && s.SIPDomain == CanonicalResourceURI.Host, "SIPUsername", 0, MAX_SIPACCOUNTS_TO_RETRIEVE); sipAccounts = GetSIPAccountsForUser_External(CanonicalResourceURI.User, CanonicalResourceURI.Host, 0, MAX_SIPACCOUNTS_TO_RETRIEVE); } foreach (SIPAccount sipAccount in sipAccounts) { SIPURI aor = SIPURI.ParseSIPURIRelaxed(sipAccount.SIPUsername + "@" + sipAccount.SIPDomain); int bindingsCount = GetSIPRegistrarBindingsCount_External(sipAccount.Id); if (bindingsCount > 0) { string safeSIPAccountID = sipAccount.Id.ToString(); Presence.Tuples.Add(new SIPEventPresenceTuple(safeSIPAccountID, SIPEventPresenceStateEnum.open, aor, Decimal.Zero, sipAccount.AvatarURL)); //logger.Debug(" full presence " + aor.ToString() + " open."); } else { string safeSIPAccountID = sipAccount.Id.ToString(); Presence.Tuples.Add(new SIPEventPresenceTuple(safeSIPAccountID, SIPEventPresenceStateEnum.closed, null, Decimal.Zero, sipAccount.AvatarURL)); //logger.Debug(" full presence " + aor.ToString() + " closed."); } } MonitorLogEvent_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Notifier, SIPMonitorEventTypesEnum.NotifySent, "Full state notification for presence and " + ResourceURI.ToString() + ".", SubscriptionDialogue.Owner)); } catch (Exception excp) { logger.Error("Exception SIPPresenceEventSubscription GetFullState. " + excp.Message); } }
public override bool AddMonitorEvent(SIPMonitorMachineEvent machineEvent) { try { lock (DialogInfo) { MonitorLogEvent_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Notifier, SIPMonitorEventTypesEnum.Monitor, "Monitor event " + machineEvent.MachineEventType + " dialog " + ResourceURI.ToString() + " (ID " + machineEvent.ResourceID + ").", SubscriptionDialogue.Owner)); string state = GetStateForEventType(machineEvent.MachineEventType); if (machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPDialogueRemoved) { DialogInfo.DialogItems.Add(new SIPEventDialog(machineEvent.ResourceID, state, null)); return(true); } else { SIPDialogue sipDialogue = GetDialogue_External(new Guid(machineEvent.ResourceID)); if (sipDialogue == null) { // Couldn't find the dialogue in the database so it must be terminated. DialogInfo.DialogItems.Add(new SIPEventDialog(machineEvent.ResourceID, "terminated", null)); return(true); } else if (machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPDialogueTransfer) { // For dialog transfer events add both dialogs involved to the notification. DialogInfo.DialogItems.Add(new SIPEventDialog(sipDialogue.Id.ToString(), state, sipDialogue)); if (sipDialogue.BridgeId != Guid.Empty) { //SIPDialogue bridgedDialogue = GetDialogues_External(d => d.BridgeId == sipDialogue.BridgeId && d.Id != sipDialogue.Id, null, 0, 1).FirstOrDefault(); SIPDialogue bridgedDialogue = GetRemoteDialogueForBridge_External(sipDialogue.BridgeId, sipDialogue.Id); if (bridgedDialogue != null) { DialogInfo.DialogItems.Add(new SIPEventDialog(bridgedDialogue.Id.ToString(), state, bridgedDialogue)); } } return(true); } else { DialogInfo.DialogItems.Add(new SIPEventDialog(sipDialogue.Id.ToString(), state, sipDialogue)); return(true); } } } } catch (Exception excp) { MonitorLogEvent_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Notifier, SIPMonitorEventTypesEnum.Monitor, "Exception AddMonitorEvent. " + excp.Message, null)); logger.Error("Exception SIPDialogEventSubscription AddMonitorEvent. " + excp.Message); throw; } }
/// <summary> /// Checks and where required adds a presence related monitor event to the list of pending notifications. /// </summary> /// <param name="machineEvent">The monitor event that has been received.</param> /// <returns>True if a notification needs to be sent as a result of this monitor event, false otherwise.</returns> public override bool AddMonitorEvent(SIPMonitorMachineEvent machineEvent) { try { MonitorLogEvent_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Notifier, SIPMonitorEventTypesEnum.Monitor, "Monitor event " + machineEvent.MachineEventType + " presence " + machineEvent.ResourceURI.ToString() + " for subscription to " + ResourceURI.ToString() + ".", SubscriptionDialogue.Owner)); string safeSIPAccountID = machineEvent.ResourceID; SIPURI sipAccountURI = machineEvent.ResourceURI; bool sendNotificationForEvent = true; string avatarURL = null; if (m_switchboardSIPAccountsOnly) { // Need to check whether the SIP account is switchboard enabled before forwarding the notification. Guid sipAccountID = new Guid(machineEvent.ResourceID); //sendNotificationForEvent = Convert.ToBoolean(m_sipAccountPersistor.GetProperty(sipAccountID, "IsSwitchboardEnabled")); sendNotificationForEvent = Convert.ToBoolean(GetSipAccountProperty_External(sipAccountID, "IsSwitchboardEnabled")); if (sendNotificationForEvent) { //avatarURL = m_sipAccountPersistor.GetProperty(sipAccountID, "AvatarURL") as string; avatarURL = GetSipAccountProperty_External(sipAccountID, "AvatarURL") as string; } } if (sendNotificationForEvent) { if (machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPRegistrarBindingUpdate) { // A binding has been updated so there is at least one device online for the SIP account. Presence.Tuples.Add(new SIPEventPresenceTuple(safeSIPAccountID, SIPEventPresenceStateEnum.open, sipAccountURI, Decimal.Zero, avatarURL)); //logger.Debug(" single presence open."); } else { // A binding has been removed but there could still be others. Guid sipAccountID = new Guid(machineEvent.ResourceID); int bindingsCount = GetSIPRegistrarBindingsCount_External(sipAccountID); if (bindingsCount > 0) { Presence.Tuples.Add(new SIPEventPresenceTuple(safeSIPAccountID, SIPEventPresenceStateEnum.open, sipAccountURI, Decimal.Zero, avatarURL)); } else { Presence.Tuples.Add(new SIPEventPresenceTuple(safeSIPAccountID, SIPEventPresenceStateEnum.closed, sipAccountURI, Decimal.Zero, avatarURL)); } } return(true); } else { return(false); } } catch (Exception excp) { logger.Error("Exception SIPresenceEventSubscription AddMonitorEvent. " + excp.Message); throw; } }
public override void GetFullState() { try { DialogInfo.State = SIPEventDialogInfoStateEnum.full; List <SIPDialogue> dialogues = GetDialoguesForOwner_External(SubscriptionDialogue.Owner, 0, MAX_DIALOGUES_FOR_NOTIFY); foreach (SIPDialogue dialogue in dialogues) { DialogInfo.DialogItems.Add(new SIPEventDialog(dialogue.Id.ToString(), "confirmed", dialogue)); } MonitorLogEvent_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Notifier, SIPMonitorEventTypesEnum.NotifySent, "Full state notification for dialog and " + ResourceURI.ToString() + ".", SubscriptionDialogue.Owner)); } catch (Exception excp) { logger.Error("Exception SIPDialogEventSubscription GetFullState. " + excp.Message); } }