private async Task <bool> LoadFragment(ILoadFragmentViewModel loadFragmentViewModel, IFragmentViewModel fragmentViewModel, Func <IFragmentViewModel, Task <Result <object> > > handler, string pathToFolder) { if (loadFragmentViewModel.IsSelectedForLoading) { try { loadFragmentViewModel.IsFragmentLoadingInProgress = true; var result = await handler(fragmentViewModel); var path = pathToFolder + "\\" + loadFragmentViewModel.UiName; if (fragmentViewModel is IFragmentFileExtension fragmentFileExtension) { path = path + "." + fragmentFileExtension.FileExtension; } result.OnSuccess(o => _serializerService.SerializeInFile(o, path)); return(result.IsSuccess); } catch (Exception e) { StaticContainer.Container.Resolve <ILogService>().LogMessage(e.Message, LogMessageTypeEnum.Error); return(false); } finally { loadFragmentViewModel.IsFragmentLoadingInProgress = false; } } return(true); }
public static RelayCommand GetFragmentCommand(IFragmentViewModel fragment, string groupName, string commandName) { return(fragment.FragmentOptionsViewModel.FragmentOptionGroupViewModels .First(model => model.NameKey == groupName).FragmentOptionCommandViewModels .First(model => model.TitleKey == commandName) .OptionCommand as RelayCommand); }
public IFragmentPaneViewModel GetFragmentPaneViewModel(IFragmentViewModel fragmentViewModel, IEnumerable <IDeviceViewModel> deviceViewModels) { IFragmentPaneViewModel fragmentPaneViewModel = _fragmentPaneViewModelgettingFunc(); fragmentPaneViewModel.FragmentViewModel = fragmentViewModel; IDeviceViewModel deviceViewModel = GetParentDevice(deviceViewModels, fragmentViewModel); //событие изменения подписи устройства void OnDeviceViewModelOnPropertyChanged(object s, PropertyChangedEventArgs e) { if (s is IDeviceViewModel) { IDeviceViewModel dvm = s as IDeviceViewModel; if (e.PropertyName == nameof(dvm.DeviceSignature)) { SetPaneTitle(fragmentPaneViewModel, fragmentViewModel, dvm); } } } deviceViewModel.PropertyChanged += OnDeviceViewModelOnPropertyChanged; LocalizeDictionary.Instance.PropertyChanged += (o, e) => { SetPaneTitle(fragmentPaneViewModel, fragmentViewModel, deviceViewModel); }; SetPaneTitle(fragmentPaneViewModel, fragmentViewModel, deviceViewModel); return(fragmentPaneViewModel); }
private void SetPaneTitle(IFragmentPaneViewModel fragmentPaneViewModel, IFragmentViewModel fragmentViewModel, IDeviceViewModel deviceViewModel) { if (!(_localizerService.TryGetLocalizedString(fragmentViewModel.NameForUiKey, out string title))) { title = fragmentViewModel.NameForUiKey; } fragmentPaneViewModel.FragmentTitle = title + " (" + deviceViewModel.DeviceSignature + ")"; }
private IDeviceViewModel GetParentDevice(IEnumerable <IDeviceViewModel> deviceViewModels, IFragmentViewModel fragmentViewModel) { foreach (IDeviceViewModel deviceViewModel in deviceViewModels) { if (deviceViewModel.FragmentViewModels.Contains(fragmentViewModel)) { return(deviceViewModel); } } return(null); }
public async Task <Result <IDeviceViewModel> > CreateDeviceViewModel(IDevice device) { IDeviceViewModel deviceViewModel = _deviceViewModelGettingFunc(); if (device.DeviceMemory == null) { device.DeviceMemory = _container.Resolve <IDeviceMemory>(); } var deviceLevelPublisher = new FragmentLevelEventsDispatcher(); DeviceContext context = new DeviceContext(device.DeviceMemory, deviceLevelPublisher, device.DeviceSignature, device, device.DeviceSharedResources); if (device.DeviceFragments != null) { foreach (IDeviceFragment deviceFragment in device.DeviceFragments) { IFragmentViewModel fragmentViewModel = _container.Resolve <IFragmentViewModel>(deviceFragment.StrongName + ApplicationGlobalNames.CommonInjectionStrings .VIEW_MODEL); if (fragmentViewModel is IDeviceContextConsumer deviceContextConsumer) { deviceContextConsumer.DeviceContext = context; } var res = await fragmentViewModel.Initialize(deviceFragment); if (!res.IsSuccess) { if (res.Exception != null) { return(Result <IDeviceViewModel> .CreateWithException(res.Exception)); } Result <IDeviceViewModel> .Create(false); } deviceViewModel.FragmentViewModels.Add(fragmentViewModel); } } deviceViewModel.TransactionCompleteSubscription = new TransactionCompleteSubscription(context, device.ConnectionState, deviceViewModel.ConnectionStateViewModel, _container, () => { if (_container.Resolve <IApplicationGlobalCommands>().AskUserGlobal( _container.Resolve <ILocalizerService>() .GetLocalizedString(ApplicationGlobalNames.StatusMessages.CONNECTION_LOST_GO_OFFLINE), deviceViewModel.DeviceSignature)) { _container.Resolve <IDevicesContainerService>().ConnectDeviceAsync(device, _container.Resolve <IDeviceConnectionFactory>(ApplicationGlobalNames .OFFLINE_CONNECTION_FACTORY_NAME).CreateDeviceConnection()); (deviceViewModel.TransactionCompleteSubscription as TransactionCompleteSubscription) ?.ResetOnConnectionRetryCounter(false); } }); deviceViewModel.TransactionCompleteSubscription.Execute(); deviceViewModel.Model = device; return(Result <IDeviceViewModel> .Create(deviceViewModel, true)); }