protected virtual void Initialize () { _serializationMananger = new DesignerSerializationManager (_host); DesignSurfaceServiceContainer serviceContainer = _host.GetService (typeof (IServiceContainer)) as DesignSurfaceServiceContainer; if (serviceContainer != null) { serviceContainer.AddService (typeof (IDesignerLoaderService), (IDesignerLoaderService) this); serviceContainer.AddNonReplaceableService (typeof (IDesignerSerializationManager), _serializationMananger); } }
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); DesignerSerializationManager designerSerializationManager = new DesignerSerializationManager(host); IDesignerSerializationManager serializationManager = (IDesignerSerializationManager)designerSerializationManager; using (designerSerializationManager.CreateSession()) { // Add list view item with 3 sub items. ListViewItem item = (ListViewItem)serializationManager.CreateInstance(typeof(ListViewItem), new object[] { "listItem1" }, "listViewItem1", false); item.SubItems.Add("subItem1"); item.SubItems.Add("subItem2"); item.SubItems.Add("subItem3"); listView.Items.Add(item); RubyCodeDomSerializer serializer = new RubyCodeDomSerializer(" "); generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, designerSerializationManager, String.Empty, 1); } } }
public void PrimitiveCodeDomSerializerTests_Serialize(object input) { var manager = new DesignerSerializationManager(); PrimitiveCodeDomSerializer underTest = PrimitiveCodeDomSerializer.Default; Assert.NotNull(underTest); var result = underTest.Serialize(manager, input) as CodePrimitiveExpression; Assert.NotNull(result); Assert.Equal(input, result.Value); Assert.Empty(result.UserData); }
public void SetUpFixture() { RubyCodeDomSerializer serializer = new RubyCodeDomSerializer(" "); using (Form form = new Form()) { form.Site = new MockSite(); CodeMemberMethod method = CreateMethod(); DesignerSerializationManager serializationManager = new DesignerSerializationManager(); using (serializationManager.CreateSession()) { generatedRubyCode = serializer.GenerateMethodBody(form, method, serializationManager, String.Empty, 0); } } }
public void DesignerSerializationManager_PropertyProvider_SetWithSession_GetReturnsExpected(string value) { var manager = new DesignerSerializationManager(); manager.CreateSession(); manager.PropertyProvider = value; Assert.Same(value, manager.PropertyProvider); // Set same manager.PropertyProvider = value; Assert.Same(value, manager.PropertyProvider); }
public void DesignerSerializationManager_PropertyProvider_Set_GetReturnsExpected(string value) { var manager = new DesignerSerializationManager { PropertyProvider = value }; Assert.Same(value, manager.PropertyProvider); // Set same manager.PropertyProvider = value; Assert.Same(value, manager.PropertyProvider); }
private void LoadChangesFromReader(SqlDataReader reader, object parameter) { if (!reader.Read()) { return; } // // Reset the min to the most recent change event DateTime tmpDT = _changesMinDT; if (!reader.IsDBNull(0)) { tmpDT = reader.GetDateTime(0); } if (reader.NextResult()) { WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); DesignerSerializationManager serializationManager = new DesignerSerializationManager(); while (reader.Read()) { IList errors = null; using (StringReader sr = new StringReader(reader.GetString(0))) { using (serializationManager.CreateSession()) { using (XmlReader xmlReader = XmlReader.Create(sr)) { ActivityChangeAction aAction = serializer.Deserialize(serializationManager, xmlReader) as ActivityChangeAction; errors = serializationManager.Errors; if (null != aAction) { aAction.ApplyTo(_def); } else { throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError); } } } } } } if (tmpDT > _changesMinDT) { _changed = true; _changesMinDT = tmpDT; } }
protected internal override Activity CreateInstance(XmlReader workflowDefinitionReader, XmlReader rulesReader) { if (workflowDefinitionReader == null) { throw new ArgumentNullException("workflowDefinitionReader"); } Activity activity = null; ValidationErrorCollection errors = new ValidationErrorCollection(); ServiceContainer container = new ServiceContainer(); ITypeProvider service = base.Runtime.GetService <ITypeProvider>(); if (service != null) { container.AddService(typeof(ITypeProvider), service); } DesignerSerializationManager manager = new DesignerSerializationManager(container); try { using (manager.CreateSession()) { WorkflowMarkupSerializationManager serializationManager = new WorkflowMarkupSerializationManager(manager); activity = new WorkflowMarkupSerializer().Deserialize(serializationManager, workflowDefinitionReader) as Activity; if ((activity != null) && (rulesReader != null)) { object obj2 = new WorkflowMarkupSerializer().Deserialize(serializationManager, rulesReader); activity.SetValue(ConditionTypeConverter.DeclarativeConditionDynamicProp, obj2); } foreach (object obj3 in manager.Errors) { if (obj3 is WorkflowMarkupSerializationException) { errors.Add(new ValidationError(((WorkflowMarkupSerializationException)obj3).Message, 0x15b)); } else { errors.Add(new ValidationError(obj3.ToString(), 0x15b)); } } } } catch (Exception exception) { errors.Add(new ValidationError(exception.Message, 0x15b)); } if (errors.HasErrors) { throw new WorkflowValidationFailedException(ExecutionStringManager.WorkflowValidationFailure, errors); } return(activity); }
public void SetUpFixture() { resourceWriter = new MockResourceWriter(); componentCreator = new MockComponentCreator(); componentCreator.SetResourceWriter(resourceWriter); resourceWriter2 = new MockResourceWriter(); componentCreator2 = new MockComponentCreator(); componentCreator2.SetResourceWriter(resourceWriter2); 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 picture box PictureBox pictureBox = (PictureBox)host.CreateComponent(typeof(PictureBox), "pictureBox1"); pictureBox.Location = new Point(0, 0); bitmap = new Bitmap(10, 10); pictureBox.Image = bitmap; pictureBox.Size = new Size(100, 120); pictureBox.TabIndex = 0; form.Controls.Add(pictureBox); // Add bitmap to form. form.BackgroundImage = new Bitmap(10, 10); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" "); generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1); } // Check that calling the GenerateInitializeComponentMethodBody also generates a resource file. host.RemoveService(typeof(IResourceService)); host.AddService(typeof(IResourceService), componentCreator2); serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" "); serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1); } } }
protected void LoadDesignerLayout(XmlReader layoutReader, out IList layoutLoadErrors) { if (layoutReader == null) { throw new ArgumentNullException("layoutReader"); } ArrayList list = new ArrayList(); layoutLoadErrors = list; ActivityDesigner designer = null; IDesignerHost service = base.GetService(typeof(IDesignerHost)) as IDesignerHost; if ((service != null) && (service.RootComponent != null)) { designer = service.GetDesigner(service.RootComponent) as ActivityDesigner; } if (designer != null) { if (designer.SupportsLayoutPersistence) { DesignerSerializationManager manager = new DesignerSerializationManager(base.LoaderHost); using (manager.CreateSession()) { WorkflowMarkupSerializationManager serializationManager = new WorkflowMarkupSerializationManager(manager); serializationManager.AddSerializationProvider(new ActivityDesignerLayoutSerializerProvider()); try { new WorkflowMarkupSerializer().Deserialize(serializationManager, layoutReader); } catch (Exception exception) { list.Add(new WorkflowMarkupSerializationException(SR.GetString("Error_LayoutDeserialization"), exception)); } finally { if (manager.Errors != null) { list.AddRange(manager.Errors); } } return; } } list.Add(new WorkflowMarkupSerializationException(SR.GetString("Error_LayoutSerializationPersistenceSupport"))); } else { list.Add(new WorkflowMarkupSerializationException(SR.GetString("Error_LayoutSerializationRootDesignerNotFound"))); } }
/// <summary> /// Deserialize a workflow from markup (xaml) /// </summary> /// <param name="fileName"></param> /// <returns></returns> private static Activity DeserializeFromMarkup(String fileName) { Activity workflow = null; try { //add a TypeProvider to resolve SharedWorkflow references ServiceContainer container = new ServiceContainer(); TypeProvider provider = new TypeProvider(container); //provider.AddAssemblyReference("SharedWorkflows.dll"); provider.AddAssembly( typeof(SharedWorkflows.MarkupOnlyBaseWorkflow).Assembly); container.AddService(typeof(ITypeProvider), provider); //add the ServiceContainer with the TypeProvider to //a serialization manager DesignerSerializationManager dsm = new DesignerSerializationManager(container); using (dsm.CreateSession()) { using (XmlReader xmlReader = XmlReader.Create(fileName)) { //deserialize the workflow from the XmlReader WorkflowMarkupSerializer markupSerializer = new WorkflowMarkupSerializer(); workflow = markupSerializer.Deserialize(dsm, xmlReader) as Activity; if (dsm.Errors.Count > 0) { foreach (WorkflowMarkupSerializationException error in dsm.Errors) { Console.WriteLine( "Deserialization error: {0}", error); } } } } } catch (Exception e) { Console.WriteLine("Exception during deserialization: {0}", e.Message); } return(workflow); }
public void Init() { host = new MockDesignerLoaderHost(); loader = new RubyDesignerLoader(new MockDesignerGenerator()); loader.BeginLoad(host); DesignerSerializationManager designerSerializationManager = (DesignerSerializationManager)host.GetService(typeof(IDesignerSerializationManager)); using (designerSerializationManager.CreateSession()) { listViewItem1 = (ListViewItem)loader.CreateInstance(typeof(ListViewItem), new object[0], "listViewItem1", false); instance = loader.GetInstance("listViewItem1"); typeName = typeof(Int32).FullName; type = loader.GetType(typeName); } }
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(); }
private static ArrayList CloneWorkflowChangeActions(ArrayList workflowChanges, Activity rootActivity) { if (workflowChanges == null) { throw new ArgumentNullException("workflowChanges"); } if (rootActivity == null) { throw new ArgumentNullException("rootActivity"); } string dynamicUpdateHistory = null; TypeProvider typeProvider = CreateTypeProvider(rootActivity); ServiceContainer serviceContainer = new ServiceContainer(); serviceContainer.AddService(typeof(ITypeProvider), typeProvider); DesignerSerializationManager manager = new DesignerSerializationManager(serviceContainer); WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer(); ArrayList clonedWorkflowChanges = null; // serialize dynamic updates using (manager.CreateSession()) { using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture)) { using (XmlWriter xmlWriter = Helpers.CreateXmlWriter(sw)) { WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager); xomlSerializer.Serialize(xomlSerializationManager, xmlWriter, workflowChanges); dynamicUpdateHistory = sw.ToString(); } } // deserialize those using (StringReader sr = new StringReader(dynamicUpdateHistory)) { using (XmlReader xmlReader = XmlReader.Create(sr)) { WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager); clonedWorkflowChanges = xomlSerializer.Deserialize(xomlSerializationManager, xmlReader) as ArrayList; } } } return(clonedWorkflowChanges); }
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 tree view. TreeView treeView = (TreeView)host.CreateComponent(typeof(TreeView), "treeView1"); treeView.LineColor = Color.Black; treeView.Location = new Point(0, 0); treeView.Size = new Size(100, 100); DesignerSerializationManager designerSerializationManager = new DesignerSerializationManager(host); IDesignerSerializationManager serializationManager = (IDesignerSerializationManager)designerSerializationManager; using (designerSerializationManager.CreateSession()) { // Add first root node. TreeNode firstRootNode = (TreeNode)serializationManager.CreateInstance(typeof(TreeNode), new object[0], "treeNode3", false); firstRootNode.Name = "RootNode0"; firstRootNode.Text = "RootNode0.Text"; treeView.Nodes.Add(firstRootNode); // Add first child node. TreeNode firstChildNode = (TreeNode)serializationManager.CreateInstance(typeof(TreeNode), new object[0], "treeNode2", false); firstChildNode.Name = "ChildNode0"; firstChildNode.Text = "ChildNode0.Text"; firstRootNode.Nodes.Add(firstChildNode); // Add second child node. TreeNode secondChildNode = (TreeNode)serializationManager.CreateInstance(typeof(TreeNode), new object[0], "treeNode1", false); secondChildNode.Name = "ChildNode1"; secondChildNode.Text = "ChildNode1.Text"; firstChildNode.Nodes.Add(secondChildNode); form.Controls.Add(treeView); RubyCodeDomSerializer serializer = new RubyCodeDomSerializer(" "); generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, designerSerializationManager, String.Empty, 1); } } }
public void DesignerSerializationManager_ValidateRecycledTypes_Set_GetReturnsExpected(bool value) { var manager = new DesignerSerializationManager { ValidateRecycledTypes = value }; Assert.Equal(value, manager.ValidateRecycledTypes); // Set same manager.ValidateRecycledTypes = value; Assert.Equal(value, manager.ValidateRecycledTypes); // Set different manager.ValidateRecycledTypes = !value; Assert.Equal(!value, manager.ValidateRecycledTypes); }
public void PrimitiveCodeDomSerializerTests_Serialize_Cast() { var manager = new DesignerSerializationManager(); PrimitiveCodeDomSerializer underTest = PrimitiveCodeDomSerializer.Default; Assert.NotNull(underTest); var cast = underTest.Serialize(manager, (byte)42) as CodeCastExpression; Assert.NotNull(cast); Assert.Equal(typeof(byte).ToString(), cast.TargetType.BaseType); Assert.IsType <CodePrimitiveExpression>(cast.Expression); var primitive = cast.Expression as CodePrimitiveExpression; Assert.Equal((byte)42, primitive.Value); Assert.Empty(cast.UserData); }
public void DesignerSerializationManager_PreserveNames_Set_GetReturnsExpected(bool value) { var manager = new DesignerSerializationManager { PreserveNames = value }; Assert.Equal(value, manager.PreserveNames); // Set same manager.PreserveNames = value; Assert.Equal(value, manager.PreserveNames); // Set different manager.PreserveNames = !value; Assert.Equal(!value, manager.PreserveNames); }
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); DesignerSerializationManager designerSerializationManager = new DesignerSerializationManager(host); IDesignerSerializationManager serializationManager = (IDesignerSerializationManager)designerSerializationManager; using (designerSerializationManager.CreateSession()) { // Add groups. ListViewGroup group1 = (ListViewGroup)serializationManager.CreateInstance(typeof(ListViewGroup), new object[0], "listViewGroup1", false); group1.Header = "ListViewGroup"; group1.HeaderAlignment = HorizontalAlignment.Right; group1.Name = "defaultGroup"; group1.Tag = "tag1"; listView.Groups.Add(group1); ListViewGroup group2 = (ListViewGroup)serializationManager.CreateInstance(typeof(ListViewGroup), new object[0], "listViewGroup2", false); group2.Header = "ListViewGroup"; group2.HeaderAlignment = HorizontalAlignment.Center; group2.Name = "listViewGroup2"; listView.Groups.Add(group2); PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" "); generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, designerSerializationManager, String.Empty, 1); } } }
protected void SaveDesignerLayout(XmlWriter layoutWriter, ActivityDesigner rootDesigner, out IList layoutSaveErrors) { if (layoutWriter == null) { throw new ArgumentNullException("layoutWriter"); } if (rootDesigner == null) { throw new ArgumentNullException("rootDesigner"); } ArrayList errors = new ArrayList(); layoutSaveErrors = errors; if (rootDesigner.SupportsLayoutPersistence) { DesignerSerializationManager serializationManager = new DesignerSerializationManager(LoaderHost); using (serializationManager.CreateSession()) { WorkflowMarkupSerializationManager layoutSerializationManager = new WorkflowMarkupSerializationManager(serializationManager); layoutSerializationManager.AddSerializationProvider(new ActivityDesignerLayoutSerializerProvider()); try { new WorkflowMarkupSerializer().Serialize(layoutSerializationManager, layoutWriter, rootDesigner); } catch (Exception e) { errors.Add(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_LayoutSerialization), e)); } finally { if (serializationManager.Errors != null) { errors.AddRange(serializationManager.Errors); } } } } else { errors.Add(new WorkflowMarkupSerializationException(SR.GetString(SR.Error_LayoutSerializationPersistenceSupport))); } }
public string WorkflowClassToXomlString(Activity workflow) { WorkflowMarkupSerializer wfSerializer = new WorkflowMarkupSerializer(); DesignerSerializationManager sm = new DesignerSerializationManager(); sm.CreateSession(); System.Text.StringBuilder s = new StringBuilder(); XmlWriter xmlwriter = XmlWriter.Create(s); wfSerializer.Serialize(sm, xmlwriter, workflow); if (sm.Errors.Count > 0) { throw new Exception("出现错误:" + sm.Errors.Count.ToString()); } return(s.ToString()); }
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"); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { PythonCodeDomSerializer serializer = new PythonCodeDomSerializer(" "); generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1); } } }
public void SetUpFixture() { AvalonEdit.TextEditor textEditor = new AvalonEdit.TextEditor(); document = textEditor.Document; textEditor.Text = GetTextEditorCode(); RubyParser parser = new RubyParser(); MockProjectContent projectContent = new MockProjectContent(); MockProject project = new MockProject(); project.RootNamespace = "RootNamespace"; projectContent.Project = project; ICompilationUnit compilationUnit = parser.Parse(projectContent, @"test.py", document.Text); 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 picture box PictureBox pictureBox = (PictureBox)host.CreateComponent(typeof(PictureBox), "pictureBox1"); pictureBox.Location = new Point(0, 0); pictureBox.Image = new Bitmap(10, 10); pictureBox.Size = new Size(100, 120); pictureBox.TabIndex = 0; form.Controls.Add(pictureBox); MockTextEditorOptions options = new MockTextEditorOptions(); options.ConvertTabsToSpaces = true; options.IndentationSize = 4; DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { AvalonEditDocumentAdapter docAdapter = new AvalonEditDocumentAdapter(document, null); RubyDesignerGenerator generator = new RubyDesignerGenerator(options); generator.Merge(host, docAdapter, compilationUnit, serializationManager); } } }
public object CreateInstance(Type type, ICollection arguments, string name, bool addToContainer) { CreatedInstance createdInstance = new CreatedInstance(type, arguments, name, addToContainer); createdInstances.Add(createdInstance); object[] argumentsArray = new object[arguments.Count]; arguments.CopyTo(argumentsArray, 0); object o = null; DesignerSerializationManager designerSerializationManager = new DesignerSerializationManager(); using (designerSerializationManager.CreateSession()) { IDesignerSerializationManager manager = designerSerializationManager as IDesignerSerializationManager; o = manager.CreateInstance(type, arguments, name, addToContainer); } createdInstance.Object = o; return(o); }
public void SetUpFixture() { using (FormsDesignerViewContent viewContent = new FormsDesignerViewContent(null, new MockOpenedFile("Test.py"))) { viewContent.DesignerCodeFileContent = "class MainForm < Form\r\n" + " def initialize()\r\n" + " self.InitializeComponent()\r\n" + " end\r\n" + "\r\n" + " def InitializeComponent()\r\n" + " end\r\n" + "end"; document = viewContent.DesignerCodeFileDocument; ParseInformation parseInfo = new ParseInformation(); RubyParser parser = new RubyParser(); ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.rb", document.TextContent); parseInfo.SetCompilationUnit(compilationUnit); 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"); MockTextEditorProperties textEditorProperties = new MockTextEditorProperties(); textEditorProperties.ConvertTabsToSpaces = true; textEditorProperties.IndentationSize = 1; DerivedRubyDesignerGenerator generator = new DerivedRubyDesignerGenerator(textEditorProperties); generator.ParseInfoToReturnFromParseFileMethod = parseInfo; generator.Attach(viewContent); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { generator.MergeRootComponentChanges(host, serializationManager); } } } }
private void LoadChangesFromReader(SqlDataReader reader, object parameter) { if (reader.Read()) { DateTime dateTime = this._changesMinDT; if (!reader.IsDBNull(0)) { dateTime = reader.GetDateTime(0); } if (reader.NextResult()) { WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); DesignerSerializationManager serializationManager = new DesignerSerializationManager(); while (reader.Read()) { using (StringReader reader2 = new StringReader(reader.GetString(0))) { using (serializationManager.CreateSession()) { using (XmlReader reader3 = XmlReader.Create(reader2)) { ActivityChangeAction action = serializer.Deserialize(serializationManager, reader3) as ActivityChangeAction; IList errors = serializationManager.Errors; if (action == null) { throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError); } action.ApplyTo(this._def); continue; } } } } } if (dateTime > this._changesMinDT) { this._changed = true; this._changesMinDT = dateTime; } } }
public WorkflowTheme Clone() { WorkflowTheme theme = null; DesignerSerializationManager serializationManager = new DesignerSerializationManager(); using (serializationManager.CreateSession()) { ThemeSerializationProvider provider = new ThemeSerializationProvider(); StringWriter output = new StringWriter(new StringBuilder(), CultureInfo.InvariantCulture); StringReader input = null; try { ((IDesignerSerializationManager)serializationManager).AddSerializationProvider(provider); WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); using (XmlWriter writer2 = Helpers.CreateXmlWriter(output)) { serializer.Serialize(serializationManager, writer2, this); } input = new StringReader(output.ToString()); using (XmlReader reader2 = XmlReader.Create(input)) { theme = serializer.Deserialize(serializationManager, reader2) as WorkflowTheme; } } finally { ((IDesignerSerializationManager)serializationManager).RemoveSerializationProvider(provider); input.Close(); output.Close(); } } if (theme != null) { theme.filePath = this.filePath; foreach (DesignerTheme theme2 in theme.DesignerThemes) { theme2.Initialize(); } } return(theme); }
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(284, 264); PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); namePropertyDescriptor.SetValue(form, "MainForm"); Panel panel = (Panel)host.CreateComponent(typeof(Panel), "panel1"); panel.Location = new Point(10, 15); panel.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; panel.TabIndex = 0; panel.Size = new Size(100, 120); TextBox textBox = (TextBox)host.CreateComponent(typeof(TextBox), "textBox1"); textBox.Location = new Point(5, 5); textBox.TabIndex = 0; textBox.Size = new Size(110, 20); panel.Controls.Add(textBox); // Add an event handler to the panel to check that this code is generated // before the text box is initialized. EventDescriptorCollection events = TypeDescriptor.GetEvents(panel); EventDescriptor clickEvent = events.Find("Click", false); PropertyDescriptor clickEventProperty = eventBindingService.GetEventProperty(clickEvent); clickEventProperty.SetValue(panel, "Panel1Click"); form.Controls.Add(panel); 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(PublicToolTipDerivedForm))) { IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); IEventBindingService eventBindingService = new MockEventBindingService(host); PublicToolTipDerivedForm form = (PublicToolTipDerivedForm)host.RootComponent; form.ClientSize = new Size(284, 264); PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); PropertyDescriptor descriptor = descriptors.Find("Name", false); descriptor.SetValue(form, "MainForm"); form.toolTip.SetToolTip(form, "test"); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { RubyCodeDomSerializer serializer = new RubyCodeDomSerializer(" "); generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1); } } }
private void LoadDefFromReader(SqlDataReader reader, object parameter) { if (null == reader) { throw new ArgumentNullException("reader"); } if (!reader.Read()) { throw new ArgumentException(ExecutionStringManager.InvalidDefinitionReader); } StringReader sr = new StringReader(reader.GetString(0)); //Deserialize the xoml and set the root activity WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); DesignerSerializationManager serializationManager = new DesignerSerializationManager(); IList errors = null; try { using (serializationManager.CreateSession()) { using (XmlReader xmlReader = XmlReader.Create(sr)) { _def = serializer.Deserialize(serializationManager, xmlReader) as Activity; errors = serializationManager.Errors; } } } finally { sr.Close(); } if ((null == _def) || ((null != errors) && (errors.Count > 0))) { throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError); } }
public void SetUpFixture() { using (DesignSurface designSurface = new DesignSurface(typeof(ProtectedPanelDerivedForm))) { 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"); // Move protected panel so we generate code for the new location. ProtectedPanelDerivedForm derivedForm = (ProtectedPanelDerivedForm)form; derivedForm.PanelLocation = new Point(10, 15); DesignerSerializationManager serializationManager = new DesignerSerializationManager(host); using (serializationManager.CreateSession()) { RubyCodeDomSerializer serializer = new RubyCodeDomSerializer(" "); generatedRubyCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1); } } }
public Session (DesignerSerializationManager manager) { _manager = manager; }