当前位置: 首页>>代码示例>>C#>>正文


C# Template.CreateShape方法代码示例

本文整理汇总了C#中Template.CreateShape方法的典型用法代码示例。如果您正苦于以下问题:C# Template.CreateShape方法的具体用法?C# Template.CreateShape怎么用?C# Template.CreateShape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Template的用法示例。


在下文中一共展示了Template.CreateShape方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ModelMappingTest

		public void ModelMappingTest() {
			Project project = new Project();
			project.Repository = new CachedRepository();
			((CachedRepository)project.Repository).Store = RepositoryHelper.CreateXmlStore();
			project.Name = "ModelMappingTest";
			project.Repository.Erase();
			project.Create();
			project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);

			// Create test data
			object[] floatTestData = CreateFloatTestData();
			object[] intTestData = CreateIntTestData();
			object[] stringTestData = CreateStringTestData();

			// Create model object and retrieve all properties
			GenericModelObject templateModelObject = (GenericModelObject)project.ModelObjectTypes["GenericModelObject"].CreateInstance();
			// Define property lists
			List<PropertyInfo> modelProperties = new List<PropertyInfo>();
			List<PropertyInfo> shapeProperties = new List<PropertyInfo>();
			GetPropertyInfos(templateModelObject.GetType(), modelProperties);
			
			// Test a shape of each shapeType
			foreach (ShapeType shapeType in project.ShapeTypes) {
				using (Shape templateShape = shapeType.CreateInstance()) {
					if (templateShape is IShapeGroup) continue;
					templateShape.ModelObject = templateModelObject;

					// Get mappable shape and model properties
					GetPropertyInfos(templateShape.GetType(), shapeProperties);

					Template template = new Template(shapeType.Name, templateShape);
					foreach (PropertyInfo modelProperty in modelProperties) {
						foreach (PropertyInfo shapeProperty in shapeProperties) {
							IModelMapping modelMapping = CreateModelMapping(shapeProperty, modelProperty);
							if (modelMapping == null) continue;
							//
							// Assign suitable test data
							object[] testValues = null;
							if (modelMapping.CanSetFloat) testValues = floatTestData;
							else if (modelMapping.CanSetInteger) testValues = intTestData;
							else if (modelMapping.CanSetString) testValues = stringTestData;
							//
							// Fill Model mappings and set expected results
							object[] testResults = null;
							if (modelMapping is NumericModelMapping)
								testResults = GetNumericMappingResults((NumericModelMapping)modelMapping, testValues);
							else if (modelMapping is FormatModelMapping)
								testResults = GetFormatMappingResults((FormatModelMapping)modelMapping, testValues);
							else if (modelMapping is StyleModelMapping)
								testResults = GetStyleMappingResults((StyleModelMapping)modelMapping, shapeProperty.PropertyType, testValues, project);
							//
							// Map properties
							template.UnmapAllProperties();
							template.MapProperties(modelMapping);

							// Test property mapping
							using (Shape testShape = template.CreateShape()) {
								IModelObject testModel = testShape.ModelObject;

								// Assign all test values to the model object and check the mapped shape property value.
								object templateShapePropValue = shapeProperty.GetValue(testShape, null);
								int cnt = testValues.Length;
								for (int i = 0; i < cnt; ++i) {
									try {
										// Assign the current test value to the model object's property value.
										// The shape's property has to be changed by the ModelMapping.
										object shapeValue = shapeProperty.GetValue(testShape, null);
										modelProperty.SetValue(testModel, testValues[i], null);
										object resultValue = shapeProperty.GetValue(testShape, null);
										object expectedValue = testResults[i] ?? templateShapePropValue;
										// 
										if (testShape is IPlanarShape && modelMapping.ShapePropertyId == 2) {
											// Angle property: All values are vonverted to positive angles < 360° (0 <= value <= 3600)
											if (expectedValue is int)
												expectedValue = ((3600 + (int)expectedValue) % 3600);
											else if (expectedValue is float)
												expectedValue = ((3600 + (float)expectedValue) % 3600);
										}
										//
										// Check mapping result
										bool areEqual = false;
										if (IsIntegerType(resultValue.GetType()) && IsIntegerType(expectedValue.GetType()))
											areEqual = object.Equals(Convert.ToInt64(resultValue), Convert.ToInt64(expectedValue));
										else if (IsFloatType(resultValue.GetType()) && IsFloatType(expectedValue.GetType()))
											areEqual = object.Equals(Convert.ToDouble(resultValue), Convert.ToDouble(expectedValue));
										else
											areEqual = object.Equals(resultValue, expectedValue);
										// Error reporting
										if (!areEqual) {
											if (object.Equals(shapeValue, resultValue))
												Assert.Fail(
													"Assigning '{0}' to {1} had no effect on {2}'s property '{3}': Property value '{4}' did not change.",
													testValues[i],
													testModel.Type.Name,
													testShape.Type.Name,
													shapeProperty.Name,
													shapeValue);
											else
												Assert.Fail(
													"Assigning '{0}' to {1} had not the expected effect on {2}'s property '{3}': Property value '{4}' changed to '{5}' instead of '{6}'.",
//.........这里部分代码省略.........
开发者ID:jestonitiro,项目名称:nshape,代码行数:101,代码来源:DiagramBaseTest.cs

示例2: TemplateTest

		public void TemplateTest() {
			Project project = new Project();
			project.Name = "Test";
			project.Repository = new CachedRepository();
			((CachedRepository)project.Repository).Store = RepositoryHelper.CreateXmlStore();
			project.Repository.Erase();
			project.Create();
			project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);
			Template template = new Template("Template1", project.ShapeTypes["RoundedBox"].CreateInstance());
			((IPlanarShape)template.Shape).FillStyle = project.Design.FillStyles.Red;
			project.Repository.InsertTemplate(template);
			Diagram diagram = new Diagram("Diagram A");
			diagram.Shapes.Add(template.CreateShape(), 1);
			project.Repository.InsertDiagram(diagram);
			Assert.ReferenceEquals(((IPlanarShape)diagram.Shapes.Bottom).FillStyle, ((IPlanarShape)template.Shape).FillStyle);
			IFillStyle fillStyle = project.Design.FillStyles.Green;
			((IPlanarShape)template.Shape).FillStyle = fillStyle;
			Assert.ReferenceEquals(((IPlanarShape)diagram.Shapes.Bottom).FillStyle, ((IPlanarShape)template.Shape).FillStyle);
			project.Repository.SaveChanges();
			project.Close();
			//
			project.Open();
			template = project.Repository.GetTemplate("Template1");
			diagram = project.Repository.GetDiagram("Diagram A");
			Assert.AreEqual(((IPlanarShape)diagram.Shapes.Bottom).FillStyle.BaseColorStyle, ((IPlanarShape)template.Shape).FillStyle.BaseColorStyle);
			project.Close();
		}
开发者ID:jestonitiro,项目名称:nshape,代码行数:27,代码来源:DiagramBaseTest.cs


注:本文中的Template.CreateShape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。