public static bool SetPropertyValue <TProperty>( IModel model, ref TProperty property, TProperty value, string propertyName) { IModelOptions options = model.ModelOptions ?? ModelOptions.Default; if (options.UseOnlyOnPropertyChanged) { property = value; model.OnPropertyChanged(propertyName); return(true); } if (property == null & value == null) { return(true); } else if (property != null && property.Equals(value)) { return(true); } TProperty oldValue = property; property = value; if (options.UseOnVerification) { var args = new MvvmElementPropertyVerifyChangeEventArgs(propertyName); model.OnVerification(args); if (!args.IsValid) { property = oldValue; model.OnErrors(args.GetErrors()); return(false); } } if (options.UseVerifyPropertyChange && !model.OnVerifyPropertyChange(propertyName)) { property = oldValue; return(false); } model.OnPropertyChanged(propertyName); return(true); }
public static void ApplyConfig(IModelOptions modelOptions) { var currentProcess = Process.GetCurrentProcess(); var modelCurrentProcess = ((IModelOpptionCurrentProcess)modelOptions).CurrentProcess; var priorityClass = modelCurrentProcess.PriorityClass; if (priorityClass.HasValue) { currentProcess.PriorityClass = priorityClass.Value; } var priorityBoostEnabled = modelCurrentProcess.PriorityBoostEnabled; if (priorityBoostEnabled.HasValue) { currentProcess.PriorityBoostEnabled = priorityBoostEnabled.Value; } }
/// <summary> /// Func creation model /// </summary> /// <typeparam name="TModel">type of model being created</typeparam> /// <param name="factory">type of factory that will spawn the model</param> /// <param name="options">model options</param> /// <returns></returns> public static TModel GetModelStatic <TModel>(IAbstractFactory factory, IModelOptions options = null) where TModel : IModel, new() { return(factory.CreateObject <object, TModel>( (_) => { var model = new TModel(); if (model is ModelBase dest) { dest.ModelOptions = options; dest.Factory = factory; if (factory is ViewModelBase source) { dest.UiServices = source.UiServices; } dest.Initialize(); } return model; } , null)); }
/// <summary> /// Create mocked view-model /// </summary> /// <param name="frame"></param> /// <param name="behavior">behavior of the mock</param> /// <param name="modelOptions"></param> /// <param name="configUiServices"></param> /// <returns></returns> protected virtual TViewModel CreateMockedViewModel(Frame frame, MockBehavior behavior = MockBehavior.Default, IModelOptions modelOptions = null, IConfigUiServices configUiServices = null) { var mockViewModel = new Mock <TViewModel>(behavior); SetupMock(mockViewModel); var viewModel = ViewModelBase.CreateViewModel <PrivateViewModel>(frame, modelOptions, configUiServices); var filter = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic; typeof(ViewModelBase).GetProperty(nameof(ViewModelBase.NavigationManager), filter) .SetValue(mockViewModel.Object, viewModel.NavigationManager); typeof(ViewModelBase).GetProperty(nameof(ViewModelBase.UiServices), filter) .SetValue(mockViewModel.Object, viewModel.UiServices); mockViewModel.Object.ModelOptions = viewModel.ModelOptions; return(mockViewModel.Object); }
internal static void BindModelStatic <TModel>(TModel model, IAbstractFactory factory, IModelOptions options, IConfigUiServices uiServices) where TModel : ModelBase { model.Factory = factory; model.ModelOptions = options; model.UiServices = uiServices; }