private static ResourceFactory SelectResourceFactoryFor(Resource resource, IRow row)
        {
            WindowsAzureActiveDirectoryGroup group = resource as WindowsAzureActiveDirectoryGroup;

            if (group != null)
            {
                ResourceFactory result = new GroupFactory(row);
                return(result);
            }

            Core2EnterpriseUser user = resource as Core2EnterpriseUser;

            if (user != null)
            {
                ResourceFactory result = new UserFactory(row);
                return(result);
            }

            DynamicUser dynamicUser = resource as DynamicUser;

            if (dynamicUser != null)
            {
                ResourceFactory result = new DynamicUserFactory(row);
                return(result);
            }

            string unsupportedSchema =
                string.Join(
                    Environment.NewLine,
                    resource.Schemas);

            throw new NotSupportedException(unsupportedSchema);
        }
        private static ResourceFactory SelectResourceFactoryFor(string schemaIdentifier, IRow row)
        {
            if (string.IsNullOrWhiteSpace(schemaIdentifier))
            {
                throw new ArgumentNullException(nameof(schemaIdentifier));
            }

            ResourceFactory resourceFactory;

            switch (schemaIdentifier)
            {
            case SchemaIdentifiers.Core2EnterpriseUser:
                resourceFactory = new UserFactory(row);
                break;

            case SchemaIdentifiers.WindowsAzureActiveDirectoryGroup:
                resourceFactory = new GroupFactory(row);
                break;

            case DynamicConstants.SchemaIdentifierUser:
                resourceFactory = new DynamicUserFactory(row);
                break;

            default:
                throw new NotSupportedException(schemaIdentifier);
            }
            return(resourceFactory);
        }
        private static IReadOnlyDictionary <string, string> PatchDynamicUser(PatchRequest2 patch, IRow row)
        {
            DynamicUser dynamicUser            = new DynamicUserFactory(row).Create();
            Dictionary <string, string> result =
                new DynamicUserColumnsFactory(dynamicUser)
                .CreateColumns()
                .ToDictionary(
                    (KeyValuePair <string, string> item) =>
                    item.Key,
                    (KeyValuePair <string, string> item) =>
                    item.Value);

            if (null == patch.Operations || !patch.Operations.Any())
            {
                return(result);
            }

            foreach (PatchOperation operation in patch.Operations)
            {
                if (string.IsNullOrWhiteSpace(operation?.Path?.AttributePath))
                {
                    continue;
                }

                string updatedValue = operation.Value.First().Value;

                string originalValue;
                if (!result.TryGetValue(operation.Path.AttributePath, out originalValue))
                {
                    result.Add(operation.Path.AttributePath, updatedValue);
                }
                else
                {
                    result[operation.Path.AttributePath] = updatedValue;
                }
            }

            return(result);
        }