示例#1
0
 public ClientInstance(TcpClient client, Server server, ILogger logger)
 {
     _client = client;
     _server = server;
     _logger = logger;
     _formatter = new BinaryFormatter();
     Id = Guid.NewGuid().ToString();
 }
示例#2
0
 public Conexao(System.Net.Sockets.TcpClient client, Server server)
 {
     this.client = client;
     this.server = server;
     Stream s = client.GetStream();
     writer = new StreamWriter(s);
     reader = new StreamReader(s);
 }
示例#3
0
        static void Main()
        {
            /*Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());*/

            Server s = new Server();
            s.Run();
        }
 private void Start_Click(object sender, EventArgs e)
 {
     // Parse the server's IP address out of the TextBox
     IPAddress ipAddr = IPAddress.Parse("127.0.0.1");
     // Create a new instance of the ChatServer object
     Server mainServer = new Server(ipAddr);
     // Hook the StatusChanged event handler to mainServer_StatusChanged
     Server.StatusChanged += new StatusChangedEventHandler(mainServer_StatusChanged);
     // Start listening for connections
     mainServer.StartListening();
     // Show that we started to listen for connections
     ListBox.AppendText("Monitoring for connections...\r\n");
 }
示例#5
0
        private static void Main()
        {
            var port = int.Parse(ConfigurationManager.AppSettings["port"]);
            var logged = bool.Parse(ConfigurationManager.AppSettings["logged"]);
            ILogger logger;

            if (logged)
            {
                logger = new FileLogger("log.txt");
            }
            else
            {
                logger = new NullObjectLogger();
            }

            var server = new Server(port, logger);
            server.Start();
        }
示例#6
0
        public bool ProcessCharge(string userID, int money)
        {
            EnvInfo  envInfo = Database.GetInstance().GetEnviroment();
            UserInfo manager = Database.GetInstance().GetManager(UserKind.Manager)[0];

            int cash        = money * envInfo.CashRate;
            int serviceCash = cash * envInfo.ChargeGivePercent / 100;

            // 수수료를 관리자에게서 제한다.
            if (GiveCash(manager.Id, -serviceCash) == false)
            {
                return(false);
            }

            if (GiveCash(userID, cash) == false)
            {
                return(false);
            }

            // 고객 충전기록
            ChargeHistoryInfo chargeHistoryInfo = new ChargeHistoryInfo();

            chargeHistoryInfo.Kind        = (int)ChargeKind.Charge;
            chargeHistoryInfo.Cash        = cash;
            chargeHistoryInfo.StartTime   = DateTime.Now;
            chargeHistoryInfo.EndTime     = DateTime.Now;
            chargeHistoryInfo.OwnId       = userID;
            chargeHistoryInfo.ApproveId   = Users.ManagerInfo.Id;
            chargeHistoryInfo.BankAccount = string.Format("收费 {0}", money - money * envInfo.ChargeGivePercent / 100);

            if (Database.GetInstance().AddChargeHistory(chargeHistoryInfo) == false)
            {
                return(false);
            }

            // 관리자 수수료기록
            chargeHistoryInfo = new ChargeHistoryInfo();

            chargeHistoryInfo.Kind        = (int)ChargeKind.Commission;
            chargeHistoryInfo.Cash        = -serviceCash;
            chargeHistoryInfo.StartTime   = DateTime.Now;
            chargeHistoryInfo.EndTime     = DateTime.Now;
            chargeHistoryInfo.OwnId       = manager.Id;
            chargeHistoryInfo.ApproveId   = Users.ManagerInfo.Id;
            chargeHistoryInfo.BankAccount = string.Format("佣金 {0}", money * envInfo.ChargeGivePercent / 100);

            if (Database.GetInstance().AddChargeHistory(chargeHistoryInfo) == false)
            {
                return(false);
            }


            // 2014-02-05: GreenRose
            // 사용자가에 충전상태를 알린다.
            UserInfo userInfo = Database.GetInstance().FindUser(userID);

            Server.GetInstance().Send(userInfo.Socket, NotifyType.Reply_UserInfo, userInfo);

            // 충전상태를 메세지로 보낸다.
            BoardInfo chargeBoardInfo = new BoardInfo();

            chargeBoardInfo.UserId  = Users.ManagerInfo.Id;
            chargeBoardInfo.SendId  = userInfo.Id;
            chargeBoardInfo.Title   = "通知";
            chargeBoardInfo.Content = string.Format("{0}缓冲填充. 您当前的缓存是{1}", cash, userInfo.Cash);
            chargeBoardInfo.Kind    = (int)BoardKind.Letter;

            if (Database.GetInstance().AddBoard(chargeBoardInfo) == false)
            {
                return(false);
            }

            List <BoardInfo> letters = Database.GetInstance().GetLetters(Users.ManagerInfo.Id);

            if (letters == null)
            {
                return(false);
            }

            HomeInfo homeInfo = new HomeInfo();

            homeInfo.Letters = letters;

            for (int i = 0; i < homeInfo.Letters.Count; i++)
            {
                if (homeInfo.Letters[i].Readed != 1)
                {
                    if (homeInfo.Letters[i].SendId == Users.ManagerInfo.Id)
                    {
                        break;
                    }
                    else
                    {
                        UserInfo liveUser = Users.GetInstance().FindUser(homeInfo.Letters[i].SendId);

                        if (liveUser != null)
                        {
                            homeInfo.Notices = Database.GetInstance().GetNotices(liveUser.Id);
                            Server.GetInstance().Send(liveUser.Socket, NotifyType.Reply_NoticeList, homeInfo);
                        }
                    }
                }
            }

            return(true);
        }
示例#7
0
        static void Main(string[] args)
        {
            Server server = new Server();

            server.Run();
        }