//Used by the CreateStream node //[IsVisibleInDynamoLibrary(false)] //public static StreamWrapper GetByStreamAndAccountId(string streamId, string accountId) //{ // var account = AccountManager.GetAccounts().FirstOrDefault(x => x.id == accountId); // try // { // return new StreamWrapper(streamId, account.id, account.serverInfo.url); // } // catch (Exception ex) // { // Utils.HandleApiExeption(ex); // } // return null; //} /// <summary> /// Update a Stream details, use is limited to 1 stream at a time /// </summary> /// <param name="stream">Stream object to update</param> /// <param name="name">Name of the Stream</param> /// <param name="description">Description of the Stream</param> /// <param name="isPublic">True if the stream is to be publicly available</param> /// <returns name="stream">Updated Stream object</returns> public static StreamWrapper Update([DefaultArgument("null")] object stream, [DefaultArgument("null")] string name, [DefaultArgument("null")] string description, [DefaultArgument("null")] bool?isPublic) { Tracker.TrackPageview(Tracker.STREAM_UPDATE); if (stream == null) { return(null); } var wrapper = Utils.ParseWrapper(stream); if (wrapper == null) { throw new SpeckleException("Invalid stream."); } if (name == null && description == null && isPublic == null) { return(null); } var account = wrapper.GetAccount().Result; var client = new Client(account); var input = new StreamUpdateInput { id = wrapper.StreamId }; if (name != null) { input.name = name; } if (description != null) { input.description = description; } if (isPublic != null) { input.isPublic = (bool)isPublic; } try { var res = client.StreamUpdate(input).Result; if (res) { return(wrapper); } } catch (Exception ex) { Utils.HandleApiExeption(ex); } return(null); }
/// <summary> /// Update a Stream details, use is limited to 1 stream at a time /// </summary> /// <param name="stream">Stream object to update</param> /// <param name="name">Name of the Stream</param> /// <param name="description">Description of the Stream</param> /// <param name="isPublic">True if the stream is to be publicly available</param> /// <returns name="stream">Updated Stream object</returns> public static StreamWrapper Update(StreamWrapper stream, [DefaultArgument("null")] string name, [DefaultArgument("null")] string description, [DefaultArgument("null")] bool?isPublic) { Tracker.TrackPageview(Tracker.STREAM_UPDATE); if (stream == null) { Core.Logging.Log.CaptureAndThrow(new Exception("Invalid stream.")); } if (name == null && description == null && isPublic == null) { return(null); } var account = stream.GetAccount(); var client = new Client(account); var input = new StreamUpdateInput { id = stream.StreamId }; if (name != null) { input.name = name; } if (description != null) { input.description = description; } if (isPublic != null) { input.isPublic = (bool)isPublic; } try { var res = client.StreamUpdate(input).Result; if (res) { return(stream); } } catch (Exception ex) { Utils.HandleApiExeption(ex); } return(null); }
public async Task SubscribeStreamUpdated() { client.SubscribeStreamUpdated(streamId); client.OnStreamUpdated += Client_OnStreamUpdated;; Thread.Sleep(100); //let server catch-up var streamInput = new StreamUpdateInput { id = streamId, description = "Hello World", name = "Super Stream 01 EDITED" }; var res = await client.StreamUpdate(streamInput); Assert.True(res); await Task.Run(() => { Thread.Sleep(100); //let client catch-up Assert.NotNull(StreamUpdatedInfo); Assert.AreEqual(streamInput.name, StreamUpdatedInfo.name); }); }
protected override void SolveInstance(IGH_DataAccess DA) { DA.DisableGapLogic(); GH_SpeckleStream ghSpeckleStream = null; string name = null; string description = null; bool isPublic = false; if (!DA.GetData(0, ref ghSpeckleStream)) { return; } DA.GetData(1, ref name); DA.GetData(2, ref description); DA.GetData(3, ref isPublic); var streamWrapper = ghSpeckleStream.Value; if (error != null) { Message = null; AddRuntimeMessage(GH_RuntimeMessageLevel.Error, error.Message); error = null; } else if (stream == null) { if (streamWrapper == null) { Message = ""; AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Not a stream wrapper!"); return; } Message = "Fetching"; Task.Run(async() => { var account = streamWrapper.UserId == null ? AccountManager.GetDefaultAccount() : AccountManager.GetAccounts().FirstOrDefault(a => a.userInfo.id == streamWrapper.UserId); if (account == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not find the specified account in this machine. Use the Speckle Manager to add an account, or modify the input stream with your credentials."); return; } var client = new Client(account); var input = new StreamUpdateInput(); try { stream = await client.StreamGet(streamWrapper.StreamId); input.id = streamWrapper.StreamId; input.name = name ?? stream.name; input.description = description ?? stream.description; if (stream.isPublic != isPublic) { input.isPublic = isPublic; } await client.StreamUpdate(input); } catch (Exception e) { error = e; } finally { Rhino.RhinoApp.InvokeOnUiThread((Action) delegate { ExpireSolution(true); }); } }); } else { stream = null; Message = "Done"; DA.SetData(0, streamWrapper.StreamId); } }
protected override void SolveInstance(IGH_DataAccess DA) { DA.DisableGapLogic(); GH_SpeckleStream ghSpeckleStream = null; string name = null; string description = null; bool isPublic = false; if (DA.Iteration == 0) { Tracker.TrackPageview(Tracker.STREAM_UPDATE); } if (!DA.GetData(0, ref ghSpeckleStream)) { return; } DA.GetData(1, ref name); DA.GetData(2, ref description); DA.GetData(3, ref isPublic); var streamWrapper = ghSpeckleStream.Value; if (error != null) { Message = null; AddRuntimeMessage(GH_RuntimeMessageLevel.Error, error.Message); error = null; } else if (stream == null) { if (streamWrapper == null) { Message = ""; AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Not a stream wrapper!"); return; } Message = "Fetching"; Task.Run(async() => { try { var account = streamWrapper.GetAccount().Result; var client = new Client(account); var input = new StreamUpdateInput(); stream = await client.StreamGet(streamWrapper.StreamId); input.id = streamWrapper.StreamId; input.name = name ?? stream.name; input.description = description ?? stream.description; if (stream.isPublic != isPublic) { input.isPublic = isPublic; } await client.StreamUpdate(input); } catch (Exception e) { error = e.InnerException ?? e; } finally { Rhino.RhinoApp.InvokeOnUiThread((Action) delegate { ExpireSolution(true); }); } }); } else { stream = null; Message = "Done"; DA.SetData(0, streamWrapper.StreamId); } }