Exemplo n.º 1
0
 /// <summary>
 /// Get the detections associated with a media
 /// </summary>
 /// <param name="mediaId">Media ID</param>
 /// <param name="waitCaptureId">Wait capture ID</param>
 /// <returns>Cogniac.MediaDetections</returns>
 public MediaDetections GetMediaDetections(string mediaId, string waitCaptureId = null)
 {
     if (!String.IsNullOrEmpty(mediaId))
     {
         string fullUrl = "";
         if (string.IsNullOrEmpty(waitCaptureId))
         {
             fullUrl = $"{_urlPrefix}/media/{mediaId}/detections";
         }
         else
         {
             fullUrl = $"{_urlPrefix}/media/{mediaId}/detections?wait_capture_id={waitCaptureId}";
         }
         var request  = new RestRequest(Method.GET);
         var response = ExecuteRequest(fullUrl, request);
         if (response.IsSuccessful && (response.StatusCode == HttpStatusCode.OK))
         {
             return(MediaDetections.FromJson(response.Content));
         }
         else
         {
             throw new WebException(message: "Network error while getting media detections: " + response.Content);
         }
     }
     else
     {
         throw new ArgumentException(message: "The media ID provided is null or empty.");
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Uploads media to a local EdgeFlow. Note that in the SDK, EdgeFlows
        /// are referred to as gateways.
        /// </summary>
        /// <param name="fileName">File to upload</param>
        /// <param name="mediaTimestamp">Media time stamp</param>
        /// <param name="externalMediaId">External media ID</param>
        /// <param name="domainUnit">(E.G. serial number) for set assignment grouping</param>"
        /// <param name="postUrl">Source URL</param>
        /// <returns>Cogniac.MediaDetections object</returns>
        public MediaDetections ProcessMedia
        (
            string subjectUid,
            string fileName        = null,
            double mediaTimestamp  = 0,
            string externalMediaId = null,
            string domainUnit      = null,
            string postUrl         = null
        )
        {
            byte[] fileBytes;
            if (File.Exists(fileName))
            {
                fileBytes = Helpers.GetFileBytesContent(fileName);
            }
            else
            {
                throw new ArgumentException(message: "File does not exist: '" + fileName + "'");
            }
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(message: "No input file provided (fileName");
            }
            string mediaFormat = Path.GetExtension(fileName);

            mediaFormat = mediaFormat.Replace(".", string.Empty);
            Dictionary <string, object> dict = new Dictionary <string, object>
            {
            };

            if (mediaTimestamp > 0)
            {
                dict.Add("media_timestamp", mediaTimestamp);
            }
            if (!String.IsNullOrEmpty(externalMediaId))
            {
                dict.Add("external_media_id", externalMediaId);
            }
            if (!String.IsNullOrEmpty(domainUnit))
            {
                dict.Add("domain_unit", domainUnit);
            }
            if (!String.IsNullOrEmpty(postUrl))
            {
                dict.Add("post_url", postUrl);
            }
            string data    = Helpers.MapToQueryString(dict);
            var    request = new RestRequest(Method.POST)
            {
                AlwaysMultipartFormData = true
            };

            request.AddFile("fileData", fileBytes, fileName);
            IRestResponse response;

            if (string.IsNullOrEmpty(_urlPrefix))
            {
                throw new ArgumentException(message: "Gateway URL is null or empty");
            }
            else
            {
                response = ExecuteRequest($"{_urlPrefix}/process/{subjectUid}?{data}", request);
            }
            if ((response.StatusCode == HttpStatusCode.OK) && (response.IsSuccessful == true))
            {
                return(MediaDetections.FromJson(response.Content));
            }
            else
            {
                throw new WebException(message: "Network error: " + response.Content);
            }
        }