/// <summary> /// Get the domain qualified entity name for an event stream /// </summary> /// <param name="eventStreamIdentity"> /// The unique identity of the event stream /// </param> public static string MakeDomainQualifiedEntityName(IEventStreamIdentity eventStreamIdentity, bool AllEntityTypes = false, bool AllDomains = false) { if (null != eventStreamIdentity) { if (!(AllEntityTypes || AllEntityTypes)) { return($"{eventStreamIdentity.DomainName}.{eventStreamIdentity.EntityTypeName}"); } if (AllEntityTypes && AllDomains) { return(@"ALL.ALL"); } if (AllEntityTypes) { return($"{eventStreamIdentity.DomainName}.ALL"); } if (AllDomains) { return($"ALL.{eventStreamIdentity.EntityTypeName}"); } } return(@""); }
public Task ExistingEntityDeleted(IEventStreamIdentity deletedEntity, string commentary = "", IWriteContext context = null) { // do nothing return(Task.CompletedTask); }
public Task NewEntityCreated(IEventStreamIdentity newEntity, string commentary = @"", IWriteContext context = null) { // do nothing return(Task.CompletedTask); }
public static Task EventGridEcho([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log, [SignalR(HubName = "retailbank")] IAsyncCollector <SignalRMessage> signalRMessages) { if (null != eventGridEvent) { log.LogInformation($"{eventGridEvent.EventType} :: {eventGridEvent.Subject}"); log.LogInformation(eventGridEvent.Data.ToString()); // Get the signalR group from the event stream identity string groupName = string.Empty; IEventStreamIdentity eventTarget = eventGridEvent.Data as IEventStreamIdentity; if (eventTarget != null) { groupName = MakeSignalRGroupName(eventTarget); } return(signalRMessages.AddAsync( new SignalRMessage { GroupName = groupName, Target = eventGridEvent.EventType, Arguments = new[] { eventGridEvent.Data } })); } else { log.LogError($"Event grid event is null"); return(Task.CompletedTask); } }
public BlobEventStreamWriter(IEventStreamIdentity identity, string connectionStringName = @"") : base(identity, writeAccess: true, connectionStringName: connectionStringName) { }
public static NewEntityEventGridPayload Create(IEventStreamIdentity newEntity, string notificationId = @"", string commentary = @"", IWriteContext context = null) { if (null == newEntity) { throw new ArgumentNullException(nameof(newEntity)); } // Default the notification id if not are provided if (string.IsNullOrEmpty(notificationId)) { notificationId = Guid.NewGuid().ToString("N"); } return(new NewEntityEventGridPayload() { DomainName = newEntity.DomainName, EntityTypeName = newEntity.EntityTypeName, InstanceKey = newEntity.InstanceKey, NotificationId = notificationId, Commentary = commentary, Context = context }); }
public static Notification NewEventNotification(IEventStreamIdentity eventStreamIdentity, string eventName) { return(new Notification(NotificationType.NewEvent, eventStreamIdentity, eventName)); }
/// <summary> /// Generate a query to get the event rows for an individual event stream between two sequence numbers (inclusive) /// </summary> /// <param name="identity"> /// The unique identifier of the event stream to read /// </param> /// <param name="startingSequence"> /// The starting sequence to read from /// </param> /// <param name="upToSequence"> /// (Optional) The end sequence to read up to (inclusive) /// </param> public static TableQuery <DynamicTableEntity> ProjectionQuery(IEventStreamIdentity identity, int startingSequence = 1, int upToSequence = 0) { if (upToSequence > 0) { if (startingSequence >= upToSequence) { throw new EventStreamReadException(identity, startingSequence, $"Requested end sequence {upToSequence} is less than or equal to start sequence {startingSequence}"); } } TableQuery <DynamicTableEntity> ret = InstanceQuery(identity).Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, SequenceNumberAsString(startingSequence))); if (upToSequence > 0) { ret = ret.Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, SequenceNumberAsString(upToSequence))); } return(ret); }
private void CreateFronEnvironmentStringIfNotExists(IEventStreamIdentity attribute) { if (!AllSettings.ContainsKey(EventStreamSetting.MakeDomainQualifiedEntityName(attribute))) { string envValue = Environment.GetEnvironmentVariable(EventStreamSetting.MakeEnvironmentStringKey(attribute)); if (string.IsNullOrWhiteSpace(envValue)) { envValue = Environment.GetEnvironmentVariable(EventStreamSetting.MakeEnvironmentStringKey(attribute, AllEntityTypes: true)); } if (string.IsNullOrWhiteSpace(envValue)) { envValue = Environment.GetEnvironmentVariable(EventStreamSetting.MakeEnvironmentStringKey(attribute, AllDomains: true)); } if (string.IsNullOrWhiteSpace(envValue)) { envValue = Environment.GetEnvironmentVariable(EventStreamSetting.MakeEnvironmentStringKey(attribute, AllEntityTypes: true, AllDomains: true)); } if (!string.IsNullOrWhiteSpace(envValue)) { EventStreamSetting newSetting = EventStreamSetting.SettingsFromEnvironmentStringValue(attribute, envValue); if (null != newSetting) { AllSettings.TryAdd(EventStreamSetting.MakeDomainQualifiedEntityName(attribute), newSetting); } } } }
public Task NewEventAppended(IEventStreamIdentity targetEntity, string eventType, int sequenceNumber, string commentary = @"", object messagePayload = null, IWriteContext context = null) { // do nothing return(Task.CompletedTask); }
/// <summary> /// Make an event type name for the newly created entity notification message /// </summary> /// <param name="newEntity"> /// The newly created entity /// </param> public static string MakeEventTypeName(IEventStreamIdentity newEntity) { if (null == newEntity) { return(EVENT_TYPE); } return($"{newEntity.DomainName}.{newEntity.EntityTypeName}.NewEntity"); }
/// <summary> /// Make an event type name for the deleted entity notification message /// </summary> /// <param name="newEntity"> /// The newly created entity /// </param> public static string MakeEventTypeName(IEventStreamIdentity deletedEntity) { if (null == deletedEntity) { return(EVENT_TYPE); } return($"{deletedEntity.DomainName}.{deletedEntity.EntityTypeName}.DeletedEntity"); }
public static ClassificationCompleteEventGridPayload Create(IEventStreamIdentity targetEntity, string classificationType, int asOfSequenceNumber, DateTime?asOfDate, ClassificationResponse response, Dictionary <string, object> parameters, string notificationId = @"", string commentary = @"") { if (null == targetEntity) { throw new ArgumentNullException(nameof(targetEntity)); } if (string.IsNullOrWhiteSpace(classificationType)) { throw new ArgumentNullException(nameof(classificationType)); } // Default the notification id if not are provided if (string.IsNullOrEmpty(notificationId)) { notificationId = Guid.NewGuid().ToString("N"); } ClassificationCompleteEventGridPayload ret = new ClassificationCompleteEventGridPayload() { DomainName = targetEntity.DomainName, EntityTypeName = targetEntity.EntityTypeName, InstanceKey = targetEntity.InstanceKey, NotificationId = notificationId, Commentary = commentary, ClassificationTypeName = classificationType, SequenceNumber = asOfSequenceNumber }; if (asOfDate.HasValue) { ret.AsOfDate = asOfDate; } if (null != response) { ret.Result = response.Result; ret.WasEverExcluded = response.WasEverExcluded; ret.WasEverIncluded = response.WasEverIncluded; } if (null != parameters) { // add them to the response ret.Parameters = parameters; } return(ret); }
public Task ProjectionCompleted(IEventStreamIdentity targetEntity, string projectionType, int asOfSequenceNumber, DateTime?asOfDate, object currentValue, string commentary = "") { // do nothing return(Task.CompletedTask); }
public TableClassificationSnapshotReader( IEventStreamIdentity identity, string classificationName, string connectionStringName = @"") : base(identity, classificationName, false, connectionStringName) { }
public static string MakeEventTypeName(IEventStreamIdentity targetEntity, string classificationType = "") { if (null == targetEntity) { return(EVENT_TYPE); } return($"{targetEntity.DomainName}.{targetEntity.EntityTypeName}.{classificationType }"); }
/// <summary> /// Make an event type name for the newly created entity notification message /// </summary> /// <param name="affectedEntity"> /// The newly created entity /// </param> public static string MakeEventTypeName(IEventStreamIdentity affectedEntity, string eventTypeName = "EventAppended") { if (null == affectedEntity) { return(EVENT_TYPE); } return($"{affectedEntity.DomainName}.{affectedEntity.EntityTypeName}.{eventTypeName}"); }
public static string MakeEventTypeName(IEventStreamIdentity targetEntity, string projectionType = "Anonymous Projection") { if (null == targetEntity) { return(EVENT_TYPE); } return($"{targetEntity.DomainName}.{targetEntity.EntityTypeName}.{projectionType}"); }
public TableEventStreamBase(IEventStreamIdentity identity, bool writeAccess = false, string connectionStringName = @"") { _domainName = identity.DomainName; _entityTypeName = identity.EntityTypeName; _instanceKey = identity.InstanceKey; // Set the connection string to use if (string.IsNullOrWhiteSpace(connectionStringName)) { connectionStringName = StorageConnectionStringSettingName; } // Create a connection to the cloud storage account to use ConfigurationBuilder builder = new ConfigurationBuilder(); builder.SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", true) .AddJsonFile("local.settings.json", true) .AddJsonFile("config.local.json", true) .AddJsonFile("config.json", true) .AddJsonFile("connectionstrings.json", true) .AddEnvironmentVariables(); IConfigurationRoot config = builder.Build(); if (null != config) { if (!string.IsNullOrWhiteSpace(connectionStringName)) { string connectionString = config.GetConnectionString(connectionStringName); if (string.IsNullOrWhiteSpace(connectionString)) { throw new NullReferenceException($"No connection string configured for {connectionStringName}"); } _storageAccount = CloudStorageAccount.Parse(connectionString); } } if (_storageAccount != null) { _cloudTableClient = _storageAccount.CreateCloudTableClient(); if (null != _cloudTableClient) { if (!Table.Exists(operationContext: GetDefaultOperationContext())) { Table.Create(); } } } }
public Task ClassificationCompleted(IEventStreamIdentity targetEntity, string classificationType, Dictionary <string, object> parameters, int asOfSequenceNumber, DateTime?asOfDate, ClassificationResponse response, string commentary = "") { // do nothing return(Task.CompletedTask); }
public string GetConnectionStringName(IEventStreamIdentity attribute) { CreateFronEnvironmentStringIfNotExists(attribute); if (AllSettings.ContainsKey(EventStreamSetting.MakeDomainQualifiedEntityName(attribute))) { return(AllSettings[EventStreamSetting.MakeDomainQualifiedEntityName(attribute)].ConnectionStringName); } else { return(ConnectionStringNameAttribute.DefaultConnectionStringName(attribute)); } }
/// <summary> /// Turn the identity of an event stream backed entity into the name of a /// queue down which the notifications about that entity should be posted /// </summary> /// <param name="targetEntity"> /// The entity for which a notification has occurred /// </param> /// <returns></returns> public static string MakeQueueName(IEventStreamIdentity targetEntity) { if (targetEntity != null) { string basename = BlobEventStreamBase.MakeValidStorageFolderName($"{targetEntity.DomainName}-{targetEntity.EntityTypeName}"); // Queues also cannot start with a number return(basename.TrimStart(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' })); } // The target that applies if the entity cannot be identified return($"unidentified-entities"); }
public EventStreamReadException(IEventStreamIdentity eventStreamIdentity, int sequenceNumber, string message = "", Exception innerException = null, string source = "") : base(eventStreamIdentity, sequenceNumber, message, innerException, source) { }
public string GetBackingImplementationType(IEventStreamIdentity attribute) { CreateFronEnvironmentStringIfNotExists(attribute); if (AllSettings.ContainsKey(EventStreamSetting.MakeDomainQualifiedEntityName(attribute))) { return(AllSettings[EventStreamSetting.MakeDomainQualifiedEntityName(attribute)].Storage.ToUpperInvariant()); } else { return(DefaultEventStreamSetting(EventStreamSetting.MakeDomainQualifiedEntityName(attribute)).Storage.ToUpperInvariant()); } }
/// <summary> /// Create an instance of the appropriate event stream writer to use for the given event stream /// </summary> /// <param name="attribute"> /// The attribute defining the Domain,Entity Type and Instance Key of the event stream /// </param> /// <remarks> /// This is to allow different event streams to be held in different backing technologies /// </remarks> public IEventStreamWriter CreateWriterForEventStream(IEventStreamIdentity attribute) { string connectionStringName = GetConnectionStringName(attribute); if (GetBackingImplementationType(attribute).Equals(EventStreamSetting.EVENTSTREAMIMPLEMENTATIOIN_TABLE, StringComparison.OrdinalIgnoreCase)) { return(new TableEventStreamWriter(attribute, connectionStringName: connectionStringName)); } // Default to an appendblob writer AppendBlob return(new BlobEventStreamWriter(attribute, connectionStringName: connectionStringName)); }
internal Notification(NotificationType notificationType, IEventStreamIdentity eventStreamInstance, string eventName = @"") { NotificationClassification = notificationType; if (null != eventStreamInstance) { DomainName = eventStreamInstance.DomainName; EntityTypeName = eventStreamInstance.EntityTypeName; InstanceKey = eventStreamInstance.InstanceKey; } EventName = eventName; }
/// <summary> /// Turn the properties passed in into a string to be sent via the queue /// </summary> /// <param name="targetEntity"> /// What the notification occured for /// </param> /// <param name="NotificationType"> /// The type of notification that occured /// </param> /// <param name="asOfSequenceNumber"> /// The sequence number of the event stream for which this notification occured /// </param> /// <param name="asOfDate"> /// The as-of date of the event in the event stream for which this notification occured /// </param> /// <returns> /// A notification message < 64kb long as pipe-separated values /// </returns> public static string MakeMessageString(IEventStreamIdentity targetEntity, string NotificationType, string NotificationClass, int asOfSequenceNumber, DateTime?asOfDate = null ) { if (asOfDate.HasValue) { return($"{NotificationType}|{NotificationClass}|{targetEntity.InstanceKey}|{asOfSequenceNumber}|{asOfDate}"); } return($"{NotificationType}|{NotificationClass}|{targetEntity.InstanceKey}|{asOfSequenceNumber}|null"); }
public TableClassificationSnapshotBase(IEventStreamIdentity identity, string classificationName, bool writeAccess = false, string connectionStringName = @"") { _domainName = identity.DomainName; _entityTypeName = identity.EntityTypeName; _instanceKey = identity.InstanceKey; _classificationName = classificationName; // Set the connection string to use if (string.IsNullOrWhiteSpace(connectionStringName)) { connectionStringName = StorageConnectionStringSettingName; } // Create a connection to the cloud storage account to use ConfigurationBuilder builder = new ConfigurationBuilder(); builder.SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", true) .AddJsonFile("local.settings.json", true) .AddJsonFile("config.local.json", true) .AddJsonFile("config.json", true) .AddJsonFile("connectionstrings.json", true) .AddEnvironmentVariables(); IConfigurationRoot config = builder.Build(); if (null != config) { if (!string.IsNullOrWhiteSpace(connectionStringName)) { _storageAccount = CloudStorageAccount.Parse(config.GetConnectionString(connectionStringName)); } } if (_storageAccount != null) { _cloudTableClient = _storageAccount.CreateCloudTableClient(); if (null != _cloudTableClient) { if (!Table.Exists()) { Table.Create(); } } } }
public TableEventStreamReader(IEventStreamIdentity identity, string connectionStringName = @"", IEventMaps eventMaps = null) : base(identity, false, connectionStringName) { // if event maps not passed in you have to create a default if (null == eventMaps) { _eventMaps = EventMaps.CreateDefaultEventMaps(); } else { _eventMaps = eventMaps; } }
public EventStreamExceptionBase(IEventStreamIdentity eventStreamIdentity, int sequenceNumber, string message = "", Exception innerException = null, string source = "") : base(message, innerException) { _sequenceNumber = sequenceNumber; if (null != eventStreamIdentity) { _domainName = eventStreamIdentity.DomainName; _entityTypeName = eventStreamIdentity.EntityTypeName; _instanceKey = eventStreamIdentity.InstanceKey; } }