Esempio n. 1
0
        static async Task TestStreams(SpeckleApiClient myClient)
        {
            string streamId       = "lol";
            string secondStreamId = "hai";

            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
            };


            myPoint.Properties = new Dictionary <string, object>();
            myPoint.Properties.Add("Really", mySecondPoint);

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

            SpeckleStream myStream = new SpeckleStream()
            {
                Name    = "Hello World My Little Stream",
                Objects = new List <SpeckleObject>()
                {
                    myCircle, myPoint
                }
            };

            SpeckleStream secondStream = new SpeckleStream()
            {
                Name    = "Second Little Stream",
                Objects = new List <SpeckleObject>()
                {
                    myCircle, mySecondPoint
                }
            };

            Console.WriteLine();
            try
            {
                Console.WriteLine("Creating a stream.");
                var Response = await myClient.StreamCreateAsync(myStream);

                Console.WriteLine("OK: " + Response.Resource.ToJson());

                streamId = Response.Resource.StreamId;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Creating a second stream.");
                var Response = await myClient.StreamCreateAsync(secondStream);

                Console.WriteLine("OK: " + Response.Resource.ToJson());

                secondStreamId = Response.Resource.StreamId;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


            Console.WriteLine();
            try
            {
                Console.WriteLine("Diffing two streams!");
                var Response = await myClient.StreamDiffAsync(streamId, secondStreamId);

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting a stream.");
                var Response = await myClient.StreamGetAsync(streamId, null);

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting a stream's objects.");
                var Response = await myClient.StreamGetObjectsAsync(streamId, null);

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Updating a stream.");
                var Response = await myClient.StreamUpdateAsync(streamId, new SpeckleStream()
                {
                    Name = "I hate api testing", ViewerLayers = new List <object>()
                    {
                        new { test = "test" }
                    }
                });

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting a stream field.");
                var Response = await myClient.StreamGetAsync(streamId, "fields=viewerLayers,name,owner");

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting all users's streams.");
                var Response = await myClient.StreamsGetAllAsync();

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


            Console.WriteLine();
            try
            {
                Console.WriteLine("Cloning a stream.");
                var Response = await myClient.StreamCloneAsync(streamId);

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Deleting a stream: " + streamId);
                var Response = await myClient.StreamDeleteAsync(streamId);

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