Example #1
0
        /// <summary>
        /// 恢复数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonRestore_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:";//注意这里写路径时要用c:而不是c: 
            openFileDialog.Filter           = "所有文件|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex      = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string fileName = openFileDialog.FileName;

                IniAc  iniFile  = new IniAc();
                string user     = iniFile.ReadValue("DBMS", "user");
                string pwd      = iniFile.ReadValue("DBMS", "pwd");
                string database = iniFile.ReadValue("DBMS", "database");

                string cmdStr = "/c mysql " + " --user="******" --password="******" " + "bbcc" + " " + " < " + fileName;

                try
                {
                    System.Diagnostics.Process.Start("cmd", cmdStr);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #2
0
        private void buttonBackupSettings_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDlg = new SaveFileDialog();

            saveFileDlg.InitialDirectory = "c:";//注意这里写路径时要用c:而不是c: 
            saveFileDlg.Filter           = "所有文件|*.*";
            saveFileDlg.RestoreDirectory = true;

            if (saveFileDlg.ShowDialog() == DialogResult.OK)
            {
                IniAc  iniFile  = new IniAc();
                string user     = iniFile.ReadValue("DBMS", "user");
                string pwd      = iniFile.ReadValue("DBMS", "pwd");
                string database = iniFile.ReadValue("DBMS", "database");
                string tables   = iniFile.ReadValue("BACKUP", "tables");

                string fileName = saveFileDlg.FileName;
                string cmdStr   = "/c mysqldump " + " -u " + user +
                                  " -p" + pwd + " " + database + " " + tables + " " +
                                  " > " + fileName;

                try
                {
                    System.Diagnostics.Process.Start("cmd", cmdStr);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #3
0
        /// <summary>
        /// 加载ini文件中的服务器信息
        /// </summary>
        private void LoadIni()
        {
            IniAc ini = new IniAc();

            ipAddrStr = ini.ReadValue("NET", "ip");

            string portStr = ini.ReadValue("NET", "port");

            portNumber = System.Convert.ToInt32(portStr);
        }
Example #4
0
        /// <summary>
        /// 加载ini文件中的服务器信息
        /// </summary>
        private void LoadIni()
        {
            IniAc ini = new IniAc();

            dbserver = ini.ReadValue("DBMS", "server");
            dbuser   = ini.ReadValue("DBMS", "user");
            dbpwd    = ini.ReadValue("DBMS", "pwd");
            database = ini.ReadValue("DBMS", "database");
            info     = ini.ReadValue("DBMS", "info");
            dbport   = ini.ReadValue("DBMS", "port");
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            IniAc  ini  = new IniAc();
            string ip   = this.textBoxIP.Text;
            string port = this.textBoxcode.Text;

            ini.WritValue("NET", "ip", ip);
            ini.WritValue("NET", "port", port);

            this.Close();
        }
        private string GetHttp()
        {
            string htp;
            IniAc  ini       = new IniAc();
            string ipAddrStr = ini.ReadValue("NET", "ip");

            string portStr = ini.ReadValue("NET", "port");

            htp = "http://" + ipAddrStr + "/";

            return(htp);
        }
Example #7
0
        static void Main()
        {
            while (true)
            {
                try
                {
                    Console.WriteLine("Begin to Start TcpSvr SVN...");

                    TestTcpSvr tts = new TestTcpSvr();
                    tts.InitSys();
                    #region 定时器事件
                    System.Timers.Timer aTimer = new System.Timers.Timer();
                    aTimer.Elapsed += new ElapsedEventHandler(TimeEvent);
                    aTimer.Interval = 5 * 1000;    //配置文件中配置的秒数
                    aTimer.Enabled  = true;
                    #endregion
                    string ipaddr = getLocalIP();
                    Console.WriteLine(ipaddr);
                    ushort portNumber = 5632;
                    IniAc  ini        = new IniAc();
                    ipaddr = ini.ReadValue("NET", "ip");
                    Console.WriteLine(ipaddr);
                    string portStr = ini.ReadValue("NET", "port");
                    portNumber = System.Convert.ToUInt16(portStr);

                    //TcpSvr svr = new TcpSvr(9050,4);//默认使用Encoding.Default编码方式
                    TcpSvr svr = new TcpSvr(IPAddress.Parse(ipaddr), 5632, 80, new Coder(Coder.EncodingMothord.Unicode), "D:\\MyVidio");

                    svr.Resovlver = new DatagramResolver("]");//0x5d

                    //定义服务器的4个事件

                    //服务器满
                    svr.ServerFull += new NetEvent(tts.ServerFull);

                    //新客户端连接
                    svr.ClientConn += new NetEvent(tts.ClientConn);

                    //客户端关闭
                    svr.ClientClose += new NetEvent(tts.ClientClose);

                    //接收到数据
                    svr.RecvData += new NetEvent(tts.RecvData);

                    //  svr.LogIn += new NetEvent(this.LogIn);

                    svr.Start();

                    Console.WriteLine("Server is listen...{0}",
                                      svr.ServerSocket.LocalEndPoint.ToString());
                    //命令控制循环
                    #region

                    while (true)
                    {
                        Console.Write(">");

                        string cmd = Console.ReadLine();

                        //退出测试程序
                        if (cmd.ToLower() == "exit")
                        {
                            break;
                        }

                        //停止服务器程序
                        if (cmd.ToLower() == "stop")
                        {
                            svr.Stop();

                            Console.WriteLine("Server is Stop.");

                            continue;
                        }

                        //运行服务器程序
                        if (cmd.ToLower() == "start")
                        {
                            svr.Start();

                            Console.WriteLine("Server is listen...{0}",
                                              svr.ServerSocket.LocalEndPoint.ToString());

                            continue;
                        }

                        //察看服务器在线客户端数目和容量
                        if (cmd.ToLower() == "count")
                        {
                            Console.WriteLine("Current count of Client is {0}/{1}",
                                              svr.SessionCount, svr.Capacity);
                            continue;
                        }

                        //发送数据到客户端格式:send [Session] [stringData]
                        if (cmd.ToLower().IndexOf("send") != -1)
                        {
                            cmd = cmd.ToLower();

                            string[] para = cmd.Split(' ');

                            if (para.Length == 3)
                            {
                                Session client = (Session)svr.SessionTable[new SessionId(int.Parse
                                                                                             (para[1]))];

                                if (client != null)
                                {
                                    svr.SendText(client, para[2]);
                                }
                                else
                                {
                                    Console.WriteLine("The Session is Null");
                                }
                            }
                            else
                            {
                                Console.WriteLine("Error Command");
                            }

                            continue;
                        }

                        //从服务器上踢掉一个客户端
                        if (cmd.ToLower().IndexOf("kick") != -1)
                        {
                            cmd = cmd.ToLower();

                            string[] para = cmd.Split(' ');

                            if (para.Length == 2)
                            {
                                Session client = (Session)svr.SessionTable[new SessionId(int.Parse
                                                                                             (para[1]))];

                                if (client != null)
                                {
                                    svr.CloseSession(client);
                                }
                                else
                                {
                                    Console.WriteLine("The Session is Null");
                                }
                            }
                            else
                            {
                                Console.WriteLine("Error command");
                            }

                            continue;
                        }

                        //列出服务器上所有的客户端信息
                        if (cmd.ToLower() == "list")
                        {
                            int i = 0;

                            foreach (Session Client in svr.SessionTable.Values)
                            {
                                if (Client != null)
                                {
                                    i++;
                                    string info = string.Format("{0} Client:{1} connected server Session:{2}. Socket Handle:{3}",
                                                                i,
                                                                Client.ClientSocket.RemoteEndPoint.ToString(),
                                                                Client.ID,
                                                                Client.ClientSocket.Handle);

                                    Console.WriteLine(info);
                                }
                                else
                                {
                                    i++;

                                    string info = string.Format("{0} null Client", i);
                                    Console.WriteLine(info);
                                }
                            }

                            continue;
                        }

                        Console.WriteLine("Unkown Command");
                    }//end of while
                    #endregion
                    Console.WriteLine("End service");
                }
                catch (Exception ex)
                {
                    string    sql      = "UPDATE device SET Device_Status = 0,Sockets = ''";
                    IDataBase database = MySqlDataBase.getInstance();
                    database.Open();
                    database.ExcuteNonQuery(sql);
                    database.Close();

                    Console.WriteLine(ex.ToString());
                }
            }
        }