/// <summary> /// Registers an <see cref="ISharperSystem{T}"/> to the Game. This should not be called from external code. /// </summary> /// <param name="system">The target system to register.</param> public void RegisterSystem(ISharperSystem <BaseSharperComponent> system) { if (Systems.Contains(system) || Systems.Any(x => x.GetType() == system.GetType())) { throw new DuplicateSharperObjectException(); } Systems.Add(system); }
/// <summary> /// Registers an <see cref="ISharperSystem{T}"/> to the Game. This should not be called from external code. /// </summary> /// <param name="system">The target system to register.</param> public void RegisterSystem <T>(T system) where T : ISharperSystem { if (Systems.Contains(system) || Systems.Any(x => x.GetType() == system.GetType())) { throw new DuplicateSharperObjectException(); } Systems.Add(system); }
private SolarSystemSummary LoadRegion(SolarSystemSummary source) { if (Systems.Any(w => w.ConstellationId == source.ConstellationId)) { source.RegionId = Systems.FirstOrDefault(w => w.ConstellationId == source.ConstellationId).RegionId; source.RegionName = Systems.FirstOrDefault(w => w.ConstellationId == source.ConstellationId).RegionName; } else { source.RegionId = new Constellation(source.ConstellationId).RegionId; source.RegionName = new Region(source.RegionId).Name; } return(source); }
public async Task StartAsync(CancellationToken cancellationToken) { if (!Systems.Any()) { return; } Log.LogInformation(w => w .WriteArray("start", array => { foreach (var(_, name) in Systems) { array.WriteValue(name); } }));
/// <summary> /// Creates the multi system. /// </summary> /// <param name="options">The options.</param> /// <returns></returns> public Task <bool> CreateMultiSystem(MultiSystemOptions options) { IMediaCopier mc = new MediaCopier(_hyperspinFrontEnd); _hsSerializer = new HyperspinSerializer(_hyperspinFrontEnd.Path, options.MultiSystemName, ""); IMultiSystem ms = new MultiSystem(_hsSerializer, _systemCreator, mc, options); var games = MultiSystemGamesList.Select(x => x.Game); if (!Systems.Any(x => x.Name == options.MultiSystemName)) { Systems.Add(new MenuItemViewModel(new MainMenu(options.MultiSystemName, 1))); } //Group the games because we can't have duplicate romnames in the database. var filteredGames = games.GroupBy(x => x.RomName).Select(grp => grp.First()); return(ms.CreateMultiSystem(filteredGames , _hyperspinFrontEnd.Path, _settingsRepo.HypermintSettings.RlPath)); }
public void AddSolarSystem(string systemFrom, string systemTo, bool isNeedSave = true) { try { lock (SyncAddSolarSystem) { GarbageCollector(); var system = GetSystem(systemTo); var isFirstStarSystemInMap = !Systems.Any(); if (system != null) { AddConnectionSolarSystem(systemFrom, systemTo); if (system.LocationInMap == new Point(0, 0)) { _log.InfoFormat("[AddSolarSystem] [AddSpaceMapCoordinates] For map with key {0} systemTo {2} systemFrom {3} coordinates before {1}", Information.Key, system.LocationInMap.X + ":" + system.LocationInMap.Y, systemTo, systemFrom); AddSpaceMapCoordinates(systemTo, systemFrom, isFirstStarSystemInMap); } return; } InsertNewPoint(systemTo); AddConnectionSolarSystem(systemFrom, systemTo); _log.InfoFormat("[AddSolarSystem] [AddSpaceMapCoordinates] For map with key {0} systemTo {2} systemFrom {3} coordinates before {1}", Information.Key, 0 + ":" + 0, systemTo, systemFrom); AddSpaceMapCoordinates(systemTo, systemFrom, isFirstStarSystemInMap); if (isNeedSave) { Save(); } } } catch (Exception) { } }
// ReSharper disable once InconsistentNaming public void ValidateUK2012(TextWriter logger, bool fixIfPossible) { //initial counter value for automatic unique names _counter = 1001; _defaultSystem = null; _anyDefaultSpace = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); //Clarity of naming //To ensure the clarity of naming, the following should be done. //• Names should use the characters A‑Z, a‑z and 0‑9 with spaces and full stops. //• Contacts should be named by use of their valid email address, including “@”. //• Names should not contain commas or double spaces, nor unusual characters(e.g. &,%, ‘, “, <, >). //• Classifications should use the colon to separate code from description and should not use commas. var all = Get <CobieObject>().ToArray(); var regex = new Regex("[,|&|%|‘|“|<|>]", RegexOptions.Compiled); var catRegex = new Regex("[:|,]", RegexOptions.Compiled); foreach (var o in all) { if (String.IsNullOrEmpty(o.Name)) { logger.WriteLine("Object of type {0} (description: {1}) doesn't have a 'Name'! This is illegal.", o.GetType().Name, o.Description); if (fixIfPossible) { o.Name = String.Format("{0} {1}", o.GetType().Name, _counter++); } } if (regex.IsMatch(o.Name)) { logger.WriteLine("Name {0} of {1} contains forbidden characters.", o.Name, o.GetType().Name); if (fixIfPossible) { o.Name = regex.Replace(o.Name, ""); } } foreach (var key in o.GetKeys().Where(key => regex.IsMatch(key.Name ?? ""))) { logger.WriteLine("Name {0} of {1} key contains forbidden characters.", key.Name, key.GetSheet("UK2012")); if (fixIfPossible) { key.Name = regex.Replace(key.Name ?? "", ""); } } if (o.Categories != null && o.Categories.Any()) { foreach (var category in o.Categories) { if (category.Code != null && catRegex.IsMatch(category.Code)) { logger.WriteLine("Category code {0} contains forbidden characters.", category.Code); if (fixIfPossible) { category.Code = catRegex.Replace(category.Code, ""); } } if (category.Description == null || !catRegex.IsMatch(category.Description)) { continue; } logger.WriteLine("Category description {0} contains forbidden characters.", category.Description); if (fixIfPossible) { category.Description = catRegex.Replace(category.Description, ""); } } } //Category entries should be provided. //Only Asset doesn't have a category in COBie XLS if ((o.Categories == null || !o.Categories.Any()) && !(o is Asset)) { logger.WriteLine("{0} '{1}' doesn't have a category defined.", o.GetType().Name, o.Name); if (fixIfPossible) { if (o.Categories == null) { o.Categories = new List <Category>(); } o.Categories.Add(new Category { Code = "unknown" }); } } //CreatedBy is a foreign key which should be defined for all objects if (o.CreatedBy == null && fixIfPossible) { o.CreatedBy = GetDefaultContactKey(); } } stopWatch.Stop(); Debug.WriteLine(" Validation of names (invalid characters) and categories: " + stopWatch.ElapsedMilliseconds); stopWatch.Restart(); //Uniqueness of information should be ensured. Names should be unique within //their sheet, except that the System, Zone and Attribute names should be unique in //conjunction with other columns. (Martin Cerny: + Assembly, Connection, Job, Impact, Document, Coordinate, Issue) //a) On the “Attribute” sheet, every Attribute Name (column A), taken with Sheet‑Name (column E) and Row‑Name (column F) should be unique. //b) On the “System” sheet, every System Name (column A) taken with Component‑Names (column E) should be unique. //c) On the “Zone” sheet, every Zone Name (column A) taken with Space‑Names (column E) should be unique. CheckForUniqueNames(Contacts, logger, fixIfPossible); CheckForUniqueNames(Floors, logger, fixIfPossible); CheckForUniqueNames(all.OfType <Space>(), logger, fixIfPossible); CheckForUniqueNames(AssetTypes, logger, fixIfPossible); CheckForUniqueNames(all.OfType <Asset>(), logger, fixIfPossible); CheckForUniqueNames(all.OfType <Spare>(), logger, fixIfPossible); CheckForUniqueNames(Resources, logger, fixIfPossible); CheckForUniqueNames(Zones, logger, fixIfPossible); CheckForUniqueNames(Systems, logger, fixIfPossible); CheckForUniqueNames(Stages, logger, fixIfPossible); //Suplementary information CheckForUniqueNames(all.OfType <Assembly>(), logger, fixIfPossible); CheckForUniqueNames(all.OfType <Connection>(), logger, fixIfPossible); CheckForUniqueNames(all.OfType <Job>(), logger, fixIfPossible); CheckForUniqueNames(all.OfType <Impact>(), logger, fixIfPossible); CheckForUniqueNames(all.OfType <Document>(), logger, fixIfPossible); CheckForUniqueNames(all.OfType <Representation>(), logger, fixIfPossible); CheckForUniqueNames(all.OfType <Issue>(), logger, fixIfPossible); //attributes are only unique within a containing object foreach (var cobieObject in all.Where(cobieObject => cobieObject.Attributes != null)) { CheckForUniqueNames(cobieObject.Attributes, logger, fixIfPossible); } stopWatch.Stop(); Debug.WriteLine(" Checking unique names: " + stopWatch.ElapsedMilliseconds); stopWatch.Restart(); var referenceWatch = new Stopwatch(); referenceWatch.Start(); //The integrity of references should be ensured as follows: //a) Every Space (location) should be assigned to one Floor (region). - If the name is unique this is granted by COBieLite data schema //b) Every Space (location) should be assigned to at least one Zone. var spaces = Get <Space>().ToList(); var zones = Zones ?? new List <Zone>(); foreach ( var space in spaces.Where( space => !zones.Any(z => z.Spaces != null && z.Spaces.Select(s => s.Name).Contains(space.Name))) ) { logger.WriteLine("Space '{0}' is not in any zone.", space.Name); if (!fixIfPossible) { continue; } if (Zones == null) { Zones = new List <Zone>(); } var defaultZone = GetDefaultZone(); defaultZone.Spaces.Add(new SpaceKey { Name = space.Name }); } referenceWatch.Stop(); Debug.WriteLine(" Every space in zone: " + referenceWatch.ElapsedMilliseconds); referenceWatch.Restart(); //c) Every Floor and Zone should have at least one Space (location). if (Floors != null) { foreach (var floor in Floors.Where(f => f.Spaces == null || !f.Spaces.Any()).ToArray()) { logger.WriteLine("Floor {0} doesn't have any space assigned.", floor.Name); if (!fixIfPossible) { continue; } if (floor.Spaces == null) { floor.Spaces = new List <Space>(); } floor.Spaces.Add(GetNewDefaultSpace(false, true)); } } if (Zones != null) { foreach (var zone in Zones.Where(z => z.Spaces == null || !z.Spaces.Any()).ToArray()) { logger.WriteLine("Zone {0} doesn't have any space assigned.", zone.Name); if (!fixIfPossible) { continue; } if (zone.Spaces == null) { zone.Spaces = new List <SpaceKey>(); } var defaultSpace = GetAnyDefaultSpace(false); zone.Spaces.Add(new SpaceKey { Name = defaultSpace.Name }); } } referenceWatch.Stop(); Debug.WriteLine(" Every floor and zone has a space: " + referenceWatch.ElapsedMilliseconds); referenceWatch.Restart(); //d) Every Component should be assigned to at least one Space (location), from which it is used, inspected or maintained. //e) Every Component should be assigned to one Type. - This is granted by design of COBieLite var assets = Get <Asset>().ToArray(); foreach (var asset in assets.Where(a => a.Spaces == null || !a.Spaces.Any())) { logger.WriteLine("Component {0} is not assigned to any space.", asset.Name); if (!fixIfPossible) { continue; } var space = GetAnyDefaultSpace(); if (asset.Spaces == null) { asset.Spaces = new List <SpaceKey>(); } asset.Spaces.Add(new SpaceKey { Name = space.Name }); } referenceWatch.Stop(); Debug.WriteLine(" Every component is in space: " + referenceWatch.ElapsedMilliseconds); referenceWatch.Restart(); //f) Every Component should be assigned to at least one System, identifying its function. foreach ( var asset in assets.Where( a => Systems == null || !Systems.Any(s => s.Components != null && s.Components.Any(c => c.Name == a.Name)))) { logger.WriteLine("Component {0} is not assigned to any system.", asset.Name); if (fixIfPossible) { GetDefaultSystem().Components.Add(new AssetKey { Name = asset.Name }); } } referenceWatch.Stop(); Debug.WriteLine(" Every component is in system: " + referenceWatch.ElapsedMilliseconds); referenceWatch.Restart(); //g) Every Type should apply to at least one Component. if (AssetTypes != null) { foreach (var type in AssetTypes.Where(t => t.Assets == null || !t.Assets.Any())) { logger.WriteLine("Type {0} doesn't contain any components.", type.Name); if (!fixIfPossible) { continue; } if (type.Assets == null) { type.Assets = new List <Asset>(); } type.Assets.Add(GetNewDefaultAsset()); } } referenceWatch.Stop(); Debug.WriteLine(" Every type has a component: " + referenceWatch.ElapsedMilliseconds); referenceWatch.Restart(); stopWatch.Stop(); Debug.WriteLine(" ------- Checking references (every type has a component, ...): " + stopWatch.ElapsedMilliseconds); stopWatch.Restart(); //h) Every reference to other sheets should be valid. - This is mostly granted by the schema itself. We only need to check the keys. ValidateKeys(logger, fixIfPossible); stopWatch.Stop(); Debug.WriteLine(" Checking valid keys: " + stopWatch.ElapsedMilliseconds); stopWatch.Restart(); //i) Every reference to PickList enumerations and classifications should be valid. - We don't store any specific pick lists like classifications etc. This depends on project specific settings. //j) Enumerations specified in the Attributes and PickLists should be adhered to. }