示例#1
0
        public override void AddedToDocument(GH_Document document)
        {
            base.AddedToDocument(document);

            SenderGuids = new List <string>();

            if (SerialisedReceiver != null)
            {
                Receiver = new SpeckleReceiver(SerialisedReceiver, new GhRhConveter());
                StreamId = Receiver.GetStreamId();
                ApiUrl   = Receiver.GetServer();
                Token    = Receiver.GetToken();

                RegistermyReceiverEvents();
            }
            else
            {
                var myForm = new SpecklePopup.MainWindow();

                var some = new System.Windows.Interop.WindowInteropHelper(myForm)
                {
                    Owner = Rhino.RhinoApp.MainWindowHandle()
                };
                myForm.ShowDialog();

                if (myForm.restApi != null && myForm.apitoken != null)
                {
                    ApiUrl = myForm.restApi;
                    Token  = myForm.apitoken;
                }
            }

            ExpireComponentAction = () => this.ExpireSolution(true);
        }
        public override void AddedToDocument(GH_Document document)
        {
            base.AddedToDocument(document);
            Document = this.OnPingDocument();

            if (Client == null)
            {
                var myForm = new SpecklePopup.MainWindow(false, true);

                var some = new System.Windows.Interop.WindowInteropHelper(myForm);
                some.Owner = Rhino.RhinoApp.MainWindowHandle();

                myForm.ShowDialog();

                if (myForm.restApi != null && myForm.apitoken != null)
                {
                    RestApi   = myForm.restApi;
                    AuthToken = myForm.apitoken;
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Account selection failed.");
                    return;
                }
            }

            StreamIdChanger           = new System.Timers.Timer(1000); StreamIdChanger.Enabled = false;
            StreamIdChanger.AutoReset = false;
            StreamIdChanger.Elapsed  += ChangeStreamId;
        }
示例#3
0
        public void Loaded(ViewLoadedParams p)
        {
            speckleAccountsMenu = new MenuItem {
                Header = "Speckle Accounts"
            };
            speckleAccountsMenu.Click += (sender, args) =>
            {
                //var viewModel = new SampleWindowViewModel(p);
                var window = new SpecklePopup.MainWindow(false)
                {
                    Owner = p.DynamoWindow
                };

                window.Left = window.Owner.Left + 400;
                window.Top  = window.Owner.Top + 200;

                // Show a modeless window.
                window.Show();
            };
            p.AddMenuItem(MenuBarType.View, speckleAccountsMenu);
        }
        public override void AddedToDocument(GH_Document document)
        {
            base.AddedToDocument(document);
            Document = OnPingDocument();

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

                var myForm = new SpecklePopup.MainWindow(false, true);

                var some = new System.Windows.Interop.WindowInteropHelper(myForm)
                {
                    Owner = Rhino.RhinoApp.MainWindowHandle()
                };

                myForm.ShowDialog();

                if (myForm.restApi != null && myForm.apitoken != null)
                {
                    Client  = new SpeckleApiClient(myForm.restApi);
                    RestApi = myForm.restApi;
                    Client.IntializeSender(myForm.apitoken, Document.DisplayName, "Grasshopper", Document.DocumentID.ToString()).ContinueWith(task =>
                    {
                        Rhino.RhinoApp.MainApplicationWindow.Invoke(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.MainApplicationWindow.Invoke(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;
        }