in SmvCloudWorker/WorkerRole.cs [236:291]
private bool SetSmvVersion(string version)
{
// The version string cannot be empty.
if (String.IsNullOrEmpty(version))
{
return false;
}
// First, check if the SMV version already exists in our local machine.
string smvName = "smv-" + version;
string smvFilename = smvName + ".zip";
CloudBlockBlob blob = versionsContainer.GetBlockBlobReference(smvFilename);
blob.FetchAttributes();
if (smvVersions.ContainsKey(version) && smvVersions[version].Item2 >= blob.Properties.LastModified.Value.UtcDateTime)
{
smvVersionsDirectory = smvVersions[version].Item1;
Environment.SetEnvironmentVariable("smv", smvVersionsDirectory);
return true;
}
// Download the SMV version if it's not available locally.
string zipPath = Path.Combine(smvVersionsDirectory, smvFilename);
if (File.Exists(zipPath))
{
File.Delete(zipPath);
}
blob.DownloadToFile(zipPath, FileMode.CreateNew);
// Delete the version's directory to clear it of any old files.
string dir = Path.Combine(smvVersionsDirectory, smvName);
if (Directory.Exists(dir))
{
Directory.Delete(dir, true);
}
// Now we'll unpack our version of SMV.
try
{
Directory.CreateDirectory(dir);
ZipFile.ExtractToDirectory(zipPath, dir);
File.Delete(zipPath);
}
catch (Exception e)
{
Trace.TraceError("Error unzipping smv.zip: Exception: {0}", e.ToString());
return false;
}
// We've setup a version of SMV successfully. Set smvPath and add this version to the list of avaiable SMV versions.
smvDirectory = dir;
Environment.SetEnvironmentVariable("smv", smvDirectory);
smvVersions[version] = new Tuple<string, DateTime>(smvDirectory, blob.Properties.LastModified.Value.UtcDateTime);
return true;
}