public override async Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier) { if (null == resourceIdentifier) { throw new ArgumentNullException(nameof(resourceIdentifier)); } if (string.IsNullOrWhiteSpace(correlationIdentifier)) { throw new ArgumentNullException(nameof(correlationIdentifier)); } if (string.IsNullOrWhiteSpace(resourceIdentifier.Identifier)) { throw new ArgumentException(FileProviderResources.ExceptionInvalidResource); } IInformationNotification notification = VerboseInformationNotificationFactory.Instance.FormatNotification( FileProviderResources.InformationDeleting, correlationIdentifier, FileProvider.NotificationIdentifierDeletionStarting, resourceIdentifier.SchemaIdentifier, resourceIdentifier.Identifier); this.Monitor.Inform(notification); await this.file.RemoveRow(resourceIdentifier.Identifier); }
public void Inform(IInformationNotification notification) { if (null == notification) { throw new ArgumentNullException(nameof(notification)); } string prefix = ConsoleMonitor.ComposePrefix <string>(notification); Console.WriteLine( SystemForCrossDomainIdentityManagementServiceResources.MonitorOutputInformationTemplate, prefix, notification.Message, notification.Verbose); }
public override async Task <Resource> CreateAsync(Resource resource, string correlationIdentifier) { if (null == resource) { throw new ArgumentNullException(nameof(resource)); } if (string.IsNullOrWhiteSpace(correlationIdentifier)) { throw new ArgumentNullException(nameof(correlationIdentifier)); } if (string.IsNullOrWhiteSpace(resource.ExternalIdentifier)) { throw new ArgumentException(FileProviderResources.ExceptionInvalidResource); } IInformationNotification notification = VerboseInformationNotificationFactory.Instance.FormatNotification( FileProviderResources.InformationCreating, correlationIdentifier, FileProvider.NotificationIdentifierCreationStarting, resource.ExternalIdentifier); this.Monitor.Inform(notification); ColumnsFactory columnsFactory = FileProvider.SelectColumnsFactoryFor(resource); IReadOnlyDictionary <string, string> columns = columnsFactory.CreateColumns(); IRow row = await this.file.InsertRow(columns); ResourceFactory resourceFactory = FileProvider.SelectResourceFactoryFor(resource, row); Resource result = resourceFactory.CreateResource(); await this.AddMembersOf(result); return(result); }
public override async Task UpdateAsync(IPatch patch, string correlationIdentifier) { if (null == patch) { throw new ArgumentNullException(nameof(patch)); } if (null == patch.ResourceIdentifier) { throw new ArgumentException(FileProviderResources.ExceptionInvalidPatch); } if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier)) { throw new ArgumentException(FileProviderResources.ExceptionInvalidPatch); } if (null == patch.PatchRequest) { throw new ArgumentException(FileProviderResources.ExceptionInvalidPatch); } IInformationNotification notification = VerboseInformationNotificationFactory.Instance.FormatNotification( FileProviderResources.InformationPatching, correlationIdentifier, FileProvider.NotificationIdentifierUpdateStarting, patch.ResourceIdentifier.SchemaIdentifier, patch.ResourceIdentifier.Identifier); this.Monitor.Inform(notification); PatchRequest2 patchRequest = patch.PatchRequest as PatchRequest2; if (null == patchRequest) { string unsupportedPatchTypeName = patch.GetType().FullName; throw new NotSupportedException(unsupportedPatchTypeName); } IRow row = await this.file.ReadRow(patch.ResourceIdentifier.Identifier); string rowSchema = null; if ( !row.Columns.TryGetValue(AttributeNames.Schemas, out rowSchema) || !string.Equals(rowSchema, patch.ResourceIdentifier.SchemaIdentifier, StringComparison.Ordinal) ) { return; } IReadOnlyDictionary <string, string> columns = FileProvider.Apply(patchRequest, rowSchema, row); IRow rowReplacement = new Row(row.Key, columns); await this.file.ReplaceRow(rowReplacement); if (string.Equals(SchemaIdentifiers.WindowsAzureActiveDirectoryGroup, rowSchema, StringComparison.OrdinalIgnoreCase)) { WindowsAzureActiveDirectoryGroup group = new GroupFactory(row).Create(); await this.UpdateMembersAsync(group, patch); } }
public override async Task <Resource> RetrieveAsync( IResourceRetrievalParameters parameters, string correlationIdentifier) { if (null == parameters) { throw new ArgumentNullException(nameof(parameters)); } if (string.IsNullOrWhiteSpace(correlationIdentifier)) { throw new ArgumentNullException(nameof(correlationIdentifier)); } if (null == parameters.ResourceIdentifier) { throw new ArgumentException(FileProviderResources.ExceptionInvalidParameters); } if (string.IsNullOrWhiteSpace(parameters.ResourceIdentifier.Identifier)) { throw new ArgumentException(FileProviderResources.ExceptionInvalidResourceIdentifier); } if (string.IsNullOrWhiteSpace(parameters.SchemaIdentifier)) { throw new ArgumentException(FileProviderResources.ExceptionInvalidParameters); } IInformationNotification notification = VerboseInformationNotificationFactory.Instance.FormatNotification( FileProviderResources.InformationRetrieving, correlationIdentifier, FileProvider.NotificationIdentifierRetrievalStarting, parameters.SchemaIdentifier, parameters.ResourceIdentifier.Identifier); this.Monitor.Inform(notification); IReadOnlyCollection <string> columnNames = this.IdentifyRequestedColumns(parameters); IRow row = await this.file.ReadRow(parameters.ResourceIdentifier.Identifier); if (null == row || null == row.Columns) { return(null); } string rowSchema = null; if ( !row.Columns.TryGetValue(AttributeNames.Schemas, out rowSchema) || !string.Equals(rowSchema, parameters.SchemaIdentifier, StringComparison.Ordinal) ) { return(null); } IRow reducedRow = FileProvider.FilterColumns(row, columnNames); ResourceFactory resourceFactory = FileProvider.SelectResourceFactoryFor(rowSchema, reducedRow); Resource result = resourceFactory.CreateResource(); return(result); }
private async Task <Resource[]> QueryReferenceAsync(IQueryParameters parameters, string correlationIdentifier) { if (null == parameters) { throw new ArgumentNullException(nameof(parameters)); } if (string.IsNullOrWhiteSpace(correlationIdentifier)) { throw new ArgumentNullException(nameof(correlationIdentifier)); } if (null == parameters.RequestedAttributePaths || !parameters.RequestedAttributePaths.Any()) { throw new NotSupportedException(FileProviderResources.ExceptionUnsupportedQuery); } string selectedAttribute = parameters.RequestedAttributePaths.SingleOrDefault(); if (string.IsNullOrWhiteSpace(selectedAttribute)) { throw new NotSupportedException(FileProviderResources.ExceptionUnsupportedQuery); } IInformationNotification notificationReferenceQueryAttribute = VerboseInformationNotificationFactory.Instance.CreateNotification( selectedAttribute, correlationIdentifier, FileProvider.NotificationIdentifierReferenceQueryAttribute); this.Monitor.Inform(notificationReferenceQueryAttribute); if ( !string.Equals( selectedAttribute, AttributeNames.Identifier, StringComparison.OrdinalIgnoreCase) ) { throw new NotSupportedException(FileProviderResources.ExceptionUnsupportedQuery); } if (null == parameters.AlternateFilters) { throw new ArgumentException(FileProviderResources.ExceptionInvalidParameters); } if (string.IsNullOrWhiteSpace(parameters.SchemaIdentifier)) { throw new ArgumentException(FileProviderResources.ExceptionInvalidParameters); } string informationAlternateFilterCount = parameters.AlternateFilters.Count.ToString(CultureInfo.InvariantCulture); IInformationNotification notificationReferenceQueryFilterCount = VerboseInformationNotificationFactory.Instance.CreateNotification( informationAlternateFilterCount, correlationIdentifier, FileProvider.NotificationIdentifierReferenceQueryFilterCount); this.Monitor.Inform(notificationReferenceQueryFilterCount); if (parameters.AlternateFilters.Count != 1) { string exceptionMessage = string.Format( CultureInfo.InvariantCulture, FileProviderResources.ExceptionFilterCountTemplate, 1, parameters.AlternateFilters.Count); throw new NotSupportedException(exceptionMessage); } IReadOnlyCollection <string> requestedColumns = this.IdentifyRequestedColumns(parameters); IFilter filterPrimary = parameters.AlternateFilters.Single(); if (null == filterPrimary.AdditionalFilter) { throw new ArgumentException(FileProviderResources.ExceptionInvalidParameters); } IFilter filterAdditional = filterPrimary.AdditionalFilter; if (filterAdditional.AdditionalFilter != null) { throw new NotSupportedException(FileProviderResources.ExceptionUnsupportedQuery); } IReadOnlyCollection <IFilter> filters = new IFilter[] { filterPrimary, filterAdditional }; IFilter filterIdentifier = filters .SingleOrDefault( (IFilter item) => string.Equals( AttributeNames.Identifier, item.AttributePath, StringComparison.OrdinalIgnoreCase)); if (null == filterIdentifier) { throw new NotSupportedException(FileProviderResources.ExceptionUnsupportedQuery); } IRow row; IFilter filterReference = filters .SingleOrDefault( (IFilter item) => string.Equals( AttributeNames.Members, item.AttributePath, StringComparison.OrdinalIgnoreCase)); if (filterReference != null) { Dictionary <string, string> columns = new Dictionary <string, string>() { { AttributeNames.Schemas, parameters.SchemaIdentifier }, { AttributeNames.Identifier, filterIdentifier.ComparisonValue }, { filterReference.AttributePath, filterReference.ComparisonValue } }; IReadOnlyCollection <IRow> rows = await this.file.Query(columns); if (null == rows || !rows.Any()) { return(new Resource[0]); } row = await this.file.ReadRow(filterIdentifier.ComparisonValue); } else { filterReference = filters .SingleOrDefault( (IFilter item) => string.Equals( AttributeNames.Manager, item.AttributePath, StringComparison.OrdinalIgnoreCase)); if (null == filterReference) { throw new NotSupportedException(FileProviderResources.ExceptionUnsupportedQuery); } row = await this.file.ReadRow(filterIdentifier.ComparisonValue); if ( null == row.Columns || !row .Columns .Any( (KeyValuePair <string, string> columnItem) => string.Equals(columnItem.Key, filterReference.AttributePath, StringComparison.Ordinal) && string.Equals(columnItem.Value, filterReference.ComparisonValue, StringComparison.Ordinal)) ) { return(new Resource[0]); } } string rowSchema = null; if ( !row.Columns.TryGetValue(AttributeNames.Schemas, out rowSchema) || !string.Equals(rowSchema, parameters.SchemaIdentifier, StringComparison.Ordinal) ) { return(new Resource[0]); } IRow reducedRow = FileProvider.FilterColumns(row, requestedColumns); ResourceFactory resourceFactory = FileProvider.SelectResourceFactoryFor(rowSchema, reducedRow); Resource resource = resourceFactory.CreateResource(); Resource[] results = new Resource[] { resource }; return(results); }
public override async Task <Resource[]> QueryAsync(IQueryParameters parameters, string correlationIdentifier) { if (null == parameters) { throw new ArgumentNullException(nameof(parameters)); } if (string.IsNullOrWhiteSpace(correlationIdentifier)) { throw new ArgumentNullException(nameof(correlationIdentifier)); } if (null == parameters.AlternateFilters) { throw new ArgumentException(FileProviderResources.ExceptionInvalidParameters); } if (string.IsNullOrWhiteSpace(parameters.SchemaIdentifier)) { throw new ArgumentException(FileProviderResources.ExceptionInvalidParameters); } string informationAlternateFilterCount = parameters.AlternateFilters.Count.ToString(CultureInfo.InvariantCulture); IInformationNotification notification = VerboseInformationNotificationFactory.Instance.CreateNotification( informationAlternateFilterCount, correlationIdentifier, FileProvider.NotificationIdentifierQueryFilterCount); this.Monitor.Inform(notification); if (parameters.AlternateFilters.Count != 1) { string exceptionMessage = string.Format( CultureInfo.InvariantCulture, FileProviderResources.ExceptionFilterCountTemplate, 1, parameters.AlternateFilters.Count); throw new NotSupportedException(exceptionMessage); } Resource[] results; IFilter queryFilter = parameters.AlternateFilters.Single(); if (queryFilter.AdditionalFilter != null) { results = await this.QueryReferenceAsync(parameters, correlationIdentifier); return(results); } IReadOnlyCollection <string> requestedColumns = this.IdentifyRequestedColumns(parameters); if (string.IsNullOrWhiteSpace(queryFilter.AttributePath)) { throw new ArgumentException(FileProviderResources.ExceptionInvalidParameters); } if (string.IsNullOrWhiteSpace(queryFilter.ComparisonValue)) { throw new ArgumentException(FileProviderResources.ExceptionInvalidParameters); } Dictionary <string, string> columns = new Dictionary <string, string>() { { AttributeNames.Schemas, parameters.SchemaIdentifier }, { queryFilter.AttributePath, queryFilter.ComparisonValue } }; IReadOnlyCollection <IRow> rows = await this.file.Query(columns); if (null == rows) { return(new Resource[0]); } IList <Resource> resources = new List <Resource>(rows.Count); foreach (IRow row in rows) { string rowSchema = null; if ( !row.Columns.TryGetValue(AttributeNames.Schemas, out rowSchema) || !string.Equals(rowSchema, parameters.SchemaIdentifier, StringComparison.Ordinal) ) { continue; } IRow reducedRow = FileProvider.FilterColumns(row, requestedColumns); ResourceFactory resourceFactory = FileProvider.SelectResourceFactoryFor(rowSchema, reducedRow); Resource resource = resourceFactory.CreateResource(); resources.Add(resource); } results = resources.ToArray(); return(results); }
private async Task WriteToStream( Type type, object value, Stream writeStream, Func <byte[], Task> writeFunction) { if (null == type) { throw new ArgumentNullException(nameof(type)); } if (null == value) { throw new ArgumentNullException(nameof(value)); } if (null == writeStream) { throw new ArgumentNullException(nameof(writeStream)); } string characters; if (typeof(string) == type) { characters = (string)value; } else { IDictionary <string, object> json; if (typeof(IDictionary <string, object>).IsAssignableFrom(type)) { json = (IDictionary <string, object>)value; characters = JsonFactory.Instance.Create(json, this.DeserializingFactory.AcceptLargeObjects); } else if (typeof(Schematized).IsAssignableFrom(type)) { Schematized schematized = (Schematized)value; json = schematized.ToJson(); characters = JsonFactory.Instance.Create(json, this.DeserializingFactory.AcceptLargeObjects); } else { throw new NotSupportedException(type.FullName); } } string information = string.Concat( SystemForCrossDomainIdentityManagementServiceResources.InformationWrote, characters); IInformationNotification notification = InformationNotificationFactory.Instance.CreateNotification( information, null, ServiceNotificationIdentifiers.SchematizedMediaTypeFormatterWroteToStream); this.Monitor.Inform(notification); byte[] bytes = SchematizedMediaTypeFormatter.Encoding.GetBytes(characters); await writeFunction(bytes).ConfigureAwait(false); writeStream.Flush(); }
private async Task <object> ReadFromStream(Type type, Stream readStream, HttpContent content) { if (null == type) { throw new ArgumentNullException(nameof(type)); } if (null == readStream) { throw new ArgumentNullException(nameof(readStream)); } if ( !typeof(IDictionary <string, object>).IsAssignableFrom(type) && !typeof(Schematized).IsAssignableFrom(type) && typeof(string) != type ) { throw new NotSupportedException(type.FullName); } string characters = await SchematizedMediaTypeFormatter.ReadFromStream(readStream).ConfigureAwait(false); string information = string.Concat(SystemForCrossDomainIdentityManagementServiceResources.InformationRead, characters); IInformationNotification notification = InformationNotificationFactory.Instance.CreateNotification( information, null, ServiceNotificationIdentifiers.SchematizedMediaTypeFormatterReadFromStream); this.Monitor.Inform(notification); if ( string.Equals( content?.Headers?.ContentType?.MediaType, MediaTypes.JavaWebToken, StringComparison.Ordinal) ) { return(characters); } Dictionary <string, object> json = JsonFactory.Instance.Create( characters, this.DeserializingFactory.AcceptLargeObjects); if (typeof(IDictionary <string, object>).IsAssignableFrom(type)) { return(json); } try { Schematized result = this.DeserializingFactory.Create(json); return(result); } catch (ArgumentException) { return(new HttpResponseException(HttpStatusCode.BadRequest)); } catch (NotSupportedException) { return(new HttpResponseException(HttpStatusCode.BadRequest)); } #pragma warning disable CA1031 // Do not catch general exception types catch { return(new HttpResponseException(HttpStatusCode.BadRequest)); } #pragma warning restore CA1031 // Do not catch general exception types }
public void Inform(IInformationNotification notification) { }
public void Inform(IInformationNotification notification) { this.consoleMonitor.Inform(notification); this.Prompt(); }
public void Inform(IInformationNotification notification) { _logger.LogInformation(notification.Message); }