public void DesignSurface_Dispose_MultipleTimes_Success()
        {
            var surface = new DesignSurface();

            surface.Dispose();
            surface.Dispose();
        }
 protected virtual void Dispose(bool isDisposing)
 {
     if (isDisposing)
     {
         designSurface.Dispose();
     }
 }
        public void DesignSurface_ComponentContainer_GetDisposed_ThrowsObjectDisposedException()
        {
            var surface = new DesignSurface();

            surface.Dispose();
            Assert.Throws <ObjectDisposedException>(() => surface.ComponentContainer);
        }
        public void DesignSurface_View_GetDisposed_ThrowsObjectDisposedException()
        {
            var surface = new DesignSurface();

            surface.Dispose();
            Assert.Throws <ObjectDisposedException>(() => surface.View);
        }
        public void DesignSurface_CreateDesigner_Disposed_ThrowsObjectDisposedException()
        {
            var surface = new DesignSurface();

            surface.Dispose();
            Assert.Throws <ObjectDisposedException>(() => surface.CreateDesigner(new Component(), true));
            Assert.Throws <ObjectDisposedException>(() => surface.CreateDesigner(new Component(), false));
        }
        public void DesignSurface_BeginLoad_Disposed_ThrowsObjectDisposedException()
        {
            var surface = new DesignSurface();

            surface.Dispose();
            var mockLoader = new Mock <DesignerLoader>(MockBehavior.Strict);

            Assert.Throws <ObjectDisposedException>(() => surface.BeginLoad(mockLoader.Object));
        }
Exemple #7
0
 public void Dispose()
 {
     if (_surface.IsLoaded)
     {
         IComponentChangeService changeService = (IComponentChangeService)_surface.GetService(typeof(IComponentChangeService));
         changeService.ComponentChanged -= new ComponentChangedEventHandler(OnComponentChanged);
         _surface.Dispose();
         _codeProvider = null;
     }
 }
        public void DesignSurface_Flush_InvokeDisposed_Nop()
        {
            var surface = new DesignSurface();

            surface.Dispose();
            surface.Flush();

            // Flush again.
            surface.Flush();
        }
