public Group CreateGroup(Type[] types)
        {
            var group = GroupFactory.Create(types);

            groups.Add(group);
            return(group);
        }
Exemple #2
0
        public IObservableGroup GetObservableGroup(IGroup group, string collectionName = null)
        {
            var requiredComponents   = ComponentTypeLookup.GetComponentTypes(group.RequiredComponents);
            var excludedComponents   = ComponentTypeLookup.GetComponentTypes(group.ExcludedComponents);
            var lookupGroup          = new LookupGroup(requiredComponents, excludedComponents);
            var observableGroupToken = new ObservableGroupToken(lookupGroup, collectionName);

            if (observableGroups.ContainsKey(observableGroupToken))
            {
                return(observableGroups[observableGroupToken]);
            }

            var entityMatches = GetEntitiesFor(lookupGroup, collectionName);
            var configuration = new ObservableGroupConfiguration
            {
                ObservableGroupToken = observableGroupToken,
                InitialEntities      = entityMatches
            };

            if (collectionName != null)
            {
                configuration.NotifyingCollection = collections[collectionName];
            }
            else
            {
                configuration.NotifyingCollection = this;
            }

            var observableGroup = GroupFactory.Create(configuration);

            observableGroups.Add(observableGroupToken, observableGroup);

            return(observableGroups[observableGroupToken]);
        }
Exemple #3
0
        public void GetGroupArticles_RealFiles_NotEmpty()
        {
            List <Group> groups = GroupFactory.GetGroupArticles(_data50Csv, _labelCsv, _groupsCsv);

            Assert.AreEqual(20, groups.Count);
            Assert.IsTrue(groups.All(g => g.Articles.Count == 50));
        }
Exemple #4
0
        public static void Main()
        {
            IInputReader consoleReader = new ConsoleReader();
            var          consoleWriter = new ConsoleWriter
            {
                AutoFlush = true
            };

            ICommandDispatcher commandDispatcher = new CommandDispatcher();
            IGroupFactory      groupFactory      = new GroupFactory();
            IWarEffectFactory  warEffectFactory  = new WarEffectFactory();
            IAttackFactory     attackFactory     = new AttackFactory();
            IDatabase          db = new EngineDb();

            var engine = new Engine(
                consoleReader,
                consoleWriter,
                commandDispatcher,
                groupFactory,
                warEffectFactory,
                attackFactory,
                db);

            engine.Start();
        }
Exemple #5
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (grvGroup.SelectedRows.Count > 0)
         {
             var dr = MessageBox.Show("Bạn có chắc là muốn xóa?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (dr == DialogResult.Yes)
             {
                 for (int i = 0; i < grvGroup.SelectedRows.Count; i++)
                 {
                     var groupID = Int32.Parse(grvGroup.SelectedRows[i].Cells["GroupID"].Value.ToString());
                     GroupFactory.DeleteGroupByGroupID(groupID);
                 }
                 MessageBox.Show("Xóa xong");
                 InitData();
             }
         }
         else
         {
             MessageBox.Show("Bạn cần chọn tờ khai.");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Xóa bị lỗi");
         logger.Error(ex.ToString());
         if (GlobalInfo.IsDebug)
         {
             MessageBox.Show(ex.ToString());
         }
     }
 }
Exemple #6
0
        public void InitData()
        {
            grvGroup.AutoGenerateColumns = false;
            var groups = GroupFactory.SelectAll();

            grvGroup.DataSource = groups;
        }
        //public Group CreateGroup(HashSet<Type> types)
        //{
        //	var group = GroupFactory.Create (types);
        //	groups.Add (group);
        //	return group;
        //}

        public Group CreateGroup(HashSet <Type> types, params Func <IEntity, IReadOnlyReactiveProperty <bool> >[] predicates)
        {
            var group = GroupFactory
                        .WithPredicates(predicates)
                        .Create(types);

            groups.Add(group);
            return(group);
        }
Exemple #8
0
        public static void Main()
        {
            var writer  = new ConsoleWriter();
            var reader  = new ConsoleReader();
            var factory = new GroupFactory();

            IRunnable engine = new Engine(reader, writer, factory);

            engine.Run();
        }
