public void setPoolList(PoolList poolList) { this.poolList = poolList; }
/* * Usage: 返回用户所在的pool列表以及用户id,需要验证信息 * Param: ip(string): 服务器ip * username(string): 用户名 * password(string): 密码 * domain(string): domain id * Retern: GetPoolResult * 如果为null,则表示返回信息为空或格式不对 * Throw: 可能有以下几种类型的异常产生,此处不作处理直接抛出 * IOException, OutOfMemoryException: IO异常,产生自ReadToEnd * WebExcption: 处理请求超时或发生错误,产生自GetResponse * OtherException: 其他一些异常,产生自create request, StreamReader */ public GetPoolResult getPoosWithAuth(string ip, string username, string password, string domain) { if (null == ip || ip.Equals("")) { logger.Error("getPools--ip为空"); throw new Exception("ip不能为空"); } string url = "http://" + ip + "/dp/rpc/dc/login?user="******"&ldap=" + domain + "&pass="******""; try { HttpWebRequest request = generateRequest(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8); s = sr.ReadToEnd().Trim(); response.Close(); sr.Close(); } catch (Exception e) { logger.Error("为用户" + username + "从" + ip + "处获取桌面池信息时产生错误,错误信息为:" + e.Message); throw; } string[] ss = s.Split('\n'); if (ss[0].Equals("error=No desktop is assigned to the user.")) { logger.Error("getPools--没有任何桌面池被分配给用户" + username); return new GetPoolResult(); } else if (ss[0].Equals("error=An incorrect user name or password was entered.")) { logger.Error("getPools--用户名或密码有误"); return null; } string userId = ""; ArrayList pools = new ArrayList(); try { userId = ss[0].Split('=')[1]; string[] temp = ss[3].Split('='); int numPool = Int32.Parse(temp[1]); int index = 4; for (int i = 0; i < numPool; i++) { string[] sss1 = ss[index++].Split('='); // pool name string[] sss2 = ss[index++].Split('='); // pool id string[] sss3 = ss[index++].Split('='); // pool status string pool_name = sss1[1]; string pool_id = sss2[1]; bool pool_ready = sss3[1].Equals("1") ? true : false; ArrayList gateways = null; if (index != ss.Length) { string[] a = ss[index].Split('='); string[] aa = a[0].Split('.'); if (a.Length == 2 && aa.Length == 4 && aa[2].Equals("gw")) { gateways = new ArrayList(); int numGw = Int32.Parse(a[1]); for (int j = 0; j < numGw; j++) { string gwType = ss[++index].Split('=')[1]; string gwAddr = ss[++index].Split('=')[1]; string gwUser = ss[++index].Split('=')[1]; string gwPass = ss[++index].Split('=')[1]; Gateway gw = new Gateway(gwUser, gwPass, gwAddr, gwType); gateways.Add(gw); } index++; } } Pool pool = new Pool(pool_id, pool_name, pool_ready, gateways); pools.Add(pool); } } catch (Exception ee) { logger.Error("为用户" + username + "从" + ip + "处获取桌面池信息时产生错误,错误信息为:" + ee.Message); throw; } PoolList poolList = new PoolList(pools); GetPoolResult result = new GetPoolResult(userId, poolList); return result; }
public GetPoolResult(string userId, PoolList poolList) { this.userId = userId; this.poolList = poolList; }
public GetPoolResult() { userId = ""; poolList = new PoolList(); }