Пример #1
0
        public string GetUrl(string absolutePath)
        {
            string retVal = absolutePath;

            try
            {
                WebDavTicket ticket = WebDavTicket.Parse(absolutePath);
                retVal = WebDavUrlBuilder.GetWebDavUrl(ticket.AbsolutePath, true);
            }
            catch (Exception)
            {
            }

            return(retVal);
        }
Пример #2
0
        /// <summary>
        /// Parses the specified SRC ticket.
        /// </summary>
        /// <param name="srcTicket">The SRC ticket.</param>
        /// <param name="format">The format.</param>
        /// <returns></returns>
        public static WebDavTicket Parse(string srcTicket)
        {
            WebDavTicket retVal = null;

            try
            {
                retVal = ParseByFormat(srcTicket, "/P/A/F");
            }
            catch (System.FormatException)
            {
            }
            if (retVal == null)
            {
                retVal = ParseByFormat(srcTicket, "A");
            }

            return(retVal);
        }
Пример #3
0
        /// <summary>
        /// Gets the absolute path.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <returns></returns>
        public string GetAbsolutePath(string url)
        {
            string retVal = url;

            try
            {
                WebDavTicket ticket = WebDavUrlBuilder.GetWebDavTicket(url);
                if (ticket != null)
                {
                    retVal = ticket.ToString();
                }
            }
            catch (System.Exception)
            {
                //throw new Exception("webdav ticket incorrect format");
            }

            return(retVal);
        }
Пример #4
0
        private static WebDavTicket ParseByFormat(string srcTicket, string format)
        {
            WebDavTicket retVal = new WebDavTicket();

            int           index  = 0;
            StringBuilder regExp = new StringBuilder();

            regExp.Append(@"^");
            foreach (char patternChar in format.ToCharArray())
            {
                char nextChar = (format.Length - index) > 1 ? format[index + 1] : '/';
                switch (patternChar)
                {
                case 'P':
                    regExp.Append(String.Format("(?<PLUGIN_TOKEN>[^{0}]+)", nextChar));
                    break;

                case 'A':
                    regExp.Append(String.Format("(?<ABSOLUTE_PATH>[^{0}]+)", nextChar));
                    break;

                case 'F':
                    regExp.Append(@"(?<FILE_NAME>[^\\/:*?\""<>|\r\n]*)");
                    break;

                default:
                    regExp.Append(patternChar);
                    break;
                }

                index++;
            }

            try
            {
                Regex  regex    = new Regex(regExp.ToString());
                Match  match    = regex.Match(srcTicket.Trim());
                string fileName = null;

                string capture = match.Groups["PLUGIN_TOKEN"].Value;
                if (!string.IsNullOrEmpty(capture))
                {
                    retVal.PluginToken = (ePluginToken)Enum.Parse(typeof(ePluginToken), capture);
                }

                capture = match.Groups["FILE_NAME"].Value;
                if (!string.IsNullOrEmpty(capture))
                {
                    fileName = capture;
                }

                capture = match.Groups["ABSOLUTE_PATH"].Value;
                Guid sessionId;
                WebDavAbsolutePath absPath;
                ParseAbsPathTicket(capture, out sessionId, out absPath);

                retVal.SessionId             = sessionId;
                retVal.AbsolutePath          = absPath;
                retVal.AbsolutePath.FileName = fileName;
            }
            catch (FormatException e)
            {
                throw new FormatException(e.Message);
            }
            catch (System.Exception)
            {
                throw new FormatException("invalid ticket");
            }

            return(retVal);
        }