Exemplo n.º 1
0
        public static string GetFileStreamUrl(File file)
        {
            const int uriLengthLimit = 1024;
            string    fileUri        = null;

            if (!DocumentServiceHelper.HaveExternalIP())
            {
                fileUri = DocumentServiceHelper.GetExternalUri(file);
            }

            if (!string.IsNullOrEmpty(fileUri))
            {
                return(fileUri);
            }

            using (var fileDao = Global.DaoFactory.GetFileDao())
            {
                if (fileDao.IsSupportedPreSignedUri(file))
                {
                    int validateTimespan;
                    int.TryParse(WebConfigurationManager.AppSettings["files.stream-url-minute"], out validateTimespan);
                    if (validateTimespan <= 0)
                    {
                        validateTimespan = 10;
                    }
                    var uri = fileDao.GetPreSignedUri(file, TimeSpan.FromMinutes(validateTimespan)).ToString();
                    if (uri.Length < uriLengthLimit)
                    {
                        return(uri);
                    }
                    Global.Logger.Debug("Very long link: " + uri.Length);
                }
            }

            //NOTE: Always build path to handler!
            var uriBuilder = new UriBuilder(CommonLinkUtility.GetFullAbsolutePath(FilesLinkUtility.FileHandlerPath));

            if (uriBuilder.Uri.IsLoopback)
            {
                uriBuilder.Host = Dns.GetHostName();
            }
            var query = uriBuilder.Query;

            query += FilesLinkUtility.Action + "=stream&";
            query += FilesLinkUtility.FileId + "=" + HttpUtility.UrlEncode(file.ID.ToString()) + "&";
            query += FilesLinkUtility.Version + "=" + file.Version + "&";
            query += FilesLinkUtility.AuthKey + "=" + EmailValidationKeyProvider.GetEmailKey(file.ID + file.Version.ToString(CultureInfo.InvariantCulture));

            return(uriBuilder.Uri + "?" + query);
        }
Exemplo n.º 2
0
        public static string GetFileStreamUrl(File file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file", FilesCommonResource.ErrorMassage_FileNotFound);
            }

            const int uriLengthLimit = 1024;
            string    fileUri        = null;

            if (!DocumentServiceHelper.HaveExternalIP())
            {
                fileUri = DocumentServiceHelper.GetExternalUri(file);
            }

            if (!string.IsNullOrEmpty(fileUri))
            {
                return(fileUri);
            }

            using (var fileDao = Global.DaoFactory.GetFileDao())
            {
                if (fileDao.IsSupportedPreSignedUri(file))
                {
                    var uri = fileDao.GetPreSignedUri(file, Global.StreamUrlExpire).ToString();
                    if (uri.Length < uriLengthLimit)
                    {
                        return(uri);
                    }
                    Global.Logger.Debug("Very long link: " + uri.Length);
                }
            }

            //NOTE: Always build path to handler!
            var uriBuilder = new UriBuilder(CommonLinkUtility.GetFullAbsolutePath(FilesLinkUtility.FileHandlerPath));

            Global.Logger.Debug("FileStreamUrl: " + uriBuilder.Uri);
            var query = uriBuilder.Query;

            query += FilesLinkUtility.Action + "=stream&";
            query += FilesLinkUtility.FileId + "=" + HttpUtility.UrlEncode(file.ID.ToString()) + "&";
            query += FilesLinkUtility.Version + "=" + file.Version + "&";
            query += FilesLinkUtility.AuthKey + "=" + EmailValidationKeyProvider.GetEmailKey(file.ID + file.Version.ToString(CultureInfo.InvariantCulture));

            return(uriBuilder.Uri + "?" + query);
        }