This commit is contained in:
DoganGunay 2024-06-06 16:59:23 +02:00 коммит произвёл GitHub
Родитель 25a6f986c8
Коммит f28cb921f5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 39 добавлений и 75 удалений

Просмотреть файл

@ -17,7 +17,8 @@
},
"iconBrandColor": "#abb8c3",
"scriptOperations": [
"Getdetails"
"Getdetails",
"Create"
],
"capabilities": [],
"policyTemplateInstances": [

Просмотреть файл

@ -4,96 +4,59 @@
{
try
{
if (this.Context.OperationId.StartsWith("Getdetails", StringComparison.OrdinalIgnoreCase))
// Use the context to forward/send an HTTP request
HttpResponseMessage response = await this.Context.SendAsync(this.Context.Request, this.CancellationToken).ConfigureAwait(continueOnCapturedContext: false);
// Do the transformation if the response was successful, otherwise return error responses as-is
if (response.IsSuccessStatusCode)
{
// Deserialize the JSON to a JObject
var jObject = JObject.Parse(await response.Content.ReadAsStringAsync());
// Use the context to forward/send an HTTP request
HttpResponseMessage response = await this.Context.SendAsync(this.Context.Request, this.CancellationToken).ConfigureAwait(continueOnCapturedContext: false);
// Do the transformation if the response was successful, otherwise return error responses as-is
if (response.IsSuccessStatusCode)
// Get the "Files" object
var filesObject = (JObject?)jObject["Files"];
// Prepare a list to hold the transformed files
var filesList = new List<JObject>();
if (filesObject is not null)
{
// Deserialize the JSON to a JObject
var jObject = JObject.Parse(await response.Content.ReadAsStringAsync());
// Get the "Files" object
var filesObject = (JObject?)jObject["Files"];
// Prepare a list to hold the transformed files
var filesList = new List<JObject>();
if (filesObject is not null)
// Iterate over each property (file) in the "Files" object
foreach (var file in filesObject.Properties())
{
// Iterate over each property (file) in the "Files" object
foreach (var file in filesObject.Properties())
// Create a JObject for each file and add it to the list
var fileEntry = new JObject
{
// Create a JObject for each file and add it to the list
var fileEntry = new JObject
{
["Links"] = file.Value["Links"],
["DisplayName"] = file.Name
};
filesList.Add(fileEntry);
}
// Create the new JObject to hold the list of files
jObject.Remove("Files");
var newFilesObject = new JObject
{
["Files"] = JArray.FromObject(filesList)
["Links"] = file.Value["Links"],
["DisplayName"] = file.Name
};
jObject.Add("Files", JArray.FromObject(filesList));
filesList.Add(fileEntry);
}
response.Content = CreateJsonContent(jObject.ToString());
return response;
// Create the new JObject to hold the list of files
jObject.Remove("Files");
var newFilesObject = new JObject
{
["Files"] = JArray.FromObject(filesList)
};
jObject.Add("Files", JArray.FromObject(filesList));
}
}
}
catch (ConnectorException ex)
{
var response = new HttpResponseMessage(ex.StatusCode);
if (ex.Message.Contains("ValidationFailure:"))
{
response.Content = CreateJsonContent(ex.JsonMessage());
}
else
{
response.Content = CreateJsonContent(ex.Message);
}
response.Content = CreateJsonContent(jObject.ToString());
}
return response;
}
return response;
}
}
public class ConnectorException : Exception
{
public HttpStatusCode StatusCode { get; }
public ConnectorException(HttpStatusCode statusCode, string message, Exception innerException = null) : base(message, innerException)
{
this.StatusCode = statusCode;
}
public override string ToString()
{
var error = new StringBuilder($"ConnectorException: Status code={this.StatusCode}, Message='{this.Message}'");
var inner = this.InnerException;
var level = 0;
while (inner != null && level < 10)
catch (Exception ex)
{
level += 1;
error.AppendLine($"Inner exception {level}: {inner.Message}");
inner = inner.InnerException;
var response = new HttpResponseMessage(HttpStatusCode.BadRequest)
{
Content = CreateJsonContent("error: "+ ex.Message)
};
return response;
}
error.AppendLine($"Stack trace: {this.StackTrace}");
return error.ToString();
}
}