Beispiel #1
0
        public StatisticsMainView()
        {
            InitializeComponent();

            listItems.SelectionChanged      += ListItemsView_SelectionChanged;
            datesRangeView.SelectionChanged += async(o, e) => await Refresh();

            Loaded += async(o, args) =>
            {
                using (MessageView.ShowLoad("Загрузка информации о статистике..."))
                {
                    try
                    {
                        var registrationInfo = await StatisticsManager.GetRegistrationInfo(ScenariosRepository.Scenarios);

                        var registered =
                            await Task.WhenAll(
                                ScenariosRepository.Scenarios
                                .Where(x => (x.GetIsAvailable() || !(x is RemoteScenario)) && registrationInfo.IsRegistered(x.Id))
                                .Select(x => StatisticsManager.GetStatisticsInfoForScenario(x, SystemActionSource)));

                        datesRangeView.Min = registered.Any() ? registered.Min(x => x.Since) : DateTime.Now;
                        datesRangeView.Max = DateTime.Now;
                        datesRangeView.DateSelectionItem = new Common.DateSelectionItem(DateSelection.Last24Hours);
                    }
                    catch (Exception e)
                    {
                        Log.Error("Ошибка во время загрузки статистики", e);
                    }
                }
            };

            Unloaded += (o, e) => (_currentView as IDisposable)?.Dispose();
        }
Beispiel #2
0
        private async Task ApplyInternal(bool reset = true)
        {
            try
            {
                using (MessageView.ShowLoad("Применение изменений..."))
                {
                    Repository.SaveScenario(_clonedScenario);
                    StatisticsManager.ReRegister(_clonedScenario);
                    await _clonedScenario.Initialize();

                    _clonedScenario.AfterInitilize();
                }

                IsModified = false;

                if (reset)
                {
                    if (await SetScenario(_clonedScenario))
                    {
                        Applied?.Invoke();
                    }
                }
                else
                {
                    _originalSenario = _clonedScenario; //crutch
                    Applied?.Invoke();
                }
            }
            catch (Exception e)
            {
                Log.Error($"Ошибка инициализации сценария [{_clonedScenario.Name}]", e);
            }
        }
        public SelectScenarioView(string[] selectedScenarios)
        {
            InitializeComponent();

            itemsList.SelectionChanged += (o, e) =>
            {
                var selection = itemsList.GetSelectedItems();
                if (selection.Length > 6)
                {
                    selection[0].Selected = false;
                }
            };

            btApply.Click += (o, e) => ApplyClicked?.Invoke(this, new EventsArgs <string[]>(SelectedIds));

            Loaded += async(o, e) =>
            {
                using (MessageView.ShowLoad("Загрузка информации о сценариях..."))
                {
                    var targetScenarios =
                        ScenariosRepository.Scenarios
                        .Where(x =>
                               (x.ValueType is FloatValueType ||
                                x.ValueType is StateValueType ||
                                x.ValueType is ButtonValueType ||
                                x.ValueType is ToggleValueType ||
                                x.ValueType is InfoValueType ||
                                x.ValueType is DateTimeValueType))
                        .ToArray();

                    var registrationInfo = await StatisticsManager.GetRegistrationInfo(targetScenarios);

                    targetScenarios = targetScenarios.Where(x => (x.GetIsAvailable() || !(x is RemoteScenario)) && registrationInfo.IsRegistered(x.Id)).ToArray();

                    foreach (var scenario in targetScenarios)
                    {
                        var item = new ItemView();
                        item.Icon       = Icons.Icon.ChevronRight;
                        item.Selectable = true;
                        item.Content    = scenario.Name.Length > 57 ? scenario.Name.Substring(0, 55) + "..." : scenario.Name;
                        item.Tag        = scenario.Id;
                        item.Margin     = new Thickness(2, 2, 2, 0);
                        item.Selected   = selectedScenarios?.Contains(scenario.Id) ?? false;
                        itemsList.Children.Add(item);
                    }

                    if (targetScenarios.Any())
                    {
                        lblEmpty.Visibility = Visibility.Collapsed;
                    }
                }
            };
        }
