Beispiel #1
0
        public override FileProperties GetFilePropertiesFromCDN(IFileQuery qryFile)
        {
            var blob = GetBlob(qryFile);

            try
            {
                blob.FetchAttributes();
                FileProperties props = new FileProperties();
                props.MetaData     = blob.Metadata;
                props.Source       = blob.Properties;
                props.Length       = blob.Properties.Length;
                props.ContentMD5   = blob.Properties.ContentMD5;
                props.ETag         = blob.Properties.ETag;
                props.ContentType  = blob.Properties.ContentType;
                props.LastModified = blob.Properties.LastModified;
                props.Created      = props.LastModified;
                props.URL          = blob.Uri.ToString();
                return(props);
            }
            catch (Microsoft.Azure.Storage.StorageException ex)
            {
                if (ex.RequestInformation.HttpStatusCode == (int)System.Net.HttpStatusCode.NotFound)
                {
                    return(null);
                }
                throw;
            }
        }
        public override FileProperties GetFilePropertiesFromCDN(IFileQuery qryFile)
        {
            try
            {
                var            objRef = S3TransferUtil.S3Client.GetObjectMetadata(GetCDNFolderPath(qryFile, true), GetFileName(qryFile));
                FileProperties props  = new FileProperties();
                props.Source        = objRef;
                props.Length        = objRef.ContentLength;
                props.ETag          = objRef.ETag;
                props.VersionNumber = objRef.VersionId;
                props.ContentMD5    = objRef.Headers.ContentMD5;
                props.ContentType   = objRef.Headers.ContentType;
                props.LastModified  = new DateTimeOffset(objRef.LastModified);
                props.Created       = props.LastModified;
                props.URL           = GetCDNURL(qryFile);

                if (objRef.Metadata != null)
                {
                    props.MetaData = new Dictionary <string, string>();
                    foreach (var key in objRef.Metadata.Keys)
                    {
                        props.MetaData.Add(key, objRef.Metadata[key]);
                    }
                }
                return(props);
            }
            catch (Amazon.S3.AmazonS3Exception ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    return(null);
                }
                throw;
            }
        }
Beispiel #3
0
 public FileProperties GetFilePropertiesLocal(IFileQuery qryFile)
 {
     try
     {
         var            objFileInfo = new System.IO.FileInfo(GetLocalDiskPath(qryFile));
         FileProperties props       = new FileProperties();
         props.Source       = objFileInfo;
         props.Length       = objFileInfo.Length;
         props.LastModified = new DateTimeOffset(objFileInfo.LastWriteTimeUtc);
         props.Created      = new DateTimeOffset(objFileInfo.CreationTimeUtc);
         props.URL          = GetLocalURL(qryFile);
         return(props);
     }
     catch (System.IO.FileNotFoundException) { return(null); }
     catch (System.IO.DirectoryNotFoundException) { return(null); }
 }
Beispiel #4
0
        public bool IsCurrentVersionOf(FileProperties fileMaster)
        {
            //First line of defense, different size means different versions
            if (this.Length != fileMaster.Length)
            {
                return(false);
            }

            //Modify date is not reliable because the local file might retain the original modify date, while the remote CDN only stores a Create Date (the moment it was stored to the CDN)
            //if (this.LastModified.HasValue && fileMaster.LastModified.HasValue)
            //    if (fileMaster.LastModified > this.LastModified)
            //        return false;

            //Apparently this isn't reliable either
            //if (this.Created.HasValue && fileMaster.Created.HasValue)
            //    if (fileMaster.Created > this.Created)
            //        return false;

            //Now I'll do an MD5 check in some cases
            if (String.IsNullOrEmpty(this.ContentMD5) && !String.IsNullOrEmpty(fileMaster.ContentMD5) && this.Source is System.IO.FileInfo)
            {
                if (this.Length < 10000000) //10 MB
                {
                    //Load MD5 for local file
                    System.IO.FileInfo objInfo = (System.IO.FileInfo) this.Source;
                    using (var md5 = System.Security.Cryptography.MD5.Create())
                    {
                        using (var stream = System.IO.File.OpenRead(objInfo.FullName))
                        {
                            this.ContentMD5 = Convert.ToBase64String(md5.ComputeHash(stream));
                        }
                    }
                }
            }
            if (!String.IsNullOrEmpty(this.ContentMD5) && !String.IsNullOrEmpty(fileMaster.ContentMD5))
            {
                if (fileMaster.ContentMD5 != this.ContentMD5)
                {
                    return(false); //MD5 hash didn't match
                }
            }
            //We'll assume they are the same, this will be accurate most of the time
            return(true);
        }
