/// <summary> /// Resolves all interdependencies e.g. edits to edit refs, control values to edits, etc. Called once /// all strategies have been loaded as there may be dependencies on EditRefs at the global level. /// </summary> public void ResolveAll(Strategy_t owningStrategy) { foreach (StrategyEdit_t strategyEdit in this) { (strategyEdit as IResolvable <Strategy_t, IParameter>).Resolve(owningStrategy, owningStrategy.Parameters); } }
/// <summary> /// Initializes a new <see cref="StrategyViewModel"/> /// </summary> /// <param name="strategy"><see cref="Strategy_t"/> for this View Model.</param> public StrategyViewModel(Strategy_t strategy, IInitialFixValueProvider initialValueProvider) { _underlyingStrategy = strategy; Controls = new ViewModelControlCollection(strategy, initialValueProvider); StrategyEdits = Controls.StrategyEdits; }
/// <summary> /// Resolves all edit refs, connects all edits to their controls. /// </summary> /// <param name="strategy"></param> public void ResolveAll(Strategy_t strategy) { foreach (StateRule_t rule in this.Items) { (rule as IResolvable <Strategy_t, Control_t>).Resolve(strategy, strategy.Controls); } }
// TODO: Unbind needed? void IResolvable <Strategy_t, T> .Resolve(Strategy_t strategy, ISimpleDictionary <T> sourceCollection) { foreach (IEdit <T> item in this.Items) { (item as IResolvable <Strategy_t, T>).Resolve(strategy, sourceCollection); } }
/// <summary> /// Resolves all interdependencies e.g. edits to edit refs, control values to edits, etc. Called once /// all strategies have been loaded as there may be dependencies on EditRefs at the global level. /// </summary> void IResolvable <Strategy_t, T> .Resolve(Strategy_t strategy, ISimpleDictionary <T> sourceCollection) { if (_editRef != null) { (_editRef as IResolvable <Strategy_t, T>).Resolve(strategy, sourceCollection); } else if (_edit != null) { (_edit as IResolvable <Strategy_t, T>).Resolve(strategy, sourceCollection); } }
public Strategy_t GetStrategyByName(string providerId, string name, bool resetStrategy) { Strategies_t strategies = _strategiesDictionary[providerId]; Strategy_t strategy = strategies[name]; if (resetStrategy) { strategy.Reset(); } return(strategy); }
public static void Render(Strategy_t strategy, XmlWriter writer, WpfComboBoxSizer sizer) { if (strategy.StrategyLayout == null) { throw ThrowHelper.New <RenderingException>(ExceptionContext, ErrorMessages.NoStrategyLayoutSupplied); } StrategyPanel_t rootPanel = strategy.StrategyLayout.StrategyPanel; if (rootPanel == null) { throw ThrowHelper.New <RenderingException>(ExceptionContext, ErrorMessages.NoStrategyPanelsInStrategy); } WpfXmlWriter wpfWriter = new WpfXmlWriter(writer); // TODO: Move this somewhere better WpfControlRenderer controlRenderer = new WpfControlRenderer(wpfWriter, sizer); // TODO: Move this elsewhere CompositionContainer defaultContainer = new CompositionContainer(new TypeCatalog(_defaultRenderers)); if (!string.IsNullOrEmpty(CustomControlRenderer)) { string applicationDirectory = (from assembly in System.AppDomain.CurrentDomain.GetAssemblies() where assembly.CodeBase.EndsWith(".exe") select System.IO.Path.GetDirectoryName(assembly.CodeBase.Replace("file:///", ""))).FirstOrDefault(); string customControlRendererPath = Path.Combine(applicationDirectory, CustomControlRenderer); AssemblyCatalog overridesCatalog = new AssemblyCatalog(customControlRendererPath); CompositionContainer aggregateContainer = new CompositionContainer(overridesCatalog, defaultContainer); aggregateContainer.ComposeParts(controlRenderer); } else { defaultContainer.ComposeParts(controlRenderer); } int depth = 0; ProcessPanel(rootPanel, wpfWriter, controlRenderer, -1, ref depth); }
/// <summary> /// Factory method for creating new ControlViewModel instances. /// </summary> /// <param name="underlyingStrategy"><see cref="Strategy_t"/> that this ControlViewModel's <see cref="Control_t"/> is a member of.</param> /// <param name="control">Underlying Control_t for this ControlViewModel.</param> /// <returns>New ControlViewModel instance.</returns> public static ControlViewModel Create(Strategy_t underlyingStrategy, Control_t control, IInitialFixValueProvider initialValueProvider) { IParameter referencedParameter = null; if (control.ParameterRef != null) { referencedParameter = underlyingStrategy.Parameters[control.ParameterRef]; if (referencedParameter == null) { throw ThrowHelper.New <ReferencedObjectNotFoundException>(ErrorMessages.UnresolvedParameterRefError, control.ParameterRef); } } ControlViewModel controlViewModel; #if !NET_40 // This is to workaround a bug in .NET Framework 3.5 where it is possible for more than one radio button in a // group to be checked at a time. if (control is RadioButton_t) { controlViewModel = new RadioButtonViewModel(control as RadioButton_t, referencedParameter); } else #endif if (control is ListControlBase) { controlViewModel = ListControlViewModel.Create(control as ListControlBase, referencedParameter); } else if (InvalidatableControlViewModel.IsInvalidatable(control)) { controlViewModel = InvalidatableControlViewModel.Create(control, referencedParameter); } else { controlViewModel = new ControlViewModel(control, referencedParameter); } controlViewModel._stateRules = new ViewModelStateRuleCollection(controlViewModel, control.StateRules); controlViewModel._fixFieldValues = new FixFieldValueProvider(initialValueProvider, underlyingStrategy.Parameters); return(controlViewModel); }
/// <remarks>This method does not throw exceptions as this causes issues with WPF data binding. Instead it /// invokes the ExceptionOccurred event handler (if registered).</remarks> private void OnStrategyPropertyChanged(Strategy_t newStrategy) { try { if (newStrategy != null) { _inputValuesSet = false; if (Atdl4netConfiguration.Settings.Wpf.ResetStrategyOnAssignmentToControl) { newStrategy.Reset(); } Render(); NotifyStrategyChanged(newStrategy.Name); } } catch (Exception ex) { NotifyExceptionOccurred(ex); } }
/// <summary> /// Initializes a new <see cref="ViewModelControlCollection"/> /// </summary> /// <param name="strategy">Strategy that the underlying controls belong to.</param> /// <param name="mode">Data entry mode.</param> public ViewModelControlCollection(Strategy_t strategy, IInitialFixValueProvider initialValueProvider) { foreach (Control_t control in strategy.Controls) { ControlViewModel controlViewModel = ControlViewModel.Create(strategy, control, initialValueProvider); Add(controlViewModel); controlViewModel.ValueChangeCompleted += new EventHandler <ValueChangeCompletedEventArgs>(ControlValueChangeCompleted); controlViewModel.ValidationStateChanged += new EventHandler <ValidationStateChangedEventArgs>(ControlValidationStateChanged); // Special treatment for radio buttons under Framework 3.5 #if !NET462 if (control is RadioButton_t) { RegisterRadioButton(control as RadioButton_t, controlViewModel as RadioButtonViewModel); } #endif } _strategyEdits = new ViewModelStrategyEditCollection(strategy.StrategyEdits, this); BindStateRules(); }