public static async ValueTask <Resource> GetResource(this IFactoryContext factoryContext, Uri uri, NameValueCollection?headers, CancellationToken token) { if (factoryContext is null) { throw new ArgumentNullException(nameof(factoryContext)); } var factories = factoryContext.ResourceLoaderFactories; if (!factories.IsDefaultOrEmpty) { foreach (var resourceLoaderFactory in factories) { if (await resourceLoaderFactory.TryGetActivator(factoryContext, uri, token).ConfigureAwait(false) is { } activator) { var resourceLoader = await activator.CreateResourceLoader(factoryContext, token).ConfigureAwait(false); return(await resourceLoader.Request(uri, headers, token).ConfigureAwait(false)); } } } throw new ProcessorException(Resources.Exception_CannotFindResourceLoaderToLoadExternalResource); }
public override FrameworkElementFactory GenerateField(IFactoryContext context, DateRangeDescription fieldDescription) { //From FrameworkElementFactory elementFrom = new FrameworkElementFactory(typeof(DatePicker)); elementFrom.SetValue(DatePicker.MarginProperty, new Thickness(0, 0, 0, 0)); elementFrom.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left); elementFrom.SetBinding(DatePicker.SelectedDateProperty, new Binding(fieldDescription.StartDate)); //To FrameworkElementFactory elementTo = new FrameworkElementFactory(typeof(DatePicker)); elementTo.SetValue(DatePicker.MarginProperty, new Thickness(4, 0, 0, 0)); elementTo.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left); elementTo.SetBinding(DatePicker.SelectedDateProperty, new Binding(fieldDescription.EndDate)); //Panel FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel)); stack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); stack.AppendChild(elementFrom); stack.AppendChild(elementTo); return(stack); }
public ValueTask <IService> CreateService(IFactoryContext factoryContext, Uri?baseUri, InvokeData invokeData, IServiceCommunication serviceCommunication, CancellationToken token) { switch (_creators[invokeData.Type]) { case IServiceCatalog.Creator creator: var service = creator(); service.Start(baseUri, invokeData, serviceCommunication); return(new ValueTask <IService>(service)); case IServiceCatalog.ServiceCreator creator: return(new ValueTask <IService>(creator(baseUri, invokeData, serviceCommunication))); case IServiceCatalog.ServiceCreatorAsync creator: return(creator(factoryContext, baseUri, invokeData, serviceCommunication, token)); default: return(Infra.Unexpected <ValueTask <IService> >(_creators[invokeData.Type]?.GetType())); } }
public override FrameworkElementFactory GenerateField(IFactoryContext context, MultiLineTextDescription fieldDescription) { if (context.FormState == FormState.View) { return(CreateReadOnlyTextElement(fieldDescription.Text, fieldDescription.StringFormat)); } else { Binding binding = new Binding(fieldDescription.Text); binding.StringFormat = null; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; FrameworkElementFactory textbox = new FrameworkElementFactory(typeof(TextBox)); textbox.SetBinding(TextBox.TextProperty, binding); textbox.SetValue(TextBox.MarginProperty, new Thickness(0, 1, 2, 1)); textbox.SetValue(TextBox.TextWrappingProperty, TextWrapping.Wrap); textbox.SetValue(TextBox.AcceptsReturnProperty, true); textbox.SetValue(TextBox.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Auto); if (fieldDescription.Height != null) { textbox.SetValue(TextBox.HeightProperty, fieldDescription.Height.Value); } return(textbox); } }
public override void Initialize(IContext context) { base.Initialize(context); IFactoryContext factoryContext = context.GetService <IFactoryContext>(); //TODO Extract into a IFactoryMappingService Mappings.ForEach(item => factoryContext.Policies.Set <IBuildKeyMappingPolicy>(new BuildKeyMappingPolicy(item.ConcreteType), item.InterfaceType)); }
public ValueTask <IDataModelHandler> CreateHandler(IFactoryContext factoryContext, string dataModelType, IErrorProcessor?errorProcessor, CancellationToken token) { Infra.Assert(CanHandle(dataModelType)); return(new ValueTask <IDataModelHandler>(new EcmaScriptDataModelHandler(errorProcessor))); }
public override FrameworkElementFactory GenerateField(IFactoryContext context, ItemsControlDescription fieldDescription) { FrameworkElementFactory element = new FrameworkElementFactory(typeof(ItemsControl)); element.SetValue(Grid.IsSharedSizeScopeProperty, true); if (fieldDescription.ItemTemplate != null) { element.SetValue(ItemsControl.ItemTemplateProperty, fieldDescription.ItemTemplate); } else { DataTemplate dt = new DataTemplate(); if (fieldDescription.ItemDefinition != null) { IFieldFactory factory = context.Mapping.Context.GetFactory(fieldDescription.ItemDefinition.GetType()); dt.VisualTree = factory.CreateField(context, fieldDescription.ItemDefinition); } else { var lbl = new FrameworkElementFactory(typeof(TextBlock)); lbl.SetBinding(TextBlock.TextProperty, new Binding()); dt.VisualTree = lbl; } element.SetValue(ItemsControl.ItemTemplateProperty, dt); } element.SetBinding(ItemsControl.ItemsSourceProperty, new Binding(fieldDescription.ItemsSource)); if (fieldDescription.Rows != null || fieldDescription.Columns != null) { FrameworkElementFactory uniformPanel = new FrameworkElementFactory(typeof(UniformGrid)); if (fieldDescription.Rows != null) { uniformPanel.SetValue(UniformGrid.RowsProperty, fieldDescription.Rows.Value); } if (fieldDescription.Columns != null) { uniformPanel.SetValue(UniformGrid.ColumnsProperty, fieldDescription.Columns.Value); } element.SetValue(ItemsControl.ItemsPanelProperty, new ItemsPanelTemplate(uniformPanel)); } FrameworkElementFactory scrollviewer = new FrameworkElementFactory(typeof(ScrollViewer)); scrollviewer.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled); scrollviewer.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Auto); scrollviewer.AppendChild(element); return(scrollviewer); }
public override void Initialize(IContext context) { base.Initialize(context); IFactoryContext factoryContext = CreateFactoryContext(); factoryContext.Policies.SetDefault <IPolicyInjectionPolicy>(new PolicyInjectionPolicy(true)); context.AddService <IFactoryContext>(factoryContext); }
public CustomActionDispatcher(IErrorProcessor?errorProcessor, ICustomAction customAction, IFactoryContext factoryContext) { _errorProcessor = errorProcessor; _customAction = customAction; _factoryContext = factoryContext; Infra.NotNull(customAction.XmlNamespace); Infra.NotNull(customAction.XmlName); Infra.NotNull(customAction.Xml); }
public override FrameworkElementFactory GenerateField(IFactoryContext context, ButtonDescription fieldDescription) { FrameworkElementFactory element = new FrameworkElementFactory(typeof(Button)); element.SetValue(Button.HorizontalAlignmentProperty, HorizontalAlignment.Left); element.SetValue(Button.ContentProperty, fieldDescription.Description); element.SetBinding(Button.CommandProperty, new Binding(fieldDescription.Command)); return(element); }
public override FrameworkElementFactory GenerateField(IFactoryContext context, ImageDescription fieldDescription) { FrameworkElementFactory border = new FrameworkElementFactory(typeof(Image)); border.SetValue(Image.StretchProperty, fieldDescription.Stretch); border.SetBinding(Image.SourceProperty, new Binding(fieldDescription.ImageSource) { Converter = new BytesToImageConverter() }); return(border); }
public override FrameworkElementFactory GenerateField(IFactoryContext context, StaticTextDescription fieldDescription) { FrameworkElementFactory root = new FrameworkElementFactory(typeof(Border)); FrameworkElementFactory element = new FrameworkElementFactory(typeof(TextBlock)); element.SetValue(TextBlock.TextProperty, fieldDescription.Text); element.SetValue(TextBlock.MarginProperty, new Thickness(4)); root.AppendChild(element); return(root); }
public override FrameworkElementFactory GenerateField(IFactoryContext context, CheckBoxDescription fieldDescription) { FrameworkElementFactory root = new FrameworkElementFactory(typeof(CheckBox)); root.SetValue(CheckBox.MarginProperty, new Thickness(2)); root.SetValue(CheckBox.IsEnabledProperty, context.FormState != FormState.View); root.SetBinding(CheckBox.IsCheckedProperty, new Binding(fieldDescription.IsChecked) { Mode = BindingMode.TwoWay }); return(root); }
public override FrameworkElementFactory GenerateField(IFactoryContext context, CustomDescription fieldDescription) { FrameworkElementFactory element; if (fieldDescription.CustomControlType.IsSubclassOf(typeof(UIElement))) { element = new FrameworkElementFactory(fieldDescription.CustomControlType); } else { element = new FrameworkElementFactory(typeof(ContentControl)); element.SetValue(ContentControl.ContentProperty, Activator.CreateInstance(fieldDescription.CustomControlType)); } return(element); }
public FrameworkElementFactory CreateField(IFactoryContext context, TFieldDescription fieldDescription) { FrameworkElementFactory result = GenerateField(context, fieldDescription); foreach (IFieldExtensionFactory extension in context.Mapping.Context.GetExtensionFactories()) { IFieldExtensionDescription foundDescription = fieldDescription.Extensions.FirstOrDefault(x => x.GetType() == extension.DescriptionType); if (foundDescription != null) { result = extension.Apply(foundDescription, result); } } return(result); }
public async ValueTask <IServiceFactoryActivator?> TryGetActivator(IFactoryContext factoryContext, Uri type, CancellationToken token) { var factories = await GetFactories(factoryContext, InvokeTypeToUri(type), token).ConfigureAwait(false); foreach (var factory in factories) { var activator = await factory.TryGetActivator(factoryContext, type, token).ConfigureAwait(false); if (activator is not null) { return(activator); } } return(null); }
public override FrameworkElementFactory GenerateField(IFactoryContext context, TreeViewDescription fieldDescription) { FrameworkElementFactory treeView = new FrameworkElementFactory(typeof(TreeView)); treeView.SetValue(TreeView.BorderThicknessProperty, new Thickness(0)); treeView.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled); if (fieldDescription.ItemTemplate != null) { treeView.SetValue(TreeView.ItemTemplateProperty, fieldDescription.ItemTemplate); } treeView.SetBinding(TreeView.ItemsSourceProperty, new Binding(fieldDescription.ItemsSource)); return(treeView); }
public override FrameworkElementFactory GenerateField(IFactoryContext context, DateDescription fieldDescription) { FrameworkElementFactory element; if (context.FormState == FormState.View) { element = CreateReadOnlyTextElement(fieldDescription.SelectedDate, fieldDescription.StringFormat); } else { element = new FrameworkElementFactory(typeof(DatePicker)); element.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left); element.SetBinding(DatePicker.SelectedDateProperty, new Binding(fieldDescription.SelectedDate)); } return(element); }
public async ValueTask <IDataModelHandlerFactoryActivator?> TryGetActivator(IFactoryContext factoryContext, string dataModelType, CancellationToken token) { if (_dataModelHandlerFactories is not null) { foreach (var factory in _dataModelHandlerFactories) { var activator = await factory.TryGetActivator(factoryContext, dataModelType, token).ConfigureAwait(false); if (activator is not null) { return(activator); } } } return(null); }
public async ValueTask <ICustomActionFactoryActivator?> TryGetActivator(IFactoryContext factoryContext, string ns, string name, CancellationToken token) { var factories = await GetFactories(factoryContext, CustomActionNamespaceToUri(ns), token).ConfigureAwait(false); foreach (var factory in factories) { var activator = await factory.TryGetActivator(factoryContext, ns, name, token).ConfigureAwait(false); if (activator is not null) { return(activator); } } return(null); }
public override FrameworkElementFactory GenerateField(IFactoryContext context, TextBoxDescription fieldDescription) { if (context.FormState == FormState.View) { return(CreateReadOnlyTextElement(fieldDescription.Text, fieldDescription.StringFormat)); } else { Binding binding = new Binding(fieldDescription.Text); binding.StringFormat = fieldDescription.StringFormat; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; FrameworkElementFactory textbox = new FrameworkElementFactory(typeof(TextBox)); textbox.SetBinding(TextBox.TextProperty, binding); textbox.SetValue(TextBox.MarginProperty, new Thickness(0, 1, 2, 1)); textbox.SetValue(TextBox.TextWrappingProperty, TextWrapping.Wrap); return(textbox); } }
public override FrameworkElementFactory GenerateField(IFactoryContext context, ComboBoxDescription fieldDescription) { FrameworkElementFactory element; if (context.FormState == FormState.View) { element = CreateReadOnlyTextElement(fieldDescription.SelectedItem, fieldDescription.StringFormat); } else { element = new FrameworkElementFactory(typeof(ComboBox)); element.SetValue(ComboBox.MinWidthProperty, 120d); element.SetValue(ScrollViewer.CanContentScrollProperty, false); element.SetValue(ComboBox.IsReadOnlyProperty, true); //element.SetValue(ComboBox.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); element.SetBinding(TextBlock.ToolTipProperty, new Binding(fieldDescription.SelectedItem)); if (fieldDescription.GroupTemplate != null) { GroupStyle groupStyle = new GroupStyle(); groupStyle.HeaderTemplate = fieldDescription.GroupTemplate; } if (fieldDescription.SelectedItem != null) { element.SetValue(ComboBox.SelectedItemProperty, new Binding(fieldDescription.SelectedItem) { Mode = BindingMode.TwoWay }); } element.SetValue(ComboBox.ItemTemplateProperty, CreateItemTemplate()); if (fieldDescription.ItemsSource != null) { element.SetValue(ComboBox.ItemsSourceProperty, new Binding(fieldDescription.ItemsSource)); } } return(element); }
public ValueTask <IServiceFactoryActivator?> TryGetActivator(IFactoryContext factoryContext, Uri type, CancellationToken token) { _activator ??= CreateActivator(); return(new ValueTask <IServiceFactoryActivator?>(_activator.CanHandle(type) ? _activator : null)); }
public FactoryCommand(IFactoryContext factoryContext) { this.factoryContext = factoryContext; }
public override FrameworkElementFactory GenerateField(IFactoryContext context, IdDescription fieldDescription) { return(CreateReadOnlyTextElement(fieldDescription.Text, fieldDescription.StringFormat, TextAlignment.Right)); }
static Context() { FactoryContext = new FactoryContext(); }
public override FrameworkElementFactory GenerateField(IFactoryContext context, GroupDescription fieldDescription) { FrameworkElementFactory root; root = new FrameworkElementFactory(typeof(DockPanel)); if (fieldDescription.RowSpan != null) { root.SetValue(Grid.RowSpanProperty, fieldDescription.RowSpan.Value); } if (fieldDescription.ColumnSpan != null) { root.SetValue(Grid.ColumnSpanProperty, fieldDescription.ColumnSpan.Value); } if (fieldDescription.DataContext != null) { root.SetBinding(Grid.DataContextProperty, new Binding(fieldDescription.DataContext)); } //group label if (!String.IsNullOrEmpty(fieldDescription.DisplayName)) { FrameworkElementFactory labelGroup = new FrameworkElementFactory(typeof(TextBlock)); labelGroup.SetValue(TextBlock.TextProperty, fieldDescription.DisplayName); labelGroup.SetValue(Control.FontWeightProperty, FontWeights.Bold); labelGroup.SetValue(FrameworkElement.MarginProperty, new Thickness(2)); labelGroup.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center); FrameworkElementFactory borderForLabelGroup = new FrameworkElementFactory(typeof(Grid)); borderForLabelGroup.SetValue(Grid.ColumnProperty, 0); borderForLabelGroup.SetValue(Grid.ColumnSpanProperty, 2); borderForLabelGroup.SetValue(Grid.RowProperty, 0); borderForLabelGroup.SetValue(DockPanel.DockProperty, Dock.Top); borderForLabelGroup.SetValue(Control.HorizontalAlignmentProperty, HorizontalAlignment.Left); borderForLabelGroup.SetValue(Control.VerticalAlignmentProperty, VerticalAlignment.Top); borderForLabelGroup.AppendChild(labelGroup); root.AppendChild(borderForLabelGroup); } int row = 1; FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid)); grid.SetValue(FrameworkElement.MarginProperty, new Thickness(4, 0, 4, 4)); //columns FrameworkElementFactory groupColumnLabel = new FrameworkElementFactory(typeof(ColumnDefinition)); FrameworkElementFactory groupColumnContent = new FrameworkElementFactory(typeof(ColumnDefinition)); groupColumnLabel.SetValue(ColumnDefinition.WidthProperty, GridLength.Auto); grid.AppendChild(groupColumnLabel); grid.AppendChild(groupColumnContent); //group row FrameworkElementFactory rowGroupDefinition = new FrameworkElementFactory(typeof(RowDefinition)); rowGroupDefinition.SetValue(RowDefinition.HeightProperty, GridLength.Auto); grid.AppendChild(rowGroupDefinition); //Properties foreach (FieldDescription property in fieldDescription.FieldDescriptions) { FrameworkElementFactory rowDefinition = new FrameworkElementFactory(typeof(RowDefinition)); if (!property.IsVerticalStretched) { rowDefinition.SetValue(RowDefinition.HeightProperty, GridLength.Auto); } else { } grid.AppendChild(rowDefinition); if (property.DisplayName != null) { //label FrameworkElementFactory label = new FrameworkElementFactory(typeof(TextBlock)); label.SetValue(Grid.ColumnProperty, 0); label.SetValue(Grid.RowProperty, row); label.SetValue(TextBlock.TextProperty, property.DisplayName); label.SetValue(FrameworkElement.MarginProperty, new Thickness(2, 1, 4, 1)); label.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Top); if (property.Visibiliy != null) { IValueConverter converter = property.VisibilityConverter; if (converter == null) { converter = new NotBoolToVisibilityConverter(); } label.SetBinding(FrameworkElement.VisibilityProperty, new Binding(property.Visibiliy) { Converter = converter }); } grid.AppendChild(label); } IFieldFactory factory = context.Mapping.Context.GetFactory(property.GetType()); //PropertyDefinitions FrameworkElementFactory element = factory.CreateField(context, property); element.SetValue(Grid.ColumnProperty, 1); element.SetValue(Grid.RowProperty, row); element.SetValue(FrameworkElement.MarginProperty, new Thickness(0, 0, 0, 1)); if (property.IsEnabled != null) { element.SetValue(FrameworkElement.IsEnabledProperty, property.IsEnabled.Value); } if (property.Visibiliy != null) { IValueConverter converter = property.VisibilityConverter; if (converter == null) { converter = new NotBoolToVisibilityConverter(); } element.SetBinding(FrameworkElement.VisibilityProperty, new Binding(property.Visibiliy) { Converter = converter }); } if (property.DisplayName == null) { element.SetValue(Grid.ColumnProperty, 0); element.SetValue(Grid.ColumnSpanProperty, 2); } element.SetValue(FrameworkElement.HorizontalAlignmentProperty, property.HorizontalAlignment); if (property.Width != null) { element.SetValue(FrameworkElement.WidthProperty, property.Width.Value); element.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left); } if (property.Style != null) { element.SetValue(Control.StyleProperty, property.Style); } grid.AppendChild(element); row++; } root.AppendChild(grid); return(root); }
public ValueTask <IDataModelHandlerFactoryActivator?> TryGetActivator(IFactoryContext factoryContext, string dataModelType, CancellationToken token) =>
public static ValueTask <Resource> GetResource(this IFactoryContext factoryContext, Uri uri, CancellationToken token) => GetResource(factoryContext, uri, headers: default, token);
public override FrameworkElementFactory GenerateField(IFactoryContext context, GroupCollectionDescription fieldDescription) { //main control FrameworkElementFactory mainGrid = new FrameworkElementFactory(typeof(Grid)); mainGrid.SetValue(FrameworkElement.MarginProperty, new Thickness(4)); int maxMainColumnIndex = fieldDescription.Groups.Max(x => x.Column); int maxMainRowIndex = fieldDescription.Groups.Max(x => x.Row); //create columns for (int i = 0; i <= maxMainColumnIndex; i++) { FrameworkElementFactory column = new FrameworkElementFactory(typeof(ColumnDefinition)); GroupDescription foundGroup = fieldDescription.Groups.First(x => x.Column == i); if (foundGroup.Width != null) { column.SetValue(ColumnDefinition.WidthProperty, new GridLength(foundGroup.Width.Value)); } else { column.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Star)); } mainGrid.AppendChild(column); } //create rows for (int i = 0; i <= maxMainRowIndex; i++) { FrameworkElementFactory row = new FrameworkElementFactory(typeof(RowDefinition)); if (!fieldDescription.Groups.Any(x => x.Row == i && x.FieldDescriptions.Any(p => p.IsVerticalStretched))) { row.SetValue(RowDefinition.HeightProperty, GridLength.Auto); } else { } mainGrid.AppendChild(row); } //Groups by column foreach (var groupsByColumn in fieldDescription.Groups .GroupBy(x => x.Column) .OrderBy(x => x.Key)) { //Groups foreach (var groups in groupsByColumn .GroupBy(x => x.Row) .OrderBy(x => x.Key)) { FrameworkElementFactory stackpanel = null; if (groups.Count() > 1) { stackpanel = new FrameworkElementFactory(typeof(StackPanel)); stackpanel.SetValue(Grid.ColumnProperty, groupsByColumn.Key); stackpanel.SetValue(Grid.RowProperty, groups.Key); stackpanel.SetValue(StackPanel.OrientationProperty, Orientation.Vertical); mainGrid.AppendChild(stackpanel); } IFieldFactory groupFactory = context.Mapping.Context.GetFactory <GroupDescription>(); foreach (var group in groups) { FrameworkElementFactory g = groupFactory.CreateField(context, group); g.SetValue(Grid.RowProperty, group.Row); g.SetValue(Grid.ColumnProperty, group.Column); if (group.ColumnSpan.HasValue) { g.SetValue(Grid.ColumnSpanProperty, group.ColumnSpan.Value); } if (groups.Count() > 1) { stackpanel.AppendChild(g); } else { g.SetValue(Grid.ColumnProperty, groupsByColumn.Key); g.SetValue(Grid.RowProperty, groups.Key); mainGrid.AppendChild(g); } } } } return(mainGrid); }