Esempio n. 1
0
        /// <summary>
        /// Update read message
        /// </summary>
        /// <param name="id"></param>
        /// <param name="readMessage"></param>
        /// <returns></returns>
        public async Task <int> Update(int id, ReadMessage readMessage)
        {
            try
            {
                var oldReadMessage = Load(id);

                if (oldReadMessage == null)
                {
                    throw new NotFoundException(Errors.ReadMessageNotFound);
                }

                //Update read message fields
                oldReadMessage.UpdateModifiedFields(readMessage, ref _context);

                _context.Update(oldReadMessage);

                await _context.SaveChangesAsync();

                return(oldReadMessage.Id);
            }
            catch
            {
                throw;
            }
        }
Esempio n. 2
0
        public static void SendUnreadPrivateMessageToClient(object data)
        {
            int        userId   = (int)data;
            ClientInfo clientTo = listClients.FirstOrDefault(x => x.UserId == userId);

            using (DataModelContainer db = new DataModelContainer())
            {
                int[] messIds    = db.ReadMessages.Where(x => x.User_Id == userId && x.IsRead == false).Select(x => x.Message_Id).ToArray();
                var   unreadMess = db.Messages.Where(x => (x.UserTo_Id == userId && x.IsRead == false) || messIds.Contains(x.Id)).OrderBy(x => x.Date); // все непрочитанные сообщения, личные и групповые

                foreach (var mess in unreadMess)
                {
                    if (mess.UserTo_Id != null) //личное сообщение
                    {
                        bool res = clientTo.callback.ReceivePrivateMessage(GetLoginFrom(mess), GetLoginTo(mess), mess.Text, mess.Date);
                        if (res)
                        {
                            mess.IsRead = true;
                            db.Entry(mess).Property(c => c.IsRead).IsModified = true;
                        }
                    }
                    else //групповое сообщение
                    {
                        bool res = clientTo.callback.ReceivePrivateMessage(GetLoginFrom(mess), GetGroupTo(mess), mess.Text, mess.Date);
                        if (res)
                        {
                            ReadMessage rm = db.ReadMessages.FirstOrDefault(x => x.Message_Id == mess.Id && x.User_Id == userId);
                            rm.IsRead = true;
                            db.Entry(rm).Property(c => c.IsRead).IsModified = true;
                        }
                    }
                }
                db.SaveChanges();
            }
        }
Esempio n. 3
0
        public void HandleReadMessage(ReadMessage readMessage, Socket socket)
        {
            byte readValue = _dataManager.Read(readMessage.ObjectLocation);

            SocketCommunicator.Send(socket, new ReadResponse {
                Value = readValue
            });
        }
 public async Task Raise(ReadMessage readMessage)
 {
     if (this.ReportEvent != null)
     {
         var args = new ReportEventArgs();
         this.ReportEvent(readMessage, args);
         await args.DeferAsync();
     }
 }
Esempio n. 5
0
        /// <summary>
        /// 构造字节流的分析链
        /// </summary>
        private void BuildReadFunctionChain()
        {
            ReadFunction readMessage = new ReadMessage(0, this.encrypter, this);
            ReadFunction readLength  = new ReadLength(readMessage, this.encrypter);

            readMessage.Next = readLength;
            ReadFunction readHandshake = new ReadHandshake(readLength, encrypter, this);

            this.currentFunction = readHandshake;
        }
