Example #1
0
        private void LoadAssembly(string fullPath)
        {
            if (fullPath == null)
            {
                throw new ArgumentNullException("fullPath");
            }

            try
            {
                var assembly = Assembly.LoadFrom(fullPath);
                BuildManager.AddReferencedAssembly(assembly);
                CompositionProvider.AddAssembly(assembly);
                _assemblies.Add(assembly);
            }
            catch (Exception err)
            {
                Trace.TraceWarning("Failed to load " + fullPath + ".", err);

                var loaderEx = err as ReflectionTypeLoadException;
                if (loaderEx != null)
                {
                    foreach (var exception in loaderEx.LoaderExceptions)
                    {
                        Trace.TraceWarning(string.Format("Loader exception for file '{0}'.", fullPath), exception);
                    }
                }

                throw;
            }
        }
Example #2
0
        public void Initialize()
        {
            PropertyGridTypeConverter.AddEditor(typeof(string), typeof(StringEditor));

            System.Windows.Forms.Integration.WindowsFormsHost.EnableWindowsFormsInterop();
            ComponentDispatcher.ThreadIdle -= ComponentDispatcher_ThreadIdle; // ensure we don't register twice
            ComponentDispatcher.ThreadIdle += ComponentDispatcher_ThreadIdle;

            CompositionProvider.LoadAssemblies();
        }
Example #3
0
        internal Assembly TryLoadAssemblyByName(string fileName, bool throwOnError = false)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                if (throwOnError)
                {
                    throw new ArgumentNullException("fileName");
                }

                return(null);
            }

            var fullPath = Path.Combine(_path, fileName);

            if (!File.Exists(fullPath))
            {
                if (throwOnError)
                {
                    throw new FileNotFoundException("file not found", fullPath);
                }

                return(null);
            }

            try
            {
                var assembly = Assembly.LoadFrom(fullPath);
                BuildManager.AddReferencedAssembly(assembly);
                CompositionProvider.AddAssembly(assembly);
                _assemblies.Add(assembly);
                return(assembly);
            }
            catch (Exception err)
            {
                Trace.TraceWarning("Failed to load " + fullPath + ".", err);

                var loaderEx = err as ReflectionTypeLoadException;
                if (loaderEx != null)
                {
                    foreach (var exception in loaderEx.LoaderExceptions)
                    {
                        Trace.TraceWarning(string.Format("Loader exception for file '{0}'.", fullPath), exception);
                    }
                }

                if (throwOnError)
                {
                    throw;
                }

                return(null);
            }
        }
Example #4
0
        protected virtual SerializableList <ISettings> LoadChildren()
        {
            SerializableList <ISettings>   result        = new SerializableList <ISettings>();
            OrderingCollection <ISettings> importedNodes = CompositionProvider.GetOrderedExports <ISettings>(this.GetType().FullName);

            foreach (var item in importedNodes)
            {
                result.Add(item.Value);
            }

            return(result);
        }
        /// <summary>
        /// Composes the specified composition context.
        /// </summary>
        /// <param name="compositionContext">The composition context.</param>
        private void compose(CompositionContext compositionContext)
        {
            var composition = CompositionProvider.Compose(compositionContext);

            CompositionResult.Set(composition);
            CompositionContext.Set(compositionContext);
            if (!composition.Failed)
            {
                Context.DynamicCall("$dynamic_composition", composition.Generator, compositionContext.InputInstances);
                Composed.Set(true);
            }
        }
Example #6
0
        protected void Application_Start()
        {
            // Initialize membership and role providers
            WebSecurity.InitializeDatabaseConnection("DefaultConnection", "Users", "Id", "Account", false);

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            CompositionProvider.AddAssembly(GetType().Assembly);
            CompositionProvider.AddAssembly(typeof(IActionVerb).Assembly);
        }
Example #7
0
        private IEnumerable <object> LoadContextMenuNodes(Type fromType)
        {
            var result = new List <object>();
            OrderingCollection <IContextMenuItem> orderedItems =
                CompositionProvider.GetOrderedExports <IContextMenuItem>(fromType);

            foreach (var item in orderedItems)
            {
                IContextMenuItem menuItem = item.Value;
                menuItem.SetupItem(this);
                result.Add(menuItem);
            }
            return(result);
        }
        public Dictionary <Type, ISPNode> GetChildrenTypes(ISPNode parentNode)
        {
            IEnumerable <Lazy <SPNode> > importedNodes = CompositionProvider.GetExports <SPNode>(parentNode.Descriptor.ClassType);
            var types = new Dictionary <Type, ISPNode>();

            foreach (var lazyItem in importedNodes)
            {
                SPNode node = lazyItem.Value;
                node.NodeProvider = parentNode.NodeProvider;

                if (node.Descriptor.AdapterItemType != null)
                {
                    types.AddOrReplace(node.Descriptor.AdapterItemType, node);
                }
            }
            return(types);
        }
Example #9
0
        public MenuItem()
        {
            OrderingCollection <MenuItem> orderedItems = CompositionProvider.GetOrderedExports <MenuItem>(this.GetType());

            //string name = AttributedModelServices.GetContractName(this.GetType());

            //var result = CompositionProvider.Current.GetExports<MenuItem, IOrderMetadata>(name);

            //// Add the items to an ordered list
            //foreach (var item in result)
            //{
            //    orderedItems.Add(item);
            //}

            // now add the items to the menu child items collection in a ordered list
            foreach (var item in orderedItems)
            {
                this.Items.Add(item.Value);
            }
        }
        /// <summary>
        /// Processes the composition.
        /// </summary>
        /// <param name="notConstructed">The not constructed instances.</param>
        /// <param name="constructed">The constructed instances.</param>
        /// <param name="toRemove">Instances to be removed from composition.</param>
        private void processComposition(IEnumerable <Instance> notConstructed, IEnumerable <Instance> constructed, IEnumerable <Instance> toRemove)
        {
            if (notConstructed == null)
            {
                notConstructed = new Instance[0];
            }

            if (constructed == null)
            {
                constructed = new Instance[0];
            }

            if (toRemove == null)
            {
                toRemove = new Instance[0];
            }

            var composition = new CompositionContext(CallingAssemblyServices, Context);

            notConstructed = notConstructed.Except(toRemove);
            constructed    = constructed.Except(toRemove);

            //add components that needs importing constructor call
            composition.AddNotConstructedComponents(notConstructed);

            //add instances that doesn't need constructor call
            composition.AddConstructedComponents(constructed);

            //create composition
            var compositionResult = CompositionProvider.Compose(composition);

            CompositionResult.Set(compositionResult);

            if (!compositionResult.Failed)
            {
                //if composition building is OK then process composition
                Context.DynamicCall("$dynamic_composition", composition.Generator, composition.InputInstances);
            }
        }