예제 #1
0
        public static void Main(string[] args)
        {
            RepConfig config = new RepConfig();
            bool isPeer;
            uint tmpPort = 0;

            /*
             * RepQuoteExample is meant to be run from build_windows\AnyCPU, in
             * either the Debug or Release directory. The required core
             * libraries, however, are in either build_windows\Win32 or
             * build_windows\x64, depending upon the platform.  That location
             * needs to be added to the PATH environment variable for the
             * P/Invoke calls to work.
             */
            try {
                String pwd = Environment.CurrentDirectory;
                pwd = Path.Combine(pwd, "..");
                pwd = Path.Combine(pwd, "..");
                if (IntPtr.Size == 4)
                    pwd = Path.Combine(pwd, "Win32");
                else
                    pwd = Path.Combine(pwd, "x64");
            #if DEBUG
                pwd = Path.Combine(pwd, "Debug");
            #else
                pwd = Path.Combine(pwd, "Release");
            #endif
                pwd += ";" + Environment.GetEnvironmentVariable("PATH");
                Environment.SetEnvironmentVariable("PATH", pwd);
            } catch (Exception e) {
                Console.WriteLine(
                    "Unable to set the PATH environment variable.");
                Console.WriteLine(e.Message);
                return;
            }

            /*  Extract the command line parameters. */
            for (int i = 0; i < args.Length; i++)
            {
                isPeer = false;
                string s = args[i];
                if (s[0] != '-')
                    continue;
                switch (s[1])
                {
                    case 'a':
                        if (i == args.Length - 1)
                            usage();
                        i++;
                        if (args[i].Equals("all"))
                            config.ackPolicy = AckPolicy.ALL;
                        else if (!args[i].Equals("quorum"))
                            usage();
                        break;
                    case 'b':
                        config.bulk = true;
                        break;
                    case 'C':
                        config.startPolicy = StartPolicy.CLIENT;
                        break;
                    case 'h':
                        if (i == args.Length - 1)
                            usage();
                        i++;
                        config.home = args[i];
                        break;
                    case 'l':
                        if (i == args.Length - 1)
                            usage();
                        i++;
                        string[] words = args[i].Split(':');
                        if (words.Length != 2)
                        {
                            Console.Error.WriteLine("Invalid host " +
                                "specification host:port needed.");
                            usage();
                        }
                        try
                        {
                            tmpPort = uint.Parse(words[1]);
                        } catch (InvalidCastException)
                        {
                            Console.Error.WriteLine("Invalid host " +
                                "specification, could not parse port number.");
                            usage();
                        }
                        config.host.Host = words[0];
                        config.host.Port = tmpPort;
                        break;
                    case 'M':
                        config.startPolicy = StartPolicy.MASTER;
                        break;
                    case 'n':
                        if (i == args.Length - 1)
                            usage();
                        i++;
                        try
                        {
                            config.totalSites = uint.Parse(args[i]);
                        } catch (InvalidCastException)
                        {
                            Console.Error.WriteLine(
                            "Unable to parse number of total sites.");
                            usage();
                        }
                        break;
                    case 'p':
                        if (i == args.Length - 1)
                            usage();
                        i++;
                        try
                        {
                            config.priority = uint.Parse(args[i]);
                        } catch (InvalidCastException)
                        {
                            Console.Error.WriteLine("Unable to parse priority.");
                            usage();
                        }
                        break;
                    case 'r':
                    case 'R':
                        if (i == args.Length - 1)
                            usage();
                        if (args[i].Equals("R"))
                            isPeer = true;
                        i++;
                        words = args[i].Split(':');
                        if (words.Length != 2)
                        {
                            Console.Error.WriteLine("Invalid host " +
                                "specification host:port needed.");
                            usage();
                        }
                        try
                        {
                            tmpPort = uint.Parse(words[1]);
                        } catch (InvalidCastException)
                        {
                            Console.Error.WriteLine("Invalid host " +
                                "specification, could not parse port number.");
                            usage();
                        }
                        config.remote.Add(
                            new RemoteSite(words[0], tmpPort, isPeer));
                        break;
                    case 'v':
                        config.verbose = true;
                        break;
                    default:
                        Console.Error.WriteLine(
                            "Unrecognized option: " + args[i]);
                        usage();
                        break;
                }
            }

            /* Error check command line. */
            if (config.host.Host == null || config.home.Length == 0)
                usage();

            RepQuoteExample runner = null;
            try
            {
                runner = new RepQuoteExample();
                runner.init(config);
                runner.doloop();
                runner.terminate();
                runner = null;
            } catch (DatabaseException dbErr)
            {
                Console.Error.WriteLine("Caught an exception during " +
                    "initialization or processing: " + dbErr);
                if (runner != null)
                    runner.terminate();
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            RepConfig config = new RepConfig();
            bool      isPeer;
            uint      tmpPort = 0;

            /*
             * RepQuoteExample is meant to be run from build_windows\AnyCPU, in
             * either the Debug or Release directory. The required core
             * libraries, however, are in either build_windows\Win32 or
             * build_windows\x64, depending upon the platform.  That location
             * needs to be added to the PATH environment variable for the
             * P/Invoke calls to work.
             */
            try {
                String pwd = Environment.CurrentDirectory;
                pwd = Path.Combine(pwd, "..");
                pwd = Path.Combine(pwd, "..");
                if (IntPtr.Size == 4)
                {
                    pwd = Path.Combine(pwd, "Win32");
                }
                else
                {
                    pwd = Path.Combine(pwd, "x64");
                }
#if DEBUG
                pwd = Path.Combine(pwd, "Debug");
#else
                pwd = Path.Combine(pwd, "Release");
#endif
                pwd += ";" + Environment.GetEnvironmentVariable("PATH");
                Environment.SetEnvironmentVariable("PATH", pwd);
            } catch (Exception e) {
                Console.WriteLine(
                    "Unable to set the PATH environment variable.");
                Console.WriteLine(e.Message);
                return;
            }

            /*  Extract the command line parameters. */
            for (int i = 0; i < args.Length; i++)
            {
                isPeer = false;
                string s = args[i];
                if (s[0] != '-')
                {
                    continue;
                }
                switch (s[1])
                {
                case 'a':
                    if (i == args.Length - 1)
                    {
                        usage();
                    }
                    i++;
                    if (args[i].Equals("all"))
                    {
                        config.ackPolicy = AckPolicy.ALL;
                    }
                    else if (!args[i].Equals("quorum"))
                    {
                        usage();
                    }
                    break;

                case 'b':
                    config.bulk = true;
                    break;

                case 'C':
                    config.startPolicy = StartPolicy.CLIENT;
                    break;

                case 'h':
                    if (i == args.Length - 1)
                    {
                        usage();
                    }
                    i++;
                    config.home = args[i];
                    break;

                case 'l':
                    if (i == args.Length - 1)
                    {
                        usage();
                    }
                    i++;
                    string[] words = args[i].Split(':');
                    if (words.Length != 2)
                    {
                        Console.Error.WriteLine("Invalid host " +
                                                "specification host:port needed.");
                        usage();
                    }
                    try
                    {
                        tmpPort = uint.Parse(words[1]);
                    } catch (InvalidCastException)
                    {
                        Console.Error.WriteLine("Invalid host " +
                                                "specification, could not parse port number.");
                        usage();
                    }
                    config.host.Host = words[0];
                    config.host.Port = tmpPort;
                    break;

                case 'M':
                    config.startPolicy = StartPolicy.MASTER;
                    break;

                case 'n':
                    if (i == args.Length - 1)
                    {
                        usage();
                    }
                    i++;
                    try
                    {
                        config.totalSites = uint.Parse(args[i]);
                    } catch (InvalidCastException)
                    {
                        Console.Error.WriteLine(
                            "Unable to parse number of total sites.");
                        usage();
                    }
                    break;

                case 'p':
                    if (i == args.Length - 1)
                    {
                        usage();
                    }
                    i++;
                    try
                    {
                        config.priority = uint.Parse(args[i]);
                    } catch (InvalidCastException)
                    {
                        Console.Error.WriteLine("Unable to parse priority.");
                        usage();
                    }
                    break;

                case 'r':
                case 'R':
                    if (i == args.Length - 1)
                    {
                        usage();
                    }
                    if (args[i].Equals("R"))
                    {
                        isPeer = true;
                    }
                    i++;
                    words = args[i].Split(':');
                    if (words.Length != 2)
                    {
                        Console.Error.WriteLine("Invalid host " +
                                                "specification host:port needed.");
                        usage();
                    }
                    try
                    {
                        tmpPort = uint.Parse(words[1]);
                    } catch (InvalidCastException)
                    {
                        Console.Error.WriteLine("Invalid host " +
                                                "specification, could not parse port number.");
                        usage();
                    }
                    config.remote.Add(
                        new RemoteSite(words[0], tmpPort, isPeer));
                    break;

                case 'v':
                    config.verbose = true;
                    break;

                default:
                    Console.Error.WriteLine(
                        "Unrecognized option: " + args[i]);
                    usage();
                    break;
                }
            }

            /* Error check command line. */
            if (config.host.Host == null || config.home.Length == 0)
            {
                usage();
            }

            RepQuoteExample runner = null;
            try
            {
                runner = new RepQuoteExample();
                runner.init(config);
                runner.doloop();
                runner.terminate();
                runner = null;
            } catch (DatabaseException dbErr)
            {
                Console.Error.WriteLine("Caught an exception during " +
                                        "initialization or processing: " + dbErr);
                if (runner != null)
                {
                    runner.terminate();
                }
            }
        }         /* End main. */