Serialization for LoadResult

This commit is contained in:
Yoshi Askharoun
2023-05-26 13:56:50 -05:00
parent caed31afb9
commit cce208c4ea
11 changed files with 207 additions and 31 deletions
@@ -13,6 +13,7 @@ using System;
namespace Microsoft.Iris.CodeModel.Cpp
{
[Serializable]
internal class DllLoadResult : LoadResult
{
private DllLoadResultFactory _source;
@@ -21,7 +22,7 @@ namespace Microsoft.Iris.CodeModel.Cpp
private IntPtr _schema;
private Map<uint, TypeSchema> _userDefinedTypes;
private Map<uint, TypeSchema> _intrinsicTypes;
private static Map<uint, DllLoadResult.IntrinsicTypeData> s_intrinsicData;
private static Map<uint, IntrinsicTypeData> s_intrinsicData;
private ushort _component;
private static ushort s_nextID = 1;
private static LoadResult s_objectContext;
@@ -35,18 +36,18 @@ namespace Microsoft.Iris.CodeModel.Cpp
private static void LoadIntrinsicTypeData()
{
s_intrinsicData = new Map<uint, DllLoadResult.IntrinsicTypeData>();
s_intrinsicData[4294967294U] = new DllLoadResult.IntrinsicTypeData(BooleanSchema.Type);
s_intrinsicData[4294967293U] = new DllLoadResult.IntrinsicTypeData(ByteSchema.Type);
s_intrinsicData[4294967292U] = new DllLoadResult.IntrinsicTypeData(DoubleSchema.Type);
s_intrinsicData[4294967285U] = new DllLoadResult.IntrinsicTypeData(ListSchema.Type, typeof(DllProxyList));
s_intrinsicData[4294967284U] = new DllLoadResult.IntrinsicTypeData(ImageSchema.Type);
s_intrinsicData[4294967283U] = new DllLoadResult.IntrinsicTypeData(Int32Schema.Type);
s_intrinsicData[4294967282U] = new DllLoadResult.IntrinsicTypeData(Int64Schema.Type);
s_intrinsicData[4294967280U] = new DllLoadResult.IntrinsicTypeData(ObjectSchema.Type);
s_intrinsicData[4294967279U] = new DllLoadResult.IntrinsicTypeData(SingleSchema.Type);
s_intrinsicData[4294967278U] = new DllLoadResult.IntrinsicTypeData(StringSchema.Type);
s_intrinsicData[4294967277U] = new DllLoadResult.IntrinsicTypeData(VoidSchema.Type);
s_intrinsicData = new Map<uint, IntrinsicTypeData>();
s_intrinsicData[4294967294U] = new IntrinsicTypeData(BooleanSchema.Type);
s_intrinsicData[4294967293U] = new IntrinsicTypeData(ByteSchema.Type);
s_intrinsicData[4294967292U] = new IntrinsicTypeData(DoubleSchema.Type);
s_intrinsicData[4294967285U] = new IntrinsicTypeData(ListSchema.Type, typeof(DllProxyList));
s_intrinsicData[4294967284U] = new IntrinsicTypeData(ImageSchema.Type);
s_intrinsicData[4294967283U] = new IntrinsicTypeData(Int32Schema.Type);
s_intrinsicData[4294967282U] = new IntrinsicTypeData(Int64Schema.Type);
s_intrinsicData[4294967280U] = new IntrinsicTypeData(ObjectSchema.Type);
s_intrinsicData[4294967279U] = new IntrinsicTypeData(SingleSchema.Type);
s_intrinsicData[4294967278U] = new IntrinsicTypeData(StringSchema.Type);
s_intrinsicData[4294967277U] = new IntrinsicTypeData(VoidSchema.Type);
}
public static void Shutdown() => DllProxyServices.Shutdown();
@@ -90,7 +91,7 @@ namespace Microsoft.Iris.CodeModel.Cpp
if (_intrinsicTypes == null)
_intrinsicTypes = new Map<uint, TypeSchema>();
TypeSchema typeSchema;
DllLoadResult.IntrinsicTypeData intrinsicTypeData;
IntrinsicTypeData intrinsicTypeData;
if (!_intrinsicTypes.TryGetValue(typeID, out typeSchema) && s_intrinsicData.TryGetValue(typeID, out intrinsicTypeData))
{
typeSchema = !intrinsicTypeData.DemandCreateTypeSchema ? intrinsicTypeData.FrameworkEquivalent : new DllIntrinsicTypeSchema(this, typeID, intrinsicTypeData.FrameworkEquivalent);
@@ -304,7 +305,7 @@ namespace Microsoft.Iris.CodeModel.Cpp
}
else
{
DllLoadResult.IntrinsicTypeData intrinsicTypeData;
IntrinsicTypeData intrinsicTypeData;
if (s_intrinsicData.TryGetValue(marshalAs, out intrinsicTypeData))
type = intrinsicTypeData.MarshalAsRuntimeType;
}
+29 -13
View File
@@ -15,9 +15,11 @@ using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace Microsoft.Iris.Markup
{
[Serializable]
internal class AssemblyLoadResult : LoadResult
{
private const string c_AssemblyProtocol = "assembly://";
@@ -30,13 +32,19 @@ namespace Microsoft.Iris.Markup
public static TypeSchema DictionaryTypeSchema;
public static TypeSchema CommandTypeSchema;
public static TypeSchema ValueRangeTypeSchema;
private static Map s_typeCache = new Map(32);
private static Map<AssemblyLoadResult.MapAssemblyKey, AssemblyLoadResult> s_assemblyCache = new Map<AssemblyLoadResult.MapAssemblyKey, AssemblyLoadResult>();
private static Map s_typeCache = new(32);
private static Map<MapAssemblyKey, AssemblyLoadResult> s_assemblyCache = new();
protected AssemblyLoadResult(SerializationInfo info, StreamingContext context) : base(info, context)
{
_namespace = info.GetString(nameof(Namespace));
_assembly = info.GetValue<Assembly>(nameof(Assembly));
}
private static LoadResult Create(string uri)
{
LoadResult loadResult = null;
string valueName = uri.Substring("assembly://".Length);
string valueName = uri.Substring(c_AssemblyProtocol.Length);
if (valueName.IndexOf('/') == -1)
{
ErrorManager.ReportError("Invalid assembly reference '{0}'. URI must contain a forward slash after the assembly name", uri);
@@ -78,7 +86,7 @@ namespace Microsoft.Iris.Markup
public static void Startup()
{
AssemblyObjectProxyHelper.InitializeStatics();
MarkupSystem.RegisterFactoryByProtocol("assembly://", new CreateLoadResultHandler(Create));
MarkupSystem.RegisterFactoryByProtocol(c_AssemblyProtocol, new CreateLoadResultHandler(Create));
Map typeCache1 = s_typeCache;
Type type1 = typeof(object);
FrameworkCompatibleAssemblyPrimitiveTypeSchema primitiveTypeSchema;
@@ -135,16 +143,16 @@ namespace Microsoft.Iris.Markup
TypeSchema.RegisterOneWayEquivalence((TypeSchema)(s_typeCache[typeof(Type)] = new FrameworkCompatibleAssemblyTypeSchema(typeof(Type), typeof(TypeSchema), null, ObjectTypeSchema)), TypeSchemaDefinition.Type);
TypeSchema.RegisterOneWayEquivalence((TypeSchema)(s_typeCache[typeof(VideoStream)] = new FrameworkCompatibleAssemblyTypeSchema(typeof(VideoStream))), VideoStreamSchema.Type);
TypeSchema producer4;
s_typeCache[typeof(Microsoft.Iris.Choice)] = (FrameworkCompatibleAssemblyTypeSchema)(producer4 = new FrameworkCompatibleAssemblyTypeSchema(typeof(Microsoft.Iris.Choice)));
s_typeCache[typeof(Choice)] = (FrameworkCompatibleAssemblyTypeSchema)(producer4 = new FrameworkCompatibleAssemblyTypeSchema(typeof(Choice)));
TypeSchema.RegisterOneWayEquivalence(producer4, ChoiceSchema.Type);
TypeSchema.RegisterOneWayEquivalence(producer4, ValueRangeSchema.Type);
TypeSchema.RegisterOneWayEquivalence((TypeSchema)(s_typeCache[typeof(Microsoft.Iris.BooleanChoice)] = new FrameworkCompatibleAssemblyTypeSchema(typeof(Microsoft.Iris.BooleanChoice))), BooleanChoiceSchema.Type);
TypeSchema.RegisterOneWayEquivalence((TypeSchema)(s_typeCache[typeof(BooleanChoice)] = new FrameworkCompatibleAssemblyTypeSchema(typeof(BooleanChoice))), BooleanChoiceSchema.Type);
TypeSchema producer5;
s_typeCache[typeof(Microsoft.Iris.RangedValue)] = (FrameworkCompatibleAssemblyTypeSchema)(producer5 = new FrameworkCompatibleAssemblyTypeSchema(typeof(Microsoft.Iris.RangedValue)));
s_typeCache[typeof(RangedValue)] = (FrameworkCompatibleAssemblyTypeSchema)(producer5 = new FrameworkCompatibleAssemblyTypeSchema(typeof(RangedValue)));
TypeSchema.RegisterOneWayEquivalence(producer5, RangedValueSchema.Type);
TypeSchema.RegisterOneWayEquivalence(producer5, ValueRangeSchema.Type);
TypeSchema.RegisterOneWayEquivalence((TypeSchema)(s_typeCache[typeof(Microsoft.Iris.IntRangedValue)] = new FrameworkCompatibleAssemblyTypeSchema(typeof(Microsoft.Iris.IntRangedValue))), IntRangedValueSchema.Type);
TypeSchema.RegisterOneWayEquivalence((TypeSchema)(s_typeCache[typeof(Microsoft.Iris.ByteRangedValue)] = new FrameworkCompatibleAssemblyTypeSchema(typeof(Microsoft.Iris.ByteRangedValue))), ByteRangedValueSchema.Type);
TypeSchema.RegisterOneWayEquivalence((TypeSchema)(s_typeCache[typeof(IntRangedValue)] = new FrameworkCompatibleAssemblyTypeSchema(typeof(IntRangedValue))), IntRangedValueSchema.Type);
TypeSchema.RegisterOneWayEquivalence((TypeSchema)(s_typeCache[typeof(ByteRangedValue)] = new FrameworkCompatibleAssemblyTypeSchema(typeof(ByteRangedValue))), ByteRangedValueSchema.Type);
TypeSchema.RegisterTwoWayEquivalence((TypeSchema)(s_typeCache[typeof(DataProviderQuery)] = new FrameworkCompatibleAssemblyTypeSchema(typeof(DataProviderQuery), typeof(MarkupDataQuery))), MarkupDataQueryInstanceSchema.Type);
TypeSchema.RegisterTwoWayEquivalence((TypeSchema)(s_typeCache[typeof(DataProviderObject)] = new FrameworkCompatibleAssemblyTypeSchema(typeof(DataProviderObject), typeof(MarkupDataType))), MarkupDataTypeInstanceSchema.Type);
TypeSchema.RegisterTwoWayEquivalence((TypeSchema)(s_typeCache[typeof(DataProviderQueryStatus)] = new FrameworkCompatibleAssemblyTypeSchema(typeof(DataProviderQueryStatus))), UIXLoadResultExports.DataQueryStatusType);
@@ -182,11 +190,11 @@ namespace Microsoft.Iris.Markup
public static AssemblyLoadResult MapAssembly(Assembly assembly, string ns)
{
AssemblyLoadResult.MapAssemblyKey key = new AssemblyLoadResult.MapAssemblyKey(assembly, ns);
MapAssemblyKey key = new MapAssemblyKey(assembly, ns);
AssemblyLoadResult assemblyLoadResult;
if (!s_assemblyCache.TryGetValue(key, out assemblyLoadResult))
{
string uri = "assembly://" + assembly.FullName;
string uri = c_AssemblyProtocol + assembly.FullName;
if (ns != null)
uri = uri + "/" + ns;
assemblyLoadResult = new AssemblyLoadResult(assembly, ns, uri);
@@ -313,7 +321,7 @@ namespace Microsoft.Iris.Markup
return assembly;
}
public override string GetCompilerReferenceName() => base.GetCompilerReferenceName() ?? string.Format("{0}{1}/{2}", "assembly://", _assembly.GetName().Name, _namespace);
public override string GetCompilerReferenceName() => base.GetCompilerReferenceName() ?? $"{c_AssemblyProtocol}{_assembly.GetName().Name}/{_namespace}";
internal Assembly Assembly => _assembly;
@@ -327,6 +335,14 @@ namespace Microsoft.Iris.Markup
_namespacePrefix = ns + ".";
}
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(nameof(Namespace), Namespace);
info.AddValue(nameof(Assembly), Assembly);
}
internal struct MapAssemblyKey
{
private Assembly _assembly;
@@ -340,7 +356,7 @@ namespace Microsoft.Iris.Markup
public override bool Equals(object obj)
{
AssemblyLoadResult.MapAssemblyKey mapAssemblyKey = (AssemblyLoadResult.MapAssemblyKey)obj;
MapAssemblyKey mapAssemblyKey = (MapAssemblyKey)obj;
return _assembly == mapAssemblyKey._assembly && _namespace == mapAssemblyKey._namespace;
}
@@ -7,9 +7,11 @@
using Microsoft.Iris.Data;
using Microsoft.Iris.Session;
using System;
using System.Runtime.Serialization;
namespace Microsoft.Iris.Markup
{
[Serializable]
internal class CompiledMarkupLoadResult : MarkupLoadResult
{
private Resource _resource;
@@ -25,6 +27,10 @@ namespace Microsoft.Iris.Markup
_loader = CompiledMarkupLoader.Load(this, resource);
}
protected CompiledMarkupLoadResult(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public override bool IsSource => false;
public override MarkupConstantsTable ConstantsTable => _binaryDataTable.ConstantsTable;
@@ -4,8 +4,11 @@
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
// Assembly location: C:\Program Files\Zune\UIX.dll
using System;
namespace Microsoft.Iris.Markup
{
[Serializable]
internal class ErrorLoadResult : LoadResult
{
public ErrorLoadResult(string uri)
+25 -3
View File
@@ -7,19 +7,29 @@
using Microsoft.Iris.Library;
using Microsoft.Iris.Session;
using System;
using System.Runtime.Serialization;
namespace Microsoft.Iris.Markup
{
public abstract class LoadResult : SharedDisposableObject
[Serializable]
public abstract class LoadResult : SharedDisposableObject, ISerializable
{
private string _uri;
private readonly string _uri;
protected string _uriUnderlying;
private uint _islandReferences;
private string _compilerReferenceName;
public static LoadResult[] EmptyList = new LoadResult[0];
public static readonly LoadResult[] EmptyList = Array.Empty<LoadResult>();
public LoadResult(string uri) => _uri = uri;
protected LoadResult(SerializationInfo info, StreamingContext context)
{
_uri = info.GetString(nameof(Uri));
_uriUnderlying = info.GetString(nameof(UnderlyingUri));
_islandReferences = info.GetUInt32(nameof(IslandReferences));
_compilerReferenceName = info.GetString("CompilerReferenceName");
}
protected override void OnDispose() => base.OnDispose();
public string Uri => _uri;
@@ -113,5 +123,17 @@ namespace Microsoft.Iris.Markup
public virtual string GetCompilerReferenceName() => _compilerReferenceName;
public override string ToString() => _uri;
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(nameof(Uri), Uri);
info.AddValue(nameof(UnderlyingUri), UnderlyingUri);
info.AddValue(nameof(IslandReferences), IslandReferences);
info.AddValue(nameof(Status), Status);
info.AddValue(nameof(Cachable), Cachable);
info.AddValue(nameof(Dependencies), Dependencies);
info.AddValue(nameof(ExportTable), ExportTable);
info.AddValue("CompilerReferenceName", GetCompilerReferenceName());
}
}
}
@@ -7,9 +7,12 @@
using Microsoft.Iris.Data;
using Microsoft.Iris.Library;
using Microsoft.Iris.Session;
using System;
using System.Runtime.Serialization;
namespace Microsoft.Iris.Markup
{
[Serializable]
public abstract class MarkupLoadResult : LoadResult
{
private LoadResult[] _dependenciesTable = EmptyList;
@@ -28,6 +31,16 @@ namespace Microsoft.Iris.Markup
: base(uri)
=> _status = LoadResultStatus.Loading;
protected MarkupLoadResult(SerializationInfo info, StreamingContext context) : base(info, context)
{
_dependenciesTable = info.GetValue<LoadResult[]>(nameof(Dependencies));
_exportTable = info.GetValue<TypeSchema[]>(nameof(ExportTable));
_aliasTable = info.GetValue<AliasMapping[]>(nameof(AliasTable));
_dataMappingsTable = info.GetValue<MarkupDataMapping[]>(nameof(DataMappingsTable));
_binaryDataTable = info.GetValue<MarkupBinaryDataTable>(nameof(BinaryDataTable));
_lineNumberTable = info.GetValue<MarkupLineNumberTable>(nameof(LineNumberTable));
}
private void OnLoaded()
{
if (_dataMappingsTable == null)
@@ -176,5 +189,18 @@ namespace Microsoft.Iris.Markup
}
public virtual void MarkLoadFailed() => _status = LoadResultStatus.Error;
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(nameof(IsSource), IsSource);
info.AddValue(nameof(ImportTables), ImportTables);
info.AddValue(nameof(AliasTable), AliasTable);
info.AddValue(nameof(DataMappingsTable), DataMappingsTable);
info.AddValue(nameof(BinaryDataTable), BinaryDataTable);
info.AddValue(nameof(ConstantsTable), ConstantsTable);
info.AddValue(nameof(LineNumberTable), LineNumberTable);
}
}
}
@@ -7,9 +7,12 @@
using Microsoft.Iris.Data;
using Microsoft.Iris.Markup.Validation;
using Microsoft.Iris.Session;
using System;
using System.Runtime.Serialization;
namespace Microsoft.Iris.Markup
{
[Serializable]
internal class SourceMarkupLoadResult : MarkupLoadResult
{
private MarkupConstantsTable _constantsTable;
@@ -32,6 +35,12 @@ namespace Microsoft.Iris.Markup
{
}
protected SourceMarkupLoadResult(SerializationInfo info, StreamingContext context) : base(info, context)
{
_constantsTable = info.GetValue<MarkupConstantsTable>(nameof(ConstantsTable));
_importTables = info.GetValue<MarkupImportTables>(nameof(ImportTables));
}
public override bool IsSource => true;
internal SourceMarkupLoader Loader => _loader;
@@ -80,5 +89,12 @@ namespace Microsoft.Iris.Markup
public void SetConstantsTable(MarkupConstantsTable constantsTable) => _constantsTable = constantsTable;
public void SetImportTables(MarkupImportTables importTables) => _importTables = importTables;
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(nameof(_resource), _resource);
}
}
}
+45
View File
@@ -7,6 +7,7 @@
using Microsoft.Iris.Library;
using Microsoft.Iris.Markup.UIX;
using System;
using System.Linq;
namespace Microsoft.Iris.Markup
{
@@ -245,6 +246,50 @@ namespace Microsoft.Iris.Markup
return typeSchema;
}
private static bool IsBasicType(TypeSchema type) =>
type == null || type.RuntimeType.Assembly.FullName.Contains("CoreLib") || type.Properties.Length == 0;
public static void GenerateModelCode(TypeSchema dataType)
{
string code =
"using Microsoft.Iris.Markup;\r\n\r\n" +
"namespace Microsoft.Zune.Schemas;\r\n\r\n" +
"public class " + dataType.Name;
if (!IsBasicType(dataType.Base))
{
code += $" : {dataType.Base.Name}";
GenerateModelCode(dataType.Base);
}
else
{
code += $" : MarkupDataType";
}
code += "\r\n{\r\n";
code += $" public {dataType.Name}(MarkupTypeSchema schema) : base(schema)\r\n";
code += " {\r\n";
code += " }\r\n\r\n";
foreach (var prop in dataType.Properties)
{
string propType = prop.PropertyType.AlternateName ?? prop.PropertyType.Name;
code += $" public {propType} {prop.Name}\r\n";
code += " {\r\n";
code += $" get => GetProperty<{propType}>();\r\n";
code += $" set => SetProperty(value);\r\n";
code += " }\r\n\r\n";
if (!IsBasicType(prop.PropertyType) && !Application.DebugSettings.DataMappingModels.Any(m => m.Type == propType))
GenerateModelCode(prop.PropertyType);
}
code += "}";
Application.DebugSettings.DataMappingModels.Add(new(dataType.RuntimeType.Name, dataType.Name, code));
}
public override string ToString() => $"typeof({Name})";
}
}
@@ -6,9 +6,12 @@
using Microsoft.Iris.Library;
using Microsoft.Iris.Markup.UIX;
using System;
using System.Runtime.Serialization;
namespace Microsoft.Iris.Markup
{
[Serializable]
internal class UIXLoadResult : LoadResult
{
public UIXLoadResult(string uri)
@@ -16,6 +19,11 @@ namespace Microsoft.Iris.Markup
{
}
protected UIXLoadResult(SerializationInfo info, StreamingContext context) : base(info, context)
{
UIXLoadResultExports.ExportTable = info.GetValue<TypeSchema[]>(nameof(ExportTable));
}
public static void InitializeStatics() => UIXLoadResultExports.InitializeStatics();
public override TypeSchema[] ExportTable => UIXLoadResultExports.ExportTable;
+15
View File
@@ -5,9 +5,12 @@
// Assembly location: C:\Program Files\Zune\UIX.dll
using Microsoft.Iris.Markup;
using System;
using System.Runtime.Serialization;
namespace Microsoft.Iris.UI
{
[Serializable]
internal class RootLoadResult : MarkupLoadResult
{
public UIClassTypeSchema RootType;
@@ -16,6 +19,11 @@ namespace Microsoft.Iris.UI
: base(name)
=> RootType = new UIClassTypeSchema(this, name);
protected RootLoadResult(SerializationInfo info, StreamingContext context) : base(info, context)
{
RootType = info.GetValue<UIClassTypeSchema>(nameof(RootType));
}
protected override void OnDispose()
{
base.OnDispose();
@@ -32,5 +40,12 @@ namespace Microsoft.Iris.UI
public override MarkupConstantsTable ConstantsTable => (MarkupConstantsTable)null;
public override MarkupImportTables ImportTables => (MarkupImportTables)null;
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(nameof(RootType), RootType);
}
}
}