public bool Update(bool Init) { bool ret = false; this.UrlFixed = false; bool WasFixed = false; bool HadError = false; Uri uri = null; bool HasDoods = this.url.EndsWith("/detect", StringComparison.OrdinalIgnoreCase); bool HasAWSObj = this.url.Equals("amazon", StringComparison.OrdinalIgnoreCase) || this.url.Equals("amazon_objects", StringComparison.OrdinalIgnoreCase); bool HasAWSFac = this.url.Equals("amazon_faces", StringComparison.OrdinalIgnoreCase); bool HasSHPer = this.url.IndexOf("/v1/detections", StringComparison.OrdinalIgnoreCase) >= 0; bool HasSHVeh = this.url.IndexOf("/v1/recognition", StringComparison.OrdinalIgnoreCase) >= 0; bool HasDSFacRec = this.url.IndexOf("/v1/vision/face/recognize", StringComparison.OrdinalIgnoreCase) >= 0; //Face Recognition bool HasDSFacDet = this.url.IndexOf("/v1/vision/face", StringComparison.OrdinalIgnoreCase) >= 0; //Face Detections bool HasDSCus = this.url.IndexOf("/v1/vision/custom", StringComparison.OrdinalIgnoreCase) >= 0; bool HasDSScn = this.url.IndexOf("/v1/vision/scene", StringComparison.OrdinalIgnoreCase) >= 0; bool HasDSDet = this.url.IndexOf("/v1/vision/detection", StringComparison.OrdinalIgnoreCase) >= 0; bool ShouldInit = Init || !this.isValid || string.IsNullOrWhiteSpace(this.url) || (!this.url.Contains("/") && !this.url.Contains("_")) || this.Type == URLTypeEnum.Unknown; if (ShouldInit) { if (this.Type == URLTypeEnum.DOODS || HasDoods) { this.DefaultURL = "http://127.0.0.1:8080/detect"; this.HelpURL = "https://github.com/snowzach/doods"; this.Type = URLTypeEnum.DOODS; } else if (this.Type == URLTypeEnum.AWSRekognition_Objects || HasAWSObj) { this.DefaultURL = "Amazon_Objects"; this.HelpURL = "https://docs.aws.amazon.com/rekognition/latest/dg/setting-up.html"; this.Type = URLTypeEnum.AWSRekognition_Objects; this.MaxImagesPerMonth = 5000; } else if (this.Type == URLTypeEnum.AWSRekognition_Faces || HasAWSFac) { this.DefaultURL = "Amazon_Faces"; this.HelpURL = "https://docs.aws.amazon.com/rekognition/latest/dg/setting-up.html"; this.Type = URLTypeEnum.AWSRekognition_Faces; this.UseAsRefinementServer = true; this.RefinementObjects = "Person, Face"; this.MaxImagesPerMonth = 5000; } else if (this.Type == URLTypeEnum.SightHound_Vehicle || HasSHVeh) { this.DefaultURL = "https://dev.sighthoundapi.com/v1/recognition?objectType=vehicle,licenseplate"; this.HelpURL = "https://docs.sighthound.com/cloud/recognition/"; this.Type = URLTypeEnum.SightHound_Vehicle; this.MaxImagesPerMonth = 5000; this.UseAsRefinementServer = true; this.RefinementObjects = "Car, Truck, Pickup Truck, Bus, SUV, Van, Motorcycle, License Plate"; this.IsLocalHost = false; this.IsLocalNetwork = false; this.HttpClient = null; } else if (this.Type == URLTypeEnum.SightHound_Person || HasSHPer) { this.DefaultURL = "https://dev.sighthoundapi.com/v1/detections?type=face,person&faceOption=gender,age,emotion"; this.HelpURL = "https://docs.sighthound.com/cloud/detection/"; this.Type = URLTypeEnum.SightHound_Person; this.UseAsRefinementServer = true; this.RefinementObjects = "Person, Face"; this.IsLocalHost = false; this.IsLocalNetwork = false; this.HttpClient = null; this.MaxImagesPerMonth = 5000; } else if (this.Type == URLTypeEnum.DeepStack_Faces || HasDSFacRec) { this.DefaultURL = "http://127.0.0.1:80/v1/vision/face/recognize"; this.HelpURL = "https://docs.deepstack.cc/face-recognition/index.html"; this.Type = URLTypeEnum.DeepStack_Faces; this.UseAsRefinementServer = true; this.RefinementObjects = "Person, Face"; } else if (this.Type == URLTypeEnum.DeepStack_Scene || HasDSScn) { this.DefaultURL = "http://127.0.0.1:80/v1/vision/scene"; this.HelpURL = "https://docs.deepstack.cc/face-recognition/index.html"; this.Type = URLTypeEnum.DeepStack_Scene; this.UseAsRefinementServer = true; this.RefinementObjects = "*"; } else if (this.Type == URLTypeEnum.DeepStack_Custom || HasDSCus) // assume deepstack //if (this.Type == URLTypeEnum.DeepStack || this.url.IndexOf("/v1/vision/detection", StringComparison.OrdinalIgnoreCase) >= 0) { this.DefaultURL = "http://127.0.0.1:80/v1/vision/custom/YOUR_CUSTOM_MODEL_NAME_HERE"; this.HelpURL = "https://docs.deepstack.cc/custom-models/index.html"; this.Type = URLTypeEnum.DeepStack_Custom; this.UseOnlyAsLinkedServer = true; } else // assume deepstack //if (this.Type == URLTypeEnum.DeepStack || this.url.IndexOf("/v1/vision/detection", StringComparison.OrdinalIgnoreCase) >= 0) { this.DefaultURL = "http://127.0.0.1:80/v1/vision/detection"; this.HelpURL = "https://docs.deepstack.cc/object-detection/index.html"; this.Type = URLTypeEnum.DeepStack; } } if (string.IsNullOrWhiteSpace(this.url)) { this.url = this.DefaultURL; } HasDoods = this.url.EndsWith("/detect", StringComparison.OrdinalIgnoreCase); HasAWSObj = this.url.Equals("amazon", StringComparison.OrdinalIgnoreCase) || this.url.Equals("amazon_objects", StringComparison.OrdinalIgnoreCase); HasAWSFac = this.url.Equals("amazon_faces", StringComparison.OrdinalIgnoreCase); HasSHPer = this.url.IndexOf("/v1/detections", StringComparison.OrdinalIgnoreCase) >= 0; HasSHVeh = this.url.IndexOf("/v1/recognition", StringComparison.OrdinalIgnoreCase) >= 0; HasDSFacRec = this.url.IndexOf("/v1/vision/face/recognize", StringComparison.OrdinalIgnoreCase) >= 0; //Face Recognition HasDSFacDet = this.url.IndexOf("/v1/vision/face", StringComparison.OrdinalIgnoreCase) >= 0; //Face Detections - Not using this for now HasDSCus = this.url.IndexOf("/v1/vision/custom", StringComparison.OrdinalIgnoreCase) >= 0; HasDSDet = this.url.IndexOf("/v1/vision/detection", StringComparison.OrdinalIgnoreCase) >= 0; HasDSScn = this.url.IndexOf("/v1/vision/scene", StringComparison.OrdinalIgnoreCase) >= 0; //================================================================================ // Try to correct any servers without a full URL //================================================================================ if (this.Type == URLTypeEnum.DOODS || HasDoods) { this.url = Global.UpdateURL(this.url, 0, "/detect", "", ref WasFixed, ref HadError); this.Type = URLTypeEnum.DOODS; } else if (this.Type == URLTypeEnum.AWSRekognition_Objects || HasAWSObj) { this.url = "Amazon_Objects"; this.Type = URLTypeEnum.AWSRekognition_Objects; this.UrlFixed = true; } else if (this.Type == URLTypeEnum.AWSRekognition_Faces || HasAWSFac) { this.Type = URLTypeEnum.AWSRekognition_Faces; this.url = "Amazon_Faces"; this.UrlFixed = true; } else if (this.Type == URLTypeEnum.SightHound_Vehicle || HasSHVeh) { this.url = Global.UpdateURL(this.url, 443, "/v1/recognition", "", ref WasFixed, ref HadError); this.Type = URLTypeEnum.SightHound_Vehicle; } else if (this.Type == URLTypeEnum.SightHound_Person || HasSHPer) { this.url = Global.UpdateURL(this.url, 443, "/v1/detections", "", ref WasFixed, ref HadError); this.Type = URLTypeEnum.SightHound_Person; } else // assume deepstack, default to detection { if (!HasDSCus && !HasDSDet && !HasDSScn && !HasDSFacRec && !HasDSFacDet) //default to regular detection { this.url = Global.UpdateURL(this.url, 0, "/v1/vision/detection", "", ref WasFixed, ref HadError); this.Type = URLTypeEnum.DeepStack; } else if (this.Type == URLTypeEnum.DeepStack_Custom && !HasDSCus) { this.url = Global.UpdateURL(this.url, 0, "/v1/vision/custom/", "", ref WasFixed, ref HadError); } else if (this.Type != URLTypeEnum.DeepStack_Custom && HasDSCus) { this.Type = URLTypeEnum.DeepStack_Custom; } else if (this.Type == URLTypeEnum.DeepStack_Faces && !HasDSFacRec && !HasDSFacDet) { this.url = Global.UpdateURL(this.url, 0, "/v1/vision/face/recognize", "", ref WasFixed, ref HadError); } else if (this.Type != URLTypeEnum.DeepStack_Faces && HasDSFacRec) { this.Type = URLTypeEnum.DeepStack_Faces; } else if (this.Type == URLTypeEnum.DeepStack && !HasDSDet) { this.url = Global.UpdateURL(this.url, 0, "/v1/vision/detection", "", ref WasFixed, ref HadError); } else if (this.Type != URLTypeEnum.DeepStack && HasDSDet) { this.Type = URLTypeEnum.DeepStack; } else if (this.Type == URLTypeEnum.DeepStack_Scene && !HasDSScn) { this.url = Global.UpdateURL(this.url, 0, "/v1/vision/scene", "", ref WasFixed, ref HadError); } else if (this.Type != URLTypeEnum.DeepStack_Scene && HasDSScn) { this.Type = URLTypeEnum.DeepStack_Scene; } } //================================================================================ // Do final validation tests //================================================================================ bool IsAWS = this.Type == URLTypeEnum.AWSRekognition_Objects || this.Type == URLTypeEnum.AWSRekognition_Faces; if (!IsAWS) { if (Global.IsValidURL(this.url) && !HadError) { uri = new Uri(this.url); this.Port = uri.Port; this.IsLocalHost = Global.IsLocalHost(uri.Host); this.IsLocalNetwork = Global.IsLocalNetwork(uri.Host); if (this.IsLocalHost && !uri.Host.Contains("127.")) { //force it to always be 127.0.0.1 for localhost AITOOL.Log($"Debug: Converting localhost from '{uri.Host}' to '127.0.0.1'. Localhost and 0.0.0.0 do not seem to be reliable."); this.url = Global.UpdateURL(this.url, 0, "", "127.0.0.1", ref WasFixed, ref HadError); } if (this.Type == URLTypeEnum.DeepStack) { this.CurSrv = "Deepstack_Objects:" + uri.Host + ":" + uri.Port; } else if (this.Type == URLTypeEnum.DeepStack_Custom) { this.CurSrv = "Deepstack_Custom:" + uri.Host + ":" + uri.Port; } else if (this.Type == URLTypeEnum.DeepStack_Faces) { this.CurSrv = "Deepstack_Faces:" + uri.Host + ":" + uri.Port; } else if (this.Type == URLTypeEnum.DeepStack_Scene) { this.CurSrv = "Deepstack_Scene:" + uri.Host + ":" + uri.Port; } else if (this.Type == URLTypeEnum.DOODS) { this.CurSrv = "DOODS:" + uri.Host + ":" + uri.Port; } else if (this.Type == URLTypeEnum.SightHound_Person) { this.CurSrv = "SightHound_Person:" + uri.Host + ":" + uri.Port; this.IsLocalHost = false; this.IsLocalNetwork = false; } else if (this.Type == URLTypeEnum.SightHound_Vehicle) { this.CurSrv = "SightHound_Vehicle:" + uri.Host + ":" + uri.Port; this.IsLocalHost = false; this.IsLocalNetwork = false; } else { this.CurSrv = "Unknown:" + uri.Host + ":" + uri.Port; this.IsLocalHost = false; this.IsLocalNetwork = false; } ret = (this.Type != URLTypeEnum.Unknown && !string.IsNullOrEmpty(this.CurSrv) && !this.CurSrv.StartsWith("Unknown")); } else { ret = false; } } else { if (IsAWS) { this.CurSrv = this.url + ":" + AppSettings.Settings.AmazonRegionEndpoint; this.IsLocalHost = false; this.IsLocalNetwork = false; if (!this.ExternalSettingsValid || ShouldInit) { string error = AITOOL.UpdateAmazonSettings(); if (string.IsNullOrEmpty(error)) { this.IsValid = true; this.ExternalSettingsValid = true; ret = true; } else { AITOOL.Log($"Error: {error}"); this.IsValid = false; this.ExternalSettingsValid = false; ret = false; this.Enabled.WriteFullFence(false); } } else { ret = true; } } } this.IsValid = ret; //disable if needed, but never try reenable if the user disabled by themselves if (!this.IsValid) { this.Enabled.WriteFullFence(false); AITOOL.Log($"Error: '{this.Type.ToString()}' URL is not known/valid: '{this.url}'"); } if (!IsAWS && this.isValid && this.HttpClient == null) { this.HttpClient = new HttpClient(); this.HttpClient.Timeout = this.GetTimeout(); } if (WasFixed) { this.UrlFixed = true; } return(ret); }
public ClsURLItem(String url, int Order, URLTypeEnum type) { this.UrlFixed = false; if (string.IsNullOrWhiteSpace(url)) { if (type == URLTypeEnum.DOODS) { this.DefaultURL = "http://127.0.0.1:8080/detect"; url = this.DefaultURL; } else if (type == URLTypeEnum.AWSRekognition) // || this.url.Equals("aws", StringComparison.OrdinalIgnoreCase) || this.url.Equals("rekognition", StringComparison.OrdinalIgnoreCase)) { this.DefaultURL = "Amazon"; url = this.DefaultURL; } else if (type == URLTypeEnum.SightHound_Vehicle) { this.DefaultURL = "https://dev.sighthoundapi.com/v1/recognition?objectType=vehicle,licenseplate"; url = this.DefaultURL; } else if (type == URLTypeEnum.SightHound_Person) { this.DefaultURL = "https://dev.sighthoundapi.com/v1/detections?type=face,person&faceOption=gender,landmark,age,pose,emotion"; url = this.DefaultURL; } else // assume deepstack //if (this.Type == URLTypeEnum.DeepStack || this.url.IndexOf("/v1/vision/detection", StringComparison.OrdinalIgnoreCase) >= 0) { this.DefaultURL = "http://127.0.0.1:80/v1/vision/detection"; url = this.DefaultURL; } } this.url = url.Trim(); this.Type = type; this.Order = Order; if (this.Type == URLTypeEnum.DOODS || this.url.EndsWith("/detect", StringComparison.OrdinalIgnoreCase)) { this.DefaultURL = "http://127.0.0.1:8080/detect"; this.HelpURL = "https://github.com/snowzach/doods"; if (!this.url.Contains("://")) { this.UrlFixed = true; this.url = "http://" + this.url; } this.Type = URLTypeEnum.DOODS; if (!(this.url.IndexOf("/detect", StringComparison.OrdinalIgnoreCase) >= 0)) { this.UrlFixed = true; this.url = this.url + "/detect"; } Uri uri = new Uri(this.url); this.CurSrv = uri.Host + ":" + uri.Port; this.Port = uri.Port; this.IsLocalHost = Global.IsLocalHost(uri.Host); this.HttpClient = new HttpClient(); this.HttpClient.Timeout = TimeSpan.FromSeconds(AppSettings.Settings.HTTPClientTimeoutSeconds); this.IsValid = true; this.Enabled.WriteFullFence(true); } else if (this.Type == URLTypeEnum.AWSRekognition || this.url.Equals("amazon", StringComparison.OrdinalIgnoreCase)) // || this.url.Equals("aws", StringComparison.OrdinalIgnoreCase) || this.url.Equals("rekognition", StringComparison.OrdinalIgnoreCase)) { this.DefaultURL = "Amazon"; this.HelpURL = "https://docs.aws.amazon.com/rekognition/latest/dg/setting-up.html"; this.Type = URLTypeEnum.AWSRekognition; this.IsLocalHost = false; string error = AITOOL.UpdateAmazonSettings(); if (string.IsNullOrEmpty(error)) { this.CurSrv = "Amazon:" + AppSettings.Settings.AmazonRegionEndpoint; this.IsValid = true; this.Enabled.WriteFullFence(true); this.MaxImagesPerMonth = 5000; } else { AITOOL.Log($"Error: {error}"); this.IsValid = false; this.Enabled.WriteFullFence(false); } } else if (this.Type == URLTypeEnum.SightHound_Person || this.url.IndexOf("/v1/detections", StringComparison.OrdinalIgnoreCase) >= 0) { this.MaxImagesPerMonth = 5000; this.UseAsRefinementServer = true; this.RefinementObjects = "person"; this.DefaultURL = "https://dev.sighthoundapi.com/v1/detections?type=face,person&faceOption=gender,landmark,age,pose,emotion"; this.HelpURL = "https://docs.sighthound.com/cloud/detection/"; if (!this.url.Contains("://")) { this.UrlFixed = true; this.url = "https://" + this.url; } this.Type = URLTypeEnum.SightHound_Person; if (!(this.url.IndexOf("/v1/detections", StringComparison.OrdinalIgnoreCase) >= 0)) { this.UrlFixed = true; this.url = this.url + "/v1/detections?type=face,person&faceOption=gender,landmark,age,pose,emotion"; } Uri uri = new Uri(this.url); this.CurSrv = uri.Host + ":" + uri.Port; this.Port = uri.Port; this.IsLocalHost = false; this.HttpClient = null; this.IsValid = true; this.Enabled.WriteFullFence(true); } else if (this.Type == URLTypeEnum.SightHound_Vehicle || this.url.IndexOf("/v1/recognition", StringComparison.OrdinalIgnoreCase) >= 0) { //https://docs.sighthound.com/cloud/recognition/ this.MaxImagesPerMonth = 5000; this.UseAsRefinementServer = true; this.RefinementObjects = "car,truck,bus,suv,van,motorcycle"; this.DefaultURL = "https://dev.sighthoundapi.com/v1/recognition?objectType=vehicle,licenseplate"; this.HelpURL = "https://docs.sighthound.com/cloud/recognition/"; if (!this.url.Contains("://")) { this.UrlFixed = true; this.url = "https://" + this.url; } this.Type = URLTypeEnum.SightHound_Vehicle; if (!(this.url.IndexOf("/v1/recognition", StringComparison.OrdinalIgnoreCase) >= 0)) { this.UrlFixed = true; this.url = this.url + "/v1/recognition?objectType=vehicle,licenseplate"; } Uri uri = new Uri(this.url); this.CurSrv = uri.Host + ":" + uri.Port; this.Port = uri.Port; this.IsLocalHost = false; this.HttpClient = null; this.IsValid = true; this.Enabled.WriteFullFence(true); } else // assume deepstack //if (this.Type == URLTypeEnum.DeepStack || this.url.IndexOf("/v1/vision/detection", StringComparison.OrdinalIgnoreCase) >= 0) { this.DefaultURL = "http://127.0.0.1:80/v1/vision/detection"; this.HelpURL = "https://ipcamtalk.com/threads/tool-tutorial-free-ai-person-detection-for-blue-iris.37330/"; if (!this.url.Contains("://")) { this.UrlFixed = true; this.url = "http://" + this.url; } this.Type = URLTypeEnum.DeepStack; bool valid = Global.IsValidURL(this.url); //only add path if none already given, for example /vision/custom/model-name if (!valid) { this.UrlFixed = true; this.url = this.url.Trim() + "/v1/vision/detection"; } Uri uri = new Uri(this.url); this.CurSrv = uri.Host + ":" + uri.Port; this.Port = uri.Port; this.IsLocalHost = Global.IsLocalHost(uri.Host); this.HttpClient = new HttpClient(); this.HttpClient.Timeout = TimeSpan.FromSeconds(AppSettings.Settings.HTTPClientTimeoutSeconds); this.IsValid = true; this.Enabled.WriteFullFence(true); } this.UpdateIsValid(); }
public ClsURLItem(String url, int Order, int Count, URLTypeEnum type) { if (!string.IsNullOrWhiteSpace(url)) { this.url = url.Trim(); this.Type = type; this.OrigOrder = Order; this.Count = Count; if (this.Type == URLTypeEnum.DOODS || this.url.EndsWith("/detect", StringComparison.OrdinalIgnoreCase)) { if (!this.url.Contains("://")) { this.url = "http://" + this.url; } this.Type = URLTypeEnum.DOODS; if (!(this.url.IndexOf("/detect", StringComparison.OrdinalIgnoreCase) >= 0)) { this.url = this.url + "/detect"; } Uri uri = new Uri(this.url); this.CurSrv = uri.Host + ":" + uri.Port; this.HttpClient = new HttpClient(); this.HttpClient.Timeout = TimeSpan.FromSeconds(AppSettings.Settings.HTTPClientTimeoutSeconds); this.IsValid = true; this.Enabled.WriteFullFence(true); } else if (this.Type == URLTypeEnum.AWSRekognition || this.url.Equals("amazon", StringComparison.OrdinalIgnoreCase)) // || this.url.Equals("aws", StringComparison.OrdinalIgnoreCase) || this.url.Equals("rekognition", StringComparison.OrdinalIgnoreCase)) { this.Type = URLTypeEnum.AWSRekognition; string error = AITOOL.UpdateAmazonSettings(); if (string.IsNullOrEmpty(error)) { this.CurSrv = "Amazon:" + AppSettings.Settings.AmazonRegionEndpoint; this.IsValid = true; this.Enabled.WriteFullFence(true); this.MaxImagesPerMonth = 5000; } else { AITOOL.Log($"Error: {error}"); } } else // assume deepstack //if (this.Type == URLTypeEnum.DeepStack || this.url.IndexOf("/v1/vision/detection", StringComparison.OrdinalIgnoreCase) >= 0) { if (!this.url.Contains("://")) { this.url = "http://" + this.url; } this.Type = URLTypeEnum.DeepStack; if (!(this.url.IndexOf("/v1/vision/detection", StringComparison.OrdinalIgnoreCase) >= 0)) { this.url = this.url.Trim() + "/v1/vision/detection"; } Uri uri = new Uri(this.url); this.CurSrv = uri.Host + ":" + uri.Port; this.HttpClient = new HttpClient(); this.HttpClient.Timeout = TimeSpan.FromSeconds(AppSettings.Settings.HTTPClientTimeoutSeconds); this.IsValid = true; this.Enabled.WriteFullFence(true); } } }