public HostControl GetNewHostFromFile(string fileName) { if (fileName == null || !File.Exists(fileName)) { MessageBox.Show("FileName is incorrect: " + fileName); } if (fileName.EndsWith("xml")) { HostSurface hostSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer); IDesignerHost host = (IDesignerHost)hostSurface.GetService(typeof(IDesignerHost)); BasicHostLoader basicHostLoader = new BasicHostLoader(fileName); hostSurface.BeginLoad(basicHostLoader); hostSurface.Loader = basicHostLoader; hostSurface.Initialize(); return(new HostControl(hostSurface)); } else { StreamReader sr = new StreamReader(fileName); string strSourceCode = sr.ReadToEnd(); return(GetHostFromSourceCode(strSourceCode)); } }
public HostControl GetNewHost(Type rootComponentType, LoaderType loaderType) { if (loaderType == LoaderType.NoLoader) { return(GetNewHost(rootComponentType)); } HostSurface hostSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer); IDesignerHost host = (IDesignerHost)hostSurface.GetService(typeof(IDesignerHost)); switch (loaderType) { case LoaderType.BasicDesignerLoader: BasicHostLoader basicHostLoader = new BasicHostLoader(rootComponentType); hostSurface.BeginLoad(basicHostLoader); hostSurface.Loader = basicHostLoader; break; case LoaderType.CodeDomDesignerLoader: CodeDomHostLoader codeDomHostLoader = new CodeDomHostLoader(); hostSurface.BeginLoad(codeDomHostLoader); hostSurface.Loader = codeDomHostLoader; break; default: throw new Exception("Loader is not defined: " + loaderType.ToString()); } hostSurface.Initialize(); return(new HostControl(hostSurface)); }