public ScanResult ScanStream(Stream stream)
        {
            EnsureDefaultKeyIsSet();

            var apiInstance = new ScanApi();
            var result      = new ScanResult();

            try
            {
                // ensure stream is ready for read
                stream.Position = 0;
                var r = apiInstance.ScanFileAdvanced(stream, false);

                if (r.CleanResult.HasValue)
                {
                    result.IsSafe = true;
                }
                else if (r.FoundViruses != null && r.FoundViruses.Count > 0)
                {
                    var viruses = new List <string>();
                    r.FoundViruses.ForEach(v => viruses.Add(v.VirusName));
                    result.Message = $"Virus found: {string.Join(",", viruses)}";
                }
            }
            catch (Exception e)
            {
                result.Message = $"Unable to complete scan, {e.Message}";
            }

            return(result);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Configure API key authorization: Apikey
            Configuration.Default.AddApiKey("Apikey", "YOUR-KEY-HERE");

            // Specify your private cloud endpoint
            Configuration.Default.BasePath = "http://cloudmersiveprivatecloud.westus.cloudapp.azure.com";


            var apiInstance = new ScanApi();
            var inputFile   = new System.IO.FileStream("C:\\temp\\document2.pdf", System.IO.FileMode.Open); // System.IO.Stream | Input file to perform the operation on.

            try
            {
                // Scan a file for viruses
                VirusScanResult result = apiInstance.ScanFile(inputFile);
                Debug.WriteLine(result);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling ScanApi.ScanFile: " + e.Message);
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting...");

            var files = Directory.EnumerateFiles("C:\\temp");

            foreach (var file in files)
            {
                // Configure API key authorization: Apikey
                Configuration.Default.AddApiKey("Apikey", "e4c8ad3b-335b-4082-a297-f3153da07770");



                var apiInstance = new ScanApi();
                using (var inputFile = new System.IO.FileStream(file, System.IO.FileMode.Open))
                {
                    try
                    {
                        // Scan a file for viruses
                        VirusScanResult result = apiInstance.ScanFile(inputFile);
                        Debug.WriteLine(JsonConvert.SerializeObject(result));
                    }
                    catch (Exception e)
                    {
                        Debug.Print("Exception when calling ScanApi.ScanFile: " + e.Message);
                    }
                }
            }
        }
コード例 #4
0
        private void btnScanForViruses_Click(object sender, RoutedEventArgs e)
        {
            var apiInstance = new ScanApi();

            apiInstance.Configuration.AddApiKey("Apikey", "YOUR_API_KEY");

            var inputFile         = new System.IO.FileStream(txtSource.Text, System.IO.FileMode.Open); // System.IO.Stream | Input file to perform the operation on.
            var allowExecutables  = false;                                                             // bool? | Set to false to block executable files (program code) from being allowed in the input file.  Default is false (recommended). (optional)
            var allowInvalidFiles = false;                                                             // bool? | Set to false to block invalid files, such as a PDF file that is not really a valid PDF file, or a Word Document that is not a valid Word Document.  Default is false (recommended). (optional)
            var allowScripts      = false;                                                             // bool? | Set to false to block script files, such as a PHP files, Pythong scripts, and other malicious content or security threats that can be embedded in the file.  Set to true to allow these file types.  Default is false (recommended). (optional)
            var restrictFileTypes = "";                                                                // string | Specify a restricted set of file formats to allow as clean as a comma-separated list of file formats, such as .pdf,.docx,.png would allow only PDF, PNG and Word document files.  All files must pass content verification against this list of file formats, if they do not, then the result will be returned as CleanResult=false.  Set restrictFileTypes parameter to null or empty string to disable; default is disabled. (optional)

            VirusScanAdvancedResult result = apiInstance.ScanFileAdvanced(inputFile, allowExecutables, allowInvalidFiles, allowScripts, restrictFileTypes);

            if (result.CleanResult.Value)
            {
                MessageBox.Show("File is clean.");
            }
            else
            {
                MessageBox.Show("File is virus infected or contains dangerous files such as executables!");
            }

            inputFile.Close();
        }
コード例 #5
0
        public bool?CloudmersiveScan(IFormFile file)
        {
            Configuration.Default.AddApiKey("Apikey", _configuration["CloudmersiveKey"]);
            var apiInstance = new ScanApi();

            VirusScanResult result = new VirusScanResult();

            try
            {
                // Scan a file for viruses
                result = apiInstance.ScanFile(file.OpenReadStream());
                Debug.WriteLine(result);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling ScanApi.ScanFile: " + e.Message);
            }

            return(result.CleanResult);
        }
 public void Init()
 {
     instance = new ScanApi();
 }