Example #1
0
        //This Shit needs testing
        public NewsDTO CreateNews(NewsDTO news, int userId)
        {
            NewsDTO dataResult = newsData.CreateNews(news, userId);

            //if (news.BackgroundPicture != null)
            //{
            //    dataResult.BackgroundPicture.PictureData = news.BackgroundPicture.PictureData;
            //}

            //TODO ovo uopste ne izgleda dobro, ne znam kako bi bolje mogle da se ucitavaju slike

            for (int i = 0; i < news.Pictures.Count; i++)
            {
                PictureDTO dto = dataResult.Pictures[i];
                dto.PictureData = news.Pictures[i].PictureData;
            }

            if (dataResult != null)
            {
                MessageQueueManager manager = MessageQueueManager.Instance;
                manager.PublishMessage(dataResult.Id, dataResult.Id, dataResult, MessageOperation.Insert);
            }

            return(dataResult);
        }
Example #2
0
        public void Execute(Message message)
        {
            Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);

            if (!Utils.BotTools.IsUserOperator(message.From.Id) &&
                !Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id))
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp        = DateTime.UtcNow,
                    Chat             = message.Chat,
                    ReplyToMessageId = message.MessageId,
                    Text             = CacheData.GetTranslation("en", "error_not_auth_command")
                });
                return;
            }

            if (message.ReplyToMessage == null)
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    ParseMode = ParseMode.Markdown,
                    Text      = CacheData.GetTranslation("en", "command_pin_missingMessage")
                });
                return;
            }

            Manager.BotClient.PinChatMessageAsync(message.Chat.Id, message.ReplyToMessage.MessageId);
        }
Example #3
0
        public bool DeleteComment(int commentId)
        {
            ISession session = null;
            bool     result  = false;

            try
            {
                session = DataLayer.GetSession();
                Comment comment = session.Load <Comment>(commentId);

                CommentDTO commentDTO = new CommentDTO(comment);
                session.Delete(comment);

                MessageQueueManager manager = MessageQueueManager.Instance;
                manager.PublishMessage(commentDTO.BelongsToNewsId, commentDTO.Id, commentDTO, MessageOperation.Delete);

                session.Flush();
                session.Close();
                result = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (session != null)
                {
                    session.Close();
                }
            }

            return(result);
        }
Example #4
0
        public void Execute(Message message)
        {
            Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);

            if (!Utils.BotTools.IsUserOperator(message.From.Id) &&
                !Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id))
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp        = DateTime.UtcNow,
                    Chat             = message.Chat,
                    ReplyToMessageId = message.MessageId,
                    Text             = CacheData.GetTranslation("en", "error_not_auth_command")
                });
                return;
            }

            bool   canRestrictMembers = false;
            bool   canDeleteMessages  = false;
            bool   canPinMessages     = false;
            string text = CacheData.SysConfigs
                          .Single(x => x.SysConfigId == "CommandCheckKoText").Value;

            var me = Manager.BotClient.GetChatMemberAsync(message.Chat.Id, Manager.MyId).Result;

            if (me.CanRestrictMembers != null)
            {
                canRestrictMembers = (bool)me.CanRestrictMembers;
            }
            if (me.CanDeleteMessages != null)
            {
                canDeleteMessages = (bool)me.CanDeleteMessages;
            }
            if (me.CanPinMessages != null)
            {
                canPinMessages = (bool)me.CanPinMessages;
            }

            if (canRestrictMembers && canDeleteMessages)
            {
                text = CacheData.SysConfigs.Single(x => x.SysConfigId == "CommandCheckOkText").Value;
            }

            text = text.Replace("{{has_ban_users}}", canRestrictMembers ? "{{true}}" : "{{false}}");
            text = text.Replace("{{has_delete_messages}}", canDeleteMessages ? "{{true}}" : "{{false}}");
            text = text.Replace("{{has_pin_messages}}", canPinMessages ? "{{true}}" : "{{false}}");

            text = Utils.Parsers.VariablesParser(text); // TODO select group's settings language

            MessageQueueManager.EnqueueMessage(
                new Models.ChatMessage()
            {
                Timestamp = DateTime.UtcNow,
                Chat      = message.Chat,
                ParseMode = ParseMode.Markdown,
                Text      = text
            });
        }
