コード例 #1
0
        protected void btnTest_Click(object sender, EventArgs e)
        {
            int contractID = int.Parse(ddlContract.Text);
            Message msg = new Message();

            string requestParams = GetRequestParams("", "0", contractID, SlnID, txtVersion.Text);
            //StringBuilder requestParams = new StringBuilder();
            //requestParams.AppendFormat("Sid={0}&Uid={1}&ActionID={2}&ClientVersion={3}&rl=1", string.Empty, string.Empty, contractID, txtVersion.Text);
            string serverUrl = txtServerUrl.Text;
            string[] keyNames = txtKeyName.Text.Split(new char[] { ',' });

            MessageReader msgReader = MessageReader.Create(serverUrl, requestParams, msg, false);
            if (msgReader != null)
            {
                try
                {
                    if (msg.ErrorCode != 0)
                    {
                        txtResponse.Text = msg.ErrorInfo;
                    }
                    else
                    {
                        txtResponse.Text = new ParamInfoBLL().LuaConfig(SlnID, contractID, keyNames, msgReader);
                    }
                }
                catch (Exception ex)
                {
                    txtResponse.Text = ex.ToString();
                }
                finally
                {
                    msgReader.Dispose();
                }
            }
        }
コード例 #2
0
        // Helper method for filling dummy data into the Conversation table
        protected void btnInsertCommand_Click(object sender, EventArgs e)
        {
            Conversation newConvo = new Conversation();

            newConvo.ParticipantA_ID = 12;
            newConvo.ParticipantB_ID = 1;

            Message msg1 = new Message();
            msg1.SenderID = 12;
            msg1.Timestamp = DateTime.Now;
            msg1.Content = "How did you get on on Saturday";

            Message msg2 = new Message();
            msg2.SenderID = 1;
            msg2.Timestamp = DateTime.Now;
            msg2.Content = "What was on Saturday?";

            Message msg3 = new Message();
            msg3.SenderID = 1;
            msg3.Timestamp = DateTime.Now;
            msg3.Content = "Wait, oh the cinema. Yeah it was nice. Good movie, highly recommended.";

            Message msg4 = new Message();
            msg4.SenderID = 12;
            msg4.Timestamp = DateTime.Now;
            msg4.Content = "Which film was it again?";

            newConvo.MessagesList.Add(msg1);
            newConvo.MessagesList.Add(msg2);
            newConvo.MessagesList.Add(msg3);
            newConvo.MessagesList.Add(msg4);

            messageManager.InsertIntoConvoTable(newConvo);
        }
コード例 #3
0
 //赋值List
 private List<Message> initMessageList(List<Model.hp_message> list)
 {
     List<Message> newlist = new List<Message>();
     for (int i = 0; i < list.Count(); i++)
     {
         Message message = new Message(list[i]);
         newlist.Add(message);
     }
     return newlist;
 }
コード例 #4
0
        public override void OnGet()
        {
            ViewData["Title"] = "一起帮 😀 系统消息";
            base.OnGet();
            PageSize = 3;
            PageUp   = PageIndex + 7;
            PageDown = PageIndex - 7;

            if (PageDown < 1)
            {
                PageDown = 1;
            }

            PageAction = 7 * (PageIndex / 7);
            if (PageAction == 0)
            {
                PageAction = 1;
            }
            Messages = _messageReporsitory.GetList(PageIndex, PageSize).ToList();
            BLL.Message message = new BLL.Message();
        }
コード例 #5
0
 protected void btnSaveHelpRequest_Click(object sender, EventArgs e)
 {
     BLL.Message msg = new BLL.Message();
     msg.AddNew();
     msg.Body = txtBody.Text;
     msg.SenderID = BLL.Member.CurrentMemberID;
     msg.Subject = txtSubject.Text;
     msg.ToMembers = lstHelpRequests.SelectedItem.Text;
     msg.Save();
     MemberMessage memberMsg = new MemberMessage();
     //add to member sent items
     memberMsg.AddNew();
     memberMsg.MessageID = msg.ID;
     memberMsg.IsRead = true;
     //add to receipent folder
     Helper.Enums.SiteMembers siteMember = Helper.EnumUtil.ParseEnum<Helper.Enums.SiteMembers>(Convert.ToInt32(lstHelpRequests.SelectedValue));
     int recipientID = BLL.Member.SiteMembers.Where(s => String.Equals(s.Name, Helper.StringEnum.GetStringValue(siteMember))).FirstOrDefault().MemberID;
     memberMsg.AddNew();
     memberMsg.MemberID = recipientID;
     memberMsg.MessageID = msg.ID;
     memberMsg.Save();
 }