Exemple #9
0
        /// <summary>
        /// Remove the current workflow from the designer
        /// </summary>
        private void ClearWorkflow()
        {
            if (_designSurface != null)
            {
                IDesignerHost designer = _designSurface.GetService(
                    typeof(IDesignerHost)) as IDesignerHost;
                if (designer != null)
                {
                    if (designer.Container.Components.Count > 0)
                    {
                        _wfLoader.RemoveFromDesigner(designer,
                                                     designer.RootComponent as Activity);
                    }
                }
            }

            if (_designSurface != null)
            {
                _designSurface.Dispose();
                _designSurface = null;
            }

            if (_workflowView != null)
            {
                ISelectionService selectionService
                    = ((IServiceProvider)_workflowView).GetService(
                          typeof(ISelectionService)) as ISelectionService;
                if (selectionService != null)
                {
                    selectionService.SelectionChanged -= new EventHandler(
                        selectionService_SelectionChanged);
                }

                Controls.Remove(_workflowView);
                _workflowView.Dispose();
                _workflowView = null;
            }

            if (_toolboxControl != null)
            {
                Controls.Remove(_toolboxControl);
            }
        }
        public void DesignSurface_Flush_InvokeWithFlushed_CallsHandler()
        {
            var surface   = new DesignSurface();
            int callCount = 0;

            surface.Flushed += (sender, e) =>
            {
                Assert.Same(surface, sender);
                Assert.Same(EventArgs.Empty, e);
                callCount++;
            };

            surface.Flush();
            Assert.Equal(1, callCount);

            // Fush again.
            surface.Flush();
            Assert.Equal(2, callCount);

            // Fush when disposed.
            surface.Dispose();
            surface.Flush();
            Assert.Equal(3, callCount);
        }
        void UnloadDesigner()
        {
            LoggingService.Debug("FormsDesigner unloading, setting ActiveDesignSurface to null");
            designSurfaceManager.ActiveDesignSurface = null;

            bool savedIsDirty = (this.DesignerCodeFile == null) ? false : this.DesignerCodeFile.IsDirty;

            this.UserControl = this.pleaseWaitLabel;
            Application.DoEvents();
            if (this.DesignerCodeFile != null)
            {
                this.DesignerCodeFile.IsDirty = savedIsDirty;
            }

            // We cannot dispose the design surface now because of SD2-451:
            // When the switch to the source view was triggered by a double-click on an event
            // in the PropertyPad, "InvalidOperationException: The container cannot be disposed
            // at design time" is thrown.
            // This is solved by calling dispose after the double-click event has been processed.
            if (designSurface != null)
            {
                designSurface.Loading   -= this.DesignerLoading;
                designSurface.Loaded    -= this.DesignerLoaded;
                designSurface.Flushed   -= this.DesignerFlushed;
                designSurface.Unloading -= this.DesignerUnloading;

                IComponentChangeService componentChangeService = designSurface.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                if (componentChangeService != null)
                {
                    componentChangeService.ComponentChanged -= ComponentChanged;
                    componentChangeService.ComponentAdded   -= ComponentListChanged;
                    componentChangeService.ComponentRemoved -= ComponentListChanged;
                    componentChangeService.ComponentRename  -= ComponentListChanged;
                }
                if (this.Host != null)
                {
                    this.Host.TransactionClosed -= TransactionClose;
                }

                ISelectionService selectionService = designSurface.GetService(typeof(ISelectionService)) as ISelectionService;
                if (selectionService != null)
                {
                    selectionService.SelectionChanged -= SelectionChangedHandler;
                }

                if (disposing)
                {
                    designSurface.Dispose();
                }
                else
                {
                    this.Control.BeginInvoke(new MethodInvoker(designSurface.Dispose));
                }
                designSurface = null;
            }

            this.typeResolutionService = null;
            this.loader = null;

            foreach (KeyValuePair <Type, TypeDescriptionProvider> entry in this.addedTypeDescriptionProviders)
            {
                TypeDescriptor.RemoveProvider(entry.Value, entry.Key);
            }
            this.addedTypeDescriptionProviders.Clear();
        }
        void UnloadDesigner()
        {
            LoggingService.Debug("FormsDesigner unloading, setting ActiveDesignSurface to null");
            designSurfaceManager.ActiveDesignSurface = null;
            timer.Stop();

            bool savedIsDirty = (this.DesignerCodeFile == null) ? false : this.DesignerCodeFile.IsDirty;

            this.UserContent = this.pleaseWaitLabel;
            if (this.DesignerCodeFile != null)
            {
                this.DesignerCodeFile.IsDirty = savedIsDirty;
            }

            if (designSurface != null)
            {
                designSurface.Loading   -= this.DesignerLoading;
                designSurface.Loaded    -= this.DesignerLoaded;
                designSurface.Flushed   -= this.DesignerFlushed;
                designSurface.Unloading -= this.DesignerUnloading;

                IComponentChangeService componentChangeService = designSurface.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                if (componentChangeService != null)
                {
                    componentChangeService.ComponentChanged -= ComponentChanged;
                    componentChangeService.ComponentAdded   -= ComponentListChanged;
                    componentChangeService.ComponentRemoved -= ComponentListChanged;
                    componentChangeService.ComponentRename  -= ComponentListChanged;
                }
                if (this.Host != null)
                {
                    this.Host.TransactionClosed -= TransactionClose;
                }

                ISelectionService selectionService = designSurface.GetService(typeof(ISelectionService)) as ISelectionService;
                if (selectionService != null)
                {
                    selectionService.SelectionChanged -= SelectionChangedHandler;
                }

                designSurface.Unloaded += delegate {
                    ServiceContainer serviceContainer = designSurface.GetService(typeof(ServiceContainer)) as ServiceContainer;
                    if (serviceContainer != null)
                    {
                        // Workaround for .NET bug: .NET unregisters the designer host only if no component throws an exception,
                        // but then in a finally block assumes that the designer host is already unloaded.
                        // Thus we would get the confusing "InvalidOperationException: The container cannot be disposed at design time"
                        // when any component throws an exception.

                        // See http://community.sharpdevelop.net/forums/p/10928/35288.aspx
                        // Reproducible with a custom control that has a designer that crashes on unloading
                        // e.g. http://www.codeproject.com/KB/toolbars/WinFormsRibbon.aspx

                        // We work around this problem by unregistering the designer host manually.
                        try {
                            var services = (Dictionary <Type, object>) typeof(ServiceContainer).InvokeMember(
                                "Services",
                                BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic,
                                null, serviceContainer, null);
                            foreach (var pair in services.ToArray())
                            {
                                if (pair.Value is IDesignerHost)
                                {
                                    serviceContainer.GetType().InvokeMember(
                                        "RemoveFixedService",
                                        BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic,
                                        null, serviceContainer, new object[] { pair.Key });
                                }
                            }
                        } catch (Exception ex) {
                            LoggingService.Error(ex);
                        }
                    }
                };
                try {
                    designSurface.Dispose();
                } catch (ExceptionCollection exceptions) {
                    foreach (Exception ex in exceptions.Exceptions)
                    {
                        LoggingService.Error(ex);
                    }
                } finally {
                    designSurface = null;
                }
            }

            this.typeResolutionService = null;
            this.loader = null;
            UpdatePropertyPad();

            foreach (KeyValuePair <Type, TypeDescriptionProvider> entry in this.addedTypeDescriptionProviders)
            {
                TypeDescriptor.RemoveProvider(entry.Value, entry.Key);
            }
            this.addedTypeDescriptionProviders.Clear();
        }
