public override Type ReadJson(JsonReader reader, Type objectType, Type existingValue, bool hasExistingValue, JsonSerializer serializer) { if (reader.Value is string unqualifiedTypeName) { return(TypeLoadHelper.LoadTypeFromUnqualifiedName(unqualifiedTypeName)); } return(null); }
public static string[] GetProvidersInSandbox(string assemblyPath) { AppDomain domain = AppDomain.CreateDomain("Container"); try { TypeLoadHelper helper = (TypeLoadHelper)domain.CreateInstanceFromAndUnwrap( Assembly.GetExecutingAssembly().Location, typeof(TypeLoadHelper).FullName); return(helper.GetProviders(assemblyPath)); } finally { AppDomain.Unload(domain); } }
public static bool Compile(string manifest, out string error) { error = null; EnsureTemporaryCache(); //Get cached key for assembly. FileInfo info = new FileInfo(manifest); string assemblyName = Path.GetFileNameWithoutExtension(manifest) + "_" + info.LastWriteTime.ToString("yyMMdd_HHmmss") + "_man.dll"; string fullpath = Path.GetFullPath(TempAssemblyCache + "\\" + assemblyName); if (!File.Exists(fullpath)) { var manifestDictionary = Tx.Windows.ManifestParser.Parse(File.ReadAllText(manifest)); Dictionary <string, string> generated = new Dictionary <string, string>(); if (TryAddManifest(manifestDictionary.Keys)) { AssemblyBuilder.OutputAssembly(manifestDictionary, fullpath); EtlViewer.Logger.Log("Manifest compiled into : " + fullpath); AssemblyCache[manifest] = fullpath; Assembly.LoadFile(fullpath); } else { error += "Could not load Provider - " + manifestDictionary.Keys.Aggregate((e, acc) => e + "\n" + acc); error += "\n\nAlready loaded assemblies for Providers -\n* " + Providers.Aggregate((e, acc) => e + "\n *" + acc); } } else { AssemblyCache[manifest] = fullpath; var providers = TypeLoadHelper.GetProvidersInSandbox(fullpath); if (TryAddManifest(providers)) { Assembly.LoadFile(fullpath); } else { error += "Could not load Provider - " + providers.Aggregate((e, acc) => e + "\n" + acc); error += "\n\nAlready loaded assemblies for Providers -\n* " + Providers.Aggregate((e, acc) => e + "\n *" + acc); } Logger.Log("Loading precompiled manifest {0}: from {1} ", manifest, fullpath); } return(String.IsNullOrEmpty(error)); }
static MessageDispatcherExtension() { var remoteMessageDispatcherType = TypeLoadHelper.LoadTypeFromUnqualifiedName("AI4E.Routing.IRemoteMessageDispatcher", throwIfNotFound: false); if (remoteMessageDispatcherType == null) { _isRemoteMessageDispatcher = _ => false; _dispatchLocalAsync = null; return; } var dispatchLocalAsyncMethod = remoteMessageDispatcherType.GetMethod( "DispatchLocalAsync", BindingFlags.Public | BindingFlags.Instance, Type.DefaultBinder, new Type[] { typeof(DispatchDataDictionary), typeof(bool), typeof(CancellationToken) }, modifiers: null); Assert(dispatchLocalAsyncMethod != null); Assert(dispatchLocalAsyncMethod.ReturnType == typeof(ValueTask <IDispatchResult>)); var messageDispatcherParameter = Expression.Parameter(typeof(IMessageDispatcher), "messageDispatcher"); var isRemoteMessageDispatcher = Expression.TypeIs(messageDispatcherParameter, remoteMessageDispatcherType); _isRemoteMessageDispatcher = Expression.Lambda <Func <IMessageDispatcher, bool> >(isRemoteMessageDispatcher, messageDispatcherParameter).Compile(); var dispatchDataParameter = Expression.Parameter(typeof(DispatchDataDictionary), "dispatchData"); var publishParameter = Expression.Parameter(typeof(bool), "publish"); var cancellationParameter = Expression.Parameter(typeof(CancellationToken), "cancellation"); var convertedMessageDispatcher = Expression.Convert(messageDispatcherParameter, remoteMessageDispatcherType); var dispatchLocalAsyncCall = Expression.Call( convertedMessageDispatcher, dispatchLocalAsyncMethod, dispatchDataParameter, publishParameter, cancellationParameter); _dispatchLocalAsync = Expression.Lambda <Func <IMessageDispatcher, DispatchDataDictionary, bool, CancellationToken, ValueTask <IDispatchResult> > >( dispatchLocalAsyncCall, messageDispatcherParameter, dispatchDataParameter, publishParameter, cancellationParameter).Compile(); }
private async Task ProjectAsync(string bucketId, string id, TaskCompletionSource <object> tcs, CancellationToken cancellation) { try { var type = TypeLoadHelper.LoadTypeFromUnqualifiedName(bucketId); if (type == null) { throw new InvalidOperationException($"Unable to load type for bucket '{bucketId}'"); } await _projectionEngine.ProjectAsync(type, id, cancellation); Task.Run(() => tcs?.TrySetResult(null)).HandleExceptions(); } catch (Exception exc) { Task.Run(() => tcs?.TrySetException(exc)).HandleExceptions(); throw; } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (!CanConvert(objectType)) { throw new InvalidOperationException(); } if (reader.TokenType == JsonToken.Null) { return(null); } if (reader.TokenType != JsonToken.StartObject) { throw new InvalidOperationException(); } var messageType = objectType.IsGenericTypeDefinition ? objectType.GetGenericArguments().First() : null; object message = null; ImmutableDictionary <string, object> .Builder data = null; while (reader.Read()) { if (reader.TokenType == JsonToken.EndObject) { break; } else if (reader.TokenType == JsonToken.PropertyName) { if ((string)reader.Value == "message-type") { reader.Read(); var deserializedMessageType = TypeLoadHelper.LoadTypeFromUnqualifiedName(reader.Value as string); if (messageType != null && messageType != deserializedMessageType) { throw new InvalidOperationException(); } messageType = deserializedMessageType; } else if ((string)reader.Value == "message") { reader.Read(); message = serializer.Deserialize(reader, typeof(object)); } else if ((string)reader.Value == "data") { data = ReadData(reader, serializer); } else { throw new InvalidOperationException(); } } else { throw new InvalidOperationException(); } } if (messageType == null || message == null) { throw new InvalidOperationException(); } return(DispatchDataDictionary.Create(messageType, message, data?.ToImmutable() ?? ImmutableDictionary <string, object> .Empty)); }
public bool TryGetEntityType(out Type entityType) { entityType = TypeLoadHelper.LoadTypeFromUnqualifiedName(EntityTypeName, throwIfNotFound: false); return(entityType != null); }
public Type DeserializeType(string serializedType) { return(TypeLoadHelper.LoadTypeFromUnqualifiedName(serializedType)); }
public Type BindToType(string assemblyName, string typeName) { return(TypeLoadHelper.LoadTypeFromUnqualifiedName(typeName)); }