コード例 #1
0
 //- The DesignSurface class provides several design-time services automatically.
 //- The DesignSurface class adds all of its services in its constructor.
 //- Most of these services can be overridden by replacing them in the
 //- protected ServiceContainer property.To replace a service, override the constructor,
 //- call base, and make any changes through the protected ServiceContainer property.
 private void InitServices()
 {
     //- each DesignSurface has its own default services
     //- We can leave the default services in their present state,
     //- or we can remove them and replace them with our own.
     //- Now add our own services using IServiceContainer
     //-
     //-
     //- Note
     //- before loading the root control in the design surface
     //- we must add an instance of naming service to the service container.
     //- otherwise the root component did not have a name and this caused
     //- troubles when we try to use the UndoEngine
     //-
     //-
     //- 1. NameCreationService
     _nameCreationService = new NameCreationServiceImp();
     if (_nameCreationService != null)
     {
         this.ServiceContainer.RemoveService(typeof(INameCreationService), false);
         this.ServiceContainer.AddService(typeof(INameCreationService), _nameCreationService);
     }
     //-
     //-
     //- 2. CodeDomComponentSerializationService
     _codeDomComponentSerializationService = new CodeDomComponentSerializationService(this.ServiceContainer);
     if (_codeDomComponentSerializationService != null)
     {
         //- the CodeDomComponentSerializationService is ready to be replaced
         this.ServiceContainer.RemoveService(typeof(ComponentSerializationService), false);
         this.ServiceContainer.AddService(typeof(ComponentSerializationService), _codeDomComponentSerializationService);
     }
     //-
     //-
     //- 3. IDesignerSerializationService
     _designerSerializationService = new DesignerSerializationServiceImpl(this.ServiceContainer);
     if (_designerSerializationService != null)
     {
         //- the IDesignerSerializationService is ready to be replaced
         this.ServiceContainer.RemoveService(typeof(IDesignerSerializationService), false);
         this.ServiceContainer.AddService(typeof(IDesignerSerializationService), _designerSerializationService);
     }
     //-
     //-
     //- 4. UndoEngine
     _undoEngine = new UndoEngineExt(this.ServiceContainer);
     //- disable the UndoEngine
     _undoEngine.Enabled = false;
     if (_undoEngine != null)
     {
         //- the UndoEngine is ready to be replaced
         this.ServiceContainer.RemoveService(typeof(UndoEngine), false);
         this.ServiceContainer.AddService(typeof(UndoEngine), _undoEngine);
     }
     //-
     //-
     //- 5. IMenuCommandService
     this.ServiceContainer.AddService(typeof(IMenuCommandService), new MenuCommandService(this));
     this.ServiceContainer.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService());
 }
コード例 #2
0
        public SampleDesignerHost(IServiceProvider parentProvider)
        {
            this.serviceContainer = new ServiceContainer(parentProvider);
            this.designerTable    = new Hashtable();
            this.sites            = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
            this.loadingDesigner  = false;
            this.transactionCount = 0;
            this.reloading        = false;
            this.serviceContainer.AddService(typeof(IDesignerHost), this);
            this.serviceContainer.AddService(typeof(IContainer), this);
            this.serviceContainer.AddService(typeof(IComponentChangeService), this);
            this.serviceContainer.AddService(typeof(IExtenderProviderService), this);
            this.serviceContainer.AddService(typeof(IDesignerEventService), this);
            CodeDomComponentSerializationService codeDomComponentSerializationService = new CodeDomComponentSerializationService(this.serviceContainer);

            if (codeDomComponentSerializationService != null)
            {
                this.serviceContainer.RemoveService(typeof(ComponentSerializationService), false);
                this.serviceContainer.AddService(typeof(ComponentSerializationService), codeDomComponentSerializationService);
            }
            ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService);

            this.serviceContainer.AddService(typeof(IToolboxService), callback);
            this.serviceContainer.AddService(typeof(ISelectionService), callback);
            this.serviceContainer.AddService(typeof(ITypeDescriptorFilterService), callback);
            this.serviceContainer.AddService(typeof(IMenuCommandService), callback);
            this.serviceContainer.AddService(typeof(IDesignerSerializationService), callback);
            ((IExtenderProviderService)this).AddExtenderProvider(new SampleNameExtenderProvider(this));
            ((IExtenderProviderService)this).AddExtenderProvider(new SampleInheritedNameExtenderProvider(this));
        }
        public void CodeDomComponentSerializationService_Constructor()
        {
            IServiceProvider provider = new DesignerSerializationManager();
            var underTest             = new CodeDomComponentSerializationService(provider);

            Assert.NotNull(underTest);
        }
