Example #1
0
        public override FileServerResult StoreImage(System.Drawing.Image objImage, IFileQuery qryFileDestination, System.Drawing.Imaging.ImageFormat enuFormat = null)
        {
            if (CDNOnly)
            {
                var result = new FileServerResult(true);
                var blob   = GetBlobForStorage(qryFileDestination);
                using (System.IO.MemoryStream stmImage = new System.IO.MemoryStream())
                {
                    if (enuFormat != null)
                    {
                        objImage.Save(stmImage, enuFormat);
                    }
                    else
                    {
                        objImage.Save(stmImage, objImage.RawFormat);
                    }

                    stmImage.Seek(0, SeekOrigin.Begin);
                    blob.UploadFromStream(stmImage);
                }
                result.Uri = blob.Uri;
                return(result);
            }
            else
            {
                var result = base.WriteImageLocal(objImage, qryFileDestination, enuFormat);
                if (result.Success)
                {
                    var blob = GetBlobForStorage(qryFileDestination);
                    blob.UploadFromFile(GetLocalDiskPath(qryFileDestination));
                    result.Uri = blob.Uri;
                }
                return(result);
            }
        }
        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;
            }
        }
Example #3
0
        protected CloudBlockBlob GetBlob(IFileQuery qryFile)
        {
            CloudBlobContainer objAzureContainer = AzureBlobClient.GetContainerReference(Settings.CDNStorageBucket);
            CloudBlockBlob     blockBlob         = objAzureContainer.GetBlockBlobReference(GetCDNPath(qryFile, false));

            return(blockBlob);
        }
Example #4
0
 public virtual Task <FileServerResult> StoreImageAsync(Image objImage, IFileQuery qryFileDestination, System.Drawing.Imaging.ImageFormat enuFormat = null)
 {
     return(Task.Factory.StartNew(() =>
     {
         return StoreImage(objImage, qryFileDestination, enuFormat);
     }));
 }
Example #5
0
 public virtual Task <FileServerResult> DeleteAsync(IFileQuery qryFile)
 {
     return(Task.Factory.StartNew(() =>
     {
         return Delete(qryFile);
     }));
 }
Example #6
0
 public Task <FileServerResult> WriteImageLocalAsync(Image objImage, IFileQuery qryFile, System.Drawing.Imaging.ImageFormat enuFormat = null)
 {
     return(Task.Factory.StartNew(() =>
     {
         return WriteImageLocal(objImage, qryFile, enuFormat);
     }));
 }
Example #7
0
        private CloudBlockBlob GetBlobForStorage(IFileQuery qryFileDestination)
        {
            var blockBlob = GetBlob(qryFileDestination);

            try
            {
                blockBlob.Properties.ContentType = Web.MimeTypeMap.GetMimeType(System.IO.Path.GetExtension(qryFileDestination.FileName));
            }
            catch { }

            #region Meta Data
            blockBlob.Metadata.Add("FileName", qryFileDestination.FileName);
            if (!String.IsNullOrWhiteSpace(qryFileDestination.Folder))
            {
                blockBlob.Metadata.Add("Folder", qryFileDestination.Folder);
            }
            if (!String.IsNullOrWhiteSpace(qryFileDestination.SubFolder))
            {
                blockBlob.Metadata.Add("SubFolder", qryFileDestination.SubFolder);
            }

            foreach (var item in qryFileDestination.MetaData)
            {
                blockBlob.Metadata.Add(item);
            }
            #endregion

            return(blockBlob);
        }
Example #8
0
 public Task <FileServerResult> WriteFileLocalAsync(System.IO.Stream stmFile, IFileQuery qryFile)
 {
     return(Task.Factory.StartNew(() =>
     {
         return WriteFileLocal(stmFile, qryFile);
     }));
 }
Example #9
0
 public Task <FileServerResult> WriteFileLocalAsync(string strSourceFilePath, IFileQuery qryFile)
 {
     return(Task.Factory.StartNew(() =>
     {
         return WriteFileLocal(strSourceFilePath, qryFile);
     }));
 }
