/// <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;
        }
        /// <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);
        }