Example #5
0
        public void Execute(JobExecutionContext context)
        {
            string projectId = context.JobDetail.JobDataMap["projectId"].ToString();
            string gatewayId = SystemInternalSetting.Projects[projectId].ToString();

            Message message = MessageFactory.CreateHeartbeatMessage(projectId, gatewayId);

            MessageQueueManager.GetSendQueue(projectId).Enqueue(message);
        }
Example #6
0
        private static void CloseGroups(List <Models.Group.NightSchedule> nightSchedules)
        {
            foreach (Models.Group.NightSchedule nightSchedule in nightSchedules)
            {
                if (CacheData.NightSchedules[nightSchedule.GroupId].State != Models.Group.NightSchedule.Status.Programmed)
                {
                    continue;
                }

                if (_firstCycle)
                {
                    TimeSpan diffStartDate = DateTime.UtcNow - nightSchedule.UtcStartDate.Value;
                    if (diffStartDate.Days > 0)
                    {
                        CacheData.NightSchedules[nightSchedule.GroupId].UtcStartDate =
                            CacheData.NightSchedules[nightSchedule.GroupId].UtcStartDate.Value
                            .AddDays(diffStartDate.Days);
                        continue;
                    }
                }

                if (nightSchedule.UtcStartDate.Value <= DateTime.UtcNow)
                {
                    CacheData.NightSchedules[nightSchedule.GroupId].State = Models.Group.NightSchedule.Status.Active;
                    long chatId = CacheData.Groups.Values
                                  .Single(x => x.GroupId == nightSchedule.GroupId).TelegramChatId;

                    chatPermissionses[chatId] = Manager.BotClient.GetChatAsync(chatId).Result.Permissions;

                    Manager.BotClient.SetChatPermissionsAsync(chatId,
                                                              new ChatPermissions()
                    {
                        CanSendMessages       = false,
                        CanAddWebPagePreviews = false,
                        CanChangeInfo         = false,
                        CanInviteUsers        = false,
                        CanPinMessages        = false,
                        CanSendMediaMessages  = false,
                        CanSendOtherMessages  = false,
                        CanSendPolls          = false
                    });

                    MessageQueueManager.EnqueueMessage(
                        new ChatMessage()
                    {
                        Timestamp = DateTime.UtcNow,
                        Chat      = new Chat()
                        {
                            Id = chatId, Type = ChatType.Supergroup
                        },
                        Text = $"The group is now closed as per Night Schedule settings."
                    });
                    CacheData.NightSchedules[nightSchedule.GroupId].UtcStartDate =
                        CacheData.NightSchedules[nightSchedule.GroupId].UtcStartDate.Value.AddDays(1);
                }
            }
        }
Example #7
0
        public void Execute(Message message)
        {
            Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);

            if (!Utils.BotTools.IsUserOperator(message.From.Id) &&
                !Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id))
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp        = DateTime.UtcNow,
                    Chat             = message.Chat,
                    ReplyToMessageId = message.MessageId,
                    Text             = CacheData.GetTranslation("en", "error_not_auth_command")
                });
                return;
            }

            int userId = 0;

            if (message.ReplyToMessage != null)
            {
                userId = message.ReplyToMessage.From.Id;
            }
            else if (message.Text.Contains(" "))
            {
                int.TryParse(message.Text.Split(" ")[1], out userId);
            }

            if (userId == 0)
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    ParseMode = ParseMode.Markdown,
                    Text      = CacheData.GetTranslation("en", "command_unmute_missingMessage")
                });
                return;
            }

            Manager.BotClient.RestrictChatMemberAsync(
                message.Chat.Id,
                userId,
                new ChatPermissions()
            {
                CanSendMessages       = true,
                CanAddWebPagePreviews = true,
                CanChangeInfo         = true,
                CanInviteUsers        = true,
                CanPinMessages        = true,
                CanSendMediaMessages  = true,
                CanSendOtherMessages  = true,
                CanSendPolls          = true
            });
        }
