/// <summary>
        /// A method is used to get the WOPIsrc value and the token value.
        /// </summary>
        /// <param name="wopiResourceUrl">A parameter represents the WOPI resource URL</param>
        /// <returns>A return value represents a name-value pairs collection which includes the WOPIsrc value and the token value. The token value can be get by "Token" key, the WOPIsrc value can be get by "WOPISrc" key.</returns>
        protected static Dictionary <string, string> GetWOPISrcAndTokenValueFromWOPIResourceUrl(string wopiResourceUrl)
        {
            if (string.IsNullOrEmpty(wopiResourceUrl))
            {
                throw new ArgumentNullException("wopiResourceUrl");
            }

            Uri currentUri = null;

            if (!Uri.TryCreate(wopiResourceUrl, UriKind.Absolute, out currentUri))
            {
                throw new ArgumentException("It must be a valid absolute URL", "wopiResourceUrl");
            }

            #region verify the URL.

            NameValueCollection queryParameterValues = HttpUtility.ParseQueryString(currentUri.Query);
            if (null == queryParameterValues || 0 == queryParameterValues.Count)
            {
                string errorMsg = string.Format("The WOPI resource URL must contain the URL query parameter. current URL:[{0}] \r\n", wopiResourceUrl);
                HelperBase.AppendLogs(typeof(TokenAndRequestUrlHelper), errorMsg);
                throw new InvalidOperationException(errorMsg);
            }

            string expectedQueryParameter = @"access_token";

            // Verify the query parameters whether contain "access_token"
            if (!queryParameterValues.AllKeys.Any(Founder => Founder.Equals(expectedQueryParameter, StringComparison.OrdinalIgnoreCase)))
            {
                string errorMsg = string.Format("The WOPI resource URL must contain [access_token] parameter. current URL:[{0}] \r\n", wopiResourceUrl);
                HelperBase.AppendLogs(typeof(TokenAndRequestUrlHelper), errorMsg);
                throw new InvalidOperationException(errorMsg);
            }

            #endregion

            string wopiSrcUrl = currentUri.GetLeftPart(UriPartial.Path);
            Dictionary <string, string> wopiSrcAndTokenValues = new Dictionary <string, string>();
            wopiSrcAndTokenValues.Add("WOPISrc", wopiSrcUrl);
            wopiSrcAndTokenValues.Add("Token", queryParameterValues[expectedQueryParameter]);
            return(wopiSrcAndTokenValues);
        }
        /// <summary>
        /// A method is used to get folder children's level URL.
        /// </summary>
        /// <param name="wopiRootResourceUrl">A parameter represents the WOPI resource URL for the folder level.</param>
        /// <param name="subResourceUrlType">A parameter represents the WOPI sub resource URL for the folder level.</param>
        /// <returns>A return value represents the folder children's level URL.</returns>
        public static string GetSubResourceUrl(string wopiRootResourceUrl, WOPISubResourceUrlType subResourceUrlType)
        {
            #region Verify parameter
            if (string.IsNullOrEmpty(wopiRootResourceUrl))
            {
                throw new ArgumentNullException("wopiRootResourceUrl");
            }

            Uri currentUri = null;
            if (!Uri.TryCreate(wopiRootResourceUrl, UriKind.Absolute, out currentUri))
            {
                throw new ArgumentException("It must be a valid absolute URL", "wopiRootResourceUrl");
            }

            string expectedIncludeStringValue    = string.Empty;
            string expectedPatternValue          = string.Empty;
            string expectedSubResourceUrlPostfix = string.Empty;
            WOPIRootResourceUrlType expectedRootResourceUrlType = WOPIRootResourceUrlType.FileLevel;
            switch (subResourceUrlType)
            {
            case WOPISubResourceUrlType.FolderChildrenLevel:
            {
                expectedIncludeStringValue    = @"/folders/";
                expectedPatternValue          = folderLevelPattern;
                expectedSubResourceUrlPostfix = @"/children";
                expectedRootResourceUrlType   = WOPIRootResourceUrlType.FolderLevel;
                break;
            }

            case WOPISubResourceUrlType.FileContentsLevel:
            {
                expectedIncludeStringValue    = @"/files/";
                expectedPatternValue          = fileLevelPattern;
                expectedSubResourceUrlPostfix = @"/contents";
                expectedRootResourceUrlType   = WOPIRootResourceUrlType.FileLevel;
                break;
            }

            default:
            {
                throw new InvalidOperationException(string.Format(@"The test suite only supports [{0}] and [{1}] two WOPI sub resource URL formats.", WOPISubResourceUrlType.FileContentsLevel, WOPISubResourceUrlType.FolderChildrenLevel));
            }
            }

            if (wopiRootResourceUrl.IndexOf(expectedIncludeStringValue, StringComparison.OrdinalIgnoreCase) < 0)
            {
                string errorMsg = string.Format(
                    @"To getting the [{0}] sub resource URL, the WOPI root resource URL must be [{1}] type, and its format must be [{2}] format.",
                    subResourceUrlType,
                    expectedRootResourceUrlType,
                    expectedPatternValue);

                HelperBase.AppendLogs(typeof(TokenAndRequestUrlHelper), errorMsg);
                throw new InvalidOperationException(errorMsg);
            }

            string pathValueOfUrl = currentUri.AbsolutePath;
            if (pathValueOfUrl.EndsWith(@"/contents", StringComparison.OrdinalIgnoreCase) ||
                pathValueOfUrl.EndsWith(@"/children", StringComparison.OrdinalIgnoreCase))
            {
                string errorMsg = string.Format(
                    @"The URL value has been WOPI sub resource URL:[{0}]",
                    wopiRootResourceUrl);
                HelperBase.AppendLogs(typeof(TokenAndRequestUrlHelper), errorMsg);
                throw new InvalidOperationException(errorMsg);
            }

            #endregion

            Dictionary <string, string> wopiSrcAndTokenValues = GetWOPISrcAndTokenValueFromWOPIResourceUrl(wopiRootResourceUrl);
            string wopiSrcValue = wopiSrcAndTokenValues["WOPISrc"];
            string tokenValue   = wopiSrcAndTokenValues["Token"];

            // Construct the sub WOPI resource URL.
            string wopiSubResourceUrl = string.Format(
                @"{0}{1}{2}{3}",
                wopiSrcValue,
                expectedSubResourceUrlPostfix,
                @"?access_token=",
                tokenValue);

            return(wopiSubResourceUrl);
        }