private void SendResultsToSubscribers(List <EmailMiner.MiningResult> results,
                                              Dictionary <Guid, List <Guid> > subscribers)
        {
            if (subscribers == null || results == null)
            {
                return;
            }
            var channelManager = ChannelManager;

            if (channelManager == null)
            {
                _log.Warn("Message channel manager is not running. Results won't be sent");
                return;
            }
            foreach (KeyValuePair <Guid, List <Guid> > valuePair in subscribers)
            {
                Guid        subscriberId = valuePair.Key;
                IMsgChannel channel      = channelManager.FindItemByUId(subscriberId);
                if (channel == null)
                {
                    continue;
                }
                List <Guid> activityIds = valuePair.Value;
                List <EmailMiner.MiningResult> subscriberResults = results
                                                                   .Where(result => activityIds.Contains(result.ActivityId))
                                                                   .ToList();
                var simpleMessage = new SimpleMessage {
                    Body = JsonConvert.SerializeObject(subscriberResults),
                    Id   = channel.Id
                };
                simpleMessage.Header.BodyTypeName = MessageBodyTypeName;
                simpleMessage.Header.Sender       = MessageSender;
                channel.PostMessage(simpleMessage);
            }
        }
        public virtual bool GetRemindingCountersScriptTaskExecute(ProcessExecutingContext context)
        {
            var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "SysAdminUnit");
            EntitySchemaQueryColumn primaryColumn = esq.AddColumn(esq.RootSchema.GetPrimaryColumnName());

            esq.AddColumn("Contact");
            esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                           "Name", UserConnection.CurrentUser.Name));
            EntityCollection entities = esq.GetEntityCollection(UserConnection);

            if (entities.Count > 0)
            {
                Guid        sysAdminUnitId = entities[0].GetTypedColumnValue <Guid>(primaryColumn.Name);
                IMsgChannel channel        = MsgChannelManager.IsRunning
                                                                        ? MsgChannelManager.Instance.FindItemByUId(sysAdminUnitId)
                                                                        : null;
                if (channel == null)
                {
                    return(true);
                }
                RemindingsHelper remindingsHelper = new RemindingsHelper(UserConnection);
                string           formattedDate    = DateTime.UtcNow.ToString("o");
                string           messageBody      = remindingsHelper.GetRemindingsCountResponse(sysAdminUnitId, formattedDate);
                var simpleMessage = new SimpleMessage {
                    Id   = sysAdminUnitId,
                    Body = messageBody
                };
                simpleMessage.Header.Sender = "GetRemindingCounters";
                channel.PostMessage(simpleMessage);
            }
            return(true);
        }
        protected override bool InternalExecute(ProcessExecutingContext context)
        {
            MsgChannelManager channelManager = MsgChannelManager.Instance;

            if (!SendForAll)
            {
                List <Guid> targetIds = UserConnection.SessionData[TargetUserIdsKey] as List <Guid>;
                if (targetIds != null)
                {
                    foreach (Guid id in targetIds)
                    {
                        IMsgChannel userChannel = channelManager.FindItemByUId(id);
                        PostMsgText(userChannel);
                    }
                }
            }
            else
            {
                foreach (IMsgChannel userChannel in channelManager.Channels.Values)
                {
                    PostMsgText(userChannel);
                }
            }
            return(true);
        }
示例#4
0
 /// <summary>
 /// Creates instance of type <see cref="ImportNotifier"/>.
 /// </summary>
 /// <param name="userConnection">User connection.</param>
 /// <param name="importParameters">Import parameters.</param>
 public ImportNotifier(UserConnection userConnection, ImportParameters importParameters)
 {
     UserConnection   = userConnection;
     ImportParameters = importParameters;
     _channel         = MsgChannelManager.Instance.FindItemByUId(UserConnection.CurrentUser.Id);
     if (_channel != null)
     {
         _channel.OnMessage += ImportMsgHandler;
     }
 }
        public virtual void PostMsgText(IMsgChannel userChannel)
        {
            IMsg msg = new SimpleMessage()
            {
                Id   = new Guid(),
                Body = MessageText
            };

            msg.Header.Sender = SenderName;
            userChannel.PostMessage(msg);
        }
        private void SendMessage(Guid sysAdminUnitId, NotificationInfoResponse messageBody)
        {
            IMsgChannel channel = GetSysAdminUnitChannel(sysAdminUnitId);

            if (channel == null)
            {
                return;
            }
            IMsg message = GetChannelMessage(sysAdminUnitId, messageBody);

            channel.PostMessage(message);
        }
