void AddNewArtifact(Dolittle.Artifacts.Artifact artifactObject, Type artifact, IDictionary <ArtifactId, ArtifactDefinition> mutableArtifacts, string artifactTypeName) { var artifactDefinition = new ArtifactDefinition(artifactObject.Generation, ClrType.FromType(artifact)); _buildMessages.Trace($"Adding '{artifact.Name}' as a new {artifactTypeName} artifact with identifier '{artifactObject.Id}'"); mutableArtifacts[artifactObject.Id] = artifactDefinition; }
/// <summary> /// Convert from <see cref="Dolittle.Artifacts.Artifact"/> to <see cref="Artifact"/> /// </summary> /// <param name="artifact"><see cref="Dolittle.Artifacts.Artifact"/> to convert from</param> /// <returns>Converted <see cref="Artifact"/></returns> public static Artifact ToProtobuf(this Dolittle.Artifacts.Artifact artifact) { var message = new Artifact(); message.Id = artifact.Id.ToProtobuf(); message.Generation = artifact.Generation.Value; return(message); }
int HandleArtifactOfType(ArtifactType artifactType, BoundedContextTopology boundedContextConfiguration, MutableAritfactsDictionary artifactsDictionary, List <string> nonMatchingArtifacts) { var targetProperty = artifactType.TargetPropertyExpression.GetPropertyInfo(); var newArtifacts = 0; var artifacts = _artifacts.Where(_ => artifactType.Type.IsAssignableFrom(_)); foreach (var artifact in artifacts) { var feature = boundedContextConfiguration.FindMatchingFeature(artifact.Namespace, nonMatchingArtifacts); if (feature.Value != null) { MutableArtifactsByTypeDictionary artifactsByType; if (!artifactsDictionary.TryGetValue(feature.Key, out artifactsByType)) { artifactsByType = artifactsDictionary[feature.Key] = new Dictionary <PropertyInfo, Dictionary <ArtifactId, ArtifactDefinition> >(); } Dictionary <ArtifactId, ArtifactDefinition> mutableArtifacts; if (!artifactsByType.TryGetValue(targetProperty, out mutableArtifacts)) { mutableArtifacts = artifactsByType[targetProperty] = new Dictionary <ArtifactId, ArtifactDefinition>(); } if (!mutableArtifacts.Any(_ => _.Value.Type.GetActualType() == artifact)) { var artifactObject = new Dolittle.Artifacts.Artifact(ArtifactId.New(), ArtifactGeneration.First); if (artifact.HasAttribute <ArtifactAttribute>()) { artifactObject = (artifact.GetTypeInfo().GetCustomAttributes(typeof(ArtifactAttribute), false).First() as ArtifactAttribute).Artifact; } AddNewArtifact(artifactObject, artifact, mutableArtifacts, artifactType.TypeName); newArtifacts++; } else { if (artifact.HasAttribute <ArtifactAttribute>()) { var artifactObject = (artifact.GetTypeInfo().GetCustomAttributes(typeof(ArtifactAttribute), false).First() as ArtifactAttribute).Artifact; var existingArtifact = mutableArtifacts.Single(_ => _.Value.Type.GetActualType() == artifact); if (!existingArtifact.Key.Value.Equals(artifactObject.Id.Value)) { mutableArtifacts.Remove(existingArtifact.Key); AddNewArtifact(artifactObject, artifact, mutableArtifacts, artifactType.TypeName); newArtifacts++; } } } } } return(newArtifacts); }
/// <summary> /// Initializes a new instance of the <see cref="ArtifactAttribute"/> class. /// </summary> /// <param name="id"><see cref="ArtifactId"/> of the artifact.</param> /// <param name="generation"><see cref="ArtifactGeneration"/>.</param> public ArtifactAttribute(string id, int generation) { Artifact = new Artifact(Guid.Parse(id), generation); }