public override void RemovedFromDocument(GH_Document document)
 {
     if (myReceiver != null)
     {
         myReceiver.Dispose();
     }
     base.RemovedFromDocument(document);
 }
        public override void DocumentContextChanged(GH_Document document, GH_DocumentContext context)
        {
            if (context == GH_DocumentContext.Close)
            {
                Client?.Dispose();
            }

            base.DocumentContextChanged(document, context);
        }
        /// <summary>
        /// Exposed method for users to call when trying to login to a Speckle server via code.
        /// </summary>
        /// <param name="email">The email of the account you wish to login with.</param>
        /// <param name="password">The corresponding password for the account.</param>
        /// <param name="callBack">A method callback which takes a <c>User</c>.</param>
        /// <returns>An async Task which can be awaited with a coroutine or just ignored.</returns>
        /// <remarks>If login was successful, the resulting user object is passed back. If failed, null
        /// is passed. Need to be using the <c>SpeckleCore</c> namespace to access this type.</remarks>
        public virtual async Task LoginAsync(string email, string password, Action <User> callBack)
        {
            if (string.IsNullOrWhiteSpace(email) || string.IsNullOrWhiteSpace(password))
            {
                throw new InvalidOperationException("The email and password arguments both need to be provided if you wish to login.");
            }

            SpeckleApiClient loginClient = new SpeckleApiClient(serverUrl.Trim());

            User user = new User {
                Email = email.Trim(), Password = password.Trim()
            };

            Debug.Log("Atempting login");

            ResponseUser userGet = await loginClient.UserLoginAsync(user);

            if (userGet == null)
            {
                Debug.LogError("Could not login");
                callBack?.Invoke(null);
            }
            else
            {
                loggedInUser = userGet.Resource;
                Debug.Log("Logged in as " + loggedInUser.Name + " " + loggedInUser.Surname);

                loginClient?.Dispose(true);

                callBack?.Invoke(loggedInUser);
            }
        }
 public override void RemovedFromDocument(GH_Document document)
 {
     if (Client != null)
     {
         Client.Dispose();
     }
     base.RemovedFromDocument(document);
 }
 public override void RemovedFromDocument(GH_Document document)
 {
     if (Client != null)
     {
         //Client.StreamUpdateAsync(Client.StreamId, new SpeckleStream() { Deleted = true });
         Client.Dispose(false);
     }
     base.RemovedFromDocument(document);
 }
Beispiel #6
0
        /// <summary>
        /// Removes reponse methods from the <c>OnReady</c>, <c>OnLogData</c>, <c>OnWsMessage</c> and
        /// <c>OnError</c> events of the internal client object. Since the internal client also gets disposed,
        /// initialization will need to happen again.
        /// </summary>
        public virtual void UnregisterClient()
        {
            client.OnReady     -= ClientOnReady;
            client.OnLogData   -= ClientOnLogData;
            client.OnWsMessage -= ClientOnWsMessage;
            client.OnError     -= ClientOnError;

            client.Dispose(true);
        }