示例#1
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);
        }
示例#2
0
        public bool ActivateUnit(string name)
        {
            var transaction = UnitRegistry.CreateActivationTransaction(name);
            var result      = transaction.Execute();

            if (result.Type != ResultType.Success)
            {
                Log.Info($"Activation 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);
        }
示例#3
0
        public Dictionary <string, List <string> > GetActivationPlan(string unit)
        {
            var transaction = UnitRegistry.CreateActivationTransaction(unit);

            return(transaction.Reasoning.ToDictionary(t => t.Key.UnitName, t => t.Value));
        }