示例#1
0
        public static void Main(string[] args)
        {
            if (args.Length == 1)
            {
                foreach (string str in System.IO.File.ReadAllLines(args[0]))
                {
                    initial.Enqueue(str);
                }
            }
            SortedDictionary <int, System.Threading.Thread> jobs = new SortedDictionary <int, System.Threading.Thread> ();

            Modifiers.Add("async");
            //BD2.Core.Database DB = new BD2.Core.Database ();
            string command;

            do
            {
                command = Query("Command>");
                if (command == null)
                {
                    return;
                }
                OffsetedArray <string> commandparts = command.Split(' ');
                string[] CommandParts = (string[])((string[])commandparts).Clone();
                commandparts.Offset = ExtractModifiers(CommandParts);
                SortedSet <string> CommandModifiers = new SortedSet <string> (commandparts.GetStrippedPart());
                switch (CommandParts [0])
                {
                case "Open":
                {
                    UR = new UserRepository(new DatabasePath(Query("path")), new UserRepositoryConfiguration());
                }
                break;

                case "CreateAdmin":
                {
                    string name     = Query("name");
                    string password = Query("Password");
                    string pepper   = Query("Pepper");
                    UR.CreateUser(name, password, pepper, null);
                }
                break;

                case "Create":
                {
                    string name     = Query("name");
                    string password = Query("Password");
                    string pepper   = (Query("Pepper"));
                    byte[] parentID;
                    parentID = HexStringToByteArray(Query("Parent").Replace(" ", "").Replace(":", ""));
                    UR.CreateUser(name, password, pepper, parentID);
                }
                break;

                case "List":
                    foreach (var U in UR.GetUsers())
                    {
                        Console.WriteLine("{0}:{1}", U.Key.ToHexadecimal(), U.Value);
                    }
                    break;

                case "Exit":
                    return;

                default:
                    Console.Error.WriteLine(string.Format("{0} is not a valid command.", CommandParts [0]));
                    break;
                }
            } while(true);
        }
