public static GroupRoomMemberAddedIntegrationEvent For(RoomEntities.GroupRoom room, User addedMember)
        {
            var members = room.Members
                          .Select(m => new Member
            {
                Id   = m.UserId,
                Name = m.User.Name,
                Tag  = m.User.Tag
            })
                          .ToArray();

            var roomData = new GroupRoom
            {
                Name    = room.Name,
                OwnerId = room.OwnerId,
                Members = members
            };

            var memberData = new Member
            {
                Id   = addedMember.Id,
                Name = addedMember.Name,
                Tag  = addedMember.Tag
            };

            return(new GroupRoomMemberAddedIntegrationEvent(room.Id, roomData, memberData));
        }
 public EditGroupRoomPOPUP(GroupRoom gr)
 {
     InitializeComponent();
     txtBx_roomName.Text      = gr.Name;
     this.name                = gr.Name;
     chkBx_whiteboard.Checked = gr.Whiteboard;
     chkBx_whiteboard.Checked = gr.Monitor;
 }
Пример #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            GroupRoom groupRoom = db.GroupRooms.Find(id);

            db.GroupRooms.Remove(groupRoom);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
 public ActionResult Edit([Bind(Include = "GroupRoomId,RoomNumber,Status,capacity")] GroupRoom groupRoom)
 {
     if (ModelState.IsValid)
     {
         db.Entry(groupRoom).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(groupRoom));
 }
Пример #5
0
        public void createGroup(GroupRoom group)
        {
            JsonObject data = new JsonObject();

            data.Add("leader", group.Leader.Id);
            data.Add("isGroup", true);
            data.Add("command", (int)DispatcherCodes.CREATE_ROOM);
            data.Add("id", group.Id);
            data.Add("alias", group.Alias);
            send(data);
            sendDone.WaitOne();
        }
Пример #6
0
        // GET: GroupRooms/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GroupRoom groupRoom = db.GroupRooms.Find(id);

            if (groupRoom == null)
            {
                return(HttpNotFound());
            }
            return(View(groupRoom));
        }
Пример #7
0
        protected void receiveIncomingConfig(JsonValue data)
        {
            var             users     = data["users"];
            var             rooms     = data["rooms"];
            List <UserRoom> userRooms = new List <UserRoom>();

            foreach (JsonObject item in users)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    UserChat u;
                    Users.getInstance().UserCollection.Add(u = new UserChat()
                    {
                        Alias      = item["alias"],
                        Id         = item["id"],
                        PUBLIC_KEY = Convert.FromBase64String(item["PKEY"]),
                        Status     = (UserStatus)Convert.ToInt32(item["status"].ToString().Replace(@"\", "").Replace("\"", ""))
                    });
                }, DispatcherPriority.ContextIdle);
            }
            foreach (JsonObject room in rooms)
            {
                RSACryptoServiceProvider decryptor = new RSACryptoServiceProvider();
                decryptor.ImportCspBlob(RSAprovider.ExportCspBlob(true));
                Application.Current.Dispatcher.Invoke(() =>
                {
                    GroupRoom gr = new GroupRoom()
                    {
                        Alias      = room["alias"],
                        Id         = room["id"],
                        PUBLIC_KEY = Convert.FromBase64String(room["PKEY"]),
                        Key        = decryptor.Decrypt(Convert.FromBase64String(room["key"]), false),
                        IV         = decryptor.Decrypt(Convert.FromBase64String(room["iv"]), false)
                    };
                    Rooms.getInstance().RoomsList.Add(gr);
                    foreach (JsonPrimitive subscriberId in room["subscribers"])
                    {
                        UserChat _subscriber = Users.getInstance().UserCollection.FirstOrDefault(s => s.Id == subscriberId);
                        if (_subscriber != null)
                        {
                            gr.Subscribers.Add(_subscriber);
                        }
                    }
                }, DispatcherPriority.ContextIdle);
            }
            Application.Current.Dispatcher.Invoke(modelPopulatedChanged, DispatcherPriority.ContextIdle);
        }
Пример #8
0
        private void newGroupBtn_Click(object sender, RoutedEventArgs e)
        {
            GroupRoom room = new GroupRoom()
            {
                Alias  = texboxNewGroup.Text,
                Id     = Guid.NewGuid().ToString().Substring(0, 6),
                Leader = User.getInstance().UserAdp
            };
            ObservableCollection <UserChat> newUsers = Users.getInstance().UserCollection;

            foreach (UserChat n in newUsers)
            {
                room.Subscribers.Add(n);
            }
            Rooms.getInstance().RoomsList.Add(room);
            newRoomEvent(room);
        }
