using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ourmsg.Server;
using IMLibrary.Server;

namespace OurmsgServer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        RouterServer routerServer = new  RouterServer(5555);//消息路由器
        AgentServer agentServer= new  AgentServer("127.0.0.1", 5555, "1", 8989);//用户登录服务器
        P2PServer  P2pServer = new P2PServer(14343);//P2P服务器
        RegisterUserServer registerUserServer = new RegisterUserServer();//用户注册服务器
        ImageFileServer imageFileServer = new ImageFileServer(90, 90);//图片服务器
        //FTPServer ftpServer = new FTPServer(@"d:\Ftp\", 21);//Ftp文件服务器
        OfflineFileServer offlineFileServer = new OfflineFileServer(88);//离线文件服务器
        OfflineMessageServer offlineMessageServer = new OfflineMessageServer();//离线消息存取服务器
        private void butStart_Click(object sender, EventArgs e)
        { 
            IMLibrary.DBAccess.SetSQLConnection("127.0.0.1", "ourmsg", "sa", "liggyi");//设置sql server数据库连接信息
            //IMLibrary.DBAccess.SetMySQLConnection("127.0.0.1", "ourmsg", "root", "admin");//设置Mysql数据库连接信息
            IMLibrary.DBAccess.DBtype = IMLibrary.DBAccess.DBType.SqlServer;//设置要使用的数据库类型
            
            butStart.Enabled = false;
            butStop.Enabled = true;
            offlineMessageServer.Start();//离线消息服务先启动 
            routerServer.Start();
            agentServer.Start();
            P2pServer.Start();
            //ftpServer.Start();
            registerUserServer.Start(8080);
            imageFileServer.Start();
            offlineFileServer.Start();
            Console.WriteLine("Start OK!");
        }

        private void butStop_Click(object sender, EventArgs e)
        {
            butStart.Enabled = true;
            butStop.Enabled = false;
            routerServer.Stop();
            agentServer.Stop();
            P2pServer.Stop();
            registerUserServer.Stop();
            //ftpServer.Stop();
            imageFileServer.Stop();
            offlineFileServer.Stop();//离线消息服务后停止
            offlineMessageServer.Stop();
            Console.WriteLine("Stop OK!");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
             
        }
    }
}
