Esempio n. 1
0
        public ActionResult LogParameterSave(NippsModule nippsModule)
        {
            ModuleNameParser mnp = new ModuleNameParser(nippsModule.ModuleName);

            try
            {
                UpdateLogParameter(nippsModule, mnp, ViewBag);

                UpdateNippsModule(nippsModule, ViewBag);

                SetLogLevel(nippsModule, mnp, ViewBag);
            }
            catch (Exception ex)
            {
                if (ViewBag.Result == Result.OK)
                {
                    ViewBag.Result = Result.SUCCESSWITHWARN;
                }
                ViewBag.ResultMessages.Add(ex.ToString());
            }

            ViewBag.ReturnToAction     = ReturnToAction;
            ViewBag.ReturnToController = ReturnToController;
            ViewBag.Title = Resources.Global.LogParametersChangeTitle;

            if (ViewBag.Result == Result.OK)
            {
                return(RedirectToAction("StatusList"));
            }

            return(View(NippsSiteHelper.ResultMessageView));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public ActionResult LogDetail(NippsModule nippsModule)
        {
            List <NippsLog> nippsLog = new List <NippsLog>();

            ViewBag.ModuleName = nippsModule.ModuleName;
            ViewBag.ModuleId   = nippsModule.ModuleId;
            ViewBag.CheckedBy  = ((User)Session["User"]).UserName;

            try
            {
                string          svcUrl     = CommonHelper.LogManagerServiceUrl + "NippsLogService/List";
                NippsLogRequest logRequest = new NippsLogRequest {
                    NippsLogs = new List <NippsLog> {
                        new NippsLog {
                            LogModuleName = nippsModule.ModuleName
                        }
                    }
                };
                NippsLogResponse logResponse = RestHelper.RestPostObject <NippsLogResponse, NippsLogRequest>(svcUrl, logRequest);
                ViewBag.ResultList = logResponse.NippsLogs;
                SetViewBagResult(logResponse, ViewBag);
            }
            catch (Exception ex)
            {
                Logger.Error("{0}\n{1}", nippsModule, ex.ToString());
            }

            return(View(nippsModule));
        }
Esempio n. 4
0
        public ActionResult LogDownload(NippsModule nippsModule)
        {
            List <NippsLogFile> logFiles = new List <NippsLogFile>();

            try
            {
                ModuleNameParser mnp       = new ModuleNameParser(nippsModule.ModuleName);
                string           svcLogUrl = NippsSiteHelper.ServiceLogUrl(mnp);
                Logger.Debug("MODULE={0}, URL={1}", mnp.ToString(), svcLogUrl);

                logFiles           = LogGetFileList(svcLogUrl, logFiles);
                ViewBag.ResultList = logFiles;
                SetViewBagResult(new NippsLogResponse {
                    Result = logFiles.Count > 0 ? Result.OK : Result.SUCCESSWITHWARN, ResultMessages = new List <string>()
                }, ViewBag);
            }
            catch (Exception ex)
            {
                Logger.Error("{0}\n{1}", nippsModule, ex.ToString());
                SetViewBagResult(new NippsLogResponse {
                    Result = Result.FAIL, ResultMessages = new List <string> {
                        ex.ToString()
                    }
                }, ViewBag);
            }

            return(PartialView("LogDownload", nippsModule));
        }
Esempio n. 5
0
        bool RemoveNippsModule(NippsModule nippsModule)
        {
            try
            {
                string             svcUrl        = CommonHelper.LogManagerServiceUrl + "NippsModuleService/Remove";
                NippsModuleRequest moduleRequest = new NippsModuleRequest {
                    NippsModules = new List <NippsModule> {
                        nippsModule
                    }
                };
                NippsModuleResponse moduleResponse = RestHelper.RestPostObject <NippsModuleResponse, NippsModuleRequest>(svcUrl, moduleRequest);

                if (moduleResponse.Result == Result.OK)
                {
                    return(true);
                }

                Logger.Error("{0}: {1}", nippsModule, moduleResponse.ResultMessages[0]);
            }
            catch (Exception ex)
            {
                Logger.Error("{0}: {1}", nippsModule, ex.ToString());
            }

            return(false);
        }
        public virtual NippsModuleResponse LogSetLevel(NippsModuleRequest nippsModuleRequest)
        {
            if (nippsModuleRequest == null || nippsModuleRequest.NippsModules == null || nippsModuleRequest.NippsModules.Count == 0)
            {
                return(new NippsModuleResponse {
                    Result = Result.FAIL
                });
            }

            NippsModule nippsModule = nippsModuleRequest.NippsModules[0];
            string      newLogLevel = Enum.GetName(typeof(NippsLogLevel), nippsModule.LogLevelId);

            foreach (LoggingRule rule in NLog.LogManager.Configuration.LoggingRules)
            {
                //first disable all
                rule.DisableLoggingForLevel(LogLevel.Trace);
                rule.DisableLoggingForLevel(LogLevel.Debug);
                rule.DisableLoggingForLevel(LogLevel.Info);
                rule.DisableLoggingForLevel(LogLevel.Warn);
                rule.DisableLoggingForLevel(LogLevel.Error);
                rule.DisableLoggingForLevel(LogLevel.Fatal);
                //then enable the new one
                rule.EnableLoggingForLevel(LogLevel.FromString(newLogLevel));
            }
            NLog.LogManager.ReconfigExistingLoggers();

            return(new NippsModuleResponse {
                Result = Result.OK
            });
        }
Esempio n. 7
0
        public void Add(NippsLog t)
        {
            NippsModule nippsModule = NippsModuleDao.GetByName(t.LogModuleName);

            //LogModule validated. go on...
            NippsLogDao.Add(t);
        }
Esempio n. 8
0
        private static void SetLogLevel(NippsModule nippsModule, ModuleNameParser mnp, dynamic ViewBag)
        {
            string             uri        = NippsSiteHelper.ServiceLogUrl(mnp) + "LogSetLevel";
            NippsModuleRequest logRequest = new NippsModuleRequest {
                NippsModules = new List <NippsModule> {
                    nippsModule
                }
            };
            NippsModuleResponse logResponse = RestHelper.RestPostObject <NippsModuleResponse, NippsModuleRequest>(uri, logRequest);

            ViewBag.Name = Resources.Global.LogLevelChange;
            SetViewBagResult(logResponse, ViewBag);
        }
Esempio n. 9
0
        private static void UpdateNippsModule(NippsModule nippsModule, dynamic ViewBag)
        {
            string uri = CommonHelper.LogManagerServiceUrl + "NippsModuleService/Update";

            NippsModuleRequest moduleUpdateRequest = new NippsModuleRequest {
                NippsModules = new List <NippsModule> {
                    nippsModule
                }
            };
            NippsModuleResponse moduleUpdateResponse = RestHelper.RestPostObject <NippsModuleResponse, NippsModuleRequest>(uri, moduleUpdateRequest);

            ViewBag.Name = Resources.Global.LogParametersChange;
            SetViewBagResult(moduleUpdateResponse, ViewBag);
        }
Esempio n. 10
0
        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));
        }