public LevelLoaderService(UnitRegistry unitRegistry, IFactory <UnitData, AllianceType, WorldPosition, SpawnUnitCommand> spawnUnitCommandFactory, CommandProcessor commandProcessor) { _spawnUnitCommandFactory = spawnUnitCommandFactory; _commandProcessor = commandProcessor; _unitRegistry = unitRegistry; }
public bool ReloadUnit(string name) { var transaction = UnitRegistry.GetUnit(name).GetReloadTransaction(); var result = transaction.Execute(); return(result.Type == Tasks.ResultType.Success); }
public UnitExpressionParserTests() { var unitRegistry = new UnitRegistry(); this.lexicalAnalyzer = A.Fake <ILexicalAnalyzer>(); this.testee = new UnitExpressionParser(unitRegistry, this.lexicalAnalyzer); }
public UnitRepository(UnitRegistry unitRegistry) { _unitRegistry = unitRegistry; ParseUnits(); BridgeData.unitRepo = this; }
public bool LoadUnitFromFile(string path) { try { UnitRegistry.AddUnitByPath(path); return(true); } catch { return(false); } }
public static void ClassInitialize(TestContext value) { PlatformUtilities.RegisterImplementations(); PlatformUtilities.GetImplementation <IPlatformInitialization>().Initialize(); UnitRegistry.InitializeTypes(); UnitRegistry.ScanDefaultDirectories(); File.WriteAllText(path, contents); }
public void AddUnitByPath_UnitNotFound_True() { // Arrange // Act UnitRegistry.AddUnitByPath(""); // Assert Assert.IsTrue(UnitRegistry.Units.Count == 0); }
public AbilityMakerAbility(UnitModel unit, AbilityData data, WorldModel world, TickService tickservice, CommandProcessor command, UnitRegistry unitRegistry, AbilityRepository abilityRepository) { _unit = unit; _world = world; _command = command; _data = new BuffAbilityParams(data); _tickService = tickservice; _unitRegistry = unitRegistry; _abilityRepository = abilityRepository; }
public BaseUnit CreateUnit <UnitClass> (Vector2Int coordinates) where UnitClass : BaseUnit { UnitClass unit = ScriptableObject.CreateInstance <UnitClass>(); unit.ID = UnitRegistry.setID(); unit.xPos = coordinates.x; unit.yPos = coordinates.y; unit.ownerID = GameMaster.Instance.getActivePlayer(); return(unit); }
public void AddUnit_UnitIsNull_True() { // Arrange Unit unit = null; // Act UnitRegistry.AddUnit(unit); // Assert Assert.IsTrue(UnitRegistry.Units.Count == 0); }
public void AddUnit_UnitIsAdded_True() { // Arrange Unit unit = new ServiceUnit(path); // Act UnitRegistry.AddUnit(unit); // Assert Assert.IsTrue(UnitRegistry.Units.Count == 1); }
public void ScanDefaultDirectories_UnitsFound_True() { // Arrange Environment.SetEnvironmentVariable("SHARPINIT_UNIT_PATH", "."); var check = Environment.GetEnvironmentVariable("SHARPINIT_UNIT_PATH"); // Act var result = UnitRegistry.ScanDefaultDirectories(); // Assert Assert.IsTrue(UnitRegistry.Units.Count > 0); }
public void AddUnit_UnitHasAlreadyBeenAdded_ThrowsException() { // Arrange Unit unit = new ServiceUnit(path); // Act UnitRegistry.AddUnit(unit); UnitRegistry.AddUnit(unit); // Assert // Exception Thrown }
public void AddUnitByPath_UnitFound_True() { // Arrange UnitRegistry.UnitFiles.Clear(); UnitRegistry.Units.Clear(); // Act UnitRegistry.IndexUnitByPath(TestUnitPath); // Assert Assert.IsNotNull(UnitRegistry.GetUnit(TestUnitFilename)); }
public void AddUnitByPath_UnitNotFound_True() { // Arrange UnitRegistry.UnitFiles.Clear(); UnitRegistry.Units.Clear(); // Act UnitRegistry.IndexUnitByPath($"{DirectoryName}/nonexistent-unit.service"); // Assert Assert.IsNull(UnitRegistry.GetUnit(TestUnitFilename)); }
public void ScanDefaultDirectories_UnitsFound_True() { // Arrange Environment.SetEnvironmentVariable("SHARPINIT_UNIT_PATH", DirectoryName); UnitRegistry.DefaultScanDirectories.Clear(); // Act UnitRegistry.ScanDefaultDirectories(); // Assert Assert.IsTrue(UnitRegistry.UnitFiles.ContainsKey(TestUnitFilename)); }
static void Main(string[] args) { Log.Info("SharpInit starting"); PlatformUtilities.RegisterImplementations(); PlatformUtilities.GetImplementation <IPlatformInitialization>().Initialize(); Log.Info("Platform initialization complete"); UnitRegistry.InitializeTypes(); UnitRegistry.ScanDefaultDirectories(); Log.Info($"Loaded {UnitRegistry.Units.Count} units"); UnitRegistry.UnitStateChange += StateChangeHandler; Log.Info("Registering IPC context..."); var context = new ServerIpcContext(); IpcFunctionRegistry.AddFunction(DynamicIpcFunction.FromContext(context)); Log.Info("Starting IPC listener..."); var ipc_listener = new IpcListener(); ipc_listener.StartListening(); Log.Info($"Listening on {ipc_listener.SocketEndPoint}"); if (UnitRegistry.GetUnit("default.target") != null) { Log.Info("Activating default.target..."); var result = UnitRegistry.CreateActivationTransaction("default.target").Execute(); if (result.Type == Tasks.ResultType.Success) { Log.Info("Successfully activated default.target."); } else { Log.Info($"Error while activating default.target: {result.Type}, {result.Message}"); } } Console.CancelKeyPress += (s, e) => { ipc_listener.StopListening(); }; Thread.Sleep(-1); }
public SpawnUnitsAbility(UnitModel unit, AbilityData data, WorldModel world, TickService tickservice, CommandProcessor command, UnitRegistry unitRegistry, IFactory <IBuff, BuffData, BuffTargetCommand> buffFactory, IFactory <StatChangeData, HPChangeCommand> HPChangeFactory, IFactory <UnitData, AllianceType, WorldPosition, SpawnUnitCommand> spawnUnitCommandFactory) { _unit = unit; _world = world; _command = command; _data = new BuffAbilityParams(data); _tickService = tickservice; _unitRegistry = unitRegistry; _spawnUnitCommandFactory = spawnUnitCommandFactory; }
public UnitInfo GetUnitInfo(string unit_name) { var unit = UnitRegistry.GetUnit(unit_name); var info = new UnitInfo(); info.Name = unit.UnitName; info.Path = unit.File.UnitPath; info.Description = unit.File.Description; info.State = Enum.Parse <Ipc.UnitState>(unit.CurrentState.ToString()); info.LastStateChangeTime = unit.LastStateChangeTime; info.ActivationTime = unit.ActivationTime; info.LoadTime = unit.LoadTime; return(info); }
public void PercentSpecifier_Checks() { // Arrange Environment.SetEnvironmentVariable("SHARPINIT_UNIT_PATH", DirectoryName); UnitRegistry.DefaultScanDirectories.Clear(); // Act UnitRegistry.ScanDefaultDirectories(); var unit_unspecified = UnitRegistry.GetUnit <ServiceUnit>(TestUnitFilename); var unit_specified = UnitRegistry.GetUnit <ServiceUnit>(TestUnitInstanceName); // Assert Assert.IsTrue(unit_unspecified.Descriptor.WorkingDirectory == "/" + StringEscaper.Unescape(unit_unspecified.Descriptor.DefaultInstance)); Assert.IsTrue(unit_specified.Descriptor.WorkingDirectory == "/" + StringEscaper.Unescape(UnitRegistry.GetUnitParameter(TestUnitInstanceName))); }
public static void ClassInitialize(TestContext value) { PlatformUtilities.RegisterImplementations(); PlatformUtilities.GetImplementation <IPlatformInitialization>().Initialize(); UnitRegistry.InitializeTypes(); Random rnd = new Random(); var random_buffer = new byte[8]; rnd.NextBytes(random_buffer); DirectoryName = BitConverter.ToString(random_buffer).Replace("-", "").ToLower(); Directory.CreateDirectory(DirectoryName); File.WriteAllText(TestUnitPath, TestUnitContents); }
/// <summary> /// Initializes a new instance of the <see cref="UnitSystemDependencies"/> class. /// </summary> /// <param name="unitRegistry">The unit registry.</param> /// <param name="lexicalAnalyzer">The lexical analyzer.</param> /// <param name="expressionParser">The expression parser.</param> /// <param name="quantityParser">The quantity parser.</param> /// <param name="unitFactory">The unit factory.</param> /// <param name="quantityOperations">The quantity operations.</param> public UnitSystemDependencies( UnitRegistry unitRegistry, ILexicalAnalyzer lexicalAnalyzer, IExpressionParser expressionParser, IQuantityParser quantityParser, IUnitFactory unitFactory, IQuantityOperations quantityOperations) { this.UnitRegistry = unitRegistry; this.LexicalAnalyzer = lexicalAnalyzer; this.ExpressionParser = expressionParser; this.QuantityParser = quantityParser; this.UnitFactory = unitFactory; this.QuantityOperations = quantityOperations; }
public void GetUnitName_Checks() { var dictionary = new Dictionary <string, string>() { { "/home/user/.config/sharpinit/units/[email protected]", "[email protected]" }, { "/etc/sharpinit/units/[email protected]", "[email protected]" }, { "C:\\Users\\User\\.config\\sharpinit\\units\\notepad.service", "notepad.service" }, { "relative/path/to/[email protected]", "[email protected]" }, { "backslash\\relative\\path\\test.target", "test.target" } }; foreach (var pair in dictionary) { Assert.AreEqual(UnitRegistry.GetUnitName(pair.Key), pair.Value); } }
public UnitInfo GetUnitInfo(string unit_name) { var unit = UnitRegistry.GetUnit(unit_name); var info = new UnitInfo(); var unit_files = unit.Descriptor.Files.OfType <OnDiskUnitFile>(); info.Name = unit.UnitName; info.Path = unit_files.Any() ? string.Join(", ", unit_files.Select(file => file.Path)) : "(not available)"; info.Description = unit.Descriptor.Description; info.State = Enum.Parse <Ipc.UnitState>(unit.CurrentState.ToString()); info.LastStateChangeTime = unit.LastStateChangeTime; info.ActivationTime = unit.ActivationTime; info.LoadTime = unit.Descriptor.Created; return(info); }
public override TaskResult Execute() { var failure_type = StopExecution ? ResultType.StopExecution : ResultType.Failure; var unit = UnitRegistry.GetUnit(TargetUnit); if (unit == null) { return(new TaskResult(this, failure_type, $"Unit {TargetUnit} is not loaded.")); } var state = unit.CurrentState; if (ComparisonState.HasFlag(state) || ComparisonState == UnitState.Any) { return(new TaskResult(this, ResultType.Success)); } return(new TaskResult(this, failure_type, $"Expected {TargetUnit} to be Active, it was instead {state}")); }
public bool DeactivateUnit(string name) { var transaction = UnitRegistry.CreateDeactivationTransaction(name); var result = transaction.Execute(); if (result.Type != ResultType.Success) { Log.Info($"Deactivation transaction failed. Result type: {result.Type}, message: {result.Message}"); Log.Info("Transaction failed at highlighted task: "); var tree = transaction.GenerateTree(0, result.Task); foreach (var line in tree.Split('\n')) { Log.Info(line); } } return(result.Type == ResultType.Success); }
/// <summary> /// Initializes the unit system. /// </summary> /// <param name="unitSystemDependencyFactory">The unit system dependency factory.</param> /// <param name="registerUnitAction">The register unit action.</param> /// <returns>A <see cref="UnitSystemDependencies"/>.</returns> public UnitSystemDependencies InitializeUnitSystem( IUnitSystemDependencyFactory unitSystemDependencyFactory, Action <IUnitRegistrar> registerUnitAction) { this.LockedAction( () => { if (!this.isInitialized) { unitSystemDependencyFactory = unitSystemDependencyFactory ?? new UnitSystemDependencyFactory( new ExpressionToFlatRepresentationConverter()); this.unitRegistry = unitSystemDependencyFactory.CreateUnitRegistry(); registerUnitAction?.Invoke(this.unitRegistry); this.expressionParser = unitSystemDependencyFactory.CreateParser(this.unitRegistry); this.lexicalAnalyzer = unitSystemDependencyFactory.CreateLexicalAnalyzer(TokenMatching.CompositeUnit); this.unitFactory = unitSystemDependencyFactory.CreateUnitFactory(this.unitRegistry); this.quantityParser = unitSystemDependencyFactory.CreateParser( this.expressionParser, this.unitFactory); this.quantityOperations = unitSystemDependencyFactory.CreateQuantityOperations(this.unitFactory); this.Dependencies = new UnitSystemDependencies( this.unitRegistry, this.lexicalAnalyzer, this.expressionParser, this.quantityParser, this.unitFactory, this.quantityOperations); this.isInitialized = true; } }); return(this.Dependencies); }
public int RescanUnits() { return(UnitRegistry.ScanDefaultDirectories()); }
public UnitExpressionParserTests() { var unitRegistry = new UnitRegistry(); this.lexicalAnalyzer = A.Fake<ILexicalAnalyzer>(); this.testee = new UnitExpressionParser(unitRegistry, this.lexicalAnalyzer); }
public Dictionary <string, List <string> > GetDeactivationPlan(string unit) { var transaction = UnitRegistry.CreateDeactivationTransaction(unit); return(transaction.Reasoning.ToDictionary(t => t.Key.UnitName, t => t.Value)); }
public bool ReloadUnitFile(string unit) { UnitRegistry.GetUnit(unit).ReloadUnitFile(); return(true); }