Exemple #9
0
    public void InitializeGrid()
    {
        groupPattern = Substitute.For <IGroupPattern>();
        rotationMock = new List <Coord[]>()
        {
            new Coord[] {
                new Coord(0, 0),
                new Coord(0, -1),
                new Coord(1, 0),
                new Coord(-1, 0),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(-1, 0),
                new Coord(0, -1),
                new Coord(0, 1),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(0, 1),
                new Coord(-1, 0),
                new Coord(1, 0),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(1, 0),
                new Coord(0, 1),
                new Coord(0, -1),
            },
        };
        groupPattern.Patterns.Returns(rotationMock);

        groupPatternList = new List <IGroupPattern>();
        groupPatternList.Add(groupPattern);

        groupFactory = new GroupFactory(blockFactory, groupPatternList);

        gridFactory = new GridFactory(setting, groupFactory);

        // create grid
        grid = gridFactory.Create();
        grid.NewGame();

        blockPattern  = Substitute.For <IBlockPattern>();
        blockTypeMock = new BlockType[]
        {
            BlockType.One,
            BlockType.Six,
            BlockType.Three,
            BlockType.Five,
        };
        blockPattern.Types.Returns(blockTypeMock);

        group = groupFactory.Create(setting, blockPattern, groupPattern);
    }
Exemple #10
0
    public void InitializeGrid()
    {
        groupPattern = Substitute.For<IGroupPattern>();
        rotationMock = new List<Coord[]>() {
            new Coord[] {
                new Coord(0, 0),
                new Coord(0, -1),
                new Coord(1, 0),
                new Coord(-1, 0),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(-1, 0),
                new Coord(0, -1),
                new Coord(0, 1),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(0, 1),
                new Coord(-1, 0),
                new Coord(1, 0),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(1, 0),
                new Coord(0, 1),
                new Coord(0, -1),
            },
        };
        groupPattern.Patterns.Returns(rotationMock);

        groupPatternList = new List<IGroupPattern>();
        groupPatternList.Add(groupPattern);

        groupFactory = new GroupFactory(blockFactory, groupPatternList);

        gridFactory = new GridFactory(setting, groupFactory);

        // create grid
        grid = gridFactory.Create();
        grid.NewGame();

        blockPattern = Substitute.For<IBlockPattern>();
        blockTypeMock = new BlockType[]
        {
            BlockType.One,
            BlockType.Six,
            BlockType.Three,
            BlockType.Five,
        };
        blockPattern.Types.Returns(blockTypeMock);

        group = groupFactory.Create(setting, blockPattern, groupPattern);
    }
        public static void Main()
        {
            var reader = new ConsoleReader();
            var writer = new ConsoleWriter();
            var data = new ISISData();
            var warFactory = new WarEffectFactory();
            var attackFactory = new AttackTypeFactory();
            var groupFactory = new GroupFactory();

            var engine = new Engine(data, reader, writer, warFactory, attackFactory, groupFactory);
            engine.Run();
        }
