public void DesignerSerializationManager_CreateSessionDispose_InvokeWithSessionDisposed_CallsHandler()
        {
            var          manager   = new DesignerSerializationManager();
            int          callCount = 0;
            EventHandler handler   = (sender, e) =>
            {
                Assert.Same(manager, sender);
                Assert.Same(EventArgs.Empty, e);
                callCount++;
            };

            manager.SessionDisposed += handler;

            IDisposable session = manager.CreateSession();

            session.Dispose();
            Assert.Equal(1, callCount);

            // Call again.
            session = manager.CreateSession();
            session.Dispose();
            Assert.Equal(2, callCount);

            // Remove handler.
            manager.SessionDisposed -= handler;
            session = manager.CreateSession();
            session.Dispose();
            Assert.Equal(2, callCount);
        }
        public void DesignerSerializationManager_CreateSession_InvokeWithSession_ThrowsInvalidOperationException()
        {
            var manager = new DesignerSerializationManager();

            manager.CreateSession();
            Assert.Throws <InvalidOperationException>(() => manager.CreateSession());
        }
        public void DesignerSerializationManager_CreateSession_Invoke_Success()
        {
            var         manager = new DesignerSerializationManager();
            IDisposable session = manager.CreateSession();

            Assert.NotNull(session);
            session.Dispose();

            // Get another.
            IDisposable session2 = manager.CreateSession();

            Assert.NotNull(session2);
            Assert.NotSame(session, session2);
            session2.Dispose();
        }
Exemple #4
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                Button button = (Button)host.CreateComponent(typeof(Button), "button1");
                button.Location = new Point(0, 0);
                button.Size     = new Size(10, 10);
                button.Text     = "button1";
                button.UseCompatibleTextRendering = false;
                form.Controls.Add(button);

                PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           acceptButtonPropertyDescriptor = descriptors.Find("AcceptButton", false);
                acceptButtonPropertyDescriptor.SetValue(form, button);

                PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    IScriptingCodeDomSerializer serializer = CreateSerializer();
                    generatedCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager);
                }
            }
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                Button button = (Button)host.CreateComponent(typeof(Button), "button1");
                button.Location = new Point(0, 0);
                button.Size     = new Size(10, 10);
                button.Text     = "button1";
                button.UseCompatibleTextRendering = false;

                button.FlatAppearance.BorderSize         = 2;
                button.FlatAppearance.BorderColor        = Color.Red;
                button.FlatAppearance.MouseOverBackColor = Color.Yellow;

                form.Controls.Add(button);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            resourceWriter   = new MockResourceWriter();
            componentCreator = new MockComponentCreator();
            componentCreator.SetResourceWriter(resourceWriter);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                host.AddService(typeof(IResourceService), componentCreator);

                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add ImageList.
                icon = new Icon(typeof(GenerateFormResourceTestFixture), "App.ico");
                ImageList imageList = (ImageList)host.CreateComponent(typeof(ImageList), "imageList1");
                imageList.Images.Add("App.ico", icon);
                imageList.Images.Add("", icon);
                imageList.Images.Add("", icon);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, "RootNamespace", 1);
                }
            }
        }
Exemple #7
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(284, 264);

                PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           descriptor  = descriptors.Find("MinimumSize", false);
                descriptor.SetValue(form, new Size(100, 200));
                descriptor = descriptors.Find("AutoScrollMinSize", false);
                descriptor.SetValue(form, new Size(10, 20));
                descriptor = descriptors.Find("AutoScrollMargin", false);
                descriptor.SetValue(form, new Size(11, 22));
                descriptor = descriptors.Find("AutoScroll", false);
                descriptor.SetValue(form, false);

                PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
