Exemple #1
0
        /// <summary>
        /// Create the main form and flow the programs inbound
        /// command line arguments.
        /// </summary>
        /// <param name="args">Command line arguments passed
        /// by the hosting program.</param>
        public MainForm(string[] args)
        {
            InitializeComponent();

            assemblyResolverDialog = new OpenFileDialogAssemblyResolver();

            imageList1.Images.Add(OutOfBoxComponentResources.EmptyNode);

            componentMapping  = new Dictionary <Type, List <Type> >();
            imageIndexMapping = new Dictionary <Type, Dictionary <string, int> >();

            WorkflowReflectionUtilitySection section = System.Configuration.ConfigurationManager.GetSection("WorkflowReflectorSettings") as WorkflowReflectionUtilitySection;

            // If no configuration section was found then
            // use the default OOB components.
            if (section == null)
            {
                section = new WorkflowReflectionUtilitySection();
                section.ShowAssemblyResolveExplanation = true;
                section.Components.Add(new ReflectionComponentElement(typeof(AssemblyComponent)));
                section.Components.Add(new ReflectionComponentElement(typeof(WorkflowComponent)));
                section.Components.Add(new ReflectionComponentElement(typeof(RuleComponent)));
                section.Components.Add(new ReflectionComponentElement(typeof(RequiredServiceInterfacesComponent)));
                section.Components.Add(new ReflectionComponentElement(typeof(XamlContextMenuComponent)));
                section.Components.Add(new ReflectionComponentElement(typeof(WorkflowDesignerViewComponent)));
                section.Components.Add(new ReflectionComponentElement(typeof(RuleEvaluatorComponent)));
                section.Components.Add(new ReflectionComponentElement(typeof(WorkflowActivitiesComponent)));
            }

            assemblyResolverDialog.ShowAssemblyResolveExplanation = section.ShowAssemblyResolveExplanation;

            InitializationContext context = new InitializationContext(componentMapping, imageList1, imageIndexMapping);

            // Initialize each component.
            foreach (ReflectionComponentElement element in section.Components)
            {
                Type nodeType = Type.GetType(element.Type);

                if (nodeType == null)
                {
                    MessageBox.Show(string.Format("Could not find type '{0}'.  Application will run without that component.", element.Type));
                    continue;
                }

                WorkflowReflectionComponent node = nodeType.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, null, CultureInfo.InvariantCulture) as WorkflowReflectionComponent;
                node.Initialize(context);
            }

            if (args != null && args.Length > 0)
            {
                LoadAssembly(args[0]);
            }
        }
        /// <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);
            }
        }