Esempio n. 1
0
        public void FileIsNotEmpty()
        {
            using (TextReader textReader = GetTextReader())
            {
                IEnumerable <Trip> parsed     = _parser.Parse(textReader);
                List <Trip>        parsedList = parsed.ToList();

                Assert.NotNull(parsedList);
                Assert.True(parsedList.Any());
                Assert.Equal(2119, parsedList.Count);
            }
        }
Esempio n. 2
0
        private async IAsyncEnumerable <Item> LoadAndWriteJsonFiles(string itemsFolder)
        {
            var folderPath = Path.Combine(DataRoot, itemsFolder);
            var index      = new List <Item>();

            var searchOptions = itemsFolder.ToLower().EndsWith("scitem")
                                                    ? SearchOption.TopDirectoryOnly
                                                    : SearchOption.AllDirectories;

            foreach (var entityFilename in Directory.EnumerateFiles(folderPath, "*.xml", searchOptions))
            {
                if (AvoidFile(entityFilename))
                {
                    continue;
                }

                EntityClassDefinition entity = null;

                // Entity
                _logger.LogInformation(entityFilename);
                entity = await _entityParser.Parse(entityFilename, OnXmlLoadout);

                if (entity == null)
                {
                    continue;
                }

                var jsonFilename = Path.Combine(OutputFolder, $"{entity.ClassName.ToLower()}.json");
                _ = _jsonFileReaderWriter.WriteFile(jsonFilename, () => new { Raw = new { Entity = entity } });

                var manufacturer =
                    FindManufacturer(entity.Components?.SAttachableComponentParams?.AttachDef.Manufacturer);

                var etd = GetLocalizedDataFromEntity(entity);
                yield return(new Item
                {
                    Id = new Guid(entity.Id),
                    JsonFilename =
                        Path.GetRelativePath(Path.GetDirectoryName(OutputFolder), jsonFilename),
                    ClassName = entity.ClassName,
                    Type = etd.Type,
                    SubType = etd.SubType,
                    ItemName = entity.ClassName.ToLower(),
                    Size = entity.Components?.SAttachableComponentParams?.AttachDef.Size,
                    Grade = entity.Components?.SAttachableComponentParams?.AttachDef.Grade,
                    Name = etd.Name,
                    Description = etd.Description,
                    Manufacturer = manufacturer,
                    ManufacturerId = manufacturer.Id
                });
            }
        }
Esempio n. 3
0
        public void TestReadInvalidEntity(string fileName)
        {
            // Given
            var invalidEntity = GetFileContents(fileName);
            var entityData    = Encoding.ASCII.GetBytes(invalidEntity);

            // When
            var parser   = new EntityParser(entityData);
            var entities = parser.Parse();

            // Then
            Assert.IsNotNull(entities);
            Assert.IsTrue(entities.Count == 0);
        }
Esempio n. 4
0
        private async IAsyncEnumerable <Commodity> LoadAndWriteJsonFiles(string itemsFolder)
        {
            var folderPath = Path.Combine(DataRoot, itemsFolder);
            var index      = new List <Item>();

            foreach (var entityFilename in Directory.EnumerateFiles(folderPath, "*.xml", SearchOption.AllDirectories))
            {
                if (AvoidFile(entityFilename))
                {
                    continue;
                }

                EntityClassDefinition entity = null;

                // Entity
                _logger.LogInformation(entityFilename);
                entity = await _entityParser.Parse(entityFilename, OnXmlLoadout);

                if (entity == null)
                {
                    continue;
                }

                var jsonFilename = Path.Combine(OutputFolder, $"{entity.ClassName.ToLower()}.json");
                _ = _jsonFileReaderWriter.WriteFile(jsonFilename, () => new { Raw = new { Entity = entity } });

                var etd = GetLocalizedDataFromEntity(entity);

                var type        = CommodityTypes[etd.Type];
                var subType     = CommodityTypes.GetValueOrDefault(etd.SubType);
                var description = string.IsNullOrWhiteSpace(etd.Description) ? subType?.Description : etd.Description;

                yield return(new Commodity
                {
                    Id = new Guid(entity.Id),
                    JsonFilename =
                        Path.GetRelativePath(Path.GetDirectoryName(OutputFolder), jsonFilename),
                    ClassName = entity.ClassName,
                    Type = type,
                    TypeId = type.Id,
                    SubType = subType,
                    SubTypeId = subType?.Id,
                    Name = etd.Name,
                    Description = description
                });
            }
        }