Exemple #8
0
        internal static void Flush_Rules_DT(IServiceProvider serviceProvider, Activity activity)
        {
            RuleDefinitions rules = (RuleDefinitions)activity.GetValue(RuleDefinitions.RuleDefinitionsProperty);

            if (rules != null)
            {
                WorkflowDesignerLoader loader = (WorkflowDesignerLoader)serviceProvider.GetService(typeof(WorkflowDesignerLoader));
                if (loader != null)
                {
                    string rulesFileName = string.Empty;
                    if (!string.IsNullOrEmpty(loader.FileName))
                    {
                        rulesFileName = Path.Combine(Path.GetDirectoryName(loader.FileName), Path.GetFileNameWithoutExtension(loader.FileName));
                    }
                    rulesFileName += ".rules";

                    using (TextWriter ruleFileWriter = loader.GetFileWriter(rulesFileName))
                    {
                        if (ruleFileWriter != null)
                        {
                            using (XmlWriter xmlWriter = Helpers.CreateXmlWriter(ruleFileWriter))
                            {
                                DesignerSerializationManager designerSerializationManager = new DesignerSerializationManager(serviceProvider);
                                using (designerSerializationManager.CreateSession())
                                {
                                    new WorkflowMarkupSerializer().Serialize(designerSerializationManager, xmlWriter, rules);
                                }
                            }
                        }
                    }
                }
            }
        }
        internal static void Flush_Rules_DT(IServiceProvider serviceProvider, Activity activity)
        {
            RuleDefinitions definitions = (RuleDefinitions)activity.GetValue(RuleDefinitions.RuleDefinitionsProperty);

            if (definitions != null)
            {
                WorkflowDesignerLoader service = (WorkflowDesignerLoader)serviceProvider.GetService(typeof(WorkflowDesignerLoader));
                if (service != null)
                {
                    string filePath = string.Empty;
                    if (!string.IsNullOrEmpty(service.FileName))
                    {
                        filePath = Path.Combine(Path.GetDirectoryName(service.FileName), Path.GetFileNameWithoutExtension(service.FileName));
                    }
                    filePath = filePath + ".rules";
                    using (TextWriter writer = service.GetFileWriter(filePath))
                    {
                        if (writer != null)
                        {
                            using (XmlWriter writer2 = System.Workflow.Activities.Common.Helpers.CreateXmlWriter(writer))
                            {
                                DesignerSerializationManager serializationManager = new DesignerSerializationManager(serviceProvider);
                                using (serializationManager.CreateSession())
                                {
                                    new WorkflowMarkupSerializer().Serialize(serializationManager, writer2, definitions);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                DataGridView dataGridView = (DataGridView)host.CreateComponent(typeof(DataGridView), "dataGridView1");
                dataGridView.Location = new Point(0, 0);
                dataGridView.Size     = new Size(100, 100);
                form.Controls.Add(dataGridView);

                DataSet dataSet = (DataSet)host.CreateComponent(typeof(DataSet), "dataSet1");
                dataGridView.DataSource = dataSet;

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            resourceWriter   = new MockResourceWriter();
            componentCreator = new MockComponentCreator();
            componentCreator.SetResourceWriter(resourceWriter);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                host.AddService(typeof(IResourceService), componentCreator);

                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Set bitmap as form background image.
                bitmap = new Bitmap(10, 10);
                form.BackgroundImage = bitmap;

                icon      = new Icon(typeof(GenerateFormResourceTestFixture), "App.ico");
                form.Icon = icon;

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, "RootNamespace", 1);
                }
            }
        }
Exemple #12
0
        public void Save(string themeFilePath)
        {
            if ((themeFilePath == null) || (themeFilePath.Length == 0))
            {
                throw new ArgumentException(DR.GetString("ThemePathNotValid", new object[0]), "themeFilePath");
            }
            DesignerSerializationManager manager = new DesignerSerializationManager();

            using (manager.CreateSession())
            {
                WorkflowMarkupSerializationManager serializationManager = new WorkflowMarkupSerializationManager(manager);
                XmlWriter writer = null;
                ThemeSerializationProvider provider = new ThemeSerializationProvider();
                try
                {
                    string directoryName = Path.GetDirectoryName(themeFilePath);
                    if ((directoryName.Length > 0) && !Directory.Exists(directoryName))
                    {
                        Directory.CreateDirectory(directoryName);
                    }
                    writer = Helpers.CreateXmlWriter(themeFilePath);
                    serializationManager.AddSerializationProvider(provider);
                    new WorkflowMarkupSerializer().Serialize(serializationManager, writer, this);
                }
                finally
                {
                    serializationManager.RemoveSerializationProvider(provider);
                    if (writer != null)
                    {
                        writer.Close();
                    }
                }
                this.filePath = themeFilePath;
            }
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(284, 264);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                TextBox textBox = (TextBox)host.CreateComponent(typeof(TextBox), "textBox1");
                textBox.Size     = new Size(110, 20);
                textBox.TabIndex = 1;
                textBox.Location = new Point(10, 10);

                form.Controls.Add(textBox);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add table layout panel.
                TableLayoutPanel tableLayoutPanel1 = (TableLayoutPanel)host.CreateComponent(typeof(TableLayoutPanel), "tableLayoutPanel1");
                tableLayoutPanel1.ColumnCount = 2;
                tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F));
                tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 60F));
                tableLayoutPanel1.Location = new Point(0, 0);
                tableLayoutPanel1.RowCount = 2;
                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F));
                tableLayoutPanel1.Size     = new Size(200, 100);
                tableLayoutPanel1.TabIndex = 0;

                form.Controls.Add(tableLayoutPanel1);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
        //将DesignerHost中的Component转成CodeType
        private CodeTypeDeclaration ConvertComponentToCodeType()
        {
            //componentInDesign = this.LoadComponent(componentInDesign);
            DesignerSerializationManager manager = new DesignerSerializationManager(this._serviceProvider);
            //这句Code是必须的,必须要有一个session,DesignerSerializationManager才能工作
            IDisposable session = manager.CreateSession();

            TypeCodeDomSerializer serializer = manager.GetSerializer(componentInDesign.GetType(), typeof(TypeCodeDomSerializer)) as TypeCodeDomSerializer;
            List <object>         list       = new List <object>();

            foreach (IComponent item in this.DesignerHost.Container.Components)
            {
                //PropertyInfo vName = item.GetType().GetProperty("Name");

                //if (vName != null)
                //{
                //    string realName = vName.GetValue(item) as string;

                //    if (realName == "")
                //    {
                //        vName.SetValue(item, "RENAMED");
                //    }
                //}

                list.Add(item);
            }
            CodeTypeDeclaration declaration = serializer.Serialize(manager, componentInDesign, list);

            session.Dispose();
            return(declaration);
        }
        public void SetUpFixture()
        {
            MockTextEditorProperties textEditorProperties = new MockTextEditorProperties();

            generator       = new DerivedPythonDesignerGenerator();
            mockViewContent = new MockTextEditorViewContent();
            viewContent     = new FormsDesignerViewContent(mockViewContent, new MockOpenedFile("Test.py"));
            viewContent.DesignerCodeFileContent = GetTextEditorCode();
            generator.Attach(viewContent);
            viewContentAttached = generator.GetViewContent();

            ParseInformation parseInfo             = new ParseInformation();
            PythonParser     parser                = new PythonParser();
            ICompilationUnit parserCompilationUnit = parser.Parse(new DefaultProjectContent(), "Test.py", GetTextEditorCode());

            parseInfo.SetCompilationUnit(parserCompilationUnit);
            generator.ParseInfoToReturnFromParseFileMethod = parseInfo;

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(499, 309);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    generator.MergeRootComponentChanges(host, serializationManager);
                    generator.Detach();
                }
            }
        }
