Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Altair Valášek committed Jul 18, 2018
1 parent 8cfe137 commit 06518ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
1 change: 0 additions & 1 deletion Altairis.Xml4web.AzureSync/JobConfiguration.cs
Expand Up @@ -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; }
Expand Down
3 changes: 2 additions & 1 deletion Altairis.Xml4web.AzureSync/JobRunner.cs
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
26 changes: 16 additions & 10 deletions Altairis.Xml4web.AzureSync/Program.cs
Expand Up @@ -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";
Expand Down Expand Up @@ -39,29 +38,25 @@ 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);
var result = runner.Run(operations);
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<string, string>(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();
Expand All @@ -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<string, string>(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
Expand Down

0 comments on commit 06518ec

Please sign in to comment.