Example #8
0
        private static void BanUserForPositiveFilter(Message message, Filters.FilterResult result)
        {
            int limitTime = 3;

            Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id]
                                                              .Where(x => x.ConfigurationParameterId == "SpamActionLimitTime")
                                                              .SingleOrDefault();
            if (configValue != null)
            {
                int.TryParse(configValue.Value, out limitTime);
            }
            RemoveMessageForPositiveFilter(message, result);

            Bot.Manager.BotClient.KickChatMemberAsync(message.Chat.Id, message.From.Id,
                                                      DateTime.UtcNow.AddMinutes(-5));
            UserTools.AddPenalty(message.Chat.Id, message.From.Id,
                                 Models.TrustFactorLog.TrustFactorAction.ban, Bot.Manager.MyId);

            Bot.Manager.BotClient.KickChatMemberAsync(message.Chat.Id, message.From.Id,
                                                      DateTime.UtcNow.AddMinutes(-5));

            UserTools.AddPenalty(message.Chat.Id, message.From.Id,
                                 Models.TrustFactorLog.TrustFactorAction.ban, Bot.Manager.MyId);

            string author = message.From.Username == null
                ? message.From.FirstName + " " + message.From.LastName
                : "@" + message.From.Username;
            string logMessage = String.Format(
                "*[Report]*\n" +
                "User banned as per group _Spam Action_ preference.\n" +
                "âš  do not open links you don't know âš \n" +
                "\nControl: `{0}`" +
                "\nChat: `{1}`" +
                "\nAuthor: `{2}`" +
                "\nUserId: `{3}`" +
                "\n\n*hash_code:* #UB{4}-{5}",
                result.CheckName,
                message.Chat.Title,
                author,
                message.From.Id,
                message.Chat.Id.ToString().Replace("-", ""),
                Guid.NewGuid());

            MessageQueueManager.EnqueueLog(new ChatMessage()
            {
                ParseMode = ParseMode.Markdown,
                Text      = logMessage
            });

            LogTools.AddActionLog(new ActionLog()
            {
                GroupId      = CacheData.Groups[message.Chat.Id].GroupId,
                UtcDate      = DateTime.UtcNow,
                ActionTypeId = "autoBan",
                Parameters   = logMessage,
            });
        }
        public void Execute(Message message)
        {
            if (!Utils.BotTools.IsUserOperator(message.From.Id) &&
                !Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id))
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp        = DateTime.UtcNow,
                    Chat             = message.Chat,
                    ReplyToMessageId = message.MessageId,
                    Text             = CacheData.GetTranslation("en", "error_not_auth_command")
                });
                return;
            }

            string[] arguments = message.Text.Split(" ");
            if (arguments.Length < 2)
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp        = DateTime.UtcNow,
                    Chat             = message.Chat,
                    ReplyToMessageId = message.MessageId,
                    Text             = CacheData.GetTranslation("en", "rwb_command_error_invalidsyntax")
                });
                return;
            }

            BusinessLogic.ButtonLogic   buttonLogic = new BusinessLogic.ButtonLogic();
            Models.SystemLog.ErrorCodes removed     = buttonLogic.Remove(CacheData.Groups[message.Chat.Id].GroupId,
                                                                         message.Text.Remove(0, arguments[0].Length + 1), -2);
            if (removed == Models.SystemLog.ErrorCodes.Error)
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp        = DateTime.UtcNow,
                    Chat             = message.Chat,
                    ReplyToMessageId = message.MessageId,
                    Text             = CacheData.GetTranslation("en", "rwb_command_error_general")
                });
                return;
            }

            Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);
            string successMsg = CacheData.GetTranslation("en", "rwb_command_success");

            MessageQueueManager.EnqueueMessage(
                new Models.ChatMessage()
            {
                Timestamp = DateTime.UtcNow,
                Chat      = message.Chat,
                Text      = successMsg.Replace("{{wbName}}", arguments[1])
            });
        }
