Exemple #1
0
        private void RunDeleteJob(JobOperation job)
        {
            if (job == null)
            {
                throw new ArgumentNullException(nameof(job));
            }

            Console.Write($"Deleting {job.StorageUri.AbsolutePath}...");
            var blob   = new CloudBlob(job.StorageUri, this.StorageCredentials);
            var result = blob.DeleteIfExistsAsync().Result;

            Console.WriteLine(result ? "OK" : "Not found");
        }
Exemple #2
0
        private void RunUploadJob(JobOperation job)
        {
            if (job == null)
            {
                throw new ArgumentNullException(nameof(job));
            }
            Console.Write($"Uploading {job.LogicalName}: ");
            var blob = new CloudBlockBlob(job.StorageUri, this.StorageCredentials);

            blob.Metadata.Add(HASH_HEADER_NAME, job.ContentHash);
            blob.Properties.ContentType  = this.ContentTypeMap.FirstOrDefault(x => x.Key.Equals(Path.GetExtension(job.LocalFileName), StringComparison.OrdinalIgnoreCase)).Value ?? "application/octet-stream";
            blob.Properties.CacheControl = this.CacheControlRules.FirstOrDefault(x => Regex.IsMatch(job.LogicalName, x.Key)).Value ?? "no-cache, no-store, must-revalidate";
            blob.SmartUploadFile(job.LocalFileName, (number, count) => Console.Write("."));
            Console.WriteLine("OK");
        }
Exemple #3
0
        public bool Run(JobOperation job)
        {
            switch (job.OperationType)
            {
            case JobOperationType.Upload:
            case JobOperationType.Update:
                return(this.RunWithRetry(() => this.RunUploadJob(job)));

            case JobOperationType.Delete:
                return(this.RunWithRetry(() => this.RunDeleteJob(job)));

            case JobOperationType.Undefined:
            case JobOperationType.Ignore:
            default:
                return(true);
            }
        }
Exemple #4
0
        private static JobOperation GetJobOperationFromFile(FileInfo fi, DirectoryInfo rootInfo) {
            // Get basic information
            var r = new JobOperation {
                LocalFileName = fi.FullName,
                LogicalName = fi.FullName.Remove(0, rootInfo.FullName.Length).Replace('\\', '/').Trim('/'),
                OperationType = JobOperationType.Undefined,
                Size = fi.Length,
            };

            // Compute storage URI
            if (!fi.Name.Equals(config.IndexFileName, StringComparison.OrdinalIgnoreCase) && config.RemoveExtensions.Contains(fi.Extension, StringComparer.OrdinalIgnoreCase)) {
                // Remove extension
                r.StorageUri = new Uri(webContainer.Uri + "/" + r.LogicalName.Substring(0, r.LogicalName.Length - fi.Extension.Length));
            } else {
                // Leave as is
                r.StorageUri = new Uri(webContainer.Uri + "/" + r.LogicalName);
            }

            return r;
        }