forked from microsoft/iqsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PackagesController.cs
76 lines (68 loc) · 2.3 KB
/
PackagesController.cs
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
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Quantum.IQSharp.Common;
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods
namespace Microsoft.Quantum.IQSharp
{
/// <summary>
/// Provides a mechanism to manage nuget packages.
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class PackagesController : ControllerBase
{
public PackagesController(IReferences references)
{
this.References = references;
}
/// <summary>
/// Packages are managed via the IReferences
/// </summary>
public IReferences References { get; }
/// <summary>
/// Default entry point. Returns the list of operations in the Workspace.
/// </summary>
[HttpGet]
public async Task<Response<string[]>> List()
{
try
{
return new Response<string[]>(Status.success, new string[] { }, References.Packages?.ToArray());
}
catch (Exception e)
{
return new Response<string[]>(Status.error, new string[] { e.Message });
}
}
/// <summary>
/// Default entry point. Returns the list of operations in the Workspace.
/// </summary>
[HttpGet("add/{pkg}")]
public async Task<Response<string[]>> Add(string pkg)
{
try
{
await References.AddPackage(pkg);
return await List();
}
catch (Exception e)
{
return new Response<string[]>(Status.error, new string[] { e.Message });
}
}
}
}
#pragma warning restore VSTHRD200 // Use "Async" suffix for async methods
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously