コード例 #1
0
ファイル: Repository.cs プロジェクト: stwehrli/IOnEx
 public void Remove(Room room)
 {
     db.Rooms.Remove(room);
     db.SaveChanges();
 }
コード例 #2
0
ファイル: IOnExHub.cs プロジェクト: stwehrli/IOnEx
        /// <summary>
        /// Called from client after connection is established
        /// </summary>
        /// <returns>True if join was successful</returns>
        public bool Join()
        {
            // Check the user id cookie
            Cookie clientIdCookie;
            if (!Context.RequestCookies.TryGetValue("IOnExId", out clientIdCookie))
            {
                return false;
            }

            //Check the user
            Client client = db.GetClientById(clientIdCookie.Value);
            if (client == null)
            {
                client = new Client
                {
                    ClientId = clientIdCookie.Value,
                    Name = clientIdCookie.Value.Substring(0, 8),
                    ConnectionId = Context.ConnectionId,
                    IsAdmin = false,
                    IsMonitor = false,
                    IsOnline = true,
                    TimeCreated = DateTime.Now,
                    TimeLastActive = DateTime.Now
                };

                db.Add(client);
                Clients.Caller.addMessage("Added Client: " + client.ClientId);
                client = db.GetClientById(clientIdCookie.Value);
            }
            else
            {
                client.IsOnline = true;
                client.ConnectionId = Context.ConnectionId;
                client.TimeLastActive = DateTime.Now;
            }

            //Check the connection
            Connection connection = db.GetConnectionById(Context.ConnectionId);
            if (connection == null)
            {
                // Get request object
                var request = Context.Request.GetHttpContext().Request;

                //Add a client
                connection = new Connection
                {
                    ConnectionId = Context.ConnectionId,
                    IsActive = true,
                    TimeCreated = DateTime.Now,
                    Ip = request.ServerVariables["REMOTE_ADDR"].ToString(),
                    TimeLastActive = DateTime.UtcNow
                };

                db.Add(connection);
                connection = db.GetConnectionById(Context.ConnectionId);
                //Clients.Caller.addMessage("Added connection: " + Context.ConnectionId);
            }

            // Check room
            Room room = db.GetRoomByName("Entrance");
            if (room == null)
            {
                room = new Room { Name = "Entrance" };
                db.Add(room);
                db.CommitChanges();
                room = db.GetRoomByName("Entrance");
            }

            // Add user, room, group, and connection
            var roomUser = room.Clients.FirstOrDefault(r => r.ClientId == client.ClientId);
            if (roomUser == null)
            {
                room.Clients.Add(client);
            }
            Groups.Add(Context.ConnectionId, "Entrance");

            //Join the two
            client.Connections.Add(connection);
            connection.Client = client;
            db.CommitChanges();

            // Notify group members
            UpdateUserList();

            Clients.Caller.addMessage(Short(Context.ConnectionId) + " has joined.");
            return true;
        }
コード例 #3
0
ファイル: Repository.cs プロジェクト: stwehrli/IOnEx
 public void Add(Room room)
 {
     db.Rooms.Add(room);
     db.SaveChanges();
 }