public override System.Net.Http.HttpResponseMessage LogGetZipFileList(NippsLogFileRequest logFileRequest)
 {
     return base.LogGetZipFileList(logFileRequest);
 }
        private List<NippsLogFile> LogGetZipFileList(string uri, List<NippsLogFile> logFiles, NippsLogFileRequest logStartFinish)
        {
            try
            {
                List<NippsLogFile> zipLogs = RestHelper.RestPostObject<List<NippsLogFile>, NippsLogFileRequest>(uri + "/LogGetZipFileList", logStartFinish);
                
                foreach (NippsLogFile zipLog in zipLogs)
                    logFiles.Add(zipLog);

            }
            catch (Exception ex) { Logger.Error(ex); }
            
            return logFiles;
        }
        private List<NippsLogFile> SMNippsLogZipFileList(List<NippsLogFile> logFiles, NippsLogFileRequest logStartFinish)
        {

            List<String> nlogFiles = NippsLogHelper.ListLogFileNames();

            string zipFileName = Request.ApplicationPath.Replace("/", "");
            string sourcePath = nlogFiles[0].Substring(0, nlogFiles[0].IndexOf("\\logs\\") + 6);

            if (NippsLogHelper.ZipFiles(zipFileName, sourcePath, ".log", logStartFinish.LogStartDate, logStartFinish.LogFinishDate))
                logFiles.Add(new NippsLogFile
                {
                    LogFileContent = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.IndexOf(Request.ApplicationPath)) + Request.ApplicationPath + "/logs/",
                    LogFileName = NippsLogHelper.TranslateZipFileName(zipFileName, ".log", logStartFinish.LogStartDate, logStartFinish.LogFinishDate)
                });

            List<NippsModule> smModules = ListSMModules();
            foreach (NippsModule smModule in smModules)
                logFiles = LogGetZipFileList(
                    GetConfigServiceLogUrl(smModule.ModuleName), 
                    logFiles, 
                    logStartFinish);

            return logFiles;
        }
        public ActionResult LogDownloadAll(NippsLogFileRequest logStartFinish)
        {
            string systemManager = Request.Params["IsSystemManager"];
            bool isSystemManager = !string.IsNullOrEmpty(systemManager) && systemManager.Equals("true");

            if (logStartFinish.LogFinishDate < logStartFinish.LogStartDate || logStartFinish.LogFinishDate > DateTime.Now)
            {
                ModelState.AddModelError("LogFinishDate", Resources.Global.MessageInvalidFinishDate);
                ViewBag.IsSystemManager = isSystemManager;
                ViewBag.ModelState = ModelState;
                return View("LogDownloadConfirm");
            }
                
            List<NippsLogFile> logFiles = new List<NippsLogFile>();

            ViewBag.Title = string.Format(Resources.Global.MessageDownloadAllLogs
                , logStartFinish.LogStartDate.ToShortDateString()
                , logStartFinish.LogFinishDate.ToShortDateString());
                
            if (isSystemManager)
                logFiles = SMNippsLogZipFileList(new List<NippsLogFile>(), logStartFinish);
            else
            {
                ModuleNameParser mnp;
                string uri = CommonHelper.LogManagerServiceUrl + "NippsModuleService/List";
                NippsModuleResponse moduleResponse = RestHelper.RestPostObject<NippsModuleResponse, NippsModuleRequest>(uri, new NippsModuleRequest());
                foreach (NippsModule nippsModule in moduleResponse.NippsModules)
                {
                    try
                    {
                        mnp = new ModuleNameParser(nippsModule.ModuleName);
                        uri = NippsSiteHelper.ServiceLogUrl(mnp);

                        logFiles = LogGetZipFileList(uri, logFiles, logStartFinish);
                    }
                    catch (Exception ex) { Logger.Error(ex.ToString()); }
                }
                        
            }

            if (logFiles.Count > 0)
                ViewBag.Result = Result.OK;
            else
                ViewBag.Result = Result.SUCCESSWITHWARN;

            ViewBag.ResultList = logFiles;
            
            return View();

        }
