/// <summary> /// /// </summary> /// <param name="components"></param> private void AnalyzeComponents(List <string> components) { switch (components.Count) { case 0: return; case 1: if (VerifyIfCallSign(components[0]) == ComponentType.CallSign) { BaseCall = components[0]; CallStructureType = CallStructureType.Call; } else { CallStructureType = CallStructureType.Invalid; } break; case 2: ProcessComponents(components[0], components[1]); break; case 3: ProcessComponents(components[0], components[1], components[2]); break; default: break; } }
/// <summary> /// Analyze each component and build a pattern of each type. /// Compare the final pattern to the CallStructureTypes allowed. /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> /// <param name="v3"></param> private void ProcessComponents(string firstComponent, string secondComponent, string thirdComponent) { var componentTypes = (firstComponentType : GetComponentType(firstComponent, 1), secondComponentType : GetComponentType(secondComponent, 2)); ComponentType state = ComponentType.Unknown; ComponentType thirdComponentType = GetComponentType(thirdComponent, 3); if (componentTypes.firstComponentType == ComponentType.Unknown || componentTypes.secondComponentType == ComponentType.Unknown) { componentTypes = ResolveAmbiguities(componentTypes.firstComponentType, componentTypes.secondComponentType); } BaseCall = firstComponent; Prefix = secondComponent; Suffix1 = thirdComponent; // ValidStructures = 'C#M:C#T:CM#:CMM:CMP:CMT:CPM:PCM:PCT:' switch (state) { // if either is invalid short cicuit all the checks and exit immediately case ComponentType _ when componentTypes.firstComponentType == ComponentType.Invalid || componentTypes.secondComponentType == ComponentType.Invalid || thirdComponentType == ComponentType.Invalid: return; // C#M case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.Numeric && thirdComponentType == ComponentType.Portable: CallStructureType = CallStructureType.CallDigitPortable; SetCallSignFlags(thirdComponent, ""); return; // C#T case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.Numeric && thirdComponentType == ComponentType.Text: CallStructureType = CallStructureType.CallDigitText; SetCallSignFlags(thirdComponent, ""); return; // CMM case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.Portable && thirdComponentType == ComponentType.Portable: CallStructureType = CallStructureType.CallPortablePortable; SetCallSignFlags(secondComponent, ""); return; // CMP case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.Portable && thirdComponentType == ComponentType.Prefix: BaseCall = firstComponent; Prefix = thirdComponent; Suffix1 = secondComponent; CallStructureType = CallStructureType.CallPortablePrefix; SetCallSignFlags(secondComponent, ""); return; // CMT case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.Portable && thirdComponentType == ComponentType.Text: CallStructureType = CallStructureType.CallPortableText; SetCallSignFlags(secondComponent, ""); return; // CPM case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.Prefix && thirdComponentType == ComponentType.Portable: CallStructureType = CallStructureType.CallPrefixPortable; SetCallSignFlags(thirdComponent, ""); return; // PCM case ComponentType _ when componentTypes.firstComponentType == ComponentType.Prefix && componentTypes.secondComponentType == ComponentType.CallSign && thirdComponentType == ComponentType.Portable: BaseCall = secondComponent; Prefix = firstComponent; Suffix1 = thirdComponent; CallStructureType = CallStructureType.PrefixCallPortable; return; // PCT case ComponentType _ when componentTypes.firstComponentType == ComponentType.Prefix && componentTypes.secondComponentType == ComponentType.CallSign && thirdComponentType == ComponentType.Text: BaseCall = secondComponent; Prefix = firstComponent; Suffix1 = thirdComponent; CallStructureType = CallStructureType.PrefixCallText; return; case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.Portable && thirdComponentType == ComponentType.Numeric: BaseCall = firstComponent; Prefix = thirdComponent; Suffix1 = secondComponent; SetCallSignFlags(thirdComponent, ""); CallStructureType = CallStructureType.CallDigitPortable; return; default: return; } }
/// <summary> /// TODO: order these in order of use for performance /// </summary> /// <param name="firstComponent"></param> /// <param name="secondComponent"></param> private void ProcessComponents(string firstComponent, string secondComponent) { var componentTypes = (firstComponentType : GetComponentType(firstComponent, 1), secondComponentType : GetComponentType(secondComponent, 2)); ComponentType state = ComponentType.Unknown; if (componentTypes.firstComponentType == ComponentType.Unknown || componentTypes.secondComponentType == ComponentType.Unknown) { componentTypes = ResolveAmbiguities(componentTypes.firstComponentType, componentTypes.secondComponentType); } BaseCall = firstComponent; Prefix = secondComponent; // ValidStructures = 'C#:CM:CP:CT:PC:'; switch (state) { // if either is invalid short cicuit all the checks and exit immediately case ComponentType _ when componentTypes.firstComponentType == ComponentType.Invalid || componentTypes.secondComponentType == ComponentType.Invalid: return; // CP case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.Prefix: CallStructureType = CallStructureType.CallPrefix; return; // PC case ComponentType _ when componentTypes.firstComponentType == ComponentType.Prefix && componentTypes.secondComponentType == ComponentType.CallSign: CallStructureType = CallStructureType.PrefixCall; SetCallSignFlags(firstComponent, ""); BaseCall = secondComponent; Prefix = firstComponent; return; // PP - PrefixPortable case ComponentType _ when componentTypes.firstComponentType == ComponentType.Prefix && componentTypes.secondComponentType == ComponentType.Portable: CallStructureType = CallStructureType.Invalid; return; // CC ==> CP - check BU - BY - VU4 - VU7 case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.CallSign: if (secondComponent.First() == 'B') { CallStructureType = CallStructureType.CallPrefix; SetCallSignFlags(firstComponent, ""); return; } else if (firstComponent.StartsWith("VU4") || firstComponent.StartsWith("VU7")) { CallStructureType = CallStructureType.CallPrefix; SetCallSignFlags(secondComponent, ""); return; } else { return; } // CT case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.Text: CallStructureType = CallStructureType.CallText; SetCallSignFlags(secondComponent, ""); return; // TC case ComponentType _ when componentTypes.firstComponentType == ComponentType.Text && componentTypes.secondComponentType == ComponentType.CallSign: CallStructureType = CallStructureType.CallText; BaseCall = secondComponent; Prefix = firstComponent; SetCallSignFlags(secondComponent, ""); return; // C# case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.Numeric: CallStructureType = CallStructureType.CallDigit; SetCallSignFlags(secondComponent, ""); return; // CM case ComponentType _ when componentTypes.firstComponentType == ComponentType.CallSign && componentTypes.secondComponentType == ComponentType.Portable: SetCallSignFlags(secondComponent, ""); CallStructureType = CallStructureType.CallPortable; return; // PU case ComponentType _ when componentTypes.firstComponentType == ComponentType.Prefix && componentTypes.secondComponentType == ComponentType.Unknown: CallStructureType = CallStructureType.PrefixCall; BaseCall = secondComponent; Prefix = firstComponent; return; default: return; } }