Пример #1
0
        /// <summary>
        /// Gets an account from the existing ones.
        /// </summary>
        /// <returns></returns>
        public static Account GetAccount( )
        {
            Console.WriteLine("What email address should we use to search for local accounts?");
            var email = Console.ReadLine();

            try
            {
                return(LocalContext.GetDefaultAccount());
            }
            catch
            {
                var accounts = LocalContext.GetAccountsByEmail(email);
                if (accounts.Count == 0)
                {
                    Console.WriteLine("No account found. Please try again!");
                    return(GetAccount());
                }

                Console.WriteLine(String.Format("Found {0} accounts. Which one should we use? (0 - {0})", accounts.Count));
                int i = 0;
                foreach (var acc in accounts)
                {
                    Console.WriteLine(String.Format("{0} : {1} at {2}", i++, acc.Email, acc.RestApi));
                }

                var selIndex = System.Convert.ToInt32(Console.ReadLine());
                return(accounts[selIndex]);
            }
        }
Пример #2
0
 public static async Task <bool> InitialLoad(TabCoordinator coordinator, IProgress <MessageEventArgs> loggingProgress)
 {
     coordinator.Init();
     try
     {
         //This will throw an exception if there is no default account
         var account = LocalContext.GetDefaultAccount();
         if (account == null)
         {
             return(false);
         }
         return(await CompleteLogin(coordinator, new SpeckleAccountForUI(account.RestApi, account.Email, account.Token), loggingProgress));
     }
     catch
     {
         loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "No default account found - press the Login button to login/select an account"));
         return(false);
     }
 }
Пример #3
0
        public override void AddedToDocument(GH_Document document)
        {
            base.AddedToDocument(document);
            Document = this.OnPingDocument();

            if (Client == null)
            {
                Account account = null;
                try
                {
                    account = LocalContext.GetDefaultAccount();
                }
                catch (Exception err)
                {
                }

                if (account == null)
                {
                    var signInWindow = new SpecklePopup.SignInWindow(true);
                    var helper       = new System.Windows.Interop.WindowInteropHelper(signInWindow);
                    helper.Owner = Rhino.RhinoApp.MainWindowHandle();

                    signInWindow.ShowDialog();

                    if (signInWindow.AccountListBox.SelectedIndex != -1)
                    {
                        account = signInWindow.accounts[signInWindow.AccountListBox.SelectedIndex];
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Account selection failed.");
                        return;
                    }
                }

                RestApi   = account.RestApi;
                AuthToken = account.Token;
            }

            StreamIdChanger           = new System.Timers.Timer(1000); StreamIdChanger.Enabled = false;
            StreamIdChanger.AutoReset = false;
            StreamIdChanger.Elapsed  += ChangeStreamId;
        }
Пример #4
0
        public override void AddedToDocument(GH_Document document)
        {
            base.AddedToDocument(document);
            Document = OnPingDocument();

            if (Client == null)
            {
                Locked   = true;
                NickName = "Initialising";

                Account account = null;
                try
                {
                    account = LocalContext.GetDefaultAccount();
                    RestApi = account.RestApi;
                    Client  = new SpeckleApiClient(account.RestApi);
                    Client.IntializeSender(account.Token, Document.DisplayName, "Grasshopper", Document.DocumentID.ToString()).ContinueWith(task =>
                    {
                        Rhino.RhinoApp.InvokeOnUiThread(ExpireComponentAction);
                    });
                }
                catch (Exception err)
                {
                }

                if (account == null)
                {
                    var signInWindow = new SpecklePopup.SignInWindow(true);
                    var helper       = new System.Windows.Interop.WindowInteropHelper(signInWindow);
                    helper.Owner = Rhino.RhinoApp.MainWindowHandle();

                    signInWindow.ShowDialog();

                    if (signInWindow.AccountListBox.SelectedIndex != -1)
                    {
                        account = signInWindow.accounts[signInWindow.AccountListBox.SelectedIndex];
                        RestApi = account.RestApi;
                        Client  = new SpeckleApiClient(account.RestApi);
                        Client.IntializeSender(account.Token, Document.DisplayName, "Grasshopper", Document.DocumentID.ToString()).ContinueWith(task =>
                        {
                            Rhino.RhinoApp.InvokeOnUiThread(ExpireComponentAction);
                        });
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Account selection failed.");
                        return;
                    }
                }
            }
            else
            {
            }

            Client.OnReady += (sender, e) =>
            {
                StreamId = Client.StreamId;
                if (!WasSerialised)
                {
                    Locked   = false;
                    NickName = "Anonymous Stream";
                }
                ////this.UpdateMetadata();
                Rhino.RhinoApp.InvokeOnUiThread(ExpireComponentAction);
            };

            Client.OnWsMessage += OnWsMessage;

            Client.OnLogData += (sender, e) =>
            {
                Log += DateTime.Now.ToString("dd:HH:mm:ss ") + e.EventData + "\n";
            };

            Client.OnError += (sender, e) =>
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.EventName + ": " + e.EventData);
                Log += DateTime.Now.ToString("dd:HH:mm:ss ") + e.EventData + "\n";
            };

            ExpireComponentAction = () => ExpireSolution(true);

            ObjectChanged += (sender, e) => UpdateMetadata();

            foreach (var param in Params.Input)
            {
                param.ObjectChanged += (sender, e) => UpdateMetadata();
            }

            MetadataSender = new System.Timers.Timer(1000)
            {
                AutoReset = false, Enabled = false
            };
            MetadataSender.Elapsed += MetadataSender_Elapsed;

            DataSender = new System.Timers.Timer(2000)
            {
                AutoReset = false, Enabled = false
            };
            DataSender.Elapsed += DataSender_Elapsed;

            ObjectCache = new Dictionary <string, SpeckleObject>();

            Grasshopper.Instances.DocumentServer.DocumentRemoved += DocumentServer_DocumentRemoved;
        }