// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseSession();

            var rabbitMQConfigs = new RabbitMQConfigs();

            new ConfigureFromConfigurationOptions <RabbitMQConfigs>(
                Configuration.GetSection("RabbitMQConfigs"))
            .Configure(rabbitMQConfigs);

            app.UseMiddleware <UserActivityMiddleware>(rabbitMQConfigs);

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
示例#2
0
        public void Application_OnError(Object sender, EventArgs e)
        {
            string          requestUrl  = DNTRequest.GetUrl();
            HttpApplication application = (HttpApplication)sender;
            HttpContext     context     = application.Context;

            if (GeneralConfigs.GetConfig().Installation == 0 && requestUrl.IndexOf("install") == -1) //当该站点未运行过安装并且当前页面不是安装程序目录下的页面时
            {
                context.Server.ClearError();                                                         //清除程序异常
                HttpContext.Current.Response.Redirect(BaseConfigs.GetForumPath + "install/index.aspx");
                return;
            }
#if EntLib
            if (RabbitMQConfigs.GetConfig() != null && RabbitMQConfigs.GetConfig().HttpModuleErrLog.Enable)//当开启errlog错误日志记录功能时
            {
                Discuz.EntLib.ServiceBus.HttpModuleErrLogClientHelper.GetHttpModuleErrLogClient().AsyncAddLog(
                    new Discuz.EntLib.ServiceBus.HttpModuleErrLogData(
                        Discuz.EntLib.ServiceBus.LogLevel.High,
                        context.Server.GetLastError().ToString()
                        ));
                return;
            }
#endif
            //context.Response.Write("<html><body style=\"font-size:14px;\">");
            //context.Response.Write("Discuz!NT Error:<br />");
            //context.Response.Write("<textarea name=\"errormessage\" style=\"width:80%; height:200px; word-break:break-all\">");
            //context.Response.Write(System.Web.HttpUtility.HtmlEncode(context.Server.GetLastError().ToString()));
            //context.Response.Write("</textarea>");
            //context.Response.Write("</body></html>");
            //context.Response.End();

            //context.Server.ClearError();//清除程序异常
        }
        public Receiver(
            RabbitMQConfigs rabbitMQConfigs,
            EventHandler <BasicDeliverEventArgs> receiver) : base(rabbitMQConfigs)
        {
            _Consumer_Received = receiver;

            this.SetupRabbitMQ();
        }
示例#4
0
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile($"application.json");

            _configuration = builder.Build();

            DbInitializer.Initialize();
            _appDbContext = new AppDbContext();

            var rabbitMQConfigs = new RabbitMQConfigs();

            new ConfigureFromConfigurationOptions <RabbitMQConfigs>(
                _configuration.GetSection("RabbitMQConfigs"))
            .Configure(rabbitMQConfigs);

            var receiver = new Receiver(rabbitMQConfigs, Consumer_Received);

            Console.Write("Aguardando Interações.");
        }
        private void BatchSendSM_Click(object sender, EventArgs e)
        {
            #region 批量短消息发送

            if (this.CheckCookie())
            {
                groupidlist = Usergroups.GetSelectString(",");

                if (groupidlist == "")
                {
                    base.RegisterStartupScript("", "<script>alert('请您先选取相关的用户组,再点击提交按钮');</script>");
                    return;
                }

#if EntLib
                if (RabbitMQConfigs.GetConfig() != null && RabbitMQConfigs.GetConfig().SendShortMsg.Enable)//当开启errlog错误日志记录功能时
                {
                    PrivateMessageInfo pm = new PrivateMessageInfo()
                    {
                        Msgfrom      = username.Replace("'", "''"),
                        Msgfromid    = userid,
                        Folder       = int.Parse(folder.SelectedValue),
                        Subject      = subject.Text,
                        Postdatetime = Discuz.Common.Utils.GetDateTime(), //获取发送消息的系统时间
                        Message      = message.Text,
                        New          = 1                                  //标记为未读
                    };
                    Discuz.EntLib.ServiceBus.SendShortMsgClientHelper.GetSendShortMsgClient().AsyncSendShortMsgByUserGroup(groupidlist, pm);
                    return;
                }
#endif
                ClientScript.RegisterStartupScript(this.GetType(), "Page", "<script>submit_Click();</script>");
            }

            #endregion
        }
 public BasicRabbitMQ(RabbitMQConfigs rabbitMQConfigs)
 {
     _rabbitMQConfigs = rabbitMQConfigs;
 }
 public UserActivityMiddleware(RequestDelegate next, RabbitMQConfigs rabbitMQConfigs)
 {
     _next            = next;
     _rabbitMQConfigs = rabbitMQConfigs;
 }
