private async ValueTask <Module> GetModuleAsync(IModuleSource source, ModuleReleaseIdentifier releaseId, CancellationToken cancellation) { var moduleId = releaseId.Module; var moduleVersion = releaseId.Version; Module module; do { module = await _entityStorageEngine.GetByIdAsync <Module>(moduleId.ToString(), cancellation); if (module == null) { var metadata = await source.GetMetadataAsync(releaseId, _metadataReader, cancellation); module = new Module(metadata, source); } else if (module.GetRelease(moduleVersion) is var release && release != null) { if (release.TryAddSource(source)) { break; } } else { var metadata = await source.GetMetadataAsync(releaseId, _metadataReader, cancellation); module.AddRelease(metadata, source); } }while (!await _entityStorageEngine.TryStoreAsync(module, cancellation));
Module(ModuleType type, IModuleSource source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } this.ModuleType = type; this.source = source; var name = source.Name; name = name.Replace("__", "{**}"); name = name.Replace('_', '.'); name = name.Replace("{**}", "_"); switch (type) { case ModuleType.x86: name = name.Replace(".86", string.Empty); break; case ModuleType.x64: name = name.Replace(".64", string.Empty); break; case ModuleType.Exe: name = name.Replace(".exe", string.Empty); break; } this.Name = name; this.assemblyReference = new WeakReference(null); }
Module(ModuleType type, IModuleSource source) { if (source == null) throw new ArgumentNullException(nameof(source)); this.ModuleType = type; this.source = source; var name = source.Name; name = name.Replace("__", "{**}"); name = name.Replace('_', '.'); name = name.Replace("{**}", "_"); switch (type) { case ModuleType.x86: name = name.Replace(".86", string.Empty); break; case ModuleType.x64: name = name.Replace(".64", string.Empty); break; case ModuleType.Exe: name = name.Replace(".exe", string.Empty); break; } this.Name = name; this.assemblyReference = new WeakReference(null); }
public bool TryAddSource(IModuleSource source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(_sources.Add(new Snapshot <IModuleSource>(source))); }
public IList <AssemblyNode> CreateNodesFromAssemblies(IModuleSource modules, CciMethodMatcher constraints) { List <AssemblyNode> assemblyNodes = modules.Modules.Select(m => CreateAssemblyNode(m, constraints)).ToList(); var root = new RootNode(); root.Children.AddRange(assemblyNodes); root.IsIncluded = true; return(assemblyNodes); }
internal ModuleRelease(Module module, IModuleMetadata metadata, IModuleSource moduleSource) { Assert(module != null); Assert(metadata != null); Assert(moduleSource != null); _sources = new HashSet <Snapshot <IModuleSource> > { new Snapshot <IModuleSource>(moduleSource) }; _metadata = new SerializedModuleMetadata(metadata); Module = module; }
public IList<AssemblyNode> CreateNodesFromAssemblies(IModuleSource modules, CciMethodMatcher constraints) { List<AssemblyNode> assemblyNodes = modules.Modules.Select(m => CreateAssemblyNode(m, constraints)).ToList(); var root = new RootNode(); root.Children.AddRange(assemblyNodes); root.IsIncluded = true; return assemblyNodes; }
public ModuleSourceListModel ProjectToListModel(IModuleSource moduleSource) { if (moduleSource is FileSystemModuleSource fileSystemModuleSource) { return(new ModuleSourceListModel { Id = fileSystemModuleSource.Id, Location = fileSystemModuleSource.Location.Location, Name = fileSystemModuleSource.Name.Value }); } return(null); }
public ModuleSourceUpdateLocationModel ProjectToUpdateLocationModel(IModuleSource moduleSource) { if (moduleSource is FileSystemModuleSource fileSystemModuleSource) { return(new ModuleSourceUpdateLocationModel { Id = fileSystemModuleSource.Id, ConcurrencyToken = fileSystemModuleSource.ConcurrencyToken, Location = fileSystemModuleSource.Location.Location }); } return(null); }
public ModuleSourceRenameModel ProjectToRenameModel(IModuleSource moduleSource) { if (moduleSource is FileSystemModuleSource fileSystemModuleSource) { return(new ModuleSourceRenameModel { Id = fileSystemModuleSource.Id, ConcurrencyToken = fileSystemModuleSource.ConcurrencyToken, Name = fileSystemModuleSource.Name.Value }); } return(null); }
public bool TryRemoveSource(IModuleSource source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var result = _sources.Remove(new Snapshot <IModuleSource>(source)); // If there are no more sources available for the release, we have to remove it. if (!_sources.Any()) { Module.RemoveRelease(this); } return(result); }
public static ValueTask <IModuleMetadata> GetMetadataAsync(this IModuleSource moduleSource, ModuleReleaseIdentifier moduleRelease, IMetadataReader moduleMetadataReader, CancellationToken cancellation = default) { if (moduleSource == null) { throw new ArgumentNullException(nameof(moduleSource)); } if (moduleRelease == default) { throw new ArgumentDefaultException(nameof(moduleRelease)); } return(moduleSource.GetMetadataAsync(moduleRelease.Module, moduleRelease.Version, moduleMetadataReader, cancellation)); }
public Module(IModuleMetadata metadata, IModuleSource moduleSource) : base(metadata.Module) { if (metadata == null) { throw new ArgumentNullException(nameof(metadata)); } if (moduleSource == null) { throw new ArgumentNullException(nameof(moduleSource)); } _releases = new Dictionary <ModuleVersion, ModuleRelease>() { [metadata.Version] = new ModuleRelease(this, metadata, moduleSource) }; Notify(new ModuleReleaseAdded(Id, metadata.Version)); }
public static Module TryCreate(IModuleSource source, bool matchProccess) { var type = ModuleTypeFromName(source.Name); if (matchProccess) { if (!Environment.Is64BitProcess) { if (type == ModuleType.x64) return null; } else { if (type == ModuleType.x86) return null; } } return new Module(type, source); }
public void Process(IModuleSource original, Mutant mutant) { var tree = SyntaxTree.ParseText(execTemplate); CompilationUnitSyntax root = tree.GetRoot(); var firstParameters = from methodDeclaration in root.DescendantNodes().OfType <MethodDeclarationSyntax>() where methodDeclaration.Identifier.ValueText == "Main" select methodDeclaration.ParameterList.Parameters.First(); // Syntax.MethodDeclaration(Syntax.) var comp = Compilation.Create("MyCompilation", new CompilationOptions(OutputKind.DynamicallyLinkedLibrary)) .AddSyntaxTrees(tree) .AddReferences(new MetadataFileReference(typeof(object).Assembly.Location)); var outputFileName = Path.Combine(Path.GetTempPath(), "MyCompilation.lib"); var ilStream = new FileStream(outputFileName, FileMode.OpenOrCreate); var result = comp.Emit(ilStream); ilStream.Close(); if (!result.Success) { var aggregate = result.Diagnostics.Select(a => a.Info.GetMessage()).Aggregate((a, b) => a + "\n" + b); throw new InvalidProgramException(aggregate); } /* Compilation compilation = Compilation.Create("") * .AddReferences(new MetadataFileReference(typeof(object).Assembly.Location)) * .AddSyntaxTrees() * * * * var method = ActeeFinder * valueSupplier.supplyValues(method);*/ }
public void Process(IModuleSource original, Mutant mutant) { var tree = SyntaxTree.ParseText(execTemplate); CompilationUnitSyntax root = tree.GetRoot(); var firstParameters = from methodDeclaration in root.DescendantNodes().OfType<MethodDeclarationSyntax>() where methodDeclaration.Identifier.ValueText == "Main" select methodDeclaration.ParameterList.Parameters.First(); // Syntax.MethodDeclaration(Syntax.) var comp = Compilation.Create("MyCompilation", new CompilationOptions(OutputKind.DynamicallyLinkedLibrary)) .AddSyntaxTrees(tree) .AddReferences(new MetadataFileReference(typeof(object).Assembly.Location)); var outputFileName = Path.Combine(Path.GetTempPath(), "MyCompilation.lib"); var ilStream = new FileStream(outputFileName, FileMode.OpenOrCreate); var result = comp.Emit(ilStream); ilStream.Close(); if (!result.Success) { var aggregate = result.Diagnostics.Select(a => a.Info.GetMessage()).Aggregate((a, b) => a + "\n" + b); throw new InvalidProgramException(aggregate); } /* Compilation compilation = Compilation.Create("") .AddReferences(new MetadataFileReference(typeof(object).Assembly.Location)) .AddSyntaxTrees() var method = ActeeFinder valueSupplier.supplyValues(method);*/ }
private async Task ProcessSourceAsync(IModuleSource source, string searchPhrase, bool includePreReleases, IDictionary <ModuleIdentifier, Module> resultSet, CancellationToken cancellation) { var available = await source.GetAvailableAsync(searchPhrase, includePreReleases, _metadataReader, cancellation); foreach (var releaseId in available) { var module = await GetModuleAsync(source, releaseId, cancellation); #if DEBUG if (resultSet.TryGetValue(module.Id, out var existingModule)) { Assert(existingModule.Revision <= module.Revision); } #endif // We override any modules that were stored previously. // We are allowed to do this, as GetModuleAsync is guaranteed to return the same or a later version of the module entity. resultSet[module.Id] = module; } }
public static Module TryCreate(IModuleSource source, bool matchProccess) { var type = ModuleTypeFromName(source.Name); if (matchProccess) { if (!Environment.Is64BitProcess) { if (type == ModuleType.x64) { return(null); } } else { if (type == ModuleType.x86) { return(null); } } } return(new Module(type, source)); }
/// <summary> /// 加载模块源的模块 /// </summary> /// <param name="services"></param> /// <param name="moduleSource"></param> /// <param name="optionAction"></param> /// <returns></returns> public static IModuleLoaderBuilder LoadModule(this IServiceCollection services, IModuleSource moduleSource, Action <ModuleLoadOptions>?optionAction = null) { if (moduleSource is null) { throw new ArgumentNullException(nameof(moduleSource)); } return(services.InternalAddModuleSource(moduleSource, optionAction)); }
public MutMod(Mutant mutant, IModuleSource modulesProvider) { Mutant = mutant; ModulesProvider = modulesProvider; }
internal static IModuleLoaderBuilder InternalAddModuleSource(this IServiceCollection services, IModuleSource moduleSource, Action <ModuleLoadOptions>?optionAction = null) { return(services.InternalConfigureModuleLoad(builder => builder.AddModuleSource(moduleSource), optionAction)); }
/// <summary> /// /// </summary> /// <param name="Source">模型</param> /// <param name="ModelSqlCon">存储模型的数据库</param> /// <param name="DataBaseSqlCon">要创建的数据库的</param> public void InstallModules(IModuleSource Source, SqlCon ModelSqlCon, SqlCon DataBaseSqlCon) { ConnectionType ConnectionType = ConnectionType.AppSys; if (ModelSqlCon.ToString() == DataBaseSqlCon.ToString()) { ConnectionType = ConnectionType.AppSys; } else { ConnectionType = ConnectionType.Current; } //System.Diagnostics.Trace.WriteLine("MODEL:"+ModelSqlCon.ToString()); //System.Diagnostics.Trace.WriteLine("CON:"+ModelSqlCon.ToString()); var modelDb = new SqlServer.dbContext(ModelSqlCon, this.ConFac); var DataDb = new SqlServer.dbContext(DataBaseSqlCon, this.ConFac); var modelMode = Global.ModeMode; var moduleMode = Global.ModuleMode; var viewMode = Global.ViewMode; var relationMode = Global.RelationModel; List <IObjectProxy> insertItems = new List <IObjectProxy>(); ModelSqlServerFactory sqlFac = new ModelSqlServerFactory(Source); var viewFac = new Soway.Model.View.AutoViewFactory(ModelSqlCon, this.ConFac); Dictionary <object, System.Data.IDbCommand> commands = new Dictionary <object, System.Data.IDbCommand>(); Dictionary <object, System.Data.IDbCommand> relationsCommands = new Dictionary <object, System.Data.IDbCommand>(); var helper = new ModelHelper(this.ConFac); var modules = Source.GetModules(); CreateDataBase(DataBaseSqlCon); foreach (var module in modules.Distinct()) { module.SqlCon = DataBaseSqlCon; IObjectProxy moduleproxy = new ObjectProxy(moduleMode, this.ConFac); helper.SetProxy(ref moduleproxy, module); if (modelDb.IsExits(moduleproxy) == true) { } else { insertItems.Add(moduleproxy); } foreach (var model in Source.GetModels(module)) { IObjectProxy proxy = new ObjectProxy(modelMode, this.ConFac, LoadType.Complete); helper.SetProxy(ref proxy, model); if (modelDb.IsExits(proxy) == false) { insertItems.Add(proxy); } if (model.ModelType != ModelType.Enum) { var command = sqlFac.GerateCreateSql(model); if (commands.ContainsKey(model)) { commands[model] = command; } else { commands.Add(model, command ); } foreach (var relation in model.Relations) { if (relationsCommands.ContainsKey(relation) == false) { relationsCommands.Add(relation, sqlFac.GetRelationSql(relation)); } } var itemView = viewFac.CreateDefaultItemView(model); itemView.ConnectionType = ConnectionType; IObjectProxy itemViewProxy = new ObjectProxy(viewMode, this.ConFac); var view = viewFac.CreateDefaultListView(model); IObjectProxy viewProxy = new ObjectProxy(viewMode, this.ConFac); view.ConnectionType = ConnectionType; helper.SetProxy(ref itemViewProxy, itemView); insertItems.Add(itemViewProxy); helper.SetProxy(ref viewProxy, view); insertItems.Add(viewProxy); } } } //创建表 foreach (var command in commands) { DataDb .Excute(command.Value as System.Data.SqlClient.SqlCommand); } foreach (var command in relationsCommands) { DataDb .Excute(command.Value as System.Data.SqlClient.SqlCommand); } //插入数据 Soway.Data.Graphic.Graphic <IObjectProxy> proxyMaps = new Data.Graphic.Graphic <IObjectProxy>(); foreach (var item in insertItems) { proxyMaps.Add(item); foreach (var ob in item.Model.Properties) { if (item[ob] is IObjectProxy) { proxyMaps.AddEdge(item[ob] as IObjectProxy, item); } } } while (proxyMaps.Nodes.Count > 0) { var ob = proxyMaps.GetTopNode(); if (ob == null) { ob = proxyMaps.Nodes[0].Data; } proxyMaps.Remove(ob); if (modelDb.IsExits(ob) == false) { modelDb.Create(ob); } else { } } }
internal static IHostBuilder InternalAddModuleSource(this IHostBuilder hostBuilder, IModuleSource moduleSource, Action <ModuleLoadOptions>?optionAction = null) { if (moduleSource is null) { throw new ArgumentNullException(nameof(moduleSource)); } if (hostBuilder.Properties.TryGetValue(HostBuilderPropertiesKey, out var storedLoadContext)) { if (storedLoadContext is HostBuilderModuleLoadContext loadContext) { loadContext.Add(moduleSource, optionAction); } else { throw new ModularityException($"The key '{HostBuilderPropertiesKey}' stored in {nameof(IHostBuilder)}.{nameof(IHostBuilder.Properties)} is invalid. Don't change it."); } } else { var loadContext = new HostBuilderModuleLoadContext(); hostBuilder.Properties.Add(HostBuilderPropertiesKey, loadContext); loadContext.Add(moduleSource, optionAction); hostBuilder.ConfigureServices((context, services) => { services.AddObjectAccessor <IConfiguration>(context.Configuration); foreach (var item in loadContext.ModuleSources) { services.LoadModule(item.Key, item.Value); } foreach (var item in loadContext.OptionActions) { services.OptionModuleLoadBuilder(item); } services.ModuleLoadComplete(); services.RemoveObjectAccessor <IConfiguration>(); }); } return(hostBuilder); }
public static Module TryBind(IModuleSource source) { return(TryCreate(source, matchProccess: true)); }
public CachedSearchContext(IModuleSource modules) => Modules = modules;
/// <summary> /// 增加要加载的模块源 /// </summary> /// <param name="moduleLoaderBuilder"></param> /// <param name="moduleSource"></param> /// <returns></returns> public static IModuleLoaderBuilder AddModule(this IModuleLoaderBuilder moduleLoaderBuilder, IModuleSource moduleSource) { return(moduleLoaderBuilder.InternalAddModule(moduleSource)); }
public MutMod(Mutant mutant, IModuleSource modulesProvider) { Mutant = mutant; ModulesProvider = modulesProvider; }
public ModelSqlServerFactory(IModuleSource fac) { this.ModelFactory = fac; }
public PatchInstaller(IModuleSource modules) : base(modules) { }
public static Module TryBind(IModuleSource source) { return TryCreate(source, matchProccess: true); }
/// <inheritdoc cref="LoadModuleServiceCollectionExtensions.LoadModule(IServiceCollection, IModuleSource, Action{ModuleLoadOptions}?)"/> public static IHostBuilder LoadModule(this IHostBuilder hostBuilder, IModuleSource moduleSource, Action <ModuleLoadOptions>?optionAction = null) { return(hostBuilder.InternalAddModuleSource(moduleSource, optionAction)); }
private static IModuleLoaderBuilder InternalAddModule(this IModuleLoaderBuilder moduleLoaderBuilder, IModuleSource moduleSource) { moduleLoaderBuilder.AddModuleSource(moduleSource); return(moduleLoaderBuilder); }