コード例 #4
0
        public void BeginLoad_PassedFakeDesignerLoaderHost_ComponentSerializationServiceAddedToDesignerLoaderHost()
        {
            BeginLoad();
            CodeDomComponentSerializationService service = fakeDesignerLoaderHost.GetService(typeof(ComponentSerializationService)) as CodeDomComponentSerializationService;

            Assert.IsNotNull(service);
        }
コード例 #5
0
        //- The DesignSurface class provides several design-time services automatically. The DesignSurface class adds all of its services in its constructor.
        //- Most of these services can be overridden by replacing them in the protected ServiceContainer property.To replace a service, override the constructor,
        //- call base, and make any changes through the protected ServiceContainer property.
        private void InitServices()
        {
            //- Each DesignSurface has its own default services, We can leave the default services in their present state,
            //- or we can remove them and replace them with our own. Now add our own services using IServiceContainer.

            //- Note, before loading the root control in the design surface, we must add an instance of naming service to the service container.
            //- otherwise the root component did not have a name and this caused troubles when we try to use the UndoEngine

            //- 1. NameCreationService
            _nameCreationService = new Service.NameCreationServiceImp();
            InitServier(typeof(INameCreationService), _nameCreationService);

            //- 2. CodeDomComponentSerializationService, the CodeDomComponentSerializationService is ready to be replaced
            _codeDomComponentSerializationService = new CodeDomComponentSerializationService(this.ServiceContainer);
            InitServier(typeof(ComponentSerializationService), _codeDomComponentSerializationService);

            //- 3. IDesignerSerializationService, the IDesignerSerializationService is ready to be replaced
            _designerSerializationService = new Service.DesignerSerializationServiceImpl(this.ServiceContainer);
            InitServier(typeof(IDesignerSerializationService), _designerSerializationService);

            _eventService = new Service.EventBindingServiceImpl(this.ServiceContainer);
            InitServier(typeof(IEventBindingService), _eventService);

            //- 4. UndoEngine, the UndoEngine is ready to be replaced
            _undoService         = new Service.UndoServiceImpl(this.ServiceContainer);
            _undoService.Enabled = false;   //- disable the UndoEngine
            InitServier(typeof(UndoEngine), _undoService);

            //- 5. IMenuCommandService
            InitServier(typeof(IMenuCommandService), new MenuCommandService(this));
        }