Exemple #12
0
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            var group = GroupFactory.Create(new Type[] { typeof(ViewComponent), typeof(HealthComponent), typeof(InputComponent), typeof(Animator) });

            group.OnAdd().Subscribe(entity =>
            {
                var viewComponent   = entity.GetComponent <ViewComponent>();
                var targetTransform = viewComponent.Transforms[0];
                var health          = entity.GetComponent <HealthComponent> ();
                var previousValue   = health.CurrentHealth.Value;

                var audioSources = targetTransform.GetComponentsInChildren <AudioSource>();
                var hurtSound    = audioSources.Where(audioSource => audioSource.clip.name.Contains("Hurt")).FirstOrDefault();

                health.CurrentHealth.DistinctUntilChanged().Subscribe(value =>
                {
                    // if you got hurt and are still alive...
                    if (value < previousValue && value >= 0)
                    {
                        if (DamageImage != null)
                        {
                            DamageImage.color = FlashColor;
                            DOTween.To(() => DamageImage.color, x => DamageImage.color = x, Color.clear, FlashSpeed);
                        }

                        hurtSound.Play();
                    }

                    HealthSlider.value = value;
                    previousValue      = value;
                }).AddTo(this.Disposer).AddTo(health.Disposer);
            }).AddTo(this.Disposer);

            DeadEntities.OnAdd().Subscribe(entity =>
            {
                if (entity.HasComponent <InputComponent>() == false)
                {
                    return;
                }

                var viewComponent = entity.GetComponent <ViewComponent>();
                var animator      = entity.GetComponent <Animator>();

                var audioSources = viewComponent.Transforms[0].GetComponentsInChildren <AudioSource>();
                var deathSound   = audioSources.Where(audioSource => audioSource.clip.name.Contains("Death")).FirstOrDefault();
                animator.SetTrigger("Die");
                deathSound.Play();
            }).AddTo(this.Disposer);
        }
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            var group = GroupFactory.Create(new Type[] { typeof(HealthComponent), typeof(ViewComponent), typeof(UnityEngine.AI.NavMeshAgent) });

            group.OnAdd().Subscribe(entity =>
            {
                var viewComponent = entity.GetComponent <ViewComponent>();
                var navMeshAgent  = entity.GetComponent <NavMeshAgent> ();
                var health        = entity.GetComponent <HealthComponent> ();

                Observable.EveryUpdate().Subscribe(_ =>
                {
                    if (Target == null)
                    {
                        var go = GameObject.FindGameObjectWithTag("Player");
                        if (go == null)
                        {
                            return;
                        }

                        Target = go.transform;
                        if (Target == null)
                        {
                            return;
                        }

                        TargetHealth = Target.GetComponent <EntityBehaviour> ().Entity.GetComponent <HealthComponent> ();
                        if (TargetHealth == null)
                        {
                            return;
                        }
                    }

                    if (health.CurrentHealth.Value > 0 && TargetHealth.CurrentHealth.Value > 0)
                    {
                        navMeshAgent.SetDestination(Target.position);
                    }
                    else
                    {
                        navMeshAgent.enabled = false;
                    }
                }).AddTo(navMeshAgent).AddTo(health);
            }).AddTo(this);
        }
        private void SaveMedicineIfNew()
        {
            PharmacyDbContext db       = new PharmacyDbContext();
            Medicine          medicine = new Medicine();

            medicine = db.Medicine.FirstOrDefault(a => a.Name == txtMedicine.Text);
            if (medicine != null)
            {
                medicine.Name        = txtMedicine.Text;
                medicine.Id          = UniqueNumber.GenerateUniqueNumber();
                medicine.CreatedBy   = currentUser;
                medicine.CreatedDate = DateTime.Now;
                medicine.GroupId     = GroupFactory.GetGroupId(txtGroup.Text, currentUser);
                medicine.CompanyId   = CompanyFactory.GetCompanyId(txtCompany.Text, currentUser);
                db.Medicine.Add(medicine);
            }
        }
Exemple #15
0
    void SetFactories(Game game)
    {
        game.CameraManager     = _cameraManager;
        game.BackgroundFactory = _backgroundFactory;

        IBlockFactory blockFactory = new BlockFactory(_blockViewSpawner);

        IGroupFactory groupFactory = new GroupFactory(blockFactory, _groupPatterns);
        IGroupStock   groupStock   = new GroupStock(groupFactory);

        groupStock.StockDisplayConfig = _setting.StockPositions;
        groupStock.Prepare(_setting);
        game.GroupFactory = groupStock;

        var gridFactory = new GridFactory(_setting, groupStock);

        game.GridFactory = gridFactory;
    }
