Example #1
0
        private IFileProtectResponse RebuildFromBytes(ContentManagementFlags contentManagementFlags, string fileType, byte[] bytes)
        {
            contentManagementFlags = contentManagementFlags.ValidatedOrDefault();

            TimeMetricTracker.Restart();
            var response = _fileProtector.GetProtectedFile(contentManagementFlags, fileType, bytes);

            TimeMetricTracker.Stop();

            MetricService.Record(Metric.RebuildTime, TimeMetricTracker.Elapsed);
            return(response);
        }
Example #2
0
        private string RebuildFile()
        {
            byte[] protectedFile = null;

            Console.WriteLine($"Using Glasswall Version: {_glasswallVersionService.GetVersion()}");

            var file = File.ReadAllBytes(_config.InputPath);

            var fileType = _fileTypeDetector.DetermineFileType(file);

            Console.WriteLine($"Filetype Detected for {_config.FileId}: {fileType.FileTypeName}");

            string status;

            if (fileType.FileType == FileType.Unknown)
            {
                status = FileOutcome.Unmodified;
            }
            else
            {
                var protectedFileResponse = _fileProtector.GetProtectedFile(GetDefaultContentManagement(), fileType.FileTypeName, file);

                if (!string.IsNullOrWhiteSpace(protectedFileResponse.ErrorMessage))
                {
                    if (protectedFileResponse.IsDisallowed)
                    {
                        status = FileOutcome.Unmodified;
                    }
                    else
                    {
                        status = FileOutcome.Failed;
                    }
                }
                else
                {
                    protectedFile = protectedFileResponse.ProtectedFile;
                    status        = FileOutcome.Replace;
                }
            }

            Directory.CreateDirectory("/output");

            File.WriteAllBytes(_config.OutputPath, protectedFile ?? file);

            Console.WriteLine($"Status of {status} for {_config.FileId}");

            return(status);
        }