Skip to content

Commit

Permalink
Upgrade to .net 8
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-work committed May 23, 2024
1 parent 1741fda commit b925f61
Show file tree
Hide file tree
Showing 87 changed files with 503 additions and 777 deletions.
13 changes: 13 additions & 0 deletions src/.idea/.idea.PASopa/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/.idea/.idea.PASopa/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/.idea/.idea.PASopa/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/.idea.PASopa/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 23 additions & 29 deletions src/PAModel/CanvasDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
namespace Microsoft.PowerPlatform.Formulas.Tools;

/// <summary>
/// Represents a PowerApps document. This can be save/loaded from a MsApp or Source representation.
/// This is a full in-memory representation of the msapp file.
/// Represents a PowerApps document. This can be save/loaded from a MsApp or Source representation.
/// This is a full in-memory representation of the msapp file.
/// </summary>
public class CanvasDocument
{
/// <summary>
/// Current source format version.
/// Current source format version.
/// </summary>
public static Version CurrentSourceVersion => SourceSerializer.CurrentSourceVersion;

// Rules for CanvasDocument
// - Save/Load must faithfully roundtrip an msapp exactly.
// - this is an in-memory representation - so it must parse/shard everything on load.
// - Save should not mutate any state.
// - Save/Load must faithfully roundtrip an msapp exactly.
// - this is an in-memory representation - so it must parse/shard everything on load.
// - Save should not mutate any state.

// Track all unknown "files". Ensures round-tripping isn't lossy.
// Track all unknown "files". Ensures round-tripping isn't lossy.
// Only contains files of FileKind.Unknown
internal Dictionary<FilePath, FileEntry> _unknownFiles = new();

Expand All @@ -42,7 +42,7 @@ public class CanvasDocument
internal EditorStateStore _editorStateStore;
internal TemplateStore _templateStore;

// Various data sources
// Various data sources
// This is references\dataSources.json
// Also includes entries for DataSources made from a DataComponent
// Key is parent entity name (datasource name for non cds data sources)
Expand Down Expand Up @@ -76,15 +76,15 @@ public class CanvasDocument
internal IDictionary<string, LocalDatabaseReferenceJson> _dataSourceReferences;

// Extracted from _properties.LibraryDependencies
// Must preserve server ordering.
// Must preserve server ordering.
internal ComponentDependencyInfo[] _libraryReferences;

internal FileEntry _logoFile;

// Save for roundtripping.
internal Entropy _entropy = new();

// Checksum from existing msapp.
// Checksum from existing msapp.
internal ChecksumJson _checksum;

// Track all asset files, key is file name
Expand All @@ -102,7 +102,7 @@ public class CanvasDocument
#region Save/Load

/// <summary>
/// Load an .msapp file for a Canvas Document.
/// Load an .msapp file for a Canvas Document.
/// </summary>
/// <param name="fullPathToMsApp">path to an .msapp file</param>
/// <returns>A tuple of the document and errors and warnings. If there are errors, the document is null. </returns>
Expand Down Expand Up @@ -218,7 +218,7 @@ public static (CanvasDocument, ErrorContainer) MakeFromSources(string appName, s

#endregion

// Wrapper to ensure consistent invariants between loading a document, exception handling, and returning errors.
// Wrapper to ensure consistent invariants between loading a document, exception handling, and returning errors.
private static CanvasDocument Wrapper(Func<CanvasDocument> worker, ErrorContainer errors)
{
try
Expand Down Expand Up @@ -320,7 +320,7 @@ internal CanvasDocument(CanvasDocument other)
_localAssetInfoJson = other._localAssetInfoJson.JsonClone();
}

// iOrder is used to preserve ordering value for round-tripping.
// iOrder is used to preserve ordering value for round-tripping.
internal void AddDataSourceForLoad(DataSourceEntry ds, int? order = null)
{
// Key is parent entity name
Expand Down Expand Up @@ -376,7 +376,7 @@ internal void ApplyAfterMsAppLoadTransforms(ErrorContainer errors)
var componentInstanceTransform = new ComponentInstanceTransform(errors);
var componentDefTransform = new ComponentDefinitionTransform(errors, _templateStore, componentInstanceTransform);

// Transform component definitions and populate template set of component instances that need updates
// Transform component definitions and populate template set of component instances that need updates
foreach (var ctrl in _components)
{
AddComponentDefaults(ctrl.Value, templateDefaults);
Expand Down Expand Up @@ -433,7 +433,7 @@ internal void ApplyBeforeMsAppWriteTransforms(ErrorContainer errors)
var componentInstanceTransform = new ComponentInstanceTransform(errors);
var componentDefTransform = new ComponentDefinitionTransform(errors, _templateStore, componentInstanceTransform);

// Transform component definitions and populate template set of component instances that need updates
// Transform component definitions and populate template set of component instances that need updates
foreach (var ctrl in _components)
{
componentDefTransform.BeforeWrite(ctrl.Value);
Expand Down Expand Up @@ -466,10 +466,10 @@ private void AddComponentDefaults(BlockNode topParent, Dictionary<string, Contro
}


// Called after loading. This will check internal fields and fill in consistency data.
// Called after loading. This will check internal fields and fill in consistency data.
internal void OnLoadComplete(ErrorContainer errors)
{
// Do integrity checks.
// Do integrity checks.
if (_header == null)
{
errors.FormatNotSupported("Missing header file");
Expand Down Expand Up @@ -502,7 +502,7 @@ internal void OnLoadComplete(ErrorContainer errors)
}
}

// Get ComponentIds for components we've imported.
// Get ComponentIds for components we've imported.
internal HashSet<string> GetImportedComponents()
{
var set = new HashSet<string>();
Expand Down Expand Up @@ -679,21 +679,15 @@ private void RestoreAssetFilePaths(ErrorContainer errors)
}
}

// Helper for traversing and ensuring unique control names.
internal class UniqueControlNameVisitor
// Helper for traversing and ensuring unique control names.
internal class UniqueControlNameVisitor(ErrorContainer errors)
{
// Control names are case sensitive.
// Control names are case sensitive.
private readonly Dictionary<string, SourceLocation?> _names = new(StringComparer.Ordinal);
private readonly ErrorContainer _errors;

public UniqueControlNameVisitor(ErrorContainer errors)
{
_errors = errors;
}

public void Visit(BlockNode node)
{
// Ignore test templates here.
// Ignore test templates here.
// Test templates have control-like syntax, but allowed to repeat names:
// Step4 As TestStep:
if (AppTestTransform.IsTestSuite(node.Name.Kind.TypeName))
Expand All @@ -712,7 +706,7 @@ public void Visit(TypedNameNode node)
{
if (_names.TryGetValue(node.Identifier, out var existing))
{
_errors.DuplicateSymbolError(node.SourceSpan.GetValueOrDefault(), node.Identifier, existing.GetValueOrDefault());
errors.DuplicateSymbolError(node.SourceSpan.GetValueOrDefault(), node.Identifier, existing.GetValueOrDefault());
}
else
{
Expand Down
16 changes: 8 additions & 8 deletions src/PAModel/Checksum/IHashMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Microsoft.PowerPlatform.Formulas.Tools;

// Helpers for creating checksums.
// Helpers for creating checksums.
internal interface IHashMaker : IDisposable
{
void AppendStartObj();
Expand All @@ -24,11 +24,11 @@ internal interface IHashMaker : IDisposable
void AppendData(bool value);
void AppendNull();

// Called after all Appends().
// Called after all Appends().
byte[] GetFinalValue();
}

// Create a checksum using an incremental hash.
// Create a checksum using an incremental hash.
internal class Sha256HashMaker : IHashMaker, IDisposable
{
private readonly IncrementalHash _hash;
Expand All @@ -37,11 +37,11 @@ internal class Sha256HashMaker : IHashMaker, IDisposable
private static readonly byte[] _endObj = "}"u8.ToArray();
private static readonly byte[] _startArray = "["u8.ToArray();
private static readonly byte[] _endArray = "]"u8.ToArray();
private static readonly byte[] _null = new byte[] { 254 };
private static readonly byte[] _true = new byte[] { 1 };
private static readonly byte[] _false = new byte[] { 0 };
private static readonly byte[] _null = [254];
private static readonly byte[] _true = [1];
private static readonly byte[] _false = [0];

private static readonly byte[] _marker = new byte[] { 255 };
private static readonly byte[] _marker = [255];

public Sha256HashMaker()
{
Expand Down Expand Up @@ -120,7 +120,7 @@ public byte[] GetFinalValue()


// A debug version of the checksum maker that captures the full raw normalized input.
// If a checksum doesn't match, re-run it with this algorithm and you can see and diff the raw inputs.
// If a checksum doesn't match, re-run it with this algorithm and you can see and diff the raw inputs.
internal class DebugTextHashMaker : IHashMaker
{
private readonly Utf8JsonWriter _writer;
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/Collections/LazyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class LazyList<T> : IEnumerable<T>
{
private readonly IEnumerable<T> values;

public static readonly LazyList<T> Empty = new(Enumerable.Empty<T>());
public static readonly LazyList<T> Empty = new([]);

public LazyList(IEnumerable<T> values)
{
Expand Down
18 changes: 5 additions & 13 deletions src/PAModel/ControlTemplates/ControlProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@

namespace Microsoft.PowerPlatform.Formulas.Tools.ControlTemplates;

internal sealed class ControlProperty
internal sealed class ControlProperty(string name, string defaultVal, string phoneDefault, string webDefault)
{
public string Name { get; }
public string DefaultValue { get; }
public string PhoneDefaultValue { get; }
public string WebDefaultValue { get; }

public ControlProperty(string name, string defaultVal, string phoneDefault, string webDefault)
{
Name = name;
DefaultValue = defaultVal;
PhoneDefaultValue = phoneDefault;
WebDefaultValue = webDefault;
}
public string Name { get; } = name;
public string DefaultValue { get; } = defaultVal;
public string PhoneDefaultValue { get; } = phoneDefault;
public string WebDefaultValue { get; } = webDefault;

public string GetDefaultValue(AppType type)
{
Expand Down
21 changes: 6 additions & 15 deletions src/PAModel/ControlTemplates/ControlTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@

namespace Microsoft.PowerPlatform.Formulas.Tools.ControlTemplates;

internal sealed class ControlTemplate
internal sealed class ControlTemplate(string name, string version, string id)
{
public string Name { get; }
public string Version { get; }
public string Id { get; }
public string Name { get; } = name;
public string Version { get; } = version;
public string Id { get; } = id;

// Property Name -> Default Expression
public Dictionary<string, string> InputDefaults { get; }
public Dictionary<string, string> InputDefaults { get; } = new();

// Variant name => property name => default expresion
public Dictionary<string, Dictionary<string, string>> VariantDefaultValues { get; }

public ControlTemplate(string name, string version, string id)
{
Name = name;
Version = version;
Id = id;
InputDefaults = new Dictionary<string, string>();
VariantDefaultValues = new Dictionary<string, Dictionary<string, string>>();
}
public Dictionary<string, Dictionary<string, string>> VariantDefaultValues { get; } = new();
}
2 changes: 1 addition & 1 deletion src/PAModel/Entropy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static string GetResourcesJsonIndicesKey(ResourceJson resource)
// Removing the 'ContentKind-' gives the resource name
public static string GetResourceNameFromKey(string key)
{
var prefix = key.Split(new char[] { '-' }).First();
var prefix = key.Split(['-']).First();
return key.Substring(prefix.Length + 1);
}

Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/Extensions/CollectionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void Add<T>(this Stack<T> stack, T item)

public static IEnumerable<T> NullOk<T>(this IEnumerable<T> list)
{
if (list == null) return Enumerable.Empty<T>();
if (list == null) return [];
return list;
}

Expand Down
9 changes: 2 additions & 7 deletions src/PAModel/IO/ControlPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace Microsoft.PowerPlatform.Formulas.Tools.IO;
/// Each segment is a control name
/// </summary>
[DebuggerDisplay("{string.Join('.', _segments)}")]
internal class ControlPath
internal class ControlPath(List<string> segments)
{
// switch this to be a queue?
private readonly List<string> _segments;
private readonly List<string> _segments = segments;
public string Current => _segments.Any() ? _segments[0] : null;
public static ControlPath Empty => new(new List<string>());

Expand All @@ -36,11 +36,6 @@ public ControlPath Append(string controlName)
return new ControlPath(newPath);
}

public ControlPath(List<string> segments)
{
_segments = segments;
}

public static bool operator ==(ControlPath left, ControlPath right)
{
return left?.Equals(right) ?? right is null;
Expand Down
Loading

0 comments on commit b925f61

Please sign in to comment.