コード例 #6
0
ファイル: SuggsetFactory.cs プロジェクト: duming223/HomeWork
        private static BLL.Suggest publish(string title, string body, User author)
        {
            SuggestReporsitory suggestReporsitory = new SuggestReporsitory(Helper.Context);

            BLL.Suggest suggest = new BLL.Suggest
            {
                Title  = title,
                Body   = body,
                Author = author
            };
            suggestReporsitory.Save(suggest);

            BLL.Message message = new BLL.Message
            {
                PublishTime = DateTime.Now,
                Owner       = author
            };
            MessageReporsitory messageReporsitory = new MessageReporsitory(Helper.Context);

            messageReporsitory.Save(message);

            return(suggest);
        }
コード例 #7
0
        protected void imgBtnSendMessage_Click(object sender, ImageClickEventArgs e)
        {
            /*
             * This button does three things:
             *  1. It saves the latest message to selectedConvo.MessageList.
             *  2. It sends the entire conversation to the database to be refreshed and then stored.
             *  3. It refreshes the repeater.
             *
             * The second point seems excessive as there will therefore be a database call every time
             * a message is sent. But for users who expect to be able to message one another,
             * a narrow frame of time between messages being sent and received,
             * and therefore stored in the database and fetched, is essential.
             * */

            try
            {
                // Point 1.
                Message newMessage = new Message();
                newMessage.SenderID = user.ID;
                newMessage.Timestamp = DateTime.Now;
                newMessage.Content = txtNewMessage.Text;

                selectedConversation.MessagesList.Add(newMessage);

                // Point 2.
                selectedConversation = messageManager.UpdateConvoTable(selectedConversation);

                // Point 3.
                PopulateMessageThread(selectedConversation);

                txtNewMessage.Text = "";
            }
            catch (Exception)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", "alert('Error sending message. Message not delivered.')", true);
                throw;
            }
        }
コード例 #8
0
 protected virtual void SuccessCallback(MessageReader writer, Message head)
 {
 }
コード例 #9
0
 protected virtual void FailCallback(Message head)
 {
     string msg = string.Format("出错:{0}-{1}", head.ErrorCode, head.ErrorInfo);
     _context.Response.Write(new JsonObject().Add("state", false).Add("message", msg).ToJson());
 }
