public void SendMessage(string to, string subject, string text, int tenantId) { if (string.IsNullOrEmpty(to) || string.IsNullOrEmpty(text)) { return; } var jid = GetJid(to, tenantId); text = ModifyJabberNotification(text); var message = new Message( jid, new Jid(GetTenantDomain(tenantId)), MessageType.chat, text, subject); var session = xmppServer.SessionManager.GetSession(jid); if (session != null) { var sender = (IXmppSender)xmppServer.GetService(typeof(IXmppSender)); sender.SendTo(session, message); } else { xmppServer.StorageManager.OfflineStorage.SaveOfflineMessages(message); } var archive = xmppServer.StorageManager.GetStorage <DbMessageArchive>("archive"); if (archive != null) { archive.SaveMessages(message); } }
protected override XElement ProcessRequest(XmppServer server, Jid jid, NameValueCollection values) { var to = values["to"]; var from = values["from"]; var command = values["command"]; if (string.IsNullOrEmpty(from) || string.IsNullOrEmpty(to) || string.IsNullOrEmpty(command)) { throw new ArgumentException("argument count mismatch"); } var jidTo = GetJid(to); var iq = new IQ(IqType.set, GetJid(from), jidTo) { Query = new Command(command) }; var session = server.SessionManager.GetSession(jidTo); if (session != null) { var sender = (IXmppSender)server.GetService(typeof(IXmppSender)); sender.SendTo(session, iq); } return(new XElement("ok")); }
protected override XElement ProcessRequest(XmppServer server, Jid jid, NameValueCollection values) { var to = values["to"]; var subject = values["subject"]; var text = values["message"]; if (!string.IsNullOrEmpty(to) && !string.IsNullOrEmpty(text)) { var jidTo = GetJid(to); text = ModifyJabberNotification(text); var message = new Message( jidTo, new Jid(CoreContext.TenantManager.GetCurrentTenant().TenantDomain), MessageType.headline, text, subject ?? "") { XDelay = new Delay() { Stamp = DateTime.UtcNow } }; var session = server.SessionManager.GetSession(jid); if (session != null) { var sender = (IXmppSender)server.GetService(typeof(IXmppSender)); sender.SendTo(session, message); } else { server.StorageManager.OfflineStorage.SaveOfflineMessages(message); } var archive = server.StorageManager.GetStorage <DbMessageArchive>("archive"); if (archive != null) { archive.SaveMessages(message); } } else { throw new ArgumentException("argument count mismatch"); } return(new XElement("ok")); }
public void SendMessage(int tenantId, string from, string to, string text, string subject) { try { _log.DebugFormat("Send Message: tenantId={0}, from={1}, to={2}, text={3}", tenantId, from, to, text); if (string.IsNullOrEmpty(text)) { return; } if (from == null) { signalrServiceClient.SendMessage(string.Empty, to.ToLowerInvariant(), text, tenantId, string.Empty); } var jidFrom = GetJid(from, tenantId); var jidTo = to != string.Empty ? GetJid(to, tenantId) : new Jid(jidFrom.Server); var message = new Message(jidTo, jidFrom, MessageType.chat, text); var sessions = _xmppServer.SessionManager.GetBareJidSessions(jidTo, GetSessionsType.All); if (sessions.Count != 0) { foreach (var session in sessions) { if (session != null && !session.IsSignalRFake) { ((IXmppSender)_xmppServer.GetService(typeof(IXmppSender))).SendTo(session, message); } } } else { _xmppServer.StorageManager.OfflineStorage.SaveOfflineMessages(message); } var handlers = _xmppServer.HandlerManager.HandlerStorage.GetStanzaHandlers(jidFrom, typeof(Message)); if (handlers.Count > 1) { var messageArchiveHandler = handlers[1] as MessageArchiveHandler; if (messageArchiveHandler != null) { messageArchiveHandler.HandleMessage(null, message, null); } } else { var messageArchiveHandler = new MessageArchiveHandler(); messageArchiveHandler.HandleMessage(null, message, null); messageArchiveHandler.FlushMessageBuffer(); } } catch (Exception e) { _log.Error(e); } }
public void Close() { _log.DebugFormat("Close connection {0}.", Id); ((SignalRXmppListener)((XmppGateway)_xmppServer.GetService(typeof(IXmppReceiver))).GetXmppListener("SignalR Listener")).CloseXmppConnection(Id); }