private static void UpdateLogParameter(NippsModule nippsModule, ModuleNameParser mnp, dynamic ViewBag) { string uri = CommonHelper.ConfigManagerServiceUrl + "NippsParameterService/Update"; string newLogLevel = Enum.GetName(typeof(NippsLogLevel), nippsModule.LogLevelId); string newArchiveEvery = Enum.GetName(typeof(FileArchivePeriod), nippsModule.ArchiveEvery); string categoryName = mnp.Service.ToUpper(); NippsParameterRequest parameterRequest = new NippsParameterRequest { NippsParameters = new List <NippsParameter> { new NippsParameter { CategoryName = categoryName, ParameterName = "MinLevel", ParameterValue = newLogLevel } , new NippsParameter { CategoryName = categoryName, ParameterName = "ArchiveEvery", ParameterValue = newArchiveEvery } , new NippsParameter { CategoryName = categoryName, ParameterName = "ArchiveAboveSize", ParameterValue = (nippsModule.ArchiveAboveSize * 1000000).ToString() } , new NippsParameter { CategoryName = categoryName, ParameterName = "MaxArchiveFiles", ParameterValue = nippsModule.MaxArchiveFiles.ToString() } } }; NippsParameterResponse parameterResponse = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(uri, parameterRequest); ViewBag.Name = Resources.Global.LogParametersChange; SetViewBagResult(parameterResponse, ViewBag); }
public ActionResult NippsParameterEditConfirm(string categoryName, string parameterName) { try { string svcUrl = CommonHelper.ConfigManagerServiceUrl + "NippsParameterService/Get"; NippsParameterRequest nippsParameterRequest = new NippsParameterRequest { NippsParameters = new List <NippsParameter> { new NippsParameter { CategoryName = categoryName, ParameterName = parameterName } } }; NippsParameterResponse nippsParameterResponse = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(svcUrl, nippsParameterRequest); return(View(nippsParameterResponse.NippsParameters[0])); } catch (Exception ex) { Logger.Error("{0}-{1}: {2}", categoryName, parameterName, ex.ToString()); ModelState.AddModelError("", Resources.Global.MessageUnknownError); } return(View()); }
private static List <NippsParameter> GetEmailParameters() { string configServiceUrl = ConfigurationManager.AppSettings["ConfigManagerServiceUrl"]; NippsParameterRequest nippsParameterRequest = new NippsParameterRequest() { Category = "EMAIL" }; NippsParameterResponse nippsParameterResponse = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(configServiceUrl + "List", nippsParameterRequest); if (nippsParameterResponse.Result == Result.OK) { return(nippsParameterResponse.NippsParameters); } else { StringBuilder sb = new StringBuilder(); foreach (string s in nippsParameterResponse.ResultMessages) { sb.Append(s).Append("\n\n"); } NLog.LogManager.GetCurrentClassLogger().Error(sb.ToString()); throw new Exception(sb.ToString()); } }
public NippsParameterResponse List(NippsParameterRequest nippsParameterRequest) { NippsParameterResponse parameterResponse = new NippsParameterResponse(); parameterResponse.ResultMessages = new List <String>(); if (nippsParameterRequest == null) { nippsParameterRequest = new NippsParameterRequest() { PageNo = 1, PageSize = 1000, Version = "" } } ; else { if (nippsParameterRequest.PageSize < 1) { nippsParameterRequest.PageSize = 1000; } if (nippsParameterRequest.PageNo < 1) { nippsParameterRequest.PageNo = 1; } } try { parameterResponse.NippsParameters = new List <NippsParameter>(); using (ILifetimeScope scope = NippsIoCHelper.IoCContainer.BeginLifetimeScope()) { INippsParameterLogicV2 nippsParameterLogic = scope.Resolve <INippsParameterLogicV2>(); try { if (!String.IsNullOrEmpty(nippsParameterRequest.Category)) { parameterResponse.NippsParameters = nippsParameterLogic.ListParameterByCategory(nippsParameterRequest.Category); } else { parameterResponse.NippsParameters = nippsParameterLogic.ListParameter(nippsParameterRequest.PageNo, nippsParameterRequest.PageSize); } } catch (Exception ex) { parameterResponse.Result = Result.FAIL; parameterResponse.ResultMessages.Add(ex.ToString()); mLogger.Error(ex.ToString()); } } } catch (Exception ex) { parameterResponse.Result = Result.FAIL; parameterResponse.ResultMessages.Add(ex.ToString()); mLogger.Error(ex.ToString()); } return(parameterResponse); }
public NippsParameterResponse Get(NippsParameterRequest nippsParameterRequest) { NippsParameterResponse parameterResponse = new NippsParameterResponse(); parameterResponse.ResultMessages = new List <String>(); if (nippsParameterRequest != null && nippsParameterRequest.NippsParameters != null && nippsParameterRequest.NippsParameters.Count > 0) { Boolean succeededOne = false; try { parameterResponse.NippsParameters = new List <NippsParameter>(); using (ILifetimeScope scope = NippsIoCHelper.IoCContainer.BeginLifetimeScope()) { INippsParameterLogicV2 nippsParameterLogic = scope.Resolve <INippsParameterLogicV2>(); foreach (NippsParameter nippsParameter in nippsParameterRequest.NippsParameters) { try { parameterResponse.NippsParameters.Add( nippsParameterLogic.GetParameter(nippsParameter.CategoryName, nippsParameter.ParameterName) ); succeededOne = true; } catch (Exception ex) { if (succeededOne) { parameterResponse.Result = Result.SUCCESSWITHWARN; } else { parameterResponse.Result = Result.FAIL; } parameterResponse.ResultMessages.Add(ex.ToString()); mLogger.Error("{0}: {1}", nippsParameter, ex.ToString()); } } } } catch (Exception ex) { parameterResponse.Result = Result.FAIL; parameterResponse.ResultMessages.Add(ex.ToString()); mLogger.Error(ex.ToString()); } } else { parameterResponse.Result = Result.FAIL; parameterResponse.ResultMessages.Add(ResultMessagesHelper.ToString(ResultMessages.REQUEST_INVALID_PARAMETER)); } return(parameterResponse); }
void GetOperationalMetricsParam(Models.Nipps nipps) { string paramName = nipps.ApplicationName.Replace("/Netas.Nipps.Service.", "").ToUpper(); string svcUrl = CommonHelper.ConfigManagerServiceUrl + "NippsParameterService/Get"; ViewBag.Result = Result.FAIL; ViewBag.ResultMessages = new List <string>(); try { NippsParameterRequest omRequest = new NippsParameterRequest { NippsParameters = new List <NippsParameter> { new NippsParameter { CategoryName = "OM", ParameterName = paramName } } }; NippsParameterResponse omResponse = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(svcUrl, omRequest); if (omResponse.Result != Result.OK) { return; } if (omResponse.NippsParameters == null || omResponse.NippsParameters.Count != 1) { return; } if (string.IsNullOrEmpty(omResponse.NippsParameters[0].ParameterValue)) { return; } List <NippsOperationalMetric> omMetrics = Newtonsoft.Json.JsonConvert.DeserializeObject <List <NippsOperationalMetric> >(omResponse.NippsParameters[0].ParameterValue); if (omMetrics == null || omMetrics.Count == 0) { return; } ViewBag.Result = Result.OK; ViewBag.ResultList = omMetrics; } catch (Exception ex) { Logger.Error(ex.ToString()); } }
public ActionResult LogParameterChange(NippsModule nippsModule) { try { ModuleNameParser mnp = new ModuleNameParser(nippsModule.ModuleName); string uri = CommonHelper.ConfigManagerServiceUrl + "NippsParameterService/List"; NippsParameterRequest listRequest = new NippsParameterRequest { Category = mnp.Service.ToUpper() }; NippsParameterResponse listResponse = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(uri, listRequest); if (listResponse.Result == Result.OK) { nippsModule.LogLevelId = (NippsLogLevel)Enum.Parse(typeof(NippsLogLevel), listResponse.NippsParameters.Where(p => p.ParameterName.Equals("MinLevel")).Single().ParameterValue, false); nippsModule.ArchiveEvery = (FileArchivePeriod)Enum.Parse(typeof(FileArchivePeriod), listResponse.NippsParameters.Where(p => p.ParameterName.Equals("ArchiveEvery")).Single().ParameterValue, false); nippsModule.ArchiveAboveSize = int.Parse( listResponse.NippsParameters.Where(p => p.ParameterName.Equals("ArchiveAboveSize")).Single().ParameterValue) / 1000000; nippsModule.MaxArchiveFiles = int.Parse( listResponse.NippsParameters.Where(p => p.ParameterName.Equals("MaxArchiveFiles")).Single().ParameterValue); } else //could not get, so set defaults { nippsModule.LogLevelId = NippsLogLevel.Warn; nippsModule.ArchiveEvery = FileArchivePeriod.Day; nippsModule.ArchiveAboveSize = 10 * 1000000; nippsModule.MaxArchiveFiles = 10; } } catch (Exception ex) { Logger.Error("{0}: {1}", nippsModule, ex); nippsModule.LogLevelId = NippsLogLevel.Warn; nippsModule.ArchiveEvery = FileArchivePeriod.Day; nippsModule.ArchiveAboveSize = 10 * 1000000; nippsModule.MaxArchiveFiles = 10; } return(View(nippsModule)); }
public ActionResult NippsParameterList() { try { string svcUrl = CommonHelper.ConfigManagerServiceUrl + "NippsParameterService/List"; NippsParameterResponse nippsParameterResponse = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(svcUrl, new NippsParameterRequest()); ViewBag.ResultList = nippsParameterResponse.NippsParameters; SetViewBagResult(nippsParameterResponse, ViewBag); } catch (Exception ex) { Logger.Error(ex.ToString()); SetViewBagResult(new NippsParameterResponse { Result = Result.FAIL, ResultMessages = new List <string> { ex.ToString() } }, ViewBag); } return(View()); }
public static string GetLicenseFilePath() { string svcUrl = ConfigurationManager.AppSettings["ConfigManagerServiceUrl"] + "Get"; NippsParameterRequest paramRequest = new NippsParameterRequest { NippsParameters = new List <NippsParameter> { new NippsParameter { CategoryName = "LICENSE", ParameterName = "LicenseFilePath" } } }; NippsParameterResponse paramResponse = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(svcUrl, paramRequest); if (paramResponse.Result == Result.OK) { return(paramResponse.NippsParameters[0].ParameterValue); } throw new Exception(paramResponse.ResultMessages[0]); }
private static string GetBcpExe() { string ConfigManagerServiceUrl = ConfigurationManager.AppSettings["ConfigManagerServiceUrl"].ToString(); NippsParameterRequest request = new NippsParameterRequest { NippsParameters = new List <NippsParameter> { new NippsParameter { CategoryName = "BACKUP", ParameterName = "BCP.EXE" } } }; NippsParameterResponse response = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(ConfigManagerServiceUrl + "Get", request); if (response.Result == Result.OK) { return(response.NippsParameters[0].ParameterValue); } //return default if not found/defined return(@"C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\bcp.exe"); }
private static string GetBackupTargetPath() { string ConfigManagerServiceUrl = ConfigurationManager.AppSettings["ConfigManagerServiceUrl"].ToString(); NippsParameterRequest request = new NippsParameterRequest { NippsParameters = new List <NippsParameter> { new NippsParameter { CategoryName = "BACKUP", ParameterName = "TargetPath" } } }; NippsParameterResponse response = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(ConfigManagerServiceUrl + "Get", request); if (response.Result == Result.OK) { return(response.NippsParameters[0].ParameterValue); } //return default if not found/defined return(@"C:\NIPPSPackages"); }
void SaveOperationalMetricsParam(Models.Nipps nipps, List <NippsOperationalMetric> opMetrics) { string paramName = nipps.ApplicationName.Replace("/Netas.Nipps.Service.", "").ToUpper(); string svcUrl = CommonHelper.ConfigManagerServiceUrl + "NippsParameterService/Update"; try { NippsParameterRequest omRequest = new NippsParameterRequest { NippsParameters = new List <NippsParameter> { new NippsParameter { CategoryName = "OM", ParameterName = paramName, ParameterValue = Newtonsoft.Json.JsonConvert.SerializeObject(opMetrics) } } }; NippsParameterResponse omResponse = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(svcUrl, omRequest); } catch (Exception ex) { Logger.Error(ex.ToString()); } }
public ActionResult NippsParameterEdit(NippsParameter parameterEdit) { ViewBag.ReturnToAction = ReturnToAction; ViewBag.ReturnToController = ReturnToController; ViewBag.Title = Resources.Global.ParameterChange; ViewBag.Name = Resources.Global.ParameterChange; try { string svcUrl = CommonHelper.ConfigManagerServiceUrl + "NippsParameterService/Update"; NippsParameterRequest request = new NippsParameterRequest { NippsParameters = new List <NippsParameter> { parameterEdit } }; NippsParameterResponse response = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(svcUrl, request); if (response.Result == Result.OK) { return(RedirectToAction("NippsParameterList")); } SetViewBagResult(response, ViewBag); } catch (Exception ex) { Logger.Error("{0}: {1}", parameterEdit, ex.ToString()); SetViewBagResult(new NippsParameterResponse { Result = Result.FAIL, ResultMessages = new List <string> { Resources.Global.MessageUnknownError } }, ViewBag); } return(View(NippsSiteHelper.ResultMessageView)); }
public static List <NippsParameter> ListNippsHost() { string configServiceUrl = CommonHelper.ConfigManagerServiceUrl; NippsParameterRequest nippsParameterRequest = new NippsParameterRequest() { NippsParameters = new List <NippsParameter> { new NippsParameter { CategoryName = "NIPPSHOST", ParameterName = "NIPPSHOSTS" } } }; NippsParameterResponse nippsParameterResponse = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(configServiceUrl + "NippsParameterService/Get", nippsParameterRequest); if (nippsParameterResponse.Result == Result.OK) { return(nippsParameterResponse.NippsParameters); } else { throw new Exception(nippsParameterResponse.ResultMessages[0]); } }
public virtual HttpResponseMessage UsageMetrics() { try { //check method, if it's POST reset metrics if (Request.Method.Equals(HttpMethod.Post)) { ResetUsageMetrics(); } //find parameter name from request url Regex appNameReqex = new Regex("(/Netas\\.Nipps\\.Service)(.*)(/api/)"); string absUri = this.Request.RequestUri.AbsoluteUri; if (!appNameReqex.Match(absUri).Success) { return new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.NoContent } } ; string paramName = appNameReqex.Match(absUri).Value.Replace("/Netas.Nipps.Service.", "").Replace("/api/", "").ToUpper(); //call parameter service, get value NippsParameterRequest omRequest = new NippsParameterRequest { NippsParameters = new List <NippsParameter> { new NippsParameter { CategoryName = "OM", ParameterName = paramName } } }; string svcUrl = ConfigurationManager.AppSettings["ConfigServiceUrl"].Replace("Service/List", "Service/Get"); NippsParameterResponse omResponse = RestHelper.RestPostObject <NippsParameterResponse, NippsParameterRequest>(svcUrl, omRequest); if (omResponse.Result != Result.OK) { return new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.NoContent } } ; if (omResponse.NippsParameters == null || omResponse.NippsParameters.Count != 1) { return new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.NoContent } } ; if (string.IsNullOrEmpty(omResponse.NippsParameters[0].ParameterValue)) { return new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.NoContent } } ; //deserialize value List <NippsOperationalMetric> omMetrics = Newtonsoft.Json.JsonConvert.DeserializeObject <List <NippsOperationalMetric> >(omResponse.NippsParameters[0].ParameterValue); if (omMetrics == null || omMetrics.Count == 0) { return new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.NoContent } } ; NippsOperationalMetric omUsage = omMetrics.Where(om => om.Name.Equals("UsageMetrics")).Single(); //is om metric active ? if (!omUsage.Active) { return new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.NoContent } } ; } catch (Exception ex) { NLog.LogManager.GetCurrentClassLogger().Error(ex.ToString()); return(new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.NoContent }); } return(new HttpResponseMessage { Content = new StringContent( string.Format("{{\"data\": [[{0}, {1}]]}}", TotalRequestCount, TotalUnhandledErrorCount), Encoding.UTF8, "application/json") }); }
private NippsParameterResponse AddUpdateRemoveParameter(NippsParameterRequest nippsParameterRequest, NippsParameterOperation operation = NippsParameterOperation.ADD) { NippsParameterResponse parameterResponse = new NippsParameterResponse(); parameterResponse.ResultMessages = new List <String>(); if (nippsParameterRequest != null && nippsParameterRequest.NippsParameters != null && nippsParameterRequest.NippsParameters.Count > 0) { Boolean succeededOne = false; try { parameterResponse.NippsParameters = new List <NippsParameter>(); using (ILifetimeScope scope = NippsIoCHelper.IoCContainer.BeginLifetimeScope()) { INippsParameterLogicV2 nippsParameterLogic = scope.Resolve <INippsParameterLogicV2>(); foreach (NippsParameter nippsParameter in nippsParameterRequest.NippsParameters) { try { if (operation == NippsParameterOperation.UPDATE) { nippsParameterLogic.UpdateParameter(nippsParameter.CategoryName, nippsParameter.ParameterName, nippsParameter.ParameterValue); } else if (operation == NippsParameterOperation.REMOVE) { nippsParameterLogic.RemoveParameter(nippsParameter.CategoryName, nippsParameter.ParameterName); } else { nippsParameterLogic.AddParameter(nippsParameter.CategoryName, nippsParameter.ParameterName, nippsParameter.ParameterValue); } succeededOne = true; } catch (Exception ex) { if (succeededOne) { parameterResponse.Result = Result.SUCCESSWITHWARN; } else { parameterResponse.Result = Result.FAIL; } parameterResponse.ResultMessages.Add(ex.ToString()); mLogger.Error(ex.ToString()); } } } } catch (Exception ex) { parameterResponse.Result = Result.FAIL; parameterResponse.ResultMessages.Add(ex.ToString()); mLogger.Error(ex.ToString()); } } else { parameterResponse.Result = Result.FAIL; parameterResponse.ResultMessages.Add(ResultMessagesHelper.ToString(ResultMessages.REQUEST_INVALID_PARAMETER)); } return(parameterResponse); }