Skip to content

Commit 18179aa

Browse files
authored
Merge pull request #2354 from Microsoft/dev
Sync from dev
2 parents 04c6b7e + 6658ffb commit 18179aa

File tree

790 files changed

+3563
-24918
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

790 files changed

+3563
-24918
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ Once you select the attributes you want your new UWP app to have, you can quickl
4545
* [Authoring Templates](docs/templates.md)
4646

4747
## Known issues
48-
* Issue ([#1753](https://github.com/Microsoft/WindowsTemplateStudio/issues/1753)): Wack tests are currently failing in our build server due to a machine configuration issue. All tests pass correctly if locally executed. We are working on getting them back to green.
4948
* Issue ([#1629](https://github.com/Microsoft/WindowsTemplateStudio/issues/1629)): the Master-Detail view has an issue if you set the background to Transparent in the MastertDetailControl. We are actively working with the UWPCommunityTookit team to get this solved as soon as possible.
5049
* Issue ([#1532](https://github.com/Microsoft/WindowsTemplateStudio/issues/1532)): when uninstalling / upgrading where you may get an error of "A value for 'Component' needs to be specified in the catalog." If you get this error, we need logs to help track this with the help of the Visual Studio team. We don't know how to reproduce it but we know a few people have hit this scenario. We have how to capture these logs in the [tracking issue on GitHub.](https://github.com/Microsoft/WindowsTemplateStudio/issues/1532)
5150
* You can't have side-by-side versions (nightly/pre-release/release) of WindowsTemplateStudio VSPackage into a single instance of Visual Studio.

_build/Extension-SetIdentityAndVersion.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,27 @@ else
190190
Write-Warning "No files found to apply version."
191191
}
192192

193+
194+
## APPLY VERSION RelayCommandPackage
195+
Write-Host
196+
Write-Host "Applying version to RelayCommandPackage.cs"
197+
$files = Get-ChildItem -include "RelayCommandPackage.cs" -Recurse | Where-Object{ $_.FullName -notmatch "\\Templates\\" }
198+
if($files)
199+
{
200+
Write-Host "Will apply $versionNumber to $($files.count) files."
201+
202+
foreach ($file in $files) {
203+
$filecontent = Get-Content($file)
204+
attrib $file -r
205+
$filecontent -replace $VersionRegex, $versionNumber | Out-File $file utf8
206+
Write-Host "$file - version applied"
207+
}
208+
}
209+
else
210+
{
211+
Write-Warning "No relaycommandPackage found to apply version."
212+
}
213+
193214
## APPLY VERSION TO PROJECT TEMPLATE WIZARD REFERENCE
194215
if($publicKeyToken){
195216
Write-Host

code/Nuget.Config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
</packageRestore>
77
<packageSources>
88
<add key="dotnet templating package source" value="https://dotnet.myget.org/F/templating/api/v3/index.json" />
9-
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
9+
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
1010
</packageSources>
1111
</configuration>

code/src/Core/Core.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@
207207
<Compile Include="Naming\DefaultNamesValidator.cs" />
208208
<Compile Include="Naming\ReservedNamesValidator.cs" />
209209
<Compile Include="Packaging\TemplatePackage.cs" />
210+
<Compile Include="PostActions\Catalog\Merge\MergeMode.cs" />
210211
<Compile Include="PostActions\Catalog\Merge\MergeResourceDictionaryPostAction.cs" />
212+
<Compile Include="PostActions\Catalog\Merge\PostactionFormatter.cs" />
211213
<Compile Include="PostActions\Catalog\Merge\ResourceDictionaryWriter.cs" />
212214
<Compile Include="PostActions\Catalog\SortNamespaces\ListStringExtensions.cs" />
213215
<Compile Include="PostActions\TemplateDefinedPostAction.cs" />
@@ -234,7 +236,6 @@
234236
<Compile Include="PostActions\Catalog\Merge\SearchAndReplacePostAction.cs" />
235237
<Compile Include="PostActions\Catalog\AddContextItemsToProjectPostAction.cs" />
236238
<Compile Include="PostActions\Catalog\Merge\MergeFailureType.cs" />
237-
<Compile Include="PostActions\Catalog\Merge\PostActionFormatter.cs" />
238239
<Compile Include="PostActions\Catalog\NewItemGeneration\CreateSummaryPostAction.cs" />
239240
<Compile Include="PostActions\Catalog\Merge\GenerateMergeInfoPostAction.cs" />
240241
<Compile Include="PostActions\Catalog\Merge\GetMergeFilesFromProjectPostAction.cs" />

code/src/Core/Gen/GenShell.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public abstract class GenShell
3939

4040
public abstract void ShowTaskList();
4141

42+
public abstract void OpenProjectOverview();
43+
4244
public abstract void ShowModal(Window dialog);
4345

4446
public abstract void CancelWizard(bool back = true);

code/src/Core/Locations/TemplatesContent.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public TemplatesContent(string workingFolder, string sourceId, Version wizardVer
4343
LoadAvailableContents();
4444

4545
Source = source;
46-
SetCurrentContent(tengineCurrentContent);
46+
SetCurrentContent(tengineCurrentContent, wizardVersion);
4747

4848
WizardVersion = wizardVersion;
4949
}
@@ -293,9 +293,17 @@ private TemplatesContentInfo GetLatestContent()
293293
return All.OrderByDescending(c => c.Version).ThenByDescending(c => c.Date).FirstOrDefault();
294294
}
295295

296-
private void SetCurrentContent(string tengineCurrentContent)
296+
private void SetCurrentContent(string tengineCurrentContent, Version wizardVersion)
297297
{
298-
Current = All.Where(c => c.Path.Equals(tengineCurrentContent, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
298+
if (!string.IsNullOrEmpty(tengineCurrentContent))
299+
{
300+
Current = All.Where(c => c.Path.Equals(tengineCurrentContent, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
301+
}
302+
else
303+
{
304+
var mainWizardVersion = $"{wizardVersion.Major.ToString()}.{wizardVersion.Minor.ToString()}";
305+
Current = All.Where(c => c.MainVersion.Equals(mainWizardVersion, StringComparison.OrdinalIgnoreCase)).OrderByDescending(c => c.Version).ThenByDescending(c => c.Date).FirstOrDefault();
306+
}
299307
}
300308

301309
internal void RefreshContentFolder(string tengineCurrentContent)

code/src/Core/Locations/TemplatesSynchronization.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,29 @@ private async Task<bool> LoadConfigFileAsync(CancellationToken ct)
147147
{
148148
bool notifyCheckingforUpdates = false;
149149

150-
Task[] downloadTasks = new Task[2];
151-
downloadTasks[0] = _content.Source.LoadConfigAsync(ct);
152-
downloadTasks[1] = Task.Delay(1000);
150+
try
151+
{
152+
Task[] downloadTasks = new Task[2];
153+
downloadTasks[0] = _content.Source.LoadConfigAsync(ct);
154+
downloadTasks[1] = Task.Delay(1000);
155+
156+
Task firstFinishedTask = await Task.WhenAny(downloadTasks);
153157

154-
Task firstFinishedTask = await Task.WhenAny(downloadTasks);
158+
if (firstFinishedTask.Id == downloadTasks[1].Id)
159+
{
160+
notifyCheckingforUpdates = true;
161+
SyncStatusChanged?.Invoke(this, new SyncStatusEventArgs { Status = SyncStatus.CheckingForUpdates });
162+
await downloadTasks[0];
163+
}
155164

156-
if (firstFinishedTask.Id == downloadTasks[1].Id)
165+
return notifyCheckingforUpdates;
166+
}
167+
catch (Exception ex)
157168
{
158-
notifyCheckingforUpdates = true;
159-
SyncStatusChanged?.Invoke(this, new SyncStatusEventArgs { Status = SyncStatus.CheckingForUpdates });
160-
await downloadTasks[0];
169+
AppHealth.Current.Error.TrackAsync(StringRes.TemplatesSynchronizationErrorDownloadingConfig, ex).FireAndForget();
170+
return notifyCheckingforUpdates;
161171
}
162-
163-
return notifyCheckingforUpdates;
164-
}
172+
}
165173

166174
private void OnCopyProgress(object sender, ProgressEventArgs eventArgs)
167175
{

code/src/Core/PostActions/Catalog/Merge/IEnumerableExtensions.cs

Lines changed: 104 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ public static class IEnumerableExtensions
1212
{
1313
internal const string MacroBeforeMode = "^^";
1414
internal const string MacroStartGroup = "{[{";
15-
internal const string MarcoEndGroup = "}]}";
15+
internal const string MacroEndGroup = "}]}";
1616

1717
internal const string MacroStartDocumentation = "{**";
1818
internal const string MacroEndDocumentation = "**}";
1919

2020
private const string MacroStartDelete = "{--{";
2121
private const string MacroEndDelete = "}--}";
2222

23+
private static string[] macros = new string[] { MacroBeforeMode, MacroStartGroup, MacroEndGroup, MacroStartDocumentation, MacroEndDocumentation, MacroStartDelete, MacroEndDelete };
24+
2325
private const string OpeningBrace = "{";
2426
private const string ClosingBrace = "}";
2527

@@ -56,98 +58,133 @@ public static IEnumerable<string> Merge(this IEnumerable<string> source, IEnumer
5658
errorLine = string.Empty;
5759
int lastLineIndex = -1;
5860
var insertionBuffer = new List<string>();
61+
var removalBuffer = new List<string>();
5962

6063
bool beforeMode = false;
61-
bool isInBlock = false;
62-
bool isInDocumentation = false;
64+
MergeMode mergeMode = MergeMode.Context;
6365

6466
var diffTrivia = FindDiffLeadingTrivia(source, merge);
6567
var result = source.ToList();
6668
var currentLineIndex = -1;
6769

6870
foreach (var mergeLine in merge)
6971
{
70-
if (!isInBlock && !isInDocumentation)
72+
// try to find line
73+
if (mergeMode == MergeMode.Context)
7174
{
7275
currentLineIndex = result.SafeIndexOf(mergeLine.WithLeadingTrivia(diffTrivia), lastLineIndex);
7376
}
7477

78+
// if line is found, add buffer if any
7579
if (currentLineIndex > -1)
7680
{
7781
var linesAdded = TryAddBufferContent(insertionBuffer, result, lastLineIndex, currentLineIndex, beforeMode);
82+
var linesRemoved = TryRemoveBufferContent(removalBuffer, result, lastLineIndex, currentLineIndex);
7883

79-
if (beforeMode)
84+
if (linesAdded > 0)
8085
{
81-
beforeMode = false;
86+
lastLineIndex = currentLineIndex + linesAdded;
8287
}
8388

84-
lastLineIndex = currentLineIndex + linesAdded;
85-
insertionBuffer.Clear();
86-
}
87-
else
88-
{
89-
if (mergeLine.Contains(MacroBeforeMode))
89+
if (linesRemoved > 0)
9090
{
91-
beforeMode = true;
91+
lastLineIndex = currentLineIndex - linesRemoved;
9292
}
93-
else if (mergeLine.Contains(MacroStartGroup))
94-
{
95-
isInBlock = true;
96-
}
97-
else if (mergeLine.Contains(MarcoEndGroup))
98-
{
99-
isInBlock = false;
100-
}
101-
else if (!isInDocumentation && (isInBlock || mergeLine == string.Empty))
93+
94+
if (beforeMode)
10295
{
103-
insertionBuffer.Add(mergeLine.WithLeadingTrivia(diffTrivia));
96+
beforeMode = false;
10497
}
105-
else if (mergeLine.Contains(MacroStartDocumentation))
98+
99+
if (linesRemoved == 0 && linesAdded == 0)
106100
{
107-
isInDocumentation = true;
101+
lastLineIndex = currentLineIndex;
108102
}
109-
else if (mergeLine.Contains(MacroEndDocumentation))
103+
104+
insertionBuffer.Clear();
105+
removalBuffer.Clear();
106+
}
107+
else
108+
{
109+
// if line is not found check if merge direction, else add to buffer
110+
if (IsMergeDirection(mergeLine))
110111
{
111-
isInDocumentation = false;
112+
mergeMode = GetMergeMode(mergeLine, mergeMode);
112113
}
113-
else if (!isInDocumentation)
114+
else
114115
{
115-
errorLine = mergeLine;
116-
return source;
116+
if (mergeMode == MergeMode.Insert || mergeMode == MergeMode.InsertBefore || mergeLine == string.Empty)
117+
{
118+
if (mergeMode == MergeMode.InsertBefore)
119+
{
120+
beforeMode = true;
121+
}
122+
123+
insertionBuffer.Add(mergeLine.WithLeadingTrivia(diffTrivia));
124+
}
125+
else if (mergeMode == MergeMode.Remove)
126+
{
127+
removalBuffer.Add(mergeLine.WithLeadingTrivia(diffTrivia));
128+
}
129+
else if (mergeMode == MergeMode.Context)
130+
{
131+
errorLine = mergeLine;
132+
return source;
133+
}
117134
}
118135
}
119136
}
120137

121138
TryAddBufferContent(insertionBuffer, result, lastLineIndex);
139+
TryRemoveBufferContent(removalBuffer, result, lastLineIndex);
122140

123141
return result;
124142
}
125143

126-
// Removes anything from the target file that should be deleted.
127-
public static List<string> HandleRemovals(this IEnumerable<string> source, IEnumerable<string> merge)
144+
private static bool IsMergeDirection(string mergeLine)
128145
{
129-
var mergeString = string.Join(Environment.NewLine, merge);
130-
var sourceString = string.Join(Environment.NewLine, source);
131-
132-
var startIndex = mergeString.IndexOf(MacroStartDelete, StringComparison.OrdinalIgnoreCase);
133-
var endIndex = mergeString.IndexOf(MacroEndDelete, StringComparison.OrdinalIgnoreCase);
146+
return macros.Any(c => mergeLine.Contains(c));
147+
}
134148

135-
while (startIndex > 0 && endIndex > startIndex)
149+
private static MergeMode GetMergeMode(string mergeLine, MergeMode current)
150+
{
151+
if (mergeLine.Contains(MacroBeforeMode))
136152
{
137-
// VB uses a single character (') to start the comment, C# uses two (//)
138-
int commentIndicatorLength = mergeString[startIndex - 1] == '\'' ? 1 : 2;
139-
140-
var toRemove = mergeString.Substring(
141-
(startIndex - commentIndicatorLength) + (MacroStartDelete.Length + commentIndicatorLength),
142-
(endIndex - commentIndicatorLength) - (startIndex - commentIndicatorLength) - (MacroStartDelete.Length + commentIndicatorLength));
143-
144-
sourceString = sourceString.Replace(toRemove, string.Empty);
145-
mergeString = mergeString.Substring(endIndex + MacroEndDelete.Length);
146-
startIndex = mergeString.IndexOf(MacroStartDelete, StringComparison.InvariantCultureIgnoreCase);
147-
endIndex = mergeString.IndexOf(MacroEndDelete, StringComparison.InvariantCultureIgnoreCase);
153+
return MergeMode.InsertBefore;
154+
}
155+
else if (mergeLine.Contains(MacroStartGroup))
156+
{
157+
if (current == MergeMode.InsertBefore)
158+
{
159+
return MergeMode.InsertBefore;
160+
}
161+
else
162+
{
163+
return MergeMode.Insert;
164+
}
165+
}
166+
else if (mergeLine.Contains(MacroEndGroup))
167+
{
168+
return MergeMode.Context;
169+
}
170+
else if (mergeLine.Contains(MacroStartDocumentation))
171+
{
172+
return MergeMode.Documentation;
173+
}
174+
else if (mergeLine.Contains(MacroEndDocumentation))
175+
{
176+
return MergeMode.Context;
177+
}
178+
else if (mergeLine.Contains(MacroStartDelete))
179+
{
180+
return MergeMode.Remove;
181+
}
182+
else if (mergeLine.Contains(MacroEndDelete))
183+
{
184+
return MergeMode.Context;
148185
}
149186

150-
return sourceString.Split(new[] { Environment.NewLine }, StringSplitOptions.None).ToList();
187+
return current;
151188
}
152189

153190
// Remove any comments from the merged file that indicate something should be removed.
@@ -198,6 +235,21 @@ private static int TryAddBufferContent(List<string> insertionBuffer, List<string
198235
return 0;
199236
}
200237

238+
private static int TryRemoveBufferContent(List<string> removalBuffer, List<string> result, int lastLineIndex, int currentLineIndex = 0)
239+
{
240+
if (removalBuffer.Any() && BlockExists(removalBuffer, result, lastLineIndex) && currentLineIndex > -1)
241+
{
242+
var index = result.SafeIndexOf(removalBuffer[0], lastLineIndex);
243+
if (index <= currentLineIndex)
244+
{
245+
result.RemoveRange(index, removalBuffer.Count);
246+
return removalBuffer.Count;
247+
}
248+
}
249+
250+
return 0;
251+
}
252+
201253
private static void EnsureNoWhiteLinesNextToBraces(List<string> insertionBuffer, List<string> result, int insertIndex)
202254
{
203255
if (LastLineIsOpeningBrace(result, insertIndex) && insertionBuffer.First().Trim() == string.Empty)
@@ -242,9 +294,9 @@ private static bool BlockExists(IEnumerable<string> blockBuffer, IEnumerable<str
242294
.All(b => target.SafeIndexOf(b, skip) > -1);
243295
}
244296

245-
private static int GetInsertLineIndex(int currentLine, int lastLine, bool isBeforeMode)
297+
private static int GetInsertLineIndex(int currentLine, int lastLine, bool beforeMode)
246298
{
247-
if (isBeforeMode)
299+
if (beforeMode)
248300
{
249301
return currentLine;
250302
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Microsoft.Templates.Core.PostActions.Catalog.Merge
6+
{
7+
public enum MergeMode
8+
{
9+
InsertBefore,
10+
Insert,
11+
Remove,
12+
Documentation,
13+
Context
14+
}
15+
}

0 commit comments

Comments
 (0)