Example #10
0
        private TransferUtilityUploadRequest GetUploadRequest(IFileQuery qryFileDestination)
        {
            TransferUtilityUploadRequest fileTransferUtilityRequest = new TransferUtilityUploadRequest
            {
                BucketName   = GetCDNFolderPath(qryFileDestination, true),
                StorageClass = StorageClass,
                Key          = GetFileName(qryFileDestination),
                CannedACL    = CurrentACL
            };

            #region Meta Data
            fileTransferUtilityRequest.Metadata.Add("FileName", qryFileDestination.FileName);
            if (!String.IsNullOrWhiteSpace(qryFileDestination.Folder))
            {
                fileTransferUtilityRequest.Metadata.Add("Folder", qryFileDestination.Folder);
            }
            if (!String.IsNullOrWhiteSpace(qryFileDestination.SubFolder))
            {
                fileTransferUtilityRequest.Metadata.Add("SubFolder", qryFileDestination.SubFolder);
            }

            foreach (var item in qryFileDestination.MetaData)
            {
                fileTransferUtilityRequest.Metadata.Add(item.Key, item.Value);
            }
            #endregion

            return(fileTransferUtilityRequest);
        }
Example #11
0
        public string GetFolderPath(IFileQuery qryFile)
        {
            if (!String.IsNullOrWhiteSpace(qryFile.SubFolder))
            {
                qryFile.SubFolder = CleanPathSegment(qryFile.SubFolder);
                if (!String.IsNullOrWhiteSpace(qryFile.SubFolder) && !qryFile.SubFolder.EndsWith("/"))
                {
                    qryFile.SubFolder = qryFile.SubFolder + "/";
                }
            }

            if (!String.IsNullOrWhiteSpace(qryFile.Folder) && !String.IsNullOrWhiteSpace(qryFile.SubFolder))
            {
                return(qryFile.Folder + "/" + qryFile.SubFolder);
            }
            else if (!String.IsNullOrWhiteSpace(qryFile.Folder))
            {
                return(qryFile.Folder);
            }
            else if (!String.IsNullOrWhiteSpace(qryFile.SubFolder))
            {
                return(qryFile.SubFolder);
            }
            else
            {
                return("");
            }
        }
Example #12
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;
            }
        }
Example #13
0
 public Task <FileServerResult> DeleteFileLocalAsync(IFileQuery qryFile)
 {
     return(Task.Factory.StartNew(() =>
     {
         return DeleteFileLocal(qryFile);
     }));
 }
Example #14
0
 public bool FileExistsLocal(IFileQuery qryFile)
 {
     if (Settings.DisableLocalStorage)
     {
         return(false);
     }
     return(System.IO.File.Exists(GetLocalDiskPath(qryFile)));
 }
Example #15
0
 public Image LoadImageLocal(IFileQuery qryFile)
 {
     if (!FileExistsLocal(qryFile))
     {
         return(null);
     }
     return(new Bitmap(GetLocalDiskPath(qryFile)));
 }
Example #16
0
 public string LoadFileTextLocal(IFileQuery qryFile, System.Text.Encoding encoding)
 {
     if (!FileExistsLocal(qryFile))
     {
         return(null);
     }
     return(System.IO.File.ReadAllText(GetLocalDiskPath(qryFile), encoding));
 }
Example #17
0
 public byte[] LoadFileBytesLocal(IFileQuery qryFile)
 {
     if (!FileExistsLocal(qryFile))
     {
         return(null);
     }
     return(System.IO.File.ReadAllBytes(GetLocalDiskPath(qryFile)));
 }
Example #18
0
 public System.IO.FileStream LoadFileStreamLocal(IFileQuery qryFile)
 {
     if (!FileExistsLocal(qryFile))
     {
         return(null);
     }
     return(System.IO.File.OpenRead(GetLocalDiskPath(qryFile)));
 }
Example #19
0
 public FileServerResult DeleteFileLocal(IFileQuery qryFile)
 {
     if (FileExistsLocal(qryFile))
     {
         System.IO.File.Delete(GetLocalDiskPath(qryFile));
     }
     return(FileServerResult.Successful());
 }
