/// <summary> /// Create /// Permits an external process to create an instance of this object without having direct access to the constructor, /// thereby permitting tighter control of the use of class instances. public static GCVision Create(TraceWriter log, string etag, string imageURL, string hash, DateTimeOffset?dateSubmitted, DateTimeOffset?dateProcessed, string name = "", string description = "") { GCPAuthentication.GetClient(log); return(new GCVision(log, etag, imageURL, hash, dateSubmitted, dateProcessed, name, description)); }
/// <summary> /// ApplyAnaysis /// Given a specific 'detectionType' the corresponding GC Vision API function is invoked. /// Returns a different type from different API calls, hence the use of a dynamic type object. /// </summary> /// <param name="detectionType"></param> /// <returns></returns> public dynamic ApplyAnalysis(AnalysisMethod detectionType) { var response = (dynamic)null; try { if (String.IsNullOrEmpty(_url.ToString())) { _log.Info($"URL: {_url.ToString()} is empty."); return(response); } _detectFunctionId = detectionType; switch (detectionType) { case AnalysisMethod.DETECT_FACES: response = GCPAuthentication.GetClient().DetectFaces(_image); break; case AnalysisMethod.DETECT_LANDMARKS: response = GCPAuthentication.GetClient().DetectLandmarks(_image); break; case AnalysisMethod.DETECT_LABELS: response = GCPAuthentication.GetClient().DetectLabels(_image); break; case AnalysisMethod.DETECT_SAFESEARCH: response = GCPAuthentication.GetClient().DetectSafeSearch(_image); break; case AnalysisMethod.DETECT_PROPERTIES: response = GCPAuthentication.GetClient().DetectImageProperties(_image); break; case AnalysisMethod.DETECT_TEXT: response = GCPAuthentication.GetClient().DetectText(_image); break; case AnalysisMethod.DETECT_LOGOS: response = GCPAuthentication.GetClient().DetectLogos(_image); break; case AnalysisMethod.DETECT_CROPHINT: response = GCPAuthentication.GetClient().DetectCropHints(_image); break; case AnalysisMethod.DETECT_WEB: response = GCPAuthentication.GetClient().DetectWebInformation(_image); break; case AnalysisMethod.DETECT_DOCTEXT: response = GCPAuthentication.GetClient().DetectDocumentText(_image); break; default: _log.Error($"Unrecognised detection method: { detectionType } "); break; } } catch (AnnotateImageException e) { _log.Error($"{ e.Response.Error } for image: { _url }"); } return(response); }