Esempio n. 5
0
        private static CommandDefinitionModel BuildModel(InputDtoClassLocator locator)
        {
            var model = new CommandDefinitionModel();

            // set the class name to create the command with
            var className = locator.InputDtoName.Replace("InputDTO", "Command");

            model.ClassName = className;

            // parse the input class
            var entityParser   = new EntityParser();
            var entityMetadata = entityParser.Parse(locator.InputDtoNode);

            model.InputMetadata = entityMetadata;

            return(model);
        }
        public ProxyModel BuildModel(IEnumerable <EntityMetadata> entityMetadata, IEnumerable <SdkMessageMetadata> messageMetadata)
        {
            var proxyModel = new ProxyModel(this.TypeConverter);

            var entities = entityMetadata
                           .Select(e => EntityParser.Parse(proxyModel, e))
                           .OrderBy(e => e.DisplayName);

            var globals = proxyModel.GlobalOptionSets = GetGlobalOptionsFromEntities(entities)
                                                        .OrderBy(o => o.DisplayName);

            var messages = messageMetadata
                           .Select(m => MessageParser.Parse(m))
                           .OrderBy(m => m.SchemaName);

            proxyModel.Entities         = entities;
            proxyModel.GlobalOptionSets = globals;
            proxyModel.Messages         = messages;

            RaiseMessage("Generated Proxy Model...");

            return(proxyModel);
        }
Esempio n. 7
0
        private async IAsyncEnumerable <Ship> LoadAndWriteAsJsonFile(string entityFolder)
        {
            var index = new List <Ship>();

            foreach (var entityFilename in Directory.EnumerateFiles(Path.Combine(DataRoot, entityFolder), "*.xml"))
            {
                if (AvoidFile(entityFilename))
                {
                    continue;
                }

                EntityClassDefinition entity = null;
                Vehicle vehicle = null;

                _logger.LogInformation(entityFilename);

                entity = await _entityParser.Parse(entityFilename, OnXmlLoadout);

                if (entity == null)
                {
                    continue;
                }

                if (entity.Components.VehicleComponentParams == null)
                {
                    _logger.LogWarning("This doesn't seem to be a vehicle");
                    continue;
                }

                var vehicleFilename = entity.Components?.VehicleComponentParams?.vehicleDefinition;
                if (vehicleFilename != null)
                {
                    vehicleFilename = Path.Combine(DataRoot, "Data", vehicleFilename.Replace('/', '\\'));
                    var vehicleModification = entity.Components?.VehicleComponentParams?.modification;
                    _logger.LogInformation(vehicleFilename);

                    vehicle = _vehicleParser.Parse(vehicleFilename, vehicleModification);
                }

                var jsonFilename = Path.Combine(OutputFolder, $"{entity.ClassName.ToLower()}.json");
                _ = _jsonFileReaderWriter.WriteFile(jsonFilename,
                                                    () => new
                {
                    Raw = new
                    {
                        Entity  = entity,
                        Vehicle = vehicle
                    }
                });

                var isGroundVehicle =
                    entity.Components?.VehicleComponentParams.vehicleCareer == "@vehicle_focus_ground";
                var isGravlevVehicle = entity.Components?.VehicleComponentParams.isGravlevVehicle ?? false;
                var isSpaceship      = !(isGroundVehicle || isGravlevVehicle);

                var manufacturer =
                    GetManufacturer(entity.Components?.SAttachableComponentParams?.AttachDef.Manufacturer);

                yield return(new Ship
                {
                    Id = new Guid(entity.Id),
                    JsonFilename =
                        Path.GetRelativePath(Path.GetDirectoryName(OutputFolder), jsonFilename),
                    ClassName = entity.ClassName,
                    Type = entity.Components?.SAttachableComponentParams?.AttachDef.Type,
                    SubType = entity.Components?.SAttachableComponentParams?.AttachDef.SubType,
                    Name =
                        _localisationService.GetText(entity.Components.VehicleComponentParams
                                                     .vehicleName),
                    Career =
                        _localisationService.GetText(entity.Components.VehicleComponentParams
                                                     .vehicleCareer),
                    Role =
                        _localisationService.GetText(entity.Components.VehicleComponentParams
                                                     .vehicleRole),
                    DogFightEnabled =
                        Convert.ToBoolean(entity.Components.VehicleComponentParams.dogfightEnabled),
                    Size = vehicle?.size,
                    Description =
                        _localisationService.GetText(entity.Components.VehicleComponentParams
                                                     .vehicleDescription),
                    IsGroundVehicle = isGroundVehicle,
                    IsGravlevVehicle = isGravlevVehicle,
                    IsSpaceship = isSpaceship,
                    NoParts = vehicle?.Parts == null || vehicle.Parts.Length == 0,
                    Manufacturer = manufacturer,
                    ManufacturerId = manufacturer.Id
                });
            }
        }
Esempio n. 8
0
 public void EnsureThatParsingOnNullTextReaderThrowsException()
 {
     Assert.Throws <ArgumentNullException>(() => _parser.Parse(null));
 }