//Private static void Main(string[] args) { ShapeDTO dto = new ShapeDTO(2, 3); string jsonstring = ShapeSerializer.ShapeToJson(dto); Console.WriteLine($"Serialized to json\n{jsonstring}"); var output = ShapeSerializer.JsonToShape(jsonstring); Shape s = new Shape(output.length, output.width); List <Shape> shapes = new List <Shape>(); for (int i = 1; i < 101; i++) { if (i % 5 == 0) { shapes.Add(new Triangle(i, i * 3)); } else { shapes.Add(new Rectangle(i, i)); } } //var bigArea = shapes.Where(s => s.Area() > 25).ToList(); // var rectangles = shapes.Where(s => s is Rectangle).ToList(); //Circle c = Circle.GetCircle; //c.Radius = 555; //foreach (var item in bigArea) //{ // Console.WriteLine(item.ToString()); //} //Console.WriteLine(c.Area()); //Console.ReadLine(); }
async void savePlayground() { var filePath = string.Empty; #if Windows using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.InitialDirectory = "D:\\School-D\\Jaar 2 1\\Periode 3\\Design Patterns\\MonoPaint\\Saves"; saveFileDialog.Filter = "monoPaint files (*.mp)|"; saveFileDialog.FilterIndex = 2; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { filePath = saveFileDialog.FileName; } } #elif OSX //NOTE: Nothing osx api not available!! #endif if (filePath != string.Empty) { int index = filePath.LastIndexOf('.'); if (filePath.Substring(index + 1) == "mp") { await ShapeSerializer.Serialize(Shapes, filePath); } else { await ShapeSerializer.Serialize(Shapes, filePath + ".mp"); } } }
private void SaveBtnClick(object sender, EventArgs e) { var shapes = shapeManager.ShapeList; ShapeSerializer.SerializeToBinary(shapes); ShapeSerializer.SerializeToXml(shapes); ShapeSerializer.SerializeToJson(shapes); }
static void Main(string[] args) { ShapeDTO dto = new ShapeDTO(2, 3); //DemoDAO.DemoShapeDBEntities database = new DemoDAO.DemoShapeDBEntities(); //DemoDAO.Shape s = new DemoDAO.Shape(); //s.width = 20; //s.height = 2; //s.fk_ShapeType = 1; //database.Shapes.Add(s); //database.SaveChanges(); string jsonString = ShapeSerializer.ShapeToJson(dto); Console.WriteLine($"Serialized to json\n{jsonString}"); string xmlString = ShapeSerializer.ShapeToXML(dto); Console.WriteLine($"Serialized to xml\n{xmlString}"); var output = ShapeSerializer.JsonToShape(jsonString); //List<theShapes> shapes = new List<theShapes>(); //shapes.Add(new Square(5)); //shapes.Add(new Square(1)); //shapes.Add(new Triangle(2, 5)); //shapes.Add(new Triangle(1, 1)); //shapes.Add(new Rectangle(4, 6)); //shapes.Add(new Rectangle(3, 9)); //shapes.Add(new theShapes(6, 7)); //Dictionary<string, theShapes> dict = new Dictionary<string, theShapes>(); //foreach (var item in dict.Keys) //{ // Console.WriteLine(item + ", "); //} //Console.WriteLine("\n\nprint shapes with area equal or greater than 4: "); //var res = shapes.Where(o => o.Area() >= 4).ToList(); //var rectlist = shapes.Where(r => r is Rectangle).ToList(); //foreach (var item in rectlist) //{ // Console.WriteLine(item.GetType()); // Console.WriteLine(item.ToString()); //} //var triList = (from t in shapes where t is Triangle select t).ToList(); //foreach (var item in res) //{ // Console.WriteLine(item.GetType()); // Console.WriteLine(item.Area()); // Console.WriteLine(item.ToString()); //} //var res2 = shapes.Where(o => o.Area() < 4).ToList(); //Console.WriteLine($"\n shapes w/ area < 4, count is {res2.Count}"); Console.WriteLine(6 / 2 * (1 + 2)); Console.ReadLine(); }
private void LoadBtnClick(object sender, EventArgs e) { var shapes = ShapeSerializer.DeserializeFromBinary(); // var shapes = ShapeSerializer.DeserializeFromXml(); // var shapes = ShapeSerializer.DeserializeFromJson(); shapeManager.ShapeList = shapes; mainTreeView.Nodes.Clear(); shapes.ForEach(AddShapeToTreeView); mainPicBox.Invalidate(); }
public void TestMethod1() { Shape tvar1 = new Shape(1, 3, 2, 5, 1, Color.Blue); var binSerializer = new BinaryFormatter(); Stream stream = File.OpenWrite("test.bin"); ShapeSerializer.ShapeSerialize(stream, tvar1); stream.Close(); stream = File.OpenRead("test.bin"); Assert.AreEqual(tvar1, ShapeSerializer.ShapeDeserialize(stream)); stream.Close(); }
async void loadPlayground() { var filePath = string.Empty; #if Windows if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = "D:\\School-D\\Jaar 2 1\\Periode 3\\Design Patterns\\MonoPaint\\Saves"; openFileDialog.Filter = "monoPaint files (*.mp)|"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { filePath = openFileDialog.FileName; } } } #elif OSX filePath = "Saves/save.mp"; #endif if (filePath != string.Empty) { if (File.Exists(filePath)) { List <aShape> loadedShapes = ShapeSerializer.Deserialize(filePath); SetShapes(loadedShapes); } else { Console.WriteLine("You need to save before you can open the save"); } } }
static void Main(string[] args) { ShapeDTO dto = new ShapeDTO(2, 3); var jsonString = ShapeSerializer.ShapeToJSON(dto); //makes object into JSON Console.WriteLine($"Serialized to JSON {jsonString}"); var output = ShapeSerializer.JSONToShape(jsonString); //makes the string an object again Shape s = new Shape(output.height, output.width); Console.WriteLine($"Shape area is {s.Area()}"); var xmlstring = ShapeSerializer.ShapeToXML(dto); Console.WriteLine($"Serialized to XML {xmlstring}"); var xmloutput = ShapeSerializer.XMLtoShape(xmlstring); Shape shape = new Rectangle(xmloutput.width, xmloutput.height); Console.WriteLine($"Rectangle Area is {shape.Area()}"); /* #region Inheritence Try/Catch Shape rect = new Rectangle (1, 2); Shape square = new Square(4); Shape triangle = new Triangle(3, 3); Shape s = new Rectangle(1, 2); IShape s2 = new Rectangle(2, 2); Console.WriteLine(s.ToString()); if (rect is Rectangle) { Console.WriteLine("rect is a rectangle"); Rectangle r = (Rectangle)rect; Rectangle r2 = rect as Rectangle; } Console.WriteLine("Rectangle " + rect.Area()); Console.WriteLine("Square " + square.Area()); Console.WriteLine("Triangle " + triangle.Area()); Square sq = new Square(0); try { sq.Area(); } catch (ShapeZeroAreaException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } Console.WriteLine("SQ area " + sq.Area()); #endregion Inheritance Try/Catch List<Shape> shapes = new List<Shape>(); shapes.Add(s); shapes.Add(new Square(4)); shapes.Add(new Triangle(2, 4)); shapes.Add(new Rectangle(4, 9)); shapes.Add(new Triangle(2, 9)); Console.WriteLine("List Contains " + shapes.Count + " Shapes"); List<Shape> result = shapes.FindAll(p => p.Area() > 4); // Console.WriteLine(result.GetType()); for (int i = 0; i < shapes.Count; i++) { //do something //var item = shapes[i]; //item.Area(); } foreach (var item in result) { Console.WriteLine(item.GetType()); Console.WriteLine(item.Area()); Console.WriteLine(item.ToString()); } Circle c = Circle.GetCircle; c.Radius = 2; Circle c1 = Circle.GetCircle; Console.WriteLine(c.Area()); Dictionary<string, Shape> dict = new Dictionary<string, Shape>(); //dict. */ Console.ReadLine(); }
public void Start() { var host = new Host(); var lineHit = new LineHit(); var propCache = new PropertyCache(); var shapeSerializer = new ShapeSerializer(propCache); var sceneStore = new JsonSceneStore(); var rotateParam = new RotateParam { Angle = 0 }; var rotateView = new IntInputView { DataContext = new RotateViewModel(rotateParam) }; var thiknessParam = new ThiknessParam { Thikness = 5 }; var thiknessView = new IntInputView { DataContext = new ThiknessViewModel(thiknessParam) }; var colorParam = new ColorParam { Color = Colors.Black }; var colorView = new ColorView { DataContext = new ColorViewModel <IShapeObject>(colorParam) }; var fillParam = new FillParam { Color = Colors.Transparent }; var fillView = new ColorView { DataContext = new ColorViewModel <IFillObject>(fillParam) }; var vm = new HostViewModel( host.Canvas, new List <ShapeToolParam> { new ShapeToolParam("Поворот", rotateView, rotateParam), new ShapeToolParam("Толщина", thiknessView, thiknessParam), new ShapeToolParam("Цвет", colorView, colorParam), new ShapeToolParam("Заливка", fillView, fillParam), }, sceneStore, new ShapeTool(0, LoadImage("pack://application:,,,/Painter;component/Resources/Images/line.png"), new PolyLineCreator(0, 50, Brushes.Black, 10, lineHit, shapeSerializer)), new ShapeTool(1, LoadImage("pack://application:,,,/Painter;component/Resources/Images/rectangle.png"), new RectangleCreator(1, 50, 50, Brushes.Black, 10, Brushes.Transparent, lineHit, shapeSerializer)) ); host.DataContext = vm; App.Current.MainWindow = host; host.Show(); }