示例#1
0
        protected override void PerformLoad(IDesignerSerializationManager designerSerializationManager)
        {
            this.host = this.LoaderHost;

            if (host == null)
            {
                throw new ArgumentNullException("BasicHostLoader.BeginLoad: Invalid designerLoaderHost.");
            }

            ArrayList errors     = new ArrayList();
            bool      successful = true;
            string    baseClassName;

            if (fileName == null)
            {
                if (rootComponentType == typeof(Form))
                {
                    IComponent component = host.CreateComponent(rootComponentType);
                    (component as Form).FormBorderStyle = FormBorderStyle.None;
                    (component as Form).Size            = Screen.PrimaryScreen.Bounds.Size;
                    baseClassName = "Form1";
                }
                else if (rootComponentType == typeof(UserControl))
                {
                    host.CreateComponent(typeof(UserControl));
                    baseClassName = "UserControl1";
                }
                else if (rootComponentType == typeof(Component))
                {
                    host.CreateComponent(typeof(Component));
                    baseClassName = "Component1";
                }
                else
                {
                    throw new Exception("Undefined Host Type: " + rootComponentType.ToString());
                }
            }
            else
            {
                baseClassName = AssemblyHelper.ReadFile(fileName, errors, out xmlDocument, host);
            }

            IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (cs != null)
            {
                cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
                cs.ComponentAdded   += new ComponentEventHandler(OnComponentAddedRemoved);
                cs.ComponentRemoved += new ComponentEventHandler(OnComponentAddedRemoved);
            }

            host.EndLoad(baseClassName, successful, errors);

            _dirty   = true;
            _unsaved = false;
        }
示例#2
0
 public static IComponent CreateComponent(IDesignerLoaderHost host, Type type, string name)
 {
     if (typeof(IComponent).IsAssignableFrom(type))
     {
         if (host != null)
         {
             INameCreationService cs = host.GetService(typeof(INameCreationService)) as INameCreationService;
             if (cs != null)
             {
                 IVplNameService ns = cs as IVplNameService;
                 if (ns != null)
                 {
                     ns.ComponentType = type;
                 }
             }
             return(host.CreateComponent(type, name));
         }
         else
         {
             IComponent ic = (IComponent)CreateObject(type);
             ic.Site      = new XTypeSite(ic);
             ic.Site.Name = name;
             return(ic);
         }
     }
     if (host != null)
     {
         INameCreationService cs = host.GetService(typeof(INameCreationService)) as INameCreationService;
         if (cs != null)
         {
             IVplNameService ns = cs as IVplNameService;
             if (ns != null)
             {
                 ns.ComponentType = typeof(XClass);
             }
         }
         XClass obj = (XClass)host.CreateComponent(typeof(XClass), name);
         obj.AssignType(type);
         obj.AssignValue(CreateObject(type));
         return(obj);
     }
     else
     {
         XClass obj = new XClass();
         obj.Site      = new XTypeSite(obj);
         obj.Site.Name = name;
         obj.AssignType(type);
         obj.AssignValue(CreateObject(type));
         return(obj);
     }
 }
示例#3
0
			// Note that IDesignerLoader : IDesignerHost
			//
			public override void BeginLoad (IDesignerLoaderHost loaderHost)
			{
				_loading = true;
				// initializa root component and designer
				//
				loaderHost.CreateComponent (_componentType);
				// finish off loading - no error collection here.
				//
				loaderHost.EndLoad (_componentType.FullName, true, null);
				_loading = false;
			}