コード例 #10
0
ファイル: UnitTest.aspx.cs プロジェクト: rongxiong/Scut
        private static void ProcessResult(string contractId, int slnId, StringBuilder respContent, Message msg, MessageReader msgReader, out string sid, out string uid)
        {
            sid = "";
            uid = "";
            //头部消息
            respContent.AppendFormat("<h3>{0}-{1}</h3>", contractId, "基本消息");
            respContent.Append("<table style=\"width:90%; border-color:#999\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">");
            respContent.Append("<tr><td style=\"width:25%;\"><strong>状态值</strong></td>");
            respContent.Append("<td style=\"width:75%;\"><strong>描述</strong></td></tr>");
            respContent.AppendFormat("<tr><td>{0}</td>", msg.ErrorCode);
            respContent.AppendFormat("<td>{0}&nbsp;</td></tr>", msg.ErrorInfo);
            respContent.Append("</table>");

            if (msg.ErrorCode != ErrorCode)
            {
                DataRowCollection respRecords = GetResponseFields(contractId, slnId);

                //消息体
                respContent.AppendFormat("<h3>{0}-{1}</h3>", contractId, "返回结果");
                respContent.Append("<table style=\"width:90%; border-color:#999\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">");
                respContent.Append("<tr><td style=\"width:15%;\"><strong>参数</strong></td><td style=\"width:10%;\"><strong>类型</strong></td>");
                respContent.Append("<td style=\"width:75%;\"><strong>参数值</strong></td></tr>");
                int loopDepth = 0;//循环深度
                List<DataRow> recordQueue = new List<DataRow>();
                #region 循环体
                foreach (DataRow record in respRecords)
                {
                    string fieldName = record["Field"].ToString();
                    FieldType fieldType = (FieldType)Enum.Parse(typeof(FieldType), record["FieldType"].ToString());
                    string fieldValue = "";
                    try
                    {
                        if (loopDepth > 0 && fieldType == FieldType.End)
                        {
                            loopDepth--;
                            recordQueue.Add(record);
                        }
                        if (loopDepth == 0 && recordQueue.Count > 0)
                        {
                            //处理循环记录
                            ProcessLoopRocord(respContent, recordQueue, msgReader);
                            recordQueue.Clear();
                        }

                        if (loopDepth == 0)
                        {
                            if (msgReader.GetFieldValue(fieldType, ref fieldValue))
                            {
                                //自动登录
                                if ("1004".Equals(contractId))
                                {
                                    if ("SessionID".Equals(fieldName)) sid = fieldValue;
                                    if ("UserID".Equals(fieldName)) uid = fieldValue;
                                }
                                respContent.Append("<tr>");
                                respContent.AppendFormat("<td>&nbsp;{0}</td>", fieldName);
                                respContent.AppendFormat("<td>&nbsp;{0}</td>", fieldType);
                                respContent.AppendFormat("<td>&nbsp;{0}</td>", fieldValue);
                                respContent.Append("</tr>");
                            }
                            if (fieldType == FieldType.Record)
                            {
                                loopDepth++;
                                recordQueue.Add(record);
                            }
                        }
                        else if (fieldType != FieldType.End)
                        {
                            if (fieldType == FieldType.Record)
                            {
                                loopDepth++;
                            }
                            recordQueue.Add(record);
                        }
                    }
                    catch (Exception ex)
                    {
                        respContent.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", fieldName, fieldType, ex.ToString());
                    }

                }
                #endregion

                respContent.Append("</table>");

            }
        }
コード例 #11
0
ファイル: UnitTest.aspx.cs プロジェクト: rongxiong/Scut
 private static string PostGameServer(string contractId, int slnId, string serverUrl, string requestParams, out string sid, out string uid)
 {
     sid = "";
     uid = "";
     StringBuilder respContent = new StringBuilder();
     Message msg = new Message();
     MessageReader msgReader = MessageReader.Create(serverUrl, requestParams, msg, IsSocket);
     if (msgReader != null)
     {
         try
         {
             ProcessResult(contractId, slnId, respContent, msg, msgReader, out sid, out uid);
         }
         finally
         {
             msgReader.Dispose();
         }
     }
     return respContent.ToString();
 }
コード例 #12
0
ファイル: MessageReader.cs プロジェクト: rongxiong/Scut
        public static MessageReader Create(string serverUrl, string requestParams, Message header, bool IsSocket)
        {
            MessageReader msgReader = null;
            if (IsSocket)
            {

                SocketAction socketAction = new SocketAction();
                socketAction.DoSocket(serverUrl, requestParams);
                MemoryStream ms = new MemoryStream(socketAction.result.ReadBuffer());
                BinaryReader reader = new BinaryReader(ms, Encoding.UTF8);
                msgReader = new MessageReader(reader);
            }
            else
            {
                Encoding encode = Encoding.GetEncoding("utf-8");
                string postData = "d=" + GetSign(requestParams);
                byte[] bufferData = encode.GetBytes(postData);

                HttpWebRequest serverRequest = (HttpWebRequest)WebRequest.Create(serverUrl);
                serverRequest.Method = "POST";
                serverRequest.ContentType = "application/x-www-form-urlencoded";
                serverRequest.ContentLength = bufferData.Length;
                Stream requestStream = serverRequest.GetRequestStream();
                requestStream.Write(bufferData, 0, bufferData.Length);
                requestStream.Close();

                //返回流

                WebResponse serverResponse = serverRequest.GetResponse();
                Stream responseStream = serverResponse.GetResponseStream();
                if (responseStream != null)
                {
                    BinaryReader reader = new BinaryReader(responseStream, Encoding.UTF8);
                    msgReader = new MessageReader(reader);

                    header.Length = msgReader.ReadInt();
                    header.ErrorCode = msgReader.ReadInt();
                    header.MsgID = msgReader.ReadInt();
                    header.ErrorInfo = msgReader.ReadString();
                    header.Action = msgReader.ReadInt();
                    header.St = msgReader.ReadString();
                }
            }
            return msgReader;
        }
コード例 #13
0
        public bool SendRoomFriendsBotMsg(int roomID, string message)
        {
            BLL.Room bllRoom = new Room();
            if (!bllRoom.LoadByPrimaryKey(roomID))
                return false;
            BLL.RoomMember bllRoomMember = new RoomMember();
            if (!bllRoomMember.GetRoomFriends(roomID))
                return false;
            message.Replace("\r\n", "</br>");
            List<int> recipients = bllRoomMember.DefaultView.Table.AsEnumerable().Select(m => Helper.TypeConverter.ToInt32(m[BLL.RoomMember.ColumnNames.MemberID])).ToList();
            BLL.Message msg = new BLL.Message();
            msg.AddNew();
            msg.Body = message;
            msg.SenderID = BLL.Member.CurrentMemberID;
            msg.Subject = "بوت أصدقاء الغرفة";
            msg.ToMembers = "أصدقاء غرفة -" + bllRoom.Name;
            msg.Save();
            MemberMessage memberMsg = new MemberMessage();
            //add to member sent items
            memberMsg.AddNew();
            memberMsg.MessageID = msg.ID;
            memberMsg.IsRead = true;
            foreach (int recipientID in recipients)
            {
                memberMsg.AddNew();
                memberMsg.MemberID = recipientID;
                memberMsg.MessageID = msg.ID;
            }
            memberMsg.Save();

            //send mail notifications
            NotificationHub notifications = new NotificationHub();
            for (int i = 0; i < recipients.Count; i++)
            {
                notifications.SendMailNotifications(recipients[i]);
            }

            return true;
        }
コード例 #14
0
        public bool SendMsg(int sender, string ToMember, string subject, string toName, string content)
        {
            List<int> recipients = new List<int>();
            string[] ToMembers = ToMember.Split(',');
            BLL.Message msg = new BLL.Message();
            msg.AddNew();
            msg.Body = content;
            msg.SenderID = sender;
            msg.Subject = subject;
            msg.ToMembers = toName;
            msg.Save();
            MemberMessage memberMsg = new MemberMessage();
            //add to member sent items
            memberMsg.AddNew();
            memberMsg.MessageID = msg.ID;
            memberMsg.IsRead = true;
            foreach (string item in ToMembers)
            {
                if (!string.IsNullOrEmpty(item))
                {
                    int recipientID = Convert.ToInt32(item);
                    // check if friend don't block sender
                    BlockedMembers bllBlocked = new BlockedMembers();
                    bllBlocked.Where.MemberID.Value = recipientID;
                    bllBlocked.Where.BlockID.Value = sender;
                    bllBlocked.Query.Load();
                    bool cansend = !(bllBlocked.RowCount > 0);

                    if (recipientID > 0 && !recipients.Contains(recipientID) && cansend) // cansend - check if friend don't block sender
                    {
                        recipients.Add(recipientID);
                        memberMsg.AddNew();
                        memberMsg.MemberID = recipientID;
                        memberMsg.MessageID = msg.ID;
                    }
                    else
                    {
                        recipientID = recipientID * -1;
                        if (Enum.IsDefined(typeof(Helper.Enums.AdminMailAddressAlias), recipientID))
                        {
                            Member aliasMembers = new Member();
                            aliasMembers.GetByAliase((Helper.Enums.AdminMailAddressAlias)recipientID);
                            do
                            {
                                if (!recipients.Contains(aliasMembers.MemberID))
                                {
                                    recipients.Add(aliasMembers.MemberID);
                                    memberMsg.AddNew();
                                    memberMsg.MemberID = aliasMembers.MemberID;
                                    memberMsg.MessageID = msg.ID;
                                }
                            } while (aliasMembers.MoveNext());
                        }
                    }
                }
            }

            memberMsg.Save();
            if (recipients.Count > 0)
            {
                NotificationHub notifications = new NotificationHub();
                for (int i = 0; i < recipients.Count; i++)
                {
                    notifications.SendMailNotifications(recipients[i]);
                }
            }
            return true;
        }
コード例 #15
0
ファイル: MessageReader.cs プロジェクト: 9tong/Scut
 public Message ReadHead()
 {
     var header = new Message();
     header.Length = ReadInt();
     header.ErrorCode = ReadInt();
     header.MsgID = ReadInt();
     header.ErrorInfo = ReadString();
     header.Action = ReadInt();
     header.St = ReadString();
     return header;
 }
コード例 #16
0
        protected void uiLinkButtonConfirm_Click(object sender, EventArgs e)
        {
            MembershipUser user = Membership.GetUser();

            if (user.PasswordQuestion == uiDropDownListQuestion.SelectedValue && BLL.Member.CurrentMember.Answer == uiTextBoxAnswer.Text.Trim())
            {
                if (uiHiddenFieldFriendID.Value != "")
                {

                    if (string.IsNullOrEmpty(uiTextBoxAmount.Text))
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Error2", @"$(document).ready(function () { notify('error', 'حدث خطأ . من فضلك أدخل قيمة التحويل.'); });", true);
                        return;
                    }
                    try
                    {
                        int points = Convert.ToInt32(uiTextBoxAmount.Text);
                        if (BLL.Member.CurrentMember.Credit_Point < points)
                        {
                            ClientScript.RegisterStartupScript(this.GetType(), "Error3", @"$(document).ready(function () { notify('error', 'حدث خطأ . رصيدك الحالى لا يسمح لإتمام التحويل.'); });", true);
                            return;
                        }

                        Member ToMember = new Member();
                        if (uiHiddenFieldFriendID.Value != "0" && uiHiddenFieldFriendID.Value != "")
                        {
                            ToMember.LoadByPrimaryKey(Convert.ToInt32(uiHiddenFieldFriendID.Value));
                        }
                        else
                        {
                            ClientScript.RegisterStartupScript(this.GetType(), "Error7", @"$(document).ready(function () { notify('error', 'حدث خطأ . من فضلك أختر صديق للتحويل.'); });", true);
                            return;
                        }

                        ToMember.Credit_Point += points;
                        BLL.Member.CurrentMember.Credit_Point -= points;
                        ToMember.Save();
                        BLL.Member.CurrentMember.Save();

                        BLL.Message msg = new BLL.Message();
                        msg.AddNew();
                        msg.Body = string.Format(GetLocalResourceObject("ConfirmMsgBody").ToString(),BLL.Member.CurrentMember.UserName, points.ToString());
                        msg.SenderID = BLL.Member.CurrentMemberID;
                        msg.Subject = GetLocalResourceObject("ConfirmMsgSubject").ToString();
                        msg.ToMembers = ToMember.UserName;
                        msg.Save();

                        MemberMessage memberMsg = new MemberMessage();
                        memberMsg.AddNew();
                        memberMsg.MemberID = ToMember.MemberID;
                        memberMsg.MessageID = msg.ID;
                        memberMsg.Save();

                        NotificationHub notifications = new NotificationHub();
                        notifications.SendMailNotifications(ToMember.MemberID);

                        IHubContext roomHub = GlobalHost.ConnectionManager.GetHubContext<ChatRoomHub>();
                        roomHub.Clients.Group(ToMember.UserName).updateBalance(ToMember.Credit_Point);

                        ClientScript.RegisterStartupScript(this.GetType(), "Success1", @"$(document).ready(function () { notify('success', 'تم تحويل النقاط بنجاح.'); });", true);

                        // logging
                        BLL.MemberLog log = new BLL.MemberLog();
                        log.AddNew(BLL.Member.CurrentMemberID, new BLL.Log.TransferPoints() { FromMemberName=BLL.Member.CurrentMember.Name, ToMemberName = ToMember.Name, Points = points }, ToMember.MemberID, null);

                        LoadBalance();
                        uiTextBoxAmount.Text = "";
                    }
                    catch (Exception ex)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Error11", @"$(document).ready(function () { notify('error', 'حدث خطأ . من فضلك أعد المحاولة.'); });", true);
                    }
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error7", @"$(document).ready(function () { notify('error', 'حدث خطأ . من فضلك أختر صديق للتحويل.'); });", true);
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "Error5", @"$(document).ready(function () { notify('error', 'حدث خطأ . من فضلك تأكد من السؤال والإجابة السرى.'); });", true);
                return;
            }
        }