public bool EnqueueItem(IMessageToSend item)
        {
            logger.Debug(MethodBase.GetCurrentMethod().Name + "() - START");
            bool success = false;

            try
            {
                lock (itemList)
                {
                    itemList.Enqueue(item);
                }
                success = true;

                try
                {
                    resourceLockOut.Set();
                }
                catch (Exception e)
                {
                    logger.Error(MethodBase.GetCurrentMethod().Name + "() - ResourceLock exception (Out)", e);
                }
            }
            catch (Exception ex)
            {
                logger.Error(MethodBase.GetCurrentMethod().Name + "() - Enqueue exception: ", ex);
                success = false;
            }

            logger.Debug(MethodBase.GetCurrentMethod().Name + "() - END");
            return success;
        }
예제 #2
0
        public override void OnMessageReceivedAction(Task <bool> task, object?state)
        {
            if (task.Result)
            {
                Message message = state as Message;
                if (ChatIsGroup(message))
                {
                    Message inReplyOf = message.ReplyToMessage;

                    if (inReplyOf != null)
                    {
                        long?targer = dBWorker.get_pair_chat_id(inReplyOf.Chat.Id, inReplyOf.MessageId, token);
                        if (targer != null)
                        {
                            IMessageToSend MyMess = RecreateMessage(message, (long)targer);
                            sender_to_tg.Put(MyMess);
                        }
                    }
                }
                else if (ChatIsPrivate(message))
                {
                    List <long> groups   = dBWorker.get_active_groups();
                    string      appendix = "\n\n#id{0}\n<a href =\"tg://user?id={0}\">{1}</a>";
                    foreach (long group_id in groups)
                    {
                        IMessageToSend MyMess = RecreateMessage(message, group_id, string.Format(appendix, message.From.Id, message.From.FirstName));
                        if (MyMess != null)
                        {
                            MyMess.AddLinkedMessage(message);
                        }
                        sender_to_tg.Put(MyMess);
                    }
                }
            }
        }
예제 #3
0
 public void Put(IMessageToSend mess)
 {
     if (mess != null)
     {
         lock (locker)
         {
             MainQuenue.Enqueue(mess);
         }
     }
 }
 public bool SendMessage(IMessageToSend message)
 {
     return SharpConnectionHelperSingleton.Instance.SendMessage(message);
 }
 public void addRequestToWorkerPool(IMessageToSend item)
 {
     workerThreadPool.AddWorkItem(new outgoingDelegate(ConnectionManager.Instance.SendMessage), item);
 }