Skip to content

ezverev/Mono.Helpers

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mono.Helpers

Extensions for Mono/Linux: processes, signals, services, daemons and etc.

Install Daemons

var installSettings = new LinuxServiceSettings
                      {
                          ServiceName = "MyAppService",
                          DisplayName = "Short Description",
                          Description = "Full Description",
                          ServiceExe = "/home/user1/MyApp/MyApp.exe",
                          ServiceArgs = "Arg1 Arg2 Arg3",
                          Username = "user1",
                          Dependencies = new[] { "$local_fs", "$network", "$remote_fs", "$syslog" }
                      };

System.Configuration.Install.Installer installer = new LsbLinuxHostInstaller(installSettings);

var stateSaver = new Hashtable();

installer.Install(stateSaver);

installer.Uninstall(stateSaver);

Start/Stop Daemons

var service = LsbLinuxServiceController.GetService("MyAppService");
service.Start();
service.Stop();

Signals

var signalListener = new LinuxSignalListener();
signalListener.Subscribe(Signum.SIGTERM, () => Console.WriteLine("Termination signal"));
signalListener.Subscribe(Signum.SIGINT, () => Console.WriteLine("Terminal interrupt signal"));
signalListener.Listen();

Processes

foreach (var process in LinuxProcess.GetProcesses())
{
    Console.WriteLine("PID={0}, Name={1}, State={2}, CommandLine={3}",
        process.Id, process.ProcessName, process.ProcessState, process.CommandLine);
}

IPC

// Server
using (var server = new FileChannelServer("MathService"))
{
    server.Subscribe("Add", (dynamic args) =>  args.Left + args.Right);
    server.Subscribe("Sub", (dynamic args) =>  args.Left - args.Right);
    server.Subscribe("Mul", (dynamic args) =>  args.Left * args.Right);
    server.Subscribe("Div", (dynamic args) =>  args.Left / args.Right);

    server.Start();

    Console.ReadLine();
}

// Client
using (var client = new FileChannelClient("MathService"))
{
    var addResult = client.Invoke("Add", new { Left = 2, Right = 2 });
    Console.WriteLine("2 + 2 = {0}", addResult); 

    var subResult = client.Invoke("Sub", new { Left = 5, Right = 2 });
    Console.WriteLine("5 - 2 = {0}", subResult);

    var mulResult = client.Invoke("Mul", new { Left = 3, Right = 2 });
    Console.WriteLine("3 * 2 = {0}", mulResult);

    var divResult = client.Invoke("Div", new { Left = 6, Right = 2 });
    Console.WriteLine("6 / 2 = {0}", divResult);
}

NuGet

https://www.nuget.org/packages/Mono.Helpers/

Install-Package Mono.Helpers

Notes

Currently Mono.Helpers code is tested only on Ubuntu 14.04.2 LTS.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.5%
  • Batchfile 0.5%