示例#4
0
 // Note that IDesignerLoader : IDesignerHost
 //
 public override void BeginLoad(IDesignerLoaderHost loaderHost)
 {
     _loading = true;
     // initializa root component and designer
     //
     loaderHost.CreateComponent(_componentType);
     // finish off loading - no error collection here.
     //
     loaderHost.EndLoad(_componentType.FullName, true, null);
     _loading = false;
 }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceControl"></param>
        /// <returns></returns>
        Control CreateComponent(Control sourceControl, MgControlType controlType)
        {
            Control newCtrl = null;

            if (controlType == MgControlType.CTRL_TYPE_DOTNET)
            {
                newCtrl = CreateDotNetWrapper(sourceControl);
            }
            else if (controlType == MgControlType.CTRL_TYPE_COMBO && ((MgComboBox)sourceControl).DrawMode == DrawMode.OwnerDrawFixed)
            {
                newCtrl = CreateMgFlexiCombo(sourceControl);
            }
            else if (SelectIsAllowed(sourceControl))
            {
                newCtrl = (Control)host.CreateComponent(GetCreateType(sourceControl));
            }
            else
            {
                newCtrl = (Control)Activator.CreateInstance(GetCreateType(sourceControl));
            }
            return(newCtrl);
        }
示例#6
0
        public ReportModel LoadOrCreateReport()
        {
            Application.UseWaitCursor = true;
            var rootComponent = host.CreateComponent(typeof(RootReportModel), "RootReportModel");
            var rootControl   = rootComponent as RootReportModel;

            UpdateStatusbar();
            var reportModel = CreateNamedSurface();

            rootControl.Size          = reportModel.ReportSettings.PageSize;
            Application.UseWaitCursor = false;
            return(reportModel);
        }
示例#7
0
        // Called by the host when we load a document.
        protected override void PerformLoad(IDesignerSerializationManager designerSerializationManager)
        {
            this.host = this.LoaderHost;

            if (host == null)
            {
                throw new ArgumentNullException("BasicHostLoader.BeginLoad: Invalid designerLoaderHost.");
            }

            // The loader will put error messages in here.
            ArrayList errors     = new ArrayList();
            bool      successful = true;
            string    baseClassName;

            // If no filename was passed in, just create a form and be done with it.  If a file name
            // was passed, read it.
            if (fileName == null)
            {
                host.CreateComponent(rootComponentType);
                baseClassName = rootComponentType.Name;
            }
            else
            {
                baseClassName = ReadFile(fileName, errors, out xmlDocument);
            }

            // Now that we are done with the load work, we need to begin to listen to events.
            // Listening to event notifications is how a designer "Loader" can also be used
            // to save data.  If we wanted to integrate this loader with source code control,
            // we would listen to the "ing" events as well as the "ed" events.
            IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (cs != null)
            {
                cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
                cs.ComponentAdded   += new ComponentEventHandler(OnComponentAddedRemoved);
                cs.ComponentRemoved += new ComponentEventHandler(OnComponentAddedRemoved);
            }

            // Let the host know we are done loading.
            host.EndLoad(baseClassName, successful, errors);

            // We've just loaded a document, so you can bet we need to flush changes.
            dirty   = true;
            unsaved = false;
        }
            public override void BeginLoad(IDesignerLoaderHost loaderHost)
            {
                string baseClassName = null;

                if (this._type != null)
                {
                    loaderHost.CreateComponent(this._type);
                    baseClassName = this._type.FullName;
                }
                else
                {
                    foreach (IComponent component in this._components)
                    {
                        loaderHost.Container.Add(component);
                    }
                }
                loaderHost.EndLoad(baseClassName, true, null);
            }
            /// <include file='doc\DocumentManager.uex' path='docs/doc[@for="DocumentManager.ComponentDesignerLoader.BeginLoad"]/*' />
            /// <devdoc>
            ///     The host will call this method when it wants to load whatever
            ///     data the code stream contains.  There are three times when this
            ///     method can be called.  First, a code stream is handed to the
            ///     host to initially create the document, so load will be called there.
            ///     Second, when a code steam is first declared through IPersistenceService,
            ///     it will be loaded immediately.  Finally, if the document needs to be
            ///     re-loaded because the user changed one or more files, then all code
            ///     streams will be re-loaded.
            /// </devdoc>
            public override void BeginLoad(IDesignerLoaderHost host)
            {
                if (this.host == null)
                {
                    host.AddService(typeof(IDesignerLoaderService), this);
                }

                this.host = host;

                loadCount = 1;
                if (errorList == null)
                {
                    errorList = new ArrayList();
                }
                else
                {
                    errorList.Clear();
                }

                bool successful = true;

                if (host != null)
                {
                    Type c = host.GetType(componentClass);
                    if (c == null)
                    {
                        errorList.Add(new Exception(SR.GetString(SR.PersisterClassNotFound, componentClass)));
                    }
                    else
                    {
                        IComponent component = null;

                        try {
                            component = host.CreateComponent(c);
                        }
                        catch (Exception e) {
                            errorList.Add(e);
                            successful = false;
                        }
                    }
                    ((IDesignerLoaderService)this).DependentLoadComplete(successful, errorList);
                }
            }
