public void Initialize(Action <ConfigurationExportSelector> onSubmit, IRuntimeConfigurationViewModel deviceConfiguration)
        {
            _onSubmit = onSubmit;
            List <SelectorForItemsGroupViewModel> selectors = new List <SelectorForItemsGroupViewModel>();

            MapConfigItemsOnSelector(selectors, ItemsGroupSelectorFunc(deviceConfiguration.RootConfigurationItemViewModels));
            Selectors            = selectors;
            IsDeviceDataPrinting = true;
            IsLocalDataPrinting  = true;
        }
        public static void ExportConfiguration(IRuntimeConfigurationViewModel deviceConfiguration,
                                               ITypesContainer typesContainer, string deviceName, string nameForUI)
        {
            var viewModel          = typesContainer.Resolve <ExportSelectionViewModel>();
            var logger             = typesContainer.Resolve <ILogService>();
            var localizer          = typesContainer.Resolve <ILocalizerService>();
            var appCommands        = typesContainer.Resolve <IApplicationGlobalCommands>();
            var nameForUiLocalized = nameForUI;

            localizer.TryGetLocalizedString(nameForUI, out nameForUiLocalized);
            ExportSelectionWindow window = new ExportSelectionWindow();

            viewModel.Initialize((async(exportSelector) =>
            {
                var sfd = new SaveFileDialog
                {
                    Filter = " HTML файл (*html)|*html" + "|Все файлы (*.*)|*.* ",
                    DefaultExt = ".html",
                    FileName = $"{nameForUiLocalized} {deviceName}"
                };
                if (sfd.ShowDialog() == true)
                {
                    try
                    {
                        viewModel.IsSavingInProcess = true;
                        File.WriteAllText(sfd.FileName,
                                          await typesContainer
                                          .Resolve <IHtmlRenderer <IRuntimeConfigurationViewModel, ConfigurationExportSelector> >()
                                          .RenderHtmlString(deviceConfiguration, exportSelector));
                        logger.LogMessage(ApplicationGlobalNames.StatusMessages.FILE_EXPORT_SUCCESSFUL);
                        viewModel.IsSavingInProcess = false;
                        window.Close();
                    }
                    catch (Exception e)
                    {
                        logger.LogMessage(e.Message + Environment.NewLine + e.StackTrace, LogMessageTypeEnum.Error);
                    }
                }
            }), deviceConfiguration);
            appCommands.ShowWindowModal(() => window, viewModel);
        }
