示例#1
0
        public RemoteContext(CCNetController controller)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            this.controller = controller;

            CallContext.SetData(CallContextSlot, this);
        }
示例#2
0
        protected override bool Execute(IIntegrationResult result)
        {
            result.BuildProgressInformation.SignalStartRunTask(
                string.Format("Running virtual machine profile '{0}' declared in configuration file '{1}'.",
                Profile, Configuration));

            string configurationFullPath = result.BaseFromWorkingDirectory(Configuration);

            XmlConfiguration xmlConfiguration = ConfigurationFileHelper.LoadConfiguration(configurationFullPath);
            XmlProfile xmlProfile = xmlConfiguration.GetProfileById(Profile);
            if (xmlProfile == null)
                throw new BuilderException(this, string.Format("Did not find profile '{0}' in configuration file '{1}'.", Profile, configurationFullPath));

            global::VMTool.Core.Profile profile = xmlProfile.ToProfile();

            using (CCNetController controller = new CCNetController(profile))
            {
                controller.ConnectionTimeout = TimeSpan.FromSeconds(ConnectionTimeout);

                using (RemoteContext remoteContext = new RemoteContext(controller))
                {
                    remoteContext.RemoteArtifactDirectory = RemoteArtifactDirectory;
                    remoteContext.RemoteWorkingDirectory = RemoteWorkingDirectory;

                    Status status = controller.GetStatus();

					switch (ConfiguredStartAction)
					{
						case StartAction.Auto:
							if (xmlProfile.Snapshot != null)
								Restart(controller, status);
							else
								StartOrResume(controller, status);
							break;
						case StartAction.StartOrResume:
							StartOrResume(controller, status);
							break;
						case StartAction.Restart:
							Restart(controller, status);
							break;
					}

                    try
                    {
						if (Tasks != null)
						{
							foreach (ITask task in Tasks)
							{
								RunTaskAndMergeResult(task, result);
								
								if (result.Status != IntegrationStatus.Success)
									break;
							}
						}
						
						if (Publishers != null)
						{
							foreach (ITask task in Publishers)
							{
								RunTaskAndMergeResult(task, result);
							}
						}
                    }
                    finally
                    {
						switch (ConfiguredStopAction)
						{
							case StopAction.Auto:
								if (xmlProfile.Snapshot != null)
									controller.PowerOff();
								else
									controller.SaveState();
								break;
							case StopAction.SaveState:
								controller.SaveState();
								break;
							case StopAction.Pause:
								controller.Pause();
								break;
							case StopAction.Shutdown:
								controller.Shutdown();
								break;
							case StopAction.PowerOff:
								controller.PowerOff();
								break;
						}
                    }
                }
            }

            return true;
        }