Ejemplo n.º 1
0
        //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();
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        public ShapeDTO GetArea(byte a, byte b, byte c, byte d)
        {
            double   PI   = 3.1415926535897931;
            ShapeDTO data = new ShapeDTO();

            data.Triangle  = ((a + b + c) / 2);
            data.Square    = (a * a);
            data.Rectangle = (a * b);
            data.Circle    = (PI * d);

            var result = _mapper.Map <ShapeDTO>(data);

            return(data);
        }
        public ActionResult <bool> GetShapePeremeter(ShapeType type, [FromBody] ShapeDTO shapeData)
        {
            switch (type)
            {
            case ShapeType.Rectangle:
            {
                return(ShapeDomain.Rectangle.Create(shapeData.Sides)
                       .Map((data) =>
                    {
                        return true;
                    }).ToActionResult());
            }

            default:
            {
                break;
            }
            }

            return(false);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> UploadShape([FromBody] ShapeDTO data)
        {
            if (UserIsLoggedIn())
            {
                if (Db.Shape.Any(s => s.Name == data.Name))
                {
                    return(Conflict());
                }

                Db.Shape.Add(new Shape
                {
                    Id     = Guid.NewGuid(),
                    Name   = data.Name,
                    Dxf    = data.Dxf,
                    UserId = Guid.Parse(GetSessionUserId()),
                    Width  = data.Width,
                    Height = data.Height
                });
                await Db.SaveChangesAsync();

                return(Ok());
            }
            return(Unauthorized());
        }
Ejemplo n.º 6
0
        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();


        }