public void SaveStatusFileTest() { string profileName = "site"; DateTime startTime = DateTime.Now; DateTime endTime = DateTime.Now.AddHours(1); StatusFileTestData[] tests = new StatusFileTestData[] { new StatusFileTestData() { State = DeployState.Succeeded, ObjectsAdded = 10, ObjectsUpdated = 20, ObjectsDeleted = 30, ParametersChanged = 40, BytesCopied = 50, StartTime = DateTime.UtcNow, EndTime = DateTime.UtcNow.AddHours(1), Complete = true } }; System.IO.Abstractions.FileBase MockFile = FileHelper.FileSystem.File; for (int i = 0; i < tests.Length; i++) { StatusFile statusFile = new StatusFile(profileName); statusFile.State = tests[i].State; statusFile.ObjectsAdded = tests[i].ObjectsAdded; statusFile.ObjectsUpdated = tests[i].ObjectsUpdated; statusFile.ObjectsDeleted = tests[i].ObjectsDeleted; statusFile.ParametersChanged = tests[i].ParametersChanged; statusFile.BytesCopied = tests[i].BytesCopied; statusFile.StartTime = tests[i].StartTime; statusFile.EndTime = tests[i].EndTime; statusFile.Complete = tests[i].Complete; statusFile.Save(); Assert.IsTrue(MockFile.Exists(@"c:\" + profileName + @"\status.xml")); statusFile = new StatusFile(profileName); statusFile.LoadOrCreate(); VerifyStatusFile(tests[i], statusFile); } }
public DeploymentChangeSummary DeployContentToOneSite( IConfigRepository repository, string contentPath, string publishSettingsFile) { var sourceBaseOptions = new DeploymentBaseOptions(); DeploymentBaseOptions destBaseOptions; string siteName = SetDestBaseOptions(publishSettingsFile, out destBaseOptions); bool success = true; DeploymentChangeSummary summary = null; AddSkips(repository.Config.SkipRules, sourceBaseOptions, destBaseOptions); Trace.TraceInformation("Starting WebDeploy for {0}", Path.GetFileName(publishSettingsFile)); using (StatusFile status = new StatusFile(siteName)) using (LogFile logFile = new LogFile(siteName, false)) { sourceBaseOptions.Trace += logFile.LogEventHandler; destBaseOptions.Trace += logFile.LogEventHandler; try { logFile.Log(TraceLevel.Info, "Beginning sync"); status.State = Models.DeployState.Deploying; status.Save(); // Publish the content to the remote site using (var deploymentObject = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath, contentPath, sourceBaseOptions)) { // Note: would be nice to have an async flavor of this API... summary = deploymentObject.SyncTo(DeploymentWellKnownProvider.ContentPath, siteName, destBaseOptions, new DeploymentSyncOptions()); } string summaryString = string.Format("Total Changes: {0} ({1} added, {2} deleted, {3} updated, {4} parameters changed, {5} bytes copied)", summary.TotalChanges, summary.ObjectsAdded, summary.ObjectsDeleted, summary.ObjectsUpdated, summary.ParameterChanges, summary.BytesCopied); status.ObjectsAdded = summary.ObjectsAdded; status.ObjectsDeleted = summary.ObjectsDeleted; status.ObjectsUpdated = summary.ObjectsUpdated; status.ParametersChanged = summary.ParameterChanges; status.BytesCopied = summary.BytesCopied; logFile.Log(TraceLevel.Info, summaryString); logFile.Log(TraceLevel.Info, "Sync completed successfully"); } catch (Exception e) { logFile.Log(TraceLevel.Error, e.ToString()); success = false; status.State = Models.DeployState.Failed; } if (success) { status.State = Models.DeployState.Succeeded; } }// Close log file and status file return(summary); }