Exemple #17
0
        private void LoadDefFromReader(SqlDataReader reader, object parameter)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (!reader.Read())
            {
                throw new ArgumentException(ExecutionStringManager.InvalidDefinitionReader);
            }
            StringReader                 input                = new StringReader(reader.GetString(0));
            WorkflowMarkupSerializer     serializer           = new WorkflowMarkupSerializer();
            DesignerSerializationManager serializationManager = new DesignerSerializationManager();
            IList errors = null;

            try
            {
                using (serializationManager.CreateSession())
                {
                    using (XmlReader reader3 = XmlReader.Create(input))
                    {
                        this._def = serializer.Deserialize(serializationManager, reader3) as Activity;
                        errors    = serializationManager.Errors;
                    }
                }
            }
            finally
            {
                input.Close();
            }
            if ((this._def == null) || ((errors != null) && (errors.Count > 0)))
            {
                throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError);
            }
        }
Exemple #18
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add month calendar.
                MonthCalendar calendar = (MonthCalendar)host.CreateComponent(typeof(MonthCalendar), "monthCalendar1");
                calendar.TabIndex = 0;
                calendar.Location = new Point(0, 0);
                calendar.AddMonthlyBoldedDate(new DateTime(2009, 1, 2));
                calendar.AddMonthlyBoldedDate(new DateTime(0));

                form.Controls.Add(calendar);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