Exemple #16
0
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            var group = GroupFactory.Create(new Type[] { typeof(InputComponent), typeof(ViewComponent), typeof(Animator) });

            group.OnAdd().Subscribe(entity =>
            {
                var input      = entity.GetComponent <InputComponent> ();
                var horizontal = input.Horizontal.DistinctUntilChanged();
                var vertical   = input.Vertical.DistinctUntilChanged();
                var animator   = entity.GetComponent <Animator>();

                Observable.CombineLatest(horizontal, vertical, (h, v) =>
                {
                    return(h != 0f || v != 0f);
                }).ToReadOnlyReactiveProperty().DistinctUntilChanged().Subscribe(value =>
                {
                    animator.SetBool("IsWalking", value);
                }).AddTo(input.Disposer);
            }).AddTo(Disposer);
        }
Exemple #17
0
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            FloorMask = LayerMask.GetMask("Floor");

            var group = GroupFactory.Create(new Type[] { typeof(ViewComponent), typeof(InputComponent), typeof(Rigidbody) });

            Observable.EveryFixedUpdate().Subscribe(_ =>
            {
                foreach (var entity in group.Entities)
                {
                    var input = entity.GetComponent <InputComponent> ();
                    input.Horizontal.Value = Input.GetAxisRaw("Horizontal");
                    input.Vertical.Value   = Input.GetAxisRaw("Vertical");

                    var movement = Vector3.zero;
                    movement.Set(input.Horizontal.Value, 0f, input.Vertical.Value);
                    var speed = 6f;
                    movement  = movement.normalized * speed * Time.deltaTime;
                    var rb    = entity.GetComponent <Rigidbody>();
                    rb.MovePosition(rb.transform.position + movement);

                    // execute turning
                    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;

                    if (Physics.Raycast(ray, out hit, 1000f, FloorMask))
                    {
                        Vector3 playerToMouse = hit.point - rb.transform.position;
                        playerToMouse.y       = 0f;

                        Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
                        rb.MoveRotation(newRotation);
                    }
                }
            }).AddTo(this);
        }
        private async Task<Resource[]> QueryReference(IQueryParameters parameters, string correlationIdentifier)
        {
            if (null == parameters)
            {
                throw new ArgumentNullException(FileProvider.ArgumentNameParameters);
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(FileProvider.ArgumentNameCorrelationIdentifier);
            }

            if (null == parameters.RequestedAttributePaths || !parameters.RequestedAttributePaths.Any())
            {
                throw new NotSupportedException(ProvisioningAgentResources.ExceptionUnsupportedQuery);
            }

            string selectedAttribute = parameters.RequestedAttributePaths.SingleOrDefault();
            if (string.IsNullOrWhiteSpace(selectedAttribute))
            {
                throw new NotSupportedException(ProvisioningAgentResources.ExceptionUnsupportedQuery);
            }
            ProvisioningAgentMonitor.Instance.Inform(selectedAttribute, true, correlationIdentifier);

            if
            (
                !string.Equals(
                    selectedAttribute,
                    Microsoft.SystemForCrossDomainIdentityManagement.AttributeNames.Identifier,
                    StringComparison.OrdinalIgnoreCase)
            )
            {
                throw new NotSupportedException(ProvisioningAgentResources.ExceptionUnsupportedQuery);
            }

            if (null == parameters.AlternateFilters)
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidParameters);
            }

            if (string.IsNullOrWhiteSpace(parameters.SchemaIdentifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidParameters);
            }

            string informationAlternateFilterCount = parameters.AlternateFilters.Count.ToString(CultureInfo.InvariantCulture);
            ProvisioningAgentMonitor.Instance.Inform(informationAlternateFilterCount, true, correlationIdentifier);
            if (parameters.AlternateFilters.Count != 1)
            {
                string exceptionMessage =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        ProvisioningAgentResources.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(ProvisioningAgentResources.ExceptionInvalidParameters);
            }

            IFilter filterAdditional = filterPrimary.AdditionalFilter;

            if (filterAdditional.AdditionalFilter != null)
            {
                throw new NotSupportedException(ProvisioningAgentResources.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(ProvisioningAgentResources.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(ProvisioningAgentResources.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;
            switch (rowSchema)
            {
                case SchemaIdentifiers.Core2EnterpriseUser:
                    resourceFactory = new UserFactory(reducedRow);
                    break;
                case SchemaIdentifiers.WindowsAzureActiveDirectoryGroup:
                    resourceFactory = new GroupFactory(reducedRow);
                    break;
                default:
                    throw new NotSupportedException(parameters.SchemaIdentifier);
            }

            Resource resource = resourceFactory.CreateResource();
            Resource[] results =
                new Resource[]
                {
                    resource
                };
            return results;
        }
        public override async Task<Resource> Retrieve(IResourceRetrievalParameters parameters, string correlationIdentifier)
        {
            if (null == parameters)
            {
                throw new ArgumentNullException(FileProvider.ArgumentNameParameters);
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(FileProvider.ArgumentNameCorrelationIdentifier);
            }

            if (null == parameters.ResourceIdentifier)
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidParameters);
            }

            if (string.IsNullOrWhiteSpace(parameters.ResourceIdentifier.Identifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidResourceIdentifier);
            }

            if (string.IsNullOrWhiteSpace(parameters.SchemaIdentifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidParameters);
            }

            string informationStarting =
                string.Format(
                    CultureInfo.InvariantCulture,
                    AzureTestProvisioningResources.InformationRetrieving,
                    parameters.SchemaIdentifier,
                    parameters.ResourceIdentifier.Identifier);
            ProvisioningAgentMonitor.Instance.Inform(informationStarting, true, correlationIdentifier);

            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;
            switch (rowSchema)
            {
                case SchemaIdentifiers.Core2EnterpriseUser:
                    resourceFactory = new UserFactory(reducedRow);
                    break;
                case SchemaIdentifiers.WindowsAzureActiveDirectoryGroup:
                    resourceFactory = new GroupFactory(reducedRow);
                    break;
                default:
                    throw new NotSupportedException(parameters.SchemaIdentifier);
            }

            Resource result = resourceFactory.CreateResource();
            return result;
        }
        public override async Task Update(IPatch patch, string correlationIdentifier)
        {
            if (null == patch)
            {
                throw new ArgumentNullException(FileProvider.ArgumentNamePatch);
            }

            if (null == patch.ResourceIdentifier)
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidPatch);
            }

            if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidPatch);
            }

            if (null == patch.PatchRequest)
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidPatch);
            }

            string informationStarting =
                string.Format(
                    CultureInfo.InvariantCulture,
                    AzureTestProvisioningResources.InformationPatching,
                    patch.ResourceIdentifier.SchemaIdentifier,
                    patch.ResourceIdentifier.Identifier);
            ProvisioningAgentMonitor.Instance.Inform(informationStarting, true, correlationIdentifier);

            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;
            WindowsAzureActiveDirectoryGroup group = null;
            switch (rowSchema)
            {
                case SchemaIdentifiers.Core2EnterpriseUser:
                    ResourceFactory<Core2EnterpriseUser> userFactory = new UserFactory(row);
                    Core2EnterpriseUser user = userFactory.Create();
                    user.Apply(patchRequest);
                    ColumnsFactory<Core2EnterpriseUser> userColumnsFactory = new UserColumnsFactory(user);
                    columns = userColumnsFactory.CreateColumns();
                    break;

                case SchemaIdentifiers.WindowsAzureActiveDirectoryGroup:
                    ResourceFactory<WindowsAzureActiveDirectoryGroup> groupFactory = new GroupFactory(row);
                    group = groupFactory.Create();
                    group.Apply(patchRequest);
                    ColumnsFactory<WindowsAzureActiveDirectoryGroup> groupColumnsFactory = new GroupColumnsFactory(group);
                    columns = groupColumnsFactory.CreateColumns();
                    break;
                default:
                    throw new NotSupportedException(patch.ResourceIdentifier.SchemaIdentifier);
            }

            IRow rowReplacement = new Row(row.Key, columns);
            await this.file.ReplaceRow(rowReplacement);

            if (group != null)
            {
                await this.UpdateMembers(group, patch);
            }
        }
        public override async Task<Resource> Create(Resource resource, string correlationIdentifier)
        {
            logger.Info("creating resource");

            if (null == resource)
            {
                throw new ArgumentNullException(FileProvider.ArgumentNameResource);
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(FileProvider.ArgumentNameCorrelationIdentifier);
            }

            if (string.IsNullOrWhiteSpace(resource.Identifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidResource);
            }

            string informationStarting =
                string.Format(
                    CultureInfo.InvariantCulture,
                    AzureTestProvisioningResources.InformationCreating,
                    resource.Identifier);
            ProvisioningAgentMonitor.Instance.Inform(informationStarting, true, correlationIdentifier);

            ColumnsFactory columnsFactory;

            WindowsAzureActiveDirectoryGroup group = resource as WindowsAzureActiveDirectoryGroup;
            if (group != null)
            {
                columnsFactory = new GroupColumnsFactory(group);
            }
            else
            {
                Core2EnterpriseUser user = resource as Core2EnterpriseUser;
                if (user != null)
                {
                    columnsFactory = new UserColumnsFactory(user);
                }
                else
                {
                    string unsupportedSchema =
                        string.Join(
                            Environment.NewLine,
                            resource.Schemas);
                    throw new NotSupportedException(unsupportedSchema);
                }
            }

            IReadOnlyDictionary<string, string> columns = columnsFactory.CreateColumns();
            IRow row = await this.file.InsertRow(columns);

            ResourceFactory resourceFactory;
            if (group != null)
            {
                resourceFactory = new GroupFactory(row);
            }
            else
            {
                resourceFactory = new UserFactory(row);
            }

            Resource result = resourceFactory.CreateResource();

            if (group != null && group.Members != null && group.Members.Any())
            {
                foreach (Member member in group.Members)
                {
                    MemberColumnsFactory memberColumnsFactory = new MemberColumnsFactory(result, member);
                    IReadOnlyDictionary<string, string> memberColumns = memberColumnsFactory.CreateColumns();
                    await this.file.InsertRow(memberColumns);
                }
            }

            return result;
        }
        public override async Task<Resource[]> Query(IQueryParameters parameters, string correlationIdentifier)
        {
            if (null == parameters)
            {
                throw new ArgumentNullException(FileProvider.ArgumentNameParameters);
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(FileProvider.ArgumentNameCorrelationIdentifier);
            }

            if (null == parameters.AlternateFilters)
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidParameters);
            }

            if (string.IsNullOrWhiteSpace(parameters.SchemaIdentifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidParameters);
            }

            string informationAlternateFilterCount = parameters.AlternateFilters.Count.ToString(CultureInfo.InvariantCulture);
            ProvisioningAgentMonitor.Instance.Inform(informationAlternateFilterCount, true, correlationIdentifier);
            if (parameters.AlternateFilters.Count != 1)
            {
                string exceptionMessage =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        ProvisioningAgentResources.ExceptionFilterCountTemplate,
                        1,
                        parameters.AlternateFilters.Count);
                throw new NotSupportedException(exceptionMessage);
            }

            Resource[] results;
            IFilter queryFilter = parameters.AlternateFilters.Single();
            if (queryFilter.AdditionalFilter != null)
            {
                results = await this.QueryReference(parameters, correlationIdentifier);
                return results;
            }

            IReadOnlyCollection<string> requestedColumns = this.IdentifyRequestedColumns(parameters);

            if (string.IsNullOrWhiteSpace(queryFilter.AttributePath))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidParameters);
            }

            if (string.IsNullOrWhiteSpace(queryFilter.ComparisonValue))
            {
                throw new ArgumentException(ProvisioningAgentResources.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;
                switch (rowSchema)
                {
                    case SchemaIdentifiers.Core2EnterpriseUser:
                        resourceFactory = new UserFactory(reducedRow);
                        break;
                    case SchemaIdentifiers.WindowsAzureActiveDirectoryGroup:
                        resourceFactory = new GroupFactory(reducedRow);
                        break;
                    default:
                        throw new NotSupportedException(parameters.SchemaIdentifier);
                }

                Resource resource = resourceFactory.CreateResource();
                resources.Add(resource);
            }

            results = resources.ToArray();
            return results;
        }