/// <summary> /// Constructor /// </summary> /// <param name="scopeName">Strongy typed cope name</param> /// <param name="classification">Failure classification</param> public TimedScopeInstanceName(TimedScopeName scopeName, TimedScopeResult classification) { Code.ExpectsArgument(scopeName, nameof(scopeName), TaggingUtilities.ReserveTag(0x23817705 /* tag_96x2f */)); CompleteScopeName = scopeName; Classification = classification; }
/// <summary> /// Tries to parse a TimedScopeInstanceName instance from a string /// </summary> /// <param name="toParse">String to be parsed, cannot be null</param> /// <param name="parsed">This output parameter is set to a new TimedScopeInstanceName instance when succeeded, null otherwise</param> /// <param name="preferMetaData">If <c>true</c>, the second field is assumed to be MetaData value</param> /// <returns>Success status</returns> public static bool TryParse(string toParse, out TimedScopeInstanceName parsed, bool preferMetaData = false) { parsed = null; if (string.IsNullOrWhiteSpace(toParse)) { return(false); } try { // The scope instance names have the following form: scope.classification[.description][/subtype][/metadata] // We are going to extract the classification substring, the remaining string with the classification and // description substring removed should form an ordinary timed scope name so we will parse it by TimedScopeName.TryParse. // Split the string by the field separators ('/') first string[] parts = toParse.Split(new[] { FieldsSeparator }, StringSplitOptions.None); // The first part is further divided by classification separator. It should have two or three fields, the first is // a scope, the second is a classification string[] firstFieldsubParts = parts[0].Split(new[] { FailureClassificationSeparator }, StringSplitOptions.None); if (firstFieldsubParts.Length < 2 || firstFieldsubParts.Length > 3) { return(false); } string scope = firstFieldsubParts[0]; string classification = firstFieldsubParts[1]; // Try to parse the classification substring TimedScopeResult parsedClassification; if (!Enum.TryParse(classification, out parsedClassification)) { return(false); } // Reconstruct the scope name string without classification and try to parse it parts[0] = scope; string scopeName = string.Join(FieldsSeparator.ToString(CultureInfo.InvariantCulture), parts); TimedScopeName parsedScopeName; if (!TimedScopeName.TryParse(scopeName, out parsedScopeName, preferMetaData)) { return(false); } // Create a new instance parsed = new TimedScopeInstanceName(parsedScopeName, parsedClassification); return(true); } catch (Exception exception) { // The parsing shouldn't throw but we catch exceptions to be safe ULSLogging.ReportExceptionTag(0x23817706 /* tag_96x2g */, Categories.Common, exception, "An unexpected exception occured during TimedScopeInstanceName.TryParse. Returning false."); return(false); } }