Ejemplo n.º 1
0
        public override void Init()
        {
            cida = GetCom <ConsoleInputDataAnalysis>();
            dac  = GetCom <DataAnalysisContainer>();

            //cida.OnCommand("create", (ps) =>
            //{
            //    if (ps == null || ps.Length != 2)
            //        return "parameter error";

            //    if (ps[0] == "db")
            //    {
            //        if (dac != null)
            //            return "only a new database can be create";

            //        CreateDatabase(DbName);
            //    }
            //    else
            //        return "parameter error";

            //    return "success!";
            //});

            cida.OnCommand("update", (ps) =>
            {
                if (dac == null)
                {
                    return("you have to create a new database and then table will automatically generate");
                }

                UpdateTable();
                return("success!");
            });

            cida.OnCommand("cusers", (ps) =>
            {
                var cnt = CreateUserTable();
                return(cnt + " users");
            });

            //cida.OnCommand("drop", (ps) =>
            //{
            //    if (ps == null || ps.Length != 2)
            //        return "parameter error";

            //    if (ps[0] == "db")
            //    {
            //        DropDatabase(ps[1]);
            //    }
            //    else
            //        return "parameter error";

            //    return "success!";
            //});

            CreateTable();
        }
Ejemplo n.º 2
0
        public void CreateTable()
        {
            dac = new DataAnalysisContainer(new MySqlDbPersistence <DataAnalysis, string>(
                                                DbName, "127.0.0.1", "root", "123456",
                                                @"Replays", "CREATE TABLE Replays(ID VARCHAR(100) BINARY, Data MediumBlob,"
                                                + "Date DATETIME, Length VARCHAR(20),"
                                                + "User1 VARCHAR(100), User2 VARCHAR(100),"
                                                + "UserName1 VARCHAR(100), UserName2 VARCHAR(100),"
                                                + "Winner VARCHAR(100),"
                                                + "DogCount1 INT, DogCount2 INT,"
                                                + "SoldierCount1 INT, SoldierCount2 INT,"
                                                + "FirebatCount1 INT, FirebatCount2 INT,"
                                                + "MagSpiderCount1 INT, MagSpiderCount2 INT,"
                                                + "GhostCount1 INT, GhostCount2 INT,"
                                                + "RobotCount1 INT, RobotCount2 INT,"
                                                + "TankCount1 INT, TankCount2 INT,"
                                                + "ThorCount1 INT, ThorCount2 INT,"
                                                + "HammerCount1 INT, HammerCount2 INT,"
                                                + "SoldierCarrierCount1 INT, SoldierCarrierCount2 INT,"
                                                + "WarplaneCount1 INT, WarplaneCount2 INT,"
                                                + "MotherShipCount1 INT, MotherShipCount2 INT,"
                                                + "PRIMARY KEY(ID ASC));",
                                                new string[]
            {
                "Date", "Length",
                "User1", "User2",
                "UserName1", "UserName2",
                "Winner",
                "DogCount1", "DogCount2",
                "SoldierCount1", "SoldierCount2",
                "FirebatCount1", "FirebatCount2",
                "MagSpiderCount1", "MagSpiderCount2",
                "GhostCount1", "GhostCount2",
                "RobotCount1", "RobotCount2",
                "TankCount1", "TankCount2",
                "ThorCount1", "ThorCount2",
                "HammerCount1", "HammerCount2",
                "SoldierCarrierCount1", "SoldierCarrierCount2",
                "WarplaneCount1", "WarplaneCount2",
                "MotherShipCount1", "MotherShipCount2",
            }, (da) =>
            {
                var buff = new WriteBuffer();
                da.Serialize(buff);
                return(buff.Data);
            }, (data) =>
            {
                var rb = new RingBuffer(data);
                var da = new DataAnalysis();
                da.Deserialize(rb);
                return(da);
            }, (DataAnalysis da, string col) =>
            {
                switch (col)
                {
                case "Date":
                    return(da.Info.Date);

                case "Length":
                    return(da.Info.Length);

                case "User1":
                    return(da.Info.User1);

                case "User2":
                    return(da.Info.User2);

                case "UserName1":
                    return(da.Info.UserName1);

                case "UserName2":
                    return(da.Info.UserName2);

                case "Winner":
                    return(da.Info.Winner);

                case "DogCount1":
                    return(da.Info.DogCount1);

                case "DogCount2":
                    return(da.Info.DogCount2);

                case "SoldierCount1":
                    return(da.Info.SoldierCount1);

                case "SoldierCount2":
                    return(da.Info.SoldierCount2);

                case "FirebatCount1":
                    return(da.Info.FirebatCount1);

                case "FirebatCount2":
                    return(da.Info.FirebatCount2);

                case "MagSpiderCount1":
                    return(da.Info.MagSpiderCount1);

                case "MagSpiderCount2":
                    return(da.Info.MagSpiderCount2);

                case "GhostCount1":
                    return(da.Info.GhostCount1);

                case "GhostCount2":
                    return(da.Info.GhostCount2);

                case "RobotCount1":
                    return(da.Info.RobotCount1);

                case "RobotCount2":
                    return(da.Info.RobotCount2);

                case "TankCount1":
                    return(da.Info.TankCount1);

                case "TankCount2":
                    return(da.Info.TankCount2);

                case "ThorCount1":
                    return(da.Info.ThorCount1);

                case "ThorCount2":
                    return(da.Info.ThorCount2);

                case "HammerCount1":
                    return(da.Info.HammerCount1);

                case "HammerCount2":
                    return(da.Info.HammerCount2);

                case "SoldierCarrierCount1":
                    return(da.Info.SoldierCarrierCount1);

                case "SoldierCarrierCount2":
                    return(da.Info.SoldierCarrierCount2);

                case "WarplaneCount1":
                    return(da.Info.WarplaneCount1);

                case "WarplaneCount2":
                    return(da.Info.WarplaneCount2);

                case "MotherShipCount1":
                    return(da.Info.MotherShipCount1);

                case "MotherShipCount2":
                    return(da.Info.MotherShipCount2);
                }
                return(null);
            }));
            cida.Srv.Add("DataAnalysisContainer", dac);
        }