Example #1
0
        /// <summary>
        /// Initializes sender.
        /// </summary>
        /// <param name="streamID">Stream ID of stream. If no stream ID is given, a new stream is created.</param>
        /// <param name="streamName">Stream name</param>
        /// <returns>Task</returns>
        public async Task InitializeSender(string streamID = "", string clientID = "", string streamName = "")
        {
            apiClient.AuthToken = apiToken;

            if (string.IsNullOrEmpty(clientID))
            {
                HelperFunctions.tryCatchWithEvents(() =>
                {
                    var streamResponse = apiClient.StreamCreateAsync(new SpeckleStream()).Result;
                    apiClient.Stream   = streamResponse.Resource;
                    apiClient.StreamId = streamResponse.Resource.StreamId;
                },
                                                   "", "Unable to create stream on the server");

                HelperFunctions.tryCatchWithEvents(() =>
                {
                    var clientResponse = apiClient.ClientCreateAsync(new AppClient()
                    {
                        DocumentName = Path.GetFileNameWithoutExtension(GSA.GsaApp.gsaProxy.FilePath),
                        DocumentType = "GSA",
                        Role         = "Sender",
                        StreamId     = this.StreamID,
                        Online       = true,
                    }).Result;
                    apiClient.ClientId = clientResponse.Resource._id;
                }, "", "Unable to create client on the server");
            }
            else
            {
                HelperFunctions.tryCatchWithEvents(() =>
                {
                    var streamResponse = apiClient.StreamGetAsync(streamID, null).Result;

                    apiClient.Stream   = streamResponse.Resource;
                    apiClient.StreamId = streamResponse.Resource.StreamId;
                }, "", "Unable to get stream response");

                HelperFunctions.tryCatchWithEvents(() =>
                {
                    var clientResponse = apiClient.ClientUpdateAsync(clientID, new AppClient()
                    {
                        DocumentName = Path.GetFileNameWithoutExtension(GSA.GsaApp.gsaProxy.FilePath),
                        Online       = true,
                    }).Result;

                    apiClient.ClientId = clientID;
                }, "", "Unable to update client on the server");
            }

            apiClient.Stream.Name = streamName;

            HelperFunctions.tryCatchWithEvents(() =>
            {
                apiClient.SetupWebsocket();
            }, "", "Unable to set up web socket");

            HelperFunctions.tryCatchWithEvents(() =>
            {
                apiClient.JoinRoom("stream", streamID);
            }, "", "Uable to join web socket");
        }
Example #2
0
        static async Task TestClients(SpeckleApiClient myClient)
        {
            string clientId = "lol";

            Console.WriteLine();
            try
            {
                Console.WriteLine("Creating a client.");
                var Response = await myClient.ClientCreateAsync(new AppClient()
                {
                    DocumentGuid = "fakester", Role = "Sender", Online = false
                });

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

                clientId = Response.Resource._id;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Updating a client.");
                var Response = await myClient.ClientUpdateAsync(clientId, new AppClient()
                {
                    Role = "Receiver", DocumentLocation = "C£aapppdata/x/xdfsdf.gh"
                });

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting a client.");
                var Response = await myClient.ClientGetAsync(clientId);

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting all users clients.");
                var Response = await myClient.ClientGetAllAsync();

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Deleteing  a client.");
                var Response = await myClient.ClientDeleteAsync(clientId);

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