예제 #1
0
        public async Task <AuditLogSettings> GetSettingsAsync()
        {
            JsonSerializer serializer = JsonSerializer.CreateDefault();

            if (!File.Exists(DefaultFileName))
            {
                // The file does not exist creating an empty one and exit
                var settings = new AuditLogSettings()
                {
                    Url = nameof(AuditLogSettings.Url),
                    PAT = nameof(AuditLogSettings.PAT)
                };

                using (StreamWriter fileStream = File.CreateText(DefaultFileName))
                    using (JsonWriter jsonWriter = new JsonTextWriter(fileStream))
                    {
                        serializer.Serialize(jsonWriter, settings);
                        throw new InvalidTargetSettingsException(Resources.Publish_Settings_file_created + DefaultFileName);
                    }
            }

            // The file is exists, try to deserialize the content
            using (StreamReader fileStream = new StreamReader(DefaultFileName))
            {
                string json = await fileStream.ReadToEndAsync();

                return(JsonConvert.DeserializeObject <AuditLogSettings>(json));
            }
        }
        public async Task <AuditLogQueryResult> QueryLogAsync(int batchSize, string continuationToken)
        {
            auditLogSettings = await SettingProvider.GetSettingsAsync();

            using (HttpResponseMessage response = await HttpClient.GetAsync(auditLogSettings.Url + "/_api/auditlog/querylog"))
            {
                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <AuditLogQueryResult>(responseBody));
            }
        }
 public AzureDevOpsAuditLogProvider(AuditLogSettings settings)
 {
     auditLogSettings = settings;
 }