Beispiel #4
0
        private async Task Refresh()
        {
            if (_currentView == null)
            {
                AppendView(new DiagramView());
            }
            else
            {
                var dateSince = datesRangeView.DateSelectionItem.Start;
                var dateTo    = datesRangeView.DateSelectionItem.End;

                using (MessageView.ShowLoad("Загрузка информации о статистике..."))
                {
                    try
                    {
                        var registrationInfo = await StatisticsManager
                                               .GetRegistrationInfo(
                            ScenariosRepository
                            .Scenarios
                            .Where(z =>
                                   _filter.All || (_filter.ScenariosIds?.Contains(z.Id) ?? false))
                            .ToArray());

                        var statisticScenariosInfos =
                            await Task.WhenAll(
                                ScenariosRepository
                                .Scenarios
                                .Where(x => (x.GetIsAvailable() || !(x is RemoteScenario)) && registrationInfo.IsRegistered(x.Id))
                                .Select(x => StatisticsManager.GetStatisticsInfoForScenario(x, SystemActionSource)));

                        var items =
                            await Task.WhenAll(
                                statisticScenariosInfos
                                .Select(x => StatisticsManager.GetItems(x, dateSince, dateTo, SystemActionSource)));

                        _currentView.RefreshItems(items, dateSince, dateTo);
                    }
                    catch (Exception e)
                    {
                        Log.Error("Ошибка во время загрузки статистики", e);
                    }
                }
            }
        }
        public void RefreshWith(ZWaveManager manager, Node node = null, byte paramId = 0)
        {
            _manager     = manager;
            SelectedNode = node;
            if (_manager.State == ZWaveManagerState.None)
            {
                _manager.Initialize();
            }
            if (_manager.State == ZWaveManagerState.Initializing)
            {
                var token = MessageView.ShowLoad("Инициализация контроллеров...", gridExternalContent);
                _manager.ManagerInitializedCallbacksPool.Add(new ManagerInitializedCallback()
                {
                    RemoveAfterInvoke = true,
                    Callback          = (s, args) => {
                        token.Cancel();
                        if (args.Successful)
                        {
                            Refresh();
                        }
                        else
                        {
                            MessageView.ShowMessage("Ошибка инициализации контроллеров.", "Ошибка", LazuriteUI.Icons.Icon.Cancel);
                        }
                    }
                });
            }
            if (_manager.State == ZWaveManagerState.Initialized)
            {
                Refresh();
            }
            if (!_manager.GetControllers().Any())
            {
                ControllersManagerView.Show(_manager, gridExternalContent, Refresh);
            }

            tbId.Text = paramId.ToString();
        }
Beispiel #6
0
 public void RefreshWith(ZWaveManager manager, NodeValue selectedValue = null, Func <NodeValue, bool> comparability = null)
 {
     _manager          = manager;
     _comparability    = comparability;
     SelectedNodeValue = selectedValue;
     if (_manager.State == ZWaveManagerState.None)
     {
         _manager.Initialize();
     }
     if (_manager.State == ZWaveManagerState.Initializing)
     {
         var token = MessageView.ShowLoad("Инициализация контроллеров...", this.gridExternalContent);
         _manager.ManagerInitializedCallbacksPool.Add(new ManagerInitializedCallback()
         {
             RemoveAfterInvoke = true,
             Callback          = (s, args) => {
                 token.Cancel();
                 if (args.Successful)
                 {
                     Refresh();
                 }
                 else
                 {
                     MessageView.ShowMessage("Ошибка инициализации контроллеров.", "Ошибка", LazuriteUI.Icons.Icon.Cancel);
                 }
             }
         });
     }
     if (_manager.State == ZWaveManagerState.Initialized)
     {
         Refresh();
     }
     if (!_manager.GetControllers().Any())
     {
         ControllersManagerView.Show(_manager, this.gridExternalContent, Refresh);
     }
 }