示例#8
0
        private void BatchSendSM_Click(object sender, EventArgs e)
        {
            #region 批量短消息发送

            if (this.CheckCookie())
            {
                string groupidlist = Usergroups.GetSelectString(",");

                if (groupidlist == "")
                {
                    base.RegisterStartupScript("", "<script>alert('请您先选取相关的用户组,再点击提交按钮');</script>");
                    return;
                }

#if EntLib
                if (RabbitMQConfigs.GetConfig() != null && RabbitMQConfigs.GetConfig().SendShortMsg.Enable)//当开启errlog错误日志记录功能时
                {
                    PrivateMessageInfo pm = new PrivateMessageInfo()
                    {
                        Msgfrom      = username.Replace("'", "''"),
                        Msgfromid    = userid,
                        Folder       = int.Parse(folder.SelectedValue),
                        Subject      = subject.Text,
                        Postdatetime = Discuz.Common.Utils.GetDateTime(), //获取发送消息的系统时间
                        Message      = message.Text,
                        New          = 1                                  //标记为未读
                    };
                    Discuz.EntLib.ServiceBus.SendShortMsgClientHelper.GetSendShortMsgClient().AsyncSendShortMsgByUserGroup(groupidlist, pm);
                }
#else
                int percount = Discuz.Common.Utils.StrToInt(postcountpercircle.Text, 100); //每多少记录为一次等待
                int count    = 0;                                                          //当前记录数

                //foreach (DataRow dr in DbHelper.ExecuteDataset("SELECT [uid] ,[username]  From [" + BaseConfigs.GetTablePrefix + "users] WHERE [groupid] IN(" + groupidlist + ")").Tables[0].Rows)
                foreach (DataRow dr in Users.GetUserListByGroupidList(groupidlist).Rows)
                {
                    //DbHelper.ExecuteNonQuery("INSERT INTO [" + BaseConfigs.GetTablePrefix + "pms] (msgfrom,msgfromid,msgto,msgtoid,folder,new,subject,postdatetime,message) VALUES ('" + this.username.Replace("'", "''") + "','" + this.userid.ToString() + "','" + dr["username"].ToString().Replace("'", "''") + "','" + dr["uid"].ToString() + "','" + folder.SelectedValue + "','1','" + subject.Text + "','" + postdatetime.Text + "','" + message.Text + "')");
                    //DbHelper.ExecuteNonQuery("UPDATE [" + BaseConfigs.GetTablePrefix + "users] SET [newpmcount]=[newpmcount]+1  WHERE [uid] =" + dr["uid"].ToString());
                    //Discuz.Data.DatabaseProvider.GetInstance().SendPMToUser(username.Replace("'", "''"), userid, dr["username"].ToString().Replace("'", "''"), Convert.ToInt32(dr["uid"].ToString()), int.Parse(folder.SelectedValue), subject.Text, Convert.ToDateTime(postdatetime.Text), message.Text);
                    PrivateMessageInfo pm = new PrivateMessageInfo();
                    pm.Msgfrom      = username.Replace("'", "''");
                    pm.Msgfromid    = userid;
                    pm.Msgto        = dr["username"].ToString().Replace("'", "''");
                    pm.Msgtoid      = Convert.ToInt32(dr["uid"].ToString());
                    pm.Folder       = int.Parse(folder.SelectedValue);
                    pm.Subject      = subject.Text;
                    pm.Postdatetime = postdatetime.Text;
                    pm.Message      = message.Text;
                    pm.New          = 1;//标记为未读
                    PrivateMessages.CreatePrivateMessage(pm, 0);
                    if (count >= percount)
                    {
                        Thread.Sleep(500);
                        count = 0;
                    }
                    count++;
                }
#endif
                base.RegisterStartupScript("PAGE", "window.location.href='global_sendSMtogroup.aspx';");
            }

            #endregion
        }
 public Publisher(RabbitMQConfigs rabbitMQConfigs) : base(rabbitMQConfigs)
 {
     this.SetupRabbitMQ();
 }