Example #10
0
        public void Execute(Message message)
        {
            if (!Utils.BotTools.IsUserOperator(message.From.Id, Models.Operator.Levels.Advanced))
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    Text      = CacheData.GetTranslation("en", "white_command_error_notoperator")
                });
                return;
            }

            int userToUnban;

            if (message.ReplyToMessage == null)
            {
                if (message.Text.Split(" ")[1].StartsWith("@"))
                {
                    if (!CacheData.Usernames.Keys.Contains(message.Text.Split(" ")[1].Remove(0, 1)))
                    {
                        MessageQueueManager.EnqueueMessage(
                            new Models.ChatMessage()
                        {
                            Timestamp = DateTime.UtcNow,
                            Chat      = message.Chat,
                            Text      = CacheData.GetTranslation("en", "white_command_error_invalidUsername")
                        });
                        return;
                    }
                    userToUnban = CacheData.Usernames[message.Text.Split(" ")[1].Remove(0, 1)];
                }
                else
                {
                    bool isValid = int.TryParse(message.Text.Split(" ")[1], out userToUnban);
                    if (!isValid)
                    {
                        MessageQueueManager.EnqueueMessage(
                            new Models.ChatMessage()
                        {
                            Timestamp = DateTime.UtcNow,
                            Chat      = message.Chat,
                            Text      = CacheData.GetTranslation("en", "white_command_error_invalidUserId")
                        });
                        return;
                    }
                }
            }
            else
            {
                userToUnban = message.ReplyToMessage.From.Id;
            }

            Utils.UserTools.RemoveUserFromBlacklist(message, userToUnban);
        }
Example #11
0
        public PictureDTO CreatePicture(PictureDTO pic)
        {
            PictureDTO dataResult = pictureData.CreatePicture(pic);

            if (dataResult != null)
            {
                MessageQueueManager menager = MessageQueueManager.Instance;
                menager.PublishMessage(dataResult.BelongsToNewsId, dataResult.Id, dataResult, MessageOperation.Insert);
            }
            return(dataResult);
        }
Example #12
0
        public bool PutPicture(int pictureId, int newsId, byte[] pictureData)
        {
            bool res = loader.SaveMedia(pictureId, newsId, pictureData);

            if (res)
            {
                MessageQueueManager manager = MessageQueueManager.Instance;
                manager.PublishMessage(newsId, pictureId, new PictureUpdateObject(pictureId, newsId), MessageOperation.Update);
            }
            return(res);
        }
Example #13
0
        public CommentDTO CreateComment(CommentDTO value)
        {
            CommentDTO dataResult = commentDataAccess.CreateComment(value);

            if (dataResult != null)
            {
                MessageQueueManager menager = MessageQueueManager.Instance;
                menager.PublishMessage(dataResult.BelongsToNewsId, dataResult.Id, dataResult, MessageOperation.Insert);
            }
            return(dataResult);
        }
Example #14
0
        public void Execute(Message message)
        {
            if (!Utils.BotTools.IsUserOperator(message.From.Id, Models.Operator.Levels.Basic) &&
                !Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id))
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp        = DateTime.UtcNow,
                    Chat             = message.Chat,
                    ReplyToMessageId = message.MessageId,
                    Text             = CacheData.GetTranslation("en", "error_not_auth_command")
                });
                return;
            }

            string[] hasMessage = message.Text.Split(" ");
            if (hasMessage.Length > 1)
            {
                bool result = Utils.ConfigTools.UpdateRulesText(message.Chat.Id, message.Text.Remove(0, hasMessage[0].Length + 1));
                if (result)
                {
                    Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);
                }
                return;
            }

            CommandMessage commandMessage = new CommandMessage()
            {
                Command   = "SetRulesText",
                Value     = "",
                Message   = message,
                Timestamp = DateTime.UtcNow
            };

            CommandQueueManager.EnqueueMessage(commandMessage);
            MessageQueueManager.EnqueueMessage(
                new Models.ChatMessage()
            {
                Timestamp        = DateTime.UtcNow,
                Chat             = message.Chat,
                ReplyToMessageId = message.MessageId,
                ParseMode        = ParseMode.Html,
                Text             = $"<b>[ADMIN] [r:{message.MessageId}]</b>\n"
                                   + CacheData.GetTranslation(
                    CacheData.Groups[message.Chat.Id].SettingsLanguage,
                    "command_setrules_instructions"),
                ReplyMarkup = new ForceReplyMarkup()
                {
                    Selective = true
                }
            });
        }