Beispiel #7
0
        public RemoteScenarioView(RemoteScenario scenario)
        {
            InitializeComponent();
            Refresh(scenario);

            tbPort.Validation = (v) => EntryViewValidation.UShortValidation().Invoke(v);

            tbServiceName.TextChanged    += (o, e) => ApplyCurrent();
            tbSecretCode.PasswordChanged += (o, e) => ApplyCurrent();
            tbPort.TextChanged           += (o, e) => ApplyCurrent();
            tbPassword.PasswordChanged   += (o, e) => ApplyCurrent();
            tbLogin.TextChanged          += (o, e) => ApplyCurrent();
            tbHost.TextChanged           += (o, e) => ApplyCurrent();
            btExitingCredentials.Click   += (o, e) => {
                var credentialsSelect = new ExistingConnectionSelect(ClientFactory.ConnectionCredentials);
                var dialog            = new DialogView(credentialsSelect);
                credentialsSelect.SelectedCredentialsChanged += (o1, args) => {
                    tbHost.Text           = args.Value.Host;
                    tbLogin.Text          = args.Value.Login;
                    tbPassword.Password   = args.Value.Password;
                    tbPort.Text           = args.Value.Port.ToString();
                    tbSecretCode.Password = args.Value.SecretKey;
                    tbServiceName.Text    = args.Value.ServiceName;
                    Modified?.Invoke();
                    dialog.Close();
                };
                dialog.Show();
            };
            btScenariosList.Click += (o, e) =>
            {
                try
                {
                    var remoteScenarios = _scenario.GetServer().GetScenariosInfo().Decrypt(_scenario.Credentials.SecretKey).ToArray();
                    if (!remoteScenarios.Any())
                    {
                        throw new Exception("На удаленном сервере отсутсвуют сценарии.");
                    }
                    var selectScenarioControl = new RemoteScenarioSelect(remoteScenarios, _scenario.RemoteScenarioId);
                    var dialog = new DialogView(selectScenarioControl);
                    selectScenarioControl.ScenarioInfoSelected += (info) =>
                    {
                        dialog.Close();
                        _scenario.RemoteScenarioId   = info.ScenarioId;
                        _scenario.RemoteScenarioName = info.Name;
                        tbScenario.Text = _scenario.RemoteScenarioName;
                        var loadWindowCloseToken = MessageView.ShowLoad("Соединение с удаленным сервером...");
                        _scenario.InitializeAsync((result) =>
                        {
                            loadWindowCloseToken.Cancel();
                            Dispatcher.BeginInvoke(new Action(() => {
                                if (result)
                                {
                                    Modified?.Invoke();
                                    Succeed?.Invoke();
                                }
                                else
                                {
                                    WarningHandler.Error("Невозможно получить список сценариев.");
                                    Failed?.Invoke();
                                }
                            }));
                        });
                    };
                    dialog.Show();
                }
                catch (Exception exception)
                {
                    WarningHandler.Error("Невозможно получить список сценариев.", exception);
                    Failed?.Invoke();
                }
            };
            btTest.Click += (o, e) => {
                var loadWindowCloseToken = MessageView.ShowLoad("Соединение с удаленным сервером...");
                _scenario.InitializeAsync((result) => {
                    loadWindowCloseToken.Cancel();
                    if (result)
                    {
                        MessageView.ShowMessage("Соединение успешно!", "Тест удаленного сценария", Icons.Icon.Check);
                        Dispatcher.BeginInvoke(new Action(() => Succeed?.Invoke()));
                    }
                    else
                    {
                        MessageView.ShowMessage("Невозможно активировать удаленный сценарий!", "Тест удаленного сценария", Icons.Icon.Cancel);
                        Dispatcher.BeginInvoke(new Action(() => Failed?.Invoke()));
                    }
                });
            };
        }