示例#1
0
        // The BSI might not have a well-formed URI in the RepositoryUri field (this may be the case in source depot based repositories, for example).
        // If this is the case, we try to make it into one to preserve this information.
        private static string GetWellFormedRepositoryUri(BuildSessionInfoData bsi)
        {
            var bsiUriString = bsi.SourceControlServer?.Uri;

            if (bsiUriString == null)
            {
                return(null);
            }

            if (Uri.IsWellFormedUriString(bsiUriString, UriKind.Absolute))
            {
                return(bsiUriString);
            }

            // If the string is not a URI, try to make it into one. If this is still not a valid URI,
            // something is wrong in the original string, so return null to leave it unspecified.
            var hopefullyFixedUri = $"sourcecontrol://{bsiUriString}";

            return(Uri.IsWellFormedUriString(hopefullyFixedUri, UriKind.Absolute) ? hopefullyFixedUri : null);
        }
示例#2
0
        /// <summary>
        /// Creates a <see cref="BsiMetadataExtractor"/> which will pull the relevant information from a BuildSessionInfo file
        /// </summary>
        /// <param name="pathToBuildSessionInfo">The full path to the JSON file with the BuildSessionInfo which will back this object</param>
        /// <exception cref="ArgumentNullException">If the specified path is null</exception>
        /// <exception cref="ArgumentException">If the specified path does not point to an existing file</exception>
        /// <exception cref="DeserializationException">If errors are encountered during deserialization of the JSON file</exception>
        public BsiMetadataExtractor(string pathToBuildSessionInfo)
        {
            if (pathToBuildSessionInfo == null)
            {
                throw new ArgumentNullException(nameof(pathToBuildSessionInfo));
            }

            if (!File.Exists(pathToBuildSessionInfo))
            {
                throw new ArgumentException($"The path to BuildSessionInfo provided, {pathToBuildSessionInfo} is invalid or does not point to an existing file", paramName: nameof(pathToBuildSessionInfo));
            }

            try
            {
                m_backingBsi = JsonConvert.DeserializeObject <BuildSessionInfoData>(File.ReadAllText(pathToBuildSessionInfo));
            }
            catch (Exception e)
            {
                throw new DeserializationException($"Exception caught while deserializing the JSON file at {pathToBuildSessionInfo}", e);
            }
        }