示例#1
0
        /// <summary>
        /// Flushes all changes to the designer.
        /// </summary>
        /// <param name="serializationManager">An <see cref="T:System.ComponentModel.Design.Serialization.IDesignerSerializationManager"/> to use for persisting the state of loaded designers.</param>
        protected override void PerformFlush(IDesignerSerializationManager serializationManager)
        {
            bool          success = true;
            ArrayList     errors  = new ArrayList();
            IDesignerHost idh     = (IDesignerHost)this.Host.GetService(typeof(IDesignerHost));

            Controls.ISerializableControl serializable = (LoaderHost.RootComponent as Controls.ISerializableControl);
            if (serializable == null)
            {
                throw new ApplicationException("Invalid root control type in designer.");
            }

            Serialization.SerializationObject serializationObject = this.GetSerializationObject();

            try
            {
                this.Buffer = this.SerializeFrameXml(serializationObject);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);

                success = false;
                errors.Add(exception);
            }

            IDesignerLoaderHost host = this.LoaderHost;

            host.EndLoad(FrameXmlDesignerLoader.hostedBaseClassName, success, errors);

            Trace.WriteLine("PerformFlush");
        }
示例#2
0
        /// <summary>
        /// 载入页面的时候调用,负责从xml文件读取信息
        /// 调用函数ReadFile进行描述文件节点的具体信息处理,根据读取的信息进行设计器的加载。
        /// </summary>
        /// <param name="document">需要加载的xml文件</param>
        /// <returns></returns>
        public bool MyPerformLoad(XmlDocument document)
        {
            ArrayList errors        = new ArrayList();
            bool      successful    = true; //标志加载过程是否成功
            string    baseClassName = null;

            this.hostLoader = this.LoaderHost;  //获取加载程序宿主。(从 BasicDesignerLoader 继承。)

            if (hostLoader == null)
            {
                //CassMessageBox.Warning("设计器加载异常!");
                return(false);
            }

            //存放错误信息,如果加载期间遇到错误,则必须将这些错误作为异常集合传递到 errorCollection 参数中。
            baseClassName = ReadFile(document, errors);

            if (baseClassName == null)
            {
                return(false);
            }

            if (errors.Count > 0)
            {
                successful = false;
            }

            // 结束设计器加载操作。
            //baseClassName 此设计器正在设计的文档的基类的完全限定名。
            //successful 如果设计器已成功加载,则为 true;否则为 false。
            //errorCollection 包含加载期间遇到的错误(如果有的话)的集合。
            hostLoader.EndLoad(baseClassName, successful, errors);
            return(successful);
        }
示例#3
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;
        }
示例#4
0
        protected override void PerformLoad(IDesignerSerializationManager designerSerializationManager)
        {
            this.host = this.LoaderHost;
            ArrayList errors     = new ArrayList();
            bool      successful = true;
            string    baseClassName;

            baseClassName = "Home";
            host.EndLoad(baseClassName, successful, errors);
        }
示例#5
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;
			}
示例#6
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;
 }
示例#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 = "Form1";


            if (rootComponentType == typeof(Form))
            {
                //Control control = (Control)host.CreateComponent(typeof(GuiForm));

                ControlFactory factory = new ControlFactory(host, createAllOwnerDrawControls, getControlDesignerInfo, runtimeHostSurface);
                Form           form    = factory.PrepearForm(formToClone, null) as Form;
                TypeDescriptor.GetProperties(form)["Locked"].SetValue(form, true);
                baseClassName = "Form1";

                SetSerializedValues(form);

                SetVisibility(form);
            }

            // 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;
        }
            /// <include file='doc\DocumentManager.uex' path='docs/doc[@for="DocumentManager.ComponentDesignerLoader.IDesignerLoaderService.DependentLoadComplete"]/*' />
            /// <devdoc>
            ///     This is called by any object that has previously called
            ///     AddLoadDependency to signal that the dependent load has completed.
            ///     The caller should pass either an empty collection or null to indicate
            ///     a successful load, or a collection of exceptions that indicate the
            ///     reason(s) for failure.
            /// </devdoc>
            void IDesignerLoaderService.DependentLoadComplete(bool successful, ICollection errorCollection)
            {
                if (loadCount > 0)
                {
                    if (errorCollection != null && errorList != null)
                    {
                        errorList.AddRange(errorCollection);
                    }

                    loadCount--;

                    if (loadCount == 0)
                    {
                        host.EndLoad(null, successful, errorList);
                    }
                }
            }
