public override void PerformReflection(ReflectionContext context) { AssemblyNode assemblyNode = new AssemblyNode(); assemblyNode.Text = Path.GetFileName(context.WorkflowAssembly.Assembly.Location); assemblyNode.Assembly = context.WorkflowAssembly; assemblyNode.SelectedImageIndex = assemblyNode.ImageIndex = context.GetImageIndex(typeof(AssemblyComponent), AssemblyNodeImageName); context.TreeView.Nodes.Add(assemblyNode); ReflectChildComponents(context.CreateClone(assemblyNode)); }
/// <summary> /// Invokes all child components of the current /// component. /// </summary> /// <param name="contextToPass">ReflectionContext that is /// passed to all childrens' PerformReflection method.</param> protected void ReflectChildComponents(ReflectionContext contextToPass) { List<Type> childTypes = contextToPass.GetChildComponents(this.GetType()); foreach (Type childType in childTypes) { WorkflowReflectionComponent componentInstance = childType.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, null, CultureInfo.InvariantCulture) as WorkflowReflectionComponent; if (componentInstance == null) { throw new ApplicationException("Could not cast component to WorkflowReflectionComponent. Type is: " + childType.FullName); } componentInstance.PerformReflection(contextToPass); } }
public CachingReflectionContext(ReflectionContext baseContext) { m_baseContext = baseContext; }
public ApplicationCatalog(ReflectionContext reflectionContext) { Requires.NotNull(reflectionContext, "reflectionContext"); this._reflectionContext = reflectionContext; }
public SafeAssemblyCatalog(string fullName, Func <Type, bool> typeFilter = null, ReflectionContext reflectionContext = null) : this(LoadAssembly(fullName), typeFilter ?? (type => type.IsPublic), reflectionContext) { }
public override Assembly GetSatelliteAssembly(CultureInfo culture, Version version) => ReflectionContext.MapAssembly(base.GetSatelliteAssembly(culture, version));
protected override TypeInfo MapItem(TypeInfo item) { return(ReflectionContext.MapType(item)); }
/// <summary> /// Creates a catalog of <see cref="ComposablePartDefinition"/>s based on all the given searchPattern /// over the files in the given directory path. /// /// Possible exceptions that can be thrown are any that <see cref="Directory.GetFiles(string, string)"/> or /// <see cref="Assembly.Load(AssemblyName)"/> can throw. /// </summary> /// <param name="path"> /// Path to the directory to scan for assemblies to add to the catalog. /// The path needs to be absolute or relative to <see cref="AppDomain.BaseDirectory"/> /// </param> /// <param name="reflectionContext"> /// The <see cref="ReflectionContext"/> a context used by the catalog when /// interpreting the types to inject attributes into the type definition. /// </param> /// <param name="definitionOrigin"> /// The <see cref="ICompositionElement"/> CompositionElement used by Diagnostics to identify the source for parts. /// </param> /// <exception cref="ArgumentException"> /// If <paramref name="path"/> is a zero-length string, contains only white space /// does not contain a valid pattern. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is <see langword="null"/> or /// <paramref name="reflectionContext"/> is <see langword="null"/> or /// <paramref name="definitionOrigin"/> is <see langword="null"/>. /// </exception> /// <exception cref="DirectoryNotFoundException"> /// The specified <paramref name="path"/> is invalid (for example, it is on an unmapped drive). /// </exception> /// <exception cref="PathTooLongException"> /// The specified <paramref name="path"/>, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters and file names must /// be less than 260 characters. /// </exception> /// <exception cref="UnauthorizedAccessException"> /// The caller does not have the required permission. /// </exception> public DirectoryCatalog(string path, ReflectionContext reflectionContext, ICompositionElement definitionOrigin) : this(path, "*.dll", reflectionContext, definitionOrigin) { }
public override void PerformReflection(ReflectionContext context) { WorkflowNode workflowNode = context.CurrentTreeNode as WorkflowNode; if (workflowNode == null) { throw new ApplicationException("Expected the parent node to be a workflow node."); } object workflowInstance = null; try { workflowInstance = workflowNode.WorkflowType.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, null, CultureInfo.InvariantCulture); } catch (Exception exc) { MessageBox.Show("Could not create workflow type: " + exc.ToString()); return; } TreeNode activitiesNode = new TreeNode(); activitiesNode.Text = "Activities"; activitiesNode.ImageIndex = activitiesNode.SelectedImageIndex = context.GetImageIndex(typeof(WorkflowActivitiesComponent), ActivitiesNodeImageName); workflowNode.Nodes.Add(activitiesNode); if (!(workflowInstance is CompositeActivity)) { TreeNode none = new TreeNode(); none.Text = "<Workflow is not a CompositeActivity>"; activitiesNode.Nodes.Add(none); } else { Queue<KeyValuePair<CompositeActivity, TreeNode>> toProcess = new Queue<KeyValuePair<CompositeActivity, TreeNode>>(); toProcess.Enqueue(new KeyValuePair<CompositeActivity, TreeNode>((CompositeActivity)workflowInstance, activitiesNode)); while (toProcess.Count > 0) { KeyValuePair<CompositeActivity, TreeNode> pair = toProcess.Dequeue(); CompositeActivity compositeActivity = pair.Key; TreeNode parent = pair.Value; foreach (Activity activity in compositeActivity.Activities) { ActivityNode activityNode = new ActivityNode (); activityNode.Activity = activity; activityNode.ImageIndex = activityNode.SelectedImageIndex = context.GetImageIndex(typeof(WorkflowActivitiesComponent), ActivityNodeImageName); parent.Nodes.Add(activityNode); ReflectChildComponents(context.CreateClone(activityNode)); if (activity is CompositeActivity) { toProcess.Enqueue(new KeyValuePair<CompositeActivity, TreeNode>((CompositeActivity)activity, activityNode)); } } } } }
protected CustomReflectionContext(ReflectionContext source) { throw new NotImplementedException(); }
/// <summary> /// Satisfies the imports of the specified attributed object exactly once and they will not /// ever be recomposed. /// </summary> /// <param name="part"> /// The attributed object to set the imports. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="compositionService"/> or <paramref name="attributedPart"/> or <paramref name="reflectionContext"/> is <see langword="null"/>. /// </exception> /// <exception cref="CompositionException"> /// An error occurred during composition. <see cref="CompositionException.Errors"/> will /// contain a collection of errors that occurred. /// </exception> /// <exception cref="ObjectDisposedException"> /// The <see cref="ICompositionService"/> has been disposed of. /// </exception> public static ComposablePart SatisfyImportsOnce(this ICompositionService compositionService, object attributedPart, ReflectionContext reflectionContext) { Requires.NotNull(compositionService, "compositionService"); Requires.NotNull(attributedPart, "attributedPart"); Requires.NotNull(reflectionContext, "reflectionContext"); Contract.Ensures(Contract.Result <ComposablePart>() != null); ComposablePart part = AttributedModelServices.CreatePart(attributedPart, reflectionContext); compositionService.SatisfyImportsOnce(part); return(part); }
public AssemblyCatalog(string codeBase, ReflectionContext reflectionContext) { this.InitializeAssemblyCatalog(LoadAssembly(codeBase)); this._reflectionContext = reflectionContext; }
public ReflectionController(ReflectionContext context) => _context = context;
public static IReflectionScanner <TypeInfo> Reflect(this IScanner <TypeInfo> source, ReflectionContext context) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } return(new ReflectionTypeInfoScanner(source, context)); }
public ExportEnumeratorHelper([NotNull] IEnumerator<ExportMetadata> metaEnumerator, [NotNull] ReflectionContext context) { _metaEnumerator = metaEnumerator; _context = context; }
protected override Type GetCurrentType(ReflectionContext context) { return context.CurrentType.GenericTypeArguments[0]; }
protected override Type GetCurrentType(ReflectionContext context) { return context.CurrentType.GetElementType(); }
public override void PerformReflection(ReflectionContext context) { ReflectChildComponents(context); }
public ApplicationCatalog(ReflectionContext reflectionContext) { Requires.NotNull(reflectionContext, nameof(reflectionContext)); _reflectionContext = reflectionContext; }
/// <summary> /// Perform reflection with the component. Do the actual /// component work. /// </summary> /// <param name="context">Context within which to /// perform the reflection.</param> public abstract void PerformReflection(ReflectionContext context);
protected override Assembly MapItem(Assembly item) { return(ReflectionContext.MapAssembly(item)); }
public override Type GetType(string name, bool throwOnError) => ReflectionContext.MapType(base.GetType(name, throwOnError));
private void LoadAssembly(string fullName) { WorkflowAssembly workflowAssembly = null; try { workflowAssembly = WorkflowAssembly.LoadFrom(fullName); } catch (Exception exception) { MessageBox.Show("Could not load the requested assembly: " + exception.ToString()); return; } assemblyResolverDialog.DialogEnabled = false; Assembly assembly = null; // Check that the Assembly, or an Assembly with // the same name, has not already been loaded by // the program. If either of the above is true then // the newly loaded assembly would just be ignored. // Instead of showing duplicate assembly nodes, we // will just display an error and then make this a // no-op. try { assembly = Assembly.Load(workflowAssembly.Assembly.FullName); } catch (Exception) { } if (assembly != null) { MessageBox.Show("Either the assembly is already loaded or an assembly with the same Assembly Qualified Name is already loaded. Please choose a different assembly."); return; } assemblyResolverDialog.DialogEnabled = true; assemblyResolverDialog.ToResolve.Add(workflowAssembly.Assembly); ReflectionContext context = new ReflectionContext(workflowAssembly, imageIndexMapping, null, componentMapping, treeView1); // Start the reflection chain. RootComponent component = new RootComponent(); component.PerformReflection(context); }
public InjectorContext([NotNull] IMetadataFactory metadataFactory, [NotNull] object memberInfo, [NotNull] Type memberType, [CanBeNull] IResolverExtension[] resolverExtensions) { ReflectionContext = new ReflectionContext(metadataFactory, memberType, this, resolverExtensions ?? new IResolverExtension[0]); MemberInfo = memberInfo; }
public override Type GetType(string name) => ReflectionContext.MapType(base.GetType(name));
/// <summary> /// Initializes a new instance of the <see cref="ReflectionTypeInfoScanner"/> class. /// </summary> /// <param name="parent">The parent <see cref="IScanner{T}"/> that this scanner retieves it's items from.</param> /// <param name="reflectionContext">The context used to reflect over <see cref="TypeInfo"/> objects.</param> /// <exception cref="ArgumentNullException">The <paramref name="parent"/> argument is a null.</exception> /// <exception cref="ArgumentNullException">The <paramref name="reflectionContext"/> argument is a null.</exception> public ReflectionTypeInfoScanner(IScanner <TypeInfo> parent, ReflectionContext reflectionContext) : base(parent, reflectionContext) { // nothing }
/// <summary> /// Creates an <see cref="AttributedRobot"/> with a <see cref="ReflectionContext"/> object to find types through. /// </summary> /// <param name="reflectionContext">The context to find types through.</param> /// <remarks> /// This constructor only needed when using commands from a library that you cannot edit the source code for. Otherwise use the other constructor. /// </remarks> public AttributedRobot(ReflectionContext reflectionContext) { m_reflectionContext = reflectionContext; }
protected CustomReflectionContext(ReflectionContext source);
public SafeDirectoryCatalog(string directory, ReflectionContext reflectionContext = null) { Initialize(directory, reflectionContext); }
public override void PerformReflection(ReflectionContext context) { Type[] workflowTypes = context.WorkflowAssembly.GetWorkflowTypes(); if (workflowTypes == null) return; foreach (Type workflowType in workflowTypes) { WorkflowNode workflowNode = new WorkflowNode(); workflowNode.Name = workflowType.Name; workflowNode.Text = workflowType.FullName; workflowNode.WorkflowType = workflowType; workflowNode.SelectedImageIndex = workflowNode.ImageIndex = context.GetImageIndex(typeof(WorkflowComponent), WorkflowNodeImageName); context.CurrentTreeNode.Nodes.Add(workflowNode); ReflectChildComponents(context.CreateClone(workflowNode)); } if (context.WorkflowAssembly.GetWorkflowTypes().Length == 0) { TreeNode node = new TreeNode(); node.Text = "<No Workflows Found>"; context.CurrentTreeNode.Nodes.Add(node); } }
protected CustomReflectionContext(ReflectionContext source !!) {
public override void PerformReflection(ReflectionContext context) { if (context.CurrentTreeNode.ContextMenu != null) { throw new ApplicationException("XamlContextMenuComponent only works with ContextMenuStrip menus. The WorkflowComponent node had an old ContextMenu assigned."); } ContextMenuStrip menu = null; if (context.CurrentTreeNode.ContextMenuStrip != null) { menu = context.CurrentTreeNode.ContextMenuStrip; } else { menu = new ContextMenuStrip(); context.CurrentTreeNode.ContextMenuStrip = menu; } ToolStripMenuItem openNotepadItem = new ToolStripMenuItem("Open XAML in Notepad"); openNotepadItem.Click += OpenXamlInNotepad; openNotepadItem.Tag = context.CurrentTreeNode; menu.Items.Add(openNotepadItem); }
protected CustomReflectionContext(ReflectionContext source) { SourceContext = source ?? throw new ArgumentNullException(nameof(source)); _projector = new ReflectionContextProjector(this); }
public override void PerformReflection(ReflectionContext context) { if (context.CurrentTreeNode.ContextMenu != null) { throw new ApplicationException("XamlContextMenuComponent only works with ContextMenuStrip menus. The WorkflowComponent node had an old ContextMenu assigned."); } ContextMenuStrip menu = null; if (context.CurrentTreeNode.ContextMenuStrip != null) { menu = context.CurrentTreeNode.ContextMenuStrip; } else { menu = new ContextMenuStrip(); context.CurrentTreeNode.ContextMenuStrip = menu; } ToolStripMenuItem viewInDesigner = new ToolStripMenuItem(); viewInDesigner.Tag = ((WorkflowNode)context.CurrentTreeNode).WorkflowType; viewInDesigner.Text = "View on Design Surface"; viewInDesigner.Click += OnItemClick; menu.Items.Add(viewInDesigner); }
protected CustomReflectionContext(ReflectionContext source) { throw new PlatformNotSupportedException(); }
public override void PerformReflection(ReflectionContext context) { Type workflowType = ((WorkflowNode)context.CurrentTreeNode).WorkflowType; object workflowInstance = null; try { workflowInstance = workflowType.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, null, CultureInfo.InvariantCulture); } catch (Exception exc) { MessageBox.Show("Workflow type could not be created: " + exc.ToString()); return; } Activity root = (Activity)workflowInstance; Queue<Activity> toProcess = new Queue<Activity>(); List<Type> foundInterfaces = new List<Type>(); toProcess.Enqueue(root); while (toProcess.Count > 0) { Activity activity = toProcess.Dequeue(); if (activity is CompositeActivity) { CompositeActivity compositeActivity = (CompositeActivity)activity; foreach (Activity child in compositeActivity.Activities) { toProcess.Enqueue(child); } } else if (activity is HandleExternalEventActivity) { HandleExternalEventActivity eventSink = (HandleExternalEventActivity)activity; if (!foundInterfaces.Contains(eventSink.InterfaceType)) { foundInterfaces.Add(eventSink.InterfaceType); } } else if (activity is CallExternalMethodActivity) { CallExternalMethodActivity invoke = (CallExternalMethodActivity)activity; if (!foundInterfaces.Contains(invoke.InterfaceType)) { foundInterfaces.Add(invoke.InterfaceType); } } } foreach (Type service in foundInterfaces) { ServiceInterfaceNode node = new ServiceInterfaceNode(); node.ServiceInterfaceType = service; node.Text = "Required Service: " + service.FullName; node.SelectedImageIndex = node.ImageIndex = context.GetImageIndex(typeof(RequiredServiceInterfacesComponent), ServiceInterfaceNodeImageName); context.CurrentTreeNode.Nodes.Add(node); ReflectChildComponents(context.CreateClone(node)); } }
/// <summary> /// Satisfies the imports of the specified attributed object exactly once and they will not /// ever be recomposed. /// </summary> /// <param name="attributedPart"> /// The attributed object to set the imports. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="compositionService"/> or <paramref name="attributedPart"/> or <paramref name="reflectionContext"/> is <see langword="null"/>. /// </exception> /// <exception cref="CompositionException"> /// An error occurred during composition. <see cref="CompositionException.Errors"/> will /// contain a collection of errors that occurred. /// </exception> /// <exception cref="ObjectDisposedException"> /// The <see cref="ICompositionService"/> has been disposed of. /// </exception> public static ComposablePart SatisfyImportsOnce(this ICompositionService compositionService, object attributedPart, ReflectionContext reflectionContext) { Requires.NotNull(compositionService, nameof(compositionService)); Requires.NotNull(attributedPart, nameof(attributedPart)); Requires.NotNull(reflectionContext, nameof(reflectionContext)); ComposablePart part = AttributedModelServices.CreatePart(attributedPart, reflectionContext); compositionService.SatisfyImportsOnce(part); Debug.Assert(part != null); return(part); }
public override void PerformReflection(ReflectionContext context) { Type workflowType = ((WorkflowNode)context.CurrentTreeNode).WorkflowType; DependencyObject workflow = ((WorkflowNode)context.CurrentTreeNode).WorkflowType.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, null, CultureInfo.InvariantCulture) as DependencyObject; if (workflow == null) { throw new ApplicationException("Could not create the workflow and cast to DependencyObject"); } RuleDefinitions definitions = workflow.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions; if (definitions != null) { foreach (RuleCondition cond in definitions.Conditions) { RuleNode node = new RuleNode(); node.Rule = cond; node.SelectedImageIndex = node.ImageIndex = context.GetImageIndex(typeof(RuleComponent), RuleNodeImageName); context.CurrentTreeNode.Nodes.Add(node); ReflectChildComponents(context.CreateClone(node)); } } }
/// <summary> /// Creates a catalog of <see cref="ComposablePartDefinition"/>s based on all the *.dll files /// in the given directory path. /// /// Possible exceptions that can be thrown are any that <see cref="Directory.GetFiles(string, string)"/> or /// <see cref="Assembly.Load(AssemblyName)"/> can throw. /// </summary> /// <param name="path"> /// Path to the directory to scan for assemblies to add to the catalog. /// The path needs to be absolute or relative to <see cref="AppDomain.BaseDirectory"/> /// </param> /// <param name="reflectionContext"> /// The <see cref="ReflectionContext"/> a context used by the catalog when /// interpreting the types to inject attributes into the type definition. /// </param> /// <exception cref="ArgumentException"> /// If <paramref name="path"/> is a zero-length string, contains only white space, or /// contains one or more implementation-specific invalid characters. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is <see langword="null"/> or /// <paramref name="reflectionContext"/> is <see langword="null"/>. /// </exception> /// <exception cref="DirectoryNotFoundException"> /// The specified <paramref name="path"/> is invalid (for example, it is on an unmapped drive). /// </exception> /// <exception cref="PathTooLongException"> /// The specified <paramref name="path"/>, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters and file names must /// be less than 260 characters. /// </exception> /// <exception cref="UnauthorizedAccessException"> /// The caller does not have the required permission. /// </exception> public DirectoryCatalog(string path, ReflectionContext reflectionContext) : this(path, "*.dll", reflectionContext) { }
public override void PerformReflection(ReflectionContext context) { if (context.CurrentTreeNode.ContextMenu != null) { throw new ApplicationException("XamlContextMenuComponent only works with ContextMenuStrip menus. The WorkflowComponent node had an old ContextMenu assigned."); } ContextMenuStrip menu = null; if (context.CurrentTreeNode.ContextMenuStrip != null) { menu = context.CurrentTreeNode.ContextMenuStrip; } else { menu = new ContextMenuStrip(); context.CurrentTreeNode.ContextMenuStrip = menu; } ToolStripMenuItem evaluateItem = new ToolStripMenuItem(); evaluateItem.Tag = context.CurrentTreeNode; evaluateItem.Text = "Evaluate Rule"; evaluateItem.Click += OnItemClick; menu.Items.Add(evaluateItem); }
/// <summary> /// Initializes a new instance of the <see cref="ReflectionAssemblyScanner"/> class. /// </summary> /// <param name="parent">The parent <see cref="IScanner{T}"/> that this scanner retieves it's items from.</param> /// <param name="reflectionContext">The context used to reflect over <see cref="Assembly"/> objects.</param> /// <exception cref="ArgumentNullException">The <paramref name="parent"/> argument is a null.</exception> /// <exception cref="ArgumentNullException">The <paramref name="reflectionContext"/> argument is a null.</exception> public ReflectionAssemblyScanner(IScanner <Assembly> parent, ReflectionContext reflectionContext) : base(parent, reflectionContext) { // nothing }