//Send XMPP message private void SendNotificationOut(NotificationViewModel notification, XMPPSettings xMPPSettings) { IXMPPClient sender = NinjectIoC.Initialize().Get <IXMPPClient>(); string[] xmppRecipients = notification.sendto.Select(s => sender.GetUserName(employeeRepository.GetEmployee(s).Login, xMPPSettings.Domain)).ToArray <string>(); if (!sender.IsConnected()) { sender.Connect(xMPPSettings.Server, xMPPSettings.Port, xMPPSettings.User, xMPPSettings.Password, xMPPSettings.AutoReconnect); Thread.Sleep(1000); } Task.Run(() => { sender.SendNotification(xmppRecipients, FullTemplate(notification, xMPPSettings.MessageTemplate)); }); }
public JsonResult SaveSettings(XMPPSettingsViewModel settings) { XMPPSettings xMPPSettings = new XMPPSettings(); xMPPSettings.Server = settings.server; xMPPSettings.Domain = settings.domain; xMPPSettings.Port = settings.port; xMPPSettings.AutoReconnect = settings.autoReconnect; xMPPSettings.Enable = settings.enable; xMPPSettings.User = settings.user; xMPPSettings.Password = settings.password; xMPPSettings.MessageTemplate = settings.messageTemplate; //Save try { XMPPConfig.SaveSettings(xMPPSettings); } catch (Exception exception) { return(Json(new { message = "errors", errors = "Ошибка: " + exception.Message }, JsonRequestBehavior.AllowGet)); } //Reconnect try { sender.Close(); if (settings.enable) { sender.Connect(settings.server, settings.port, settings.user, settings.password, settings.autoReconnect); Thread.Sleep(1000); } settings.isConnected = sender.IsConnected(); } catch (Exception exception) { return(Json(new { message = "errors", errors = "Ошибка: " + exception.Message }, JsonRequestBehavior.AllowGet)); } return(Json(new { message = "OK", result = settings }, JsonRequestBehavior.AllowGet)); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //Ninject ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()); GlobalHost.DependencyResolver = new NinjectSignalRDependencyResolver(NinjectIoC.Initialize()); //XMPP XMPPSettings xMPPSettings = XMPPConfig.ReadSettings(); if (xMPPSettings.Enable) { IXMPPClient sender = NinjectIoC.Initialize().Get <IXMPPClient>(); sender.Connect(xMPPSettings.Server, xMPPSettings.Port, xMPPSettings.User, xMPPSettings.Password, xMPPSettings.AutoReconnect); } }