예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Smelly Sockets");

            SelectedAccount = SpkConsole.Program.GetAccount();

            var spkClient_A = new SpeckleApiClient(SelectedAccount.RestApi, false, "console application");
            var spkClient_B = new SpeckleApiClient(SelectedAccount.RestApi, false, "console application");

            spkClient_A.AuthToken = SelectedAccount.Token;
            spkClient_B.AuthToken = SelectedAccount.Token;

            //gen streamid
            DummyStreamId = spkClient_A.StreamCreateAsync(new SpeckleStream()
            {
                Name = "WS Test"
            }).Result.Resource.StreamId;
            Console.WriteLine($"Created dummy stream: {DummyStreamId}. Press any key to continue stuff.");

            // Add event handlers and setup streamId on both ws clients. The event handlers just spit out what they get.
            spkClient_A.StreamId = DummyStreamId;
            spkClient_A.SetupWebsocket();
            spkClient_A.OnWsMessage += SpkClient_A_OnWsMessage;

            spkClient_B.StreamId = DummyStreamId;
            spkClient_B.SetupWebsocket();
            spkClient_B.OnWsMessage += SpkClient_B_OnWsMessage;


            Console.WriteLine("Waiting for 200ms, ensure connection actually happened. This is an issue with core, it doesn't expose a 'onwsconnection' event :/");
            Thread.Sleep(200);

            // Flop them in a room - this is important if you want to broadcast messages.
            spkClient_A.JoinRoom("stream", DummyStreamId);
            spkClient_B.JoinRoom("stream", DummyStreamId);

            // Same hack as above.
            Thread.Sleep(200);

            // Send some dummy broadcasts
            spkClient_A.BroadcastMessage("stream", DummyStreamId, new { customEventType = "update-mesh", data = "42" });
            spkClient_A.BroadcastMessage("stream", DummyStreamId, new { customEventType = "update-mesh-other", data = "wow" });

            spkClient_B.BroadcastMessage("stream", DummyStreamId, new { customEventType = "update-mesh-other", data = "wow" });
            spkClient_B.SendMessage(spkClient_A.ClientId, new { what = "This is a direct, 1-1 message from B to A." });


            Console.WriteLine("Press any key to continue testing the barebones approach!");

            BareBonesApproach();

            Console.WriteLine("Done. Press any key to continue.");
            spkClient_A.StreamDeleteAsync(DummyStreamId);
            Console.ReadLine();
        }
예제 #2
0
 private void BroadcastStreamUpdate(ref int numErrors)
 {
     try
     {
         apiClient.BroadcastMessage("stream", StreamID, new { eventType = "update-global" });
     }
     catch (Exception ex)
     {
         numErrors++;
         var speckleExceptionContext = ExtractSpeckleExceptionContext(ex);
         var errContext = speckleExceptionContext.Concat(new[] { "Failed to broadcast update-global message on stream", "StreamId=" + StreamID });
         GSA.GsaApp.gsaMessenger.CacheMessage(MessageIntent.TechnicalLog, MessageLevel.Error, ex, errContext.ToArray());
     }
 }
예제 #3
0
        private void MetadataSender_Elapsed(object sender, ElapsedEventArgs e)
        {
            //if (ManualMode)
            //{
            //    return;
            //}
            // we do not need to enque another metadata sending event as the data update superseeds the metadata one.
            if (DataSender.Enabled)
            {
                return;
            }
            ;
            SpeckleStream updateStream = new SpeckleStream()
            {
                Name   = BucketName,
                Layers = BucketLayers
            };

            var updateResult = Client.StreamUpdateAsync(Client.StreamId, updateStream).Result;

            //Log += updateResult.Message;
            Client.BroadcastMessage("stream", Client.StreamId, new { eventType = "update-meta" });
        }