Пример #9
0
 public ActionResult Create([Bind(Include = "GroupRoomId,RoomNumber,Status,capacity")] GroupRoom groupRoom)
 {
     if (ModelState.IsValid)
     {
         if (Logic.CheckRoomNumber(groupRoom.RoomNumber) == false)
         {
             groupRoom.Status = "Available";
             db.GroupRooms.Add(groupRoom);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("", "Room Number Already exists , please use another combination");
             return(View(groupRoom));
         }
     }
     return(View(groupRoom));
 }
Пример #10
0
        public List <GroupRoom> GetGroupRooms()
        {
            List <GroupRoom> groupRooms = new List <GroupRoom>();

            using (var con = new DBCon())
            {
                string        sqlCommand = "SELECT * FROM [GroupRoom]";
                SqlDataReader rs         = con.ExecuteStringGet(sqlCommand);

                while (rs.Read())
                {
                    bool whiteboard = (bool)rs.GetValue(2);
                    bool monitor    = (bool)rs.GetValue(2);

                    GroupRoom room = new GroupRoom(rs.GetInt32(0), rs.GetString(1), whiteboard, monitor);
                    groupRooms.Add(room);
                }
            }
            return(groupRooms);
        }
Пример #11
0
        public GroupChat(GroupRoom item)
        {
            InitializeComponent();
            sock         = SocketConnection.getInstance();
            this.item    = item;
            messageSent += new SendMessage(sock.sendMessage);
            UserChat temp = item.Subscribers.FirstOrDefault(x => x.Alias.Equals("Você"));

            if (temp != null)
            {
                item.Subscribers.Remove(temp);
            }
            item.Subscribers.Add(new UserChat()
            {
                Alias = "Você",
                Id    = User.getInstance().Id
            });
            usersConversationView.ItemsSource = item.Subscribers;
            chats.ItemsSource = item.Chat.col;
            this.DataContext  = new
            {
                room = item
            };
        }
Пример #12
0
        public async Task <Result <RoomModel> > CreateAsync(string userId, string[] othersIds)
        {
            var othersCount = othersIds.Length;

            if (othersCount == 0 || othersCount > 9)
            {
                var error = Errors.InvalidOtherUsersCount(othersCount);
                return(Result <RoomModel> .Failure(error));
            }

            var user = await _context.Set <User>()
                       .SingleOrDefaultAsync(u => u.Id == userId);

            if (user is null)
            {
                var error = Errors.UserNotFound(userId);
                return(Result <RoomModel> .Failure(error));
            }

            var otherUsers = await _context.Set <Connection>()
                             .Include(u => u.OtherUser)
                             .Where(u => u.UserId == userId)
                             .Where(u => othersIds.Contains(u.OtherId))
                             .Where(u => u.Relationship == RelationshipEnum.Friend)
                             .ToListAsync();

            var errors = new List <string>();

            foreach (var otherId in othersIds)
            {
                var otherUserExists = otherUsers.Exists(r => r.OtherId == otherId);

                if (!otherUserExists)
                {
                    var error = Errors.UnableToAddNonFriendToRoom(otherId);
                    errors.Add(error);
                }
            }

            if (errors.Count > 0)
            {
                return(Result <RoomModel> .Failure(errors.ToArray()));
            }

            Room room;

            if (othersCount < 2)
            {
                var otherId    = othersIds.First();
                var roomExists = await _context.Set <Room>()
                                 .Where(r => r.Type == RoomType.Private)
                                 .Where(r => r.Members.Any(m => m.UserId == userId))
                                 .Where(r => r.Members.Any(m => m.UserId == otherId))
                                 .AnyAsync();

                if (roomExists)
                {
                    var error = Errors.PrivateRoomAlreadyExists(userId, otherId);
                    return(Result <RoomModel> .Failure(error));
                }

                room = new Room();
            }
            else
            {
                room = new GroupRoom()
                {
                    OwnerId = userId
                };
            }

            await _context.AddAsync(room);

            _context.Set <Member>().Add(new Member {
                RoomId = room.Id, UserId = userId
            });

            foreach (var other in otherUsers)
            {
                var member = new Member
                {
                    RoomId = room.Id,
                    UserId = other.OtherId
                };

                _context.Set <Member>().Add(member);
            }

            await _context.SaveChangesAsync();

            var roomCreatedEvent = RoomCreatedIntegrationEvent.For(room);
            await _integrationEventService.SaveEventsAndUsersContextChangesAsync(roomCreatedEvent);

            await _integrationEventService.PublishThroughEventBusAsync(roomCreatedEvent);

            var model = RoomModel.MapFrom(room);

            return(Result <RoomModel> .SuccessWith(model));
        }