示例#7
0
        private static void PostMessageInternal(IMsgChannel channel, string sender, string msg)
        {
            IMsg simpleMessage = new SimpleMessage()
            {
                Id   = Guid.NewGuid(),
                Body = msg
            };

            simpleMessage.Header.Sender = sender;
            _log.Debug($"Channel {channel.Name} post for {sender} msg: {msg}");
            channel.PostMessage(simpleMessage);
        }
        private static void PostMessageInternal(IMsgChannel channel, string sender, string msg)
        {
            IMsg simpleMessage = new SimpleMessage()
            {
                Id   = new Guid(),
                Body = msg
            };

            simpleMessage.Header.Sender = sender;
            _log.Debug(string.Format("Channel {0} post for {1} msg: {2}", channel.Name, sender, msg));
            channel.PostMessage(simpleMessage);
        }
示例#9
0
        /// <summary>
        /// Import message handler.
        /// </summary>
        /// <param name="sender">Message sender.</param>
        /// <param name="args">Event arguments.</param>
        public void ImportMsgHandler(IMsgChannel sender, IMsg args)
        {
            if (args == null || args.Header.Sender != TagImportMessageHeader || args.Body == null)
            {
                return;
            }
            SimpleMessage message = new SimpleMessage {
                Body = args.Body
            };

            message.Header.Sender = TagImportMessageHeader;
            _channel.PostMessage(message);
        }
        private void SendNotification(
            IMsgChannel channel,
            FileConversionTask fileConversionTask,
            UserReportGenerationTask reportGenerationTask)
        {
            var simpleMessage = new SimpleMessage {
                Id   = Guid.NewGuid(),
                Body = GetNotificationBody(fileConversionTask, reportGenerationTask),
            };

            simpleMessage.Header.Sender = NotifySender;
            channel.PostMessage(simpleMessage);
        }
        /// <summary>
        /// Posts a message.
        /// </summary>
        /// <param name="contactId">Identifier of the contact.</param>
        /// <param name="messageBuilder">Message builder.</param>
        public void PostMessage(Guid contactId, INotificationMessageBuilder messageBuilder)
        {
            messageBuilder.CheckArgumentNull("messageBuilder");
            Guid adminUnitId = FindSysAdminUnitId(contactId);

            messageBuilder.SysAdminUnitId = adminUnitId;
            IMsg        message = messageBuilder.Build();
            IMsgChannel channel = _channelManager.FindItemByUId(adminUnitId);

            if (channel != null)
            {
                channel.PostMessage(message);
            }
        }
 /// <summary>
 /// Sends notification message for user.
 /// </summary>
 private void SendSocketMessage(UserConnection userConnection)
 {
     try {
         var         sysAdminUnitId = userConnection.CurrentUser.Id;
         IMsgChannel channel        = MsgChannelManager.Instance.FindItemByUId(sysAdminUnitId);
         if (channel == null)
         {
             return;
         }
         var simpleMessage = new SimpleMessage {
             Id   = sysAdminUnitId,
             Body = string.Empty
         };
         simpleMessage.Header.Sender = "UpdateSectionInWorkplace";
         channel.PostMessage(simpleMessage);
     } catch (InvalidOperationException) {
     }
 }
        protected virtual void PostMessage(string sender, string body)
        {
            Guid        sysAdminUnit = _userConnection.CurrentUser.Id;
            IMsgChannel channel      = MsgChannelManager.Instance.FindItemByUId(sysAdminUnit);

            if (channel == null)
            {
                return;
            }
            var simpleMessage = new SimpleMessage()
            {
                Id   = sysAdminUnit,
                Body = body,
            };

            simpleMessage.Header.Sender = sender;
            channel.PostMessage(simpleMessage);
        }
		public static void PostMessage(UserConnection userConnection, string senderName, string messageText)
		{
			if (!CheckCanPostMessage(userConnection.CurrentUser.Name, senderName))
			{
				return;
			}
			MsgChannelManager channelManager = MsgChannelManager.Instance;
			IMsgChannel userChannel = channelManager.FindItemByUId(userConnection.CurrentUser.Id);
			if (userChannel != null)
			{
				PostMessageInternal(userChannel, senderName, messageText);
			}
			else
			{
				_log.Info(string.Format("Channel not found for user {0} from {1}",
					userConnection.CurrentUser.Name, senderName));
			}
		}
