private void GenerateFile(FileNode fileNode, CloudBlob cloudBlob, List <FileNode> snapshotList)
        {
            this.CheckFileNode(fileNode);

            if ((StorageBlob.BlobType.PageBlob == cloudBlob.BlobType) && (fileNode.SizeInByte % 512 != 0))
            {
                throw new InvalidOperationException(string.Format("Can only generate page blob which size is multiple of 512bytes. Expected size is {0}", fileNode.SizeInByte));
            }

            string tempFileName  = Guid.NewGuid().ToString();
            string localFilePath = Path.Combine(this.TempFolder, tempFileName);

            DMLibDataHelper.CreateLocalFile(fileNode, localFilePath);

            BlobRequestOptions storeMD5Options = new BlobRequestOptions()
            {
                RetryPolicy         = new LinearRetry(TimeSpan.FromSeconds(90), 3),
                StoreBlobContentMD5 = true,
            };

            cloudBlob.UploadFromFile(localFilePath, null, storeMD5Options);

            if (null != fileNode.MD5 ||
                null != fileNode.ContentType ||
                null != fileNode.CacheControl ||
                null != fileNode.ContentDisposition ||
                null != fileNode.ContentEncoding ||
                null != fileNode.ContentLanguage)
            {
                cloudBlob.Properties.ContentMD5         = fileNode.MD5;
                cloudBlob.Properties.ContentType        = fileNode.ContentType;
                cloudBlob.Properties.CacheControl       = fileNode.CacheControl;
                cloudBlob.Properties.ContentDisposition = fileNode.ContentDisposition;
                cloudBlob.Properties.ContentEncoding    = fileNode.ContentEncoding;
                cloudBlob.Properties.ContentLanguage    = fileNode.ContentLanguage;
                cloudBlob.SetProperties(options: HelperConst.DefaultBlobOptions);
            }

            if (null != fileNode.Metadata && fileNode.Metadata.Count > 0)
            {
                cloudBlob.Metadata.Clear();
                foreach (var metaData in fileNode.Metadata)
                {
                    cloudBlob.Metadata.Add(metaData);
                }

                cloudBlob.SetMetadata(options: HelperConst.DefaultBlobOptions);
            }

            cloudBlob.FetchAttributes(options: HelperConst.DefaultBlobOptions);
            this.BuildFileNode(cloudBlob, fileNode);

            for (int i = 0; i < fileNode.SnapshotsCount; ++i)
            {
                CloudBlob snapshot = cloudBlob.Snapshot();
                snapshotList.Add(this.BuildSnapshotFileNode(snapshot, fileNode.Name));
            }
        }
        private void GenerateFile(FileNode fileNode, CloudFile cloudFile, string parentPath)
        {
            this.CheckFileNode(fileNode);

            string tempFileName  = Guid.NewGuid().ToString();
            string localFilePath = Path.Combine(parentPath, tempFileName);

            DMLibDataHelper.CreateLocalFile(fileNode, localFilePath);

            FileRequestOptions storeMD5Options = new FileRequestOptions()
            {
                RetryPolicy          = DMLibTestConstants.DefaultRetryPolicy,
                StoreFileContentMD5  = true,
                MaximumExecutionTime = DMLibTestConstants.DefaultExecutionTimeOut
            };

            cloudFile.UploadFromFile(localFilePath, options: storeMD5Options);

            if (null != fileNode.MD5 ||
                null != fileNode.ContentType ||
                null != fileNode.CacheControl ||
                null != fileNode.ContentDisposition ||
                null != fileNode.ContentEncoding ||
                null != fileNode.ContentLanguage)
            {
                // set user defined MD5 to cloud file
                cloudFile.Properties.ContentMD5         = fileNode.MD5;
                cloudFile.Properties.ContentType        = fileNode.ContentType;
                cloudFile.Properties.CacheControl       = fileNode.CacheControl;
                cloudFile.Properties.ContentDisposition = fileNode.ContentDisposition;
                cloudFile.Properties.ContentEncoding    = fileNode.ContentEncoding;
                cloudFile.Properties.ContentLanguage    = fileNode.ContentLanguage;

                cloudFile.SetProperties(options: HelperConst.DefaultFileOptions);
            }

            if (null != fileNode.SMBAttributes)
            {
                cloudFile.Properties.NtfsAttributes = fileNode.SMBAttributes;
                cloudFile.Properties.CreationTime   = fileNode.CreationTime;
                cloudFile.Properties.LastWriteTime  = fileNode.LastWriteTime;
                cloudFile.SetProperties(options: HelperConst.DefaultFileOptions);
            }

            if (null != fileNode.Metadata && fileNode.Metadata.Count > 0)
            {
                cloudFile.Metadata.Clear();
                foreach (var metaData in fileNode.Metadata)
                {
                    cloudFile.Metadata.Add(metaData);
                }

                cloudFile.SetMetadata(options: HelperConst.DefaultFileOptions);
            }

            this.BuildFileNode(cloudFile, fileNode);
        }
        private void GenerateFile(FileNode fileNode, string parentPath)
        {
            this.CheckFileNode(fileNode);

            string localFilePath = Path.Combine(parentPath, fileNode.Name);

            DMLibDataHelper.CreateLocalFile(fileNode, localFilePath);

            FileInfo fileInfo = new FileInfo(localFilePath);

            this.BuildFileNode(fileInfo, fileNode);
        }