Exemple #5
0
        public virtual HttpResponseMessage LogGetZipFileList(NippsLogFileRequest logFileRequest)
        {
            HttpResponseMessage responseMessage = new HttpResponseMessage();

            string absoluteUri = Request.RequestUri.AbsoluteUri;
            int apiPos = absoluteUri.IndexOf("/api/");

            //is this a webapi request?
            if (apiPos < 0)
            {
                responseMessage.StatusCode = System.Net.HttpStatusCode.NotFound;
                return responseMessage;
            }

            //get all names of NLog.FileTarget
            List<string> logFilePaths = NippsLogHelper.ListLogFileNames();

            if (logFilePaths.Count == 0)
            {
                responseMessage.Content = new StringContent(
                        "{ \"FileNotFound\": \"NLog->targets does not include an entry type is FileTarget.\"}",
                        System.Text.Encoding.UTF8,
                        "application/json");
                responseMessage.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                return responseMessage;
            }

            int logPos = logFilePaths[0].IndexOf("\\logs\\");
            //is name in valid form ?
            if (logPos < 0)
            {
                responseMessage.Content = new StringContent(
                        "{ \"ExceptionMessage\": \"NLog->targets->target->fileName attribute should include backslash character instead of slash character.\"}",
                        System.Text.Encoding.UTF8,
                        "application/json");
                responseMessage.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                return responseMessage;
            }

            string baseLogPath = logFilePaths[0].Substring(0, logPos + 6);
            string zipFileName = Request.GetConfiguration().VirtualPathRoot.Replace("/", "");
            bool isZipped = NippsLogHelper.ZipFiles(zipFileName, baseLogPath, ".log", logFileRequest.LogStartDate, logFileRequest.LogFinishDate);

            if (!isZipped)
            {
                responseMessage.Content = new StringContent(
                        "{ \"ExceptionMessage\": \"Logs can not ZIPped.  See the logs for more detail.\"}",
                        System.Text.Encoding.UTF8,
                        "application/json");
                responseMessage.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                return responseMessage;
            }

            List<NippsLogFile> logFiles = new List<NippsLogFile> {
                new NippsLogFile {
                    LogFileContent = absoluteUri.Substring(0, apiPos + 1) + "logs/",
                    LogFileName = NippsLogHelper.TranslateZipFileName(zipFileName, ".log", logFileRequest.LogStartDate, logFileRequest.LogFinishDate)
                }};

            string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(logFiles);
            responseMessage.Content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
            responseMessage.StatusCode = System.Net.HttpStatusCode.OK;

            return responseMessage;
        }
        public virtual HttpResponseMessage LogGetZipFileList(NippsLogFileRequest logFileRequest)
        {
            HttpResponseMessage responseMessage = new HttpResponseMessage();

            string absoluteUri = Request.RequestUri.AbsoluteUri;
            int    apiPos      = absoluteUri.IndexOf("/api/");

            //is this a webapi request?
            if (apiPos < 0)
            {
                responseMessage.StatusCode = System.Net.HttpStatusCode.NotFound;
                return(responseMessage);
            }

            //get all names of NLog.FileTarget
            List <string> logFilePaths = NippsLogHelper.ListLogFileNames();

            if (logFilePaths.Count == 0)
            {
                responseMessage.Content = new StringContent(
                    "{ \"FileNotFound\": \"NLog->targets does not include an entry type is FileTarget.\"}",
                    System.Text.Encoding.UTF8,
                    "application/json");
                responseMessage.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                return(responseMessage);
            }

            int logPos = logFilePaths[0].IndexOf("\\logs\\");

            //is name in valid form ?
            if (logPos < 0)
            {
                responseMessage.Content = new StringContent(
                    "{ \"ExceptionMessage\": \"NLog->targets->target->fileName attribute should include backslash character instead of slash character.\"}",
                    System.Text.Encoding.UTF8,
                    "application/json");
                responseMessage.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                return(responseMessage);
            }

            string baseLogPath = logFilePaths[0].Substring(0, logPos + 6);
            string zipFileName = Request.GetConfiguration().VirtualPathRoot.Replace("/", "");
            bool   isZipped    = NippsLogHelper.ZipFiles(zipFileName, baseLogPath, ".log", logFileRequest.LogStartDate, logFileRequest.LogFinishDate);

            if (!isZipped)
            {
                responseMessage.Content = new StringContent(
                    "{ \"ExceptionMessage\": \"Logs can not ZIPped.  See the logs for more detail.\"}",
                    System.Text.Encoding.UTF8,
                    "application/json");
                responseMessage.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                return(responseMessage);
            }

            List <NippsLogFile> logFiles = new List <NippsLogFile> {
                new NippsLogFile {
                    LogFileContent = absoluteUri.Substring(0, apiPos + 1) + "logs/",
                    LogFileName    = NippsLogHelper.TranslateZipFileName(zipFileName, ".log", logFileRequest.LogStartDate, logFileRequest.LogFinishDate)
                }
            };

            string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(logFiles);

            responseMessage.Content    = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
            responseMessage.StatusCode = System.Net.HttpStatusCode.OK;

            return(responseMessage);
        }