Esempio n. 1
0
        static UrlType GetUrlType(string url)
        {
            UrlType urlType = UrlType.Local;

            if (AzureHelper.MatchHandler(url))
            {
                urlType = UrlType.Azure;
            }
            else if (AzureHelper.MatchFileHandler(url))
            {
                urlType = UrlType.AzureFile;
            }
            else if (S3Helper.MatchHandler(url))
            {
                urlType = UrlType.S3;
            }
            else if (SkyDriveHelper.MatchHandler(url))
            {
                urlType = UrlType.SkyDrive;
            }
            else if (SharepointHelper.MatchHandler(url))
            {
                urlType = UrlType.Sharepoint;
            }
            else if (DropboxHelper.MatchHandler(url))
            {
                urlType = UrlType.Dropbox;
            }
            else
            {
                urlType = UrlType.Local;  // local filesystem.
            }

            return(urlType);
        }
Esempio n. 2
0
        /// <summary>
        /// Makes a usable URL for a blob. This will need to handle security on the source blob.
        /// Each cloud provider is different.
        /// Cloud providers developed:
        ///     Azure
        ///     S3xx
        ///
        /// Cloud providers soon:
        ///     Dropbox
        ///     Onedrive
        /// </summary>
        /// <param name="origBlob"></param>
        /// <returns></returns>
        private static string GeneratedAccessibleUrl(BasicBlobContainer origBlob)
        {
            var    sourceUrl = origBlob.Url; // +"/" + origBlob.Name;
            string url       = "";

            // if S3, then generate signed url.
            if (S3Helper.MatchHandler(sourceUrl))
            {
                var bucket = S3Helper.GetBucketFromUrl(sourceUrl);
                var key    = origBlob.Name;
                url = S3Helper.GeneratePreSignedUrl(bucket, key);
            }
            else if (AzureHelper.MatchHandler(sourceUrl))
            {
                // generate Azure signed url.
                var client = AzureHelper.GetSourceCloudBlobClient(sourceUrl);
                var policy = new SharedAccessBlobPolicy();
                policy.SharedAccessStartTime  = DateTime.UtcNow.AddMinutes(-1);
                policy.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(ConfigHelper.SharedAccessSignatureDurationInSeconds / 60);
                policy.Permissions            = SharedAccessBlobPermissions.Read;
                var blob = client.GetBlobReferenceFromServer(new Uri(sourceUrl));
                url = sourceUrl + blob.GetSharedAccessSignature(policy);
            }
            else if (DropboxHelper.MatchHandler(sourceUrl))
            {
                // need shorter url. (no base url);
                var uri      = new Uri(sourceUrl);
                var shortUrl = uri.PathAndQuery;
                var client   = DropboxHelper.GetClient();
                var media    = client.GetMedia(shortUrl);
                return(media.Url);
            }
            else if (SkyDriveHelper.MatchHandler(sourceUrl))
            {
                throw new NotImplementedException("Blobcopy against onedrive is not implemented yet");
            }

            Console.WriteLine("shared url is {0}", url);
            return(url);
        }