Esempio n. 1
0
        public async Task <ActionResult> Calculate([Bind("Length, Width, Radius, ShapeType, Area")] Models.Shape shape)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri("http://calculatorapi");

            try
            {
                Console.WriteLine("Shape is " + shape.ShapeType);
                switch (shape.ShapeType)
                {
                case "circle":
                    var r1 = await httpClient.PostAsync("/api/area/circle",
                                                        FormatPayload(new { radius = shape.Radius }));

                    shape.Area = await ExtractResponse(r1);

                    break;

                case "rectangle":
                    var r2 = await httpClient.PostAsync("/api/area/rectangle",
                                                        FormatPayload(new { length = shape.Length, width = shape.Width }));

                    shape.Area = await ExtractResponse(r2);

                    break;
                }
                return(View(shape));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(View(ex));
            }
        }
Esempio n. 2
0
        public void ReadXml_Polygon(string file_name)
        {
            string      lat, lon, alt;
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(file_name);

            string dialog_text = "XMLReadPath\n\n";

            // Get Polygons

            XmlNodeList shapelist   = xmlDoc.DocumentElement.SelectNodes("/WPG/Polygon_List/Polygon");
            int         shape_count = shapelist.Count;

            dialog_text = dialog_text + "Shape Count : " + shape_count + "\n";
            ClearShapes();
            foreach (XmlNode shape_node in shapelist)
            {
                Models.Shape shape = new Models.Shape();
                shape.name        = shape_node.SelectSingleNode("Name").InnerText;
                shape.internal_id = Convert.ToInt16(shape_node.SelectSingleNode("InternalId").InnerText);
                dialog_text       = dialog_text + "Shape : " + shape.name + "\n";
                LinkedList <PolyPoint> polypoints   = new LinkedList <PolyPoint>();
                XmlNodeList            vertex_nodes = shape_node.SelectNodes("./Vertex_List/Vertex");
                dialog_text = dialog_text + "Vertex Count: " + Convert.ToString(vertex_nodes.Count) + "\n";

                foreach (XmlNode vertex_node in vertex_nodes)
                {
                    lat = vertex_node.SelectSingleNode("Lat").InnerText;
                    lon = vertex_node.SelectSingleNode("Lon").InnerText;
                    alt = vertex_node.SelectSingleNode("Alt").InnerText;
                    PolyPoint point = new PolyPoint();
                    point.lat = Convert.ToDouble(lat);
                    point.lon = Convert.ToDouble(lon);
                    point.alt = Convert.ToDouble(alt);
                    polypoints.AddLast(point);
                    dialog_text = dialog_text + "\tVertex : " + lat + ", " + lon + ", " + alt + "\n";
                }

                shape.points = polypoints;
                AddShapeId(shape.internal_id, shape);
                //MessageBox.Show(Convert.ToString(polypoints.Count), "xxx");
            }
        }
Esempio n. 3
0
            /// <summary>
            /// ShapeChanged event. A new shape position is sent.
            /// </summary>
            /// <param name="shape">The new shape position.</param>
            public async void ShapeChanged(Models.Shape shape)
            {
                if (isClosing)
                {
                    return;
                }

                await App.Current.Dispatcher.InvokeAsync(() =>
                {
                    Canvas.SetTop(UiShape, shape.Y);
                    Canvas.SetLeft(UiShape, shape.X);
                    ((RotateTransform)UiShape.RenderTransform).Angle = shape.Angle;

                    if (!shapesCanvas.Children.Contains(UiShape))
                    {
                        shapesCanvas.Children.Add(UiShape);
                    }
                });
            }
Esempio n. 4
0
 private void DrawShape(Models.Shape shape)
 {
     shape.Draw();
 }