Пример #1
0
        public bool DeleteSpaceComment(int messageId)
        {
            CheckUserId(this.UserId);
            User user;

            CheckUserId(this.UserId, out user);
            CheckMessageId(messageId);
            SysMessage systemMessage;

            CheckSpaceCommentId(messageId, user, out systemMessage);
            var messageRead = (from mr in this._messageReadRepository.GetEntityList()
                               where mr.MessageId == systemMessage.Id && mr.UserId == user.Id
                               select mr).FirstOrDefault();

            if (messageRead != null)
            {
                messageRead.State = (int)SystemMessageStateEnum.Deleted; //表示删除
                return(this._messageReadRepository.UpdateEntity(messageRead));
            }
            else
            {
                var newMessageRead = new MessageRead()
                {
                    MessageId = systemMessage.Id,
                    UserId    = user.Id,
                    State     = (int)SystemMessageStateEnum.Deleted//表示删除
                };
                return(this._messageReadRepository.CreateEntity(newMessageRead));
            }
        }
Пример #2
0
        private async Task ReadContinuouslyAsync()
        {
            while (true)
            {
                var message = new List <byte>();

                var lengthBytes = await ReadAsync(4, CancellationToken.None).ConfigureAwait(false);

                var length = BitConverter.ToInt32(lengthBytes, 0);
                message.AddRange(lengthBytes);

                var codeBytes = await ReadAsync(4, CancellationToken.None).ConfigureAwait(false);

                message.AddRange(codeBytes);

                var payloadBytes = await ReadAsync(length - 4, CancellationToken.None).ConfigureAwait(false);

                message.AddRange(payloadBytes);

                var messageBytes = message.ToArray();

                NormalizeMessageCode(messageBytes, (int)Type);

                MessageRead?.Invoke(this, new Message(messageBytes));
            }
        }
Пример #3
0
        private async Task ReadContinuouslyAsync()
        {
            ReadingContinuously = true;

            try
            {
                while (true)
                {
                    var message = new List <byte>();

                    var lengthBytes = await ReadAsync(4, CancellationToken.None).ConfigureAwait(false);

                    var length = BitConverter.ToInt32(lengthBytes, 0);
                    message.AddRange(lengthBytes);

                    var codeBytes = await ReadAsync(4, CancellationToken.None).ConfigureAwait(false);

                    message.AddRange(codeBytes);

                    var payloadBytes = await ReadAsync(length - 4, CancellationToken.None).ConfigureAwait(false);

                    message.AddRange(payloadBytes);

                    var messageBytes = message.ToArray();

                    MessageRead?.Invoke(this, messageBytes);
                }
            }
            finally
            {
                ReadingContinuously = false;
            }
        }
