Ejemplo n.º 1
0
        public async Task <TResponse> PostXmlToRealex <TResponse, TRequest>(
            TRequest request,
            string secretKey,
            LogLevel logLevelForSuccess)
            where TRequest : RealAuthRequest
            where TResponse : RealAuthResponse, new()
        {
            request.SetSha1Hash(secretKey);

            string postUrl = RealEx.Default.RealVaultRemoteUrl;
            var    client  = LoggingHttpHandler.CreateLoggingClient(
                this.Logger,
                typeof(RealexApiProvider),
                logLevelRequest: LogLevel.Info,
                logLevelResponse: LogLevel.Debug);
            // MUST use the XmlSerializer instead of default DataContractSerializer to honour the XmlAttribute and XmlRoot attributes
            XmlMediaTypeFormatter formatter = new XmlMediaTypeFormatter()
            {
                UseXmlSerializer = true
            };
            HttpResponseMessage response = await client.PostAsync <TRequest>(
                postUrl,
                request,
                formatter,
                System.Threading.CancellationToken.None);

            string responseFromServer = await response.Content.ReadAsStringAsync();

            TResponse parsedResponse = RealAuthResponseParser <TResponse> .DeserializeFromString(
                responseFromServer,
                response.StatusCode,
                request);

            LogLevel levelToLog = parsedResponse.IsSuccess ? logLevelForSuccess : LogLevel.Error;

            this.Logger.CreateEntry(typeof(RealexApiProvider), levelToLog,
                                    $"StatusCode {(int) response.StatusCode} content {responseFromServer}");

            if (!parsedResponse.IsSha1HashCorrect(secretKey))
            {
                this.Logger.CreateEntry(typeof(RealexApiProvider), LogLevel.Warn,
                                        $"Incorrect Sha1Hash {responseFromServer}");
            }

            return(parsedResponse);
        }
Ejemplo n.º 2
0
        private static async Task MainAsync(string[] args)
        {
            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(Directory.GetCurrentDirectory())
                                       .AddJsonFile("appsettings.dev.json", optional: false);
            var configuration         = configurationBuilder.Build();
            var packageSourceSettings = new PackageSourceSettings();

            configuration.Bind(packageSourceSettings);
            var options = Options.Create(packageSourceSettings);
            var packageSourceProvider = new PackageSourceProvider(options);
            var packageReader         = new PackageReader();
            var testData          = TestData.InitializeFromRepository();
            var httpClientHandler = new HttpClientHandler();
            var loggerFactory     = new LoggerFactory();
            var parser            = new Parser();
            var mapper            = new Mapper();

            loggerFactory.AddConsole();
            var loggingHttpHandler = new LoggingHttpHandler(httpClientHandler, loggerFactory.CreateLogger <LoggingHttpHandler>());

            using (var httpClient = new HttpClient(loggingHttpHandler))
            {
                var protocol = new Protocol(httpClient, parser);
                var client   = new Client(protocol, packageReader);

                /*
                 * var sources = packageSourceProvider.GetPackageSources();
                 * foreach (var source in sources)
                 * {
                 *  using (var package = testData.PackageUnlisted)
                 *  {
                 *      await client.PushAndUnlistPackageIfNotExistsAsync(source, package);
                 *  }
                 * }
                 */

                /*
                 * var schemaComparisonTest = new SchemaComparisonTest(packageSourceProvider, client);
                 * var schemaComparison = await schemaComparisonTest.ExecuteAsync();
                 *
                 * var propertyComparisonTest = new PropertyComparisonTest(packageSourceProvider, packageReader, testData, client, mapper);
                 * var propertyComparison = await propertyComparisonTest.ExecuteAsync();
                 *
                 * var propertyConsistencyTest = new PropertyConsistencyTest(packageSourceProvider, client, testData, packageReader);
                 * var propertyConsistency = await propertyConsistencyTest.ExecuteAsync();
                 *
                 * Console.WriteLine(JsonConvert.SerializeObject(
                 *  new
                 *  {
                 *      SchemaComparison = schemaComparison,
                 *      PropertyComparison = propertyComparison,
                 *      PropertyConsistency = propertyConsistency,
                 *  },
                 *  new JsonSerializerSettings
                 *  {
                 *      Formatting = Formatting.Indented,
                 *      Converters = new[]
                 *      {
                 *          new StringEnumConverter(),
                 *      },
                 *  }));
                 */

                /*
                 * var abbreviation = new Abbreviations();
                 * var markdownTableWriter = new MarkdownTableWriter();
                 * var report = new SchemaComparisonWriter(abbreviation, markdownTableWriter);
                 * var sb = new StringBuilder();
                 * report.Write(sb, schemaComparison);
                 *
                 * Console.WriteLine(sb.ToString());
                 */
            }
        }