diff --git a/Altairis.Xml4web.AzureSync/JobConfiguration.cs b/Altairis.Xml4web.AzureSync/JobConfiguration.cs index db44e01..20a5ce9 100644 --- a/Altairis.Xml4web.AzureSync/JobConfiguration.cs +++ b/Altairis.Xml4web.AzureSync/JobConfiguration.cs @@ -20,7 +20,6 @@ public class JobConfiguration { } public string StorageConnectionString { get; set; } - public bool UseStorageIndex { get; set; } public string FolderName { get; set; } public bool ConvertToLowercase { get; set; } public string IndexFileName { get; set; } diff --git a/Altairis.Xml4web.AzureSync/JobRunner.cs b/Altairis.Xml4web.AzureSync/JobRunner.cs index 7e6b436..f3b7b17 100644 --- a/Altairis.Xml4web.AzureSync/JobRunner.cs +++ b/Altairis.Xml4web.AzureSync/JobRunner.cs @@ -9,6 +9,7 @@ namespace Altairis.Xml4web.AzureSync { public class JobRunner { + private const string HASH_HEADER_NAME = "X4W_SHA256"; private const int MEGABYTE = 1048576; // 1 MB private const int FILE_SIZE_THRESHOLD = 32 * MEGABYTE; // 32 MB private const int BLOCK_SIZE = 4 * MEGABYTE; // 4 MB @@ -72,7 +73,7 @@ public class JobRunner { if (job == null) throw new ArgumentNullException(nameof(job)); Console.Write($"Uploading {job.LogicalName}: "); var blob = new CloudBlockBlob(job.StorageUri, this.StorageCredentials); - blob.Metadata.Add(Program.HASH_HEADER_NAME, job.ContentHash); + 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.SmartUploadFile(job.LocalFileName, (number, count) => { Console.Write("."); }); Console.WriteLine("OK"); diff --git a/Altairis.Xml4web.AzureSync/Program.cs b/Altairis.Xml4web.AzureSync/Program.cs index 467c3d0..2a01b76 100644 --- a/Altairis.Xml4web.AzureSync/Program.cs +++ b/Altairis.Xml4web.AzureSync/Program.cs @@ -11,7 +11,6 @@ namespace Altairis.Xml4web.AzureSync { class Program { public const int ERRORLEVEL_SUCCESS = 0; public const int ERRORLEVEL_FAILURE = 1; - public const string HASH_HEADER_NAME = "X_SHA256"; private const string WEB_CONTAINER_NAME = "$web"; private const string SYS_CONTAINER_NAME = "xml4web"; private const string STORAGE_INDEX_NAME = "storage-index.json"; @@ -39,14 +38,17 @@ class Program { Console.WriteLine($@"o o o o O---o o o o o-o o-o www.xml4web.com | www.rider.cz"); Console.WriteLine(); + // Preparations LoadConfiguration(args); InitializeStorage(); + + // Index everything and create list of operations IndexLocalFolder(); IndexAzureStorage(); AddNewLocalItems(); - DisplayStatistics(); // Perform operations + DisplayStatistics(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var runner = new JobRunner(credentials, config.ContentTypeMap); @@ -54,14 +56,7 @@ class Program { sw.Stop(); // Save storage index - Console.Write("Saving index..."); - var indexItems = from o in operations - where o.OperationType != JobOperationType.Delete && o.OperationType != JobOperationType.Undefined - select new KeyValuePair(o.StorageUri.AbsolutePath.Remove(0, WEB_CONTAINER_NAME.Length + 2), o.ContentHash); - storageIndex = new StorageIndex(indexItems); - storageIndexBlob.Properties.ContentType = "application/json"; - storageIndex.Save(storageIndexBlob); - Console.WriteLine("OK"); + SaveIndexFile(); // Display results Console.WriteLine(); @@ -74,6 +69,17 @@ class Program { } } + private static void SaveIndexFile() { + Console.Write("Saving index..."); + var indexItems = from o in operations + where o.OperationType != JobOperationType.Delete && o.OperationType != JobOperationType.Undefined + select new KeyValuePair(o.StorageUri.AbsolutePath.Remove(0, WEB_CONTAINER_NAME.Length + 2), o.ContentHash); + storageIndex = new StorageIndex(indexItems); + storageIndexBlob.Properties.ContentType = "application/json"; + storageIndex.Save(storageIndexBlob); + Console.WriteLine("OK"); + } + private static void InitializeStorage() { try { // Get storage account