Example #20
0
 public string GetFileName(IFileQuery qryFile)
 {
     if (!String.IsNullOrWhiteSpace(Settings.GlobalFileNamePrepend))
     {
         return(Settings.GlobalFileNamePrepend + qryFile.FileName);
     }
     return(qryFile.FileName);
 }
Example #21
0
 public FileService(IFileQuery fileQuery,
                    IFileUpsertCommand fileCommand,
                    IApplicationContext cntx)
 {
     this.fileQuery   = fileQuery;
     this.fileCommand = fileCommand;
     this.cntx        = cntx;
 }
Example #22
0
 public override System.IO.Stream LoadFileStream(IFileQuery qryFile)
 {
     if (FileExpiredLocal(qryFile))
     {
         SaveFromCDN(qryFile);
     }
     return(base.LoadFileStream(qryFile));
 }
Example #23
0
 public override byte[] LoadFileBytes(IFileQuery qryFile)
 {
     if (FileExpiredLocal(qryFile))
     {
         SaveFromCDN(qryFile);
     }
     return(base.LoadFileBytes(qryFile));
 }
Example #24
0
 public override System.Drawing.Image LoadImage(IFileQuery qryFile)
 {
     if (FileExpiredLocal(qryFile))
     {
         SaveFromCDN(qryFile);
     }
     return(base.LoadImage(qryFile));
 }
Example #25
0
 public override string LoadFileText(IFileQuery qryFile)
 {
     if (FileExpiredLocal(qryFile))
     {
         SaveFromCDN(qryFile);
     }
     return(base.LoadFileText(qryFile));
 }
Example #26
0
 public override string LoadFileText(IFileQuery qryFile, System.Text.Encoding encoding)
 {
     if (FileExpiredLocal(qryFile))
     {
         SaveFromCDN(qryFile);
     }
     return(base.LoadFileText(qryFile, encoding));
 }
Example #27
0
 public FileServerResult WriteImageLocal(string strSourceImagePath, IFileQuery qryFile)
 {
     if (Settings.LocalReadOnlyMode)
     {
         return(FileServerResult.Failure());
     }
     System.IO.File.Copy(strSourceImagePath, GetAndCreateLocalDiskPath(qryFile), Settings.OverwriteExistingFiles);
     return(FileServerResult.Successful());
 }
Example #28
0
        public override FileServerResult StoreImage(string strSourceImagePath, IFileQuery qryFileDestination)
        {
            var result = new FileServerResult(false);
            var blob   = GetBlobForStorage(qryFileDestination);

            blob.UploadFromFile(strSourceImagePath);
            result = base.WriteImageLocal(strSourceImagePath, qryFileDestination);
            return(result);
        }
Example #29
0
 public bool ImportIfNeeded(IFileQuery qryFile)
 {
     if (FileExistsLocal(qryFile) && !FileExistsInCDN(qryFile))
     {
         PushToCDN(qryFile);
         return(true);
     }
     return(false);
 }
Example #30
0
        private void SaveFromCDN(IFileQuery qryFile)
        {
            var blockBlobToDownload = GetBlob(qryFile);

            using (var fileStream = System.IO.File.OpenWrite(GetAndCreateLocalDiskPath(qryFile)))
            {
                blockBlobToDownload.DownloadToStream(fileStream);
            }
        }
Example #31
0
 public override bool FileExpiredLocal(IFileQuery qryFile)
 {
     var propsLocal = GetFilePropertiesLocal(qryFile);
     if (propsLocal == null)
         return true;
     var propsCDN = GetFilePropertiesFromCDN(qryFile);
     if (propsCDN == null)
         return false;
     return !propsLocal.IsCurrentVersionOf(propsCDN);
 }
Example #32
0
 public virtual Task<FileServerResult> StoreImageAsync(string strSourceImagePath, IFileQuery qryFileDestination)
 {
     return Task.Factory.StartNew(() =>
     {
         return StoreImage(strSourceImagePath, qryFileDestination);
     });
 }
