예제 #1
0
 public void Ref(FPackageFileSummary summary)
 {
     ClassIndex.Ref(summary);
     TemplateIndex.Ref(summary);
     OuterIndex.Ref(summary);
     SuperIndex.Ref(summary);
     ObjectName.Ref(summary);
 }
예제 #2
0
파일: GameEngine.cs 프로젝트: suzuke/forge
        /// <summary>
        /// Creates a multithreaded system from the given base system.
        /// </summary>
        private MultithreadedSystem CreateMultithreadedSystem(ISystem baseSystem,
                                                              TemplateIndex templateIndex)
        {
            // initialize references in the system
            baseSystem.EventDispatcher = EventNotifier;
            baseSystem.GlobalEntity    = _globalEntity;
            baseSystem.EntityIndex     = _entityIndex;
            baseSystem.TemplateIndex   = templateIndex;

            MultithreadedSystem multithreadingSystem = new MultithreadedSystem(this, baseSystem);

            foreach (var entity in _entities)
            {
                multithreadingSystem.Restore(entity);
            }
            return(multithreadingSystem);
        }
예제 #3
0
파일: GameEngine.cs 프로젝트: suzuke/forge
        public GameEngine(string snapshotJson, string templateJson)
        {
            _templateJson = templateJson;

            // Create our own little island of references with its own set of templates
            GameSnapshotRestorer restorer = GameSnapshotRestorer.Restore(
                snapshotJson, templateJson, Maybe.Just(this));
            GameSnapshot snapshot = restorer.GameSnapshot;

            EntityIdGenerator = snapshot.EntityIdGenerator;

            _systems     = snapshot.Systems;
            _entityIndex = new EntityIndex();

            // TODO: ensure that when correctly restore UpdateNumber
            //UpdateNumber = updateNumber;

            _globalEntity = (RuntimeEntity)snapshot.GlobalEntity;

            EventNotifier.Submit(EntityAddedEvent.Create(_globalEntity));

            foreach (var entity in snapshot.AddedEntities)
            {
                AddEntity((RuntimeEntity)entity);
            }

            foreach (var entity in snapshot.ActiveEntities)
            {
                RuntimeEntity runtimeEntity = (RuntimeEntity)entity;

                // add the entity
                InternalAddEntity(runtimeEntity);

                // TODO: verify that if the modification notifier is already triggered, we can
                // ignore this
                //if (((ContentEntity)entity).HasModification) {
                //    runtimeEntity.ModificationNotifier.Notify();
                //}

                // done via InternalAddEntity
                //if (deserializedEntity.HasStateChange) {
                //    deserializedEntity.Entity.DataStateChangeNotifier.Notify();
                //}
            }

            foreach (var entity in snapshot.RemovedEntities)
            {
                RuntimeEntity runtimeEntity = (RuntimeEntity)entity;

                // add the entity
                InternalAddEntity(runtimeEntity);

                // TODO: verify that if the modification notifier is already triggered, we can
                // ignore this
                //if (((ContentEntity)entity).HasModification) {
                //    runtimeEntity.ModificationNotifier.Notify();
                //}

                // done via InternalAddEntity
                //if (deserializedEntity.HasStateChange) {
                //    deserializedEntity.Entity.DataStateChangeNotifier.Notify();
                //}

                RemoveEntity(runtimeEntity);
            }

            TemplateIndex templateIndex = new TemplateIndex(restorer.Templates.Templates);

            _executionGroups = new List <ExecutionGroup>();
            var executionGroups = SystemExecutionGroup.GetExecutionGroups(snapshot.Systems);

            foreach (var executionGroup in executionGroups)
            {
                List <MultithreadedSystem> multithreadedSystems = new List <MultithreadedSystem>();
                foreach (var system in executionGroup.Systems)
                {
                    MultithreadedSystem multithreaded = CreateMultithreadedSystem(system, templateIndex);
                    multithreadedSystems.Add(multithreaded);
                }
                _executionGroups.Add(new ExecutionGroup(multithreadedSystems));
            }

            _nextState = GameEngineNextState.SynchronizeState;
            SynchronizeState().Wait();

            // call of the engine loaded systems
            foreach (var group in _executionGroups)
            {
                foreach (var system in group.Systems)
                {
                    var onLoaded = system.System as Trigger.OnEngineLoaded;
                    if (onLoaded != null)
                    {
                        onLoaded.OnEngineLoaded(EventNotifier);

                        // TODO: verify that OnEngineLoaded didn't change any state (via hashing)
                    }
                }
            }
        }