示例#2
0
        public static void Main(string[] args)
        {
            System.Threading.ThreadPool.SetMinThreads(64, 16);
            if (args.Length == 1)
            {
                foreach (string str in System.IO.File.ReadAllLines(args[0]))
                {
                    initial.Enqueue(str);
                }
            }
            SortedDictionary <int, System.Threading.Thread> jobs = new SortedDictionary <int, System.Threading.Thread> ();

            repositories = new SortedDictionary <string, ChunkRepository> ();
            Modifiers.Add("async");
            //BD2.Core.Database DB = new BD2.Core.Database ();
            string command;

            do
            {
                command = Query("Command>");
                if (command == null)
                {
                    return;
                }
                OffsetedArray <string> commandparts = command.Split(' ');
                string[] CommandParts = (string[])((string[])commandparts).Clone();
                commandparts.Offset = ExtractModifiers(CommandParts);
                SortedSet <string> CommandModifiers = new SortedSet <string> (commandparts.GetStrippedPart());
                switch (CommandParts [0])
                {
                case "Run":
                    if (CommandParts.Length < 2)
                    {
                        Console.Error.WriteLine("Run requires at least two parameter: [async] Run <Type>");
                        continue;
                    }
                    switch (CommandParts [1])
                    {
                    case "Daemon":
                        if (CommandParts.Length < 3)
                        {
                            Console.Error.WriteLine("Run Daemon requires at least one parameter: [async] Run Daemon <Daemon Type>");
                            continue;
                        }
                        switch (CommandParts [2])
                        {
                        case "SQL":
                            if (CommandModifiers.Contains("async"))
                            {
                                System.Threading.Thread t_runSourceDaemon = new System.Threading.Thread(RunSourceDaemon);
                                jobs.Add(t_runSourceDaemon.ManagedThreadId, t_runSourceDaemon);
                                t_runSourceDaemon.Start();
                            }
                            else
                            {
                                RunSourceDaemon();
                            }
                            break;                            //source

                        default:
                            Console.Error.WriteLine("Invalid Daemon Type.");
                            break;
                        }
                        break;
                    }
                    break;                    //daemon

                case "Open":
                    if (CommandParts.Length < 2)
                    {
                        Console.Error.WriteLine("Open requires at least one parameter: [async] Open <Repository Type>");
                        continue;
                    }
                    switch (CommandParts [1])
                    {
                    case "LevelDB":
                        if (CommandParts.Length < 4)
                        {
                            Console.Error.WriteLine("LevelDB repository requires at least two parameter: [async] Open File <Repository Nick> <Repository> <Path>");
                            continue;
                        }
                        if (CommandModifiers.Contains("async"))
                        {
                            System.Threading.Thread t_addrepo = new System.Threading.Thread(() => {
                                OpenLevelDBRepository(CommandParts);
                            });
                            t_addrepo.Start();
                            Console.WriteLine("[{0}]", t_addrepo.ManagedThreadId);
                        }
                        else
                        {
                            OpenLevelDBRepository(CommandParts);
                        }
                        break;                        //file

                    case "Network":
                        if (CommandParts.Length < 5)
                        {
                            Console.Error.WriteLine("Network repository requires at least three parameter: [async] Open File <Repository Nick> <Repository> <IPAddress> <Port>");
                            continue;
                        }
                        if (CommandModifiers.Contains("async"))
                        {
                            System.Threading.Thread t_addrepo = new System.Threading.Thread(() => {
                                OpenNetworkRepository(CommandParts);
                            });
                            t_addrepo.Start();
                            Console.WriteLine("[{0}]", t_addrepo.ManagedThreadId);
                        }
                        else
                        {
                            OpenNetworkRepository(CommandParts);
                        }

                        break;

                    case "Socket":
                        break;
                    }
                    break;

                case "Close":
                    break;

                case "Execute":

                    break;

                case "Convert":
                    if (CommandParts.Length < 2)
                    {
                        Console.Error.WriteLine("Open requires at least one parameter: [async] Open <Repository Type> [Parameters]");
                        continue;
                    }
                    switch (CommandParts [1])
                    {
                    case "Table":
                        string daemonIPAddress            = Query("Daemon IP Address");
                        string DaemonPort                 = Query("Daemon Port");
                        System.Net.IPAddress         IPA  = System.Net.IPAddress.Parse(daemonIPAddress);
                        System.Net.IPEndPoint        IPEP = new System.Net.IPEndPoint(IPA, int.Parse(DaemonPort));
                        System.Net.Sockets.TcpClient TC   = new  System.Net.Sockets.TcpClient();
                        TC.Connect(IPEP);
                        System.Net.Sockets.NetworkStream NS = TC.GetStream();
                        BD2.Daemon.StreamHandler         SH = new BD2.Daemon.StreamHandler(NS);
                        BD2.Daemon.ObjectBus             OB = new BD2.Daemon.ObjectBus(SH);
                        BD2.Daemon.ServiceManager        SM = new BD2.Daemon.ServiceManager(OB);
                        SM.AnounceReady();
                        SM.WaitForRemoteReady();

                        Guid serviceType_SQL = Guid.Parse("57ce8883-1010-41ec-96da-41d36c64d65d");
                        var  RS = SM.EnumerateRemoteServices();
                        BD2.Daemon.ServiceAnnounceMessage TSA = null;
                        foreach (var SA in RS)
                        {
                            if (SA.Type == serviceType_SQL)
                            {
                                TSA = SA;
                            }
                        }
                        if (TSA == null)
                        {
                            Console.WriteLine("Required services for Table Conversion not found on remote host.");
                        }
                        BD2.Daemon.TransparentAgent agent =
                            (BD2.Daemon.TransparentAgent)
                            SM.RequestService(TSA, (new BD2.Conv.Daemon.MSSQL.ServiceParameters(Query("Connection String"))).Serialize(),
                                              BD2.Daemon.TransparentAgent.CreateAgent, null);
                        Client CL = new Client(agent, repositories [Query("Repository Name")], Query("Database Name"));
                        CL.Convert();
                        break;
                    }
                    break;

                case "await":
                    string jobID    = commandparts [1];
                    int    intJobID = int.Parse(jobID);
                    jobs [intJobID].Join();
                    break;

                case "Exit":
                    return;

                default:
                    Console.Error.WriteLine(string.Format("{0} is not a valid command.", CommandParts [0]));
                    break;
                }
            } while(true);
        }