Example #1
0
        public void Load(IProgressEx Progress)
        {
            AssemblyLoader  asmLoader = new AssemblyLoader();
            ProgressExValue pV        = new ProgressExValue();

            // Flatten the tree of views, so it can be iterated
            _flattenViewDictionary = FlattenViewTree(_views);

            foreach (KeyValuePair <string, DynView> entry in _flattenViewDictionary)
            {
                string viewAssembly;
                string className;
                string nameSpace;

                string logMessage = string.Format(Resources.Messages.LoadingViewFile, entry.Value.Name);

                if (Progress != null)
                {
                    pV.MainStatus = logMessage;
                    Progress.Report(pV);
                }

                if (VerboseLoad)
                {
                    Parent.MainLogger.Log(logMessage, 0, LogMessageType.Information, LogReceiver.Console);
                }

                // Search for the View's DLL file
                if (!DiscoverViewAssembly(entry.Value, out viewAssembly, out nameSpace, out className))
                {
                    Parent.MainLogger.Log(new ViewNotFoundException(String.Format(Resources.Messages.CanNotFindView, entry.Value.Ident)),
                                          LogReceiver.Console | LogReceiver.MessageBox);

                    HasExceptions = true;

                    continue;
                }

                string ViewPluginType = String.Format("{0}.{1}", nameSpace, className);

                IView plugin = null;

                try
                {
                    plugin = asmLoader.Load <IView>(viewAssembly, ViewPluginType);
                }
                catch (Exception ex)
                {
                    throw new ViewException(ex.Message);
                }

                if (plugin == null)
                {
                    throw new ViewException(String.Format(Resources.Messages.CanNotLoadView, entry.Value.Ident));
                }

                entry.Value.Plugin = plugin;
            }

            int i = 0;

            // Initializing the views (calling the LoadPlugin method)
            foreach (KeyValuePair <string, DynView> entry in _flattenViewDictionary)
            {
                if (entry.Value.Plugin == null)
                {
                    continue;
                }

                string logMessage = string.Format(Resources.Messages.InitializingView, entry.Value.Name);

                if (Progress != null)
                {
                    pV.MainStatus = logMessage;
                    pV.Percentage = i * 100 / _flattenViewDictionary.Count;
                    Progress.Report(pV);
                }

                if (VerboseLoad)
                {
                    Parent.MainLogger.Log(logMessage, 0, LogMessageType.Information, LogReceiver.Console);
                }

                entry.Value.Load(Progress);

                i++;
            }

            Progress.Report(null);
        }
Example #2
0
        public void Load(IProgressEx Progress)
        {
            AssemblyLoader asmLoader = new AssemblyLoader();

            // Loading the assemblies
            foreach (DynComponent component in this)
            {
                string logMessage = string.Format("Loading component '{0}'...", component.Ident);

                if (Progress != null)
                {
                    ProgressExValue pV = new ProgressExValue();
                    pV.MainStatus = logMessage;
                    Progress.Report(pV);
                }

                if (VerboseLoad)
                {
                    Parent.MainLogger.Log(logMessage, 0, LogMessageType.Information, LogReceiver.Console);
                }

                string ComponentAssembly = DiscoverComponentAssembly(component);

                if (string.IsNullOrEmpty(ComponentAssembly))
                {
                    throw new ComponentNotFoundException(String.Format("Can not find the component '{0}' of type '{1}'",
                                                                       component.Ident, component.ComponentType));
                }

                string ComponentType = String.Format("{0}.{1}", component.Ident, component.ComponentType);

                try
                {
                    switch (component.ComponentType)
                    {
                    case "Target":
                        component.Plugin = asmLoader.Load <ITarget>(ComponentAssembly, ComponentType);
                        break;

                    default:
                        component.Plugin = asmLoader.Load <IComponent>(ComponentAssembly, ComponentType);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    throw new ComponentException(ex.Message);
                }

                if (component.Plugin == null)
                {
                    throw new ComponentException(String.Format("Can not load the component '{0}'", component.Ident));
                }
            }

            int i = 0;

            // Loading the components
            foreach (DynComponent component in this)
            {
                string logMessage = string.Format("Initializing component '{0}'...", component.Ident);

                if (Progress != null)
                {
                    ProgressExValue pV = new ProgressExValue();
                    pV.MainStatus = logMessage;
                    pV.Percentage = i * 100 / this._components.Count;
                    Progress.Report(pV);
                }

                if (VerboseLoad)
                {
                    Parent.MainLogger.Log(logMessage, 0, LogMessageType.Information, LogReceiver.Console);
                }

                component.Load(Progress);

                i++;
            }

            Progress.Report(null);
        }