예제 #4
0
 private static Repositories.Common.Search.SearchResult <TemplateIndex> CreateTemplateResult(TemplateIndex templateIndex)
 {
     return(new Repositories.Common.Search.SearchResult <TemplateIndex>()
     {
         Result = templateIndex
     });
 }
예제 #5
0
        /// <summary>
        /// Creates a multithreaded system from the given base system.
        /// </summary>
        private MultithreadedSystem CreateMultithreadedSystem(ISystem baseSystem,
            TemplateIndex templateIndex) {

            // initialize references in the system
            baseSystem.EventDispatcher = EventNotifier;
            baseSystem.GlobalEntity = _globalEntity;
            baseSystem.EntityIndex = _entityIndex;
            baseSystem.TemplateIndex = templateIndex;

            MultithreadedSystem multithreadingSystem = new MultithreadedSystem(this, baseSystem);
            foreach (var entity in _entities) {
                multithreadingSystem.Restore(entity);
            }
            return multithreadingSystem;
        }
예제 #6
0
        public GameEngine(string snapshotJson, string templateJson) {
            _templateJson = templateJson;

            // Create our own little island of references with its own set of templates
            GameSnapshotRestorer restorer = GameSnapshotRestorer.Restore(
                snapshotJson, templateJson, Maybe.Just(this));
            GameSnapshot snapshot = restorer.GameSnapshot;

            EntityIdGenerator = snapshot.EntityIdGenerator;

            _systems = snapshot.Systems;
            _entityIndex = new EntityIndex();

            // TODO: ensure that when correctly restore UpdateNumber
            //UpdateNumber = updateNumber;

            _globalEntity = (RuntimeEntity)snapshot.GlobalEntity;

            EventNotifier.Submit(EntityAddedEvent.Create(_globalEntity));

            foreach (var entity in snapshot.AddedEntities) {
                AddEntity((RuntimeEntity)entity);
            }

            foreach (var entity in snapshot.ActiveEntities) {
                RuntimeEntity runtimeEntity = (RuntimeEntity)entity;

                // add the entity
                InternalAddEntity(runtimeEntity);

                // TODO: verify that if the modification notifier is already triggered, we can
                // ignore this
                //if (((ContentEntity)entity).HasModification) {
                //    runtimeEntity.ModificationNotifier.Notify();
                //}

                // done via InternalAddEntity
                //if (deserializedEntity.HasStateChange) {
                //    deserializedEntity.Entity.DataStateChangeNotifier.Notify();
                //}
            }

            foreach (var entity in snapshot.RemovedEntities) {
                RuntimeEntity runtimeEntity = (RuntimeEntity)entity;

                // add the entity
                InternalAddEntity(runtimeEntity);

                // TODO: verify that if the modification notifier is already triggered, we can
                // ignore this
                //if (((ContentEntity)entity).HasModification) {
                //    runtimeEntity.ModificationNotifier.Notify();
                //}

                // done via InternalAddEntity
                //if (deserializedEntity.HasStateChange) {
                //    deserializedEntity.Entity.DataStateChangeNotifier.Notify();
                //}

                RemoveEntity(runtimeEntity);
            }

            TemplateIndex templateIndex = new TemplateIndex(restorer.Templates.Templates);

            _executionGroups = new List<ExecutionGroup>();
            var executionGroups = SystemExecutionGroup.GetExecutionGroups(snapshot.Systems);
            foreach (var executionGroup in executionGroups) {
                List<MultithreadedSystem> multithreadedSystems = new List<MultithreadedSystem>();
                foreach (var system in executionGroup.Systems) {
                    MultithreadedSystem multithreaded = CreateMultithreadedSystem(system, templateIndex);
                    multithreadedSystems.Add(multithreaded);
                }
                _executionGroups.Add(new ExecutionGroup(multithreadedSystems));
            }

            _nextState = GameEngineNextState.SynchronizeState;
            SynchronizeState().Wait();

            // call of the engine loaded systems
            foreach (var group in _executionGroups) {
                foreach (var system in group.Systems) {
                    var onLoaded = system.System as Trigger.OnEngineLoaded;
                    if (onLoaded != null) {
                        onLoaded.OnEngineLoaded(EventNotifier);

                        // TODO: verify that OnEngineLoaded didn't change any state (via hashing)
                    }
                }
            }
        }
