internal protected Result(string plate, int accuracy, string countryCode, Pattern pattern) { this.Plate = plate; this.Accuracy = accuracy; this.CountryCode = countryCode; this.LeftBar = pattern.LeftBar; this.RightBar = pattern.RightBar; this.PlateBackColor = pattern.PlateBackColor; this.PlateTextColor = pattern.PlateTextColor; this.EU = PlateDefinition.IsEU(countryCode); }
internal protected CountryResultSet(PlateDefinition pd, IEnumerable <Result> plates) { CountryPlateDefinition = pd; BestAccuracy = 99; WorstAccuracy = 0; BestPlate = null; List <Result> r = new List <Result>(); foreach (var plate in plates) { if (plate.CountryCode == pd.CountryCode) { r.Add(plate); if (BestAccuracy >= 0) { if (plate.CountryCode == PlateDefinition.PriorityCountry) { foreach (var priorityPlate in PriorityPlates) { if (plate.Plate.StartsWith(priorityPlate)) { BestAccuracy = -1; BestPlate = plate; break; } } } } if (plate.Accuracy < BestAccuracy) { BestAccuracy = plate.Accuracy; BestPlate = plate; } if (plate.Accuracy > WorstAccuracy) { WorstAccuracy = plate.Accuracy; } } } Plates = r.ToArray(); }
public static PlateDefinition[] LoadConfigFile() { List <PlateDefinition> ret = new List <PlateDefinition>(); lock (configFile) { string file = Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "bin//RestApi//" + configFile); XmlDocument xDoc = new XmlDocument(); try { if (File.Exists(file)) { xDoc.Load(file); string identicalChars = "", equalChars = "", similarChars = "", order = "", eu = ""; string priorityplates = ""; foreach (XmlAttribute a in xDoc.DocumentElement.Attributes) { switch (a.Name.ToLower()) { case "identicalchars": identicalChars = a.Value.Trim(); break; case "equalchars": equalChars = a.Value.Trim(); break; case "similarchars": similarChars = a.Value.Trim(); break; case "order": order = a.Value.Trim(); break; case "eucountries": eu = a.Value.Trim(); break; case "priorityplates": priorityplates = a.Value.ToUpper().Trim(); break; } } PlateDefinition.IdenticalChars = _MakeCharsList(identicalChars, null).ToArray(); PlateDefinition.EqualChars = _MakeCharsList(equalChars, null).ToArray(); PlateDefinition.SimilarChars = _MakeCharsList(similarChars, null).ToArray(); PlateDefinition.SetPreferredOrder(order); PlateDefinition.EUCountries = _MakeList(eu).ToArray(); PlateDefinition.PriorityPlates = _MakeList(priorityplates).ToArray(); XmlNodeList badges = xDoc.GetElementsByTagName("badge"); foreach (XmlNode n in badges) { string id = (n.Attributes["id"] != null) ? n.Attributes["id"].Value.ToUpper() : ""; if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(n.InnerText)) { Image badge = null; try { badge = new Bitmap(new MemoryStream(Convert.FromBase64String(n.InnerText))); } catch (Exception e) { } if (badge != null) { if (!plateBadges.Contains(id)) { plateBadges.Add(id, badge); } } } } XmlNodeList plates = xDoc.GetElementsByTagName("plate"); foreach (XmlNode n in plates) { PlateDefinition plate = new PlateDefinition(); ret.Add(plate); string abb = ""; string country = ""; bool eubar = false; bool rightbar = false; string plateColors = ""; string badge = ""; similarChars = ""; equalChars = ""; identicalChars = ""; string include = ""; string exclude = ""; string pauk = ""; string goGradId = ""; List <string> wcfLocations = new List <string>(); List <string> goServiceLocations = new List <string>(); List <string> connStrings = new List <string>(); foreach (XmlAttribute a in n.Attributes) { switch (a.Name.ToLower()) { case "abb": abb = a.Value.ToUpper().Trim(); break; case "CountryCode": country = a.Value.Trim(); break; case "eubar": try { eubar = bool.Parse(a.Value); } catch { } break; case "rightbar": try { rightbar = bool.Parse(a.Value); } catch { } break; case "color": plateColors = a.Value.Trim(); break; case "badge": badge = a.Value.Trim(); break; case "identicalchars": identicalChars = a.Value.Trim(); break; case "similarchars": similarChars = a.Value.Trim(); break; case "equalchars": equalChars = a.Value.Trim(); break; case "includechars": include = a.Value.ToUpper().Trim(); break; case "excludechars": exclude = a.Value.ToUpper().Trim(); break; default: break; } } plate.CountryCode = abb; plate.CountryName = country; plate.EUbar = eubar; plate.RightBar = rightbar; plate.SetColors(plateColors); plate.PlateIdenticalChars = _MakeCharsList(identicalChars, PlateDefinition.IdenticalChars).ToArray(); plate.PlateEqualChars = _MakeCharsList(equalChars, PlateDefinition.EqualChars).ToArray(); plate.PlateSimilarChars = _MakeCharsList(similarChars, PlateDefinition.SimilarChars).ToArray(); plate.IncExlChars(include, true); plate.IncExlChars(exclude, false); foreach (XmlNode nn in n.ChildNodes) { identicalChars = ""; similarChars = ""; equalChars = ""; bool peubar = eubar; bool prightbar = rightbar; string list = ""; string id = ""; plateColors = ""; badge = ""; if (nn.Attributes == null) { continue; } foreach (XmlAttribute a in nn.Attributes) { switch (a.Name.ToLower()) { case "list": list = a.Value.ToUpper().Trim(); break; case "id": id = a.Value.Trim(); break; case "color": plateColors = a.Value.Trim(); break; case "badge": badge = a.Value.Trim(); break; case "identicalchars": identicalChars = a.Value.Trim(); break; case "similarchars": similarChars = a.Value.Trim(); break; case "equalchars": equalChars = a.Value.Trim(); break; case "eubar": try { peubar = bool.Parse(a.Value); } catch { } break; case "rightbar": try { prightbar = bool.Parse(a.Value); } catch { } break; default: break; } } switch (nn.Name.ToLower()) { case "pattern": plate.AddPattern(nn.InnerText, list, plateColors, peubar, prightbar); break; case "list": plate.AddList(id, nn.InnerText); break; } } } } //else CFMessageBox.MessageBoxCF.Show("Ne postoji datoteka " + file); } catch (Exception ex) { } finally { } } CountryPlates = ret.ToArray(); return(CountryPlates); }