示例#15
0
        public virtual void SendMessage(string operation)
        {
            string      messageTpl     = "{{\"Id\":\"{0}\"}}";
            string      messageBody    = String.Format(messageTpl, Entity.Id);
            Guid        sysAdminUnitId = UserConnection.CurrentUser.Id;
            IMsgChannel channel        = MsgChannelManager.Instance.FindItemByUId(sysAdminUnitId);

            if (channel == null)
            {
                return;
            }
            var simpleMessage = new SimpleMessage {
                Id   = sysAdminUnitId,
                Body = messageBody
            };

            simpleMessage.Header.Sender = operation;
            channel.PostMessage(simpleMessage);
        }
示例#16
0
        protected static void LogMessage(String messageBody, UserConnection userConnection, string sender)
        {
            var log = LogManager.GetLogger("Terrasoft.Sync");

            log.Info(string.Format("[{0}] - {1}", sender, messageBody));
            Guid sysAdminUnitId = userConnection.CurrentUser.Id;

            try {
                IMsgChannel channel = MsgChannelManager.Instance.FindItemByUId(sysAdminUnitId);
                if (channel == null)
                {
                    return;
                }
                var simpleMessage = new SimpleMessage {
                    Id = sysAdminUnitId, Body = messageBody
                };
                simpleMessage.Header.Sender = sender;
                channel.PostMessage(simpleMessage);
            } catch (InvalidOperationException) {
            }
        }
        /// <summary>
        /// Sends error notification to users.
        /// </summary>
        /// <param name="mailbox"><see cref="MailboxSyncSettings"/> instance.</param>
        protected virtual void SendErrorNotification(Entity mailbox)
        {
            string message = GetErrorMessage(mailbox);

            if (message.IsNullOrEmpty())
            {
                return;
            }
            foreach (Guid subscriberId in GetMailboxOwners(mailbox))
            {
                IMsgChannel channel = GetMessageChannel(subscriberId);
                if (channel == null)
                {
                    continue;
                }
                var simpleMessage = new SimpleMessage();
                simpleMessage.Body          = message;
                simpleMessage.Id            = channel.Id;
                simpleMessage.Header.Sender = "SynchronizationError";
                channel.PostMessage(simpleMessage);
            }
        }
示例#18
0
 /// <summary>
 /// ########## ######### ###########.
 /// </summary>
 /// <param name="type">### #########.</param>
 /// <param name="message">#########.</param>
 private static void NotifySubscribers(string type, string message)
 {
     try {
         foreach (Guid subscriberId in QueuesNotificationsSubscribers)
         {
             MsgChannelManager manager = MsgChannelManager.Instance;
             IMsgChannel       channel = manager.FindItemByUId(subscriberId);
             if (channel == null)
             {
                 continue;
             }
             var simpleMessage = new SimpleMessage();
             simpleMessage.Body = message;
             simpleMessage.Id   = channel.Id;
             simpleMessage.Header.BodyTypeName = type;
             simpleMessage.Header.Sender       = "QueuesNotification";
             channel.PostMessage(simpleMessage);
         }
     } catch (Exception e) {
         _log.ErrorFormat(message, e.Message, e);
     }
 }
示例#19
0
        private bool inUse;                         // True if the message is considered to be
                                                    // owned by the messaging library.
#endif

        /// <summary>
        /// Constructor.
        /// </summary>
        public Msg()
        {
            this.version   = 0;
            this.flags     = 0;
            this.ttl       = 0;
            this.toEP      = null;
            this.fromEP    = null;
            this.receiptEP = null;
            this.msgID     = Guid.Empty;
            this.sessionID = Guid.Empty;
#if WINFULL
            this.session = null;
#endif
            this.token      = null;
            this.extHeaders = null;
#if WINFULL
            this.recvChannel = null;
#endif
            this.msgFrame = null;
#if DEBUG
            this.inUse = false;
#endif
        }
示例#20
0
 public PriceClient(IMsgChannel msgChannel)
 {
     this.msgChannel = msgChannel;
     this.msgChannel.OnMessage += new Action<string, Dictionary<string, string>>(msgChannel_OnMessage);
 }
		private static void PostMessageInternal(IMsgChannel channel, string sender, string msg)
		{
			IMsg simpleMessage = CreateMessage(sender, msg);
			_log.Debug($"Channel {channel.Name} post for {sender} msg: {msg}");
			channel.PostMessage(simpleMessage);
		}