Ejemplo n.º 1
0
        public static void ClassInitialize(TestContext value)
        {
            PlatformUtilities.RegisterImplementations();
            PlatformUtilities.GetImplementation <IPlatformInitialization>().Initialize();
            UnitRegistry.InitializeTypes();
            UnitRegistry.ScanDefaultDirectories();

            File.WriteAllText(path, contents);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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)));
        }
Ejemplo n.º 6
0
 public int RescanUnits()
 {
     return(UnitRegistry.ScanDefaultDirectories());
 }