/**
         * Scan is done asynchronously and each scan request is tracked by data id of which result can be retrieved by API Fetch Scan Result.
         *
         * @see <a href="http://software.opswat.com/metascan/Documentation/Metascan_v4/documentation/user_guide_metascan_developer_guide_scan_file.html" target="_blank">REST API doc</a>
         *
         * @param inputStream Stream of data (file) to scan. Required
         * @param fileScanOptions Optional file scan options. Can be NULL.
         * @return unique data id for this file scan
         */
        public string ScanFile(Stream inputStream, FileScanOptions fileScanOptions, out string coreId, long contentLength = 0)
        {
            //if (inputStream == null)
            //{
            //    throw new MetadefenderClientException("Stream cannot be null");
            //}

            if ((fileScanOptions != null && fileScanOptions.GetUserAgent() == null) && user_agent != null)
            {
                fileScanOptions.SetUserAgent(user_agent);
            }

            if (fileScanOptions == null && user_agent != null)
            {
                fileScanOptions = new FileScanOptions().SetUserAgent(user_agent);
            }

            Dictionary <string, string> headers = (fileScanOptions == null) ? null : fileScanOptions.GetOptions();

            cookieContainer = new System.Net.CookieContainer();

            HttpConnector.HttpResponse response =
                httpConnector.SendRequest(apiEndPointUrl + "/file", "POST", inputStream, headers, contentLength, cookieContainer);

            coreId = apiEndPointUrl;
            if (response.responseCode == 200)
            {
                try
                {
                    Responses.ScanRequest scanRequest = JsonConvert.DeserializeObject <Responses.ScanRequest>(response.response);
                    if (scanRequest != null)
                    {
                        if (cookieContainer.Count > 0)
                        {
                            foreach (System.Net.Cookie cookie in response.cookieContainer.GetCookies(new Uri(apiEndPointUrl)))
                            {
                                coreId = cookie.Value;
                            }
                        }

                        return(scanRequest.data_id);
                    }
                    else
                    {
                        ThrowRequestError(response);
                        return(null);
                    }
                }
                catch (JsonSerializationException)
                {
                    ThrowRequestError(response);
                    return(null);
                }
            }
            else
            {
                ThrowRequestError(response);
                return(null);
            }
        }
Exemple #2
0
        /**
         * Scan is done asynchronously and each scan request is tracked by data id of which result can be retrieved by API Fetch Scan Result.
         *
         * @see <a href="http://software.opswat.com/metascan/Documentation/Metascan_v4/documentation/user_guide_metascan_developer_guide_scan_file.html" target="_blank">REST API doc</a>
         *
         * @param inputStream Stream of data (file) to scan. Required
         * @param fileScanOptions Optional file scan options. Can be NULL.
         * @return unique data id for this file scan
         */
        public string ScanFile(Stream inputStream, FileScanOptions fileScanOptions)
        {
            if (inputStream == null)
            {
                throw new MetadefenderClientException("Stream cannot be null");
            }

            if ((fileScanOptions != null && fileScanOptions.GetUserAgent() == null) && user_agent != null)
            {
                fileScanOptions.SetUserAgent(user_agent);
            }

            if (fileScanOptions == null && user_agent != null)
            {
                fileScanOptions = new FileScanOptions().SetUserAgent(user_agent);
            }

            Dictionary <string, string> headers = (fileScanOptions == null) ? null : fileScanOptions.GetOptions();

            HttpConnector.HttpResponse response =
                httpConnector.SendRequest(apiEndPointUrl + "/file", "POST", inputStream, headers);

            if (response.responseCode == 200)
            {
                try
                {
                    Responses.ScanRequest scanRequest = JsonConvert.DeserializeObject <Responses.ScanRequest>(response.response);
                    if (scanRequest != null)
                    {
                        return(scanRequest.data_id);
                    }
                    else
                    {
                        ThrowRequestError(response);
                        return(null);
                    }
                }
                catch (JsonSerializationException)
                {
                    ThrowRequestError(response);
                    return(null);
                }
            }
            else
            {
                ThrowRequestError(response);
                return(null);
            }
        }