本文整理汇总了C#中Project.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Project.Close方法的具体用法?C# Project.Close怎么用?C# Project.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Project
的用法示例。
在下文中一共展示了Project.Close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportToImageTest
public void ExportToImageTest() {
// -- Create a project --
Project project = new Project();
project.Name = "ExportToImageTest";
project.Repository = new CachedRepository();
((CachedRepository)project.Repository).Store = new XmlStore(@"C:\Temp", ".xml");
project.Repository.Erase();
project.Create();
// Add Libraries:
// GeneralShapes
project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);
// ElectricalShapes
project.AddLibrary(typeof(Dataweb.NShape.ElectricalShapes.AutoDisconnectorSymbol).Assembly);
// FlowChartShapes
project.AddLibrary(typeof(Dataweb.NShape.FlowChartShapes.ProcessSymbol).Assembly);
// SoftwareArchitectureShapes
project.AddLibrary(typeof(Dataweb.NShape.SoftwareArchitectureShapes.CloudSymbol).Assembly);
//
DiagramHelper.CreateDiagram(project, "Export Test Diagram", 10, 10, true, false, false, false);
string filePathFmt = System.IO.Path.Combine(Environment.GetEnvironmentVariable("Temp"), "ExportTest {0}.{1}");
const int dpi = 150;
foreach (Diagram diagram in project.Repository.GetDiagrams()) {
IEnumerable<Shape> shapes = diagram.Shapes.FindShapes(diagram.Width / 4, diagram.Height / 4, diagram.Width / 2, diagram.Height / 2, false);
foreach (ImageFileFormat fileFormat in Enum.GetValues(typeof(ImageFileFormat))) {
try {
string fileExt = (fileFormat == ImageFileFormat.EmfPlus) ? "Plus.emf" : fileFormat.ToString();
using (Image img = diagram.CreateImage(fileFormat))
GdiHelpers.SaveImageToFile(img, string.Format(filePathFmt, "Whole Diagram", fileExt), fileFormat);
using (Image img = diagram.CreateImage(fileFormat, shapes))
GdiHelpers.SaveImageToFile(img, string.Format(filePathFmt, "Shapes", fileExt), fileFormat);
using (Image img = diagram.CreateImage(fileFormat, shapes, true))
GdiHelpers.SaveImageToFile(img, string.Format(filePathFmt, "Shapes with Background", fileExt), fileFormat);
using (Image img = diagram.CreateImage(fileFormat, shapes, 5))
GdiHelpers.SaveImageToFile(img, string.Format(filePathFmt, "Shapes with Margin", fileExt), fileFormat);
using (Image img = diagram.CreateImage(fileFormat, shapes, 5, false, Color.AliceBlue))
GdiHelpers.SaveImageToFile(img, string.Format(filePathFmt, "Shapes with Background Color", fileExt), fileFormat);
using (Image img = diagram.CreateImage(fileFormat, shapes, 5, false, Color.AliceBlue, dpi))
GdiHelpers.SaveImageToFile(img, string.Format(filePathFmt, string.Format("Shapes with Background Color {0} Dpi", dpi), fileExt), fileFormat);
} catch (NotImplementedException) {
// Do nothing
}
}
}
project.Close();
}
示例2: BaseTest
public void BaseTest() {
// -- Create a project --
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);
//
Diagram diagram = new Diagram("All Shapes");
diagram.Width = 800;
diagram.Height = 600;
project.Repository.InsertDiagram(diagram);
int x = 0;
int shapeCount = 0;
foreach (ShapeType st in project.ShapeTypes) {
x += 50;
Shape s = st.CreateInstance();
s.X = x;
s.Y = 50;
if (s is IPlanarShape) {
((IPlanarShape)s).Angle = -300;
//((IPlanarShape)s).FillStyle
// ((ILinearShape)s).LineStyle
}
diagram.Shapes.Add(s, shapeCount + 1);
project.Repository.InsertShape(s, diagram);
++shapeCount;
}
//
Diagram diagram2 = new Diagram("Connections");
diagram2.Width = 800;
diagram2.Height = 600;
Circle circle = (Circle)project.ShapeTypes["Circle"].CreateInstance();
circle.X = 50;
circle.Y = 50;
circle.Diameter = 10;
diagram2.Shapes.Add(circle, diagram.Shapes.MaxZOrder + 10);
Box box = (Box)project.ShapeTypes["Box"].CreateInstance();
box.X = 100;
box.Y = 50;
box.Width = 20;
box.Height = 10;
box.Angle = 450;
diagram2.Shapes.Add(box, diagram2.Shapes.MaxZOrder + 10);
Polyline polyLine = (Polyline)project.ShapeTypes["Polyline"].CreateInstance();
polyLine.Connect(1, box, 3);
polyLine.Connect(2, circle, 7);
diagram2.Shapes.Add(polyLine, diagram2.Shapes.MaxZOrder + 10);
project.Repository.InsertDiagram(diagram2);
//
project.Repository.SaveChanges();
project.Close();
//
// -- Reload project and modify --
project.Open();
diagram = project.Repository.GetDiagram("All Shapes");
project.Repository.GetDiagramShapes(diagram);
foreach (Shape s in diagram.Shapes) {
s.MoveBy(300, 300);
if (s is ICaptionedShape)
((ICaptionedShape)s).SetCaptionText(0, s.Type.Name);
project.Repository.UpdateShape(s);
}
project.Repository.SaveChanges();
project.Close();
//
// -- Reload and check --
project.Open();
diagram = project.Repository.GetDiagram("All Shapes");
int c = 0;
foreach (Shape s in diagram.Shapes) {
Assert.AreEqual(350, s.Y);
if (s is IPlanarShape) Assert.AreEqual(3300, ((IPlanarShape)s).Angle, s.Type.Name);
if (s is ICaptionedShape)
Assert.AreEqual(((ICaptionedShape)s).GetCaptionText(0), s.Type.Name);
++c;
}
Assert.AreEqual(shapeCount, diagram.Shapes.Count);
Assert.AreEqual(shapeCount, c);
project.Close();
}
示例3: ModelMappingTest
//.........这里部分代码省略.........
// 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}'.",
testValues[i],
testModel.Type.Name,
testShape.Type.Name,
shapeProperty.Name,
shapeValue,
resultValue,
expectedValue);
}
} catch (TargetInvocationException exc) {
bool throwInnerException = true;
if (exc.InnerException is OverflowException && modelMapping is NumericModelMapping) {
double testValue = Convert.ToDouble(testValues[i]);
if (double.IsNaN(testValue))
throwInnerException = false;
else {
double resultValue = (double)(((NumericModelMapping)modelMapping).Intercept + (testValue * ((NumericModelMapping)modelMapping).Slope));
double minValue, maxValue;
GetMinAndMaxValue(shapeProperty.PropertyType, out minValue, out maxValue);
if (resultValue < minValue || resultValue > maxValue)
throwInnerException = false;
}
} else if (exc.InnerException is ArgumentOutOfRangeException)
throwInnerException = false;
// throw inner exception if the exception was not handled.
if (throwInnerException) throw exc.InnerException;
}
} // foreach test value
} // using block (Shape testShape)
} // foreach Shape property
} // foreach IModelObject property
} // using block (Shape templateShape)
} // foreach ShapeType (...)
project.Close();
}
示例4: BoundingRectangleTest
public void BoundingRectangleTest() {
// -- Create a project --
Project project = new Project();
project.Name = "BoundingRectangleTest";
project.Repository = new CachedRepository();
((CachedRepository)project.Repository).Store = new XmlStore(@"C:\Temp", ".xml");
project.Repository.Erase();
project.Create();
// Add Libraries:
// GeneralShapes
project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);
// ElectricalShapes
project.AddLibrary(typeof(Dataweb.NShape.ElectricalShapes.AutoDisconnectorSymbol).Assembly);
// FlowChartShapes
project.AddLibrary(typeof(Dataweb.NShape.FlowChartShapes.ProcessSymbol).Assembly);
// SoftwareArchitectureShapes
project.AddLibrary(typeof(Dataweb.NShape.SoftwareArchitectureShapes.CloudSymbol).Assembly);
//
Diagram diagram = new Diagram("All Shapes");
diagram.Width = 500;
diagram.Height = 500;
project.Repository.InsertDiagram(diagram);
int shapeCount = 0;
foreach (ShapeType st in project.ShapeTypes) {
Shape s = st.CreateInstance();
diagram.Shapes.Add(s, shapeCount + 1);
project.Repository.InsertShape(s, diagram);
++shapeCount;
}
BoundingRectangleTestCore(diagram.Shapes, 0, 100, 0);
BoundingRectangleTestCore(diagram.Shapes, 200, 100, 300);
BoundingRectangleTestCore(diagram.Shapes, 100, 2, 600);
project.Close();
}
示例5: StylesTest
public void StylesTest() {
Project project = new Project();
project.Repository = new CachedRepository();
((CachedRepository)project.Repository).Store = RepositoryHelper.CreateXmlStore();
project.Name = "Test";
project.Repository.Erase();
project.Create();
project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);
ColorStyle colorStyle = (ColorStyle)project.Design.ColorStyles.Blue;
colorStyle.Color = Color.LightBlue;
project.Repository.UpdateStyle(colorStyle);
project.Repository.SaveChanges();
project.Close();
project.Open();
colorStyle = (ColorStyle)project.Design.ColorStyles.Blue;
Assert.AreEqual(Color.LightBlue.ToArgb(), colorStyle.Color.ToArgb());
project.Close();
}
示例6: CommandTest
public void CommandTest() {
// Initialize the project
Project project = new Project();
project.Repository = new CachedRepository();
((CachedRepository)project.Repository).Store = RepositoryHelper.CreateXmlStore();
project.Name = "Test";
project.Repository.Erase();
project.Create();
project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);
// Create a diagram with one shape
Diagram diagram = new Diagram("Diagram A");
project.Repository.InsertDiagram(diagram);
Shape shape = project.ShapeTypes["Square"].CreateInstance();
shape.X = 100;
shape.Y = 100;
// Execute commands
project.ExecuteCommand(new InsertShapeCommand(diagram, LayerIds.None, shape, true, false));
project.ExecuteCommand(new MoveShapeByCommand(shape, 200, 200));
project.History.Undo();
project.History.Undo();
Assert.AreEqual(diagram.Shapes.Count, 0);
project.History.Redo();
Assert.AreEqual(diagram.Shapes.Count, 1);
Assert.AreEqual(diagram.Shapes.Bottom.X, 100);
project.History.Redo();
Assert.AreEqual(diagram.Shapes.Bottom.X, 300);
project.Repository.SaveChanges();
project.Close();
}
示例7: 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();
}
示例8: AggregationTest
public void AggregationTest() {
// -- Create a project --
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);
Diagram diagram = new Diagram("Diagram A");
// Create a group
ShapeGroup group = (ShapeGroup)project.ShapeTypes["ShapeGroup"].CreateInstance();
group.Children.Add(project.ShapeTypes["Circle"].CreateInstance(), 1);
group.Children.Add(project.ShapeTypes["Square"].CreateInstance(), 2);
group.Children.Add(project.ShapeTypes["Diamond"].CreateInstance(), 3);
group.MoveTo(200, 200);
diagram.Shapes.Add(group, 1);
// Create an aggregation
Box box = (Box)project.ShapeTypes["Box"].CreateInstance();
box.Children.Add(project.ShapeTypes["Circle"].CreateInstance(), 1);
box.Children.Add(project.ShapeTypes["Square"].CreateInstance(), 2);
box.Children.Add(project.ShapeTypes["Diamond"].CreateInstance(), 3);
box.MoveTo(400, 200);
diagram.Shapes.Add(box, 2);
// Save everything
project.Repository.InsertDiagram(diagram);
project.Repository.SaveChanges();
project.Close();
//
// -- Reload and modify --
project.Open();
foreach (Diagram d in project.Repository.GetDiagrams())
diagram = d;
group = (ShapeGroup)diagram.Shapes.Bottom;
Shape shape = null;
foreach (Shape s in group.Children)
shape = s;
group.Children.Remove(shape);
project.Repository.DeleteShape(shape);
box = (Box)diagram.Shapes.TopMost;
foreach (Shape s in box.Children)
shape = s;
box.Children.Remove(shape);
project.Repository.DeleteShape(shape);
project.Repository.SaveChanges();
project.Close();
//
// -- Check --
project.Open();
foreach (Diagram d in project.Repository.GetDiagrams()) {
project.Repository.GetDiagramShapes(d);
foreach (Shape s in d.Shapes)
Assert.AreEqual(2, s.Children.Count);
}
project.Close();
}
示例9: ShapeTest
//.........这里部分代码省略.........
//
// -- Test Properties --
s.Fit(0, 0, 40, 40); // ensure that the shape has a defined size
s.X = 100;
Assert.AreEqual(100, s.X);
s.Y = -100;
Assert.AreEqual(-100, s.Y);
Assert.ReferenceEquals(st, s.Type);
Assert.ReferenceEquals(null, s.Template);
Assert.ReferenceEquals(null, s.Tag);
s.Tag = "Hello";
Assert.AreEqual("Hello", (string)s.Tag);
Assert.AreEqual('A', s.SecurityDomainName);
s.SecurityDomainName = 'K';
Assert.AreEqual('K', s.SecurityDomainName);
Assert.ReferenceEquals(null, s.Parent);
s.Parent = null;
Assert.ReferenceEquals(null, s.ModelObject);
// s.ModelObject = project.ModelObjectTypes["Generic ModelObjectTypes Object"].CreateInstance();
// Assert
Assert.ReferenceEquals(project.Design.LineStyles.Normal, s.LineStyle);
s.LineStyle = project.Design.LineStyles.HighlightDashed;
Assert.ReferenceEquals(project.Design.LineStyles.HighlightDashed, s.LineStyle);
Assert.ReferenceEquals(null, ((IEntity)s).Id);
Assert.ReferenceEquals(null, s.DisplayService);
Assert.AreEqual(0, s.Children.Count);
Rectangle bounds1 = s.GetBoundingRectangle(true);
//
// -- Test Methods --
RelativePosition relPos = s.CalculateRelativePosition(100, -100);
Point absPos = s.CalculateAbsolutePosition(relPos);
Assert.AreEqual(absPos.X, 100);
Assert.AreEqual(absPos.Y, -100);
//
Shape clone = s.Clone();
Assert.AreEqual(clone.Y, s.Y);
Assert.ReferenceEquals(clone.LineStyle, s.LineStyle);
//
// TODO 2: Do not know, how to test the result.
s.ContainsPoint(0, 0);
s.ContainsPoint(105, -95);
s.ContainsPoint(-10000, +10000);
//
int cpc = 0;
foreach (ControlPointId id in s.GetControlPointIds(ControlPointCapabilities.Resize)) {
++cpc;
s.GetControlPointPosition(id);
Assert.IsTrue(s.HasControlPointCapability(id, ControlPointCapabilities.Resize));
}
//
s.MoveBy(-320, 1000);
Rectangle bounds2 = s.GetBoundingRectangle(true);
bounds2.Offset(320, -1000);
Assert.AreEqual(bounds1, bounds2);
s.MoveTo(100, -100);
bounds2 = s.GetBoundingRectangle(true);
Assert.AreEqual(bounds2, bounds1);
//
Point cPos = s.GetControlPointPosition(ControlPointId.Reference);
ControlPointId cpId = s.FindNearestControlPoint(cPos.X, cPos.Y, 1, ControlPointCapabilities.All);
Assert.IsTrue(s.HasControlPointCapability(cpId, ControlPointCapabilities.Reference));
//
Point oiPoint = s.CalculateConnectionFoot(1000, 1000);
bounds1 = s.GetBoundingRectangle(true);
bounds1.Inflate(2, 2);
Assert.IsTrue(Geometry.RectangleContainsPoint(bounds1, oiPoint));
//
Assert.IsTrue(s.IntersectsWith(bounds1.X, bounds1.Y, bounds1.Width, bounds1.Height));
//
bounds1 = new Rectangle(500, 500, 100, 100);
s.Fit(bounds1.X, bounds1.Y, bounds1.Width, bounds1.Height);
bounds1.Inflate(10, 10);
Assert.IsTrue(Geometry.RectangleContainsRectangle(bounds1, s.GetBoundingRectangle(true)));
//
foreach (MenuItemDef a in s.GetMenuItemDefs(0, 0, 0))
Assert.IsNotNull(a.Name);
//
// Connections
// One connection from each connection point to the shape
// One connection from each connection point to the next connection point
foreach (ControlPointId cpi in s.GetControlPointIds(ControlPointCapabilities.Connect)) {
Polyline polyline = (Polyline)project.ShapeTypes["Polyline"].CreateInstance();
polyline.Connect(1, s, cpi);
polyline.Connect(2, s, ControlPointId.Reference);
Assert.AreNotEqual(ControlPointId.None, s.IsConnected(ControlPointId.Any, polyline));
Assert.AreNotEqual(ControlPointId.None, s.IsConnected(cpi, polyline));
Assert.AreNotEqual(ControlPointId.None, s.IsConnected(ControlPointId.Reference, polyline));
}
// Control point manipulation
Point p = s.GetControlPointPosition(1);
if (s.MoveControlPointBy(1, -10, -10, ResizeModifiers.None)) {
p.Offset(-10, -10);
Assert.AreEqual(p, s.GetControlPointPosition(1));
s.MoveControlPointTo(1, p.X + 10, p.Y + 10, ResizeModifiers.None);
p.Offset(+10, +10);
Assert.AreEqual(p, s.GetControlPointPosition(1));
}
}
project.Close();
}