/// <summary> /// Subscribe to events of streams updated for a specific streamId /// </summary> /// <param name="id">streamId</param> public void SubscribeStreamUpdated(string id) { try { var request = new GraphQLRequest { Query = $@"subscription {{ streamUpdated( streamId: ""{id}"") }}", }; var res = GQLClient.CreateSubscriptionStream <StreamUpdatedResult>(request); StreamUpdatedSubscription = res.Subscribe(response => { if (response.Errors != null) { throw new SpeckleException("Could not subscribe to streamUpdated", response.Errors); } if (response.Data != null) { OnStreamUpdated(this, response.Data.streamUpdated); } }); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Subscribe to events of commit created for a stream /// </summary> /// <returns></returns> public void SubscribeCommitCreated(string streamId) { try { var request = new GraphQLRequest { Query = $@"subscription {{ commitCreated (streamId: ""{streamId}"") }}" }; var res = GQLClient.CreateSubscriptionStream <CommitCreatedResult>(request); CommitCreatedSubscription = res.Subscribe(response => { if (response.Errors != null) { throw new SpeckleException("Could not subscribe to commitCreated", response.Errors); } if (response.Data != null) { OnCommitCreated?.Invoke(this, response.Data.commitCreated); } }); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Subscribe to events of streams added for the current user /// </summary> /// <returns></returns> public void SubscribeUserStreamAdded() { try { var request = new GraphQLRequest { Query = @"subscription { userStreamAdded }" }; var res = GQLClient.CreateSubscriptionStream <UserStreamAddedResult>(request); UserStreamAddedSubscription = res.Subscribe(response => { if (response.Errors != null) { throw new SpeckleException("Could not subscribe to userStreamAdded", response.Errors); } if (response.Data != null) { OnUserStreamAdded(this, response.Data.userStreamAdded); } }); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Subscribe to events of commit updated for a stream /// </summary> /// <returns></returns> public void SubscribeCommitUpdated(string streamId, string commitId = null) { try { var request = new GraphQLRequest { Query = $@"subscription {{ commitUpdated (streamId: ""{streamId}"", commitId: ""{commitId}"") }}" }; var res = GQLClient.CreateSubscriptionStream <CommitUpdatedResult>(request); CommitUpdatedSubscription = res.Subscribe(response => { if (response.Errors != null) { Log.CaptureAndThrow(new GraphQLException("Could not subscribe to commitUpdated"), response.Errors); } if (response.Data != null) { OnCommitUpdated(this, response.Data.commitUpdated); } }); } catch (Exception e) { Log.CaptureException(e); throw e; } }
/// <summary> /// Subscribe to events of streams removed for the current user /// </summary> /// <param name="id"></param> public void SubscribeUserStreamRemoved() { try { var request = new GraphQLRequest { Query = $@"subscription {{ userStreamRemoved }}", }; var res = GQLClient.CreateSubscriptionStream <UserStreamRemovedResult>(request); UserStreamRemovedSubscription = res.Subscribe(response => { if (response.Errors != null) { Log.CaptureAndThrow(new GraphQLException("Could not subscribe to userStreamRemoved"), response.Errors); } if (response.Data != null) { OnUserStreamRemoved(this, response.Data.userStreamRemoved); } }); } catch (Exception e) { Log.CaptureException(e); throw e; } }
/// <summary> /// Revokes permissions of a user on a given stream. /// </summary> /// <param name="streamId">Id of the stream to revoke permissions from</param> /// <param name="userId">Id of the user to revoke permissions from</param> /// <returns></returns> public async Task <bool> StreamRevokePermission(CancellationToken cancellationToken, StreamRevokePermissionInput permissionInput) { try { var request = new GraphQLRequest { Query = @"mutation streamRevokePermission($permissionParams: StreamRevokePermissionInput!) { streamRevokePermission(permissionParams: $permissionParams) }", Variables = new { permissionParams = permissionInput } }; var res = await GQLClient.SendMutationAsync <Dictionary <string, object> >(request).ConfigureAwait(false); if (res.Errors != null) { throw new SpeckleException("Could not revoke permission", res.Errors); } return((bool)res.Data["streamRevokePermission"]); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Creates a stream. /// </summary> /// <param name="streamInput"></param> /// <returns>The stream's id.</returns> public async Task <string> StreamCreate(CancellationToken cancellationToken, StreamCreateInput streamInput) { try { var request = new GraphQLRequest { Query = @"mutation streamCreate($myStream: StreamCreateInput!) { streamCreate(stream: $myStream) }", Variables = new { myStream = streamInput } }; var res = await GQLClient.SendMutationAsync <Dictionary <string, object> >(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null) { throw new SpeckleException("Could not create stream", res.Errors); } return((string)res.Data["streamCreate"]); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Deletes a stream. /// </summary> /// <param name="id">Id of the stream to be deleted</param> /// <returns></returns> public async Task <bool> StreamDelete(CancellationToken cancellationToken, string id) { try { var request = new GraphQLRequest { Query = @"mutation streamDelete($id: String!) { streamDelete(id:$id) }", Variables = new { id } }; var res = await GQLClient.SendMutationAsync <Dictionary <string, object> >(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null) { throw new SpeckleException("Could not delete stream", res.Errors); } return((bool)res.Data["streamDelete"]); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Subscribe to events of branch updated for a stream /// </summary> /// <returns></returns> public void SubscribeBranchUpdated(string streamId, string branchId = null) { try { var request = new GraphQLRequest { Query = $@"subscription {{ branchUpdated (streamId: ""{streamId}"", branchId: ""{branchId}"") }}" }; var res = GQLClient.CreateSubscriptionStream <BranchUpdatedResult>(request); BranchUpdatedSubscription = res.Subscribe(response => { if (response.Errors != null) { throw new SpeckleException("Could not subscribe to branchUpdated", response.Errors); } if (response.Data != null) { OnBranchUpdated(this, response.Data.branchUpdated); } }); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Gets the current user. /// </summary> /// <returns></returns> public async Task <User> UserGet(CancellationToken cancellationToken) { try { var request = new GraphQLRequest { Query = @"query User { user{ id, email, name, bio, company, avatar, verified, profiles, role, } }" }; var res = await GQLClient.SendMutationAsync <UserData>(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null && res.Errors.Any()) { throw new SpeckleException(res.Errors[0].Message, res.Errors); } return(res.Data.user); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Creates a branch on a stream. /// </summary> /// <param name="branchInput"></param> /// <returns>The stream's id.</returns> public async Task <string> BranchCreate(CancellationToken cancellationToken, BranchCreateInput branchInput) { try { var request = new GraphQLRequest { Query = @"mutation branchCreate($myBranch: BranchCreateInput!){ branchCreate(branch: $myBranch)}", Variables = new { myBranch = branchInput } }; var res = await GQLClient.SendMutationAsync <Dictionary <string, object> >(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null) { Log.CaptureAndThrow(new GraphQLException("Could not create branch"), res.Errors); } return((string)res.Data["branchCreate"]); } catch (Exception e) { Log.CaptureException(e); throw e; } }
/// <summary> /// Creates a commit on a branch. /// </summary> /// <param name="commitInput"></param> /// <returns>The commit id.</returns> public async Task <string> CommitCreate(CancellationToken cancellationToken, CommitCreateInput commitInput) { try { var request = new GraphQLRequest { Query = @"mutation commitCreate($myCommit: CommitCreateInput!){ commitCreate(commit: $myCommit)}", Variables = new { myCommit = commitInput } }; var res = await GQLClient.SendMutationAsync <Dictionary <string, object> >(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null && res.Errors.Any()) { throw new SpeckleException(res.Errors[0].Message, res.Errors); } return((string)res.Data["commitCreate"]); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Updates a stream. /// </summary> /// <param name="streamInput">Note: the id field needs to be a valid stream id.</param> /// <returns>The stream's id.</returns> public async Task <bool> StreamUpdate(CancellationToken cancellationToken, StreamUpdateInput streamInput) { try { var request = new GraphQLRequest { Query = @"mutation streamUpdate($myStream: StreamUpdateInput!) { streamUpdate(stream:$myStream) }", Variables = new { myStream = streamInput } }; var res = await GQLClient.SendMutationAsync <Dictionary <string, object> >(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null) { Log.CaptureAndThrow(new GraphQLException("Could not update stream"), res.Errors); } return((bool)res.Data["streamUpdate"]); } catch (Exception e) { Log.CaptureException(e); throw e; } }
/// <summary> /// Deletes a stream. /// </summary> /// <param name="branchInput"></param> /// <returns></returns> public async Task <bool> BranchDelete(CancellationToken cancellationToken, BranchDeleteInput branchInput) { try { var request = new GraphQLRequest { Query = @"mutation branchDelete($myBranch: BranchDeleteInput!){ branchDelete(branch: $myBranch)}", Variables = new { myBranch = branchInput } }; var res = await GQLClient.SendMutationAsync <Dictionary <string, object> >(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null) { throw new SpeckleException("Could not delete branch", res.Errors); } return((bool)res.Data["branchDelete"]); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Gets a given object from a stream. /// </summary> /// <param name="cancellationToken"></param> /// <param name="streamId"></param> /// <param name="objectId"></param> /// <returns></returns> public async Task <Object> ObjectCountGet(CancellationToken cancellationToken, string streamId, string objectId) { try { var request = new GraphQLRequest { Query = $@"query Stream($streamId: String!, $objectId: String!) {{ stream(id: $streamId) {{ object(id: $objectId){{ totalChildrenCount }} }} }}", Variables = new { streamId, objectId } }; var res = await GQLClient.SendQueryAsync <StreamData>(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null && res.Errors.Any()) { throw new SpeckleException(res.Errors[0].Message, res.Errors); } return(res.Data.stream.@object); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Gets a stream by id including basic branch info (id, name, description, and total commit count). /// For detailed commit and branch info, use StreamGetCommits and StreamGetBranches respectively. /// </summary> /// <param name="id">Id of the stream to get</param> /// <param name="branchesLimit">Max number of branches to retrieve</param> /// <returns></returns> public async Task <Stream> StreamGet(CancellationToken cancellationToken, string id, int branchesLimit = 10) { try { var request = new GraphQLRequest { Query = $@"query Stream($id: String!) {{ stream(id: $id) {{ id name description isPublic role createdAt updatedAt collaborators {{ id name role avatar }}, branches (limit: {branchesLimit}){{ totalCount, cursor, items {{ id, name, description, commits {{ totalCount }} }} }} }} }}", Variables = new { id } }; var res = await GQLClient.SendMutationAsync <StreamData>(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null) { throw new SpeckleException("Could not get stream", res.Errors); } return(res.Data.stream); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Gets all streams for the current user /// </summary> /// <param name="limit">Max number of streams to return</param> /// <returns></returns> public async Task <List <Stream> > StreamsGet(CancellationToken cancellationToken, int limit = 10) { try { var request = new GraphQLRequest { Query = $@"query User {{ user{{ id, email, name, bio, company, avatar, verified, profiles, role, streams(limit:{limit}) {{ totalCount, cursor, items {{ id, name, description, isPublic, role, createdAt, updatedAt, collaborators {{ id, name, role, avatar }} }} }} }} }}" }; var res = await GQLClient.SendMutationAsync <UserData>(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null) { throw new SpeckleException("Could not get streams", res.Errors); } return(res.Data.user.streams.items); } catch (Exception e) { throw new SpeckleException(e.Message, e); } }
/// <summary> /// Gets a given branch from a stream. /// </summary> /// <param name="cancellationToken"></param> /// <param name="streamId">Id of the stream to get the branch from</param> /// <param name="branchName">Name of the branch to get</param> /// <returns></returns> public async Task <Branch> BranchGet(CancellationToken cancellationToken, string streamId, string branchName, int commitsLimit = 10) { try { var request = new GraphQLRequest { Query = $@"query Stream($streamId: String!, $branchName: String!) {{ stream(id: $streamId) {{ branch(name: $branchName){{ id, name, description, commits (limit: {commitsLimit}) {{ totalCount, cursor, items {{ id, referencedObject, sourceApplication, totalChildrenCount, message, authorName, authorId, branchName, parents, createdAt }} }} }} }} }}", Variables = new { streamId, branchName } }; var res = await GQLClient.SendMutationAsync <StreamData>(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null && res.Errors.Any()) { Log.CaptureAndThrow(new GraphQLException(res.Errors[0].Message), res.Errors); } return(res.Data.stream.branch); } catch (Exception e) { Log.CaptureException(e); throw e; } }
/// <summary> /// Get branches from a given stream /// </summary> /// <param name="cancellationToken"></param> /// <param name="streamId">Id of the stream to get the branches from</param> /// <param name="branchesLimit">Max number of branches to retrieve</param> /// <param name="commitsLimit">Max number of commits to retrieve</param> /// <returns></returns> /// <exception cref="Exception"></exception> public async Task <List <Branch> > StreamGetBranches(CancellationToken cancellationToken, string streamId, int branchesLimit = 10, int commitsLimit = 10) { try { var request = new GraphQLRequest { Query = $@"query Stream ($streamId: String!) {{ stream(id: $streamId) {{ branches(limit: {branchesLimit}) {{ items {{ id name description commits (limit: {commitsLimit}) {{ totalCount cursor items {{ id referencedObject sourceApplication message authorName authorId branchName parents createdAt }} }} }} }} }} }}", Variables = new { streamId } }; var res = await GQLClient.SendMutationAsync <StreamData>(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null && res.Errors.Any()) { Log.CaptureAndThrow(new GraphQLException(res.Errors[0].Message), res.Errors); } return(res.Data.stream.branches.items); } catch (Exception e) { Log.CaptureException(e); throw e; } }
/// <summary> /// Searches the user's streams by name, description, and ID /// </summary> /// <param name="query">String query to search for</param> /// <param name="limit">Max number of streams to return</param> /// <returns></returns> public async Task <List <Stream> > StreamSearch(CancellationToken cancellationToken, string query, int limit = 10) { try { var request = new GraphQLRequest { Query = @"query Streams ($query: String!, $limit: Int!) { streams(query: $query, limit: $limit) { totalCount, cursor, items { id, name, description, isPublic, role, createdAt, updatedAt, collaborators { id, name, role } } } }", Variables = new { query, limit } }; var res = await GQLClient.SendMutationAsync <StreamsData>(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null) { Log.CaptureAndThrow(new GraphQLException("Could not search streams"), res.Errors); } return(res.Data.streams.items); } catch (Exception e) { Log.CaptureException(e); throw e; } }
/// <summary> /// Gets the latest commits from a stream /// </summary> /// <param name="cancellationToken"></param> /// <param name="streamId">Id of the stream to get the commits from</param> /// <param name="limit">Max number of commits to get</param> /// <returns></returns> /// <exception cref="Exception"></exception> public async Task <List <Commit> > StreamGetCommits(CancellationToken cancellationToken, string streamId, int limit = 10) { try { var request = new GraphQLRequest { Query = @"query Stream($streamId: String!, $limit: Int!) { stream(id: $streamId) { commits(limit: $limit) { items { id, message, branchName, sourceApplication, totalChildrenCount, referencedObject, createdAt, parents, authorName, authorId, authorAvatar } } } }", Variables = new { streamId, limit } }; var res = await GQLClient.SendMutationAsync <StreamData>(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null && res.Errors.Any()) { Log.CaptureAndThrow(new GraphQLException(res.Errors[0].Message), res.Errors); } return(res.Data.stream.commits.items); } catch (Exception e) { Log.CaptureException(e); throw e; } }
/// <summary> /// Gets a given commit from a stream. /// </summary> /// <param name="cancellationToken"></param> /// <param name="streamId">Id of the stream to get the commit from</param> /// <param name="commitId">Id of the commit to get</param> /// <returns></returns> public async Task <Commit> CommitGet(CancellationToken cancellationToken, string streamId, string commitId) { try { var request = new GraphQLRequest { Query = $@"query Stream($streamId: String!, $commitId: String!) {{ stream(id: $streamId) {{ commit(id: $commitId){{ id, message, sourceApplication, totalChildrenCount, referencedObject, branchName, createdAt, parents, authorName }} }} }}", Variables = new { streamId, commitId } }; var res = await GQLClient.SendMutationAsync <StreamData>(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null && res.Errors.Any()) { Log.CaptureAndThrow(new GraphQLException(res.Errors[0].Message), res.Errors); } return(res.Data.stream.commit); } catch (Exception e) { Log.CaptureException(e); throw e; } }
/// <summary> /// Searches for a user on the server. /// </summary> /// <param name="query">String to search for. Must be at least 3 characters</param> /// <param name="limit">Max number of users to return</param> /// <returns></returns> public async Task <List <User> > UserSearch(CancellationToken cancellationToken, string query, int limit = 10) { try { var request = new GraphQLRequest { Query = @"query UserSearch($query: String!, $limit: Int!) { userSearch(query: $query, limit: $limit) { cursor, items { id name bio company avatar verified } } }", Variables = new { query, limit } }; var res = await GQLClient.SendMutationAsync <UserSearchData>(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null && res.Errors.Any()) { Log.CaptureAndThrow(new GraphQLException(res.Errors[0].Message), res.Errors); } return(res.Data.userSearch.items); } catch (Exception e) { Log.CaptureException(e); throw e; } }
/// <summary> /// Gets a stream by id, includes commits and branches /// </summary> /// <param name="id">Id of the stream to get</param> /// <param name="branchesLimit">Max number of branches to retrieve</param> /// <param name="commitsLimit">Max number of commits per branch to retrieve</param> /// <returns></returns> public async Task <Stream> StreamGet(CancellationToken cancellationToken, string id, int branchesLimit = 10, int commitsLimit = 10) { try { var request = new GraphQLRequest { Query = $@"query Stream($id: String!) {{ stream(id: $id) {{ id name description isPublic createdAt updatedAt collaborators {{ id name role }}, branches (limit: {branchesLimit}){{ totalCount, cursor, items {{ id, name, description, commits (limit: {commitsLimit}) {{ totalCount, cursor, items {{ id, referencedObject, message, authorName, authorId, createdAt }} }} }} }} }} }}", Variables = new { id } }; var res = await GQLClient.SendMutationAsync <StreamData>(request, cancellationToken).ConfigureAwait(false); if (res.Errors != null) { Log.CaptureAndThrow(new GraphQLException("Could not get stream"), res.Errors); } return(res.Data.stream); } catch (Exception e) { Log.CaptureException(e); throw e; } }