コード例 #1
0
ファイル: ScanManager.cs プロジェクト: ppvasude/kudu
        /*[SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]*/
        private static ScanStatusResult ReadScanStatusFile(String scanId, String mainScanDirPath, String fileName, String folderName)
        {
            ScanStatusResult obj      = null;
            String           readPath = Path.Combine(mainScanDirPath, Constants.ScanFolderName + scanId, fileName);

            //Give preference to folderName if given
            if (folderName != null)
            {
                readPath = Path.Combine(folderName, fileName);
            }

            //Check if scan status file has been formed
            if (FileSystemHelpers.FileExists(readPath))
            {
                //Read json file and deserialize into JObject
                using (FileStream file = System.IO.File.OpenRead(readPath))
                {
                    using (StreamReader sr = new StreamReader(file))
                    {
                        JsonSerializer serializer = new JsonSerializer();
                        obj = (ScanStatusResult)serializer.Deserialize(sr, typeof(ScanStatusResult));
                    }
                }
            }

            return(obj);
        }
コード例 #2
0
ファイル: ScanManager.cs プロジェクト: ppvasude/kudu
        public async Task <ScanReport> GetScanResultFile(String scanId, String mainScanDirPath)
        {
            //JObject statusRes = await GetScanStatus(scanId, mainScanDirPath);
            ScanReport report = null;
            //Run task to read the result file
            await Task.Run(() =>
            {
                String report_path   = Path.Combine(mainScanDirPath, Constants.ScanFolderName + scanId, Constants.ScanLogFile);
                ScanStatusResult scr = ReadScanStatusFile(scanId, mainScanDirPath, Constants.ScanStatusFile, null);

                //Proceed only if this scan has actually been conducted
                //Handling possibility of user entering invalid scanId and breaking the application
                if (scr != null)
                {
                    report = new ScanReport
                    {
                        Id        = scr.Id,
                        Timestamp = DateTime.ParseExact(scr.Id, DATE_TIME_FORMAT, System.Globalization.CultureInfo.InvariantCulture).ToUniversalTime(),
                        Report    = GetScanParsedLogs(report_path)
                    };
                }
            });

            //All the contents of the file and the timestamp
            return(report);
        }
コード例 #3
0
ファイル: ScanManager.cs プロジェクト: ppvasude/kudu
        public async Task <ScanStatusResult> GetScanStatus(String scanId, String mainScanDirPath)
        {
            ScanStatusResult obj = null;
            await Task.Run(() =>
            {
                obj = ReadScanStatusFile(scanId, mainScanDirPath, Constants.ScanStatusFile, null);
            });

            return(obj);
        }
コード例 #4
0
ファイル: ScanManager.cs プロジェクト: ppvasude/kudu
        private static IEnumerable <ScanOverviewResult> EnumerateResults(String mainScanDir)
        {
            if (FileSystemHelpers.DirectoryExists(mainScanDir))
            {
                foreach (String scanFolderPath in FileSystemHelpers.GetDirectories(mainScanDir))
                {
                    ScanOverviewResult result     = new ScanOverviewResult();
                    ScanStatusResult   scanStatus = ReadScanStatusFile("", "", Constants.ScanStatusFile, scanFolderPath);
                    result.Status = scanStatus;

                    yield return(result);
                }
            }
        }
コード例 #5
0
ファイル: ScanManager.cs プロジェクト: ppvasude/kudu
        private static void UpdateScanStatus(String folderPath, ScanStatus status)
        {
            String           filePath = Path.Combine(folderPath, Constants.ScanStatusFile);
            ScanStatusResult obj      = ReadScanStatusFile("", "", Constants.ScanStatusFile, folderPath);

            //Create new Scan Id if file is empty
            //else get existing scan Id
            if (obj == null || obj.Id == null)
            {
                obj    = new ScanStatusResult();
                obj.Id = DateTime.UtcNow.ToString(DATE_TIME_FORMAT);
            }

            //Update status of the scan
            obj.Status = status;
            File.WriteAllText(filePath, JsonConvert.SerializeObject(obj));
        }