コード例 #6
0
        /// <summary>
        /// 初始化设计界面
        /// </summary>
        /// <returns></returns>
        private SEDesignSurface InitialseDesignSurface()
        {
            //绑定事件
            this._designSurface.Loading   += new EventHandler(_designSurface_Loading);
            this._designSurface.Unloading += new EventHandler(_designSurface_Unloading);
            this._designSurface.Host.TransactionClosed += new DesignerTransactionCloseEventHandler(Host_TransactionClosed);

            #region 加载服务

            //共享的服务,如工具箱,在释放DesignSurface前,必须移除
            //否则会连同DesignSurface一起被释放掉

            CodeDomComponentSerializationService codeDomComponentSerializationService =
                new CodeDomComponentSerializationService(this._designSurface.GetServiceContainer());
            this._designSurface.Host.AddService(typeof(ComponentSerializationService), codeDomComponentSerializationService);

            //供一个可调用序列化和反序列化的接口
            this._designSurface.Host.AddService(typeof(IDesignerSerializationService),
                                                new SEDesignerSerializationService(this._designSurface.GetServiceContainer()));

            //工具盒服务
            this._designSurface.Host.AddService(typeof(IToolboxService), HostingContainer.Toolbox);

            //提供可以生成对象的唯一名称的服务
            this._designSurface.Host.AddService(typeof(INameCreationService), new SENameCreationService());

            //撤销/重复功能
            //_undoEngine= new SEUndoEngine(this._designSurface.GetServiceContainer());
            //this._designSurface.Host.AddService(typeof(UndoEngine), _undoEngine);

            //选择服务
            this._selectionService = (ISelectionService)(this._designSurface.GetService(typeof(ISelectionService)));

            //快捷菜单服务
            this._designSurface.Host.AddService(typeof(IMenuCommandService),
                                                new DesignerMenuCommandService(this._designSurface.GetServiceContainer()));

            this._menuCommandService = (IMenuCommandService)_designSurface.GetService(typeof(IMenuCommandService));

            //事件服务
            DesignerEventBindingService designerEventBindingService = new DesignerEventBindingService(this._designSurface.GetServiceContainer());
            this._designSurface.Host.AddService(typeof(IEventBindingService), designerEventBindingService);

            #endregion

            //创建窗体根对象
            //必须在获取View前创建,此函数完毕后需要使用View呈现
            this._rootComponentForm = this._designSurface.CreateRootComponent(
                _windowCompontsContainer.GetWindowDesignerRootComponent(), this._windowEntity.Size)
                                      as IWindowDesignerRootComponent;

            _rootComponentForm.Entity = _windowEntity;
            _rootComponentForm.UpdateView();

            this._designSurface.GetView().BackColor = Color.White;
            return(this._designSurface);
        }
コード例 #7
0
        private IntPtr CreateDesignerView(IVsHierarchy hierarchy, uint itemid, IVsTextLines textLines, ref string editorCaption, ref Guid cmdUI, string documentMoniker)
        {
            // Request the Designer Service
            IVSMDDesignerService designerService = (IVSMDDesignerService)GetService(typeof(IVSMDDesignerService));

            try
            {
                // Get the service provider
                IOleServiceProvider provider = serviceProvider.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider;
                IObjectWithSite     ows      = (IObjectWithSite)textLines;
                ows.SetSite(provider);
                // Create loader for the designer
                LimnorXmlDesignerLoader2 designerLoader = new LimnorXmlDesignerLoader2(documentMoniker, itemid);

                // Create the designer using the provider and the loader
                IVSMDDesigner designer = designerService.CreateDesigner(provider, designerLoader);

                designerLoader.AddComponentChangeEventHandler();

                // Retrieve the design surface
                DesignSurface designSurface = (DesignSurface)designer;

                IDesignerHost dh = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                dh.AddService(typeof(INameCreationService), new NameCreationService());

                IServiceContainer serviceContainer = dh.GetService(typeof(ServiceContainer)) as IServiceContainer;
                dh.AddService(typeof(IDesignerSerializationService), new DesignerSerializationService(serviceContainer));
                //DesignerSerializationService uses CodeDomComponentSerializationService
                CodeDomComponentSerializationService codeDomComponentSerializationService = new CodeDomComponentSerializationService(serviceContainer);
                dh.AddService(typeof(ComponentSerializationService), codeDomComponentSerializationService);

                //LimnorUndoEngine undoEngine = new LimnorUndoEngine(serviceContainer);
                //undoEngine.Enabled = false;//not use undo during loading
                //dh.AddService(typeof(UndoEngine), undoEngine);
                //object v = dh.GetService(typeof(IOleUndoManager));
                //if (v != null)
                //{
                //    object v2 = dh.GetService(typeof(UndoEngine));
                //    if (v2 == null)
                //    {
                //        dh.AddService(typeof(UndoEngine), v);
                //    }
                //}
                // Create pane with this surface
                LimnorXmlPane2 limnorXmlPane = new LimnorXmlPane2(designSurface);//, winControlPME);

                // Get command guid from designer
                cmdUI         = limnorXmlPane.CommandGuid;
                editorCaption = " [Design]";
                if (designerLoader.IsSetup)
                {
                }
                else
                {
                    if (limnorXmlPane.Loader.ObjectMap != null)
                    {
                        limnorXmlPane.BeginApplyConfig();
                    }
                }
                // Return LimnorXmlPane
                return(Marshal.GetIUnknownForObject(limnorXmlPane));
            }
            catch (Exception ex)
            {
                MathNode.Log(ex);
                //Trace.WriteLine("Exception: " + ex.Message);
                // Just rethrow for now
                throw;
            }
        }