예제 #4
0
        public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
        {
            base.AppendAdditionalMenuItems(menu);
            GH_DocumentObject.Menu_AppendItem(menu, "Copy streamId (" + StreamId + ") to clipboard.", (sender, e) =>
            {
                if (StreamId != null)
                {
                    System.Windows.Clipboard.SetText(StreamId);
                }
            });

            GH_DocumentObject.Menu_AppendSeparator(menu);

            base.AppendAdditionalMenuItems(menu);
            GH_DocumentObject.Menu_AppendItem(menu, "Fore refresh.", (sender, e) =>
            {
                if (StreamId != null)
                {
                    DataSender.Start();
                }
            });

            GH_DocumentObject.Menu_AppendSeparator(menu);

            GH_DocumentObject.Menu_AppendItem(menu, "View stream.", (sender, e) =>
            {
                if (StreamId == null)
                {
                    return;
                }
                System.Diagnostics.Process.Start(RestApi.Replace("api", "view") + @"/?" + StreamId);
            });

            GH_DocumentObject.Menu_AppendItem(menu, "View stream data.", (sender, e) =>
            {
                if (StreamId == null)
                {
                    return;
                }
                System.Diagnostics.Process.Start(RestApi + @"/streams/" + StreamId);
            });

            GH_DocumentObject.Menu_AppendItem(menu, "View layers data online.", (sender, e) =>
            {
                if (StreamId == null)
                {
                    return;
                }
                System.Diagnostics.Process.Start(RestApi + @"/streams/" + StreamId + @"/layers");
            });

            GH_DocumentObject.Menu_AppendItem(menu, "View objects data online.", (sender, e) =>
            {
                if (StreamId == null)
                {
                    return;
                }
                System.Diagnostics.Process.Start(RestApi + @"/streams/" + StreamId + @"/objects?omit=displayValue,base64");
            });

            GH_DocumentObject.Menu_AppendSeparator(menu);
            GH_DocumentObject.Menu_AppendItem(menu, "Save current stream as a version.", (sender, e) =>
            {
                var cloneResult = mySender.StreamCloneAsync(StreamId).Result;
                mySender.Stream.Children.Add(cloneResult.Clone.StreamId);

                mySender.BroadcastMessage(new { eventType = "update-children" });

                System.Windows.MessageBox.Show("Stream version saved. CloneId: " + cloneResult.Clone.StreamId);
            });

            if (mySender.Stream == null)
            {
                return;
            }

            GH_DocumentObject.Menu_AppendSeparator(menu);
            if (mySender.Stream.Parent == null)
            {
                GH_DocumentObject.Menu_AppendItem(menu: menu, text: "This is a parent stream.", enabled: false, click: null);
            }
            else
            {
                GH_DocumentObject.Menu_AppendItem(menu: menu, text: "Parent: " + mySender.Stream.Parent, click: (sender, e) =>
                {
                    System.Windows.Clipboard.SetText(mySender.Stream.Parent);
                    System.Windows.MessageBox.Show("Parent id copied to clipboard. Share away!");
                });
            }
            GH_DocumentObject.Menu_AppendSeparator(menu);


            GH_DocumentObject.Menu_AppendSeparator(menu);
            GH_DocumentObject.Menu_AppendItem(menu, "Children:");
            GH_DocumentObject.Menu_AppendSeparator(menu);

            foreach (string childId in mySender.Stream.Children)
            {
                GH_DocumentObject.Menu_AppendItem(menu, "Child " + childId, (sender, e) =>
                {
                    System.Windows.Clipboard.SetText(childId);
                    System.Windows.MessageBox.Show("Child id copied to clipboard. Share away!");
                });
            }
        }
