Skip to content

Commit

Permalink
Improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cturano committed Dec 1, 2015
1 parent 04bb038 commit 0e2461b
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions SitecorePackageDeployer/Tasks/InstallPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,25 @@ internal static void ExecutePostSteps(InstallLogger installLogger, PostStepDetai
MetadataView metedateView = UpdateHelper.LoadMetadata(postStepDetails.PostStepPackageFilename);
List<ContingencyEntry> logMessages = new List<ContingencyEntry>();

//Execute the post install steps
DiffInstaller diffInstaller = new DiffInstaller(UpgradeAction.Upgrade);
diffInstaller.ExecutePostInstallationInstructions(postStepDetails.PostStepPackageFilename, postStepDetails.HistoryPath, InstallMode.Update, metedateView, installLogger, ref logMessages);

//Move the update package into the history folder
File.Move(postStepDetails.PostStepPackageFilename, Path.Combine(postStepDetails.HistoryPath, Path.GetFileName(postStepDetails.PostStepPackageFilename)));
try
{
//Execute the post install steps
DiffInstaller diffInstaller = new DiffInstaller(UpgradeAction.Upgrade);
diffInstaller.ExecutePostInstallationInstructions(postStepDetails.PostStepPackageFilename, postStepDetails.HistoryPath, InstallMode.Update, metedateView, installLogger, ref logMessages);
}
finally
{
//Move the update package into the history folder
File.Move(postStepDetails.PostStepPackageFilename, Path.Combine(postStepDetails.HistoryPath, Path.GetFileName(postStepDetails.PostStepPackageFilename)));
}
}
catch (Exception ex)
{
Log.Fatal("Post step execution failed", ex, "InstallPackage");

installLogger.Fatal("Post step execution failed", ex);

throw;
}
}

Expand Down Expand Up @@ -345,18 +352,25 @@ private void FindAndUpdateChangedConfigs(string installPackageName)
/// <param name="logMessages"></param>
private void SaveInstallationMessages(string installationHistoryRoot, List<ContingencyEntry> logMessages)
{
if (string.IsNullOrEmpty(installationHistoryRoot))
try
{
installationHistoryRoot = FileUtil.MakePath(FileUtils.InstallationHistoryRoot, "Upgrade_FAILURE_" + DateTime.Now.ToString("yyyyMMddTHHmmss") + DateTime.Now.Millisecond);
}
if (string.IsNullOrEmpty(installationHistoryRoot))
{
installationHistoryRoot = FileUtil.MakePath(FileUtils.InstallationHistoryRoot, "Upgrade_FAILURE_" + DateTime.Now.ToString("yyyyMMddTHHmmss") + DateTime.Now.Millisecond);
}

string messagesFile = Path.Combine(installationHistoryRoot, "messages.xml");
FileUtil.EnsureFolder(messagesFile);
string messagesFile = Path.Combine(installationHistoryRoot, "messages.xml");
FileUtil.EnsureFolder(messagesFile);

using (FileStream fileStream = File.Create(messagesFile))
using (FileStream fileStream = File.Create(messagesFile))
{
XmlEntrySerializer xmlEntrySerializer = new XmlEntrySerializer();
xmlEntrySerializer.Serialize(logMessages, fileStream);
}
}
catch(Exception ex)
{
XmlEntrySerializer xmlEntrySerializer = new XmlEntrySerializer();
xmlEntrySerializer.Serialize(logMessages, fileStream);
Log.Fatal("Error saving installation messages", ex, typeof(InstallPackage));
}
}
}
Expand Down

0 comments on commit 0e2461b

Please sign in to comment.