Exemplo n.º 1
0
        private void timer_Tick(object sender, EventArgs e)
        {
            var generators = DataProxy.Generators;
            int loadSum    = 0;

            generatorsControl.Items.Clear();

            if (!DataStorage.Connected)
            {
                MessageBox.Show("Соединение с сервером потеряно.", "Ошибка");
                _exit = false;
                Close();
            }

            if (generators != null)
            {
                foreach (var generator in generators)
                {
                    generatorsControl.Items.Add(new
                    {
                        Number = generator.Number.ToString(),
                        Load   = generator.Load.ToString()
                    });

                    loadSum += generator.Load;
                }

                if (generators.Count > 0)
                {
                    loadSum /= generators.Count;
                }

                infrastructureLoadingRate.Content = generators.Count == 0 ? "N/A" : loadSum.ToString() + "%";
            }
            else
            {
                infrastructureLoadingRate.Content = "N/A";
            }

            var tasks = DataStorage.GetData <ActiveTasks>();

            tasksConrtol.Items.Clear();

            if (tasks != null && tasks.Tasks != null)
            {
                foreach (var task in tasks.Tasks)
                {
                    tasksConrtol.Items.Add(new { User = task.Owner, Number = task.GroupNumber, Load = task.Loading });
                }
            }

            Profiles profiles = DataStorage.GetData <Profiles>();

            if (profiles != null && profiles != _profiles)
            {
                _profilesData.Clear();
                profileControl.Items.Clear();

                if (profiles.List != null)
                {
                    foreach (var profile in profiles.List)
                    {
                        _profilesData.Add(profile.Name, profile.Data);
                        profileControl.Items.Add(profile.Name);
                    }
                }

                _profiles = profiles;
            }
        }