Beispiel #1
0
        /// <summary>
        /// Clones the stream.
        /// </summary>
        /// <param name="restApi">Server address</param>
        /// <param name="apiToken">API token for account</param>
        /// <param name="streamID">Stream ID of stream to clone</param>
        /// <returns>Stream ID of the clone</returns>
        public static async Task <string> CloneStream(string restApi, string apiToken, string streamID)
        {
            SpeckleApiClient myClient = new SpeckleApiClient()
            {
                BaseUrl = restApi, AuthToken = apiToken
            };

            ResponseStreamClone response = await myClient.StreamCloneAsync(streamID);

            return(response.Clone.StreamId);
        }
Beispiel #2
0
 private void CloneStream(ref int numErrors)
 {
     try
     {
         _ = apiClient.StreamCloneAsync(StreamID).Result;
     }
     catch (Exception ex)
     {
         numErrors++;
         var speckleExceptionContext = ExtractSpeckleExceptionContext(ex);
         var errContext = speckleExceptionContext.Concat(new[] { "Failed to clone", "StreamId=" + StreamID });
         GSA.GsaApp.gsaMessenger.CacheMessage(MessageIntent.TechnicalLog, MessageLevel.Error, ex, errContext.ToArray());
     }
 }
Beispiel #3
0
        /// <summary>
        /// Clones the stream.
        /// </summary>
        /// <param name="restApi">Server address</param>
        /// <param name="apiToken">API token for account</param>
        /// <param name="streamId">Stream ID of stream to clone</param>
        /// <returns>Stream ID of the clone</returns>
        public static async Task <string> CloneStream(string restApi, string apiToken, string streamId, ISpeckleAppMessenger messenger)
        {
            SpeckleApiClient myClient = new SpeckleApiClient()
            {
                BaseUrl = restApi, AuthToken = apiToken
            };

            try
            {
                ResponseStreamClone response = await myClient.StreamCloneAsync(streamId);

                return(response.Clone.StreamId);
            }
            catch (SpeckleException se)
            {
                if (messenger != null)
                {
                    messenger.Message(MessageIntent.Display, MessageLevel.Error, "Unable to clone stream name for " + streamId);
                    var context = new List <string>()
                    {
                        "Unable to clone stream name for " + streamId,
                        "StatusCode=" + se.StatusCode, "ResponseData=" + se.Response, "Message=" + se.Message, "BaseUrl=" + restApi,
                        "Endpoint=StreamCloneAsync"
                    };
                    if (se is SpeckleException <ResponseBase> && ((SpeckleException <ResponseBase>)se).Result != null)
                    {
                        var responseJson = ((SpeckleException <ResponseBase>)se).Result.ToJson();
                        context.Add("ResponseJson=" + responseJson);
                    }
                    messenger.Message(MessageIntent.TechnicalLog, MessageLevel.Error, se, context.ToArray());
                }
            }
            catch (Exception ex)
            {
                if (messenger != null)
                {
                    messenger.Message(MessageIntent.Display, MessageLevel.Error, "Unable to clone stream name for " + streamId);
                    messenger.Message(MessageIntent.TechnicalLog, MessageLevel.Error, ex, "Unable to rename stream", "StreamId=" + streamId, "BaseUrl=" + restApi);
                }
            }
            return("");
        }
Beispiel #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!");
                });
            }
        }
Beispiel #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!");
                });
            }
        }
Beispiel #6
0
        static async Task TestStreams(SpeckleApiClient myClient)
        {
            string streamId       = "lol";
            string secondStreamId = "hai";

            var myPoint = new SpecklePoint()
            {
                Value = new List <double>()
                {
                    1, 2, 3
                }
            };
            var mySecondPoint = new SpecklePoint()
            {
                Value = new List <double>()
                {
                    23, 33, 12
                }
            };
            var myCircle = new SpeckleCircle()
            {
                Radius = 21
            };


            myPoint.Properties = new Dictionary <string, object>();
            myPoint.Properties.Add("Really", mySecondPoint);

            myCircle.Properties = new Dictionary <string, object>();
            myCircle.Properties.Add("a property", "Hello!");
            myCircle.Properties.Add("point", myPoint);

            SpeckleStream myStream = new SpeckleStream()
            {
                Name    = "Hello World My Little Stream",
                Objects = new List <SpeckleObject>()
                {
                    myCircle, myPoint
                }
            };

            SpeckleStream secondStream = new SpeckleStream()
            {
                Name    = "Second Little Stream",
                Objects = new List <SpeckleObject>()
                {
                    myCircle, mySecondPoint
                }
            };

            Console.WriteLine();
            try
            {
                Console.WriteLine("Creating a stream.");
                var Response = await myClient.StreamCreateAsync(myStream);

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

                streamId = Response.Resource.StreamId;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Creating a second stream.");
                var Response = await myClient.StreamCreateAsync(secondStream);

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

                secondStreamId = Response.Resource.StreamId;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


            Console.WriteLine();
            try
            {
                Console.WriteLine("Diffing two streams!");
                var Response = await myClient.StreamDiffAsync(streamId, secondStreamId);

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting a stream.");
                var Response = await myClient.StreamGetAsync(streamId, null);

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting a stream's objects.");
                var Response = await myClient.StreamGetObjectsAsync(streamId, null);

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Updating a stream.");
                var Response = await myClient.StreamUpdateAsync(streamId, new SpeckleStream()
                {
                    Name = "I hate api testing", ViewerLayers = new List <object>()
                    {
                        new { test = "test" }
                    }
                });

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting a stream field.");
                var Response = await myClient.StreamGetAsync(streamId, "fields=viewerLayers,name,owner");

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting all users's streams.");
                var Response = await myClient.StreamsGetAllAsync();

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


            Console.WriteLine();
            try
            {
                Console.WriteLine("Cloning a stream.");
                var Response = await myClient.StreamCloneAsync(streamId);

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

            Console.WriteLine();
            try
            {
                Console.WriteLine("Deleting a stream: " + streamId);
                var Response = await myClient.StreamDeleteAsync(streamId);

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