Example #33
0
 public virtual FileServerResult Delete(IFileQuery qryFile)
 {
     return DeleteFileLocal(qryFile);
 }
Example #34
0
 public virtual Task<FileServerResult> StoreImageAsync(System.IO.Stream stmImage, IFileQuery qryFileDestination, System.Drawing.Imaging.ImageFormat enuFormat = null)
 {
     return Task.Factory.StartNew(() =>
     {
         return StoreImage(stmImage, qryFileDestination, enuFormat);
     });
 }
Example #35
0
 public virtual FileServerResult StoreImage(string strSourceImagePath, IFileQuery qryFileDestination)
 {
     return WriteImageLocal(strSourceImagePath, qryFileDestination);
 }
Example #36
0
 public virtual System.IO.Stream LoadFileStream(IFileQuery qryFile)
 {
     return LoadFileStreamLocal(qryFile);
 }
Example #37
0
 public virtual FileServerResult StoreImage(System.IO.Stream stmImage, IFileQuery qryFileDestination, System.Drawing.Imaging.ImageFormat enuFormat = null)
 {
     return WriteImageLocal(stmImage, qryFileDestination, enuFormat);
 }
Example #38
0
 public FileServerResult WriteImageLocal(System.IO.Stream stmImage, IFileQuery qryFile, System.Drawing.Imaging.ImageFormat enuFormat = null)
 {
     if (Settings.LocalReadOnlyMode)
         return FileServerResult.Failure;
     if (Settings.OverwriteExistingFiles)
         DeleteFileLocal(qryFile);
     using (Image img = System.Drawing.Image.FromStream(stmImage))
     {
         if (enuFormat != null)
             img.Save(GetAndCreateLocalDiskPath(qryFile), enuFormat);
         else
             img.Save(GetAndCreateLocalDiskPath(qryFile));
     }
     return FileServerResult.Successful;
 }
Example #39
0
 public Task<FileServerResult> WriteImageLocalAsync(Image objImage, IFileQuery qryFile, System.Drawing.Imaging.ImageFormat enuFormat = null)
 {
     return Task.Factory.StartNew(() =>
     {
         return WriteImageLocal(objImage, qryFile, enuFormat);
     });
 }
Example #40
0
 public FileServerResult WriteImageLocal(string strSourceImagePath, IFileQuery qryFile)
 {
     if (Settings.LocalReadOnlyMode)
         return FileServerResult.Failure;
     System.IO.File.Copy(strSourceImagePath, GetAndCreateLocalDiskPath(qryFile), Settings.OverwriteExistingFiles);
     return FileServerResult.Successful;
 }
Example #41
0
 public FileServerResult WriteFileLocal(System.IO.Stream stmFile, IFileQuery qryFile)
 {
     if (Settings.LocalReadOnlyMode)
         return FileServerResult.Failure;
     if (Settings.OverwriteExistingFiles)
         DeleteFileLocal(qryFile);
     using (var writer = new System.IO.StreamWriter(GetAndCreateLocalDiskPath(qryFile)))
     {
         stmFile.Seek(0, System.IO.SeekOrigin.Begin);
         stmFile.CopyTo(writer.BaseStream);
         writer.Close();
     }
     return FileServerResult.Successful;
 }
Example #42
0
 public virtual string LoadFileText(IFileQuery qryFile, System.Text.Encoding encoding)
 {
     return LoadFileTextLocal(qryFile, encoding);
 }
Example #43
0
 public virtual string LoadFileText(IFileQuery qryFile)
 {
     return LoadFileTextLocal(qryFile);
 }
Example #44
0
 public virtual byte[] LoadFileBytes(IFileQuery qryFile)
 {
     return LoadFileBytesLocal(qryFile);
 }
Example #45
0
 public virtual Task<FileServerResult> DeleteAsync(IFileQuery qryFile)
 {
     return Task.Factory.StartNew(() =>
     {
         return Delete(qryFile);
     });
 }
Example #46
0
 public virtual string GetCDNURL(IFileQuery qryFile)
 {
     throw new NotImplementedException("No remote server has been specified for file retrieval");
 }