Example #15
0
 public void Execute(Message message)
 {
     MessageQueueManager.EnqueueMessage(
         new Models.ChatMessage()
     {
         Timestamp = DateTime.UtcNow,
         Chat      = message.Chat,
         Text      = CacheData.SysConfigs
                     .Single(x => x.SysConfigId == "motd")
                     .Value
     });
 }
Example #16
0
        public void Execute(Message message)
        {
            if (!Utils.BotTools.IsUserOperator(message.From.Id, Models.Operator.Levels.Basic) &&
                !Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id))
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    Text      = CacheData.GetTranslation("en", "feedback_command_error_notadmin")
                });
                return;
            }

            List <List <InlineKeyboardButton> > buttons = new List <List <InlineKeyboardButton> >();

            buttons.Add(new List <InlineKeyboardButton>()
            {
                InlineKeyboardButton.WithCallbackData(
                    CacheData.GetTranslation("en", "feedback_type_suggestion"),
                    $"/feedback type:suggestion"
                    )
            });
            buttons.Add(new List <InlineKeyboardButton>()
            {
                InlineKeyboardButton.WithCallbackData(
                    CacheData.GetTranslation("en", "feedback_type_reportBug"),
                    $"/feedback type:reportBug"
                    )
            });
            buttons.Add(new List <InlineKeyboardButton>()
            {
                InlineKeyboardButton.WithCallbackData(
                    CacheData.GetTranslation("en", "feedback_type_reportUser"),
                    $"/feedback type:reportUser"
                    )
            });

            MessageQueueManager.EnqueueMessage(
                new Models.ChatMessage()
            {
                Timestamp        = DateTime.UtcNow,
                Chat             = message.Chat,
                ReplyToMessageId = message.MessageId,
                ParseMode        = ParseMode.Markdown,
                Text             = "*[ADMIN]*\nSelect feedback type:",
                ReplyMarkup      = new InlineKeyboardMarkup(
                    buttons
                    )
            });
        }
Example #17
0
        public bool DeletePicture(int id)
        {
            PictureDTO resultData = pictureData.DeletePicture(id);
            bool       result     = false;

            if (resultData != null)
            {
                result = loader.DeleteMedia(resultData.Id, resultData.BelongsToNewsId);
                MessageQueueManager manager = MessageQueueManager.Instance;
                manager.PublishMessage(resultData.BelongsToNewsId, resultData.Id, resultData, MessageOperation.Delete);
            }
            return(result);
        }
Example #18
0
        public bool UpdateComment(int id, string content)
        {
            bool       result     = false;
            CommentDTO dataResult = commentDataAccess.UpdateComment(id, content);

            if (dataResult != null)
            {
                MessageQueueManager menager = MessageQueueManager.Instance;
                menager.PublishMessage(dataResult.BelongsToNewsId, dataResult.Id, dataResult, MessageOperation.Update);
                result = true;
            }
            return(result);
        }
