private static void ScanFile(string apiUrl, string file, string rule = "")
        {
            MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(apiUrl);

            try
            {
                // The Core ID is usefull when using external LB
                // It actually points the cookie value that identify the core server the LB sent the file to
                string CoreId = apiUrl;

                Stream inputStream = File.Open(file, FileMode.Open);

                FileScanOptions fso = new FileScanOptions();
                fso.SetFileName(GetFileNameFromPath(file));
                if (!string.IsNullOrEmpty(rule))
                {
                    fso.SetRule(rule);
                }

                string dataId = metadefenderCoreClient.ScanFile(inputStream, fso, out CoreId, inputStream.Length);
                Console.WriteLine("File scan started. The data id is: " + dataId);
                if (CoreId.ToLower() != apiUrl.ToLower())
                {
                    Console.WriteLine("Core Id: {0}", CoreId);
                }
            }
            catch (MetadefenderClientException e)
            {
                Console.WriteLine("Error during file scan: " + e.GetDetailedMessage());
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("File not found: " + file + " Exception: " + e.Message);
            }
        }
        public void SuccessWithFileOptions()
        {
            MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(GetMockApiUrl());

            CreateStub("/file", "POST", 200, GetJsonFromFile("MetadefenderCoreClient.test.resources.apiResponses.scanFile.scanFile_success.json"));

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MetadefenderCoreClient.test.resources.testScanFile.txt"))
            {
                string dataId = metadefenderCoreClient.ScanFile(
                    stream,
                    new FileScanOptions()
                    .SetUserAgent("Java client")
                    .SetFileName("file.txt")
                    .SetRule("Default Rule")
                    );
                Assert.AreEqual("61dffeaa728844adbf49eb090e4ece0e", dataId);
            }

            HttpServer.AssertWasCalled(x =>
            {
                var ret = x.CustomVerb("POST", "/file");
                ret.WithHeader("user_agent", new EqualConstraint("Java client"));
                return(ret);
            }
                                       );
        }
        public void WithError()
        {
            MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(GetMockApiUrl());

            CreateStub("/file", "POST", 500, GetJsonFromFile("MetadefenderCoreClient.test.resources.apiResponses.errorJson.json"));

            bool isException = false;

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MetadefenderCoreClient.test.resources.testScanFile.txt"))
            {
                try
                {
                    metadefenderCoreClient.ScanFile(stream, null);
                }
                catch (MetadefenderClientException)
                {
                    isException = true;
                }
            }
            Assert.True(isException);

            HttpServer.AssertWasCalled(x =>
            {
                return(x.CustomVerb("POST", "/file"));
            }
                                       );
        }
        public void Success()
        {
            MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(GetMockApiUrl());

            CreateStub("/file", "POST", 200, GetJsonFromFile("MetadefenderCoreClient.test.resources.apiResponses.scanFile.scanFile_success.json"));

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MetadefenderCoreClient.test.resources.testScanFile.txt"))
            {
                string dataId = metadefenderCoreClient.ScanFile(stream, null);
                Assert.AreEqual("61dffeaa728844adbf49eb090e4ece0e", dataId);
            }

            HttpServer.AssertWasCalled(x =>
            {
                return(x.CustomVerb("POST", "/file"));
            }
                                       );
        }
        private static void ScanFile(string apiUrl, string file)
        {
            MetadefenderCoreClient metadefenderCoreClient = new MetadefenderCoreClient(apiUrl);

            // This is optional: using custom HttpConnector
            metadefenderCoreClient.SetHttpConnector(new CustomHttpConnector());

            try
            {
                Stream inputStream = File.Open(file, FileMode.Open);
                string dataId      = metadefenderCoreClient.ScanFile(inputStream,
                                                                     new FileScanOptions().SetFileName(GetFileNameFromPath(file)));
                Console.WriteLine("File scan started. The data id is: " + dataId);
            }
            catch (MetadefenderClientException e)
            {
                Console.WriteLine("Error during file scan: " + e.GetDetailedMessage());
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("File not found: " + file + " Exception: " + e.Message);
            }
        }