/// <summary> /// Executes behavior with given context /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override BehaviorReturnCode Behave(IBehaviorContext context) { UnitBehaviorContext unitContext = context as UnitBehaviorContext; if (unitContext == null) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } if (!unitContext.Unit.CanSleep) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } SleepTask task = new SleepTask(unitContext.Unit); task.Execute(); if (unitContext.Unit.IsSleeping) { returnCode = BehaviorReturnCode.Success; return(returnCode); } returnCode = BehaviorReturnCode.Failure; return(returnCode); }
protected override void Do(IEvent e) { if (e.Data.Count < 1) { return; } SleepTask.Execute(Convert.ToInt32(e.Data[0])); }
/// <summary> /// Internal task execution code. /// </summary> /// <param name="context">The script execution environment.</param> protected override void DoExecute(ITaskContext context) { string configSettingName = String.Format( System.Globalization.CultureInfo.InvariantCulture, "ServicesExist/{0}", serviceName); CheckIfServiceExistsTask checkIfServiceExistsTask = new CheckIfServiceExistsTask(serviceName, configSettingName); checkIfServiceExistsTask.Execute(context); if (context.Properties.Get <bool>(configSettingName)) { switch (mode) { case InstallWindowsServiceMode.DoNothingIfExists: return; case InstallWindowsServiceMode.FailIfAlreadyInstalled: throw new TaskExecutionException( String.Format( System.Globalization.CultureInfo.InvariantCulture, "The Windows service '{0}' already exists.", serviceName)); case InstallWindowsServiceMode.ReinstallIfExists: UninstallWindowsServiceTask uninstallWindowsServiceTask = new UninstallWindowsServiceTask(executablePath); uninstallWindowsServiceTask.Execute(context); // wait for a while to ensure the service is really deleted SleepTask.Execute(context, serviceUninstallationWaitTime); break; default: throw new NotSupportedException(); } } IDictionary savedState = new Hashtable(); string[] commandLine = new string[0]; using (System.Configuration.Install.AssemblyInstaller assemblyInstaller = new System.Configuration.Install.AssemblyInstaller(executablePath, commandLine)) { try { assemblyInstaller.UseNewContext = true; assemblyInstaller.Install(savedState); assemblyInstaller.Commit(savedState); } catch (System.ComponentModel.Win32Exception ex) { // 1073 context.WriteInfo( "ex.ErrorCode = {0}", ex.NativeErrorCode); throw; } } }
public TRunner Sleep(TimeSpan sleepPeriod) { SleepTask.Execute(scriptExecutionEnvironment, sleepPeriod); return(ReturnThisTRunner()); }