/// <summary> /// The NewTrace /// </summary> /// <typeparam name="TLinkData"></typeparam> /// <param name="input">The input<see cref="NewTraceInput{TLinkData}"/></param> /// <returns>The <see cref="Task{TraceState{TState, TLinkData}}"/></returns> public async Task <TraceState <TState, TLinkData> > NewTraceAsync <TLinkData>(NewTraceInput <TLinkData> input) { //extract info from input string actionKey = input.ActionKey; TLinkData data = input.Data; string groupLabel = input.GroupLabel; SdkConfig sdkConfig = await this.GetConfigAsync(); string workflowId = sdkConfig.WorkflowId; string configId = sdkConfig.ConfigId; string accountId = sdkConfig.AccountId; string groupId = sdkConfig.GetGroupId(groupLabel); // upload files and transform data await this.UploadFilesInLinkData(data); TraceLinkBuilderConfig <TLinkData> cfg = new TraceLinkBuilderConfig <TLinkData>() { WorkflowId = workflowId, // and workflow config id ConfigId = configId, }; // use a TraceLinkBuilder to create the first link // only provide workflowId to initiate a new trace TraceLinkBuilder <TLinkData> linkBuilder = new TraceLinkBuilder <TLinkData>(cfg); // this is an attestation linkBuilder.ForAttestation(actionKey, data).WithGroup(groupId).WithCreatedBy(accountId); // call createLink helper return(await this.CreateLinkAsync(linkBuilder)); }
/// <summary> /// The AppendLink /// </summary> /// <typeparam name="TLinkData"></typeparam> /// <param name="input">The input<see cref="AppendLinkInput{TLinkData}"/></param> /// <returns>The <see cref="Task{TraceState{TState, TLinkData}}"/></returns> public async Task <TraceState <TState, TLinkData> > AppendLinkAsync <TLinkData>(AppendLinkInput <TLinkData> input) { // retrieve parent link TransferResponseInput <TLinkData> headLinkInput = new TransferResponseInput <TLinkData>(input.TraceId, null); TraceLink <TLinkData> parentLink = await this.GetHeadLinkAsync <TLinkData>(headLinkInput); //extract info from input string actionKey = input.ActionKey; TLinkData data = input.Data; string groupLabel = input.GroupLabel; SdkConfig sdkConfig = await this.GetConfigAsync(); string workflowId = sdkConfig.WorkflowId; string configId = sdkConfig.ConfigId; string accountId = sdkConfig.AccountId; string groupId = sdkConfig.GetGroupId(groupLabel); // upload files and transform data await this.UploadFilesInLinkData(data); TraceLinkBuilderConfig <TLinkData> cfg = new TraceLinkBuilderConfig <TLinkData>() { // provide workflow id WorkflowId = workflowId, // and workflow config id ConfigId = configId, // and parent link to append to the existing trace ParentLink = parentLink }; // use a TraceLinkBuilder to create the first link // only provide workflowId to initiate a new trace TraceLinkBuilder <TLinkData> linkBuilder = new TraceLinkBuilder <TLinkData>(cfg); // this is an attestation linkBuilder.ForAttestation(actionKey, data) .WithGroup(groupId) .WithCreatedBy(accountId); // call createLink helper return(await this.CreateLinkAsync(linkBuilder)); }
public async Task <TraceState <TState, TLinkData> > RejectTransferAsync <TLinkData>(TransferResponseInput <TLinkData> input) { // retrieve parent link TransferResponseInput <TLinkData> headLinkInput = new TransferResponseInput <TLinkData>(input.TraceId, null); TraceLink <TLinkData> parentLink = await this.GetHeadLinkAsync <TLinkData>(headLinkInput); TLinkData data = input.Data; string groupLabel = input.GroupLabel; SdkConfig sdkConfig = await this.GetConfigAsync(); String workflowId = sdkConfig.WorkflowId; string configId = sdkConfig.ConfigId; String accountId = sdkConfig.AccountId; String groupId = sdkConfig.GetGroupId(groupLabel); TraceLinkBuilderConfig <TLinkData> cfg = new TraceLinkBuilderConfig <TLinkData>() { // provide workflow id WorkflowId = workflowId, // and workflow config id ConfigId = configId, // and parent link to append to the existing trace ParentLink = parentLink }; // use a TraceLinkBuilder to create the first link // only provide workflowId to initiate a new trace TraceLinkBuilder <TLinkData> linkBuilder = new TraceLinkBuilder <TLinkData>(cfg); // this is a push transfer linkBuilder.ForRejectTransfer(data) // add group info .WithGroup(groupId) // add creator info .WithCreatedBy(accountId); // call createLink helper return(await this.CreateLinkAsync(linkBuilder)); }
/// <summary> /// Get the traces in a given stage (INCOMING, OUTGOING, BACKLOG, ATTESTATION)T /// When stageType=ATTESTATION, you must also provide the form id to identify the /// stage. If no stage correspond to the stageType x actionKey, it will throw. If /// more than one stage is found it will also throw. /// /// @param stageType the stage type /// @param paginationInfo the pagination info /// @param actionKey (optional) the action key in case of ATTESTATION /// @return the traces in a given stage /// @throws Error /// @throws Exception //// /// </summary> /// <typeparam name="TLinkData"></typeparam> /// <param name="stageType">The stageType<see cref="TraceStageType"/></param> /// <param name="paginationInfo">The paginationInfo<see cref="PaginationInfo"/></param> /// <param name="actionKey">The action key<see cref="String"/></param> /// <returns>The <see cref="Task{TracesState{TState, TLinkData}}"/></returns> public async Task <TracesState <TState, TLinkData> > GetTracesInStageAsync <TLinkData>(TraceStageType stageType, PaginationInfo paginationInfo, String actionKey) { // actionKey can only be set in ATTESTATION case if (stageType == TraceStageType.ATTESTATION && actionKey == null) { throw new Exception("You must and can only provide actionKey when stageType is ATTESTATION"); } // extract info from config SdkConfig sdkConfig = await this.GetConfigAsync(); String groupId = sdkConfig.GetGroupId(); // create variables Dictionary <String, object> variables = new Dictionary <String, object> { { "groupId", groupId }, { "stageType", stageType.ToString() }, }; if (actionKey != null) { variables.Add("actionKey", actionKey); } Dictionary <String, object> variablesPaginationInfo = JsonHelper.ObjectToMap(paginationInfo); variablesPaginationInfo.ToList().ForEach(x => variables.Add(x.Key, x.Value)); // execute the graphql query string query = GraphQL.QUERY_GETTRACESINSTAGE; GraphQLResponse <dynamic> jsonResponse = await this.client.GraphqlAsync(query, variables, null, null); var jsonData = jsonResponse.Data; // extract relevant info from the response var stages = jsonData.group.stages.nodes; // there must be exactly one stage if (stages.Count == 1) { var stage = stages[0]; var trace = stage.traces; // extract traces response and pagination var info = trace.info; int totalCount = trace.totalCount; List <TraceState <TState, TLinkData> > traces = new List <TraceState <TState, TLinkData> >(); // get all the groups that are owned by one of my accounts var nodes = trace.nodes; foreach (var node in nodes) { traces.Add(this.MakeTraceState <TLinkData>((JObject)node)); } TracesState <TState, TLinkData> tracesList = new TracesState <TState, TLinkData>() { Traces = traces, TotalCount = totalCount, Info = nodes.Count >= 1 ? info.ToObject <Info>() : null }; return(tracesList); } // comAdde detail for error String stageDetail = stageType.ToString() + actionKey ?? ""; // throw if no stages were found if if (stages.size() == 0) { throw new Exception("No " + stageDetail + " stage"); } // throw if multiple stages were found throw new throw new Exception("Multiple " + stageDetail + " stages"); }