public static IAppBuilder UseRavenDB(this IAppBuilder app, RavenDBOptions options) { if (options == null) { throw new ArgumentNullException("options"); } if (app.Properties.ContainsKey(HostOnAppDisposing)) { // This is a katana specific key (i.e. not a standard OWIN key) to be notified // when the host in being shut down. Works both in HttpListener and SystemWeb hosting // Until owin spec is officially updated, there is no other way to know the host // is shutting down / disposing var appDisposing = app.Properties[HostOnAppDisposing] as CancellationToken?; if (appDisposing.HasValue) { appDisposing.Value.Register(options.Dispose); } } AssemblyExtractor.ExtractEmbeddedAssemblies(); #if DEBUG app.UseInterceptor(); #endif app.Use((context, func) => UpgradeToWebSockets(options, context, func)); app.UseWebApi(CreateHttpCfg(options)); return(app); }
protected DomainExtractorPair GetExtractorInTempAppDomain(string assemblyPath) { AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = Path.GetDirectoryName(assemblyPath); setup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence); Interlocked.Increment(ref _domainID); string appDomainName = Constants.ExtractionDomainPrefix + " " + _domainID.ToString(); string typeName = new AssemblyExtractor().GetType().FullName; // Do it this way to work with obfuscator string extractorPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "BitDiffer.Extractor.dll"); Log.Verbose("Creating {0}", appDomainName); AppDomain domain = AppDomain.CreateDomain(appDomainName, evidence, setup); AssemblyExtractor extractor = (AssemblyExtractor)domain.CreateInstanceFromAndUnwrap(extractorPath, _extractorTypeName); // When running in another app domain - need to copy the Visual Studio trace listeners over. // This allows unit tests running in the other AppDomain to have their trace output displayed in the Visual Studio trace output. // TraceListener is MarshalByRef so this is safe. foreach (TraceListener listener in Trace.Listeners) { if (listener.Name == "") { extractor.AddTraceListener(listener); } } return(new DomainExtractorPair(domain, extractor)); }
internal static bool Initialize(ExternalUpdaterResult launchOption) { if (!Directory.Exists(LauncherConstants.ApplicationBasePath)) { throw new DirectoryNotFoundException($"Required directory '{LauncherConstants.ApplicationBasePath}' not found."); } SetupRegistry(); try { if (CheckRestoreRequired(launchOption)) { Restore(); } HandleLastUpdateResult(launchOption, out var skipWriteToDisk); if (!skipWriteToDisk) { AssemblyExtractor.WriteNecessaryAssembliesToDisk(LauncherConstants.ApplicationBasePath, LauncherConstants.ApplicationFileNames); } } catch (Exception e) { Logger.Error(e); if (e is AggregateException aggregate) { e = aggregate.GetBaseException(); } LauncherRegistryHelper.WriteValue(LauncherRegistryKeys.ForceRestore, true); // TODO: This and the exception dialog should be the same dialog new RestartSystemDialog(e.Message).ShowDialog(); Environment.Exit(0); } LogInstalledAssemblies(); SetCurrentUpdateSearchMode(); return(ShallUpdate(launchOption)); }
private static Type DoActualCompilation(string source, string name, string queryText, OrderedPartCollection <AbstractDynamicCompilationExtension> extensions, string basePath, string indexFilePath, InMemoryRavenConfiguration configuration) { var provider = new CSharpCodeProvider(new Dictionary <string, string> { { "CompilerVersion", "v4.0" } }); var assemblies = new HashSet <string> { typeof(SystemTime).Assembly.Location, typeof(AbstractViewGenerator).Assembly.Location, typeof(NameValueCollection).Assembly.Location, typeof(Enumerable).Assembly.Location, typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly.Location, AssemblyExtractor.GetExtractedAssemblyLocationFor(typeof(Field), configuration), }; foreach (var extension in extensions) { foreach (var assembly in extension.Value.GetAssembliesToReference()) { assemblies.Add(assembly); } } var compilerParameters = new CompilerParameters { GenerateExecutable = false, GenerateInMemory = false, IncludeDebugInformation = Debugger.IsAttached, OutputAssembly = indexFilePath }; if (basePath != null) { compilerParameters.TempFiles = new TempFileCollection(basePath, false); } foreach (var assembly in assemblies) { compilerParameters.ReferencedAssemblies.Add(assembly); } CompilerResults compileAssemblyFromFile; if (indexFilePath != null) { var sourceFileName = indexFilePath + ".cs"; File.WriteAllText(sourceFileName, source); compileAssemblyFromFile = provider.CompileAssemblyFromFile(compilerParameters, sourceFileName); } else { compileAssemblyFromFile = provider.CompileAssemblyFromSource(compilerParameters, source); } var results = compileAssemblyFromFile; if (results.Errors.HasErrors) { var sb = new StringBuilder() .AppendLine("Compilation Errors:") .AppendLine(); foreach (CompilerError error in results.Errors) { sb.AppendFormat("Line {0}, Position {1}: Error {2} - {3}\n", error.Line, error.Column, error.ErrorNumber, error.ErrorText); } sb.AppendLine(); sb.AppendLine("Source code:") .AppendLine(queryText) .AppendLine(); throw new InvalidOperationException(sb.ToString()); } var asm = Assembly.Load(File.ReadAllBytes(indexFilePath)); // avoid locking the file // ReSharper disable once AssignNullToNotNullAttribute File.SetCreationTime(indexFilePath, DateTime.UtcNow); CodeVerifier.AssertNoSecurityCriticalCalls(asm); Type result = asm.GetType(name); if (result == null) { throw new InvalidOperationException( "Could not get compiled index type. This probably means that there is something wrong with the assembly load context."); } return(result); }
public DomainExtractorPair(AppDomain domain, AssemblyExtractor extractor) { _domain = domain; _extractor = extractor; }