예제 #5
0
        public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
        {
            base.AppendAdditionalMenuItems(menu);
            GH_DocumentObject.Menu_AppendItem(menu, "Copy streamId (" + StreamId + ") to clipboard.", (sender, e) =>
            {
                if (StreamId != null)
                {
                    System.Windows.Clipboard.SetText(StreamId);
                }
            });

            GH_DocumentObject.Menu_AppendSeparator(menu);

            base.AppendAdditionalMenuItems(menu);
            GH_DocumentObject.Menu_AppendItem(menu, "Force refresh.", (sender, e) =>
            {
                if (StreamId != null)
                {
                    DataSender.Start();
                }
            });

            GH_DocumentObject.Menu_AppendSeparator(menu);

            base.AppendAdditionalMenuItems(menu);
            GH_DocumentObject.Menu_AppendItem(menu, "Toggle Manual Mode (Status: " + ManualMode + ")", (sender, e) =>
            {
                ManualMode = !ManualMode;
                m_attributes.ExpireLayout();

                if (!ManualMode && State == "Expired")
                {
                    UpdateData();
                }
            });

            GH_DocumentObject.Menu_AppendSeparator(menu);

            GH_DocumentObject.Menu_AppendItem(menu, "View stream.", (sender, e) =>
            {
                if (StreamId == null)
                {
                    return;
                }
                System.Diagnostics.Process.Start(RestApi.Replace("api/v1", "view") + @"/?streams=" + StreamId);
            });

            GH_DocumentObject.Menu_AppendItem(menu, "(API) View stream data.", (sender, e) =>
            {
                if (StreamId == null)
                {
                    return;
                }
                System.Diagnostics.Process.Start(RestApi + @"/streams/" + StreamId);
            });

            GH_DocumentObject.Menu_AppendItem(menu, "(API) View objects data online.", (sender, e) =>
            {
                if (StreamId == null)
                {
                    return;
                }
                System.Diagnostics.Process.Start(RestApi + @"/streams/" + StreamId + @"/objects?omit=displayValue,base64");
            });

            GH_DocumentObject.Menu_AppendSeparator(menu);
            GH_DocumentObject.Menu_AppendItem(menu, "Save current stream as a version.", (sender, e) =>
            {
                var cloneResult = mySender.StreamCloneAsync(StreamId).Result;
                mySender.Stream.Children.Add(cloneResult.Clone.StreamId);

                mySender.BroadcastMessage(new { eventType = "update-children" });

                System.Windows.MessageBox.Show("Stream version saved. CloneId: " + cloneResult.Clone.StreamId);
            });

            if (mySender.Stream == null)
            {
                return;
            }

            GH_DocumentObject.Menu_AppendSeparator(menu);
            GH_DocumentObject.Menu_AppendItem(menu, "Enable remote control of definition", (sender, e) =>
            {
                EnableRemoteControl = !EnableRemoteControl;
                if (EnableRemoteControl)
                {
                    List <SpeckleInput> speckleInputs   = null;
                    List <SpeckleOutput> speckleOutputs = null;
                    GetSpeckleParams(ref speckleInputs, ref speckleOutputs);

                    DefaultSpeckleInputs  = speckleInputs;
                    DefaultSpeckleOutputs = speckleOutputs;
                }
            }, true, EnableRemoteControl);

            if (EnableRemoteControl)
            {
                GH_DocumentObject.Menu_AppendItem(menu, "Update/Set the default state for the controller stream.", (sender, e) =>
                {
                    SetDefaultState(true);
                    System.Windows.MessageBox.Show("Updated default state.");
                }, true);
            }

            GH_DocumentObject.Menu_AppendSeparator(menu);

            if (mySender.Stream.Parent == null)
            {
                GH_DocumentObject.Menu_AppendItem(menu: menu, text: "This is a parent stream.", enabled: false, click: null);
            }
            else
            {
                GH_DocumentObject.Menu_AppendItem(menu: menu, text: "Parent: " + mySender.Stream.Parent, click: (sender, e) =>
                {
                    System.Windows.Clipboard.SetText(mySender.Stream.Parent);
                    System.Windows.MessageBox.Show("Parent id copied to clipboard. Share away!");
                });
            }
            GH_DocumentObject.Menu_AppendSeparator(menu);


            GH_DocumentObject.Menu_AppendSeparator(menu);
            GH_DocumentObject.Menu_AppendItem(menu, "Children:");
            GH_DocumentObject.Menu_AppendSeparator(menu);

            foreach (string childId in mySender.Stream.Children)
            {
                GH_DocumentObject.Menu_AppendItem(menu, "Child " + childId, (sender, e) =>
                {
                    System.Windows.Clipboard.SetText(childId);
                    System.Windows.MessageBox.Show("Child id copied to clipboard. Share away!");
                });
            }
        }