public JsonResult AddTopic(string invites, string title, string topic, string topicText, int gradeId, int subjectId)
        {
            topic = HttpUtility.UrlDecode(topic);
            if (B_StaticObject.swh.HasBadWord(string.Concat(title, topic)))
            {
                return(Json(new { status = "1", message = "标题或者内容中含有敏感词汇,不能提交!", value = 0 }));
            }
            topicText = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(topicText).Replace("\n", "").Replace("\t", "")).Trim();
            T_Topic t = new T_Topic()
            {
                UserId       = UserInfo.Id,
                Invites      = invites,
                Title        = title,
                TopicContent = ProcessBigPic(topic, 760),
                TopicText    = topicText,
                Hit          = 0,
                Good         = 0,
                ReplyCount   = 0,
                GradeId      = gradeId,
                SubjectId    = subjectId,
                Deleted      = false,
                Blocked      = false,
                CreateDate   = DateTime.Now,
                Ip           = ClientUtil.Ip
            };
            int i = B_Topic.AddTopic(t);

            if (i > 0 && !string.IsNullOrEmpty(invites))
            {
                B_Topic.AddTopicInvites(i, invites.Split(' '));
            }
            return(Json(new { status = "0", message = "", value = i }));
        }
Example #2
0
        public void Run(string fileName, string args, object top)
        {
            T_Topic tt          = (T_Topic)top;
            string  returnvalue = string.Empty;
            // 定義呼叫程式的info
            ProcessStartInfo info = new ProcessStartInfo(fileName);

            info.UseShellExecute = false;
            // 設定命令列輸入參數
            info.Arguments = args;
            // 重新導向標準輸出 輸入 錯誤
            info.RedirectStandardInput  = true;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError  = true;
            // 設定是否建立視窗
            info.CreateNoWindow = true;
            Process process = new Process();

            process.StartInfo = info;
            // 設定標準輸出 , 錯誤的接收事件
            process.OutputDataReceived += new DataReceivedEventHandler(Display);
            process.ErrorDataReceived  += new DataReceivedEventHandler(Display);
            // 開始執行程序
            process.Start();
            // 加入process list 用來離開程式 關閉publisher process
            pss.Add(process);
            // 開始讀取標準輸出 , 錯誤
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            StreamWriter sw = process.StandardInput;

            // 輸入要傳送的TOPIC
            sw.WriteLine(tt.topic);
            sw.Flush();
            T_Data input;

            while (true)
            {
                // 確任是否在queue中有無要傳送的訊息
                if (Input_Topic_Queue[tt.id] != null && Input_Topic_Queue[tt.id].TryDequeue(out input))
                {
                    // 傳送訊息
                    sw.WriteLine(input.data);
                    sw.Flush();
                    // 傳送訊息
                    sw.WriteLine(input.count);
                    sw.Flush();
                }
                Thread.Sleep(5);
            }
            // 等待程式執行結束
            process.WaitForExit();
        }
Example #3
0
        /// <summary>
        /// 插入话题,返回话题Id
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        public static int AddTopic(T_Topic topic)
        {
            object o = MySqlHelper.ExecuteScalar(Util.GetConnectString(BBSConnString),
                                                 "insert into T_Topic(Id, UserId, Invites, Title, TopicContent, TopicText, CreateDate, Good, Hit, ReplyCount, GradeId, SubjectId, Deleted, Blocked, Ip) values (null, @UserId, @Invites, @Title, @TopicContent, @TopicText, @CreateDate, @Good, @Hit, @ReplyCount, @GradeId, @SubjectId, @Deleted, @Blocked, @Ip); select last_insert_id();",
                                                 "@UserId".ToInt32InPara(topic.UserId),
                                                 "@Invites".ToVarCharInPara(topic.Invites),
                                                 "@Title".ToVarCharInPara(topic.Title),
                                                 "@TopicContent".ToVarCharInPara(topic.TopicContent),
                                                 "@TopicText".ToVarCharInPara(topic.TopicText),
                                                 "@CreateDate".ToDateTimeInPara(topic.CreateDate),
                                                 "@Good".ToInt32InPara(topic.Good),
                                                 "@Hit".ToInt32InPara(topic.Hit),
                                                 "@ReplyCount".ToInt32InPara(topic.ReplyCount),
                                                 "@GradeId".ToInt32InPara(topic.GradeId),
                                                 "@SubjectId".ToInt32InPara(topic.SubjectId),
                                                 "@Deleted".ToBitInPara(topic.Deleted),
                                                 "@Blocked".ToBitInPara(topic.Blocked),
                                                 "@Ip".ToVarCharInPara(topic.Ip)
                                                 );

            return(o == null ? 0 : int.Parse(o.ToString()));
        }
