コード例 #1
0
 public async Task Connect(PeepParameter peepParameter)
 {
     try
     {
         var peepHttpParameter = peepParameter as PeepHttpParameter;
         await DoConnect(peepHttpParameter.ServiceUri,
                         peepHttpParameter.MethodKind, peepHttpParameter.Headers,
                         peepHttpParameter.MessageBody,
                         peepHttpParameter.BypassServerCertValidation, peepHttpParameter.ClientCertificateDetail,
                         peepHttpParameter.LoadTestCount);
     }
     catch (Exception ex)
     {
         await Logger.ErrorMessage(ex.ToString());
     }
 }
コード例 #2
0
        public async Task Connect(PeepParameter peepParameter)
        {
            PeepSqlParameter sqlParameter        = peepParameter as PeepSqlParameter;
            string           sqlConnectionString = string.Empty;
            string           accessToken         = string.Empty;

            try
            {
                if (sqlParameter.AADTenantId is not null)
                {
                    string aadInstanceId = $"https://login.windows.net/{sqlParameter.AADTenantId}";
                    string resourceId    = "https://database.windows.net/";
                    sqlConnectionString = $"Data Source=tcp:{sqlParameter.SqlServer},{sqlParameter.SqlServerPort};Initial Catalog={sqlParameter.SqlDatabase};Persist Security Info=False;Connect Timeout=30;Encrypt=True;TrustServerCertificate=False";

                    // Get the AAD access token
                    accessToken = await GetAccessToken(
                        sqlParameter.AADClientId,
                        sqlParameter.AADClientSecretKey,
                        aadInstanceId,
                        resourceId
                        );

                    // Prepare for the Sql operation
                    await SqlCall(sqlConnectionString, sqlParameter.SqlQuery, accessToken);
                }
                else if (sqlParameter.SqlUserID is not null)
                {
                    sqlConnectionString = $"Data Source=tcp:{sqlParameter.SqlServer},{sqlParameter.SqlServerPort};Initial Catalog={sqlParameter.SqlDatabase};Persist Security Info=False;User ID={sqlParameter.SqlUserID};Password={sqlParameter.SqlUserPassword};Connect Timeout=30;Encrypt=True;TrustServerCertificate=False";
                    await SqlCall(sqlConnectionString, sqlParameter.SqlQuery);
                }
            }
            catch (Exception ex)
            {
                await Logger.ErrorMessage(ex.ToString());
            }
            finally
            {
                if (sqlParameter != null)
                {
                    sqlParameter = null;
                }
                if (sqlConnectionString != null)
                {
                    sqlConnectionString = null;
                }
            }
        }
コード例 #3
0
 public async Task Invoke(PeepParameter peepParameter)
 {
     await _peepClient.Connect(peepParameter);
 }
コード例 #4
0
        public async Task <bool> ParseArguments(string[] args)
        {
            bool parseFlag = false;

            if (args.Length == 0)
            {
                await Logger.Message(message : await ArgumentParser.OnUsage());

                return(parseFlag);
            }

            var parsedResult = await ArgumentParser.Parse(args);

            // read the key-value pair and type
            var dictionaryResult = parsedResult.Item2;

            _clientType = parsedResult.Item1;

            if (dictionaryResult != null && dictionaryResult.Count > 0)
            {
                // Set the response as parameters are parsed
                switch (_clientType)
                {
                case "sql":
                    if (dictionaryResult.ContainsKey("aadTenantId"))
                    {
                        _peepParameter = new PeepSqlParameter(
                            sqlServer: dictionaryResult["sqlServer"],
                            sqlServerPort: Int32.Parse(dictionaryResult["sqlServerPort"]),
                            sqlDatabase: dictionaryResult["sqlDatabase"],
                            sqlQuery: dictionaryResult["sqlQuery"],
                            aadTenantId: dictionaryResult["aadTenantId"],
                            aadClientId: dictionaryResult["aadClientId"],
                            aadClientSecretKey: dictionaryResult["aadClientSecretKey"]
                            );
                    }
                    else if (dictionaryResult.ContainsKey("sqlUserID"))
                    {
                        _peepParameter = new PeepSqlParameter(
                            sqlServer: dictionaryResult["sqlServer"],
                            sqlServerPort: Int32.Parse(dictionaryResult["sqlServerPort"]),
                            sqlDatabase: dictionaryResult["sqlDatabase"],
                            sqlQuery: dictionaryResult["sqlQuery"],
                            sqlUserID: dictionaryResult["sqlUserID"],
                            sqlPassword: dictionaryResult["sqlUserPassword"]
                            );
                    }
                    break;

                case "httpclient":
                    var peepHttpParameter = new PeepHttpParameter(
                        dictionaryResult["serviceUri"],
                        dictionaryResult["methodKind"]
                        );

                    string dictionaryValue;

                    if (dictionaryResult.TryGetValue("headers", out dictionaryValue))
                    {
                        peepHttpParameter.Headers = await HttpHelper.GetHeaders(dictionaryValue);
                    }
                    if (dictionaryResult.TryGetValue("bypassServerCertValidation", out dictionaryValue))
                    {
                        peepHttpParameter.BypassServerCertValidation = Boolean.Parse(dictionaryValue);
                    }
                    if (dictionaryResult.TryGetValue("clientCertificate", out dictionaryValue))
                    {
                        peepHttpParameter.ClientCertificateDetail = HttpHelper.GetClientCertificateDetails(dictionaryValue);
                    }
                    if (dictionaryResult.TryGetValue("body", out dictionaryValue))
                    {
                        peepHttpParameter.MessageBody = await HttpHelper.GetMessageBody(dictionaryValue);
                    }
                    if (dictionaryResult.TryGetValue("loadTest", out dictionaryValue))
                    {
                        peepHttpParameter.LoadTestCount = Int32.Parse(dictionaryValue);
                    }

                    // Set the global PeepParameter
                    _peepParameter = peepHttpParameter;

                    break;

                default:
                    break;
                }
            }

            parseFlag = true;
            return(parseFlag);
        }