Пример #4
0
        private void GenerateFile(FileNode fileNode, CloudFile cloudFile, string parentPath)
        {
            this.CheckFileNode(fileNode);

            string tempFileName  = Guid.NewGuid().ToString();
            string localFilePath = Path.Combine(parentPath, tempFileName);

            DMLibDataHelper.CreateLocalFile(fileNode, localFilePath);

            FileRequestOptions storeMD5Options = new FileRequestOptions()
            {
                RetryPolicy         = new LinearRetry(TimeSpan.FromSeconds(90), 3),
                StoreFileContentMD5 = true,
            };

            cloudFile.UploadFromFile(localFilePath, FileMode.Open, options: storeMD5Options);

            if (null != fileNode.MD5 ||
                null != fileNode.ContentType ||
                null != fileNode.CacheControl ||
                null != fileNode.ContentDisposition ||
                null != fileNode.ContentEncoding ||
                null != fileNode.ContentLanguage)
            {
                // set user defined MD5 to cloud file
                cloudFile.Properties.ContentMD5         = fileNode.MD5;
                cloudFile.Properties.ContentType        = fileNode.ContentType;
                cloudFile.Properties.CacheControl       = fileNode.CacheControl;
                cloudFile.Properties.ContentDisposition = fileNode.ContentDisposition;
                cloudFile.Properties.ContentEncoding    = fileNode.ContentEncoding;
                cloudFile.Properties.ContentLanguage    = fileNode.ContentLanguage;
                cloudFile.SetProperties(options: HelperConst.DefaultFileOptions);
            }

            if (null != fileNode.Metadata && fileNode.Metadata.Count > 0)
            {
                cloudFile.Metadata.Clear();
                foreach (var metaData in fileNode.Metadata)
                {
                    cloudFile.Metadata.Add(metaData);
                }

                cloudFile.SetMetadata(options: HelperConst.DefaultFileOptions);
            }

            this.BuildFileNode(cloudFile, fileNode);
        }
Пример #5
0
        private void GenerateFile(FileNode fileNode, string parentPath, bool handleSMBAttributes = false)
        {
            this.CheckFileNode(fileNode);

            string localFilePath = Path.Combine(parentPath, fileNode.Name);

            DMLibDataHelper.CreateLocalFile(fileNode, localFilePath);

            if (handleSMBAttributes)
            {
                LongPathFileExtension.SetAttributes(localFilePath, Helper.ToFileAttributes(fileNode.SMBAttributes.Value));
            }

#if DOTNET5_4
            FileInfo fileInfo = new FileInfo(localFilePath);

            this.BuildFileNode(fileInfo, fileNode, handleSMBAttributes);
#else
            this.BuildFileNode(localFilePath, fileNode, handleSMBAttributes);
#endif
        }