示例#10
0
            public override void BeginLoad(IDesignerLoaderHost loaderHost)
            {
                string typeName = null;

                if (_type != null)
                {
                    loaderHost.CreateComponent(_type);
                    typeName = _type.FullName;
                }
                else
                {
                    foreach (IComponent component in _components)
                    {
                        loaderHost.Container.Add(component);
                    }
                }

                loaderHost.EndLoad(typeName, true, null);
            }
        public virtual IComponent CreateInstance(Type type, string name)
        {
            IComponent c = null;

            try
            {
                VPLUtil.SetupExternalDllResolve(Path.GetDirectoryName(type.Assembly.Location));
            }
            catch
            {
            }
            try
            {
                if (_loaderHost == null)
                {
                    c = (IComponent)Activator.CreateInstance(type);
                }
                else
                {
                    c = _loaderHost.CreateComponent(type, name);
                    //VPLUtil.FixPropertyValues(c);
                }
                if (c != null)
                {
                    VPLUtil.FixPropertyValues(c);
                }
                else
                {
                    MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "Cannot create design time instance for type [{0}], name:[{1}]", type.AssemblyQualifiedName, name), "Load design object");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "Cannot create design time instance for type [{0}], name:[{1}]. Error:{2}", type.AssemblyQualifiedName, name, err.Message), "Load design object");
                throw;
            }
            finally
            {
                VPLUtil.RemoveExternalDllResolve();
            }
            return(c);
        }
        public override void BeginLoad(IDesignerLoaderHost host)
        {
            string baseClassName;

            if (host == null)
            {
                throw new ArgumentNullException("SampleDesignerLoader.BeginLoad: Invalid designerLoaderHost.");
            }
            this.host = host;
            ArrayList errors     = new ArrayList();
            bool      successful = true;

            host.AddService(typeof(IDesignerSerializationManager), new SampleDesignerSerializationManager(this));
            host.AddService(typeof(IEventBindingService), new SampleEventBindingService(host));
            host.AddService(typeof(ITypeResolutionService), new SampleTypeResolutionService());
            host.AddService(typeof(CodeDomProvider), new CSharpCodeProvider());
            host.AddService(typeof(IResourceService), new SampleResourceService(host));
            if (this.fileName == null)
            {
                baseClassName = host.CreateComponent(typeof(Form)).Site.Name;
            }
            else
            {
                baseClassName = this.ReadFile(this.fileName, errors, out this.xmlDocument);
            }
            IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (cs != null)
            {
                cs.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
                cs.ComponentAdded   += new ComponentEventHandler(this.OnComponentAddedRemoved);
                cs.ComponentRemoved += new ComponentEventHandler(this.OnComponentAddedRemoved);
            }
            host.EndLoad(baseClassName, successful, errors);
            this.dirty   = true;
            this.unsaved = false;
        }
        ///     Creates an instance of the given type and adds it to a collection
        ///     of named instances.  Objects that implement IComponent will be
        ///     added to the design time container if addToContainer is true.
        object IDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, string name, bool addToContainer)
        {
            object[] argArray = null;

            if (arguments != null && arguments.Count > 0)
            {
                argArray = new object[arguments.Count];
                arguments.CopyTo(argArray, 0);
            }

            object instance = null;

            // We do some special casing here.  If we are adding to the container, and if this type
            // is an IComponent, then we don't create the instance through Activator, we go
            // through the loader host.  The reason for this is that if we went through activator,
            // and if the object already specified a constructor that took an IContainer, our
            // deserialization mechanism would equate the container to the designer host.  This
            // is the correct thing to do, but it has the side effect of adding the component
            // to the designer host twice -- once with a default name, and a second time with
            // the name we provide.  This equates to a component rename, which isn't cheap,
            // so we don't want to do it when we load each and every component.
            //
            if (addToContainer && typeof(IComponent).IsAssignableFrom(type))
            {
                IDesignerLoaderHost host = _loader.LoaderHost;
                if (host != null)
                {
                    if (name == null)
                    {
                        instance = host.CreateComponent(type);
                    }
                    else
                    {
                        instance = host.CreateComponent(type, name);
                    }
                }
            }

            if (instance == null)
            {
                // If we have a name but the object wasn't a component
                // that was added to the design container, save the
                // name/value relationship in our own nametable.
                //
                if (name != null && _instancesByName != null)
                {
                    if (_instancesByName.ContainsKey(name))
                    {
                        Exception ex = new InvalidOperationException("Duplicate component declaration for " + name + ".");
                        throw ex;
                    }
                }

                try
                {
                    instance = Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, argArray, null);
                }
                catch (MissingMethodException)
                {
                    StringBuilder argTypes = new StringBuilder();
                    foreach (object o in argArray)
                    {
                        if (argTypes.Length > 0)
                        {
                            argTypes.Append(", ");
                        }

                        if (o != null)
                        {
                            argTypes.Append(o.GetType().Name);
                        }
                        else
                        {
                            argTypes.Append("null");
                        }
                    }

                    Exception ex = new InvalidOperationException("No matching constructor for " + type.FullName + "(" + argTypes.ToString() + ")");
                    throw ex;
                }

                // If we have a name but the object wasn't a component
                // that was added to the design container, save the
                // name/value relationship in our own nametable.
                //
                if (name != null)
                {
                    if (_instancesByName == null)
                    {
                        _instancesByName = new Hashtable();
                        _namesByInstance = new Hashtable();
                    }

                    _instancesByName[name]     = instance;
                    _namesByInstance[instance] = name;
                }
            }

            return(instance);
        }
 public override void BeginLoad(IDesignerLoaderHost host)
 {
     string baseClassName;
     if (host == null)
     {
         throw new ArgumentNullException("SampleDesignerLoader.BeginLoad: Invalid designerLoaderHost.");
     }
     this.host = host;
     ArrayList errors = new ArrayList();
     bool successful = true;
     host.AddService(typeof(IDesignerSerializationManager), new SampleDesignerSerializationManager(this));
     host.AddService(typeof(IEventBindingService), new SampleEventBindingService(host));
     host.AddService(typeof(ITypeResolutionService), new SampleTypeResolutionService());
     host.AddService(typeof(CodeDomProvider), new CSharpCodeProvider());
     host.AddService(typeof(IResourceService), new SampleResourceService(host));
     if (this.fileName == null)
     {
         baseClassName = host.CreateComponent(typeof(Form)).Site.Name;
     }
     else
     {
         baseClassName = this.ReadFile(this.fileName, errors, out this.xmlDocument);
     }
     IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
     if (cs != null)
     {
         cs.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
         cs.ComponentAdded += new ComponentEventHandler(this.OnComponentAddedRemoved);
         cs.ComponentRemoved += new ComponentEventHandler(this.OnComponentAddedRemoved);
     }
     host.EndLoad(baseClassName, successful, errors);
     this.dirty = true;
     this.unsaved = false;
 }
