-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathV3ResponseUtil.cs
More file actions
67 lines (54 loc) · 2.21 KB
/
Copy pathV3ResponseUtil.cs
File metadata and controls
67 lines (54 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.PowerShell.PSResourceGet.UtilClasses;
using System;
using System.Collections.Generic;
using System.Text.Json;
namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
{
internal class V3ResponseUtil : ResponseUtil
{
#region Members
internal override PSRepositoryInfo Repository { get; set; }
#endregion
#region Constructor
public V3ResponseUtil(PSRepositoryInfo repository) : base(repository)
{
this.Repository = repository;
}
#endregion
#region Overridden Methods
public override IEnumerable<PSResourceResult> ConvertToPSResourceResult(FindResults responseResults, bool isResourceRequestedWithWildcard = false)
{
// in FindHelper:
// serverApi.FindName() -> return responses, and out errRecord
// check outErrorRecord
//
// v3Converter.ConvertToPSResourceInfo(responses) -> return PSResourceResult
// check resourceResult for error, write if needed
string[] responses = responseResults.StringResponse;
foreach (string response in responses)
{
string responseConversionError = String.Empty;
PSResourceInfo pkg = null;
try
{
using (JsonDocument pkgVersionEntry = JsonDocument.Parse(response))
{
PSResourceInfo.TryConvertFromJson(pkgVersionEntry, out pkg, Repository, out responseConversionError);
}
}
catch (Exception e)
{
responseConversionError = e.Message;
}
if (!String.IsNullOrEmpty(responseConversionError))
{
yield return new PSResourceResult(returnedObject: null, new ConvertToPSResourceException(responseConversionError), isTerminatingError: false);
}
yield return new PSResourceResult(returnedObject: pkg, exception: null, isTerminatingError: false);
}
}
#endregion
}
}