Exemple #19
0
        public void SetUpFixture()
        {
            AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor();
            document        = textEditor.Document;
            textEditor.Text = GetTextEditorCode();

            RubyParser       parser          = new RubyParser();
            ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.py", document.Text);

            using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) {
                IDesignerHost host        = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                UserControl   userControl = (UserControl)host.RootComponent;
                userControl.ClientSize = new Size(489, 389);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(userControl);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(userControl, "userControl1");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    AvalonEditDocumentAdapter docAdapter = new AvalonEditDocumentAdapter(document, null);
                    RubyDesignerGenerator     generator  = new RubyDesignerGenerator(new MockTextEditorOptions());
                    generator.Merge(host, docAdapter, compilationUnit, serializationManager);
                }
            }
        }
        public void SetUpFixture()
        {
            resourceWriter  = new MockResourceWriter();
            resourceService = new MockResourceService();
            resourceService.SetResourceWriter(resourceWriter);

            AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor();
            document        = textEditor.Document;
            textEditor.Text = GetTextEditorCode();

            RubyParser       parser          = new RubyParser();
            ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.rb", document.Text);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(499, 309);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyDesignerGenerator generator = new RubyDesignerGenerator(new MockTextEditorOptions());
                    generator.Merge(host, new AvalonEditDocumentAdapter(document, null), compilationUnit, serializationManager);
                }
            }
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add timer. This checks that the components Container is only created once in the
                // generated code.
                Timer timer = (Timer)host.CreateComponent(typeof(Timer), "timer1");

                // Add menu strip.
                ContextMenuStrip menuStrip = (ContextMenuStrip)host.CreateComponent(typeof(ContextMenuStrip), "contextMenuStrip1");

                // Set the context menu strip OwnerItem to simulate leaving the context menu
                // open in the designer before generating the source code. We do not want the
                // OwnerItem to be serialized.
                menuStrip.OwnerItem   = new DerivedToolStripMenuItem();
                menuStrip.RightToLeft = RightToLeft.No;
                menuStripSize         = menuStrip.Size;

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
Exemple #22
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                host.AddService(typeof(IEventBindingService), eventBindingService);

                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Simulate giving a name to the Load event handler in the property grid.
                EventDescriptorCollection events            = TypeDescriptor.GetEvents(form);
                EventDescriptor           loadEvent         = events.Find("Load", false);
                PropertyDescriptor        loadEventProperty = eventBindingService.GetEventProperty(loadEvent);
                loadEventProperty.SetValue(form, "MainFormLoad");

                // Add a second event handler method.
                EventDescriptor    closedEvent         = events.Find("FormClosed", false);
                PropertyDescriptor closedEventProperty = eventBindingService.GetEventProperty(closedEvent);
                closedEventProperty.SetValue(form, "MainFormClosed");

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add combo box.
                ComboBox comboBox = (ComboBox)host.CreateComponent(typeof(ComboBox), "comboBox1");
                comboBox.TabIndex = 0;
                comboBox.Location = new Point(0, 0);
                comboBox.Size     = new System.Drawing.Size(121, 21);
                comboBox.Items.Add("aaa");
                comboBox.Items.Add("bbb");
                comboBox.Items.Add("ccc");

                form.Controls.Add(comboBox);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, 1);
                }
            }
        }
Exemple #24
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add menu strip.
                MenuStrip menuStrip = (MenuStrip)host.CreateComponent(typeof(MenuStrip), "menuStrip1");
                menuStrip.Text     = "menuStrip1";
                menuStrip.TabIndex = 0;
                menuStrip.Location = new Point(0, 0);
                form.Controls.Add(menuStrip);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
