/// <summary> /// 创建客户端不 /// </summary> /// <param name="name"></param> /// <param name="apiUrl"></param> /// <param name="accessKey"></param> /// <param name="allowInstructTypes"></param> /// <returns></returns> public override PassportClient CreatePassportClient(string name, string url, string apiFilePath, string accessKey, IEnumerable <InstructType> allowInstructTypes) { using (SqlQuery query = new SqlQuery()) { query.CommandText = "INSERT INTO bx_PassportClients( ClientName, Url, APIFilePath, AccessKey, InstructTypes) VALUES( @ClientName, @Url, @APIFilePath, @AccessKey, @InstructTypes); SELECT * FROM bx_PassportClients WHERE ClientID = @@IDENTITY;"; query.CommandType = System.Data.CommandType.Text; query.CreateParameter <string>("@ClientName", name, System.Data.SqlDbType.NVarChar, 50); query.CreateParameter <string>("@Url", url, System.Data.SqlDbType.NVarChar, 50); query.CreateParameter <string>("@AccessKey", accessKey, System.Data.SqlDbType.VarChar, 50); query.CreateParameter <string>("@APIFilePath", apiFilePath, SqlDbType.NVarChar, 500); query.CreateParameter <string>("@InstructTypes", StringUtil.Join(allowInstructTypes), SqlDbType.Text); using (XSqlDataReader reader = query.ExecuteReader()) { PassportClient client = null; while (reader.Next) { client = new PassportClient(reader); } return(client); } } }
internal InstructDriver(PassportClient client) { LogHelper.CreateLog(null, string.Format("ID为{0}的Passport客户端启动", client.ClientID), "passport.log"); this.Client = client; this.InstructList = new Queue <Instruct>(this.QueueSize); watch = new Stopwatch(); ClientService = new ClientInterface(); ClientService.Url = UrlUtil.JoinUrl(Client.Url.Trim(), client.APIFilePath); ClientService.AllowAutoRedirect = true; LastSuccessTime = DateTime.Now; LoadDbInstruct();//载入数据库数据 if (this.InstructList.Count > 0) { this.thread = new Thread(ThreadStart); thread.IsBackground = true; thread.Start(); } else { this.IsOpenQueue = true; //没有数据库记录, 打开队列 } }
public override PassportClient TryUpdateClientInfo(string name, string clientUrl, string apiFile, string accessKey, IEnumerable <InstructType> allowInstructTypes) { using (SqlQuery query = new SqlQuery()) { query.CommandText = @"UPDATE bx_PassportClients SET ClientName = @ClientName,InstructTypes = @InstructTypes, AccessKey = @AccessKey WHERE Url = @Url AND APIFilePath = @APIFilePath; SELECT * FROM bx_PassportClients WHERE Url = @Url AND APIFilePath = @APIFilePath;"; query.CommandType = System.Data.CommandType.Text; query.CreateParameter <string>("@ClientName", name, System.Data.SqlDbType.NVarChar, 50); query.CreateParameter <string>("@Url", clientUrl, System.Data.SqlDbType.NVarChar, 50); query.CreateParameter <string>("@AccessKey", accessKey, System.Data.SqlDbType.VarChar, 50); query.CreateParameter <string>("@APIFilePath", apiFile, SqlDbType.NVarChar, 500); query.CreateParameter <string>("@InstructTypes", StringUtil.Join(allowInstructTypes), SqlDbType.Text); using (XSqlDataReader reader = query.ExecuteReader()) { PassportClient client = null; while (reader.Next) { client = new PassportClient(reader); } return(client); } } }
protected void CreatePassportClient() { MessageDisplay msgDisplay = CreateMessageDisplay("clientname", "url", "apifilepath"); string clientname = _Request.Get("clientname", Method.Post); string url = _Request.Get("url", Method.Post); string apifilepath = _Request.Get("apifilepath", Method.Post); string accesskey = _Request.Get("accesskey", Method.Post); InstructType[] structs = _Request.GetList <InstructType>("instructs", Method.Post, new InstructType[0]); using (ErrorScope es = new ErrorScope()) { PassportClient client = PassportBO.Instance.CreatePassportClient(clientname, url, apifilepath, accesskey, structs); if (client != null) { Return(true); //ShowSuccess("创建客户端成功!"); } else { es.CatchError(delegate(ErrorInfo error) { msgDisplay.AddError(error); }); } } }
/// <summary> /// 创建客户端 /// 可能出现客户端已经存在的异常 /// </summary> /// <param name="client"></param> public void CreateClient(PassportClient client) { lock (locker) { Dictionary <int, InstructDriver> drivers = new Dictionary <int, InstructDriver>(this.DriverList); drivers.Add(client.ClientID, new InstructDriver(client)); this.DriverList = drivers; } }
public override PassportClient GetPassportClient(int clientID) { using( SqlQuery query = new SqlQuery()) { query.CommandText = "SELECT * FROM bx_PassportClients WHERE ClientID = @ClientID"; query.CreateParameter<int>("@ClientID", clientID, SqlDbType.Int); PassportClient client = null; using (XSqlDataReader reader = query.ExecuteReader()) { while (reader.Next) client = new PassportClient(reader); return client; } } }
/// <summary> /// 创建客户端 /// 可能出现客户端已经存在的异常 /// </summary> /// <param name="client"></param> public void CreateClient(PassportClient client) { lock (locker) { if (this.DriverList.ContainsKey(client.ClientID)) { InstructDriver d = this.DriverList[client.ClientID]; d.Client = client; } else { Dictionary <int, InstructDriver> drivers = new Dictionary <int, InstructDriver>(this.DriverList); drivers.Add(client.ClientID, new InstructDriver(client)); this.DriverList = drivers; } } }
public PassportClient CreatePassportClient(string name, string url, string apiFilePath, string accessKey, IEnumerable <InstructType> instrcutTypes) { if (!AllSettings.Current.PassportServerSettings.EnablePassportService) { ThrowError(new CustomError(string.Empty, "服务器未开启Passport服务!")); } if (url == null || url.Trim() == string.Empty) { ThrowError(new CustomError("url", "请输入客户端url路径!")); } if (name == null || name.Trim() == string.Empty) { ThrowError(new CustomError("clientname", "请输入客户端名称!")); } if (apiFilePath == null || apiFilePath.Trim() == string.Empty) { ThrowError(new CustomError("apiFilePath", "请输入客户端接口文件路径!")); } if (string.IsNullOrEmpty(accessKey) || accessKey.Length < 10) { ThrowError(new CustomError("accesskey", "通信密钥不能少于10位")); } if (HasUnCatchedError) { return(null); } PassportClient client = PassportDao.Instance.TryUpdateClientInfo(name, url, apiFilePath, accessKey, instrcutTypes); if (client == null) { client = PassportDao.Instance.CreatePassportClient(name, url, apiFilePath, accessKey, instrcutTypes); } if (client != null) { s_Engin.CreateClient(client); } return(client); }
public override PassportClient GetPassportClient(int clientID) { using (SqlQuery query = new SqlQuery()) { query.CommandText = "SELECT * FROM bx_PassportClients WHERE ClientID = @ClientID"; query.CreateParameter <int>("@ClientID", clientID, SqlDbType.Int); PassportClient client = null; using (XSqlDataReader reader = query.ExecuteReader()) { while (reader.Next) { client = new PassportClient(reader); } return(client); } } }
internal InstructDriver(PassportClient client) { LogHelper.CreateLog(null, string.Format("ID为{0}的Passport客户端启动", client.ClientID), "passport.log"); this.Client = client; this.InstructList = new Queue<Instruct>(this.QueueSize); watch = new Stopwatch(); ClientService = new ClientInterface(); ClientService.Url = UrlUtil.JoinUrl(Client.Url.Trim(), client.APIFilePath); ClientService.AllowAutoRedirect = true; LastSuccessTime = DateTime.Now; LoadDbInstruct();//载入数据库数据 if (this.InstructList.Count>0) { this.thread = new Thread(ThreadStart); thread.IsBackground = true; thread.Start(); } else this.IsOpenQueue = true; //没有数据库记录, 打开队列 }
/// <summary> /// 创建客户端 /// 可能出现客户端已经存在的异常 /// </summary> /// <param name="client"></param> public void CreateClient(PassportClient client) { lock (locker) { Dictionary<int, InstructDriver> drivers = new Dictionary<int, InstructDriver>(this.DriverList); drivers.Add(client.ClientID, new InstructDriver(client)); this.DriverList = drivers; } }
/// <summary> /// 创建客户端 /// 可能出现客户端已经存在的异常 /// </summary> /// <param name="client"></param> public void CreateClient(PassportClient client) { lock (locker) { if (this.DriverList.ContainsKey(client.ClientID)) { InstructDriver d = this.DriverList[client.ClientID]; d.Client = client; } else { Dictionary<int, InstructDriver> drivers = new Dictionary<int, InstructDriver>(this.DriverList); drivers.Add(client.ClientID, new InstructDriver(client)); this.DriverList = drivers; } } }
/// <summary> /// 创建客户端不 /// </summary> /// <param name="name"></param> /// <param name="apiUrl"></param> /// <param name="accessKey"></param> /// <param name="allowInstructTypes"></param> /// <returns></returns> public override PassportClient CreatePassportClient(string name, string url,string apiFilePath, string accessKey, IEnumerable<InstructType> allowInstructTypes) { using (SqlQuery query = new SqlQuery()) { query.CommandText = "INSERT INTO bx_PassportClients( ClientName, Url, APIFilePath, AccessKey, InstructTypes) VALUES( @ClientName, @Url, @APIFilePath, @AccessKey, @InstructTypes); SELECT * FROM bx_PassportClients WHERE ClientID = @@IDENTITY;"; query.CommandType = System.Data.CommandType.Text; query.CreateParameter<string>("@ClientName", name, System.Data.SqlDbType.NVarChar, 50); query.CreateParameter<string>("@Url", url, System.Data.SqlDbType.NVarChar, 50); query.CreateParameter<string>("@AccessKey", accessKey, System.Data.SqlDbType.VarChar, 50); query.CreateParameter<string>("@APIFilePath", apiFilePath, SqlDbType.NVarChar, 500); query.CreateParameter<string>("@InstructTypes", StringUtil.Join(allowInstructTypes), SqlDbType.Text); using (XSqlDataReader reader = query.ExecuteReader()) { PassportClient client = null; while (reader.Next) client = new PassportClient(reader); return client; } } }
public override PassportClient TryUpdateClientInfo(string name, string clientUrl, string apiFile, string accessKey, IEnumerable<InstructType> allowInstructTypes) { using (SqlQuery query = new SqlQuery()) { query.CommandText = @"UPDATE bx_PassportClients SET ClientName = @ClientName,InstructTypes = @InstructTypes, AccessKey = @AccessKey WHERE Url = @Url AND APIFilePath = @APIFilePath; SELECT * FROM bx_PassportClients WHERE Url = @Url AND APIFilePath = @APIFilePath;"; query.CommandType = System.Data.CommandType.Text; query.CreateParameter<string>("@ClientName", name, System.Data.SqlDbType.NVarChar, 50); query.CreateParameter<string>("@Url", clientUrl, System.Data.SqlDbType.NVarChar, 50); query.CreateParameter<string>("@AccessKey", accessKey, System.Data.SqlDbType.VarChar, 50); query.CreateParameter<string>("@APIFilePath", apiFile, SqlDbType.NVarChar, 500); query.CreateParameter<string>("@InstructTypes", StringUtil.Join(allowInstructTypes), SqlDbType.Text); using (XSqlDataReader reader = query.ExecuteReader()) { PassportClient client = null; while (reader.Next) client = new PassportClient(reader); return client; } } }
public APIResult Passport_RegiserClient(string ownerUsername, string ownerPassword, string clientName, string url, string apiFilePath, string accessKey, int[] instructList, out int clientID) { APIResult result = new APIResult(); string ip = Context.Request.UserHostAddress; //获取客户端ip int count = 0; KeyValuePair <string, int> tryer = new KeyValuePair <string, int>(); foreach (KeyValuePair <string, int> c in clientTryRegCounter) { if (c.Key == ip) { tryer = c; break; } } count = tryer.Value; if (count > 10) //最多一个IP10次尝试 { result.IsSuccess = false; result.Messages.Add("超过允许的尝试注册次数!请联系Passport管理员"); clientID = 0; return(result); } if (clientTryRegCounter.Count > 100) //每次超过100个客户端要注册, 认为是不正常的 { throw new Exception("接口出现异常,已关闭注册。 请联系服务器管理员"); } clientID = 0; AuthUser user = UserBO.Instance.GetAuthUser(ownerUsername); if (user == null || user == MaxLabs.bbsMax.Entities.User.Guest || !user.IsOwner || !SecurityUtil.ComparePassword(user.PasswordFormat, ownerPassword, user.Password)) { result.IsSuccess = false; result.Messages.Add("Passport创始人信息无效!"); if (string.IsNullOrEmpty(tryer.Key)) { tryer = new KeyValuePair <string, int>(ip, 1); clientTryRegCounter.Add(tryer); } else { clientTryRegCounter.Remove(tryer); clientTryRegCounter.Add(new KeyValuePair <string, int>(ip, count + 1)); } return(result); } using (ErrorScope es = new ErrorScope()) { InstructType[] instrcuts = new InstructType[instructList == null ? 0 : instructList.Length]; for (int i = 0; i < instrcuts.Length; i++) { instrcuts[i] = (InstructType)instructList[i]; } PassportClient client = PassportBO.Instance.CreatePassportClient(clientName, url, apiFilePath, accessKey, instrcuts); if (client == null) { result.IsSuccess = false; es.CatchError <ErrorInfo>(delegate(ErrorInfo error) { result.AddError(error.TatgetName, error.Message); } ); } else { clientID = client.ClientID; result.IsSuccess = true; } } return(result); }