Ejemplo n.º 1
0
        //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));
            });
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        // GET: Settings
        public ActionResult Settings()
        {
            XMPPSettings xMPPSettings = XMPPConfig.ReadSettings();

            var result = new XMPPSettingsViewModel
            {
                server          = xMPPSettings.Server,
                domain          = xMPPSettings.Domain,
                port            = xMPPSettings.Port,
                autoReconnect   = xMPPSettings.AutoReconnect,
                enable          = xMPPSettings.Enable,
                user            = xMPPSettings.User,
                password        = xMPPSettings.Password,
                messageTemplate = xMPPSettings.MessageTemplate,
                isConnected     = sender.IsConnected()
            };

            return(PartialView(result));
        }
Ejemplo n.º 4
0
        public JsonResult SendNotificationXMPP(NotificationViewModel _notification)
        {
            //recipients
            IEnumerable <long> recipients = Enumerable.Empty <long>();

            _notification.sendto.Where(s => s < 0).ToList().ForEach(o =>
            {
                GetAllChilds(o, ref recipients);
            });

            _notification.sendto = _notification.sendto.Where(s => s > 0).Concat(recipients.Where(r => r > 0)).Distinct();


            if (_notification.sendto.Count() > 0)
            {
                try
                {
                    XMPPSettings xMPPSettings = XMPPConfig.ReadSettings();
                    if (xMPPSettings.Enable)
                    {
                        xMPPSettings.MessageTemplate = "{notification.content}";
                        SendNotificationOut(_notification, xMPPSettings);
                    }
                    else
                    {
                        return(Json(new { message = "errors", errors = "Ошибка: Сервис рассылки отключен!" }, JsonRequestBehavior.AllowGet));
                    }

                    return(Json(new { message = "OK", result = _notification }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception exc)
                {
                    return(Json(new { message = "errors", errors = "Ошибка: " + exc.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { message = "errors", errors = "Ошибка: Не найден ни один получатель!" }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        public JsonResult CreateNotification(NotificationViewModel _notification)
        {
            //TODO
            var author = _notification.author == null ? ((CustomPrincipal)User).UserID : _notification.author.id;// employeeRepository.GetEmployee( User.Identity.Name.Split('\\')[1]).ID;

            var entity = new Notifications.Domain.Entities.Notification();

            //author
            _notification.author = ConvertToViewModel(employeeRepository.GetEmployee(author));

            _notification.title = string.IsNullOrEmpty(_notification.title) ? _notification.author.fullname : _notification.title;

            //recipients
            IEnumerable <long> recipients = Enumerable.Empty <long>();

            _notification.sendto.Where(s => s < 0).ToList().ForEach(o =>
            {
                GetAllChilds(o, ref recipients);
            });

            _notification.sendto = _notification.sendto.Where(s => s > 0).Concat(recipients.Where(r => r > 0)).Distinct();
            if (_notification.sendto.Count() > 0)
            {
                _notification.ToEntity(entity);
                try
                {
                    notificationRepository.CreateNotification(entity);

                    _notification.id       = entity.ID;
                    _notification.content  = entity.Content;
                    _notification.datetime = entity.DateTime;
                    _notification.priority = ConvertToViewModel(notificationRepository.Priorities.FirstOrDefault(p => p.ID == entity.PriorityID));

                    _notification.employeenotification = ConvertToViewModel(entity.EmployeesNotifications.FirstOrDefault());

                    //New Notification
                    displayNewNotification(_notification);

                    //Create success Notification
                    displayAddNotification(_notification);

                    //Out Send
                    try
                    {
                        XMPPSettings xMPPSettings = XMPPConfig.ReadSettings();
                        if (xMPPSettings.Enable)
                        {
                            SendNotificationOut(_notification, xMPPSettings);
                        }
                    }
                    catch { } /*(Exception exc)
                               * {
                               * return Json(new { message = "errors", errors = "Ошибка: " + exc.Message }, JsonRequestBehavior.AllowGet);
                               * }*/

                    return(Json(new { message = "OK", result = _notification }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception exc)
                {
                    return(Json(new { message = "errors", errors = "Ошибка: " + exc.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { message = "errors", errors = "Ошибка: Не найден ни один получатель!" }, JsonRequestBehavior.AllowGet));
            }
        }