public static List <StreamWrapper> List([DefaultArgument("null")] Core.Credentials.Account account = null, [DefaultArgument("10")] int limit = 10) { Tracker.TrackPageview(Tracker.STREAM_LIST); if (account == null) { account = AccountManager.GetDefaultAccount(); } if (account == null) { Utils.HandleApiExeption(new Exception("No accounts found. Please use the Speckle Manager to manage your accounts on this computer.")); } var client = new Client(account); var streamWrappers = new List <StreamWrapper>(); try { var res = Task.Run(async() => await client.StreamsGet(limit)).Result; res.ForEach(x => { streamWrappers.Add(new StreamWrapper(x.id, account.userInfo.id, account.serverInfo.url)); }); } catch (Exception ex) { Utils.HandleApiExeption(ex); } return(streamWrappers); }
public static Dictionary <string, object> Details(Core.Credentials.Account account) { Tracker.TrackPageview(Tracker.ACCOUNT_DETAILS); if (account == null) { Utils.HandleApiExeption(new WarningException("Provided account was invalid.")); } return(new Dictionary <string, object> { { "id", account.id }, { "isDefault", account.isDefault }, { "serverInfo", new Dictionary <string, string> { { "name", account.serverInfo.name }, { "company", account.serverInfo.company }, { "url", account.serverInfo.url } } }, { "userInfo", new Dictionary <string, string> { { "id", account.userInfo.id }, { "name", account.userInfo.name }, { "email", account.userInfo.email }, { "company", account.userInfo.company }, } } }); }
public static Dictionary <string, object> Details(Core.Credentials.Account account) { Tracker.TrackPageview(Tracker.ACCOUNT_DETAILS); return(new Dictionary <string, object> { { "id", account.id }, { "isDefault", account.isDefault }, { "serverInfo", new Dictionary <string, string> { { "name", account.serverInfo.name }, { "company", account.serverInfo.company }, { "url", account.serverInfo.url } } }, { "userInfo", new Dictionary <string, string> { { "id", account.userInfo.id }, { "name", account.userInfo.name }, { "email", account.userInfo.email }, { "company", account.userInfo.company }, } } }); }
public static object Get([ArbitraryDimensionArrayImport] object stream, [DefaultArgument("null")] Core.Credentials.Account account) { Tracker.TrackPageview(Tracker.STREAM_GET); var streams = Utils.InputToStream(stream); if (!streams.Any()) { throw new SpeckleException("Please provide one or more Stream Ids."); } else if (streams.Count > 20) { throw new SpeckleException("Please provide less than 20 Stream Ids."); } try { foreach (var s in streams) { //lets ppl override the account for the specified stream Core.Credentials.Account accountToUse = null; if (account != null) { accountToUse = account; } else { accountToUse = Task.Run(async() => await s.GetAccount()).Result; } var client = new Client(accountToUse); //Exists? Core.Api.Stream res = Task.Run(async() => await client.StreamGet(s.StreamId)).Result; s.UserId = accountToUse.userInfo.id; } } catch (Exception ex) { Utils.HandleApiExeption(ex); } if (streams.Count() == 1) { return(streams[0]); } return(streams); }
public static object GetAs([ArbitraryDimensionArrayImport] object stream, Core.Credentials.Account account = null) { Tracker.TrackPageview(Tracker.STREAM_GET); var streams = Utils.InputToStream(stream); if (!streams.Any()) { Log.CaptureAndThrow(new Exception("Please provide one or more Stream Ids.")); } else if (streams.Count > 20) { Log.CaptureAndThrow(new Exception("Please provide less than 20 Stream Ids.")); } try { var client = new Client(account); foreach (var s in streams) { //Exists? Core.Api.Stream res = client.StreamGet(s.StreamId).Result; s.AccountId = account.id; } } catch (Exception e) { if (e.InnerException != null) { if (e.InnerException is HttpRequestException) { throw new Exception("Could not reach the server, is it online?"); } throw e.InnerException; } } if (streams.Count() == 1) { return(streams[0]); } return(streams); }
public static List <StreamWrapper> List([DefaultArgument("null")] Core.Credentials.Account account = null, [DefaultArgument("10")] int limit = 10) { Tracker.TrackPageview(Tracker.STREAM_LIST); if (account == null) { account = AccountManager.GetDefaultAccount(); } var client = new Client(account); var res = client.StreamsGet(limit).Result; var streamWrappers = new List <StreamWrapper>(); res.ForEach(x => { streamWrappers.Add(new StreamWrapper(x.id, account.id, account.serverInfo.url)); }); return(streamWrappers); }
public static Dictionary <string, object> Receive(StreamWrapper stream, CancellationToken cancellationToken, Action <ConcurrentDictionary <string, int> > onProgressAction = null, Action <string, Exception> onErrorAction = null, Action <int> onTotalChildrenCountKnown = null) { Core.Credentials.Account account = stream.GetAccount(); stream.BranchName = string.IsNullOrEmpty(stream.BranchName) ? "main" : stream.BranchName; var client = new Client(account); Commit commit = null; if (string.IsNullOrEmpty(stream.CommitId)) { var res = client.StreamGet(cancellationToken, stream.StreamId).Result; var mainBranch = res.branches.items.FirstOrDefault(b => b.name == stream.BranchName); if (mainBranch == null) { Log.CaptureAndThrow(new Exception("No branch found with name " + stream.BranchName)); } if (!mainBranch.commits.items.Any()) { throw new Exception("No commits found."); } commit = mainBranch.commits.items[0]; } else { commit = client.CommitGet(cancellationToken, stream.StreamId, stream.CommitId).Result; } if (commit == null) { throw new Exception("Could not get commit."); } if (cancellationToken.IsCancellationRequested) { return(null); } var transport = new ServerTransport(account, stream.StreamId); var @base = Operations.Receive( commit.referencedObject, cancellationToken, remoteTransport: transport, onProgressAction: onProgressAction, onErrorAction: onErrorAction, onTotalChildrenCountKnown: onTotalChildrenCountKnown ).Result; if (cancellationToken.IsCancellationRequested) { return(null); } var converter = new BatchConverter(); var data = converter.ConvertRecursivelyToNative(@base); return(new Dictionary <string, object> { { "data", data }, { "commit", commit } }); }
/// <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); } Core.Credentials.Account account = null; try { account = Task.Run(async() => await wrapper.GetAccount()).Result; } catch (Exception e) { throw e.InnerException ?? e; } 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 = Task.Run(async() => await client.StreamUpdate(input)).Result; if (res) { return(wrapper); } } catch (Exception ex) { Utils.HandleApiExeption(ex); } return(null); }
public static object GetWithAccount([ArbitraryDimensionArrayImport] object stream, Core.Credentials.Account account = null) { Tracker.TrackPageview(Tracker.STREAM_GET); var streams = Utils.InputToStream(stream); if (!streams.Any()) { Log.CaptureAndThrow(new Exception("Please provide one or more Stream Ids.")); } else if (streams.Count > 20) { Log.CaptureAndThrow(new Exception("Please provide less than 20 Stream Ids.")); } try { var client = new Client(account); foreach (var s in streams) { //Exists? Core.Api.Stream res = client.StreamGet(s.StreamId).Result; s.AccountId = account.id; } } catch (Exception ex) { Utils.HandleApiExeption(ex); } if (streams.Count() == 1) { return(streams[0]); } return(streams); }