public void TestGetSessionFromDriverWithSessionReturnedToPool()
        {
            var sendCommandResponseWithStartSession = new SendCommandResponse
            {
                StartSession = new StartSessionResult
                {
                    SessionToken = "testToken"
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };
            var sendCommandResponseEmpty = new SendCommandResponse();

            mockClient.SetupSequence(x => x.SendCommandAsync(It.IsAny <SendCommandRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(sendCommandResponseWithStartSession))
            .Returns(Task.FromResult(sendCommandResponseEmpty));
            builder = PooledQldbDriver.Builder().WithLedger("testLedger");

            var driver  = new PooledQldbDriver("ledgerName", mockClient.Object, 4, 4, 4, NullLogger.Instance);
            var session = driver.GetSession();

            session.Dispose();
            session = driver.GetSession();
            Assert.IsNotNull(session);
            // Once for start session, once for abort. Second will throw exception if start session due to empty response.
            mockClient.Verify(x => x.SendCommandAsync(It.IsAny <SendCommandRequest>(), It.IsAny <CancellationToken>()),
                              Times.Exactly(2));
        }
Beispiel #2
0
        public void TestExecuteStatementReturnsResponse()
        {
            var testExecuteStatementResult = new ExecuteStatementResult
            {
                FirstPage = new Page()
            };
            var testExecuteStatementResponse = new SendCommandResponse
            {
                ExecuteStatement = testExecuteStatementResult
            };

            SetResponse(testExecuteStatementResponse);

            IValueFactory valueFactory = new ValueFactory();
            var           parameters   = new List <IIonValue>
            {
                valueFactory.NewString("param1"),
                valueFactory.NewString("param2")
            };

            var executeResultParams = session.ExecuteStatement("txnId", "statement", parameters);

            Assert.AreEqual(testExecuteStatementResult, executeResultParams);

            var executeResultEmptyParams = session.ExecuteStatement("txnId", "statement", new List <IIonValue>());

            Assert.AreEqual(testExecuteStatementResult, executeResultEmptyParams);
        }
        public void SetupTest()
        {
            mockClient = new Mock <AmazonQLDBSessionClient>();
            var sendCommandResponse = new SendCommandResponse
            {
                StartSession = new StartSessionResult
                {
                    SessionToken = "testToken"
                },
                StartTransaction = new StartTransactionResult
                {
                    TransactionId = "testTransactionIdddddd"
                },
                ExecuteStatement = new ExecuteStatementResult
                {
                    FirstPage = new Page
                    {
                        NextPageToken = null,
                        Values        = new List <ValueHolder>()
                    }
                },
                CommitTransaction = new CommitTransactionResult
                {
                    CommitDigest = new MemoryStream(digest)
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };

            mockClient.Setup(x => x.SendCommandAsync(It.IsAny <SendCommandRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(sendCommandResponse));
            builder = PooledQldbDriver.Builder().WithLedger("testLedger");
        }
Beispiel #4
0
#pragma warning disable IDE0060 // Remove unused parameter
        public static void Setup(TestContext context)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            var sendCommandResponse = new SendCommandResponse
            {
                StartSession = new StartSessionResult
                {
                    SessionToken = "testToken"
                },
                StartTransaction = new StartTransactionResult
                {
                    TransactionId = "testTransactionIdddddd"
                },
                ExecuteStatement = new ExecuteStatementResult
                {
                    FirstPage = new Page
                    {
                        NextPageToken = null,
                        Values        = new List <ValueHolder>()
                    }
                },
                CommitTransaction = new CommitTransactionResult
                {
                    CommitDigest = new MemoryStream(digest)
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };

            mockClient.Setup(x => x.SendCommandAsync(It.IsAny <SendCommandRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(sendCommandResponse));
        }
        internal void QueueResponse(SendCommandResponse response)
        {
            Output output = new Output
            {
                exception = null,
                response  = response
            };

            this.responses.Enqueue(output);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            SendCommandResponse response = new SendCommandResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("AbortTransaction", targetDepth))
                {
                    var unmarshaller = AbortTransactionResultUnmarshaller.Instance;
                    response.AbortTransaction = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("CommitTransaction", targetDepth))
                {
                    var unmarshaller = CommitTransactionResultUnmarshaller.Instance;
                    response.CommitTransaction = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("EndSession", targetDepth))
                {
                    var unmarshaller = EndSessionResultUnmarshaller.Instance;
                    response.EndSession = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ExecuteStatement", targetDepth))
                {
                    var unmarshaller = ExecuteStatementResultUnmarshaller.Instance;
                    response.ExecuteStatement = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("FetchPage", targetDepth))
                {
                    var unmarshaller = FetchPageResultUnmarshaller.Instance;
                    response.FetchPage = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("StartSession", targetDepth))
                {
                    var unmarshaller = StartSessionResultUnmarshaller.Instance;
                    response.StartSession = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("StartTransaction", targetDepth))
                {
                    var unmarshaller = StartTransactionResultUnmarshaller.Instance;
                    response.StartTransaction = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
 internal MockSessionClient()
 {
     this.responses       = new Queue <Output>();
     this.defaultResponse = new SendCommandResponse
     {
         StartSession      = new StartSessionResult(),
         StartTransaction  = new StartTransactionResult(),
         ExecuteStatement  = new ExecuteStatementResult(),
         CommitTransaction = new CommitTransactionResult(),
         ResponseMetadata  = new ResponseMetadata()
     };
 }
Beispiel #8
0
        public void TestAbortTransactionReturnsResponse()
        {
            var testAbortTransactionResult   = new AbortTransactionResult();
            var testAbortTransactionResponse = new SendCommandResponse
            {
                AbortTransaction = testAbortTransactionResult
            };

            SetResponse(testAbortTransactionResponse);

            Assert.AreEqual(testAbortTransactionResult, session.AbortTransaction());
        }
Beispiel #9
0
        public void TestEndSessionReturnsResponse()
        {
            var testEndSessionResult   = new EndSessionResult();
            var testEndSessionResponse = new SendCommandResponse
            {
                EndSession = testEndSessionResult
            };

            SetResponse(testEndSessionResponse);

            Assert.AreEqual(testEndSessionResult, session.EndSession());
        }
Beispiel #10
0
        public void TestStartTransactionReturnsResponse()
        {
            var testStartTransactionResult = new StartTransactionResult
            {
                TransactionId = "testTxnIdddddddddddddd"
            };
            var testStartTransactionResponse = new SendCommandResponse
            {
                StartTransaction = testStartTransactionResult
            };

            SetResponse(testStartTransactionResponse);

            Assert.AreEqual(testStartTransactionResult, session.StartTransaction());
        }
Beispiel #11
0
        public void TestFetchPageReturnsResponse()
        {
            var testFetchPageResult = new FetchPageResult
            {
                Page = new Page()
            };
            var testFetchPageResponse = new SendCommandResponse
            {
                FetchPage = testFetchPageResult
            };

            SetResponse(testFetchPageResponse);

            Assert.AreEqual(testFetchPageResult, session.FetchPage("txnId", "nextPageToken"));
        }
Beispiel #12
0
        public async Task <IEnumerable <string> > EnumerateAsync(CancellationToken cancel)
        {
            SendCommandResponse response = await SendCommandAsync(null, "enumerate", null, cancel).ConfigureAwait(false);

            JArray jarr = response.ParseToJToken() as JArray;

            var hwis = new List <string>();

            foreach (JObject json in jarr)
            {
                string jsonString = json.ToString();
                hwis.Add(jsonString);
            }

            return(hwis);
        }
Beispiel #13
0
        public void TestCommitTransactionReturnsResponse()
        {
            var testCommitTransactionResult = new CommitTransactionResult
            {
                TransactionId = "testTxnIdddddddddddddd",
                CommitDigest  = new MemoryStream()
            };
            var testCommitTransactionResponse = new SendCommandResponse
            {
                CommitTransaction = testCommitTransactionResult
            };

            SetResponse(testCommitTransactionResponse);

            Assert.AreEqual(testCommitTransactionResult, session.CommitTransaction("txnId", new MemoryStream()));
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            SendCommandResponse response = new SendCommandResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Command", targetDepth))
                {
                    var unmarshaller = CommandUnmarshaller.Instance;
                    response.Command = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Beispiel #15
0
#pragma warning disable IDE0060 // Remove unused parameter
        public static void Setup(TestContext context)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            var testStartSessionResponse = new SendCommandResponse
            {
                StartSession = new StartSessionResult
                {
                    SessionToken = "testSessionToken"
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };

            SetResponse(testStartSessionResponse);

            session = Session.StartSession("testLedgerName", mockClient.Object, NullLogger.Instance);
        }
        public JObject FunctionHandler(JObject input)
        {
            Amazon.Runtime.BasicAWSCredentials  credentials = new Amazon.Runtime.BasicAWSCredentials(Environment.GetEnvironmentVariable("AD_AccessKey"), Environment.GetEnvironmentVariable("AD_SecretKey"));
            AmazonSimpleSystemsManagementClient client      = new AmazonSimpleSystemsManagementClient(credentials, Amazon.RegionEndpoint.APSoutheast2);

            string username  = input.SelectToken("EventData.username").ToString();
            string accountId = input.SelectToken("CreateAccountResponse.CreateAccountStatus.AccountId").ToString();
            string roleName  = input.SelectToken("EventData.roleName").ToString();
            string groupName = roleName.Split("-")[0] + "-" + accountId + "-" + roleName.Split("-")[1];
            string groupPath = Environment.GetEnvironmentVariable("AD_SandboxOU");
            string type      = input.SelectToken("EventData.type").ToString();

            if (type == "production")
            {
                groupPath = Environment.GetEnvironmentVariable("AD_ProdOU");
            }

            Dictionary <string, List <string> > ParametersData = new Dictionary <string, List <string> >();

            ParametersData.Add("commands", new List <string> {
                string.Format("New-ADGroup -Name \"{0}\" -SamAccountName {0} -GroupCategory Security -GroupScope Global -DisplayName \"{0}\" -Path \"{1}\" -Description \"AWS Account Group\"", groupName, groupPath),
                string.Format("Add-ADGroupMember -Identity {0} -Members {1}", groupName, username)
            });

            SendCommandRequest request = new SendCommandRequest()
            {
                DocumentName = "AWS-RunPowerShellScript",
                InstanceIds  = new List <string> {
                    Environment.GetEnvironmentVariable("AD_InstanceId")
                },
                Parameters = ParametersData
            };

            SendCommandResponse response = client.SendCommandAsync(request).Result;

            return(input);
        }
Beispiel #17
0
        public async Task <Version> GetVersionAsync(CancellationToken cancel)
        {
            SendCommandResponse response = await SendCommandAsync("--version", null, null, cancel).ConfigureAwait(false);

            string responseString = response.ResponseString;

            // Example output: hwi 1.0.0
            var vTry1 = responseString.Substring(responseString.IndexOf("hwi") + 3).Trim();

            if (Version.TryParse(vTry1, out Version v1))
            {
                return(v1);
            }

            // Example output: hwi.exe 1.0.0
            var vTry2 = responseString.Substring(responseString.IndexOf("hwi.exe") + 7).Trim();

            if (Version.TryParse(vTry2, out Version v2))
            {
                return(v2);
            }

            throw new FormatException($"Cannot parse version from HWI's response. Response: {response}");
        }
        public async Task Execute_ExceptionOnExecute_ShouldOnlyRetryOnISEAndTAOE(Exception exception, bool expectThrow)
        {
            var statement = "DELETE FROM table;";
            var h1        = QldbHash.ToQldbHash(TestTransactionId);

            h1 = Transaction.Dot(h1, statement, new List <IIonValue> {
            });

            var sendCommandResponseWithStartSession = new SendCommandResponse
            {
                StartTransaction = new StartTransactionResult
                {
                    TransactionId = TestTransactionId
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };

            var sendCommandResponseExecute = new SendCommandResponse
            {
                ExecuteStatement = new ExecuteStatementResult
                {
                    FirstPage = new Page
                    {
                        NextPageToken = null
                    }
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };

            var sendCommandResponseCommit = new SendCommandResponse
            {
                CommitTransaction = new CommitTransactionResult
                {
                    TransactionId = TestTransactionId,
                    CommitDigest  = new MemoryStream(h1.Hash),
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };
            var mockCreator = new Mock <Func <Task <Session> > >();
            var mockSession = new Mock <Session>(null, null, null, null, null);

            mockSession.Setup(x => x.StartTransaction(It.IsAny <CancellationToken>())).ReturnsAsync(sendCommandResponseWithStartSession.StartTransaction);
            mockSession.SetupSequence(x => x.ExecuteStatement(It.IsAny <String>(), It.IsAny <String>(), It.IsAny <List <IIonValue> >(), It.IsAny <CancellationToken>()))
            .ThrowsAsync(exception)
            .ThrowsAsync(exception)
            .ReturnsAsync(sendCommandResponseExecute.ExecuteStatement);
            mockSession.Setup(x => x.CommitTransaction(It.IsAny <String>(), It.IsAny <MemoryStream>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(sendCommandResponseCommit.CommitTransaction);

            mockCreator.Setup(x => x()).ReturnsAsync(mockSession.Object);

            var driver = new QldbDriver(
                new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 4, NullLogger.Instance));

            try
            {
                await driver.Execute(txn => txn.Execute(statement));
            }
            catch (Exception e)
            {
                Assert.AreEqual(exception, e);
                Assert.IsTrue(expectThrow);
                return;
            }

            Assert.IsFalse(expectThrow);
        }
        public async Task TestListTableNamesLists()
        {
            var factory = new ValueFactory();
            var tables  = new List <string>()
            {
                "table1", "table2"
            };
            var ions = tables.Select(t => CreateValueHolder(factory.NewString(t))).ToList();

            var h1 = QldbHash.ToQldbHash(TestTransactionId);

            h1 = Transaction.Dot(h1, QldbDriver.TableNameQuery, new List <IIonValue> {
            });

            var sendCommandResponseWithStartSession = new SendCommandResponse
            {
                StartSession = new StartSessionResult
                {
                    SessionToken = "testToken"
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };
            var sendCommandResponseStartTransaction = new SendCommandResponse
            {
                StartTransaction = new StartTransactionResult
                {
                    TransactionId = TestTransactionId
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };
            var sendCommandResponseExecute = new SendCommandResponse
            {
                ExecuteStatement = new ExecuteStatementResult
                {
                    FirstPage = new Page
                    {
                        NextPageToken = null,
                        Values        = ions
                    }
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };
            var sendCommandResponseCommit = new SendCommandResponse
            {
                CommitTransaction = new CommitTransactionResult
                {
                    CommitDigest  = new MemoryStream(h1.Hash),
                    TransactionId = TestTransactionId
                },
                ResponseMetadata = new ResponseMetadata
                {
                    RequestId = "testId"
                }
            };

            mockClient.SetupSequence(x => x.SendCommandAsync(It.IsAny <SendCommandRequest>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(sendCommandResponseWithStartSession))
            .Returns(Task.FromResult(sendCommandResponseStartTransaction))
            .Returns(Task.FromResult(sendCommandResponseExecute))
            .Returns(Task.FromResult(sendCommandResponseCommit));

            var driver = new QldbDriver(
                new SessionPool(() => Session.StartSession("ledgerName", mockClient.Object, NullLogger.Instance),
                                QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 4, NullLogger.Instance));

            var result = await driver.ListTableNames();

            Assert.IsNotNull(result);
            CollectionAssert.AreEqual(tables, result.ToList());
        }
 internal void SetDefaultResponse(SendCommandResponse response)
 {
     this.defaultResponse = response;
 }
Beispiel #21
0
    public async Task <SsmCommandResponse> RunSsmCommand(UserRequest request, HandlerConfig config)
    {
        if (request == null || config == null)
        {
            return(null);
        }
        string             errorMessage = string.Empty;
        SsmCommandResponse output       = new SsmCommandResponse()
        {
            Status = "Failed" // If no processing is done.
        };

        AmazonSimpleSystemsManagementConfig clientConfig = new AmazonSimpleSystemsManagementConfig()
        {
            MaxErrorRetry    = config.ClientMaxErrorRetry,
            Timeout          = TimeSpan.FromSeconds(config.ClientTimeoutSeconds),
            ReadWriteTimeout = TimeSpan.FromSeconds(config.ClientReadWriteTimeoutSeconds),
            RegionEndpoint   = RegionEndpoint.GetBySystemName(request.AwsRegion) // Or RegionEndpoint.EUWest1
        };

        try
        {
            // https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-creds.html
            // Accessing Credentials and Profiles in an Application
            CredentialProfileStoreChain chain = new CredentialProfileStoreChain(config.AwsProfilesLocation);

            AWSCredentials awsCredentials;
            if (chain.TryGetAWSCredentials(request.AwsRole, out awsCredentials))
            {
                // Use awsCredentials
                AmazonSimpleSystemsManagementClient ssmClient =
                    new AmazonSimpleSystemsManagementClient(awsCredentials, clientConfig);
                if (request.CommandType == "send-command")
                {
                    List <string> instanceIds = new List <string> {
                        request.InstanceId
                    };
                    SendCommandRequest commandRequest = new SendCommandRequest(request.CommandDocument, instanceIds);
                    commandRequest.MaxConcurrency = config.CommandMaxConcurrency; // 50%
                    commandRequest.MaxErrors      = config.CommandMaxErrors;
                    commandRequest.TimeoutSeconds = config.CommandTimeoutSeconds;
                    commandRequest.Comment        = request.CommandComment;
                    commandRequest.Parameters     = request.CommandParameters;
                    SendCommandResponse sendCommandResponse = await ssmClient.SendCommandAsync(commandRequest);

                    output.Status         = "Complete";
                    output.CommandId      = sendCommandResponse.Command.CommandId;
                    output.CommandStatus  = sendCommandResponse.Command.StatusDetails;
                    output.ErrorMessage   = errorMessage;
                    output.CommandComment = sendCommandResponse.Command.Comment;
                }
                else if (request.CommandType == "get-command-invocation")
                {
                    //GetCommandInvocationRequest commandRequest = new GetCommandInvocationRequest()
                    //{
                    //    CommandId = request.CommandId,
                    //    InstanceId = request.InstanceId,
                    //    PluginName = request.CommandPluginName // If there are more than one plugins, this cannot be null.
                    //};
                    //GetCommandInvocationResponse getCommandResponse =
                    //    await ssmClient.GetCommandInvocationAsync(commandRequest);

                    ListCommandInvocationsRequest commandRequest = new ListCommandInvocationsRequest()
                    {
                        CommandId = request.CommandId,
                        Details   = true
                    };
                    ListCommandInvocationsResponse commandResponse = await ssmClient.ListCommandInvocationsAsync(commandRequest);

                    if (commandResponse.CommandInvocations.Count > 0)
                    {
                        output.Status         = "Complete";
                        output.CommandId      = commandResponse.CommandInvocations[0].CommandId;
                        output.CommandStatus  = commandResponse.CommandInvocations[0].StatusDetails;
                        output.CommandComment = commandResponse.CommandInvocations[0].Comment;
                        if (commandResponse.CommandInvocations[0].StatusDetails == "Success" &&
                            commandResponse.CommandInvocations[0].CommandPlugins.Count > 0)
                        {
                            output.StandardOutput = commandResponse.CommandInvocations[0].CommandPlugins[0].Output;
                        }
                        else if (commandResponse.CommandInvocations[0].StatusDetails == "Failed" &&
                                 commandResponse.CommandInvocations[0].CommandPlugins.Count > 0)
                        {
                            GetCommandInvocationRequest invocationRequest = new GetCommandInvocationRequest()
                            {
                                CommandId  = request.CommandId,
                                InstanceId = request.InstanceId,
                                PluginName = request.CommandPluginName // If there are more than one plugins, this cannot be null.
                            };
                            GetCommandInvocationResponse getCommandResponse =
                                await ssmClient.GetCommandInvocationAsync(invocationRequest);

                            output.StandardOutput = getCommandResponse.StandardOutputContent;
                            output.StandardError  = getCommandResponse.StandardErrorContent;
                        }
                    }
                    else
                    {
                        errorMessage = "The command id and instance id specified did not match any invocation.";
                    }
                }
            }
            else
            {
                errorMessage = "AWS credentials cannot be found for the execution.";
            }
        }
        catch (AmazonSimpleSystemsManagementException ex)
        {
            switch (ex.ErrorCode)
            {
            // https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_SendCommand.html
            // Error codes for "SendCommandRequest"
            case "DuplicateInstanceId":
                errorMessage = "You cannot specify an instance ID in more than one association.";
                break;

            case "InternalServerError":
                errorMessage = "Internal server error.";
                break;

            case "InvalidDocument":
                errorMessage = "The specified document does not exist.";
                break;

            case "InvalidDocumentVersion":
                errorMessage = "The document version is not valid or does not exist.";
                break;

            case "ExpiredTokenException":
                errorMessage = "The security token included in the request is expired.";
                break;

            case "InvalidInstanceId":
                errorMessage = "Possible causes are the 1) server instance may not be running 2) Server instance may not exist. 3) SSM agent may not be running. 4) Account used does not have permssion to access the instance.";
                break;

            case "InvalidNotificationConfig":
                errorMessage = "One or more configuration items is not valid.";
                break;

            case "InvalidOutputFolder":
                errorMessage = "The S3 bucket does not exist.";
                break;

            case "InvalidParameters":
                errorMessage =
                    "You must specify values for all required parameters in the Systems Manager document.";
                break;

            case "InvalidRole":
                errorMessage = "The role name can't contain invalid characters.";
                break;

            case "MaxDocumentSizeExceeded":
                errorMessage = "The size limit of a document is 64 KB.";
                break;

            case "UnsupportedPlatformType":
                errorMessage = "The document does not support the platform type of the given instance ID(s).";
                break;

            // Error codes for "GetcommandInvocation"
            case "InvalidCommandId":
                errorMessage = "The command ID is invalid.";
                break;

            case "InvocationDoesNotExist":
                errorMessage =
                    "The command id and instance id specified did not match any invocation.";
                break;

            case "ValidationException":
                errorMessage = ex.Message;
                break;

            default:
                errorMessage = ex.Message;
                break;
            }
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
        }

        if (!string.IsNullOrWhiteSpace(errorMessage))
        {
            throw new Exception(errorMessage);
        }
        return(output);
    }
Beispiel #22
0
        public async Task <string> GetHelpAsync(CancellationToken cancel)
        {
            SendCommandResponse response = await SendCommandAsync("--help", null, null, cancel).ConfigureAwait(false);

            return(response.ResponseString);
        }
Beispiel #23
0
 private static void SetResponse(SendCommandResponse response)
 {
     mockClient.Setup(x => x.SendCommandAsync(It.IsAny <SendCommandRequest>(), It.IsAny <CancellationToken>()))
     .Returns(Task.FromResult(response));
 }