private void configureHistory(Dictionary <string, object> config = null) { ResponseStreamClone response = null; Task <ResponseStreamClone> respStreamClTask = null; object enableHistoryObj = null; if (config != null) { config.TryGetValue("EnableHistory", out enableHistoryObj); } bool?enableHistory = enableHistoryObj as bool?; if (enableHistory != null && !(bool)enableHistory) { return; } // The following line creates a new stream (with a different StreamId), where the current stream content is copied, before it gets modified. // The streamId of the cloned "backup" is saved among the main Stream "children" field, // accessible through SpeckleServerAddress/api/v1/streams/streamId respStreamClTask = SpeckleClient.StreamCloneAsync(SpeckleStreamId); try { response = respStreamClTask?.Result; } catch (Exception e) { } if (response == null) { BH.Engine.Reflection.Compute.RecordWarning($"Could not set the EnableHistory option. Task status: {respStreamClTask.Status.ToString()}"); } }
private void SetupHistory() { ResponseStreamClone cloneResult = null; Task <ResponseStreamClone> respStreamClTask = null; // The following line creates a new stream (with a different StreamId), where the current stream content is copied, before it gets modified. // The streamId of the cloned "backup" is saved among the main Stream "children" field, // accessible through SpeckleServerAddress/api/v1/streams/streamId respStreamClTask = SpeckleClient.StreamCloneAsync(SpeckleClient.Stream.StreamId); try { cloneResult = respStreamClTask?.Result; SpeckleClient.Stream.Children = cloneResult.Parent.Children; } catch (Exception e) { BH.Engine.Reflection.Compute.RecordWarning($"Failed configuring Speckle History. Error: {e.InnerException}"); } if (cloneResult == null) { BH.Engine.Reflection.Compute.RecordWarning($"Failed configuring Speckle History. Task status: {respStreamClTask.Status.ToString()}"); } }
/// <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); }
/// <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(""); }