/// <summary> /// Workflow instance constructor. /// </summary> /// <param name="runtime"></param> /// <param name="definition">The workflow definition.</param> /// <param name="metadata">The metadata which includes parameters etc.</param> /// <param name="pipelineInput">This is input coming from pipeline, which is added to the input stream.</param> /// <param name="job"></param> internal PSWorkflowApplicationInstance( PSWorkflowRuntime runtime, PSWorkflowDefinition definition, PSWorkflowContext metadata, PSDataCollection<PSObject> pipelineInput, PSWorkflowJob job) { Tracer.WriteMessage("Creating Workflow instance."); InitializePSWorkflowApplicationInstance(runtime); this._definition = definition; this._metadatas = metadata; this._streams = new PowerShellStreams<PSObject, PSObject>(pipelineInput); RegisterHandlersForDataAdding(_streams); this._timers = new PSWorkflowTimer(this); this.creationMode = WorkflowInstanceCreationMode.Normal; _job = job; _stores = Runtime.Configuration.CreatePSWorkflowInstanceStore(this); this._remoteActivityState = new PSWorkflowRemoteActivityState(_stores); }
private PSWorkflowDefinition DeserializeWorkflowDefinitionFromStore() { PSWorkflowDefinition pSWorkflowDefinition; string str = null; try { Guid id = base.PSWorkflowInstance.Id; string str1 = Path.Combine(this._configuration.InstanceStorePath, id.ToString(), this.Definition); if (Directory.Exists(str1)) { string str2 = File.ReadAllText(Path.Combine(str1, this.WorkflowDefinition_xaml)); if (File.Exists(Path.Combine(str1, this.RuntimeAssembly_dll))) { str = Path.Combine(str1, this.RuntimeAssembly_dll); } PSWorkflowDefinition activity = new PSWorkflowDefinition(null, str2, str); if (activity.Workflow == null && !string.IsNullOrEmpty(activity.WorkflowXaml)) { if (!string.IsNullOrEmpty(activity.RuntimeAssemblyPath)) { Assembly assembly = Assembly.LoadFrom(activity.RuntimeAssemblyPath); string name = assembly.GetName().Name; string str3 = null; activity.Workflow = ImportWorkflowCommand.ConvertXamlToActivity(activity.WorkflowXaml, null, null, ref str3, ref assembly, ref name); } else { activity.Workflow = ImportWorkflowCommand.ConvertXamlToActivity(activity.WorkflowXaml); } } return activity; } else { pSWorkflowDefinition = null; } } catch (Exception exception1) { Exception exception = exception1; this.Tracer.TraceException(exception); throw; } return pSWorkflowDefinition; }
/// <summary> /// Workflow instance constructor for shutdown or crashed workflows. /// </summary> /// <param name="runtime"></param> /// <param name="instanceId"></param> internal PSWorkflowApplicationInstance(PSWorkflowRuntime runtime, PSWorkflowId instanceId) { Tracer.WriteMessage("Creating Workflow instance after crash and shutdown workflow."); InitializePSWorkflowApplicationInstance(runtime); this._definition = null; this._metadatas = null; this._streams = null; this._timers = null; this.id = instanceId.Guid; this.creationMode = WorkflowInstanceCreationMode.AfterCrashOrShutdown; _stores = Runtime.Configuration.CreatePSWorkflowInstanceStore(this); this._remoteActivityState = null; }
internal void LoadWorkflow(CommandParameterCollection commandParameterCollection, Activity activity, string xaml) { _tracer.WriteMessage(ClassNameTrace, "LoadWorkflow", WorkflowGuidForTraces, this, "BEGIN"); Dbg.Assert(_workflowInstance == null, "LoadWorkflow() should only be called once by the adapter"); // If activity hasn't been cached, we can't generate it from _definition. if (activity == null) { bool windowsWorkflow; activity = DefinitionCache.Instance.GetActivityFromCache(_definition, out windowsWorkflow); if (activity == null) { // The workflow cannot be run. throw new InvalidOperationException(Resources.ActivityNotCached); } } string workflowXaml; string runtimeAssemblyPath; if (string.IsNullOrEmpty(xaml)) { workflowXaml = DefinitionCache.Instance.GetWorkflowXaml(_definition); runtimeAssemblyPath = DefinitionCache.Instance.GetRuntimeAssemblyPath(_definition); } else { workflowXaml = xaml; runtimeAssemblyPath = null; } _location = null; SortStartParameters(activity as DynamicActivity, commandParameterCollection); // Set location if ComputerName wasn't specified in the parameters. if (string.IsNullOrEmpty(_location)) _location = Constants.DefaultComputerName; if (_jobMetadata.ContainsKey(Constants.JobMetadataLocation)) _jobMetadata.Remove(Constants.JobMetadataLocation); _jobMetadata.Add(Constants.JobMetadataLocation, _location); if (_jobMetadata.ContainsKey(Constants.WorkflowJobCreationContext)) _jobMetadata.Remove(Constants.WorkflowJobCreationContext); _jobMetadata.Add(Constants.WorkflowJobCreationContext, _jobCreationContext); PSWorkflowDefinition definition = new PSWorkflowDefinition(activity, workflowXaml, runtimeAssemblyPath, _definition.RequiredAssemblies); PSWorkflowContext metadatas = new PSWorkflowContext(_workflowParameters, _psWorkflowCommonParameters, _jobMetadata, _privateMetadata); _workflowInstance = _runtime.Configuration.CreatePSWorkflowInstance(definition, metadatas, _inputCollection, this); this.ConfigureWorkflowHandlers(); // Create a WorkflowApplication instance. _tracer.WriteMessage(ClassNameTrace, "LoadWorkflow", WorkflowGuidForTraces, this, "Calling instance loader"); #if DEBUG try { _workflowInstance.CreateInstance(); } catch (Exception e) { if (e.Message.IndexOf("Cannot create unknown type", StringComparison.OrdinalIgnoreCase) >= 0) { // Capture environment to help diagnose: MSFT:246456 PSObject inputObject = new PSObject(); inputObject.Properties.Add( new PSNoteProperty("activity", activity)); inputObject.Properties.Add( new PSNoteProperty("workflowXaml", workflowXaml)); inputObject.Properties.Add( new PSNoteProperty("runtimeAssemblyPath", runtimeAssemblyPath)); inputObject.Properties.Add( new PSNoteProperty("_definition.RequiredAssemblies", _definition.RequiredAssemblies)); string tempPath = System.IO.Path.GetTempFileName(); System.Management.Automation.PowerShell.Create().AddCommand("Export-CliXml"). AddParameter("InputObject", inputObject). AddParameter("Depth", 10). AddParameter("Path", tempPath).Invoke(); throw new Exception("Bug MSFT:246456 detected. Please capture " + tempPath + ", open a new issue " + "at https://github.com/PowerShell/PowerShell/issues/new and attach the file."); } else { throw; } } #else _workflowInstance.CreateInstance(); #endif InitializeWithWorkflow(_workflowInstance); WorkflowInstanceLoaded = true; _tracer.WriteMessage(ClassNameTrace, "LoadWorkflow", WorkflowGuidForTraces, this, "END"); }
public virtual PSWorkflowInstance CreatePSWorkflowInstance(PSWorkflowDefinition definition, PSWorkflowContext metadata, PSDataCollection <PSObject> pipelineInput, PSWorkflowJob job) { return(new PSWorkflowApplicationInstance(this.Runtime, definition, metadata, pipelineInput, job)); }
internal PSWorkflowApplicationInstance(PSWorkflowRuntime runtime, PSWorkflowId instanceId) { this.Tracer = PowerShellTraceSourceFactory.GetTraceSource(); this.wfAppNeverLoaded = true; this.ReactivateSync = new object(); if (runtime != null) { this.Tracer.WriteMessage("Creating Workflow instance after crash and shutdown workflow."); this._definition = null; this._metadatas = null; this._streams = null; this._timers = null; this.id = instanceId.Guid; this.creationMode = WorkflowInstanceCreationMode.AfterCrashOrShutdown; this.PersistAfterNextPSActivity = false; this.suspendAtNextCheckpoint = false; base.Runtime = runtime; this._stores = base.Runtime.Configuration.CreatePSWorkflowInstanceStore(this); this.asyncExecutionCollection = new Dictionary<string, PSActivityContext>(); base.ForceDisableStartOrEndPersistence = false; return; } else { throw new ArgumentNullException("runtime"); } }
internal PSWorkflowApplicationInstance(PSWorkflowRuntime runtime, PSWorkflowDefinition definition, PSWorkflowContext metadata, PSDataCollection<PSObject> pipelineInput, PSWorkflowJob job) { this.Tracer = PowerShellTraceSourceFactory.GetTraceSource(); this.wfAppNeverLoaded = true; this.ReactivateSync = new object(); if (runtime != null) { this.Tracer.WriteMessage("Creating Workflow instance."); this._definition = definition; this._metadatas = metadata; this._streams = new PowerShellStreams<PSObject, PSObject>(pipelineInput); this.RegisterHandlersForDataAdding(this._streams); this._timers = new PSWorkflowTimer(this); this.creationMode = WorkflowInstanceCreationMode.Normal; this.PersistAfterNextPSActivity = false; this.suspendAtNextCheckpoint = false; this._job = job; base.Runtime = runtime; this._stores = base.Runtime.Configuration.CreatePSWorkflowInstanceStore(this); this.asyncExecutionCollection = new Dictionary<string, PSActivityContext>(); base.ForceDisableStartOrEndPersistence = false; return; } else { throw new ArgumentNullException("runtime"); } }
internal void LoadWorkflow(CommandParameterCollection commandParameterCollection, Activity activity, string xaml) { bool flag = false; string workflowXaml; string runtimeAssemblyPath; this._tracer.WriteMessage("PSWorkflowJob", "LoadWorkflow", this.WorkflowGuidForTraces, this, "BEGIN", new string[0]); if (activity == null) { activity = DefinitionCache.Instance.GetActivityFromCache(this._definition, out flag); if (activity == null) { throw new InvalidOperationException(Resources.ActivityNotCached); } } if (!string.IsNullOrEmpty(xaml)) { workflowXaml = xaml; runtimeAssemblyPath = null; } else { workflowXaml = DefinitionCache.Instance.GetWorkflowXaml(this._definition); runtimeAssemblyPath = DefinitionCache.Instance.GetRuntimeAssemblyPath(this._definition); } this._location = null; this.SortStartParameters(activity as DynamicActivity, commandParameterCollection); if (string.IsNullOrEmpty(this._location)) { this._location = "localhost"; } if (this._jobMetadata.ContainsKey("Location")) { this._jobMetadata.Remove("Location"); } this._jobMetadata.Add("Location", this._location); PSWorkflowDefinition pSWorkflowDefinition = new PSWorkflowDefinition(activity, workflowXaml, runtimeAssemblyPath); PSWorkflowContext pSWorkflowContext = new PSWorkflowContext(this._workflowParameters, this._psWorkflowCommonParameters, this._jobMetadata, this._privateMetadata); this._workflowInstance = this._runtime.Configuration.CreatePSWorkflowInstance(pSWorkflowDefinition, pSWorkflowContext, this._inputCollection, this); this.ConfigureWorkflowHandlers(); this._tracer.WriteMessage("PSWorkflowJob", "LoadWorkflow", this.WorkflowGuidForTraces, this, "Calling instance loader", new string[0]); this._workflowInstance.CreateInstance(); this.InitializeWithWorkflow(this._workflowInstance, false); this.WorkflowInstanceLoaded = true; this._tracer.WriteMessage("PSWorkflowJob", "LoadWorkflow", this.WorkflowGuidForTraces, this, "END", new string[0]); }