Example #47
0
 public virtual bool FileExpiredLocal(IFileQuery qryFile)
 {
     throw new NotImplementedException("No remote server has been specified to check expiration");
 }
Example #48
0
 public Task<FileServerResult> WriteFileFromStringLocalAsync(string strFileBody, IFileQuery qryFile)
 {
     return Task.Factory.StartNew(() =>
     {
         return WriteFileFromStringLocal(strFileBody, qryFile);
     });
 }
Example #49
0
 public FileServerResult WriteImageLocal(Image objImage, IFileQuery qryFile, System.Drawing.Imaging.ImageFormat enuFormat = null)
 {
     if (Settings.LocalReadOnlyMode)
         return FileServerResult.Failure;
     if (Settings.OverwriteExistingFiles)
         DeleteFileLocal(qryFile);
     if (enuFormat != null)
         objImage.Save(GetAndCreateLocalDiskPath(qryFile), enuFormat);
     else
         objImage.Save(GetAndCreateLocalDiskPath(qryFile));
     return FileServerResult.Successful;
 }
Example #50
0
 public virtual FileProperties GetFilePropertiesFromCDN(IFileQuery qryFile)
 {
     throw new NotImplementedException("No remote server has been specified to check file dates");
 }
Example #51
0
 public virtual Image LoadImage(IFileQuery qryFile)
 {
     return LoadImageLocal(qryFile);
 }
Example #52
0
 public Task<FileServerResult> WriteImageLocalAsync(string strSourceImagePath, IFileQuery qryFile)
 {
     return Task.Factory.StartNew(() =>
     {
         return WriteImageLocal(strSourceImagePath, qryFile);
     });
 }
Example #53
0
 public Task<FileServerResult> WriteFileLocalAsync(System.IO.Stream stmFile, IFileQuery qryFile)
 {
     return Task.Factory.StartNew(() =>
     {
         return WriteFileLocal(stmFile, qryFile);
     });
 }
Example #54
0
 public virtual FileServerResult StoreFile(System.IO.Stream stmFile, IFileQuery qryFileDestination)
 {
     return WriteFileLocal(stmFile, qryFileDestination);
 }
Example #55
0
 public Task<FileServerResult> DeleteFileLocalAsync(IFileQuery qryFile)
 {
     return Task.Factory.StartNew(() =>
     {
         return DeleteFileLocal(qryFile);
     });
 }
Example #56
0
 public virtual Task<FileServerResult> StoreFileAsync(System.IO.Stream stmFile, IFileQuery qryFileDestination)
 {
     return Task.Factory.StartNew(() =>
     {
         return StoreFile(stmFile, qryFileDestination);
     });
 }
Example #57
0
 public virtual FileServerResult StoreFileFromString(string strFileBody, IFileQuery qryFileDestination, System.Text.Encoding encoding = null)
 {
     return WriteFileFromStringLocal(strFileBody, qryFileDestination, encoding);
 }
Example #58
0
 public virtual Task<FileServerResult> StoreFileFromStringAsync(string strSourceFilePath, IFileQuery qryFileDestination, System.Text.Encoding encoding = null)
 {
     return Task.Factory.StartNew(() =>
     {
         return StoreFileFromString(strSourceFilePath, qryFileDestination, encoding);
     });
 }
Example #59
0
 public virtual bool FileExistsInCDN(IFileQuery qryFile)
 {
     throw new NotImplementedException("No remote server has been specified to check existance");
 }
Example #60
0
 public FileServerResult WriteFileFromStringLocal(string strFileBody, IFileQuery qryFile, System.Text.Encoding encoding = null)
 {
     if (Settings.LocalReadOnlyMode)
         return FileServerResult.Failure;
     if (encoding != null)
         System.IO.File.WriteAllText(GetAndCreateLocalDiskPath(qryFile), strFileBody, encoding);
     else
         System.IO.File.WriteAllText(GetAndCreateLocalDiskPath(qryFile), strFileBody);
     return FileServerResult.Successful;
 }