Skip to content

Commit 0b6780d

Browse files
MAUI viewer ran against PerformanceAnalysisMode (#1456)
1 parent ceb06b7 commit 0b6780d

File tree

5 files changed

+24
-27
lines changed

5 files changed

+24
-27
lines changed

src/MAUI/Maui.Samples/Controls/CategoriesFlyoutContent.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ private void CategoriesCollectionView_SelectionChanged(object sender, SelectionC
2929
selectedCategory.IsSelected = true;
3030
previousCategory.IsSelected = false;
3131

32-
_viewModel.CategorySelected(selectedCategory.CategoryName);
32+
FlyoutMenuViewModel.CategorySelected(selectedCategory.CategoryName);
3333

3434
}
3535
catch (Exception ex)
3636
{
3737
Debug.Write(ex.ToString());
3838
}
3939
}
40-
}
40+
}

src/MAUI/Maui.Samples/ViewModels/CategoryViewModel.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ArcGIS.ViewModels
1111
{
1212
public partial class CategoryViewModel : ObservableObject
1313
{
14-
private static readonly string DefaultCategory = "Featured";
14+
private const string DefaultCategory = "Featured";
1515
private double _sampleImageWidth;
1616
private double _sampleImageHeight;
1717
public double SampleImageWidth => _sampleImageWidth;
@@ -71,7 +71,7 @@ private void UpdateCategory(string category)
7171
SamplesItems = samplesCollection;
7272
}
7373

74-
private List<SampleInfo> GetSamplesInCategory(string category)
74+
private static List<SampleInfo> GetSamplesInCategory(string category)
7575
{
7676
var categoryNode = SampleManager.Current.FullTree.Items.OfType<SearchableTreeNode>().FirstOrDefault(c => c.Name == category);
7777

@@ -100,7 +100,7 @@ void UpdateFavorite(string sampleFormalName)
100100
}
101101

102102
[RelayCommand]
103-
void SampleSelected(SampleViewModel sampleViewModel)
103+
static void SampleSelected(SampleViewModel sampleViewModel)
104104
{
105105
if(SampleManager.Current.SelectedSample == null)
106106
_ = SampleLoader.LoadSample(sampleViewModel.SampleObject);

src/MAUI/Maui.Samples/ViewModels/FlyoutMenuViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private void Initialize()
6868
[ObservableProperty]
6969
private ObservableCollection<FlyoutCategoryViewModel> _categories;
7070

71-
public void CategorySelected(string categoryName)
71+
public static void CategorySelected(string categoryName)
7272
{
7373
WeakReferenceMessenger.Default.Send(categoryName);
7474
}

src/MAUI/Maui.Samples/ViewModels/SearchViewModel.cs

+5-8
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void PerformSearch()
4848
else
4949
{
5050
// Remove punctuation from the search text and any trailing white space at the end.
51-
var searchKeywords = GetKeywords(SearchText);
51+
var searchKeywords = SearchViewModel.GetKeywords(SearchText);
5252

5353
// Check if the keywords are the same as the previous search.
5454
if (Enumerable.SequenceEqual(searchKeywords, _previousSearchKeywords))
@@ -84,7 +84,7 @@ void PerformSearch()
8484

8585
try
8686
{
87-
if (sampleResults.Any())
87+
if (sampleResults.Count != 0)
8888
{
8989
sampleResults = sampleResults.OrderByDescending(sampleResults => sampleResults.Score).ThenBy(sampleResults => sampleResults.SampleName).ToList();
9090
SearchItems = new ObservableCollection<SearchResultViewModel>(sampleResults);
@@ -101,7 +101,7 @@ void PerformSearch()
101101
}
102102
}
103103

104-
private int GetMatches(string[] contentKeywords, string[] searchKeywords)
104+
private static int GetMatches(string[] contentKeywords, string[] searchKeywords)
105105
{
106106
int matches = 0;
107107

@@ -123,7 +123,7 @@ private int GetMatches(string[] contentKeywords, string[] searchKeywords)
123123
return matches;
124124
}
125125

126-
private string[] GetKeywords(string text)
126+
private static string[] GetKeywords(string text)
127127
{
128128
// Remove punctuation from the search text and any trailing white space at the end.
129129
Regex regex = new Regex("[^a-zA-Z0-9 -]");
@@ -134,10 +134,7 @@ private string[] GetKeywords(string text)
134134

135135
foreach (var word in commonWords)
136136
{
137-
if (cleanedTextWords.Contains(word))
138-
{
139-
cleanedTextWords.Remove(word);
140-
}
137+
cleanedTextWords.Remove(word);
141138
}
142139

143140
return cleanedTextWords.ToArray();

src/MAUI/Maui.Samples/Views/SamplePage.xaml.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public partial class SamplePage : ContentPage
3535
{
3636
private ContentPage _sampleContent;
3737
private Assembly _assembly;
38-
private int _lastViewedFileIndex = 0;
38+
private int _lastViewedFileIndex;
3939

4040
// single-instance webviews reused on each view, to avoid a memory leak in webview
4141
private static WebView DescriptionView = new WebView();
@@ -179,21 +179,21 @@ private static IEnumerable<T> TreeWalker<T>(VisualElement root)
179179
private async Task<string> GetDescriptionHtml(SampleInfo sampleInfo)
180180
{
181181
string category = sampleInfo.Category;
182-
if (category.Contains(" "))
182+
if (category.Contains(' '))
183183
{
184184
// Make categories with spaces into titlecase folder name.
185185
category = $"{category.Split(" ")[0]}{category.Split(" ")[1][0].ToString().ToUpper()}{category.Split(" ")[1].Substring(1)}";
186186
}
187187

188188
using Stream fileStream = await FileSystem.Current.OpenAppPackageFileAsync($"Samples/{category}/{sampleInfo.FormalName}/readme.md").ConfigureAwait(false);
189189
StreamReader r = new StreamReader(fileStream);
190-
var readmeContent = r.ReadToEnd();
190+
var readmeContent = await r.ReadToEndAsync();
191191
readmeContent = Markdig.Markdown.ToHtml(readmeContent);
192192

193193
// Set CSS for dark mode or light mode.
194194
string markdownCssType = Application.Current.RequestedTheme == Microsoft.Maui.ApplicationModel.AppTheme.Dark ? "github-markdown-dark.css" : "github-markdown.css";
195195
string cssResource = _assembly.GetManifestResourceNames().Single(n => n.EndsWith($"SyntaxHighlighting.{markdownCssType}"));
196-
string cssContent = new StreamReader(_assembly.GetManifestResourceStream(cssResource)).ReadToEnd();
196+
string cssContent = await new StreamReader(_assembly.GetManifestResourceStream(cssResource)).ReadToEndAsync();
197197

198198
#if WINDOWS
199199
// Remove the readme header on Windows so it doesn't repeat the title.
@@ -205,7 +205,7 @@ private async Task<string> GetDescriptionHtml(SampleInfo sampleInfo)
205205
if (sourceStream is not null)
206206
{
207207
using var memoryStream = new MemoryStream();
208-
sourceStream.CopyTo(memoryStream);
208+
await sourceStream.CopyToAsync(memoryStream);
209209
byte[] image = memoryStream.ToArray();
210210
memoryStream.Close();
211211

@@ -502,7 +502,7 @@ private async void GitHubToolbarItem_Clicked(object sender, EventArgs e)
502502
await OpenGitHub();
503503
}
504504

505-
private async Task OpenGitHub()
505+
private static async Task OpenGitHub()
506506
{
507507
try
508508
{
@@ -529,7 +529,7 @@ private void ScreenshotButton_Clicked(object sender, EventArgs e)
529529
// Code here is adapted from the following Stack Overflow answers:
530530
// https://stackoverflow.com/q/24466482
531531
// https://stackoverflow.com/a/15537372
532-
private void SaveScreenshot(VisualElement source)
532+
private static void SaveScreenshot(VisualElement source)
533533
{
534534
double scale = ScreenshotManager.ScreenshotSettings.ScaleFactor.HasValue ? ScreenshotManager.ScreenshotSettings.ScaleFactor.Value : double.NaN;
535535

@@ -643,23 +643,23 @@ private async Task LoadContent()
643643
{
644644
var fileName = _path.Split('/').Last();
645645
var xamlPath = assembly.GetManifestResourceNames().Single(n => n.EndsWith($"{fileName}"));
646-
SourceCode = baseContent = new StreamReader(assembly.GetManifestResourceStream(xamlPath)).ReadToEnd();
646+
SourceCode = baseContent = await new StreamReader(assembly.GetManifestResourceStream(xamlPath)).ReadToEndAsync();
647647
}
648648
else
649649
{
650650
using Stream fileStream = await FileSystem.Current.OpenAppPackageFileAsync(_path).ConfigureAwait(false);
651-
SourceCode = baseContent = new StreamReader(fileStream).ReadToEnd();
651+
SourceCode = baseContent = await new StreamReader(fileStream).ReadToEndAsync();
652652
}
653653
#else
654654
using Stream fileStream = await FileSystem.Current.OpenAppPackageFileAsync(_path).ConfigureAwait(false);
655-
SourceCode = baseContent = new StreamReader(fileStream).ReadToEnd();
655+
SourceCode = baseContent = await new StreamReader(fileStream).ReadToEndAsync();
656656
#endif
657657
// For xaml files, search for dynamic resource styles, taking into account any whitespace.
658658
if (_path.EndsWith(".xaml") && String.Concat(baseContent.Where(c => !Char.IsWhiteSpace(c)))
659659
.Contains("Style=\"{DynamicResource"))
660660
{
661661
// Display a comment on the second line of the file.
662-
baseContent = baseContent.Insert(baseContent.IndexOf(">")+1,
662+
baseContent = baseContent.Insert(baseContent.IndexOf('>')+1,
663663
"\n<!-- Styles used in this sample can be copied from Resources/Styles/Styles.xaml. -->");
664664
}
665665

@@ -672,15 +672,15 @@ private async Task LoadContent()
672672
// Set CSS for dark mode or light mode.
673673
string markdownCssType = Application.Current.RequestedTheme == Microsoft.Maui.ApplicationModel.AppTheme.Dark ? "highlight-dark.css" : "highlight.css";
674674
string cssResource = assembly.GetManifestResourceNames().Single(n => n.EndsWith($"SyntaxHighlighting.{markdownCssType}"));
675-
string cssContent = new StreamReader(assembly.GetManifestResourceStream(cssResource)).ReadToEnd();
675+
string cssContent = await new StreamReader(assembly.GetManifestResourceStream(cssResource)).ReadToEndAsync();
676676

677677
// Set the background color. Color values are taken from corresponding css files.
678678
string backgroundColor = Application.Current.RequestedTheme == Microsoft.Maui.ApplicationModel.AppTheme.Dark ? "#1e1e1e" : "#fff";
679679
cssContent = $"{cssContent} body {{ background: {backgroundColor};}}";
680680

681681
// Read javascript content.
682682
string jsResource = assembly.GetManifestResourceNames().Single(n => n.EndsWith($"SyntaxHighlighting.highlight.js"));
683-
string jsContent = new StreamReader(assembly.GetManifestResourceStream(jsResource)).ReadToEnd();
683+
string jsContent = await new StreamReader(assembly.GetManifestResourceStream(jsResource)).ReadToEndAsync();
684684

685685
// Build the html.
686686
_fullContent =

0 commit comments

Comments
 (0)