Пример #13
0
        public void actionHandler(String response)
        {
            if (response.GetType() == typeof(string))
            {
                var json = JsonValue.Parse((String)response);
                if (json["command"] == (int)DispatcherCodes.CONNECT)
                {
                    receiveIncomingConfig(json);
                }
                else if (json["command"] == (int)DispatcherCodes.SEND)
                {
                    forwardChat(json);
                }
                else if (json["command"] == (int)DispatcherCodes.NEW_USER)
                {
                    UserChat newUser = new UserChat()
                    {
                        Alias      = json["alias"],
                        Id         = json["id"],
                        Status     = (UserStatus)Convert.ToInt32(json["status"].ToString()),
                        PUBLIC_KEY = Convert.FromBase64String(json["PKEY"]),
                    };
                    foreach (JsonValue item in json["groups"])
                    {
                        String    groupId = item.ToString().Replace(@"\", "").Replace("\"", "");
                        GroupRoom room    = (GroupRoom)Rooms.getInstance().RoomsList.FirstOrDefault(x => x.Id == groupId);
                        if (room != null)
                        {
                            room.Subscribers.Add(newUser);
                        }
                    }

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        Users.getInstance().UserCollection.Add(newUser);
                    }, DispatcherPriority.ContextIdle);
                }
                else if (json["command"] == (int)DispatcherCodes.QUIT)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        UserChat user = Users.getInstance().UserCollection.FirstOrDefault(x => x.Id == json["user"]);
                        Users.getInstance().UserCollection.Remove(user);
                    }, DispatcherPriority.ContextIdle);
                }
                else if (json["command"] == (int)DispatcherCodes.STATUS_UPDATE)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        UserChat _user = Users.getInstance().UserCollection.FirstOrDefault(s => s.Id == json["user"]);
                        if (_user != null)
                        {
                            Users.getInstance().UserCollection.Remove(_user);
                            _user.Status = (UserStatus)Convert.ToInt32(json["status"].ToString().Replace(@"\", "").Replace("\"", ""));
                            Users.getInstance().UserCollection.Add(_user);
                        }
                    }, DispatcherPriority.ContextIdle);
                }
                else if (json["command"] == (int)DispatcherCodes.NEW_ROOM)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        GroupRoom room   = new GroupRoom();
                        room.Alias       = json["alias"];
                        room.Id          = json["id"];
                        room.PUBLIC_KEY  = Convert.FromBase64String(json["key"]);
                        UserChat _leader = Users.getInstance().UserCollection.FirstOrDefault(x => x.Id == json["leader"]);
                        room.Leader      = _leader;
                        foreach (JsonValue item in json["subscribers"])
                        {
                            String userId = item.ToString().Replace(@"\", "").Replace("\"", "");
                            UserChat user = Users.getInstance().UserCollection.FirstOrDefault(x => x.Id == userId);
                            if (user != null)
                            {
                                room.Subscribers.Add(user);
                            }
                        }
                        Rooms.getInstance().RoomsList.Add(room);
                    }, DispatcherPriority.ContextIdle);
                }
                else if (json["command"] == (int)DispatcherCodes.DROP_USER)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        GroupRoom room = (GroupRoom)Rooms.getInstance().RoomsList.FirstOrDefault(x => x.Id == json["room_id"]);
                        UserChat user  = Users.getInstance().UserCollection.FirstOrDefault(x => x.Id == json["user_id"]);
                        if (user == null)
                        {
                            if (dropped != null)
                            {
                                dropped();
                            }
                            else
                            {
                                MessageBox.Show("alguém removeu você de um grupo...");
                            }
                            Rooms.getInstance().RoomsList.Remove(room);
                        }
                        room.Subscribers.Remove(user);
                    }, DispatcherPriority.ContextIdle);
                }
            }
            response = null;
        }
 public GroupRoomMemberAddedIntegrationEvent(int roomId, GroupRoom room, Member addedMember)
 {
     RoomId      = roomId;
     Room        = room;
     AddedMember = addedMember;
 }