Ejemplo n.º 1
0
        public void OnAllPersonsChanged()
        {
            PersonsUpdateHistory.Append("Update: ").Append(PrintPersons()).AppendLine();

            var accounts = new List <ViewerAccount>();

            if (_showMan != null)
            {
                accounts.Add(_showMan);
            }

            try
            {
                AllPersons = accounts.Concat(_players).Concat(_viewers)
                             .Where(account => account.IsConnected)
                             .ToDictionary(account => account.Name);
            }
            catch (ArgumentException exc)
            {
                throw new Exception($"OnAllPersonsChanged error: {PersonsUpdateHistory}", exc);
            }

            if (!AllPersons.ContainsKey(Name))
            {
                throw new Exception($"!AllPersons.ContainsKey({Name})! {string.Join(",", AllPersons.Keys)} {PersonsUpdateHistory}");
            }
        }
Ejemplo n.º 2
0
 private void RemovePersonFromPersonList(Person person)
 {
     if (person != null)
     {
         AllPersons.Remove(person);
     }
 }
Ejemplo n.º 3
0
 private void AddPersonToPersonList(Person person)
 {
     if (person != null && !AllPersons.Contains(person))
     {
         AllPersons.Add(person);
     }
 }
Ejemplo n.º 4
0
        private void AddPerson()
        {
            Person p = DefaultManager.Instance.DefaultPerson;

            AllPersons.Add(p);
            CurrentPerson = p;

            OpenPerson();
        }
Ejemplo n.º 5
0
        private void DeleteCurrentPerson()
        {
            MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show(string.Format("Вы действительно хотите удалить {0}?", CurrentPerson.FullName), "Подтвердите удаление", System.Windows.MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                DataManager.Instance.RemovePerson(CurrentPerson);
                AllPersons.Remove(CurrentPerson);
                OnPropertyChanged("AllPersons");
            }

            //   CurrentPerson = null;
        }
Ejemplo n.º 6
0
        internal void Disconnect(bool shoudClearInfo = false)
        {
            _communicationManager.Disconnect();

            //Обработка отключение от сервера
            if (shoudClearInfo)
            {
                CurrentPerson  = null;
                SelectedPerson = null;
                AllPersons.Clear();
            }

            IsConnected = false;
        }
Ejemplo n.º 7
0
        public void SortPerson(string sortValue)
        {
            switch (sortValue)
            {
            case "Surname":
                SortedPerson = AllPersons.OrderBy(x => x.Surname);
                return;

            case "Year":
                SortedPerson = AllPersons.OrderBy(x => x.YearOfBirth);
                return;

            default:
                return;
            }
        }
Ejemplo n.º 8
0
        private void InitializeInvalidationTimer()
        {
            InvalidationTimer = new Timer()
            {
                AutoReset = true,
                Interval  = 5000,
                Enabled   = false
            };

            InvalidationTimer.Elapsed += (sender, e) =>
            {
                if (CurrentIndex > 2)
                {
                    return;
                }
                Persons.Add(AllPersons.ElementAt(CurrentIndex++));
                InvalidateChildren();
            };

            InvalidationTimer.Start();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Подключение к серверу
        /// </summary>
        private void Connect()
        {
            Person person = new Person {
                Name = UserName
            };

            try
            {
                var callback = new ChatServiceCallback();
                callback.ChatCallbackEvent += Callback_ChatCallbackEvent;

                var joinResult = _communicationManager.Connect(serverIP: ServerIP, serverPort: ServerPort, person: person, callback: callback);

                if (!joinResult.Success)
                {
                    Disconnect();
                    LogError(joinResult);
                    return;
                }

                //Задается основной пользователь клиента
                CurrentPerson = person;

                AllPersons.Clear();
                foreach (var per in joinResult.Result.OrderBy(x => x.Name))
                {
                    AllPersons.Add(per);
                }

                IsConnected = true;
            }
            catch (Exception ex)
            {
                LogError("Не получилось подключиться к серверу: " + ex.Message);
                IsConnected = false;
            }
        }