Esempio n. 6
0
        public bool SendPrivateMessage(int idUserFrom, string idTo, string text)
        {
            using (DataModelContainer db = new DataModelContainer())
            {
                var userFrm = db.Users.FirstOrDefault(x => x.Id == idUserFrom);
                var userT   = db.Users.FirstOrDefault(x => x.Login.Equals(idTo));
                if (userT != null) //личное сообщение
                {
                    Message mess = new Message {
                        UserFrom_Id = idUserFrom, UserTo_Id = userT.Id, GroupTo_Id = null, Text = text, Date = DateTime.Now, IsRead = false
                    };
                    ReadMessage readMess = new ReadMessage {
                        Message_Id = mess.Id, User_Id = null, IsRead = false
                    };
                    db.Messages.Add(mess);
                    db.ReadMessages.Add(readMess);
                    db.SaveChanges();

                    Thread thread = new Thread(new ParameterizedThreadStart(Clients.SendPrivateMessageToClients));
                    thread.IsBackground = true;
                    thread.Start(mess);
                    return(true);
                }
                else //групповое сообщение
                {
                    var grp = db.Groups.FirstOrDefault(x => x.Name.Equals(idTo));
                    if (grp == null)
                    {
                        return(false);
                    }
                    else
                    {
                        Message mess = new Message {
                            UserFrom_Id = idUserFrom, UserTo_Id = null, GroupTo_Id = grp.Id, Text = text, Date = DateTime.Now, IsRead = null
                        };
                        db.Messages.Add(mess);

                        foreach (var us in grp.User)
                        {
                            ReadMessage readMess = new ReadMessage {
                                Message_Id = mess.Id, User_Id = us.Id, IsRead = false
                            };
                            db.ReadMessages.Add(readMess);
                        }
                        db.SaveChanges();

                        Thread thread = new Thread(new ParameterizedThreadStart(Clients.SendPrivateMessageToClients));
                        thread.IsBackground = true;
                        thread.Start(mess);
                        return(true);
                    }
                }
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            IWriteMessage message    = new WriteMessage();
            IReadMessage  input      = new ReadMessage();
            HelloWorld    helloWorld = new HelloWorld(message, input);

            helloWorld.DisplayMessageToWorld();

            Console.ReadKey();
        }
Esempio n. 8
0
    private void RecieveReadMessage(ReadMessage message)
    {
        List <int> messages = new List <int>(message.MessagesId);

        foreach (Message mess in this.messages)
        {
            if (messages.Contains(mess.Id))
            {
                mess.Readen.Add(message.Login);
            }
        }
    }
Esempio n. 9
0
        public static void SendPrivateMessageToClients(object data)
        {
            Message mess = (Message)data;

            if (mess.UserTo_Id != null) // шлем личное сообщение пользователю
            {
                ClientInfo clientTo = listClients.FirstOrDefault(x => x.UserId == mess.UserTo_Id);
                if (clientTo != null)
                {
                    bool res = clientTo.callback.ReceivePrivateMessage(GetLoginFrom(mess), GetLoginTo(mess), mess.Text, mess.Date);
                    if (res)
                    {
                        using (var db = new DataModelContainer())
                        {
                            Message message = db.Messages.FirstOrDefault(x => x.Id == mess.Id);
                            message.IsRead          = true;
                            db.Entry(message).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }
                ClientInfo clientFrom = listClients.FirstOrDefault(x => x.UserId == mess.UserFrom_Id);
                if (clientFrom != null && clientFrom != clientTo)
                {
                    clientFrom.callback.ReceivePrivateMessage(GetLoginFrom(mess), GetLoginTo(mess), mess.Text, mess.Date);
                }
            }
            else if (mess.GroupTo_Id != null) //шлем групповое сообщение
            {
                using (var db = new DataModelContainer())
                {
                    Group grp = db.Groups.FirstOrDefault(x => x.Id == mess.GroupTo_Id);
                    foreach (var us in grp.User)
                    {
                        ClientInfo client = listClients.FirstOrDefault(x => x.UserId == us.Id);
                        if (client != null)
                        {
                            bool res = client.callback.ReceivePrivateMessage(GetLoginFrom(mess), GetGroupTo(mess), mess.Text, mess.Date);
                            if (res)
                            {
                                ReadMessage rm = db.ReadMessages.FirstOrDefault(x => x.Message_Id == mess.Id && x.User_Id == client.UserId);
                                rm.IsRead          = true;
                                db.Entry(rm).State = System.Data.Entity.EntityState.Modified;
                            }
                        }
                    }
                    db.SaveChanges();
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Save read message
        /// </summary>
        /// <param name="readMessage"></param>
        /// <returns></returns>
        public async Task <int> Save(ReadMessage readMessage)
        {
            try
            {
                _context.MessagesRead.Add(readMessage);

                await _context.SaveChangesAsync();

                return(readMessage.Id);
            }
            catch
            {
                throw;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Reads the values for one or more attributes.
        /// </summary>
        public ReadResponseMessage Read(ReadMessage request)
        {
            try
            {
                lock (m_lock)
                {
                    // verify that the session is still valid.
                    VerifySession(request.RequestHeader, false);

                    // process each attribute.
                    ListOfDataValue      results         = new ListOfDataValue();
                    ListOfDiagnosticInfo diagnosticInfos = new ListOfDiagnosticInfo();

                    for (int ii = 0; ii < request.NodesToRead.Count; ii++)
                    {
                        DataValue      result         = new DataValue();
                        DiagnosticInfo diagnosticInfo = new DiagnosticInfo();

                        m_nodeManager.Read(
                            request.NodesToRead[ii],
                            result,
                            diagnosticInfo);

                        results.Add(result);
                        diagnosticInfos.Add(diagnosticInfo);
                    }

                    // return the response.
                    ReadResponseMessage response = new ReadResponseMessage();

                    response.ResponseHeader  = CreateResponseHeader(request.RequestHeader);
                    response.Results         = results;
                    response.DiagnosticInfos = diagnosticInfos;

                    return(response);
                }
            }
            catch (Exception e)
            {
                throw CreateSoapFault(request.RequestHeader, e);
            }
        }
Esempio n. 12
0
 private async Task HandleSyncedReadMessage(ReadMessage readMessage)
 {
     var updatedConversation = SignalDBContext.UpdateMessageRead(readMessage.Timestamp);
     await SignalLibHandle.Instance.DispatchMessageRead(updatedConversation);
 }
Esempio n. 13
0
 static void Main(string[] args)
 {
     ReadMessage readMessage = new ReadMessage(new VisaMap(), "020042000400000000021612345678901234560609173030123456789ABC1000123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
 }
Esempio n. 14
0
 public void OnReadMessage()
 {
     ReadMessage?.Invoke(this, new UserEventArgs(users[senderID], message));
 }
Esempio n. 15
0
        private async Task HandleSyncedReadMessage(ReadMessage readMessage)
        {
            var conv = await SignalDBContext.UpdateMessageRead(readMessage);

            await SignalLibHandle.Instance.DispatchMessageRead(conv.LastSeenMessageIndex, conv);
        }
Esempio n. 16
0
 private void _connection_OnRead(object sender, string e)
 {
     ReadMessage?.Invoke(sender, e);
 }