Example #19
0
        public void Execute(Message message)
        {
            if (!Utils.BotTools.IsUserOperator(message.From.Id, Models.Operator.Levels.Basic) &&
                !Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id))
            {
                return;
            }

            string[] arguments = message.Text.Split(" ");

            if (arguments.Length < 3)
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    Text      = CacheData.GetTranslation("en", "addbadword_command_error_missingargument")
                });
                return;
            }

            bool added = Filters.BadWordFilter.BanWord(
                CacheData.Groups[message.Chat.Id].GroupId,
                arguments[1].Trim(),
                message.Text
                .Substring(arguments[0].Length + arguments[1].Length + 1)
                .Trim());

            if (!added)
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    Text      = CacheData.GetTranslation("en", "addbadword_command_error")
                });
                return;
            }

            Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);
            MessageQueueManager.EnqueueMessage(
                new Models.ChatMessage()
            {
                Timestamp = DateTime.UtcNow,
                Chat      = message.Chat,
                Text      = CacheData.GetTranslation("en", "addbadword_command_success")
            });
            return;
        }
Example #20
0
        public bool DeleteAudio(int audioId)
        {
            bool     result     = false;
            AudioDTO resultData = audioDataAccess.DeleteAudio(audioId);

            if (resultData.AudioData != null)
            {
                result = loader.SaveMedia(resultData.Id, resultData.BelongsToNewsId, resultData.GetAudioBytes());

                MessageQueueManager manager = MessageQueueManager.Instance;
                manager.PublishMessage(resultData.BelongsToNewsId, resultData.Id, resultData, MessageOperation.Delete);
            }
            return(result);
        }
Example #21
0
        public bool UpdatePicture(PictureDTO pic)
        {
            bool       resault    = false;
            PictureDTO dataResult = pictureData.UpdatePicture(pic);

            if (dataResult != null)
            {
                loader.SaveMedia(dataResult.Id, dataResult.BelongsToNewsId, dataResult.GetPictureBytes());

                MessageQueueManager menager = MessageQueueManager.Instance;
                menager.PublishMessage(dataResult.BelongsToNewsId, dataResult.Id, dataResult, MessageOperation.Update);
                resault = true;
            }
            return(resault);
        }
        static void Main(string[] args)
        {
            //create a new MSMQ implementation object
            IMessageQueue msmq = new MSMQ("QueueA");
            //bind the implementation to the MessageQueueManager
            IMessageQueueManager mqm = new MessageQueueManager(msmq);

            //create a new message object
            Message m = new Message();

            m.Label   = "test";
            m.Content = "this is test";
            try
            {
                mqm.OpenConnection();
                mqm.SendMessage(m);
                Message retrievedMessage = mqm.RetrieveMessage();
                //send two more method the queue for MessageArrival event test later
                mqm.SendMessage(m);
                mqm.SendMessage(m);
            }
            finally
            {
                mqm.CloseConnection();
            }

            //register the client with the message arrive
            mqm.RegisterMessageArrivalHanlder(new MessageArrivalHandler(RecieveMessage));

            //create a new MQSeries implementation
            IMessageQueue mqseries = new MQSeries("QueueB");

            //bind implementation object to the MessageQueueManager
            mqm = new MessageQueueManager(mqseries);
            try
            {
                mqm.OpenConnection();
                mqm.SendMessage(m);
                Message retrievedMessage = mqm.RetrieveMessage();
            }
            finally
            {
                mqm.CloseConnection();
            }


            Console.ReadLine();
        }
Example #23
0
        private void requestNewValue(CallbackQuery callbackQuery,
                                     string configurationParameterId)
        {
            Manager.BotClient.DeleteMessageAsync(callbackQuery.Message.Chat.Id, callbackQuery.Message.MessageId);
            ConfigurationParameter conf = CacheData.GroupConfigs[callbackQuery.Message.Chat.Id]
                                          .Where(x => x.ConfigurationParameterId == configurationParameterId)
                                          .SingleOrDefault();

            if (conf == null)
            {
                return;
            }

            switch (conf.Type)
            {
            case "string":
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp   = DateTime.UtcNow,
                    Chat        = callbackQuery.Message.Chat,
                    ParseMode   = ParseMode.Markdown,
                    Text        = $"*[ADMIN] Settings [r:{callbackQuery.Message.MessageId}]*\nProvide new value:",
                    ReplyMarkup = new ForceReplyMarkup()
                    {
                        Selective = true
                    }
                });
                break;

            case "language":
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp   = DateTime.UtcNow,
                    Chat        = callbackQuery.Message.Chat,
                    ParseMode   = ParseMode.Markdown,
                    Text        = $"*[ADMIN] Settings [r:{callbackQuery.Message.MessageId}]*\nSelect language:",
                    ReplyMarkup = new InlineKeyboardMarkup(
                        buildLanguageSelectionMenu(callbackQuery.From.Id)
                        )
                });
                break;

            default:
                break;
            }
        }