Example #4
0
        public void RunSub(string fileName, string args, object top)
        {
            T_Topic tt          = (T_Topic)top;
            string  returnvalue = string.Empty;
            // 定義呼叫程式的info
            ProcessStartInfo info = new ProcessStartInfo(fileName);

            info.UseShellExecute = false;
            // 設定命令列輸入參數
            info.Arguments = args;
            // 設定標準輸出 , 錯誤的接收事件
            info.RedirectStandardInput  = true;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError  = true;
            // 設定是否建立視窗
            info.CreateNoWindow = true;
            Process process = new Process();

            process.StartInfo = info;
            // 設定標準輸出 , 錯誤的接收事件
            process.OutputDataReceived += new DataReceivedEventHandler(tt.dateRecivedHanlder);
            process.ErrorDataReceived  += new DataReceivedEventHandler(Display);
            // 開始執行程序
            process.Start();
            // 加入process list 用來離開程式 關閉subsciber process
            pss.Add(process);
            StreamWriter sw = process.StandardInput;

            // 開始讀取標準輸出 , 錯誤
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            // 輸入要訂閱的主題
            sw.WriteLine(tt.topic);
            sw.Flush();
            // 等待程式離開
            process.WaitForExit();
        }
Example #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // 初始化Topic queue
            for (int i = 0; i < 4; i++)
            {
                Input_Topic_Queue[i] = new ConcurrentQueue <T_Data>();
            }

            // 設定 Topic
            // Topic porperty
            // topic : 主題名稱
            // id :  Input Queue Array index 執行續溝通用
            // dateRecivedHanlder:接收 subscirbe 訊息的匿名函式
            T_Topic t1 = new T_Topic("A", 0);

            // 接收 subscirbe 訊息的實作
            t1.dateRecivedHanlder = (sendingProcess, outLine) =>
            {
                if (!String.IsNullOrEmpty(outLine.Data))
                {
                    string data   = outLine.Data;
                    string cstr   = "message count ";
                    string estr   = ";message time ";
                    int    tindex = data.IndexOf(cstr);
                    int    eindex = data.IndexOf(estr);
                    System.Diagnostics.Debug.WriteLine(outLine.Data);
                    if (tindex >= 0)
                    {
                        int  len   = eindex - (tindex + cstr.Length);
                        long count = Convert.ToInt64(data.Substring(tindex + cstr.Length, len));
                        SetText(label7, outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        T_Data da = new T_Data();
                        da.data = this.textBox1.Text;
                        if (checkBox5.Checked == true)
                        {
                            if (count != -1 && count >= Convert.ToInt64(textBox6.Text) && Convert.ToInt64(textBox6.Text) != 0)
                            {
                                counts[0] = -1;
                                return;
                            }
                            if (timer1_count == Convert.ToInt64(textBox5.Text) && Convert.ToInt64(textBox5.Text) != 0)
                            {
                                counts[0] = -1;
                                return;
                            }

                            if (count == counts[0] + 1)
                            {
                                counts[0] = counts[0] + 2;
                                da.count  = counts[0];
                                Input_Topic_Queue[0].Enqueue(da);
                            }
                        }
                    }
                }
            };

            T_Topic t2 = new T_Topic("B", 1);

            t2.dateRecivedHanlder = (sendingProcess, outLine) =>
            {
                if (!String.IsNullOrEmpty(outLine.Data))
                {
                    string data   = outLine.Data;
                    string cstr   = "message count ";
                    string estr   = ";message time ";
                    int    tindex = data.IndexOf(cstr);
                    int    eindex = data.IndexOf(estr);
                    System.Diagnostics.Debug.WriteLine(outLine.Data);
                    if (tindex >= 0)
                    {
                        SetText(label8, outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        int    len   = eindex - (tindex + cstr.Length);
                        long   count = Convert.ToInt64(data.Substring(tindex + cstr.Length, len));
                        T_Data da    = new T_Data();
                        da.data = this.textBox3.Text;
                        if (checkBox5.Checked == true)
                        {
                            if (count != -1 && count >= Convert.ToInt64(textBox8.Text) && Convert.ToInt64(textBox8.Text) != 0)
                            {
                                counts[1] = -1;
                                return;
                            }
                            if (timer2_count == Convert.ToInt64(textBox7.Text) && Convert.ToInt64(textBox7.Text) != 0)
                            {
                                counts[1] = -1;
                                return;
                            }
                            if (count == counts[1] + 1)
                            {
                                counts[1] = counts[1] + 2;
                                da.count  = counts[1];
                                Input_Topic_Queue[1].Enqueue(da);
                            }
                        }
                    }
                }
            };

            T_Topic t3 = new T_Topic("C", 2);

            t3.dateRecivedHanlder = (sendingProcess, outLine) =>
            {
                if (!String.IsNullOrEmpty(outLine.Data))
                {
                    string data   = outLine.Data;
                    string cstr   = "message count ";
                    string estr   = ";message time ";
                    int    tindex = data.IndexOf(cstr);
                    int    eindex = data.IndexOf(estr);
                    System.Diagnostics.Debug.WriteLine(outLine.Data);
                    if (tindex >= 0)
                    {
                        SetText(label9, outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        int    len   = eindex - (tindex + cstr.Length);
                        long   count = Convert.ToInt64(data.Substring(tindex + cstr.Length, len));
                        T_Data da    = new T_Data();
                        da.data = this.textBox2.Text;
                        if (checkBox5.Checked == true)
                        {
                            if (count != -1 && count >= Convert.ToInt64(textBox10.Text) && Convert.ToInt64(textBox10.Text) != 0)
                            {
                                counts[2] = -1;
                                return;
                            }
                            if (timer3_count == Convert.ToInt64(textBox9.Text) && Convert.ToInt64(textBox9.Text) != 0)
                            {
                                counts[2] = -1;
                                return;
                            }
                            if (count == counts[2] + 1)
                            {
                                counts[2] = counts[2] + 2;
                                da.count  = counts[2];
                                Input_Topic_Queue[2].Enqueue(da);
                            }
                        }
                    }
                }
            };

            T_Topic t4 = new T_Topic("D", 3);

            t4.dateRecivedHanlder = (sendingProcess, outLine) =>
            {
                if (!String.IsNullOrEmpty(outLine.Data))
                {
                    string data   = outLine.Data;
                    string cstr   = "message count ";
                    string estr   = ";message time ";
                    int    tindex = data.IndexOf(cstr);
                    int    eindex = data.IndexOf(estr);
                    System.Diagnostics.Debug.WriteLine(outLine.Data);
                    if (tindex >= 0)
                    {
                        SetText(label10, outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        System.Diagnostics.Debug.WriteLine(outLine.Data);
                        int    len   = eindex - (tindex + cstr.Length);
                        long   count = Convert.ToInt64(data.Substring(tindex + cstr.Length, len));
                        T_Data da    = new T_Data();
                        da.data = this.textBox4.Text;
                        if (checkBox5.Checked == true)
                        {
                            if (count != -1 && count >= Convert.ToInt64(textBox12.Text) && Convert.ToInt64(textBox12.Text) != 0)
                            {
                                counts[3] = -1;
                                return;
                            }
                            if (timer4_count == Convert.ToInt64(textBox11.Text) && Convert.ToInt64(textBox11.Text) != 0)
                            {
                                counts[3] = -1;
                                return;
                            }
                            if (count == counts[3] + 1)
                            {
                                counts[3] = counts[3] + 2;
                                da.count  = counts[3];
                                Input_Topic_Queue[3].Enqueue(da);
                            }
                        }
                    }
                }
            };
            // 啟動執行續監控push,subscribe
            Thread oThread1 = new Thread(new ParameterizedThreadStart(push));

            // 啟用執行續並提供所需資訊
            oThread1.Start(t1);
            Thread oThread2 = new Thread(new ParameterizedThreadStart(push));

            oThread2.Start(t2);
            Thread oThread3 = new Thread(new ParameterizedThreadStart(push));

            oThread3.Start(t3);
            Thread oThread4 = new Thread(new ParameterizedThreadStart(push));

            oThread4.Start(t4);
            Thread oThread5 = new Thread(new ParameterizedThreadStart(recevie));

            oThread5.Start(t1);
            Thread oThread6 = new Thread(new ParameterizedThreadStart(recevie));

            oThread6.Start(t2);
            Thread oThread7 = new Thread(new ParameterizedThreadStart(recevie));

            oThread7.Start(t3);
            Thread oThread8 = new Thread(new ParameterizedThreadStart(recevie));

            oThread8.Start(t4);
        }