Beispiel #5
0
        public bool IsCurrentVersionOf(FileProperties fileMaster)
        {
            //First line of defense, different size means different versions
            if (this.Length != fileMaster.Length)
                return false;

            //Modify date is not reliable because the local file might retain the original modify date, while the remote CDN only stores a Create Date (the moment it was stored to the CDN)
            //if (this.LastModified.HasValue && fileMaster.LastModified.HasValue)
            //    if (fileMaster.LastModified > this.LastModified)
            //        return false;

            //Apparently this isn't reliable either
            //if (this.Created.HasValue && fileMaster.Created.HasValue)
            //    if (fileMaster.Created > this.Created)
            //        return false;

            //Now I'll do an MD5 check in some cases
            if (String.IsNullOrEmpty(this.ContentMD5) && !String.IsNullOrEmpty(fileMaster.ContentMD5) && this.Source is System.IO.FileInfo)
            {
                if (this.Length < 10000000) //10 MB
                {
                    //Load MD5 for local file
                    System.IO.FileInfo objInfo = (System.IO.FileInfo) this.Source;
                    using (var md5 = System.Security.Cryptography.MD5.Create())
                    {
                        using (var stream = System.IO.File.OpenRead(objInfo.FullName))
                        {
                            this.ContentMD5 = Convert.ToBase64String(md5.ComputeHash(stream));
                        }
                    }
               } 
            }
            if (!String.IsNullOrEmpty(this.ContentMD5) && !String.IsNullOrEmpty(fileMaster.ContentMD5))
                if (fileMaster.ContentMD5 != this.ContentMD5)
                    return false; //MD5 hash didn't match

            //We'll assume they are the same, this will be accurate most of the time
            return true;
        }
Beispiel #6
0
 public FileProperties GetFilePropertiesLocal(IFileQuery qryFile)
 {
     try
     {
         var objFileInfo = new System.IO.FileInfo(GetLocalDiskPath(qryFile));
         FileProperties props = new FileProperties();
         props.Source = objFileInfo;
         props.Length = objFileInfo.Length;
         props.LastModified = new DateTimeOffset(objFileInfo.LastWriteTimeUtc);
         props.Created = new DateTimeOffset(objFileInfo.CreationTimeUtc);
         props.URL = GetLocalURL(qryFile);
         return props;
     }
     catch (System.IO.FileNotFoundException) { return null; }
     catch (System.IO.DirectoryNotFoundException) { return null; }
 }
        public override FileProperties GetFilePropertiesFromCDN(IFileQuery qryFile)
        {
            try
            {
                var objRef = S3TransferUtil.S3Client.GetObjectMetadata(GetCDNFolderPath(qryFile, true), GetFileName(qryFile));
                FileProperties props = new FileProperties();
                props.Source = objRef;
                props.Length = objRef.ContentLength;
                props.ETag = objRef.ETag;
                props.VersionNumber = objRef.VersionId;
                props.ContentMD5 = objRef.Headers.ContentMD5;
                props.ContentType = objRef.Headers.ContentType;
                props.LastModified = new DateTimeOffset(objRef.LastModified);
                props.Created = props.LastModified;
                props.URL = GetCDNURL(qryFile);

                if (objRef.Metadata != null)
                {
                    props.MetaData = new Dictionary<string, string>();
                    foreach (var key in objRef.Metadata.Keys) {
                        props.MetaData.Add(key, objRef.Metadata[key]);
                    }
                }
                return props;
            }
            catch (Amazon.S3.AmazonS3Exception ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
                    return null;
                throw;
            }
        }