Example #24
0
        private void Awake()
        {
            //
            //TODO: Add managers in list with order
            //
            // PropertyAnimationManager
            managers.Add(PropertyAnimationManager.GetInstance());
            // MessageQueueManager
            managers.Add(MessageQueueManager.GetInstance());

            //Awake
            foreach (var manager in managers)
            {
                manager.Awake();
            }
        }
Example #25
0
        public void ShouldCreateExchangeHeaders()
        {
            // Given
            var session         = new Mock <IMessageQueueSession>();
            var commandExecutor = new Mock <IMessageQueueCommandExecutor>();
            var workerContainer = new Mock <IMessageQueueWorkerContainer>();

            commandExecutor.Setup(m => m.Execute(It.IsAny <Action <IMessageQueueSession> >())).Callback <Action <IMessageQueueSession> >(command => command(session.Object));

            // When
            var target = new MessageQueueManager(commandExecutor.Object, workerContainer.Object);
            var result = target.CreateExchangeHeaders(ExchangeName);

            // Then
            Assert.IsNotNull(result);
            session.Verify(m => m.CreateExchangeHeaders(It.Is <ExchangeConfig>(p => p.ExchangeName == ExchangeName)));
        }
Example #26
0
        public SimpleNewsDTO UpdateNews(SimpleNewsDTO simpleDTO, int userId)
        {
            SimpleNewsDTO dataResult = newsData.UpdateNews(simpleDTO, userId);

            if (dataResult != null && simpleDTO.BackgroundPicture != null)
            {
                //loader.SaveMedia(simpleDTO.BackgroundPicture.Id, simpleDTO.Id, simpleDTO.BackgroundPicture.GetPictureBytes());
                dataResult.BackgroundPicture.PictureData = simpleDTO.BackgroundPicture.PictureData;
            }

            if (dataResult != null)
            {
                MessageQueueManager manager = MessageQueueManager.Instance;
                manager.PublishMessage(dataResult.Id, dataResult.Id, dataResult, MessageOperation.Update);
            }
            return(dataResult);
        }
Example #27
0
        public void Execute(Message message)
        {
            Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);

            string text = Utils.Parsers.VariablesParser(CacheData.SysConfigs
                                                        .Single(x => x.SysConfigId == "HelpMenu")
                                                        .Value);

            if (ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id))
            {
                text += Environment.NewLine;
                text += CacheData.SysConfigs
                        .Single(x => x.SysConfigId == "HelpMenuAdmin")
                        .Value;
            }

            if (BotTools.IsUserOperator(message.From.Id))
            {
                text += Environment.NewLine;
                text += CacheData.SysConfigs
                        .Single(x => x.SysConfigId == "HelpMenuOperatorBase")
                        .Value;

                if (BotTools.IsUserOperator(message.From.Id, Models.Operator.Levels.Advanced))
                {
                    text += Environment.NewLine;
                    text += CacheData.SysConfigs
                            .Single(x => x.SysConfigId == "HelpMenuOperatorAdv")
                            .Value;
                }
            }

            text += Environment.NewLine;
            text += Environment.NewLine;
            text += "* usernames are saved in cache and never stored on database or file. The cache is cleared at every reboot or update.";

            MessageQueueManager.EnqueueMessage(
                new Models.ChatMessage()
            {
                Timestamp = DateTime.UtcNow,
                Chat      = message.Chat,
                ParseMode = ParseMode.Html,
                Text      = text
            });
        }