示例#9
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);
            }
示例#11
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);
            }
        protected virtual void OnEndLoad(bool successful, ICollection errors)
        {
            _host.EndLoad(_baseComponentClassName, successful, errors);

            if (successful)
            {
                _loaded = true;
                EnableComponentNotification(true);
            }
            else
            {
                if (_reloadScheduled) // we are reloading
                {
                    bool modify = ((_reloadOptions & ReloadOptions.ModifyOnError) == ReloadOptions.ModifyOnError);
                    if (modify)
                    {
                        OnModifying();
                        this.Modified = true;
                    }
                }
            }
            _loading = false;
        }
        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;
        }
 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);
 }
 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;
 }
		// 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;
		}
示例#17
0
        protected override void OnBeginLoad()
        {
            CodeCompileUnit ccu = null;

            ds = new DesignSurface();
            ds.BeginLoad(typeof(Form));
            IDesignerHost idh = (IDesignerHost)ds.GetService(typeof(IDesignerHost));

            idh.RootComponent.Site.Name = "Form1";

            cg  = new CodeGen();
            ccu = cg.GetCodeCompileUnit(idh);

            AssemblyName[] names = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
            for (int i = 0; i < names.Length; i++)
            {
                Assembly assembly = Assembly.Load(names[i]);
                ccu.ReferencedAssemblies.Add(assembly.Location);
            }

            codeCompileUnit = ccu;

            this.host = this.LoaderHost;

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

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

                // 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 = 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;
            }
        }
示例#18
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;
		}
示例#19
0
 public override void BeginLoad(IDesignerLoaderHost loaderHost)
 {
     loaderHost.CreateComponent(_type);
     loaderHost.EndLoad(_type.FullName, true, null);
 }
        /// <summary>
        /// ����ҳ���ʱ����ã������xml�ļ���ȡ��Ϣ
        /// ���ú���ReadFile���������ļ��ڵ�ľ�����Ϣ��������ݶ�ȡ����Ϣ����������ļ��ء�
        /// </summary>
        /// <param name="document">��Ҫ���ص�xml�ļ�</param>
        /// <returns></returns>
        public bool MyPerformLoad(XmlDocument document)
        {
            ArrayList errors = new ArrayList();
            bool successful = true;        //��־���ع����Ƿ�ɹ�
            string baseClassName = null;
            this.hostLoader = this.LoaderHost;  //��ȡ���س������������� BasicDesignerLoader �̳С���

            if (hostLoader == null)
            {
                //CassMessageBox.Warning("����������쳣��");
                return false;
            }

            //��Ŵ�����Ϣ,��������ڼ�������������뽫��Щ������Ϊ�쳣���ϴ��ݵ� errorCollection �����С�
            baseClassName = ReadFile(document, errors);

            if (baseClassName == null)
            {
                return false;
            }

            if (errors.Count > 0)
            {
                successful = false;
            }

            // ������������ز�����
            //baseClassName �������������Ƶ��ĵ��Ļ������ȫ�޶�����
            //successful ���������ѳɹ����أ���Ϊ true������Ϊ false��
            //errorCollection ���������ڼ������Ĵ�������еĻ����ļ��ϡ�
            hostLoader.EndLoad(baseClassName, successful, errors);
            return successful;
        }