示例#15
0
        /// Reads the "Object" tags. This returns an instance of the
        /// newly created object. Returns null if there was an error.
        private object ReadObject(XmlNode node, ArrayList errors)
        {
            XmlAttribute typeAttr = node.Attributes["type"];

            if (typeAttr == null)
            {
                errors.Add("<Object> tag is missing required type attribute");
                return(null);
            }

            Type type = Type.GetType(typeAttr.Value);

            if (type == null)
            {
                errors.Add(string.Format("Type {0} could not be loaded.", typeAttr.Value));
                return(null);
            }

            // This can be null if there is no name for the object.
            //
            XmlAttribute nameAttr = node.Attributes["name"];

            object instance = null;
            bool   bExist   = false;

            foreach (IComponent c in host.Container.Components)
            {
                if (c.Site.Name == nameAttr.Value)
                {
                    bExist   = true;
                    instance = c;
                }
            }

            if (bExist == false)
            {
                if (typeof(IComponent).IsAssignableFrom(type))
                {
                    if (nameAttr == null)
                    {
                        instance = host.CreateComponent(type);
                    }
                    else
                    {
                        instance = host.CreateComponent(type, nameAttr.Value);
                    }
                }
                else
                {
                    instance = Activator.CreateInstance(type);
                }
            }

            // Got an object, now we must process it.  Check to see if this tag
            // offers a child collection for us to add children to.
            //
            XmlAttribute childAttr = node.Attributes["children"];
            IList        childList = null;

            if (childAttr != null)
            {
                PropertyDescriptor childProp = TypeDescriptor.GetProperties(instance)[childAttr.Value];

                if (childProp == null)
                {
                    errors.Add(string.Format("The children attribute lists {0} as the child collection but this is not a property on {1}", childAttr.Value, instance.GetType().FullName));
                }
                else
                {
                    childList = childProp.GetValue(instance) as IList;
                    if (childList == null)
                    {
                        errors.Add(string.Format("The property {0} was found but did not return a valid IList", childProp.Name));
                    }
                }
            }

            // Now, walk the rest of the tags under this element.
            //
            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.Name.Equals("Object"))
                {
                    // Another object.  In this case, create the object, and
                    // parent it to ours using the children property.  If there
                    // is no children property, bail out now.
                    if (childAttr == null)
                    {
                        errors.Add("Child object found but there is no children attribute");
                        continue;
                    }

                    // no sense doing this if there was an error getting the property.  We've already reported the
                    // error above.
                    if (childList != null)
                    {
                        object childInstance = ReadObject(childNode, errors);

                        childList.Add(childInstance);
                    }
                }
                else if (childNode.Name.Equals("Property"))
                {
                    // A property.  Ask the property to parse itself.
                    //
                    ReadProperty(childNode, instance, errors);
                }
                else if (childNode.Name.Equals("Event"))
                {
                    // An event.  Ask the event to parse itself.
                    //
                    ReadEvent(childNode, instance, errors);
                }
            }

            return(instance);
        }
