private static IReadOnlyDictionary <string, string> Apply(
            PatchRequest2Base <PatchOperation2> patch,
            string schemaIdentifier, IRow row)
        {
            if (null == patch)
            {
                throw new ArgumentNullException(nameof(patch));
            }

            if (string.IsNullOrWhiteSpace(schemaIdentifier))
            {
                throw new ArgumentNullException(nameof(schemaIdentifier));
            }

            IReadOnlyDictionary <string, string> result;

            switch (schemaIdentifier)
            {
            case SchemaIdentifiers.Core2EnterpriseUser:
                result = FileProvider.PatchUser(patch, row);
                return(result);

            case SchemaIdentifiers.WindowsAzureActiveDirectoryGroup:
                result = FileProvider.PatchGroup(patch, row);
                return(result);

            default:
                throw new NotSupportedException(schemaIdentifier);
            }
        }
        private static IReadOnlyDictionary <string, string> PatchUser(PatchRequest2Base <PatchOperation2> patch, IRow row)
        {
            ResourceFactory <Core2EnterpriseUser> userFactory = new UserFactory(row);
            Core2EnterpriseUser user = userFactory.Create();

            user.Apply(patch);
            ColumnsFactory <Core2EnterpriseUser> userColumnsFactory = new UserColumnsFactory(user);
            IReadOnlyDictionary <string, string> result             = userColumnsFactory.CreateColumns();

            return(result);
        }
        private static IReadOnlyDictionary <string, string> PatchGroup(PatchRequest2Base <PatchOperation2> patch, IRow row)
        {
            ResourceFactory <WindowsAzureActiveDirectoryGroup> groupFactory = new GroupFactory(row);
            WindowsAzureActiveDirectoryGroup group = groupFactory.Create();

            group.Apply(patch);
            ColumnsFactory <WindowsAzureActiveDirectoryGroup> groupColumnsFactory = new GroupColumnsFactory(group);
            IReadOnlyDictionary <string, string> result = groupColumnsFactory.CreateColumns();

            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);

            PatchRequest2Base <PatchOperation2> patchRequest =
                patch.PatchRequest as PatchRequest2Base <PatchOperation2>;

            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);
            }
        }