Exemple #25
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                Form          form = (Form)host.RootComponent;
                form.ClientSize = new Size(284, 264);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                Button button = (Button)host.CreateComponent(typeof(Button), "button1");
                button.Location = new Point(0, 0);
                button.Size     = new Size(10, 10);
                button.Text     = "button1";
                button.TabIndex = 0;
                button.UseCompatibleTextRendering = false;
                form.Controls.Add(button);

                RadioButton radioButton = (RadioButton)host.CreateComponent(typeof(RadioButton), "radioButton1");
                radioButton.Location = new Point(20, 0);
                radioButton.Size     = new Size(10, 10);
                radioButton.Text     = "radioButton1";
                radioButton.TabIndex = 1;
                radioButton.UseCompatibleTextRendering = false;
                form.Controls.Add(radioButton);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, 1);
                }
            }
        }
        public void DesignerSerializationManager_RecycleInstances_SetWithSession_ThrowsInvalidOperationException(bool value)
        {
            var manager = new DesignerSerializationManager();

            manager.CreateSession();
            Assert.Throws <InvalidOperationException>(() => manager.RecycleInstances = value);
            Assert.False(manager.RecycleInstances);
        }
        public void DesignerSerializationManager_ValidateRecycledTypes_SetWithSession_ThrowsInvalidOperationException(bool value)
        {
            var manager = new DesignerSerializationManager();

            manager.CreateSession();
            Assert.Throws <InvalidOperationException>(() => manager.ValidateRecycledTypes = value);
            Assert.True(manager.ValidateRecycledTypes);
        }
Exemple #28
0
        public static WorkflowTheme Load(string themeFilePath)
        {
            DesignerSerializationManager serializationManager = new DesignerSerializationManager();

            using (serializationManager.CreateSession())
            {
                return(Load(serializationManager, themeFilePath));
            }
        }
        public void DesignerSerializationManager_Errors_NoSessionWithPreviousSession_ThrowsInvalidOperationException()
        {
            var         manager = new DesignerSerializationManager();
            IDisposable session = manager.CreateSession();

            Assert.Empty(manager.Errors);
            session.Dispose();
            Assert.Throws <InvalidOperationException>(() => manager.Errors);
        }
Exemple #30
0
        public void SetUpFixture()
        {
            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add list view.
                ListView listView = (ListView)host.CreateComponent(typeof(ListView), "listView1");
                listView.TabIndex   = 0;
                listView.Location   = new Point(0, 0);
                listView.ClientSize = new Size(200, 100);
                descriptors         = TypeDescriptor.GetProperties(listView);
                PropertyDescriptor descriptor = descriptors.Find("UseCompatibleStateImageBehavior", false);
                descriptor.SetValue(listView, true);
                descriptor = descriptors.Find("View", false);
                descriptor.SetValue(listView, View.Details);
                form.Controls.Add(listView);

                // Add column headers.
                columnHeader1 = (ColumnHeader)host.CreateComponent(typeof(ColumnHeader), "columnHeader1");
                descriptors   = TypeDescriptor.GetProperties(columnHeader1);
                descriptor    = descriptors.Find("Text", false);
                descriptor.SetValue(columnHeader1, "columnHeader1");
                listView.Columns.Add(columnHeader1);

                columnHeader2 = (ColumnHeader)host.CreateComponent(typeof(ColumnHeader), "columnHeader2");
                descriptors   = TypeDescriptor.GetProperties(columnHeader2);
                descriptor    = descriptors.Find("Text", false);
                descriptor.SetValue(columnHeader2, "columnHeader2");
                listView.Columns.Add(columnHeader2);

                // Add list view items.
                DesignerSerializationManager  designerSerializationManager = new DesignerSerializationManager(host);
                IDesignerSerializationManager serializationManager         = (IDesignerSerializationManager)designerSerializationManager;
                using (designerSerializationManager.CreateSession()) {
                    ListViewItem item = (ListViewItem)serializationManager.CreateInstance(typeof(ListViewItem), new object[] { "aaa" }, "listViewItem1", false);
                    item.ToolTipText = "tooltip";
                    listView.Items.Add(item);

                    item = (ListViewItem)serializationManager.CreateInstance(typeof(ListViewItem), new object[] { "bbb" }, "listViewItem2", false);
                    listView.Items.Add(item);

                    item = (ListViewItem)serializationManager.CreateInstance(typeof(ListViewItem), new object[0], "listViewItem3", false);
                    listView.Items.Add(item);

                    RubyCodeDomSerializer serializer = new RubyCodeDomSerializer("    ");
                    generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, 1);
                }
            }
        }