예제 #7
0
        public void SearchIndexTest_GivenSearchSchemasAndModels_EnsureFieldsMatch()
        {
            // Arrange
            IList <string>         ErrorLog = new List <string>();
            DatasetDefinitionIndex datasetDefinitionIndex = new DatasetDefinitionIndex();
            ProvidersIndex         providersIndex         = new ProvidersIndex();
            PublishedFundingIndex  publishedfundingindex  = new PublishedFundingIndex();
            PublishedProviderIndex publishedProviderIndex = new PublishedProviderIndex();
            SpecificationIndex     specificationindex     = new SpecificationIndex();
            TemplateIndex          templateIndex          = new TemplateIndex();

            IEnumerable <Type> searchIndexTypes = GetTypesWithSearchIndexAttribute();

            IEnumerable <string> indexNames = Directory
                                              .GetDirectories(searchIndexDirectoryPath, "*index", SearchOption.TopDirectoryOnly)
                                              .Select(m => new DirectoryInfo(m).Name);

            //Act
            foreach (string indexName in indexNames)
            {
                try
                {
                    string jsonFilePath = $@"{searchIndexDirectoryPath}\{indexName}\{indexName}.json";

                    string            jsonText          = File.ReadAllText(jsonFilePath, Encoding.UTF8);
                    SearchIndexSchema searchIndexSchema = JsonConvert.DeserializeObject <SearchIndexSchema>(jsonText);
                    if (searchIndexSchema?.Name == null)
                    {
                        ErrorLog.Add(string.IsNullOrWhiteSpace(jsonText)
                            ? $"{indexName} json is blank"
                            : $"{indexName} json name is not available");
                    }
                    else if (searchIndexSchema.Name != indexName)
                    {
                        ErrorLog.Add($"Expected to find index { indexName }, but found { searchIndexSchema.Name }");
                    }
                    else
                    {
                        Type searchIndexType = searchIndexTypes
                                               .FirstOrDefault(m => m.CustomAttributes
                                                               .FirstOrDefault(p => p.NamedArguments
                                                                               .Any(n => n.TypedValue.Value.ToString() == searchIndexSchema.Name)) != null);

                        IEnumerable <string> searchIndexProperties = searchIndexType.GetProperties()
                                                                     .Select(m => m.CustomAttributes
                                                                             .FirstOrDefault(a => a.AttributeType.Name == "JsonPropertyAttribute")
                                                                             ?.ConstructorArguments[0].Value.ToString().ToLower())
                                                                     .Where(p => p != null);

                        IEnumerable <string> searchIndexJsonProperties = searchIndexSchema.Fields
                                                                         .Select(m => m.Name.ToLower())
                                                                         .Where(p => p != null);

                        if (!searchIndexProperties.Any())
                        {
                            ErrorLog.Add($"Index {indexName}: The model contains no properties");
                        }
                        else if (!searchIndexJsonProperties.Any())
                        {
                            ErrorLog.Add($"Index {indexName}: The json contains no properties");
                        }
                        else
                        {
                            IEnumerable <string> notInJson = searchIndexProperties.Except(searchIndexJsonProperties);
                            if (notInJson.Any())
                            {
                                string properties = string.Join(",", notInJson);
                                ErrorLog.Add($"Index {indexName}: The model contains the following properties not found in the json schema ({properties})");
                            }

                            IEnumerable <string> notInModel = searchIndexJsonProperties.Except(searchIndexProperties);
                            if (notInModel.Any())
                            {
                                string properties = string.Join(",", notInModel);
                                ErrorLog.Add($"Index {indexName}: The json schema contains the following properties not found in the model ({properties})");
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLog.Add($"Unexpected error checking '{indexName}': {e.Message}{Environment.NewLine}{ e.StackTrace }");
                }
            }

            //Assert
            if (ErrorLog.Any())
            {
                Assert.Fail(string.Join(Environment.NewLine, ErrorLog));
            }
        }
예제 #8
0
        public void SearchIndexTest_GivenSearchSchemasAndModels_EnsuresAttributesMatch()
        {
            //Arrange
            IList <string>         ErrorLog = new List <string>();
            DatasetDefinitionIndex datasetDefinitionIndex = new DatasetDefinitionIndex();
            ProvidersIndex         providersIndex         = new ProvidersIndex();
            PublishedFundingIndex  publishedfundingindex  = new PublishedFundingIndex();
            PublishedProviderIndex publishedProviderIndex = new PublishedProviderIndex();
            SpecificationIndex     specificationindex     = new SpecificationIndex();
            TemplateIndex          templateIndex          = new TemplateIndex();

            IEnumerable <Type> searchIndexTypes = GetTypesWithSearchIndexAttribute();

            IEnumerable <string> indexNames = Directory
                                              .GetDirectories(searchIndexDirectoryPath, "*index", SearchOption.TopDirectoryOnly)
                                              .Select(m => new DirectoryInfo(m).Name);

            //Act
            foreach (string indexName in indexNames)
            {
                try
                {
                    string jsonFilePath = $@"{searchIndexDirectoryPath}\{indexName}\{indexName}.json";

                    string jsonText = File.ReadAllText(jsonFilePath, Encoding.UTF8);

                    SearchIndexSchema searchIndexSchema = JsonConvert.DeserializeObject <SearchIndexSchema>(jsonText);
                    if (searchIndexSchema?.Name == null)
                    {
                        ErrorLog.Add(string.IsNullOrWhiteSpace(jsonText)
                            ? $"{indexName} json is blank"
                            : $"{indexName} json name is not available");
                    }
                    else if (searchIndexSchema.Name != indexName)
                    {
                        ErrorLog.Add($"Expected to find index {indexName}, but found {searchIndexSchema.Name}");
                    }
                    else
                    {
                        Type searchIndexType = searchIndexTypes.FirstOrDefault(m =>
                                                                               m.CustomAttributes.FirstOrDefault(p =>
                                                                                                                 p.NamedArguments.Any(n =>
                                                                                                                                      n.TypedValue.Value.ToString() == searchIndexSchema.Name)) != null);

                        IEnumerable <PropertyInfo> searchIndexProperties = searchIndexType.GetProperties();

                        foreach (SearchIndexField searchIndexField in searchIndexSchema.Fields)
                        {
                            PropertyInfo matchedProperty = searchIndexProperties.FirstOrDefault(m =>
                                                                                                string.Equals(m.CustomAttributes
                                                                                                              .SingleOrDefault(x => x.AttributeType.Name == "JsonPropertyAttribute")
                                                                                                              ?.ConstructorArguments[0].ToString().Replace("\"", "")
                                                                                                              ?? m.Name,
                                                                                                              searchIndexField.Name,
                                                                                                              StringComparison.InvariantCultureIgnoreCase));

                            if (matchedProperty == null)
                            {
                                ErrorLog.Add($"{indexName}: {searchIndexField.Name} did not match any properties");
                            }
                            else
                            {
                                CheckIndexFieldTypes(matchedProperty, searchIndexField, ErrorLog, indexName);
                                CheckIndexAttributes(matchedProperty, searchIndexField, ErrorLog, indexName);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLog.Add($"Unexpected error checking '{indexName}': {e.Message}{Environment.NewLine}{e.StackTrace}");
                }
            }

            //Assert
            if (ErrorLog.Any())
            {
                Assert.Fail(string.Join(Environment.NewLine, ErrorLog));
            }
        }