示例#16
0
        object IDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, string name, bool addToContainer)
        {
            object[] argArray = null;
            if ((arguments != null) && (arguments.Count > 0))
            {
                argArray = new object[arguments.Count];
                arguments.CopyTo(argArray, 0);
            }
            object instance = null;

            if (addToContainer && typeof(IComponent).IsAssignableFrom(type))
            {
                IDesignerLoaderHost host = this._loader.LoaderHost;
                if (host != null)
                {
                    if (name == null)
                    {
                        instance = host.CreateComponent(type);
                    }
                    else
                    {
                        instance = host.CreateComponent(type, name);
                    }
                }
            }
            if (instance == null)
            {
                Exception ex;
                if (((name != null) && (this._instancesByName != null)) && this._instancesByName.ContainsKey(name))
                {
                    ex = new InvalidOperationException("Duplicate component declaration for " + name + ".");
                    throw ex;
                }
                try
                {
                    instance = Activator.CreateInstance(type, BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance, null, argArray, null);
                }
                catch (MissingMethodException)
                {
                    StringBuilder argTypes = new StringBuilder();
                    foreach (object o in argArray)
                    {
                        if (argTypes.Length > 0)
                        {
                            argTypes.Append(", ");
                        }
                        if (o != null)
                        {
                            argTypes.Append(o.GetType().Name);
                        }
                        else
                        {
                            argTypes.Append("null");
                        }
                    }
                    ex = new InvalidOperationException("No matching constructor for " + type.FullName + "(" + argTypes.ToString() + ")");
                    throw ex;
                }
                if (name == null)
                {
                    return(instance);
                }
                if (this._instancesByName == null)
                {
                    this._instancesByName = new Hashtable();
                    this._namesByInstance = new Hashtable();
                }
                this._instancesByName[name]     = instance;
                this._namesByInstance[instance] = name;
            }
            return(instance);
        }
 private void loadControl(IDesignerLoaderHost host)
 {
     ctrl          = host.CreateComponent(typeof(T), "A" + Guid.NewGuid().GetHashCode().ToString("x")) as Control;
     ctrl.Location = new Point(0, 0);
     this.Controls.Add(ctrl);
 }
