| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | namespace IceBox; |
| | 4 | |
|
| | 5 | | public static class Server |
| | 6 | | { |
| | 7 | | private static void usage() |
| | 8 | | { |
| 0 | 9 | | Console.Error.WriteLine("Usage: iceboxnet [options] --Ice.Config=<file>\n"); |
| 0 | 10 | | Console.Error.WriteLine( |
| 0 | 11 | | "Options:\n" + |
| 0 | 12 | | "-h, --help Show this message.\n" + |
| 0 | 13 | | "-v, --version Display the Ice version."); |
| 0 | 14 | | } |
| | 15 | |
|
| | 16 | | private static int run(Ice.Communicator communicator, string[] args) |
| | 17 | | { |
| | 18 | | const string prefix = "IceBox.Service."; |
| 1 | 19 | | Ice.Properties properties = communicator.getProperties(); |
| 1 | 20 | | Dictionary<string, string> services = properties.getPropertiesForPrefix(prefix); |
| | 21 | |
|
| 1 | 22 | | var argSeq = new List<string>(args); |
| 1 | 23 | | foreach (KeyValuePair<string, string> pair in services) |
| | 24 | | { |
| 1 | 25 | | string name = pair.Key[prefix.Length..]; |
| 0 | 26 | | argSeq.RemoveAll(v => v.StartsWith($"--{name}", StringComparison.Ordinal)); |
| | 27 | | } |
| | 28 | |
|
| 1 | 29 | | foreach (string arg in args) |
| | 30 | | { |
| 0 | 31 | | if (arg == "-h" || arg == "--help") |
| | 32 | | { |
| 0 | 33 | | usage(); |
| 0 | 34 | | return 0; |
| | 35 | | } |
| 0 | 36 | | else if (arg == "-v" || arg == "--version") |
| | 37 | | { |
| 0 | 38 | | Console.Out.WriteLine(Ice.Util.stringVersion()); |
| 0 | 39 | | return 0; |
| | 40 | | } |
| | 41 | | else |
| | 42 | | { |
| 0 | 43 | | Console.Error.WriteLine("IceBox.Server: unknown option `" + arg + "'"); |
| 0 | 44 | | usage(); |
| 0 | 45 | | return 1; |
| | 46 | | } |
| | 47 | | } |
| | 48 | |
|
| 1 | 49 | | var serviceManagerImpl = new ServiceManagerI(communicator, args); |
| 1 | 50 | | return serviceManagerImpl.run(); |
| | 51 | | } |
| | 52 | |
|
| | 53 | | public static int Main(string[] args) |
| | 54 | | { |
| 1 | 55 | | int status = 0; |
| | 56 | |
|
| 1 | 57 | | var initData = new Ice.InitializationData |
| 1 | 58 | | { |
| 1 | 59 | | properties = new Ice.Properties(ref args, new Ice.Properties(["IceBox"])) |
| 1 | 60 | | }; |
| 1 | 61 | | initData.properties.setProperty("Ice.Admin.DelayCreation", "1"); |
| | 62 | |
|
| | 63 | | try |
| | 64 | | { |
| 1 | 65 | | using Ice.Communicator communicator = Ice.Util.initialize(initData); |
| 1 | 66 | | Console.CancelKeyPress += (sender, eventArgs) => |
| 1 | 67 | | { |
| 0 | 68 | | eventArgs.Cancel = true; |
| 0 | 69 | | communicator.shutdown(); |
| 0 | 70 | | }; |
| | 71 | |
|
| 1 | 72 | | status = run(communicator, args); |
| 1 | 73 | | } |
| 0 | 74 | | catch (Exception ex) |
| | 75 | | { |
| 0 | 76 | | Console.Error.WriteLine(ex); |
| 0 | 77 | | status = 1; |
| 0 | 78 | | } |
| | 79 | |
|
| 1 | 80 | | return status; |
| | 81 | | } |
| | 82 | | } |