Пример #1
0
        private string get_computerlist(string user)
        {
            string result_s = "{ \"computer\": [] }";

            new ServerClass().removeFailList(); //清除已下线客户端
            List <ServerClass.serverUser> all = ServerClass.allServerList;

            foreach (ServerClass.serverUser only in all)
            {
                //检测用户
                if (only.user != user)
                {
                    continue;
                }

                List <ServerClass.serverComputer> all_computer = only.server; //循环列表
                List <object> result_all = new List <object>();               //需要返回的列表

                //循环获取在线数量
                for (int i = all_computer.Count - 1; i >= 0; i--)
                {
                    ServerClass.serverComputer only_computer = all_computer[i];
                    object result_a = new { name = only_computer.name };
                    result_all.Add(result_a);
                }

                /* 设置result */
                object result_o = new { computer = result_all };
                result_s = JsonConvert.SerializeObject(result_o).ToString();
            }
            return(result_s);
        }
Пример #2
0
 private bool addServerData(ServerClass.serverUser server)
 {
     try
     {
         MessageClass mess = new MessageClass();
         List <ServerClass.serverUser> allServerList = ServerClass.allServerList;
         for (int i = 0; i < allServerList.Count; i++)
         {
             string user = allServerList[i].user;
             if (server.user.Equals(user))
             {
                 List <ServerClass.serverComputer> nowUserList = allServerList[i].server;
                 for (int ii = 0; ii < nowUserList.Count; ii++)
                 {
                     string name = server.server[0].name; //当前要控制的设备名称
                     if (name.Equals(nowUserList[ii].name))
                     {
                         ServerClass.serverComputer temp = server.server[0];
                         //ServerClass.allServerList[i].server[ii].data = temp.data; //修改列表
                         if (nowUserList[ii].socket != null)
                         {
                             if (new BasicSocketClass().sendSocket(nowUserList[ii].socket, temp.data))   //客户端在线
                             //mess.writeLine(String.Format("Client user:{0} name:{1} shell:{2}", server.user, temp.name, temp.data));
                             {
                                 return(true);
                             }
                             else   //客户端不在线
                             {
                                 mess.writeLine(String.Format("Server user:{0} name:{1} Leave", server.user, temp.name));
                                 ServerClass.allServerList.Remove(allServerList[i]); //删除这条记录
                                 mess.writeLine(String.Format("Client user:{0} name:{1} shell:{2},客户端已下线,指令取消", server.user, temp.name, temp.data));
                                 return(false);
                             }
                         }
                         return(false);
                     }
                 }
                 mess.writeLog(String.Format("Client:该用户电脑未在线,Code:1,用户:{0},电脑:{1}", server.user, server.server[0].name));
                 return(false); //没有该设备
             }
         }
         mess.writeLog(String.Format("Client:该用户电脑未在线,Code:2,用户:{0},电脑:{1}", server.user, server.server[0].name));
         return(false); //没有该用户
     }
     catch (Exception error)
     {
         new MessageClass().writeLog("Client::addServerData Error:" + error.Message);
         return(true);
     }
 }
Пример #3
0
        int allServerListInt = -1; //用于addServerUserList函数临时记录位置

        public void removeFailList()
        { //移除已退出的电脑
            List <ServerClass.serverUser> all = ServerClass.allServerList;

            foreach (ServerClass.serverUser only in all)
            {
                List <ServerClass.serverComputer> all_computer = only.server; //循环列表
                List <object> result_all = new List <object>();               //需要返回的列表
                //循环获取在线数量
                for (int i = all_computer.Count - 1; i >= 0; i--)
                {
                    ServerClass.serverComputer only_computer = all_computer[i];
                    try {
                        only_computer.socket.Send(Encoding.Default.GetBytes(""));
                    }
                    catch { //失效Socket
                        all_computer.Remove(only_computer);
                        continue;
                    }
                }
            }
        }
Пример #4
0
        private bool getServerList(string data, ref ServerClass.serverUser server)
        {
            try
            {
                /* AppConfig */
                AppConfigClass AppConfig = new AppConfigClass();

                /* user */
                string user = AppConfig.GetConfig(ref data, "_");
                if (user == "")
                {
                    return(false);
                }
                server.user = user;

                /* shell */
                string ComputerName = AppConfig.GetConfig(ref data, "|"); //执行完毕后data为shell
                if (ComputerName == "")
                {
                    return(false);
                }
                ServerClass.serverComputer b = new ServerClass.serverComputer()
                {
                    name = ComputerName, data = data
                };

                /* Add List  */
                server.server.Add(b);
                return(true);
            }
            catch (Exception error)
            {
                new MessageClass().writeLog("Client::getServerList Error:" + error.Message);
                return(false);
            }
        }