Пример #4
0
        public HttpResponseMessage MessageViewed(MessageRead request)
        {
            MessageViewed temp = db.MessagesViewed.SingleOrDefault(mv => mv.EmployeeID.Equals(request.employeeID) && mv.MessageID.Equals(request.messageID));

            temp.DateViewed = request.time;

            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
Пример #5
0
 private void OnMessageRead(int messageId, int chatId)
 {
     MessageRead?.Invoke(this, new MessageReadEventArgs()
     {
         ChatId    = chatId,
         MessageId = messageId
     });
 }
Пример #6
0
        public void Read(int id)
        {
            var path = Path.Combine(WorkingDirectory, id + ".txt");
            var msg  = File.ReadAllText(path);

            MessageRead?.Invoke(this, new MessageEventArgs {
                Message = msg
            });
        }
Пример #7
0
        public HttpResponseMessage MessageViewed(MessageRead request)
        {
            using (var db = new TimeClockContext())
            {
                /******************************************************************************    TODO ITEM    *********************************/
                //Need to mark the corresponding message read.
                MessageViewed temp = db.MessagesViewed.SingleOrDefault(mv => mv.EmployeeID.Equals(request.employeeID) && mv.MessageID.Equals(request.messageID));

                temp.DateViewed = request.time;

                return(new HttpResponseMessage(HttpStatusCode.Created));
            }
        }
Пример #8
0
        /// <summary>
        /// Mark the message as read by the user
        /// </summary>
        /// <param name="msgId"></param>
        /// <param name="username"></param>
        public bool SetMessageRead(int msgId, string username)
        {
            MessageRead isSet = MessageReads
                                .Where(mr => mr.MessgeId == msgId && mr.UserId == username).FirstOrDefault();

            if (isSet == null)
            {
                MessageReads.Add(new MessageRead()
                {
                    MessgeId = msgId, UserId = username
                });
            }
            return(isSet == null);
        }
Пример #9
0
        private void readmessages()
        {
            MessageRead.Clear();
            MessageRead.ScrollToCaret();
            string Read_Query = "select * from comments where Sender_ID = '" + sendertext + "' and Reciver_ID = '" + recivertext + "' or Sender_ID = '" + recivertext + "' and Reciver_ID = '" + sendertext + "' ";

            connection.Open();
            MySqlCommand    cmd = new MySqlCommand(Read_Query, connection);
            MySqlDataReader dr  = cmd.ExecuteReader();


            DateTime today = DateTime.Now;


            string text;

            while (dr.Read())
            {
                DateTime date_sent = (DateTime)dr["Date_sent"];
                MessageRead.Text += date_sent.ToString("dddd HH:mm");
                MessageRead.Text += ": ";
                MessageRead.Text += dr["Sender_ID"].ToString();
                MessageRead.Text += ": ";
                if (dr["Important"].ToString() == "1")
                {
                    MessageRead.Text += "<<<IMPORTANT>>>";
                }
                string message = dr["message"].ToString();



                using (Aes myAes = Aes.Create())
                {
                    text = SendClass.Decrypt(message);
                }

                MessageRead.Text += text.ToString();

                if (dr["Important"].ToString() == "1")
                {
                    MessageRead.Text += "<<<IMPORTANT>>>";
                }
                MessageRead.Text += (Environment.NewLine);
            }

            connection.Close();
        }
Пример #10
0
        public void Parse()
        {
            try
            {
                int type = 0;
                var bb   = new BitBuffer(Data);
                while (bb.BitsLeft > NetMessageBits && !ShouldStop)
                {
                    var dataBitWriter        = new BitWriterDeluxe();
                    var withoutTypeBitWriter = new BitWriterDeluxe();
                    int startIndex           = bb.CurrentBit;

                    type = (int)bb.ReadUnsignedBits(NetMessageBits);
                    MessageTypeRead?.Invoke(this, new MessageReceivedEventArgs(type, bb));
                    int withoutTypeIndex = bb.CurrentBit;

                    MsgHandler handler;
                    if (Handlers.TryGetValue((uint)type, out handler))
                    {
                        handler(bb);
                        dataBitWriter.WriteRangeFromArray(Data, startIndex, bb.CurrentBit);
                        withoutTypeBitWriter.WriteRangeFromArray(Data, withoutTypeIndex, bb.CurrentBit);

                        var bytes  = dataBitWriter.Data;
                        var bytes2 = withoutTypeBitWriter.Data;
                        MessageRead?.Invoke(this, new DataReadEventArgs(bytes, dataBitWriter, bytes2, withoutTypeBitWriter, type));
                    }
                    else
                    {
                        throw new Exception("Unknown packet type found.");
                    }
                }

                PacketSuccessfullyRead?.Invoke(this, new EventArgs());
            }
            catch (Exception e)
            {
                ExceptionThrown?.Invoke(this, new ExceptionEventArgs(e));
            }
        }
Пример #11
0
 private void SendMessage(Message m)
 {
     MessageRead.Raise(this, m);
 }
Пример #12
0
 protected void OnMessageRead(Message message)
 {
     MessageRead?.Invoke(this, new MessageEvent(message));
 }
Пример #13
0
 public bool DeleteEntity(MessageRead entity)
 {
     return(base.DeleteEntity <MessageRead>(entity));
 }
Пример #14
0
 public bool UpdateEntity(MessageRead entity)
 {
     return(base.UpdateEntity <MessageRead>(entity));
 }
Пример #15
0
 public bool CreateEntity(MessageRead entity)
 {
     return(base.CreateEntity <MessageRead>(entity));
 }