Example #28
0
        public void Execute(Message message)
        {
            if (!Utils.BotTools.IsUserOperator(message.From.Id, Models.Operator.Levels.Basic) &&
                !Utils.ChatTools.IsUserAdmin(message.Chat.Id, message.From.Id))
            {
                return;
            }

            if (message.ReplyToMessage != null)
            {
                if (!message.ReplyToMessage.Text.StartsWith("#"))
                {
                    MessageQueueManager.EnqueueMessage(
                        new Models.ChatMessage()
                    {
                        Timestamp        = DateTime.UtcNow,
                        Chat             = message.Chat,
                        ReplyToMessageId = message.MessageId,
                        Text             = CacheData.GetTranslation("en", "error_addnote_command_onreply")
                    });
                    return;
                }

                Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.ReplyToMessage.MessageId);
                Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);
                SaveNote(message.ReplyToMessage);
                return;
            }

            if (!message.Text.Remove(0, 9).StartsWith("#"))
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp        = DateTime.UtcNow,
                    Chat             = message.Chat,
                    ReplyToMessageId = message.MessageId,
                    Text             = CacheData.GetTranslation("en", "error_addnote_command_starttag")
                });
                return;
            }

            Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);
            SaveNote(message);
        }
Example #29
0
        public void Execute(Message message)
        {
            if (!Utils.BotTools.IsUserOperator(message.From.Id, Models.Operator.Levels.Basic))
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    Text      = CacheData.GetTranslation("en", "feedback_command_error_notoperator")
                });
                return;
            }

            if (CacheData.ActiveSupport.Contains(message.Chat.Id))
            {
                CacheData.ActiveSupport.Remove(message.Chat.Id);
                CacheData.CurrentChatAdmins.Remove(message.Chat.Id);

                Manager.BotClient.SendTextMessageAsync(
                    chatId: message.Chat.Id,
                    parseMode: ParseMode.Markdown,
                    text: String.Format(
                        "Operator *{0}* ended the support session.",
                        message.From.Username)
                    );
                MessageQueueManager.EnqueueLog(new ChatMessage()
                {
                    ParseMode = ParseMode.Markdown,
                    Text      = String.Format(
                        "*[Log]*" +
                        "\n\nSupport session ended by operator *{0}*" +
                        "\nChatId: `{1}`" +
                        "\nChat: `{2}`" +
                        "\nUserId: `{3}`" +
                        "\n\n*hash_code:* #UB{4}-{5}",
                        message.From.Username,
                        message.Chat.Id,
                        message.Chat.Title,
                        message.From.Id,
                        message.Chat.Id.ToString().Replace("-", ""),
                        Guid.NewGuid())
                });
            }
        }
Example #30
0
        public void Execute(Message message)
        {
            if (message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Private ||
                message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Channel)
            {
                if (MessageQueueManager.AddChatIfNotPresent(message.Chat.Id))
                {
                    Models.SysConfig startMessage = CacheData.SysConfigs
                                                    .SingleOrDefault(x => x.SysConfigId == "StartMessage");
                    if (startMessage == null)
                    {
                        Manager.BotClient.SendTextMessageAsync(
                            chatId: message.Chat.Id,
                            text: $"Your chat {message.Chat.Title} has been added successfully!"
                            );
                        return;
                    }

                    Manager.BotClient.SendTextMessageAsync(
                        chatId: message.Chat.Id,
                        parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
                        text: Utils.Parsers.VariablesParser(startMessage.Value, message)
                        );
                    return;
                }

                Manager.BotClient.SendTextMessageAsync(
                    chatId: message.Chat.Id,
                    text: $"Error adding chat {message.Chat.Title}! Please contact our support"
                    );
                return;
            }

            if (message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Group ||
                message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Supergroup)
            {
                return;
            }

            Manager.BotClient.SendTextMessageAsync(
                chatId: message.Chat.Id,
                text: $"Error: chat type not recognized. Please contact our support."
                );
        }