public void UpdateServerInfo(McsMetaModel mcsInfo, McsMetaModelMask mask) { try { //// Way1 //var SomeObject = new { .../*properties*/... }; //var PropertyInfos = SomeObject.GetType().GetProperties(); //foreach (PropertyInfo pInfo in PropertyInfos) //{ // string propertyName = pInfo.Name; //gets the name of the property // doSomething(pInfo.GetValue(SomeObject, null)); //} //// Way2 //mcsInfo.GetType().GetProperties().ToList().ForEach(p => { // //p is each PropertyInfo // DoSomething(p); //}); mStore.McsGroup[mcsInfo.ServerId].ApplyUpdate(mcsInfo, mask); UpdateServerLastSeen(mcsInfo.ServerId); } catch (Exception e) { Logger.LogErr(e.ToString()); } }
public McsMetaModel RegisterNewServer(McsMetaModel mcsInfo, bool inner = false) { if (string.IsNullOrEmpty(mcsInfo.ServerId)) { // throw new Exception("No serverid found at mcs inner register."); return(null); } if (inner) { mStore.McsGroup[mcsInfo.ServerId] = mcsInfo; if (mStore.McsMonitoringGroup.ContainsKey(mcsInfo.ServerId)) { return(mcsInfo); } else { mStore.McsMonitoringGroup[mcsInfo.ServerId] = new McsMonitoringModel { ServerId = mcsInfo.ServerId, Status = "new", LastSeen = DateTime.UtcNow, }; } } else { var x = mStore.McsGroup.Select(i => i.Value).Where(d => d.Name == mcsInfo.Name).ToList(); if (x.Count == 0) { Guid serverId = Guid.NewGuid(); mcsInfo.ServerId = serverId.ToString("N"); mStore.McsGroup[mcsInfo.ServerId] = mcsInfo; mStore.McsMonitoringGroup[mcsInfo.ServerId] = new McsMonitoringModel { ServerId = mcsInfo.ServerId, Status = "new", LastSeen = DateTime.UtcNow, }; return(mcsInfo); } else { return(x[0]); } } return(null); }
public MonitoringModule() { Before += BeforeMonitoringApiRequest; After += AfterMonitoringApiResponse; OnError += OnMonitoringApiRequestError; Post["/api/mcs/register"] = parameters => { var x = new McsMetaModel { Name = requestMonitoringModel.Name, Address = requestMonitoringModel.Address, McVersion = requestMonitoringModel.McVersion, ModVersion = requestMonitoringModel.ModVersion, ModPort = requestMonitoringModel.ModPort, Endpoint = string.Format("http://{0}:{1}/", requestMonitoringModel.Address, requestMonitoringModel.ModPort), }; var p = AirFrog.DataAccess.RegisterNewServer(x); if (p == null) { throw new Exception("RequestDataOrProcessError: Register Mcs failed."); } else { return(Response.AsJson(new { result = "success", errormsg = "", text = p.ServerId })); } }; Post["/api/mcs/update"] = parameters => { var x = new McsMetaModel { ServerId = requestMonitoringModel.ServerId, Name = requestMonitoringModel.Name, Address = requestMonitoringModel.Address, McVersion = requestMonitoringModel.McVersion, ModVersion = requestMonitoringModel.ModVersion, ModPort = requestMonitoringModel.ModPort }; var y = new McsMetaModelMask { Name = false, Address = string.IsNullOrEmpty(requestMonitoringModel.Address) ? false : true, McVersion = string.IsNullOrEmpty(requestMonitoringModel.McVersion) ? false : true, ModVersion = string.IsNullOrEmpty(requestMonitoringModel.ModVersion) ? false : true, ModPort = requestMonitoringModel.ModPort == 0 ? false : true }; AirFrog.DataAccess.UpdateServerInfo(x, y); return(Response.AsJson(new { result = "success", errormsg = "" })); }; Post["/api/mcs/golive"] = parameters => { AirFrog.DataAccess.UpdateServerMonitoringInfo( new McsMonitoringModel { ServerId = requestMonitoringModel.ServerId, Status = "live", }, new McsMonitoringModelMask { Status = true, }); return(Response.AsJson(successResponse)); }; Post["/api/mcs/heartbeat"] = parameters => { AirFrog.DataAccess.UpdateServerLastSeen(requestMonitoringModel.ServerId); return(Response.AsJson(successResponse)); }; Post["/api/mcs/server_closedown"] = parameters => { AirFrog.DataAccess.UpdateServerMonitoringInfo( new McsMonitoringModel { ServerId = requestMonitoringModel.ServerId, Status = "down", }, new McsMonitoringModelMask { Status = true, }); return(Response.AsJson(successResponse)); }; }