protected CartoProcessEngineBase(string name, IProcessingContext context, IProcessingFeedback feedback) { Name = name ?? nameof(CartoProcess); Context = context ?? throw new ArgumentNullException(nameof(context)); Feedback = feedback ?? throw new ArgumentNullException(nameof(feedback)); }
/// <summary> /// Create a delegate to convert data after reading from the database. /// </summary> /// <param name="dataTable">The data table.</param> /// <param name="context">The context.</param> /// <returns></returns> private Func <Guid, Guid, object, object> GetDataConverter(string dataTable, IProcessingContext context) { Func <Guid, Guid, object, object> converter; switch (dataTable) { case "Xml": ///// // Use Xml processor to remap EntityRefs located in XML ///// var xmlProcessor = new XmlFieldProcessor { ConversionMode = XmlConversionMode.LocalIdToUpgradeGuid, TenantId = TenantId, DatabaseContext = DatabaseContext, ProcessingContext = context }; converter = (entityUpgradeId, fieldUpgradeId, value) => xmlProcessor.RemapXmlEntities(entityUpgradeId, fieldUpgradeId, ( string )value); break; default: converter = (entityUpgradeId, fieldUpgradeId, value) => value; break; } return(converter); }
protected bool CheckValidity(IProcessingContext processingContext, KraftModule module, LoadedNodeSet loadedNodeSet) { if (processingContext.InputModel.LoaderType == ELoaderType.None) { Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"You have to specify a loader type."); return(false); } if (module == null) { Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"Requested module: {processingContext.InputModel.Module} doesn't exist or not loaded."); return(false); } if (loadedNodeSet == null) { Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"Requested nodeset: {processingContext.InputModel.NodeSet} doesn't exist or not loaded."); return(false); } //If authentication is required but the user is not logged in redirect to authentication if (loadedNodeSet.StartNode.RequireAuthentication && !processingContext.InputModel.SecurityModel.IsAuthenticated) { Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.Unauthorized, null); return(false); } return(true); }
/// <summary> /// Gets the binary data. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> IEnumerable <BinaryDataEntry> IDataSource.GetBinaryData(IProcessingContext context) { if (_binaryCache == null) { var data = new List <BinaryDataEntry>( ); Func <string, byte[]> loadBinaryData = token => FileRepositoryUtils.LoadFileData(Factory.BinaryFileRepository, token, context); using (IDbCommand command = CreateCommand( )) { command.CommandType = CommandType.Text; command.CommandText = CommandText.TenantSourceGetBinaryDataCommandText; command.AddParameterWithValue("@tenant", TenantId); using (IDataReader reader = command.ExecuteReader( )) { while (reader.Read( )) { var binaryDataEntry = new BinaryDataEntry { DataHash = reader.GetString(0), LoadDataCallback = loadBinaryData }; data.Add(binaryDataEntry); } } } _binaryCache = data; } return(_binaryCache); }
/// <summary> /// Setups the specified context. /// </summary> /// <param name="context">The context.</param> /// <exception cref="System.InvalidOperationException">No xml writer specified.</exception> void IDataTarget.Setup(IProcessingContext context) { ///// // TODO: Use Autofac to inject appropriate serializer. Need to check version in the xml header. ///// switch (Format) { case Format.Xml: _serializer = new XmlSerializer { NameResolver = NameResolver, VersionOverride = VersionOverride }; break; case Format.XmlVer2: _serializer = new XmlSerializerV2 { NameResolver = NameResolver, VersionOverride = VersionOverride }; break; default: throw new InvalidOperationException($"XmlPackageTarget cannot be used with {Format} format."); } _packageData = new PackageData( ); }
public async Task <IProcessingContext> ExecuteAsync( LoadedNodeSet loadedNodeSet, IProcessingContext processingContext, IPluginServiceManager pluginServiceManager, IPluginAccessor <IDataLoaderPlugin> externalService, IPluginAccessor <INodePlugin> customService ) { _dataIteratorContext.LoadedNodeSet = loadedNodeSet; _dataIteratorContext.ProcessingContext = processingContext; _dataIteratorContext.PluginServiceManager = pluginServiceManager; _dataIteratorContext.DataLoaderPluginAccessor = externalService; _dataIteratorContext.CustomPluginAccessor = customService; _dataIteratorContext.CheckNulls(); // dataIteratorContext already has a reference to processingContext.ReturrnModel.Data, // that's why previous implementation with assigning the retturn result from Begin(Read\Write)Operation to it is obsolete. if (processingContext.InputModel.IsWriteOperation == false) { BeginReadOperation(_dataIteratorContext); } else if (processingContext.InputModel.IsWriteOperation == true) { BeginWriteOperation(_dataIteratorContext); } return(await Task.FromResult(processingContext)); }
/// <summary> /// Deletes the document data. /// </summary> /// <param name="documentData">The document data.</param> /// <param name="context">The context.</param> public void DeleteDocumentData(IEnumerable <DocumentDataEntry> documentData, IProcessingContext context) { foreach (DocumentDataEntry documentDataEntry in documentData) { context.WriteInfo("Deleted document data: " + documentDataEntry.DataHash); } }
/// <summary> /// Tenants the exists. /// </summary> /// <param name="name">The name.</param> /// <param name="tenant">The tenant.</param> /// <param name="context">The context.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">name</exception> public static bool UserExists(string name, string tenant, IProcessingContext context) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } if (string.IsNullOrEmpty(tenant)) { throw new ArgumentNullException("tenant"); } if (context == null) { context = new ProcessingContext( ); } context.Report.StartTime = DateTime.Now; UserAccount user; using (new TenantAdministratorContext(tenant)) { user = Entity.GetByName <UserAccount>(name).FirstOrDefault( ); } context.Report.EndTime = DateTime.Now; return(user != null); }
/// <summary> /// Write in collection of relationships. /// </summary> /// <param name="relationships"></param> /// <param name="context"></param> void IDataTarget.WriteSecureData(IEnumerable <SecureDataEntry> data, IProcessingContext context) { foreach (var entry in data) { context.WriteInfo($"Added secure entry: {entry.SecureId} {entry.Context} Length:{entry.Data.Length}"); } }
/// <summary> /// Write list of entities that should not be removed during upgrade operations. /// </summary> /// <param name="entities"></param> /// <param name="context"></param> void IDataTarget.WriteDoNotRemove(IEnumerable <Guid> entities, IProcessingContext context) { foreach (Guid entity in entities) { context.WriteInfo("Do not remove: " + entity); } }
public void WriteDocumentData(IEnumerable <DocumentDataEntry> data, IProcessingContext context) { foreach (DocumentDataEntry dataEntry in data) { context.WriteInfo(string.Format("Added Document DataHash:{0}", dataEntry.DataHash)); } }
/// <summary> /// Deletes binary data entries. /// </summary> /// <param name="binaryData"></param> /// <param name="context"></param> void IMergeTarget.DeleteBinaryData(IEnumerable <BinaryDataEntry> binaryData, IProcessingContext context) { foreach (BinaryDataEntry binaryDataEntry in binaryData) { context.WriteInfo("Deleted binary data: " + binaryDataEntry.DataHash); } }
/// <summary> /// Writes the binary data. /// </summary> /// <param name="data">The data.</param> /// <param name="context">The context.</param> void IDataTarget.WriteBinaryData(IEnumerable <BinaryDataEntry> data, IProcessingContext context) { foreach (BinaryDataEntry dataEntry in data) { context.WriteInfo(string.Format("Added Binary DataHash:{0}", dataEntry.DataHash)); } }
/// <summary> /// Gets the users. /// </summary> /// <param name="tenantName">Name of the tenant.</param> /// <param name="context">The context.</param> /// <returns></returns> public static IEnumerable <string> GetUsers(string tenantName, IProcessingContext context) { if (string.IsNullOrEmpty(tenantName)) { throw new ArgumentNullException("tenantName"); } if (context == null) { context = new ProcessingContext( ); } context.Report.StartTime = DateTime.Now; List <string> userNames; using (new TenantAdministratorContext(tenantName)) { IEnumerable <UserAccount> users = Entity.GetInstancesOfType <UserAccount>(false, "isOfType.id, name"); userNames = users.Select(user => user.Name).ToList( ); } context.Report.EndTime = DateTime.Now; return(userNames); }
/// <summary> /// Deletes entities. /// </summary> /// <param name="entities"></param> /// <param name="context"></param> void IMergeTarget.DeleteEntities(IEnumerable <EntityEntry> entities, IProcessingContext context) { foreach (EntityEntry entity in entities) { context.WriteInfo("Deleted entity: " + entity.EntityId); } }
/// <summary> /// Load field data. /// </summary> /// <param name="dataTable"></param> /// <param name="context"></param> /// <returns></returns> /// <remarks> /// Data sources MUST: /// - ensure that bits are represented as Booleans /// - ensure that XML is transformed so that entityRefs contain UpgradeIds /// - or where XML contains an alias, translate it to upgradeId|alias (as the alias may be changed in the target) /// - ensure that aliases export their namespace and direction marker. /// </remarks> IEnumerable <DataEntry> IDataSource.GetFieldData(string dataTable, IProcessingContext context) { List <DataEntry> data; if (!_entityDataCache.TryGetValue(dataTable, out data)) { data = new List <DataEntry>( ); bool isAliasTable = dataTable == "Alias"; string extraSql = isAliasTable ? ", [Namespace], AliasMarkerId" : ""; ///// // Converter for XML entity ref data ///// Func <Guid, Guid, object, object> converter = GetDataConverter(dataTable, context); ///// // Query entities that are part of the solution ///// using (IDbCommand command = CreateCommand( )) { command.CommandText = "spGetTenantAppFieldData"; command.CommandType = CommandType.StoredProcedure; command.AddParameterWithValue("@solutionId", SolutionId); command.AddParameterWithValue("@tenant", TenantId); command.AddParameterWithValue("@dataTable", dataTable); command.AddParameterWithValue("@extraSql", extraSql); using (IDataReader reader = command.ExecuteReader( )) { while (reader.Read( )) { var entry = new DataEntry { EntityId = reader.GetGuid(0), FieldId = reader.GetGuid(1), Data = reader.GetValue(2) }; if (isAliasTable) { entry.Namespace = reader.GetString(3); entry.AliasMarkerId = reader.GetInt32(4); } data.Add(entry); } } foreach (DataEntry entry in data) { entry.Data = converter(entry.EntityId, entry.FieldId, entry.Data); } } _entityDataCache[dataTable] = data; } return(data); }
/// <summary> /// Interception called before invoking the handler to process the request. /// </summary> /// <param name="context">The processing context.</param> /// <param name="token">The cancellation token.</param> /// <returns> /// A task. /// </returns> public Task BeforeProcessAsync(IProcessingContext context, CancellationToken token) { Contract.Requires(context != null); Contract.Ensures(Contract.Result<Task>() != null); return Contract.Result<Task>(); }
/// <summary> /// Tenants the exists. /// </summary> /// <param name="name">The name.</param> /// <param name="context">The context.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">name</exception> public static bool TenantExists(string name, IProcessingContext context) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } if (context == null) { context = new ProcessingContext( ); } context.Report.StartTime = DateTime.Now; Tenant tenant; using (new GlobalAdministratorContext( )) { tenant = Entity.GetByName <Tenant>(name).FirstOrDefault( ); } context.Report.EndTime = DateTime.Now; return(tenant != null); }
public void Execute(IProcessingContext context) { var arguments = context.Get <ApplicationArguments>(); var information = (AssemblyInformation)context.GetService(typeof(AssemblyInformation)); var profile = context.GetService(typeof(BuildProfile)) as BuildProfile ?? new DefaultBuildProfile(); writer.WriteLine($"{GetType().Name} has been executed with the following information:"); writer.WriteLine($@"Processor File / Input File: ""{arguments.ProcessorFile}"" / ""{arguments.InputFile}"""); writer.WriteLine($"Application Name: {information.Name}"); writer.WriteLine($"Application Version: {information.Version}"); writer.WriteLine($"Application Author: {information.Author}"); writer.WriteLine(string.Empty); writer.WriteLine("Requested Files to Build:"); foreach (var file in profile.Files) { writer.WriteLine($"- {file.Path}"); } writer.WriteLine(string.Empty); writer.WriteLine(string.Empty); writer.WriteLine("Thank you for building and exploring this sample. Further steps could include:"); writer.WriteLine("1. Serialize build profile, application information, and other services as XML."); writer.WriteLine("2. Execute XSLT against XML from above to generate a traditional .csproj file, save result to a temp directory."); writer.WriteLine("3. Launch msbuild.exe and point it to .csproj from above."); writer.WriteLine(string.Empty); }
/// <summary> /// Load entities. /// </summary> /// <param name="context"></param> /// <returns></returns> public IEnumerable <EntityEntry> GetEntities(IProcessingContext context) { ///// // Query entities that are part of the solution ///// const string sql = @"select Uid from _Entity"; using (IDbCommand command = CreateCommand( )) { command.CommandText = sql; using (IDataReader reader = command.ExecuteReader( )) { while (reader.Read( )) { if (reader.IsDBNull(0)) { context.WriteWarning("Unexpected null UpgradeId in Entity."); continue; } var entry = new EntityEntry { EntityId = reader.GetGuid(0) }; yield return(entry); } } } }
/// <summary> /// Migrates the data. /// </summary> public void MigrateData( ) { IProcessingContext context = Context; ///// // Run any setup logic. ///// DataSource.Setup(context); DataTarget.Setup(context); ///// // Migrate metadata ///// context.WriteInfo("Copying metadata..."); Metadata metadata = DataSource.GetMetadata(context); DataTarget.SetMetadata(metadata, context); if (!CopyMetadataOnly) { MigrateContent(context); } ///// // Run any teardown logic. ///// DataTarget.TearDown(context); DataSource.TearDown(context); }
protected bool CheckValidity(IProcessingContext processingContext, KraftModule module, LoadedNodeSet loadedNodeSet) { if (processingContext.InputModel.LoaderType == ELoaderType.None) { Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"You have to specify a loader type."); return(false); } if (module == null) { Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"Requested module: {processingContext.InputModel.Module} doesn't exist or not loaded."); return(false); } if (loadedNodeSet == null) { Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"Requested nodeset: {processingContext.InputModel.NodeSet} doesn't exist or not loaded."); return(false); } if (loadedNodeSet.StartNode == null)//Handle errors better and show when a node is addressed but missing. { string error = $"Node: {processingContext.InputModel.Nodepath} from module: {processingContext.InputModel.Module}, nodeset: {processingContext.InputModel.NodeSet} is missing!"; KraftLogger.LogError(error); Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.InternalServerError, error); return(false); } //If authentication is required but the user is not logged in redirect to authentication if (loadedNodeSet.StartNode.RequireAuthentication && !processingContext.InputModel.SecurityModel.IsAuthenticated) { Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.Unauthorized, null); return(false); } return(true); }
/// <summary> /// Loads the application data. /// </summary> /// <param name="source">The source.</param> /// <param name="context">The context.</param> /// <param name="ignoreCardinalityViolations">if set to <c>true</c> [ignore cardinality violations].</param> /// <returns></returns> public static AppContents Load(IDataSource source, IProcessingContext context, bool ignoreCardinalityViolations = false) { ///// // Load entities, relationships and field data. ///// Dictionary <string, DocumentDataEntry> documentData = source.GetDocumentData(context) != null && source.GetDocumentData(context).Any( ) ? source.GetDocumentData(context).ToDictionary(d => d.GetKey( )) : new Dictionary <string, DocumentDataEntry>( ); var app = new AppContents { Entities = source.GetEntities(context).ToDictionary(e => e.GetKey( )), Relationships = ProcessRelationships(source.GetRelationships(context), context, ignoreCardinalityViolations), MissingRelationships = ProcessRelationships(source.GetMissingRelationships(context), context, true), FieldData = new Dictionary <string, Dictionary <Tuple <Guid, Guid>, DataEntry> >( ), MissingFieldData = source.GetMissingFieldData(context).ToDictionary(d => d.GetKey( )), BinaryData = source.GetBinaryData(context).ToDictionary(b => b.GetKey( )), DocumentData = documentData, DoNotRemove = new HashSet <Guid>(source.GetDoNotRemove(context)) }; foreach (string dataTable in Helpers.FieldDataTables) { app.FieldData[dataTable] = source.GetFieldData(dataTable, context).ToDictionary(d => d.GetKey( )); } return(app); }
/// <summary> /// Serializes the application using the specified XML writer. /// </summary> /// <param name="xmlWriter">The XML writer.</param> /// <param name="context">The context.</param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.InvalidOperationException">No xml writer specified.</exception> public void Serialize(XmlWriter xmlWriter, IProcessingContext context = null) { if (xmlWriter == null) { throw new ArgumentNullException(nameof(xmlWriter)); } if (context == null) { context = new ProcessingContext( ); } Context = context; RestructureFieldData( ); // XmlSerializerV2 needs metadata about relationships to build a nice hierarchy. // Most IDataSource don't provide it. So hit up the application library hacker to get some metadata. // Cross finders. if (PackageData.Metadata.RelationshipTypeCallback == null) { AppLibraryRelationshipMetadataRepository appLibRelMetadataRepos = new AppLibraryRelationshipMetadataRepository( ); PackageData.Metadata.RelationshipTypeCallback = appLibRelMetadataRepos.CreateMetadataCallback(PackageData.Relationships); } Stack <string> xmlStack = new Stack <string>( ); SerializeHeader(xmlWriter, xmlStack); if (xmlStack.Count > 0) { throw new InvalidOperationException($"Xml stack corruption detected. Expected empty stack but found '{string.Join( ",", xmlStack.ToArray( ).Reverse( ) )}'"); } }
/// <summary> /// Write in collection of entities. /// </summary> /// <param name="entities">The entities.</param> /// <param name="context">The context.</param> void IDataTarget.WriteEntities(IEnumerable <EntityEntry> entities, IProcessingContext context) { Func <DataColumn[]> getColumnsAction = () => new[] { new DataColumn("UpgradeId", typeof(Guid)) { AllowDBNull = false } }; Func <EntityEntry, DataRow, PopulateRowResult> populateRowAction = (entry, row) => { row[0] = entry.EntityId; return(PopulateRowResult.Success); }; var executionArguments = new ExecutionArguments <EntityEntry> { Entries = entities, GetColumnsAction = getColumnsAction, TableName = "Entities", Context = context, PopulateRowAction = populateRowAction, CommandText = CommandText.TenantMergeTargetWriteEntitiesCommandText, ExecuteAction = ExecuteAction.Writing, SetupCommandAction = c => c.AddParameterWithValue("@tenant", TenantId) }; Execute(executionArguments); ///// // Populate the UpgradeId to Id map. ///// PopulateUpgradeIdToIdMap( ); }
/// <summary> /// Deserializes the application using the specified XML reader. /// </summary> /// <param name="xmlReader">The XML text reader.</param> /// <param name="context">The context.</param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.InvalidOperationException"></exception> public PackageData Deserialize(XmlReader xmlReader, IProcessingContext context = null) { if (xmlReader == null) { throw new ArgumentNullException(nameof(xmlReader)); } if (context == null) { context = new ProcessingContext( ); } Context = context; DeserializeRoot(xmlReader); DecodeMembers( ); PackageData result = new PackageData { Binaries = _binaries, Documents = _documents, Entities = _entities, Relationships = _relationships, DoNotRemove = _doNotRemove, FieldData = _fieldData.ToDictionary(pair => pair.Key, pair => (IEnumerable <DataEntry>)pair.Value), Metadata = _metadata, SecureData = _secureData }; return(result); }
/// <summary> /// Setups the specified context. /// </summary> /// <param name="context">The context.</param> void IDataTarget.Setup(IProcessingContext context) { context?.WriteInfo("Initializing..."); long userId; RequestContext.TryGetUserId(out userId); using (EntryPointContext.UnsafeToIncludeEntryPoint( )) using (IDbCommand command = CreateCommand( )) { command.CommandText = CommandText.TenantRepairTargetSetupCommandText; command.CommandType = CommandType.Text; command.ExecuteNonQuery( ); command.CommandText = @" IF ( @context IS NOT NULL ) BEGIN DECLARE @contextInfo VARBINARY(128) = CONVERT( VARBINARY(128), @context ) SET CONTEXT_INFO @contextInfo END"; command.AddParameter("@context", DbType.AnsiString, DatabaseContextInfo.GetMessageChain(userId), 128); command.ExecuteNonQuery( ); } }
public IEnumerable <DocumentDataEntry> GetDocumentData(IProcessingContext context) { if (_documentCache == null) { var data = new List <DocumentDataEntry>( ); Func <string, byte[]> loadDocumentData = token => FileRepositoryUtils.LoadFileData(Factory.DocumentFileRepository, token, context); using (IDbCommand command = CreateCommand( )) { command.CommandType = CommandType.StoredProcedure; command.CommandText = "spGetTenantAppDocumentFileData"; command.AddParameterWithValue("@solutionId", SolutionId); command.AddParameterWithValue("@tenant", TenantId); using (IDataReader reader = command.ExecuteReader( )) { while (reader.Read( )) { var binaryDataEntry = new DocumentDataEntry { DataHash = reader.GetString(0), LoadDataCallback = loadDocumentData }; data.Add(binaryDataEntry); } } } _documentCache = data; } return(_documentCache); }
public void Execute(IProcessingContext processingContext, ITransactionScopeContext transactionScopeContext) { KraftModule loadedModule = _KraftModuleCollection.GetModule(processingContext.InputModel.Module); LoadedNodeSet loadedNodeSet = _NodesSetService.LoadNodeSet( processingContext.InputModel.Module, processingContext.InputModel.NodeSet, processingContext.InputModel.Nodepath); StringBuilder sb; if (!CheckValidity(processingContext, loadedModule, loadedNodeSet, out sb)) { PluginAccessorImp <IDataLoaderPlugin> externalService = new PluginAccessorImp <IDataLoaderPlugin>(transactionScopeContext, loadedModule.ModuleSettings); PluginAccessorImp <INodePlugin> customService = new PluginAccessorImp <INodePlugin>(transactionScopeContext, loadedModule.ModuleSettings); INodeTaskExecutor taskExecutor = new NodeTaskExecutor(transactionScopeContext, loadedModule.ModuleSettings); taskExecutor.Execute(loadedNodeSet, processingContext, externalService, customService); } else { processingContext.ReturnModel.Status.IsSuccessful = false; processingContext.ReturnModel.Status.StatusResults.Add(new StatusResult() { Message = sb.ToString(), StatusResultType = SysPlugins.Interfaces.Packet.StatusResultEnum.EStatusResult.StatusResultError }); } }
/// <summary> /// Updates the document data. /// </summary> /// <param name="documentData">The document data.</param> /// <param name="context">The context.</param> public void UpdateDocumentData(IEnumerable <DocumentDataEntry> documentData, IProcessingContext context) { foreach (DocumentDataEntry documentDataEntry in documentData) { context.WriteInfo(string.Format("Updated binary data: {0}", documentDataEntry.DataHash)); } }
/// <summary> /// Deletes entities. /// </summary> /// <param name="entities"></param> /// <param name="context"></param> void IMergeTarget.DeleteEntities(IEnumerable <EntityEntry> entities, IProcessingContext context) { ///// // Populate the UpgradeId to Id map. ///// PopulateUpgradeIdToIdMap( ); }
/// <summary> /// Processes the provided request asynchronously and returns a response promise. /// </summary> /// <param name="request">The request to be handled.</param> /// <param name="context">The processing context.</param> /// <param name="token">The cancellation token.</param> /// <returns> /// The response promise. /// </returns> public Task<IResponse> ProcessAsync(IRequest request, IProcessingContext context, CancellationToken token) { Contract.Requires(request != null); Contract.Requires(context != null); Contract.Ensures(Contract.Result<Task<IResponse>>() != null); return Contract.Result<Task<IResponse>>(); }
public void EnrichConstructor(IProcessingContext context, ConstructorInfo ctor) { XmlDocReader reader = this.GetDocReader(ctor.DeclaringType.Assembly); if (reader != null) { XElement element = reader.GetDocComments(ctor); if (element != null) this.RewriteXml(context, ctor.ReflectedType.Assembly, element, "param", "typeparam"); } }
public void EnrichType(IProcessingContext context, Type type) { XmlDocReader reader = this.GetDocReader(type.Assembly); if (reader != null) { XElement element = reader.GetDocComments(type); if (element != null) this.RewriteXml(context, type.Assembly, element, "typeparam"); } }
public void EnrichParameter(IProcessingContext context, ParameterInfo parameter) { XmlDocReader reader = this.GetDocReader(context, parameter.Member.ReflectedType.Assembly); if (reader != null) { XElement element = reader.GetDocComments(parameter); if (element != null) this.RewriteXmlContent(context, parameter.Member.ReflectedType.Assembly, "summary", element); } }
public void EnrichParameter(IProcessingContext context, ParameterInfo parameter) { XmlDocReader reader = this.GetDocReader(parameter.Member.DeclaringType.Assembly); if (reader != null) { XNamespace ns = "urn:doc"; XElement element = reader.GetDocComments(parameter); if (element != null) this.RewriteXmlContent(context, "summary", element); } }
public new void InstallSecurity(string path, IProcessingContext context) { Assert.ArgumentNotNullOrEmpty(path, "path"); Assert.ArgumentNotNull((object)context, "context"); Log.Info("Installing security from package: " + path, (object)this); PackageReader packageReader = new PackageReader(path); AccountInstaller accountInstaller = new AccountInstaller(); accountInstaller.Initialize(context); packageReader.Populate((ISink<PackageEntry>)accountInstaller); accountInstaller.Flush(); accountInstaller.Finish(); }
private void GenerateImplementsElement(IProcessingContext context, MemberInfo mInfo) { Type declaringType = mInfo.DeclaringType; if (declaringType.IsGenericType && !declaringType.IsGenericTypeDefinition) declaringType = declaringType.GetGenericTypeDefinition(); if (!declaringType.IsInterface) { Type[] interfaces = declaringType.GetInterfaces(); foreach (Type ifType in interfaces) { if (context.IsFiltered(AssetIdentifier.FromMemberInfo(ifType))) continue; InterfaceMapping ifMap = declaringType.GetInterfaceMap(ifType); if (ifMap.TargetType != declaringType) continue; var targetMethod = ifMap.TargetMethods.SingleOrDefault(mi => mi.MetadataToken == mInfo.MetadataToken && mi.Module == mInfo.Module); if (targetMethod != null) { int mIx = Array.IndexOf(ifMap.TargetMethods, targetMethod); AssetIdentifier miAid; if (ifMap.InterfaceMethods[mIx].DeclaringType.IsGenericType) { Type declType = ifMap.InterfaceMethods[mIx].DeclaringType.GetGenericTypeDefinition(); MethodInfo[] allMethods = declType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); miAid = AssetIdentifier.FromMemberInfo(allMethods.Single(mi => mi.MetadataToken == ifMap.InterfaceMethods[mIx].MetadataToken && mi.Module == ifMap.InterfaceMethods[mIx].Module)); } else { miAid = AssetIdentifier.FromMemberInfo(ifMap.InterfaceMethods[mIx]); } context.Element.Add(new XElement("implements", new XAttribute("member", miAid))); context.AddReference(miAid); } } } }
private XElement GenerateMethodElement(IProcessingContext context, AssetIdentifier assetId) { // Debug.Assert(context.Element.Name.LocalName != "type", "Cannot put Method into closed generic type"); MethodBase mBase = (MethodBase)context.AssetResolver.Resolve(assetId); if (mBase is ConstructorInfo) return this.GenerateConstructorElement(context, assetId); MethodInfo mInfo = (MethodInfo)mBase; string elemName; if (this.IsOperator(mInfo)) elemName = "operator"; else elemName = "method"; XElement ret = new XElement(elemName, new XAttribute("name", mInfo.Name), new XAttribute("assetId", assetId), new XAttribute("phase", context.Phase)); context.Element.Add(ret); Type declaringType = mInfo.DeclaringType; if (declaringType.IsGenericType && !declaringType.IsGenericTypeDefinition) declaringType = declaringType.GetGenericTypeDefinition(); MethodInfo realMethodInfo = declaringType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).Single( mi => mi.MetadataToken == mInfo.MetadataToken && mi.Module == mInfo.Module); AssetIdentifier declaredAs = AssetIdentifier.FromMemberInfo(realMethodInfo); if (declaringType != mInfo.ReflectedType) { ret.Add(new XAttribute("declaredAs", declaredAs)); context.AddReference(declaredAs); } else if (realMethodInfo.GetBaseDefinition() != realMethodInfo) { MethodInfo baseMethod = realMethodInfo.GetBaseDefinition(); if (baseMethod.ReflectedType.IsGenericType) { Type realTypeBase = baseMethod.ReflectedType.GetGenericTypeDefinition(); MethodInfo[] allMethods = realTypeBase.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); baseMethod = allMethods.Single( m => m.Module == baseMethod.Module && m.MetadataToken == baseMethod.MetadataToken); } declaredAs = AssetIdentifier.FromMemberInfo(baseMethod); ret.Add(new XAttribute("overrides", declaredAs)); context.AddReference(declaredAs); } this.GenerateImplementsElement(context.Clone(ret), mInfo); this.GenerateAccessModifiers(ret, mInfo); if (mInfo.ContainsGenericParameters) { Type[] typeParams = mInfo.GetGenericArguments(); foreach (Type tp in typeParams) this.GenerateTypeParamElement(context.Clone(ret), mInfo, tp); } foreach (IEnricher item in this.Enrichers) item.EnrichMethod(context.Clone(ret), mInfo); ParameterInfo[] methodParams = mInfo.GetParameters(); this.GenerateParameterElements(context.Clone(ret), methodParams); if (mInfo.ReturnType != typeof(void)) { XElement retElem = new XElement("returns"); GenerateTypeRef(context.Clone(retElem), mInfo.ReturnType); foreach (IEnricher item in this.Enrichers) item.EnrichReturnValue(context.Clone(retElem), mInfo); ret.Add(retElem); } return ret; }
private void GenerateTypeParamElement(IProcessingContext context, MemberInfo mInfo, Type tp) { // AssetIdentifier assetId = AssetIdentifier.FromType(mInfo, tp); var tpElem = new XElement("typeparam", new XAttribute("name", tp.Name)); context.Element.Add(tpElem); foreach (Type constraint in tp.GetGenericParameterConstraints()) { var ctElement = new XElement("constraint"); tpElem.Add(ctElement); GenerateTypeRef(context.Clone(ctElement), constraint); } // enrich typeparam foreach (IEnricher enricher in this.Enrichers) enricher.EnrichTypeParameter(context.Clone(tpElem), tp); }
private XElement GenerateTypeElement(IProcessingContext context, AssetIdentifier assetId) { XElement ret; Type type = (Type)context.AssetResolver.Resolve(assetId); string elemName; if (type.IsClass) elemName = "class"; else if (type.IsEnum) elemName = "enum"; else if (type.IsValueType) elemName = "struct"; else if (type.IsInterface) elemName = "interface"; else throw new ArgumentException("Unknown asset type: " + assetId.Type.ToString(), "assetId"); ret = new XElement(elemName, new XAttribute("name", type.Name), new XAttribute("assetId", assetId), new XAttribute("phase", context.Phase)); if (type.IsEnum) { AssetIdentifier aid = AssetIdentifier.FromType(type.GetEnumUnderlyingType()); ret.Add(new XAttribute("underlyingType", aid)); context.AddReference(aid); } if (!type.IsInterface && type.IsAbstract) ret.Add(new XAttribute("isAbstract", XmlConvert.ToString(type.IsAbstract))); if (!type.IsVisible || type.IsNested && type.IsNestedAssembly) ret.Add(new XAttribute("isInternal", XmlConvert.ToString(true))); if (type.IsPublic || type.IsNested && type.IsNestedPublic) ret.Add(new XAttribute("isPublic", XmlConvert.ToString(true))); if (type.IsNested && type.IsNestedPrivate) ret.Add(new XAttribute("isPrivate", XmlConvert.ToString(true))); if (type.IsNested && type.IsNestedFamily) ret.Add(new XAttribute("isProtected", XmlConvert.ToString(true))); if (type.IsNested && type.IsNestedFamANDAssem) ret.Add(new XAttribute("isProtectedAndInternal", XmlConvert.ToString(true))); if (type.IsNested && type.IsNestedFamORAssem) ret.Add(new XAttribute("isProtectedOrInternal", XmlConvert.ToString(true))); if (type.IsClass && type.IsSealed) ret.Add(new XAttribute("isSealed", XmlConvert.ToString(true))); if (type.BaseType != null) { AssetIdentifier baseAid = AssetIdentifier.FromType(type.BaseType); if (!context.IsFiltered(baseAid)) { var inheritsElem = new XElement("inherits"); ret.Add(inheritsElem); GenerateTypeRef(context.Clone(inheritsElem), type.BaseType); } } if (type.ContainsGenericParameters) { Type[] typeParams = type.GetGenericArguments(); foreach (Type tp in typeParams) { this.GenerateTypeParamElement(context.Clone(ret), type, tp); } } if (type.IsClass) { foreach (Type interfaceType in type.GetInterfaces()) { InterfaceMapping mapping = type.GetInterfaceMap(interfaceType); if (mapping.TargetType == type) { AssetIdentifier interfaceAssetId = AssetIdentifier.FromType(interfaceType.IsGenericType ? interfaceType.GetGenericTypeDefinition() : interfaceType); if (!context.IsFiltered(interfaceAssetId)) { var implElement = new XElement("implements"); ret.Add(implElement); GenerateTypeRef(context.Clone(implElement), interfaceType, "interface"); } } } } foreach (IEnricher enricher in this._enrichers) enricher.EnrichType(context.Clone(ret), type); context.Element.Add(ret); return ret; }
public void EnrichTypeParameter(IProcessingContext context, Type typeParameter) { GenerateAttributeElements(context, typeParameter.GetCustomAttributesData()); }
private XElement GeneratePropertyElement(IProcessingContext context, AssetIdentifier assetId) { PropertyInfo propInfo = (PropertyInfo)context.AssetResolver.Resolve(assetId); XElement ret = new XElement("property", new XAttribute("name", propInfo.Name), new XAttribute("assetId", assetId), new XAttribute("phase", context.Phase)); GenerateTypeRef(context.Clone(ret), propInfo.PropertyType); ParameterInfo[] pInfos = propInfo.GetIndexParameters(); this.GenerateParameterElements(context.Clone(ret), pInfos); MethodInfo setMethod = propInfo.GetSetMethod(true); MethodInfo getMethod = propInfo.GetGetMethod(true); if ((setMethod ?? getMethod).IsAbstract) ret.Add(new XAttribute("isAbstract", XmlConvert.ToString(true))); if ((setMethod ?? getMethod).IsVirtual) ret.Add(new XAttribute("isVirtual", XmlConvert.ToString(true))); const int C_PUBLIC = 10; const int C_INTERNAL_OR_PROTECTED = 8; const int C_INTERNAL = 6; const int C_PROTECTED = 4; const int C_INTERNAL_AND_PROTECTED = 2; const int C_PRIVATE = 0; int leastRestrictiveAccessModifier; if (setMethod != null && setMethod.IsPublic || getMethod != null && getMethod.IsPublic) { ret.Add(new XAttribute("isPublic", XmlConvert.ToString(true))); leastRestrictiveAccessModifier = C_PUBLIC; } else if (setMethod != null && setMethod.IsFamilyOrAssembly || getMethod != null && getMethod.IsFamilyOrAssembly) { ret.Add(new XAttribute("isInternalOrProtected", XmlConvert.ToString(true))); leastRestrictiveAccessModifier = C_INTERNAL_OR_PROTECTED; } else if (setMethod != null && setMethod.IsAssembly || getMethod != null && getMethod.IsAssembly) { ret.Add(new XAttribute("isInternal", XmlConvert.ToString(true))); leastRestrictiveAccessModifier = C_INTERNAL; } else if (setMethod != null && setMethod.IsFamily || getMethod != null && getMethod.IsFamily) { ret.Add(new XAttribute("isProtected", XmlConvert.ToString(true))); leastRestrictiveAccessModifier = C_PROTECTED; } else if (setMethod != null && setMethod.IsFamilyAndAssembly || getMethod != null && getMethod.IsFamilyAndAssembly) { ret.Add(new XAttribute("isInternalAndProtected", XmlConvert.ToString(true))); leastRestrictiveAccessModifier = C_INTERNAL_AND_PROTECTED; } else if (setMethod != null && setMethod.IsPrivate || getMethod != null && getMethod.IsPrivate) { ret.Add(new XAttribute("isPrivate", XmlConvert.ToString(true))); leastRestrictiveAccessModifier = C_PRIVATE; } else { throw new InvalidOperationException("What the hell happened here?"); } if (setMethod != null) { var setElem = new XElement("set"); if (leastRestrictiveAccessModifier > C_INTERNAL_OR_PROTECTED && setMethod.IsFamilyOrAssembly) setElem.Add(new XAttribute("isInternalOrProtected", XmlConvert.ToString(setMethod.IsFamilyOrAssembly))); if (leastRestrictiveAccessModifier > C_INTERNAL && setMethod.IsAssembly) setElem.Add(new XAttribute("isInternal", XmlConvert.ToString(setMethod.IsAssembly))); if (leastRestrictiveAccessModifier > C_PROTECTED && setMethod.IsFamily) setElem.Add(new XAttribute("isProtected", XmlConvert.ToString(setMethod.IsFamily))); if (leastRestrictiveAccessModifier > C_INTERNAL_AND_PROTECTED && setMethod.IsFamilyAndAssembly) setElem.Add(new XAttribute("isInternalAndProtected", XmlConvert.ToString(setMethod.IsFamilyAndAssembly))); if (leastRestrictiveAccessModifier > C_PRIVATE && setMethod.IsPrivate) setElem.Add(new XAttribute("isPrivate", XmlConvert.ToString(setMethod.IsPrivate))); ret.Add(setElem); } if (getMethod != null) { var getElem = new XElement("get"); if (leastRestrictiveAccessModifier > C_INTERNAL_OR_PROTECTED && getMethod.IsFamilyOrAssembly) getElem.Add(new XAttribute("isInternalOrProtected", XmlConvert.ToString(getMethod.IsFamilyOrAssembly))); if (leastRestrictiveAccessModifier > C_INTERNAL && getMethod.IsAssembly) getElem.Add(new XAttribute("isInternal", XmlConvert.ToString(getMethod.IsAssembly))); if (leastRestrictiveAccessModifier > C_PROTECTED && getMethod.IsFamily) getElem.Add(new XAttribute("isProtected", XmlConvert.ToString(getMethod.IsFamily))); if (leastRestrictiveAccessModifier > C_INTERNAL_AND_PROTECTED && getMethod.IsFamilyAndAssembly) getElem.Add(new XAttribute("isInternalAndProtected", XmlConvert.ToString(getMethod.IsFamilyAndAssembly))); if (leastRestrictiveAccessModifier > C_PRIVATE && getMethod.IsPrivate) getElem.Add(new XAttribute("isPrivate", XmlConvert.ToString(getMethod.IsPrivate))); ret.Add(getElem); } if (propInfo.IsSpecialName) ret.Add(new XAttribute("isSpecialName", XmlConvert.ToString(propInfo.IsSpecialName))); context.Element.Add(ret); this.GenerateImplementsElement(context.Clone(ret), propInfo); foreach (IEnricher item in this.Enrichers) item.EnrichProperty(context.Clone(ret), propInfo); return ret; }
private XElement GenerateFieldElement(IProcessingContext context, AssetIdentifier assetId) { object resolve = context.AssetResolver.Resolve(assetId); FieldInfo fieldInfo = (FieldInfo)resolve; XElement ret = new XElement("field", new XAttribute("name", fieldInfo.Name), new XAttribute("assetId", assetId), new XAttribute("phase", context.Phase)); if (fieldInfo.IsStatic) ret.Add(new XAttribute("isStatic", XmlConvert.ToString(fieldInfo.IsStatic))); if (fieldInfo.IsPublic) ret.Add(new XAttribute("isPublic", XmlConvert.ToString(fieldInfo.IsPublic))); if (fieldInfo.IsPrivate) ret.Add(new XAttribute("isPrivate", XmlConvert.ToString(fieldInfo.IsPrivate))); if (fieldInfo.IsFamily) ret.Add(new XAttribute("isProtected", XmlConvert.ToString(fieldInfo.IsFamily))); if (fieldInfo.IsFamilyOrAssembly) ret.Add(new XAttribute("isProtectedOrInternal", XmlConvert.ToString(fieldInfo.IsFamilyOrAssembly))); if (fieldInfo.IsFamilyAndAssembly) ret.Add(new XAttribute("isProtectedAndInternal", XmlConvert.ToString(fieldInfo.IsFamilyAndAssembly))); if (fieldInfo.IsSpecialName) ret.Add(new XAttribute("isSpecialName", XmlConvert.ToString(fieldInfo.IsSpecialName))); GenerateTypeRef(context.Clone(ret), fieldInfo.FieldType); context.Element.Add(ret); foreach (IEnricher item in this.Enrichers) item.EnrichField(context.Clone(ret), fieldInfo); return ret; }
public void EnrichProperty(IProcessingContext context, PropertyInfo propertyInfo) { GenerateAttributeElements(context, propertyInfo.GetCustomAttributesData()); }
public void EnrichReturnValue(IProcessingContext context, MethodInfo methodInfo) { GenerateAttributeElements(context, CustomAttributeData.GetCustomAttributes(methodInfo.ReturnParameter)); }
public void RegisterNamespace(IProcessingContext context) { }
// ------------------------------------------------------------------- // Public // ------------------------------------------------------------------- public void BuildProjectFile(IList<CarbonFileResult> sources, CarbonFile target, IProcessingContext context) { Diagnostic.Info("Building {0} Sources into {2}", sources.Count, target); }
private static void GenerateAttributeElements(IProcessingContext context, IEnumerable<CustomAttributeData> attrData) { foreach (CustomAttributeData custAttr in attrData) { context.AddReference(AssetIdentifier.FromMemberInfo(custAttr.Constructor)); var attrElem = new XElement("attribute", new XAttribute("type", AssetIdentifier.FromMemberInfo( custAttr.Constructor. ReflectedType ?? custAttr.Constructor. DeclaringType)), new XAttribute("constructor", AssetIdentifier.FromMemberInfo(custAttr.Constructor))); foreach (CustomAttributeTypedArgument cta in custAttr.ConstructorArguments) { if (cta.Value is ReadOnlyCollection<CustomAttributeTypedArgument>) { AssetIdentifier elementAssetId = AssetIdentifier.FromMemberInfo(cta.ArgumentType.GetElementType()); context.AddReference(elementAssetId); attrElem.Add(new XElement("argument", new XElement("array", new XAttribute("type", elementAssetId), ((IEnumerable<CustomAttributeTypedArgument>)cta.Value). Select( ata => new XElement("element", GenerateAttributeArgument( context, ata)))))); } else { attrElem.Add(new XElement("argument", GenerateAttributeArgument(context, cta))); } } foreach (CustomAttributeNamedArgument cta in custAttr.NamedArguments) { AssetIdentifier namedMember = AssetIdentifier.FromMemberInfo(cta.MemberInfo); context.AddReference(namedMember); if (cta.TypedValue.Value is ReadOnlyCollection<CustomAttributeTypedArgument>) { context.AddReference(namedMember); AssetIdentifier elementAssetId = AssetIdentifier.FromMemberInfo(cta.TypedValue.ArgumentType.GetElementType()); context.AddReference(elementAssetId); attrElem.Add(new XElement("argument", new XAttribute("member", namedMember), new XElement("array", new XAttribute("type", elementAssetId), ((IEnumerable<CustomAttributeTypedArgument>) cta.TypedValue.Value).Select( ata => new XElement("element", GenerateAttributeArgument (context, ata)))))); } else { attrElem.Add(new XElement("argument", new XAttribute("member", namedMember), GenerateAttributeArgument(context, cta.TypedValue))); } } context.Element.Add(attrElem); } }
public void EnrichEvent(IProcessingContext context, EventInfo eventInfo) { GenerateAttributeElements(context, eventInfo.GetCustomAttributesData()); }
// namespaces don't have attributes public void EnrichNamespace(IProcessingContext context, string ns) { }
private void GenerateParameterElements(IProcessingContext context, ParameterInfo[] methodParams) { foreach (ParameterInfo item in methodParams) { XElement pElem = new XElement("param", new XAttribute("name", item.Name)); Type pType; if (item.ParameterType.IsByRef) pType = item.ParameterType.GetElementType(); else pType = item.ParameterType; if (item.ParameterType.IsByRef && item.IsOut && !item.IsIn) pElem.Add(new XAttribute("isOut", true)); else if (item.ParameterType.IsByRef) pElem.Add(new XAttribute("isRef", true)); GenerateTypeRef(context.Clone(pElem), pType); foreach (IEnricher enricher in this.Enrichers) enricher.EnrichParameter(context.Clone(pElem), item); context.Element.Add(pElem); } }
private XElement GenerateConstructorElement(IProcessingContext context, AssetIdentifier assetId) { ConstructorInfo constructorInfo = (ConstructorInfo)context.AssetResolver.Resolve(assetId); XElement ret = new XElement("constructor", new XAttribute("assetId", assetId), new XAttribute("phase", context.Phase)); if (constructorInfo.IsStatic) ret.Add(new XAttribute("isStatic", XmlConvert.ToString(constructorInfo.IsStatic))); if (constructorInfo.IsPublic) ret.Add(new XAttribute("isPublic", XmlConvert.ToString(constructorInfo.IsPublic))); if (constructorInfo.IsPrivate) ret.Add(new XAttribute("isPrivate", XmlConvert.ToString(constructorInfo.IsPrivate))); if (constructorInfo.IsFamily) ret.Add(new XAttribute("isProtected", XmlConvert.ToString(constructorInfo.IsFamily))); context.Element.Add(ret); foreach (IEnricher item in this.Enrichers) item.EnrichConstructor(context.Clone(ret), constructorInfo); ParameterInfo[] methodParams = constructorInfo.GetParameters(); this.GenerateParameterElements(context.Clone(ret), methodParams); return ret; }
public void EnrichField(IProcessingContext context, FieldInfo fieldInfo) { GenerateAttributeElements(context, fieldInfo.GetCustomAttributesData()); }
private XElement GenerateEventElement(IProcessingContext context, AssetIdentifier assetId) { EventInfo eventInfo = (EventInfo)context.AssetResolver.Resolve(assetId); XElement ret = new XElement("event", new XAttribute("name", eventInfo.Name), new XAttribute("assetId", assetId), new XAttribute("phase", context.Phase)); GenerateTypeRef(context.Clone(ret), eventInfo.EventHandlerType); MethodInfo addMethod = eventInfo.GetAddMethod(true); MethodInfo removeMethod = eventInfo.GetRemoveMethod(true); if (addMethod != null) { var addElem = new XElement("add"); if (addMethod.IsPublic) addElem.Add(new XAttribute("isPublic", XmlConvert.ToString(addMethod.IsPublic))); if (addMethod.IsPrivate) addElem.Add(new XAttribute("isPrivate", XmlConvert.ToString(addMethod.IsPrivate))); if (addMethod.IsFamily) addElem.Add(new XAttribute("isProtected", XmlConvert.ToString(addMethod.IsFamily))); ret.Add(addElem); } if (removeMethod != null) { var removeElem = new XElement("remove"); if (removeMethod.IsPublic) removeElem.Add(new XAttribute("isPublic", XmlConvert.ToString(removeMethod.IsPublic))); if (removeMethod.IsPrivate) removeElem.Add(new XAttribute("isPrivate", XmlConvert.ToString(removeMethod.IsPrivate))); if (removeMethod.IsFamily) removeElem.Add(new XAttribute("isProtected", XmlConvert.ToString(removeMethod.IsFamily))); ret.Add(removeElem); } context.Element.Add(ret); this.GenerateImplementsElement(context.Clone(ret), eventInfo); foreach (IEnricher item in this.Enrichers) item.EnrichEvent(context.Clone(ret), eventInfo); return ret; }
private XElement GenerateNamespaceElement(IProcessingContext context, AssetIdentifier assetId) { string ns = (string)context.AssetResolver.Resolve(assetId); var ret = new XElement("namespace", new XAttribute("name", ns), new XAttribute("assetId", assetId), new XAttribute("phase", context.Phase)); context.Element.Add(ret); foreach (IEnricher enricher in this._enrichers) enricher.EnrichNamespace(context.Clone(ret), ns); return ret; }
public static void GenerateTypeRef(IProcessingContext context, Type pType, string attrName = null) { if (pType.IsArray) { var arrayElem = new XElement("arrayOf", new XAttribute("rank", pType.GetArrayRank())); context.Element.Add(arrayElem); GenerateTypeRef(context.Clone(arrayElem), pType.GetElementType()); } else { if (pType.IsGenericParameter) context.Element.Add(new XAttribute("param", pType.Name)); else if (pType.IsGenericType) { AssetIdentifier aid = AssetIdentifier.FromType(pType.GetGenericTypeDefinition()); context.AddReference(aid); context.Element.Add(new XAttribute(attrName ?? "type", aid)); foreach (Type genArg in pType.GetGenericArguments()) { XElement argElem = new XElement("with"); GenerateTypeRef(context.Clone(argElem), genArg); context.Element.Add(argElem); } } else { AssetIdentifier aid = AssetIdentifier.FromMemberInfo(pType); context.AddReference(aid); context.Element.Add(new XAttribute(attrName ?? "type", aid)); } } }
public void EnrichParameter(IProcessingContext context, ParameterInfo item) { GenerateAttributeElements(context, item.GetCustomAttributesData()); }
private XElement GenerateAssemblyElement(IProcessingContext context, AssetIdentifier assetId) { Assembly asm = (Assembly)context.AssetResolver.Resolve(assetId); var ret = new XElement("assembly", new XAttribute("name", asm.GetName().Name), new XAttribute("filename", asm.ManifestModule.Name), new XAttribute("assetId", assetId), new XAttribute("phase", context.Phase), asm.GetReferencedAssemblies().Select( an => new XElement("references", new XAttribute("assembly", AssetIdentifier. FromAssembly( Assembly . ReflectionOnlyLoad (an . FullName)))))); context.Element.Add(ret); foreach (IEnricher enricher in this._enrichers) enricher.EnrichAssembly(context.Clone(ret), asm); return ret; }
public void EnrichMethod(IProcessingContext context, MethodInfo mInfo) { GenerateAttributeElements(context, mInfo.GetCustomAttributesData()); }