summaryrefslogtreecommitdiff
path: root/csharp/src/IceBox/Server.cs
blob: b777151cc5b7aea2296f9a1269214fa965f92580 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

using System;
using System.Collections.Generic;

namespace IceBox
{

public class Server
{
    private static void usage()
    {
        Console.Error.WriteLine("Usage: iceboxnet [options] --Ice.Config=<file>\n");
        Console.Error.WriteLine(
            "Options:\n" +
            "-h, --help           Show this message.\n"
        );
    }

    public static int Main(string[] args)
    {
        int status = 0;
        List<string> argSeq = new List<string>();
        const string prefix = "IceBox.Service.";

        Ice.InitializationData initData = new Ice.InitializationData();
        initData.properties = Ice.Util.createProperties();
        initData.properties.setProperty("Ice.Admin.DelayCreation", "1");

        try
        {
            using(var communicator = Ice.Util.initialize(ref args, initData))
            {
                Console.CancelKeyPress += (sender, eventArgs) =>
                {
                    eventArgs.Cancel = true;
                    communicator.shutdown();
                };

                Ice.Properties properties = communicator.getProperties();
                Dictionary<string, string> services = properties.getPropertiesForPrefix(prefix);

                foreach(string arg in argSeq)
                {
                    bool valid = false;
                    foreach(KeyValuePair<string, string> pair in services)
                    {
                        string name = pair.Key.Substring(prefix.Length);
                        if(arg.StartsWith("--" + name, StringComparison.CurrentCulture))
                        {
                            valid = true;
                            break;
                        }
                    }
                    if(!valid)
                    {
                        if(arg.Equals("-h") || arg.Equals("--help"))
                        {
                            usage();
                            status = 1;
                            break;
                        }
                        else if(arg.Equals("-v") || arg.Equals("--version"))
                        {
                            Console.Out.WriteLine(Ice.Util.stringVersion());
                            status = 1;
                            break;
                        }
                        else
                        {
                            Console.Error.WriteLine("IceBox.Server: unknown option `" + arg + "'");
                            usage();
                            status = 1;
                            break;
                        }
                    }
                }

                ServiceManagerI serviceManagerImpl = new ServiceManagerI(communicator, argSeq.ToArray());
                status = serviceManagerImpl.run();
            }
        }
        catch(Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        return status;
    }
}
}