예제 #1
0
        static void Main(string[] args)
        {
            try
            {
                ConsoleLogger.LogMessage("AutoCompleteServer");
            #if DEBUG
                ConsoleLogger.LogMessage("DEBUG");
            #endif
            #if VERBOSE
                ConsoleLogger.LogMessage("VERBOSE");
            #endif

                if (args.Length < 2)
                {
                    ConsoleLogger.LogMessage("Usage AutoCompleteServer.exe <in_file> <port> [server_type:1|2]");
                    return;
                }
                IPrefixBuilder wdc = new TriePrefixBuilder();
                string filename = args[0];
                int port = int.Parse(args[1]);
                int servertype = 1;

                if (args.Length >= 3)
                {
                    servertype = int.Parse(args[2]);
                }

                //
                EnumError result=wdc.BuildData(args[0]);
                if (result != EnumError.NoError)
                {
                    ConsoleLogger.LogMessage("Cant build prefix tree: " + result.ToString());
                    return;
                }
                SimplePrefixServer srv = new SimplePrefixServer(port, wdc, (ClientWorkerTypes)servertype);

                result= srv.StartLoop();
                if (result != EnumError.NoError)
                {
                    ConsoleLogger.LogMessage("Server error: " + result.ToString());
                }
            }
            catch (Exception ex)
            {
                ConsoleLogger.LogMessage("Error: " + ex.ToString());
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            EnumError result = EnumError.NoError;
            try
            {
                IPrefixBuilder wdc = null;

                if (args.Length > 0)
                {
                    if (args.Length != 3)
                    {
                        ConsoleLogger.LogMessage("\r\nUsage AutoCompleteConsole.exe\r\n\r\nor\r\n\r\nUsage AutoCompleteConsole.exe [prefixbuilder:1|2] <in_file> <out_file>");
                        return;
                    }
                    switch (int.Parse(args[0]))
                    {
                        case (int)EnumPrefixBuilder.Simple:
                            {
                                wdc = new SimplePrefixBuilder();
                                break;
                            }
                        case (int)EnumPrefixBuilder.Trie:
                            {
                                wdc = new TriePrefixBuilder();
                                break;
                            }
                        default:
                            {
                                wdc = new TriePrefixBuilder();
                                break;
                            }

                    }
                    wdc.Init(10);

                    result = wdc.DoBuildAndUseFiles(args[1], args[2]);
            #if DEBUG
                    ConsoleLogger.LogMessage("Press Enter to continue");
                    Console.Read();
            #endif

                }
                else
                {
                    wdc = new TriePrefixBuilder();
                    result = wdc.UseDataConsole();
                }
                if (result != EnumError.NoError)
                {
                    ConsoleLogger.LogMessage("Code return with error: result: " + result.ToString());
                }
            }
            catch (IOException ioe)
            {
                ConsoleLogger.LogMessage("Ошибка ввода/вывода " + ioe.Message);
            }
            catch (Exception ex)
            {
                ConsoleLogger.LogMessage("Error: "+ex.Message);
            }
        }