示例#18
0
        /// <summary>
        /// 读取"Object"标签,返回设计的实例:Object对象。
        /// 根据类型和名称生成相应的控件。
        /// 对描述文件中控件的属性Property节点,则调用函数ReadProperty,对控件的相应属性进行值的设定。
        /// 该函数被递归调用。
        /// </summary>
        /// <param name="node">父节点</param>
        /// <param name="errors">加载期间遇到的错误(如果有的话)的集合</param>
        /// <returns>控件对象</returns>
        private object ReadObject(XmlNode node, ArrayList errors)
        {
            //XmlNode.Attributes 获取一个 XmlAttributeCollection,它包含该节点的属性。
            //这里是获得"type"的属性
            XmlAttribute typeAttr = node.Attributes["type"];
            object       instance = null;

            if (typeAttr == null)
            {
                errors.Add("没有type节点");
                return(null);
            }

            try
            {
                Type type = Type.GetType(typeAttr.Value);
                if (type == null)       //没有找到匹配的
                {
                    errors.Add(string.Format("type节点的内容为空.", typeAttr.Value));
                    return(null);
                }

                XmlAttribute nameAttr = node.Attributes["name"];

                if (typeof(IComponent).IsAssignableFrom(type))  //确定当前的 Type 的实例是否可以从指定 Type 的实例分配。
                {
                    if (nameAttr == null)
                    {
                        instance = hostLoader.CreateComponent(type);
                    }
                    else if (nameAttr.Value.Equals(currentForm))
                    {
                        instance = hostLoader.RootComponent;   //当前对象为CassView,即为根设计器
                    }
                    else
                    {
                        instance = hostLoader.CreateComponent(type, nameAttr.Value);
                    }
                }
                else
                {
                    instance = Activator.CreateInstance(type);
                }
                IList childList = null;

                //通过将指定的属性 (Attribute) 数组用作筛选器并使用自定义类型说明符来返回指定组件的属性 (Property) 的集合
                //PropertyDescriptor childProp = TypeDescriptor.GetProperties(instance)[childAttr.Value];
                PropertyDescriptor childProp = TypeDescriptor.GetProperties(instance)["Controls"];

                if (childProp == null)
                {
                    errors.Add(string.Format(" 该实例并不包含Control属性"));
                }
                else
                {
                    //PropertyDescriptor.GetValue 方法,获取组件上的属性的当前值,通常,通过反射实现此方法
                    childList = childProp.GetValue(instance) as IList;
                    if (childList == null)
                    {
                        errors.Add(string.Format("属性 {0} 已找到但并不是有效属性链表", childProp.Name));
                    }
                }

                //现在开始遍历子元素
                object    childInstance = null;
                ArrayList combineList   = new ArrayList();  //组合队列
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    if (childNode.Name.Equals("Object"))
                    {
                        if (childList != null)
                        {
                            childInstance = ReadObject(childNode, errors);
                            if (childInstance != null)
                            {
                                combineList.Add(childInstance);
                                childList.Add(childInstance);
                            }
                        }
                    }
                    else if (childNode.Name.Equals("Property"))
                    {
                        ReadProperty(childNode, instance, errors);
                    }
                }
            }
            catch (Exception ex)
            {
                //CassMessageBox.Error("创建对象失败!");
                errors.Add(ex.Message);
            }
            return(instance);
        }
