Example #1
0
        static async Task TestObjects(SpeckleApiClient myClient)
        {
            var myPoint = new SpecklePoint()
            {
                Value = new List <double>()
                {
                    1, 2, 3
                }
            };
            var mySecondPoint = new SpecklePoint()
            {
                Value = new List <double>()
                {
                    23, 33, 12
                }
            };
            var myCircle = new SpeckleCircle()
            {
                Radius = 21
            };
            var myPlane = new SpecklePlane()
            {
                Origin = new SpecklePoint()
                {
                    Value = new List <double>()
                    {
                        12, 12, 12
                    }
                }
            };
            var myArc = new SpeckleArc()
            {
                Radius = 2, AngleRadians = 2.1, EndAngle = 1, StartAngle = 0
            };

            myCircle.Properties = new Dictionary <string, object>();
            myCircle.Properties.Add("a  property", "Hello!");
            myCircle.Properties.Add("point", myPoint);


            List <SpeckleObject> myList = new List <SpeckleObject>();

            Console.WriteLine();
            try
            {
                Console.WriteLine("Creating some objects.");
                var Response = await myClient.ObjectCreateAsync(new List <SpeckleObject>() { myPoint, myCircle, myArc, myPlane });

                Console.WriteLine("OK: Saved " + Response.Resources.Count + " objects");
                myList = Response.Resources;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Updating an object");
                var Response = await myClient.ObjectUpdateAsync(myList[1]._id, new SpeckleCircle()
                {
                    Radius = 42
                });

                Console.WriteLine("OK: Saved " + Response.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Updating an object's properties");
                var Response = await myClient.ObjectUpdatePropertiesAsync(myList[1]._id, new { hello = "World", max = 3.14 });

                Console.WriteLine("OK: Saved " + Response.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting an object");
                var Response = await myClient.ObjectGetAsync(myList[1]._id);

                Console.WriteLine("OK: Got " + Response.Resource.ToJson());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting objects in bulk");
                var Response = await myClient.ObjectGetBulkAsync(new string[] { myList[1]._id, myList[0]._id, myList[2]._id }, "fields=properties,radius");

                Console.WriteLine("OK: Got " + Response.Resources.Count);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Deleting an object");
                var Response = await myClient.ObjectDeleteAsync(myList[0]._id);

                Console.WriteLine("OK: Got " + Response.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }