Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: Support for Windows.ApplicationModel.Resources.Core #10948

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/Uno.UWP/ApplicationModel/Resources/Core/NamedResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;

namespace Windows.ApplicationModel.Resources.Core;

/// <summary>
/// Represents a single logical, named resource.
/// </summary>
public partial class NamedResource
{
/// <summary>
/// Gets all possible candidate values for this named resource.
/// </summary>
public IReadOnlyList<ResourceCandidate> Candidates
{
get
{
throw new global::System.NotImplementedException("The member IReadOnlyList<ResourceCandidate> NamedResource.Candidates is not implemented in Uno.");
}
}

public Uri Uri
{
get
{
throw new global::System.NotImplementedException("The member Uri NamedResource.Uri is not implemented in Uno.");
}
}

public ResourceCandidate Resolve()
{
throw new global::System.NotImplementedException("The member ResourceCandidate NamedResource.Resolve() is not implemented in Uno.");
}

public ResourceCandidate Resolve( ResourceContext resourceContext)
{
throw new global::System.NotImplementedException("The member ResourceCandidate NamedResource.Resolve(ResourceContext resourceContext) is not implemented in Uno.");
}

public global::System.Collections.Generic.IReadOnlyList<ResourceCandidate> ResolveAll()
{
throw new global::System.NotImplementedException("The member IReadOnlyList<ResourceCandidate> NamedResource.ResolveAll() is not implemented in Uno.");
}

public global::System.Collections.Generic.IReadOnlyList<ResourceCandidate> ResolveAll( ResourceContext resourceContext)
{
throw new global::System.NotImplementedException("The member IReadOnlyList<ResourceCandidate> NamedResource.ResolveAll(ResourceContext resourceContext) is not implemented in Uno.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public string GetQualifierValue(string qualifierName)
{
return Qualifiers.FirstOrDefault(qualifier => qualifier.QualifierName == qualifierName)?.QualifierValue;
}

internal static ResourceCandidate Parse(string fullPath, string relativePath)
{
var logicalPath = GetLogicalPath(relativePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Windows.ApplicationModel.Resources.Core;

/// <summary>
/// Defines values that represent the type of resource that is encapsulated in a ResourceCandidate.
/// </summary>
public enum ResourceCandidateKind
{
/// <summary>
/// The resource is a string.
/// </summary>
String,

/// <summary>
/// The resource is a file located at the specified location.
/// </summary>
File,

/// <summary>
/// The resource is embedded data in some containing resource file (such as a .resw file).
/// </summary>
EmbeddedData,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;

namespace Windows.ApplicationModel.Resources.Core;

/// <summary>
/// Represents a collection of ResourceCandidate objects.
/// </summary>
public partial class ResourceCandidateVectorView : IReadOnlyList<ResourceCandidate>, IEnumerable<ResourceCandidate>
{
private readonly IReadOnlyList<ResourceCandidate> _candidates;

internal ResourceCandidateVectorView(IReadOnlyList<ResourceCandidate> candidates)
{
_candidates = candidates;
}

public ResourceCandidate this[int index] => _candidates[index];

public int Count => _candidates.Count;

public uint Size => (uint)Count;

public IEnumerator<ResourceCandidate> GetEnumerator() => _candidates.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
80 changes: 80 additions & 0 deletions src/Uno.UWP/ApplicationModel/Resources/Core/ResourceContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace Windows.ApplicationModel.Resources.Core
{
public partial class ResourceContext
{
public ResourceContext()
{
}

public static ResourceContext GetForCurrentView() => new ResourceContext();

public static ResourceContext GetForViewIndependentUse() => new ResourceContext();

public global::System.Collections.Generic.IReadOnlyList<string> Languages
{
get
{
throw new global::System.NotImplementedException("The member IReadOnlyList<string> ResourceContext.Languages is not implemented in Uno.");
}
set
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Resources.Core.ResourceContext", "IReadOnlyList<string> ResourceContext.Languages");
}
}
public global::Windows.Foundation.Collections.IObservableMap<string, string> QualifierValues
{
get
{
throw new global::System.NotImplementedException("The member IObservableMap<string, string> ResourceContext.QualifierValues is not implemented in Uno.");
}
}

public static ResourceContext GetForUIContext(global::Windows.UI.UIContext context)
{
throw new global::System.NotImplementedException("The member ResourceContext ResourceContext.GetForUIContext(UIContext context) is not implemented in Uno.");
}

public void Reset()
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Resources.Core.ResourceContext", "void ResourceContext.Reset()");
}

public void Reset(global::System.Collections.Generic.IEnumerable<string> qualifierNames)
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Resources.Core.ResourceContext", "void ResourceContext.Reset(IEnumerable<string> qualifierNames)");
}

public void OverrideToMatch(global::System.Collections.Generic.IEnumerable<ResourceQualifier> result)
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Resources.Core.ResourceContext", "void ResourceContext.OverrideToMatch(IEnumerable<ResourceQualifier> result)");
}

public ResourceContext Clone()
{
throw new global::System.NotImplementedException("The member ResourceContext ResourceContext.Clone() is not implemented in Uno.");
}

public static void SetGlobalQualifierValue(string key, string value, ResourceQualifierPersistence persistence)
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Resources.Core.ResourceContext", "void ResourceContext.SetGlobalQualifierValue(string key, string value, ResourceQualifierPersistence persistence)");
}


public static void SetGlobalQualifierValue(string key, string value)
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Resources.Core.ResourceContext", "void ResourceContext.SetGlobalQualifierValue(string key, string value)");
}
public static void ResetGlobalQualifierValues()
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Resources.Core.ResourceContext", "void ResourceContext.ResetGlobalQualifierValues()");
}
public static void ResetGlobalQualifierValues(global::System.Collections.Generic.IEnumerable<string> qualifierNames)
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Resources.Core.ResourceContext", "void ResourceContext.ResetGlobalQualifierValues(IEnumerable<string> qualifierNames)");
}
public static ResourceContext CreateMatchingContext(global::System.Collections.Generic.IEnumerable<ResourceQualifier> result)
{
throw new global::System.NotImplementedException("The member ResourceContext ResourceContext.CreateMatchingContext(IEnumerable<ResourceQualifier> result) is not implemented in Uno.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;

namespace Windows.ApplicationModel.Resources.Core;

/// <summary>
/// Represents a collection of ResourceContext language qualifiers.
/// </summary>
public partial class ResourceContextLanguagesVectorView : IReadOnlyList<string>, IEnumerable<string>
{
private readonly IReadOnlyList<string> _languages;

internal ResourceContextLanguagesVectorView(IReadOnlyList<string> languages)
{
_languages = languages;
}

public string this[int index] => _languages[index];

public int Count => _languages.Count;

public uint Size => (uint)Count;

public IEnumerator<string> GetEnumerator() => _languages.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
32 changes: 32 additions & 0 deletions src/Uno.UWP/ApplicationModel/Resources/Core/ResourceLayoutInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Windows.ApplicationModel.Resources.Core;

/// <summary>
/// Structure that determines version and counts of resources returned for the app package.
/// </summary>
public partial struct ResourceLayoutInfo
{
/// <summary>
/// Major version of resources to be returned.
/// </summary>
public uint MajorVersion;

/// <summary>
/// Minor version of resources to be returned.
/// </summary>
public uint MinorVersion;

/// <summary>
/// Number of resource subtrees to be returned.
/// </summary>
public uint ResourceSubtreeCount;

/// <summary>
/// Number of named resources to be returned.
/// </summary>
public uint NamedResourceCount;

/// <summary>
/// Framework-generated checksum.
/// </summary>
public int Checksum;
}
58 changes: 58 additions & 0 deletions src/Uno.UWP/ApplicationModel/Resources/Core/ResourceManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Linq;

namespace Windows.ApplicationModel.Resources.Core;

/// <summary>
/// Provides access to application resource maps and more advanced resource functionality.
/// </summary>
public partial class ResourceManager
{
private Dictionary<string, ResourceMap> _resourceMaps;

private ResourceManager() { }

/// <summary>
/// Gets the ResourceManager for the currently running application.
/// </summary>
public static ResourceManager Current { get; } = new ResourceManager();

/// <summary>
/// Gets the default ResourceContext for the currently running application.
/// Unless explicitly overridden, the default ResourceContext is used to determine
/// the most appropriate representation of any given named resource.
/// </summary>
public ResourceContext DefaultContext { get; } = new ResourceContext();

public IReadOnlyDictionary<string, ResourceMap> AllResourceMaps => new ResourceMapMapView(_resourceMaps.AsReadOnly());

public ResourceMap MainResourceMap
{
get
{
throw new global::System.NotImplementedException("The member ResourceMap ResourceManager.MainResourceMap is not implemented in Uno.");
}
}

public void LoadPriFiles( global::System.Collections.Generic.IEnumerable<global::Windows.Storage.IStorageFile> files)
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Resources.Core.ResourceManager", "void ResourceManager.LoadPriFiles(IEnumerable<IStorageFile> files)");
}
public void UnloadPriFiles( global::System.Collections.Generic.IEnumerable<global::Windows.Storage.IStorageFile> files)
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.ApplicationModel.Resources.Core.ResourceManager", "void ResourceManager.UnloadPriFiles(IEnumerable<IStorageFile> files)");
}
public global::System.Collections.Generic.IReadOnlyList<NamedResource> GetAllNamedResourcesForPackage( string packageName, ResourceLayoutInfo resourceLayoutInfo)
{
throw new global::System.NotImplementedException("The member IReadOnlyList<NamedResource> ResourceManager.GetAllNamedResourcesForPackage(string packageName, ResourceLayoutInfo resourceLayoutInfo) is not implemented in Uno.");
}

public global::System.Collections.Generic.IReadOnlyList<ResourceMap> GetAllSubtreesForPackage( string packageName, ResourceLayoutInfo resourceLayoutInfo)
{
throw new global::System.NotImplementedException("The member IReadOnlyList<ResourceMap> ResourceManager.GetAllSubtreesForPackage(string packageName, ResourceLayoutInfo resourceLayoutInfo) is not implemented in Uno.");
}
public static bool IsResourceReference( string resourceReference)
{
throw new global::System.NotImplementedException("The member bool ResourceManager.IsResourceReference(string resourceReference) is not implemented in Uno.");
}
}
56 changes: 56 additions & 0 deletions src/Uno.UWP/ApplicationModel/Resources/Core/ResourceMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace Windows.ApplicationModel.Resources.Core;

public partial class ResourceMap : IReadOnlyDictionary<string, NamedResource>, IEnumerable<KeyValuePair<string, NamedResource>>
{
private readonly Dictionary<string, NamedResource> _namedResources;

internal ResourceMap(Dictionary<string, NamedResource> namedResources)
{
_namedResources = namedResources;
}

public Uri Uri
{
get
{
throw new global::System.NotImplementedException("The member Uri ResourceMap.Uri is not implemented in Uno.");
}
}

public int Count => _namedResources;

public uint Size => (uint)Count;

public ResourceCandidate GetValue( string resource)
{
throw new global::System.NotImplementedException("The member ResourceCandidate ResourceMap.GetValue(string resource) is not implemented in Uno.");
}

public ResourceCandidate GetValue( string resource, ResourceContext context)
{
throw new global::System.NotImplementedException("The member ResourceCandidate ResourceMap.GetValue(string resource, ResourceContext context) is not implemented in Uno.");
}

public ResourceMap GetSubtree( string reference)
{
throw new global::System.NotImplementedException("The member ResourceMap ResourceMap.GetSubtree(string reference) is not implemented in Uno.");
}

public bool ContainsKey(string key) => _namedResources.ContainsKey(key);

public bool TryGetValue(string key, out NamedResource value) => _namedResources.TryGetValue(key, out value);

public NamedResource this[string key] => _namedResources[key];

public IEnumerable<string> Keys => _namedResources.Keys;

public IEnumerable<NamedResource> Values => _namedResources.Values;

public IEnumerator<KeyValuePair<string, NamedResource>> GetEnumerator() => _namedResources.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
Loading