示例#19
0
		// Called by the host when we load a document.
		protected override void PerformLoad(IDesignerSerializationManager designerSerializationManager)
		{
			this.host = this.LoaderHost;

			if (host == null)
			{
				throw new ArgumentNullException("BasicHostLoader.BeginLoad: Invalid designerLoaderHost.");
			}

			// The loader will put error messages in here.
			ArrayList errors = new ArrayList();
			bool successful = true;
			string baseClassName;

			// If no filename was passed in, just create a form and be done with it.  If a file name
			// was passed, read it.
			if (fileName == null)
			{
                baseClassName = name;
				if (rootComponentType == typeof(Form))
				{
					host.CreateComponent(typeof(Form));
				}
				else if (rootComponentType == typeof(UserControl))
				{
					host.CreateComponent(typeof(UserControl));
				}
				else if (rootComponentType == typeof(Component))
				{
					host.CreateComponent(typeof(Component));
				}
				else
				{
					throw new Exception("Undefined Host Type: " + rootComponentType.ToString());
				}
			}
			else
			{
				baseClassName = ReadFile(fileName, errors, out xmlDocument);
			}

			// Now that we are done with the load work, we need to begin to listen to events.
			// Listening to event notifications is how a designer "Loader" can also be used
			// to save data.  If we wanted to integrate this loader with source code control,
			// we would listen to the "ing" events as well as the "ed" events.
			IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

			if (cs != null)
			{
				cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
				cs.ComponentAdded += new ComponentEventHandler(OnComponentAddedRemoved);
				cs.ComponentRemoved += new ComponentEventHandler(OnComponentAddedRemoved);
			}

			// Let the host know we are done loading.
			host.EndLoad(baseClassName, successful, errors);

			// We've just loaded a document, so you can bet we need to flush changes.
			dirty = true;
			unsaved = false;
		}
示例#20
0
 public override void BeginLoad(IDesignerLoaderHost loaderHost)
 {
     loaderHost.CreateComponent(_type);
     loaderHost.EndLoad(_type.FullName, true, null);
 }
		// Called by the host when we load a document.
		public override void BeginLoad(IDesignerLoaderHost host) 
		{
			if (host == null) 
			{
				throw new ArgumentNullException("SampleDesignerLoader.BeginLoad: Invalid designerLoaderHost.");
			}

			this.host = host;

			// The loader will put error messages in here.
			//
			ArrayList errors = new ArrayList();
			bool successful = true;
			string baseClassName;
			
			// The loader is responsible for providing certain services to the host.
			//
			host.AddService(typeof(IDesignerSerializationManager), new SampleDesignerSerializationManager(this));
			host.AddService(typeof(IEventBindingService), new SampleEventBindingService(host));
			host.AddService(typeof(ITypeResolutionService), new SampleTypeResolutionService());
			host.AddService(typeof(CodeDomProvider), new CSharpCodeProvider());
			host.AddService(typeof(IResourceService), new SampleResourceService(host));

			// If no filename was passed in, just create a form and be done with it.  If a file name
			// was passed, read it.
			//
			if (fileName == null) 
			{
				baseClassName = host.CreateComponent(typeof(System.Windows.Forms.Form)).Site.Name;
			}
			else 
			{
				baseClassName = ReadFile(fileName, errors, out xmlDocument);
			}

			// Now that we are done with the load work, we need to begin to listen to events.
			// Listening to event notifications is how a designer "Loader" can also be used
			// to save data.  If we wanted to integrate this loader with source code control,
			// we would listen to the "ing" events as well as the "ed" events.
			//
			IComponentChangeService cs = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
			if (cs != null)
			{
				cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
				cs.ComponentAdded += new ComponentEventHandler(OnComponentAddedRemoved);
				cs.ComponentRemoved += new ComponentEventHandler(OnComponentAddedRemoved);
			}

			// Let the host know we are done loading.
			host.EndLoad(baseClassName, successful, errors);
			
			// We've just loaded a document, so you can bet we need to flush changes.
			dirty = true;
			unsaved = false;
		}
 public override void BeginLoad(IDesignerLoaderHost loaderHost)
 {
     string baseClassName = null;
     if (this._type != null)
     {
         loaderHost.CreateComponent(this._type);
         baseClassName = this._type.FullName;
     }
     else
     {
         foreach (IComponent component in this._components)
         {
             loaderHost.Container.Add(component);
         }
     }
     loaderHost.EndLoad(baseClassName, true, null);
 }