Esempio n. 3
0
        public IFragmentOptionsViewModel CreateConfigurationFragmentOptionsViewModel(
            IRuntimeConfigurationViewModel runtimeConfigurationViewModel, ITypesContainer container,
            IDeviceConfiguration deviceConfiguration)
        {
            _runtimeConfigurationViewModel = runtimeConfigurationViewModel;
            _container           = container;
            _deviceConfiguration = deviceConfiguration;
            Func <IFragmentOptionGroupViewModel> fragmentOptionGroupViewModelGettingFunc =
                container.Resolve <Func <IFragmentOptionGroupViewModel> >();
            Func <IFragmentOptionCommandViewModel> fragmentOptionCommandViewModelGettingFunc =
                container.Resolve <Func <IFragmentOptionCommandViewModel> >();

            IFragmentOptionsViewModel fragmentOptionsViewModel = container.Resolve <IFragmentOptionsViewModel>();


            fragmentOptionsViewModel.FragmentOptionGroupViewModels =
                new ObservableCollection <IFragmentOptionGroupViewModel>();


            IFragmentOptionGroupViewModel fragmentOptionGroupViewModel =
                fragmentOptionGroupViewModelGettingFunc();



            //группа устройство
            fragmentOptionGroupViewModel.NameKey = ApplicationGlobalNames.UiGroupingStrings.DEVICE_STRING_KEY;
            fragmentOptionGroupViewModel.FragmentOptionCommandViewModels = new List <IFragmentOptionCommandViewModel>();

            IFragmentOptionCommandViewModel fragmentOptionCommandViewModel =
                fragmentOptionCommandViewModelGettingFunc();


            fragmentOptionCommandViewModel.TitleKey = ApplicationGlobalNames.UiCommandStrings.READ_STRING_KEY;
            fragmentOptionCommandViewModel.IconKey  = IconResourceKeys.IconInboxIn;
            this.ReadConfigurationCommand           = new RelayCommand(() => OnExecuteReadConfiguration(true),
                                                                       () => _runtimeConfigurationViewModel.DeviceContext.DataProviderContainer.DataProvider.IsSuccess &&
                                                                       !this._isQueryInProgress);
            fragmentOptionCommandViewModel.OptionCommand = this.ReadConfigurationCommand;
            fragmentOptionGroupViewModel.FragmentOptionCommandViewModels.Add(fragmentOptionCommandViewModel);

            fragmentOptionCommandViewModel               = fragmentOptionCommandViewModelGettingFunc();
            fragmentOptionCommandViewModel.TitleKey      = ConfigurationKeys.TRANSFER_FROM_DEVICE_TO_LOCAL_STRING_KEY;
            fragmentOptionCommandViewModel.IconKey       = IconResourceKeys.IconChevronRight;
            fragmentOptionCommandViewModel.OptionCommand = new RelayCommand(OnExecuteTransferFromDeviceToLocal,
                                                                            () => _runtimeConfigurationViewModel.DeviceContext.DataProviderContainer.DataProvider.IsSuccess);
            fragmentOptionGroupViewModel.FragmentOptionCommandViewModels.Add(fragmentOptionCommandViewModel);

            fragmentOptionCommandViewModel          = fragmentOptionCommandViewModelGettingFunc();
            fragmentOptionCommandViewModel.TitleKey = ConfigurationKeys.WRITE_LOCAL_VALUES_TO_DEVICE_STRING_KEY;
            fragmentOptionCommandViewModel.IconKey  = IconResourceKeys.IconInboxOut;
            WriteConfigurationCommand =
                new RelayCommand(OnExecuteWriteLocalValuesToDevice,
                                 () => _runtimeConfigurationViewModel.DeviceContext.DataProviderContainer.DataProvider.IsSuccess &&
                                 !this._isQueryInProgress);
            fragmentOptionCommandViewModel.OptionCommand = this.WriteConfigurationCommand;
            fragmentOptionGroupViewModel.FragmentOptionCommandViewModels.Add(fragmentOptionCommandViewModel);


            fragmentOptionsViewModel.FragmentOptionGroupViewModels.Add(fragmentOptionGroupViewModel);
            fragmentOptionGroupViewModel = fragmentOptionGroupViewModelGettingFunc();
            //группа файл
            fragmentOptionGroupViewModel.NameKey = ApplicationGlobalNames.UiGroupingStrings.FILE_STRING_KEY;
            fragmentOptionGroupViewModel.FragmentOptionCommandViewModels = new List <IFragmentOptionCommandViewModel>();

            fragmentOptionCommandViewModel               = fragmentOptionCommandViewModelGettingFunc();
            fragmentOptionCommandViewModel.TitleKey      = ConfigurationKeys.LOAD_FROM_FILE_STRING_KEY;
            fragmentOptionCommandViewModel.IconKey       = IconResourceKeys.IconDiscUpload;
            fragmentOptionCommandViewModel.OptionCommand = new RelayCommand(OnExecuteLoadConfiguration);
            fragmentOptionGroupViewModel.FragmentOptionCommandViewModels.Add(fragmentOptionCommandViewModel);

            fragmentOptionCommandViewModel               = fragmentOptionCommandViewModelGettingFunc();
            fragmentOptionCommandViewModel.TitleKey      = ConfigurationKeys.SAVE_CONFUGURATION_STRING_KEY;
            fragmentOptionCommandViewModel.IconKey       = IconResourceKeys.IconDiscDownload;
            fragmentOptionCommandViewModel.OptionCommand = new RelayCommand(OnExecuteSaveConfiguration);
            fragmentOptionGroupViewModel.FragmentOptionCommandViewModels.Add(fragmentOptionCommandViewModel);

            fragmentOptionCommandViewModel               = fragmentOptionCommandViewModelGettingFunc();
            fragmentOptionCommandViewModel.TitleKey      = ConfigurationKeys.EXPORT_CONFUGURATION_STRING_KEY;
            fragmentOptionCommandViewModel.IconKey       = IconResourceKeys.IconPrintText;
            fragmentOptionCommandViewModel.OptionCommand = new RelayCommand(OnExecuteExportConfiguration);
            fragmentOptionGroupViewModel.FragmentOptionCommandViewModels.Add(fragmentOptionCommandViewModel);

            fragmentOptionsViewModel.FragmentOptionGroupViewModels.Add(fragmentOptionGroupViewModel);

            // // группа дерево
            // fragmentOptionGroupViewModel = fragmentOptionGroupViewModelGettingFunc();
            // fragmentOptionGroupViewModel.NameKey = ApplicationGlobalNames.UiGroupingStrings.TREE_STRING_KEY;
            // fragmentOptionGroupViewModel.FragmentOptionCommandViewModels = new List<IFragmentOptionCommandViewModel>();
            //
            // fragmentOptionCommandViewModel = fragmentOptionCommandViewModelGettingFunc();
            // fragmentOptionCommandViewModel.TitleKey = ConfigurationKeys.EXPAND_LEVEL_STRING_KEY;
            // fragmentOptionCommandViewModel.IconKey = IconResourceKeys.IconStepInto;
            // fragmentOptionCommandViewModel.OptionCommand = new RelayCommand(OnExecuteExpandLevel);
            // fragmentOptionGroupViewModel.FragmentOptionCommandViewModels.Add(fragmentOptionCommandViewModel);
            //
            //
            // fragmentOptionCommandViewModel = fragmentOptionCommandViewModelGettingFunc();
            // fragmentOptionCommandViewModel.TitleKey = ConfigurationKeys.COLLAPSE_LEVEL_STRING_KEY;
            // fragmentOptionCommandViewModel.IconKey = IconResourceKeys.IconStepOut;
            // fragmentOptionCommandViewModel.OptionCommand = new RelayCommand(OnExecuteCollapseLevel);
            // fragmentOptionGroupViewModel.FragmentOptionCommandViewModels.Add(fragmentOptionCommandViewModel);


            //fragmentOptionsViewModel.FragmentOptionGroupViewModels.Add(fragmentOptionGroupViewModel);

            // группа базовые уставки
            if (runtimeConfigurationViewModel.BaseValuesViewModel.BaseValueViewModels.Any())
            {
                fragmentOptionGroupViewModel = fragmentOptionGroupViewModelGettingFunc();

                fragmentOptionGroupViewModel.NameKey = ApplicationGlobalNames.UiGroupingStrings.BASE_VALUES_STRING_KEY;
                fragmentOptionGroupViewModel.FragmentOptionCommandViewModels =
                    new List <IFragmentOptionCommandViewModel>();
                foreach (var baseValueViewModel in runtimeConfigurationViewModel.BaseValuesViewModel.BaseValueViewModels
                         )
                {
                    fragmentOptionCommandViewModel               = fragmentOptionCommandViewModelGettingFunc();
                    fragmentOptionCommandViewModel.TitleKey      = baseValueViewModel.Name;
                    fragmentOptionCommandViewModel.IconKey       = IconResourceKeys.IconBaseValuesTransfer;
                    fragmentOptionCommandViewModel.OptionCommand = baseValueViewModel.OnBaseValueApply;
                    fragmentOptionGroupViewModel.FragmentOptionCommandViewModels.Add(fragmentOptionCommandViewModel);
                }

                fragmentOptionsViewModel.FragmentOptionGroupViewModels.Add(fragmentOptionGroupViewModel);
            }


            return(fragmentOptionsViewModel);
        }