Exemple #13
0
        void ReleaseDesignerOutlets()
        {
            if (PointInspector != null)
            {
                PointInspector.Dispose();
                PointInspector = null;
            }

            if (ArrowInspector != null)
            {
                ArrowInspector.Dispose();
                ArrowInspector = null;
            }

            if (AttachedStyleInspector != null)
            {
                AttachedStyleInspector.Dispose();
                AttachedStyleInspector = null;
            }

            if (BackButton != null)
            {
                BackButton.Dispose();
                BackButton = null;
            }

            if (BooleanPropertyInspector != null)
            {
                BooleanPropertyInspector.Dispose();
                BooleanPropertyInspector = null;
            }

            if (BorderInspectorsButton != null)
            {
                BorderInspectorsButton.Dispose();
                BorderInspectorsButton = null;
            }

            if (ColorPaletteInspector != null)
            {
                ColorPaletteInspector.Dispose();
                ColorPaletteInspector = null;
            }

            if (ConnectionInspectorsButton != null)
            {
                ConnectionInspectorsButton.Dispose();
                ConnectionInspectorsButton = null;
            }

            if (ConnectionsInspector != null)
            {
                ConnectionsInspector.Dispose();
                ConnectionsInspector = null;
            }

            if (DesignSurface != null)
            {
                DesignSurface.Dispose();
                DesignSurface = null;
            }

            if (DetailsInspectorButton != null)
            {
                DetailsInspectorButton.Dispose();
                DetailsInspectorButton = null;
            }

            if (DocumentScrollView != null)
            {
                DocumentScrollView.Dispose();
                DocumentScrollView = null;
            }

            if (DocumentView != null)
            {
                DocumentView.Dispose();
                DocumentView = null;
            }

            if (DocumentViewHeight != null)
            {
                DocumentViewHeight.Dispose();
                DocumentViewHeight = null;
            }

            if (DocumentViewWidth != null)
            {
                DocumentViewWidth.Dispose();
                DocumentViewWidth = null;
            }

            if (ExportButton != null)
            {
                ExportButton.Dispose();
                ExportButton = null;
            }

            if (FillInspector != null)
            {
                FillInspector.Dispose();
                FillInspector = null;
            }

            if (FillInspectorsButton != null)
            {
                FillInspectorsButton.Dispose();
                FillInspectorsButton = null;
            }

            if (FontInspector != null)
            {
                FontInspector.Dispose();
                FontInspector = null;
            }

            if (FrameInspector != null)
            {
                FrameInspector.Dispose();
                FrameInspector = null;
            }

            if (GeneralInfoInspector != null)
            {
                GeneralInfoInspector.Dispose();
                GeneralInfoInspector = null;
            }

            if (GradientInspector != null)
            {
                GradientInspector.Dispose();
                GradientInspector = null;
            }

            if (GroupInspector != null)
            {
                GroupInspector.Dispose();
                GroupInspector = null;
            }

            if (InspectorScrollView != null)
            {
                InspectorScrollView.Dispose();
                InspectorScrollView = null;
            }

            if (InspectorView != null)
            {
                InspectorView.Dispose();
                InspectorView = null;
            }

            if (LanguageSelector != null)
            {
                LanguageSelector.Dispose();
                LanguageSelector = null;
            }

            if (LibrarySelector != null)
            {
                LibrarySelector.Dispose();
                LibrarySelector = null;
            }

            if (NumberPropertyInspector != null)
            {
                NumberPropertyInspector.Dispose();
                NumberPropertyInspector = null;
            }

            if (OSSelector != null)
            {
                OSSelector.Dispose();
                OSSelector = null;
            }

            if (PolygonInspector != null)
            {
                PolygonInspector.Dispose();
                PolygonInspector = null;
            }

            if (PortfolioInspector != null)
            {
                PortfolioInspector.Dispose();
                PortfolioInspector = null;
            }

            if (PropertyInspector != null)
            {
                PropertyInspector.Dispose();
                PropertyInspector = null;
            }

            if (RectPropertyInspector != null)
            {
                RectPropertyInspector.Dispose();
                RectPropertyInspector = null;
            }

            if (RoundRectInspector != null)
            {
                RoundRectInspector.Dispose();
                RoundRectInspector = null;
            }

            if (ScriptDebuggerInspector != null)
            {
                ScriptDebuggerInspector.Dispose();
                ScriptDebuggerInspector = null;
            }

            if (SketchInspector != null)
            {
                SketchInspector.Dispose();
                SketchInspector = null;
            }

            if (SketchPath != null)
            {
                SketchPath.Dispose();
                SketchPath = null;
            }

            if (SourceList != null)
            {
                SourceList.Dispose();
                SourceList = null;
            }

            if (StarInspector != null)
            {
                StarInspector.Dispose();
                StarInspector = null;
            }

            if (StyleInspector != null)
            {
                StyleInspector.Dispose();
                StyleInspector = null;
            }

            if (TextEditor != null)
            {
                TextEditor.Dispose();
                TextEditor = null;
            }

            if (TextEditorMode != null)
            {
                TextEditorMode.Dispose();
                TextEditorMode = null;
            }

            if (TextEditorTitle != null)
            {
                TextEditorTitle.Dispose();
                TextEditorTitle = null;
            }

            if (TextInspector != null)
            {
                TextInspector.Dispose();
                TextInspector = null;
            }

            if (TextPropertyInspector != null)
            {
                TextPropertyInspector.Dispose();
                TextPropertyInspector = null;
            }

            if (ToolArrow != null)
            {
                ToolArrow.Dispose();
                ToolArrow = null;
            }

            if (ToolBezier != null)
            {
                ToolBezier.Dispose();
                ToolBezier = null;
            }

            if (ToolCursor != null)
            {
                ToolCursor.Dispose();
                ToolCursor = null;
            }

            if (ToolLine != null)
            {
                ToolLine.Dispose();
                ToolLine = null;
            }

            if (ToolOval != null)
            {
                ToolOval.Dispose();
                ToolOval = null;
            }

            if (ToolPolygon != null)
            {
                ToolPolygon.Dispose();
                ToolPolygon = null;
            }

            if (ToolRect != null)
            {
                ToolRect.Dispose();
                ToolRect = null;
            }

            if (ToolRoundRect != null)
            {
                ToolRoundRect.Dispose();
                ToolRoundRect = null;
            }

            if (ToolStar != null)
            {
                ToolStar.Dispose();
                ToolStar = null;
            }

            if (ToolText != null)
            {
                ToolText.Dispose();
                ToolText = null;
            }

            if (ToolTriangle != null)
            {
                ToolTriangle.Dispose();
                ToolTriangle = null;
            }

            if (ToolVector != null)
            {
                ToolVector.Dispose();
                ToolVector = null;
            }
        }