コード例 #8
0
        internal void Initialize()
        {
            Control       control = null;
            IDesignerHost host    = (IDesignerHost)this.GetService(typeof(IDesignerHost));

            if (host == null)
            {
                return;
            }

            try
            {
                // Set the backcolor
                Type hostType = host.RootComponent.GetType();
                if (hostType == typeof(Form))
                {
                    control           = this.View as Control;
                    control.BackColor = Color.White;
                }
                else if (hostType == typeof(UserControl))
                {
                    control           = this.View as Control;
                    control.BackColor = Color.White;
                }
                else if (hostType == typeof(Component))
                {
                    control           = this.View as Control;
                    control.BackColor = Color.FloralWhite;
                }
                else
                {
                    throw new Exception("Undefined Host Type: " + hostType.ToString());
                }

                // Set SelectionService - SelectionChanged event handler
                _selectionService = (ISelectionService)(this.ServiceContainer.GetService(typeof(ISelectionService)));
                //_selectionService.SelectionChanged += new EventHandler(selectionService_SelectionChanged);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
            //lizheng add
            //- 1. CodeDomComponentSerializationService
            _codeDomComponentSerializationService = new CodeDomComponentSerializationService(this.ServiceContainer);
            if (_codeDomComponentSerializationService != null)
            {
                //- the CodeDomComponentSerializationService is ready to be replaced
                this.ServiceContainer.RemoveService(typeof(ComponentSerializationService), false);
                this.ServiceContainer.AddService(typeof(ComponentSerializationService), _codeDomComponentSerializationService);
            }
            //- 2. IDesignerSerializationService
            _designerSerializationService = new DesignerSerializationServiceImpl(this.ServiceContainer);
            if (_designerSerializationService != null)
            {
                //- the IDesignerSerializationService is ready to be replaced
                this.ServiceContainer.RemoveService(typeof(IDesignerSerializationService), false);
                this.ServiceContainer.AddService(typeof(IDesignerSerializationService), _designerSerializationService);
            }
            //
            //- 3. UndoEngine
            _undoEngine = new UndoEngineExt(this.ServiceContainer);
            //- disable the UndoEngine
            _undoEngine.Enabled = false;
            if (_undoEngine != null)
            {
                //- the UndoEngine is ready to be replaced
                this.ServiceContainer.RemoveService(typeof(UndoEngine), false);
                this.ServiceContainer.AddService(typeof(UndoEngine), _undoEngine);
            }
            _undoEngine.Enabled = true;

            //xhy
//             serviceProvider = this.GetService(typeof(IServiceContainer)) as IServiceContainer;
//             opsService = serviceProvider.GetService(typeof(DesignerOptionService)) as DesignerOptionService;
//             if (null != opsService)
//             {
//                 serviceProvider.RemoveService(typeof(DesignerOptionService));
//             }
//             DesignerOptionService opsService2 = new DesignerOptionServiceExt4NoGuides();
//             serviceProvider.AddService(typeof(DesignerOptionService), opsService2);
        }
コード例 #9
0
        public void ComponentSerializationServiceCreated()
        {
            CodeDomComponentSerializationService service = mockDesignerLoaderHost.GetService(typeof(ComponentSerializationService)) as CodeDomComponentSerializationService;

            Assert.IsNotNull(service);
        }
コード例 #10
0
        public ILimnorDesignPane CreateDesigner(ClassData classData)
        {
            ILimnorDesignPane limnorXmlPane = null;

            try
            {
                DesignUtil.LogIdeProfile("Create designer loader");
                LimnorXmlDesignerLoader2 designerLoader = new LimnorXmlDesignerLoader2(classData);
                DesignUtil.LogIdeProfile("Create designer surface");
                HostSurface designSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer);

                IDesignerHost dh = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));

                dh.AddService(typeof(INameCreationService), new NameCreationService());

                IServiceContainer serviceContainer = dh.GetService(typeof(ServiceContainer)) as IServiceContainer;
                DesignUtil.LogIdeProfile("Load designer surface");
                designSurface.Loader = designerLoader;
                designSurface.BeginLoad(designerLoader);
                if (VPLUtil.Shutingdown)
                {
                    return(null);
                }
                DesignUtil.LogIdeProfile("Add designer services");
                XMenuCommandService menuServices = new XMenuCommandService(serviceContainer);
                dh.AddService(typeof(IMenuCommandService), menuServices);
                menuServices.AddVerb(new DesignerVerb("Cut", null, StandardCommands.Cut));
                menuServices.AddVerb(new DesignerVerb("Copy", null, StandardCommands.Copy));
                menuServices.AddVerb(new DesignerVerb("Paste", null, StandardCommands.Paste));
                menuServices.AddVerb(new DesignerVerb("Delete", null, StandardCommands.Delete));
                menuServices.AddVerb(new DesignerVerb("Undo", null, StandardCommands.Undo));
                menuServices.AddVerb(new DesignerVerb("Redo", null, StandardCommands.Redo));

                if (dh.GetService(typeof(IDesignerSerializationService)) == null)
                {
                    dh.AddService(typeof(IDesignerSerializationService), new DesignerSerializationService(serviceContainer));
                }

                if (dh.GetService(typeof(ComponentSerializationService)) == null)
                {
                    //DesignerSerializationService uses CodeDomComponentSerializationService
                    CodeDomComponentSerializationService codeDomComponentSerializationService = new CodeDomComponentSerializationService(serviceContainer);
                    dh.AddService(typeof(ComponentSerializationService), codeDomComponentSerializationService);
                }
                VOB.UndoEngineImpl undoEngine = new VOB.UndoEngineImpl(serviceContainer);
                undoEngine.Enabled = false;
                dh.AddService(typeof(UndoEngine), undoEngine);

                designerLoader.AddComponentChangeEventHandler();
                DesignUtil.LogIdeProfile("Create designer pane");
                limnorXmlPane = new LimnorXmlPane2(designSurface, designerLoader);
                if (designerLoader.IsSetup)
                {
                }
                else
                {
                    DesignUtil.LogIdeProfile("Apply config");
                    if (limnorXmlPane.Loader.ObjectMap != null)
                    {
                        limnorXmlPane.BeginApplyConfig();
                    }
                }
                DesignUtil.LogIdeProfile("Initialize designer surface");
                designSurface.Initialize();
                ILimnorToolbox toolbox = (ILimnorToolbox)GetService(typeof(IToolboxService));
                toolbox.Host             = dh;
                this.ActiveDesignSurface = designSurface;
                //
            }
            catch (Exception ex)
            {
                MathNode.Log(TraceLogClass.MainForm, ex);
                // Just rethrow for now
                throw;
            }
            DesignUtil.LogIdeProfile("Finish creating designer");
            return(limnorXmlPane);
        }