Пример #1
0
        static void Main(string[] args)
        {
            var developer = new Person()
            {
                DateOfBirth = new DateTime(1987, 08, 20),
                FirstName   = "Christian",
                LastName    = "Nikolov",
                Height      = 187,
                Id          = 35
            };
            var headOfRecruitment = new Person()
            {
                DateOfBirth = new DateTime(1991, 05, 02),
                FirstName   = "Radostina",
                LastName    = "Maneva",
                Height      = 173,
                Id          = 1
            };
            var chatRoom   = new ChatRoom();
            var subscriber = new Subscriber("Jonathan Green");

            chatRoom.Publish += subscriber.Notify;

            chatRoom.Add(developer);
            chatRoom.Add(headOfRecruitment);
            chatRoom.Schedule(1000 * 60);
            chatRoom.Remove();


            Console.ReadLine();
        }
Пример #2
0
        public void AddActor(Actor a)
        {
            string id = string.Format("{0}_{1}", a.ActorId, a.ActorName);

            if (!ChatRoom.ContainsKey(id))
            {
                ChatRoom.Add(id, a);
            }
        }
Пример #3
0
        public void GivenAChatRoomThatContains(string chatRoomName, Table table)
        {
            var chatRoom = new ChatRoom(chatRoomName);

            _context.Register(chatRoom);
            foreach (var row in table.Rows)
            {
                var user = _context.LocateUser(row[0]);
                chatRoom.Add(user);
            }
        }
Пример #4
0
        public static void Update(Guid objID, Message message)
        {
            var      current = GetAll <ChatRoom>();
            ChatRoom obj     = current.First(r => r.ID == objID);

            obj.Add(message);
            File.WriteAllText(fileMap[typeof(ChatRoom)], JsonSerializer.Serialize(current, new JsonSerializerOptions()
            {
                WriteIndented = true
            }));
        }
Пример #5
0
        private void AddActor(ChatMessage msg)
        {
            string id = string.Format("{0}_{1}", msg.ChatActor.ActorId, msg.ChatActor.ActorName);

            if (!ChatRoom.ContainsKey(id))
            {
                ChatRoom.Add(id, msg.ChatActor);
            }
            else
            {
                Console.WriteLine("Client with that ID already in chatroom...");
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            var chatRoom = new ChatRoom();

            var userFromMobile  = new UserFromCellPhone(chatRoom);
            var userFromDesktop = new UserFromDesktop(chatRoom);
            var userFromWeb     = new UserFromWeb(chatRoom);

            var observerList = new List <IObserver> {
                userFromWeb, userFromDesktop, userFromMobile
            };

            chatRoom.Add(observerList);

            chatRoom.SetState("state 1");

            userFromWeb.WriteLastMessageToConsole();
            userFromDesktop.WriteLastMessageToConsole();
            userFromMobile.WriteLastMessageToConsole();

            chatRoom.SetState("state 2");

            userFromWeb.WriteMessagesToConsole();
            userFromDesktop.WriteMessagesToConsole();
            userFromMobile.WriteMessagesToConsole();

            var removedObserverList = new List <IObserver> {
                userFromWeb, userFromDesktop
            };

            chatRoom.Remove(removedObserverList);

            chatRoom.SetState("state 3");

            userFromWeb.WriteMessagesToConsole();
            userFromDesktop.WriteMessagesToConsole();
            userFromMobile.WriteMessagesToConsole();

            userFromWeb.WriteLastMessageToConsole();
            userFromDesktop.WriteLastMessageToConsole();
            userFromMobile.WriteLastMessageToConsole();
        }