예제 #1
0
        /// <summary>
        /// Copies the specified folder element.
        /// </summary>
        /// <param name="folderElement">The folder element.</param>
        /// <param name="newParentId">The parent id.</param>
        public static void Copy(FolderElement folderElement, int parentId)
        {
            FolderElement newElement = null;

            BlobInfo blobInfo    = folderElement.GetBlobInfo();
            BlobInfo blobInfoNew = (BlobInfo)blobInfo.Clone();

            blobInfoNew.Uid = Guid.NewGuid();

            BlobStorageProvider provider = BlobStorage.Providers[folderElement.BlobStorageProvider];

            using (Stream srcStream = provider.ReadStream(blobInfo))
            {
                using (Stream dstStream = provider.CreateStream(blobInfoNew))
                {
                    BlobStreamHelper.WriteToStream(dstStream, srcStream, 0, srcStream.Length);
                    provider.CommitStream(blobInfoNew);
                }
            }

            newElement         = (FolderElement)folderElement.Clone();
            newElement.BlobUid = blobInfoNew.Uid;
            newElement.Save();

            Move(newElement, parentId);
        }
예제 #2
0
        /// <summary>
        /// Creates the specified parent id.
        /// </summary>
        /// <param name="parentId">The parent id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="srcStream">The SRC stream.</param>
        /// <returns></returns>
        public static FolderElement Create(int parentId, string fileName,
                                           Stream srcStream, Guid progressUid)
        {
            FolderElement retVal   = new FolderElement();
            BlobInfo      blobInfo = new BlobInfo(Guid.NewGuid());

            retVal.ParentId = parentId;

            //Try recognize provider from config setings
            BlobStorageProvider provider = BlobStorage.Provider;
            String providerName;
            String contentType = Mediachase.Ibn.Blob.ContentTypeResolver.ContentType.ResolveByPath(fileName);
            long   fileSize    = srcStream.Length;

            if (TryRecognizeStorageProvider(retVal, fileName, contentType,
                                            fileSize, out providerName))
            {
                provider = BlobStorage.Providers[providerName];
            }

            blobInfo.FileName    = fileName;
            blobInfo.Provider    = provider.Name;
            blobInfo.Created     = DateTime.UtcNow;
            blobInfo.ContentSize = fileSize;
            blobInfo.ContentType = contentType;
            //Content type assigned by provider

            //Save blob info to storage
            using (Stream dstStream = provider.CreateStream(blobInfo))
            {
                //BlobStreamHelper.WriteToStream(dstStream, srcStream, 0, fileSize);
                WriteToStream(dstStream, srcStream, 0, fileSize, progressUid);
            }

            provider.CommitStream(blobInfo);

            retVal.BlobStorageProvider = provider.Name;
            retVal.BlobUid             = blobInfo.Uid;
            retVal.Created             = DateTime.UtcNow;
            retVal.Name = blobInfo.FileName;
            if (retVal.Properties.Contains("ContentSize"))
            {
                retVal.Properties["ContentSize"].Value = (Int32)blobInfo.ContentSize;
            }
            if (retVal.Properties.Contains("ContentType"))
            {
                retVal.Properties["ContentType"].Value = blobInfo.ContentType;
            }

            //try
            IFolderElementExtension folderEl = GetCfgFolderElementExtension(blobInfo);

            if (folderEl != null)
            {
                folderEl.Process(retVal);
            }

            retVal.Save();
            return(retVal);
        }
예제 #3
0
 /// <summary>
 /// Moves the specified folder element.
 /// </summary>
 /// <param name="folderElement">The folder element.</param>
 /// <param name="newParentId">The new parent id.</param>
 public static void Move(FolderElement folderElement, int newParentId)
 {
     folderElement.ParentId = newParentId;
     folderElement.Save();
 }