void Status_Load(object sender, EventArgs e) { APIConfigInfo apiInfo = APIConfigs.GetConfig(); if (!apiInfo.Enable) { return; } ApplicationInfo appInfo = null; ApplicationInfoCollection appcollection = apiInfo.AppCollection; foreach (ApplicationInfo newapp in appcollection) { if (newapp.APIKey == DNTRequest.GetString("api_key")) { appInfo = newapp; } } if (appInfo == null) { return; } string next = DNTRequest.GetString("next"); string reurl = string.Format("{0}{1}user_status={2}{3}", appInfo.CallbackUrl, appInfo.CallbackUrl.IndexOf("?") > 0 ? "&" : "?", userid > 0 ? "1" : "0", next == string.Empty ? next : "next=" + next); Response.Redirect(reurl); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { APIConfigInfo aci = APIConfigs.GetConfig(); allowpassport.SelectedValue = aci.Enable ? "1" : "0"; passportbody.Attributes.Add("style", "display:" + (aci.Enable ? "block" : "none")); allowpassport.Items[0].Attributes.Add("onclick", "setAllowPassport(1)"); allowpassport.Items[1].Attributes.Add("onclick", "setAllowPassport(0)"); ApplicationInfoCollection appColl = aci.AppCollection; DataTable dt = new DataTable(); dt.Columns.Add("appname"); dt.Columns.Add("callbackurl"); dt.Columns.Add("apikey"); dt.Columns.Add("secret"); foreach (ApplicationInfo ai in appColl) { DataRow dr = dt.NewRow(); dr["appname"] = ai.AppName; dr["callbackurl"] = ai.CallbackUrl; dr["apikey"] = ai.APIKey; dr["secret"] = ai.Secret; dt.Rows.Add(dr); } DataGrid1.TableHeaderName = "整合程序列表"; DataGrid1.DataKeyField = "apikey"; DataGrid1.DataSource = dt; DataGrid1.DataBind(); } }
void RESTServer_Load(object sender, EventArgs e) { List <DNTParam> parameters = GetParamsFromRequest(HttpContext.Current.Request); APIConfigInfo apiInfo = APIConfigs.GetConfig(); if (!apiInfo.Enable) { RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_SERVICE, parameters)); return; } //查找匹配客户端配置信息 ApplicationInfo appInfo = null; ApplicationInfoCollection appcollection = apiInfo.AppCollection; foreach (ApplicationInfo newapp in appcollection) { if (newapp.APIKey == DNTRequest.GetString("api_key")) { appInfo = newapp; break; } } if (appInfo == null) { RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_APPLICATION, parameters)); return; } //check request ip string ip = DNTRequest.GetIP(); if (appInfo.IPAddresses != null && appInfo.IPAddresses.Trim() != string.Empty && !Utils.InIPArray(ip, appInfo.IPAddresses.Split(','))) { RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_BAD_IP, parameters)); return; } string sig = GetSignature(parameters, appInfo.Secret); if (sig != DNTRequest.GetString("sig")) { //输出签名错误 RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_SIGNATURE, parameters)); return; } string method = DNTRequest.GetString("method").Trim().ToLower(); //如果客户端未指定方法名称 if (string.IsNullOrEmpty(method)) { RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_METHOD, parameters)); return; } RESTServerResponse(CommandManager.Run(new CommandParameter(method, parameters, appInfo))); }
/// <summary> /// 发送请求 /// </summary> /// <param name="action"></param> /// <param name="data"></param> private static void SendRequest(string action, DiscuzParam[] data, string apiKey) { ApplicationInfoCollection appCollection = GetAsyncTarget(action); foreach (ApplicationInfo appInfo in appCollection) { if (appInfo.APIKey != apiKey) { new ProcessAsync(GetUrl(appInfo.SyncUrl, appInfo.Secret, action, data)).Enqueue(); } } }
/// <summary> /// 获得同步退出登录脚本 /// </summary> /// <param name="uId"></param> /// <returns></returns> public static string GetLogoutScript(int uId) { StringBuilder builder = new StringBuilder(); ApplicationInfoCollection appCollection = GetAsyncTarget(ASYNC_LOGOUT); List <DiscuzParam> paramList = new List <DiscuzParam>(); paramList.Add(DiscuzParam.Create("uid", uId)); foreach (ApplicationInfo appInfo in appCollection) { builder.AppendFormat("<script src=\"{0}\" reload=\"1\"></script>", GetUrl(appInfo.SyncUrl, appInfo.Secret, ASYNC_LOGOUT, paramList.ToArray())); } return(builder.ToString()); }
private void writeTimer_Elapsed(object sender, ElapsedEventArgs e) { try { ApplicationInfoCollection result = this.GetCurrentStorageInfo(); result.MergeWith(this.CurrentState); this.WriteStorageInfo(result); } catch (Exception exc) { Console.WriteLine(exc.Message); } }
public void SendInfoToServer() { if (this.IsConnectedToServer) { ApplicationInfoCollection info = this.connectionManager.JustConnected ? this.monitor.CollectedInfo : this.monitor.CollectedInfo.GetDifference(this.connectionManager.LastSentInfo); if (info.Count > 0) { this.connectionManager.SendObject(info); } } }
public void DeserializeTest() { const string json = "[{\"Name\":\"proc1\",\"PPID\":3333,\"StartTime\":null,\"ActivityTime\":null,\"EndTime\":null,\"IsRunning\":true,\"Modules\":[{\"Name\":\"lib.dll\"}]}]"; ApplicationInfoCollection result = JsonSerializer.ConvertToObject(json); ApplicationInfo info = result.First(); Assert.AreEqual(info.Name, "proc1"); Assert.AreEqual(info.PPID, 3333); bool libExists = info.Modules.Any(item => item.Name == "lib.dll"); bool libIsSingle = info.Modules.Count == 1; Assert.IsTrue(libExists && libIsSingle); }
private void refreshTimer_Elapsed(object sender, ElapsedEventArgs e) { ApplicationInfoCollection result = new ApplicationInfoCollection(); result.AddRange(ProcessMonitor.GetProcesses()); foreach (ApplicationInfo info in this.CollectedInfo) { ApplicationInfo running = result .FirstOrDefault(item => ApplicationInfo.AreEqualsByProcess(item, info)); if (running == null) { info.IsRunning = false; } } this.storage.CurrentState.MergeWith(result); }
private ApplicationInfoCollection GetCurrentStorageInfo() { try { this.CreateIfNotExist(); ApplicationInfoCollection buffer = this.ReadStorageInfo(); if (buffer == null) { buffer = new ApplicationInfoCollection(); this.WriteStorageInfo(buffer); } return(buffer); } catch (Exception exc) { Console.WriteLine(exc.Message); return(new ApplicationInfoCollection()); } }
private void APILogin(APIConfigInfo apiInfo) { ApplicationInfo appInfo = null; ApplicationInfoCollection appcollection = apiInfo.AppCollection; foreach (ApplicationInfo newapp in appcollection) { if (newapp.APIKey == DNTRequest.GetString("api_key")) { appInfo = newapp; break; } } if (appInfo == null) { return; } RedirectAPILogin(appInfo); }
private bool CheckEndOfMessage(ConnectionInfo client, out ApplicationInfoCollection message) { try { String json = client.LastMessage.ToString(); message = null; if (json.Contains(CommonData.EndOfMessage)) { json = json.Substring(0, json.IndexOf(CommonData.EndOfMessage, System.StringComparison.Ordinal)); message = JsonSerializer.ConvertToObject(json); return(true); } return(false); } catch (Exception) { message = null; return(false); } }
public void SerializeTest() { ApplicationInfoCollection collection = new ApplicationInfoCollection(); ApplicationInfo info = new ApplicationInfo { Name = "proc1", PPID = 3333, IsRunning = true, Modules = new List <ModuleInfo> { new ModuleInfo { Name = "lib.dll" } } }; collection.Add(info); string result = JsonSerializer.ConvertToJson(collection); const string expectedResult = "[{\"Name\":\"proc1\",\"PPID\":3333,\"StartTime\":null,\"ActivityTime\":null,\"EndTime\":null,\"IsRunning\":true,\"Modules\":[{\"Name\":\"lib.dll\"}]}]"; Assert.AreEqual(result, expectedResult); }
/// <summary> /// 获取需要数据同步的应用程序列表 /// </summary> /// <param name="actionName"></param> /// <returns></returns> private static ApplicationInfoCollection GetAsyncTarget(string action) { ApplicationInfoCollection appCollection = new ApplicationInfoCollection(); APIConfigInfo apiInfo = APIConfigs.GetConfig(); if (!apiInfo.Enable) { return(appCollection); } foreach (ApplicationInfo appInfo in apiInfo.AppCollection) { if (appInfo.SyncMode == 1 || (appInfo.SyncMode == 2 && Utils.InArray(action, appInfo.SyncList))) { if (appInfo.SyncUrl.Trim() == string.Empty) { continue; } appCollection.Add(appInfo); } } return(appCollection); }
public void MergingTest() { ApplicationInfo info1 = new ApplicationInfo { Name = "proc1" }; ApplicationInfo info2 = new ApplicationInfo { Name = "proc2" }; ApplicationInfoCollection a = new ApplicationInfoCollection { info1 }; ApplicationInfoCollection b = new ApplicationInfoCollection { info2 }; a.MergeWith(b); Assert.AreEqual(a.Count, 2); Assert.AreEqual(a.First().Name, info1.Name); Assert.AreEqual(a.Skip(1).Take(1).First().Name, info2.Name); }
public void GettingDifferenceTest() { ApplicationInfo info1 = new ApplicationInfo { Name = "proc1" }; ApplicationInfo info2 = new ApplicationInfo { Name = "proc2" }; ApplicationInfoCollection a = new ApplicationInfoCollection { info1, info2 }; ApplicationInfoCollection b = new ApplicationInfoCollection { info1 }; ApplicationInfoCollection c = a.GetDifference(b); Assert.AreEqual(c.Count, 1); Assert.AreEqual(c.First().Name, info2.Name); }
protected void DelRec_Click(object sender, EventArgs e) { string apikeylist = DNTRequest.GetString("apikey"); if (apikeylist == "") { return; } foreach (string apikey in apikeylist.Split(',')) { APIConfigInfo aci = APIConfigs.GetConfig(); ApplicationInfoCollection appColl = aci.AppCollection; foreach (ApplicationInfo ai in appColl) { if (ai.APIKey == apikey) { aci.AppCollection.Remove(ai); break; } } APIConfigs.SaveConfig(aci); } Response.Redirect("global_passportmanage.aspx"); }
private void SendingCallback(IAsyncResult result) { try { Socket socket = (Socket)result.AsyncState; int bytesSend = socket.EndSend(result); if (bytesSend != 0 && bytesSend == this.buffer.Length) { Console.WriteLine("Сообщение успешно отправлено;"); this.JustConnected = false; String json = Encoding.Unicode.GetString(this.buffer); this.lastSentInfo = JsonSerializer.ConvertToObject(json); } else { Console.WriteLine("Ничего не отправлено!"); } } catch (Exception exc) { Console.WriteLine(exc.Message); } }
public void UpdateTo(ApplicationInfoCollection state) { this.CurrentState.MergeWith(state); }
void RESTServer_Load(object sender, EventArgs e) { Response.Clear(); Response.ContentType = "text/xml"; APIConfigInfo apiInfo = APIConfigs.GetConfig(); if (!apiInfo.Enable) { ResponseErrorInfo((int)ErrorType.API_EC_SERVICE); return; } //check sig DNTParam[] parameters = GetParamsFromRequest(Request); //GetRequests /*---- optional ----*/ //format string format = DNTRequest.GetString("format"); //callback string callback = DNTRequest.GetString("callback"); /*---- required ----*/ //api_key string api_key = DNTRequest.GetString("api_key"); //整合程序对象 ApplicationInfo appInfo = null; ApplicationInfoCollection appcollection = apiInfo.AppCollection; foreach (ApplicationInfo newapp in appcollection) { if (newapp.APIKey == DNTRequest.GetString("api_key")) { appInfo = newapp; } } if (appInfo == null) { //输出API Key错误 ResponseErrorInfo((int)ErrorType.API_EC_APPLICATION); return; } //check request ip string ip = DNTRequest.GetIP(); if (appInfo.IPAddresses != null && appInfo.IPAddresses.Trim() != string.Empty && !Utils.InIPArray(ip, appInfo.IPAddresses.Split(','))) { ResponseErrorInfo((int)ErrorType.API_EC_BAD_IP); return; } /*---- required by specific method----*/ string sig = GetSignature(parameters, appInfo.Secret); //if (sig != DNTRequest.GetString("sig")) //{ // //输出签名错误 // ResponseErrorInfo((int)ErrorType.API_EC_SIGNATURE); // return; //} //get session_key and check user string session_key = DNTRequest.GetString("session_key"); int uid = GetUidFromSessionKey(session_key, appInfo.Secret); string method = DNTRequest.GetString("method"); if (method == string.Empty) { ResponseErrorInfo((int)ErrorType.API_EC_METHOD); return; } string classname = method.Substring(0, method.LastIndexOf('.')); string methodname = method.Substring(method.LastIndexOf('.') + 1); string content; ActionBase action; double lastcallid = -1; double callid = -1; try { Type type = Type.GetType(string.Format("Discuz.Web.Services.API.Actions.{0}, Discuz.Web.Services", classname), false, true); action = (ActionBase)Activator.CreateInstance(type); action.ApiKey = api_key; action.Params = parameters; action.App = appInfo; action.Secret = appInfo.Secret; action.Uid = uid; action.Format = FormatType.XML; action.Signature = sig; //call_id - milliseconds record last callid double.TryParse(DNTRequest.GetString("call_id"), out callid); if (callid > -1) { if (Session["call_id"] == null) lastcallid = -1; else double.TryParse(Session["call_id"].ToString(), out lastcallid); } action.CallId = callid; action.LastCallId = lastcallid; if (format.Trim().ToLower() == "json") { Response.ContentType = "text/html"; action.Format = FormatType.JSON; } content = type.InvokeMember(methodname, BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.IgnoreCase, null, action, new object[] { }).ToString(); } catch { content = ""; ResponseErrorInfo((int)ErrorType.API_EC_METHOD); return; } if (action.ErrorCode > 0) { ResponseErrorInfo(action.ErrorCode); return; } //update callid if (callid > lastcallid) { Session["call_id"] = callid; } //成功后适当的地方更新用户在线状态 if (callback != string.Empty) { Response.ContentType = "text/html"; if (action.Format == FormatType.JSON) { content = callback + "(" + content + ");"; } else { content = callback + "(\"" + content.Replace("\"", "\\\"") + "\");"; } } Response.Write(content); Response.End(); }
private void WriteStorageInfo(ApplicationInfoCollection result) { String json = JsonSerializer.ConvertToJson(result); File.WriteAllText(this.FilePath, json); }