1@* Generator: WebPage *@
2
3@using System.Globalization;
4@{
5    // Setup layout
6    var currentPage = Href(PageUtils.GetPageVirtualPath("PackageSources"));
7    PageData["BreadCrumbs"].Add(Tuple.Create(PackageManagerResources.ManageSourcesTitle, currentPage));
8    Page.Desc = PackageManagerResources.ManageSourcesDesc;
9    Page.SectionTitle = PackageManagerResources.ManageSourcesTitle;
10
11    if (IsPost) {
12        AntiForgery.Validate();
13        var action = Request.Form["action"];
14        var sourceUrl = Request.Form["sourceUrl"];
15        var sourceName = Request.Form["sourceName"];
16        try {
17            if (action.Equals(PackageManagerResources.AddPackageSourceLabel, StringComparison.OrdinalIgnoreCase)) {
18
19                ModelState.SetModelValue("sourceName", sourceName);
20                ModelState.SetModelValue("sourceUrl", sourceUrl);
21
22                Uri url;
23                if (!Uri.TryCreate(sourceUrl, UriKind.Absolute, out url)) {
24                    ModelState.AddError("sourceUrl", PackageManagerResources.Validation_InvalidPackageSourceUrl);
25                } else if (!PackageManagerModule.AddPackageSource(source: sourceUrl, name: sourceName)) {
26                    ModelState.AddError("sourceName", PackageManagerResources.Validation_PackageSourceAlreadyExists);
27                } else {
28                    // The feed was successfully added. Clear the model state.
29                    ModelState.Clear();
30                }
31            }
32            else if (action.Equals(PackageManagerResources.DeleteLabel, StringComparison.OrdinalIgnoreCase)) {
33                PackageManagerModule.RemovePackageSource(sourceName);
34            }
35            else if (action.Equals(PackageManagerResources.RestoreDefaultSources, StringComparison.OrdinalIgnoreCase)) {
36                foreach(var packageSource in PackageManagerModule.DefaultSources) {
37                    PackageManagerModule.AddPackageSource(packageSource);
38                }
39            }
40        } catch (UnauthorizedAccessException) {
41            <div class="message error">
42                @String.Format(CultureInfo.CurrentCulture, PackageManagerResources.PackageSourceFileInstructions, PackageManagerModule.PackageSourceFilePath)
43            </div>
44        }
45    }
46
47    var numSources = PackageManagerModule.PackageSources.Count();
48}
49
50@Html.ValidationSummary(excludeFieldErrors: true)
51
52<table id="feeds">
53<thead>
54    <tr>
55        <th scope="col">@PackageManagerResources.SourceNameLabel</th>
56        <th scope="col">@PackageManagerResources.SourceUrlLabel</th>
57        <th></th>
58    </tr>
59</thead>
60<tbody>
61    @foreach(var source in PackageManagerModule.PackageSources) {
62    <tr>
63        <td>@source.Name</td>
64        <td><a href="@source.Source">@source.Source</a></td>
65        <td>
66            @if(numSources > 1) {
67                <form method="post" action="">
68                    <input type="hidden" name="sourceName" value="@source.Name" />
69                    <input type="submit" name="action" value="@PackageManagerResources.DeleteLabel" />
70                    @AntiForgery.GetHtml()
71                </form>
72            }
73        </td>
74    </tr>
75    }
76</tbody>
77</table>
78<br />
79<form method="post" action="">
80@AntiForgery.GetHtml()
81<fieldset>
82    <legend>@PackageManagerResources.AddPackageSourceLabel</legend>
83    <ol>
84        <li>
85            <label for="feedName">@PackageManagerResources.SourceNameLabel:</label>
86            @Html.TextBox("sourceName") @Html.ValidationMessage("sourceName")
87        </li>
88        <li>
89            <label for="feedUrl">@PackageManagerResources.SourceUrlLabel:</label>
90            @Html.TextBox("sourceUrl") @Html.ValidationMessage("sourceUrl")
91        </li>
92    </ol>
93    <p class="form-actions">
94
95    <input type="submit" name="action" class="long-input" value="@PackageManagerResources.AddPackageSourceLabel" />
96    </p>
97</fieldset>
98</form>
99
100@{
101    if (PackageManagerModule.DefaultSources.Intersect(PackageManagerModule.PackageSources).Count() != PackageManagerModule.DefaultSources.Count()) {
102    <p>
103        <form method="post" action="">
104            @AntiForgery.GetHtml()
105            <fieldset class="no-border">
106                <input type="submit" name="action" class="long-input"  value="@PackageManagerResources.RestoreDefaultSources" />
107            </fieldset>
108        </form>
109    </p>
110    }
111}
112