コード例 #1
0
 public PSWorkflowTimer(PSWorkflowInstance instance, object deserializedTimers)
 {
     this.Tracer          = PowerShellTraceSourceFactory.GetTraceSource();
     this.syncLock        = new object();
     this.syncElapsedLock = new object();
     this._instance       = instance;
     this._timers         = new Dictionary <WorkflowTimerType, PSTimer>();
     if (deserializedTimers != null)
     {
         List <object> objs = (List <object>)deserializedTimers;
         foreach (object obj in objs)
         {
             if (obj == null || obj as Dictionary <string, object> == null)
             {
                 continue;
             }
             PSTimer pSTimer = new PSTimer((Dictionary <string, object>)obj, new WorkflowTimerElapsedHandler(this.Timer_WorkflowTimerElapsed));
             this._timers.Add(pSTimer.TimerType, pSTimer);
         }
         return;
     }
     else
     {
         throw new ArgumentNullException("deserializedTimers");
     }
 }
コード例 #2
0
ファイル: PSWorkflowTimer.cs プロジェクト: nickchal/pash
		public PSWorkflowTimer(PSWorkflowInstance instance, object deserializedTimers)
		{
			this.Tracer = PowerShellTraceSourceFactory.GetTraceSource();
			this.syncLock = new object();
			this.syncElapsedLock = new object();
			this._instance = instance;
			this._timers = new Dictionary<WorkflowTimerType, PSTimer>();
			if (deserializedTimers != null)
			{
				List<object> objs = (List<object>)deserializedTimers;
				foreach (object obj in objs)
				{
					if (obj == null || obj as Dictionary<string, object> == null)
					{
						continue;
					}
					PSTimer pSTimer = new PSTimer((Dictionary<string, object>)obj, new WorkflowTimerElapsedHandler(this.Timer_WorkflowTimerElapsed));
					this._timers.Add(pSTimer.TimerType, pSTimer);
				}
				return;
			}
			else
			{
				throw new ArgumentNullException("deserializedTimers");
			}
		}
コード例 #3
0
        internal static bool GetJobInfoFromMetadata(PSWorkflowInstance workflowInstance, out string command, out string name, out Guid instanceId)
        {
            bool retVal = false;

            command    = string.Empty;
            name       = string.Empty;
            instanceId = Guid.Empty;

            do
            {
                object data;
                if (!workflowInstance.PSWorkflowContext.JobMetadata.TryGetValue(Constants.JobMetadataName, out data))
                {
                    break;
                }
                name = (string)data;

                if (!workflowInstance.PSWorkflowContext.JobMetadata.TryGetValue(Constants.JobMetadataCommand, out data))
                {
                    break;
                }
                command = (string)data;

                if (!workflowInstance.PSWorkflowContext.JobMetadata.TryGetValue(Constants.JobMetadataInstanceId, out data))
                {
                    break;
                }
                instanceId = (Guid)data;

                retVal = true;
            } while (false);

            return(retVal);
        }
コード例 #4
0
ファイル: WorkflowTimers.cs プロジェクト: x1m0/PowerShell
        /// <summary>
        /// Creates a workflow timer for a workflow instance based on a BLOB
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="deserializedTimers"></param>
        public PSWorkflowTimer(PSWorkflowInstance instance, object deserializedTimers)
        {
            _instance = instance;
            _timers   = new Dictionary <WorkflowTimerType, PSTimer>();

            if (deserializedTimers == null)
            {
                throw new ArgumentNullException("deserializedTimers");
            }

            List <object> deserializedTimerList = (List <object>)deserializedTimers;

            foreach (object data in deserializedTimerList)
            {
                Debug.Assert(data != null, "Timer data should not have been null.");
                if (data != null)
                {
                    Debug.Assert(data is Dictionary <string, object>, "The timer data should be of type Dictionary<string, object>.");
                    if (data is Dictionary <string, object> )
                    {
                        PSTimer timer = new PSTimer((Dictionary <string, object>)data, Timer_WorkflowTimerElapsed);
                        _timers.Add(timer.TimerType, timer);
                    }
                }
            }
        }
コード例 #5
0
ファイル: PSWorkflowTimer.cs プロジェクト: nickchal/pash
		internal PSWorkflowTimer(PSWorkflowInstance instance)
		{
			this.Tracer = PowerShellTraceSourceFactory.GetTraceSource();
			this.syncLock = new object();
			this.syncElapsedLock = new object();
			this._instance = instance;
			this._timers = new Dictionary<WorkflowTimerType, PSTimer>();
		}
コード例 #6
0
 internal PSWorkflowTimer(PSWorkflowInstance instance)
 {
     this.Tracer          = PowerShellTraceSourceFactory.GetTraceSource();
     this.syncLock        = new object();
     this.syncElapsedLock = new object();
     this._instance       = instance;
     this._timers         = new Dictionary <WorkflowTimerType, PSTimer>();
 }
コード例 #7
0
ファイル: RuntimeBase.cs プロジェクト: x1m0/PowerShell
        /// <summary>
        /// PSWorkflowInstanceStore
        /// </summary>
        /// <param name="workflowInstance"></param>
        protected PSWorkflowInstanceStore(PSWorkflowInstance workflowInstance)
        {
            if (workflowInstance == null)
            {
                throw new ArgumentNullException("workflowInstance");
            }

            PSWorkflowInstance = workflowInstance;
        }
コード例 #8
0
 protected PSWorkflowInstanceStore(PSWorkflowInstance workflowInstance)
 {
     if (workflowInstance != null)
     {
         this.PSWorkflowInstance = workflowInstance;
         return;
     }
     else
     {
         throw new ArgumentNullException("workflowInstance");
     }
 }
コード例 #9
0
		protected PSWorkflowInstanceStore(PSWorkflowInstance workflowInstance)
		{
			if (workflowInstance != null)
			{
				this.PSWorkflowInstance = workflowInstance;
				return;
			}
			else
			{
				throw new ArgumentNullException("workflowInstance");
			}
		}
コード例 #10
0
        internal void RemoveChildJob(Job2 childWorkflowJob)
        {
            object obj = null;

            this._structuredTracer.RemoveJobStarted(childWorkflowJob.InstanceId);
            this.PopulateJobRepositoryIfRequired();
            object[] instanceId = new object[1];
            instanceId[0] = childWorkflowJob.InstanceId;
            this._tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "WorkflowJobSourceAdapter: Removing Workflow job with instance id: {0}", instanceId));
            lock (this._syncRemoveChilJob)
            {
                PSWorkflowJob pSWorkflowJob = childWorkflowJob as PSWorkflowJob;
                if (pSWorkflowJob != null)
                {
                    PSWorkflowInstance pSWorkflowInstance = pSWorkflowJob.PSWorkflowInstance;
                    if (pSWorkflowInstance.PSWorkflowContext.JobMetadata.TryGetValue("ParentInstanceId", out obj))
                    {
                        Guid guid = (Guid)obj;
                        ContainerParentJob item = this._jobRepository.GetItem(guid);
                        item.ChildJobs.Remove(pSWorkflowJob);
                        try
                        {
                            this.GetJobManager().RemoveJob(pSWorkflowJob.InstanceId);
                            this._structuredTracer.JobRemoved(item.InstanceId, pSWorkflowJob.InstanceId, pSWorkflowJob.WorkflowGuid);
                        }
                        catch (ArgumentException argumentException1)
                        {
                            ArgumentException argumentException = argumentException1;
                            object[]          objArray          = new object[1];
                            objArray[0] = argumentException;
                            this._tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "WorkflowJobSourceAdapter: Ingnoring the exception. Exception details: {0}", objArray));
                            this._structuredTracer.JobRemoveError(item.InstanceId, pSWorkflowJob.InstanceId, pSWorkflowJob.WorkflowGuid, argumentException.Message);
                        }
                        if (item.ChildJobs.Count == 0)
                        {
                            try
                            {
                                this._jobRepository.Remove(item);
                            }
                            catch (ArgumentException argumentException3)
                            {
                                ArgumentException argumentException2 = argumentException3;
                                object[]          objArray1          = new object[1];
                                objArray1[0] = argumentException2;
                                this._tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "WorkflowJobSourceAdapter: Ingnoring the exception. Exception details: {0}", objArray1));
                            }
                            item.Dispose();
                        }
                    }
                }
            }
        }
コード例 #11
0
        internal static bool GetJobInfoFromMetadata(PSWorkflowInstance workflowInstance, out string command, out string name, out Guid instanceId)
        {
            object obj  = null;
            bool   flag = false;

            command    = string.Empty;
            name       = string.Empty;
            instanceId = Guid.Empty;
            if (workflowInstance.PSWorkflowContext.JobMetadata.TryGetValue("Name", out obj))
            {
                name = (string)obj;
                if (workflowInstance.PSWorkflowContext.JobMetadata.TryGetValue("Command", out obj))
                {
                    command = (string)obj;
                    if (workflowInstance.PSWorkflowContext.JobMetadata.TryGetValue("InstanceId", out obj))
                    {
                        instanceId = (Guid)obj;
                        flag       = true;
                    }
                }
            }
            return(flag);
        }
コード例 #12
0
 // Override this method so that the runtime uses this instance store rather than the default store.
 public override PSWorkflowInstanceStore CreatePSWorkflowInstanceStore(PSWorkflowInstance workflowInstance)
 {
     return new SampleSqlInstanceStore(this, workflowInstance, _connectionString);
 }
コード例 #13
0
ファイル: WorkflowTimers.cs プロジェクト: x1m0/PowerShell
 /// <summary>
 /// Default Constructor
 /// </summary>
 internal PSWorkflowTimer(PSWorkflowInstance instance)
 {
     _instance = instance;
     _timers   = new Dictionary <WorkflowTimerType, PSTimer>();
 }
コード例 #14
0
		public PSWorkflowFileInstanceStore(PSWorkflowConfigurationProvider configuration, PSWorkflowInstance instance) : base(instance)
		{
			this.Tracer = PowerShellTraceSourceFactory.GetTraceSource();
			this.Streams = "Str";
			this.Error = "Err";
			this.Metadatas = "Meta";
			this.Definition = "Def";
			this.WorkflowState = "Stat";
			this.Version_xml = "V.xml";
			this.InputStream_xml = "IS.xml";
			this.OutputStream_xml = "OS.xml";
			this.ErrorStream_xml = "ES.xml";
			this.WarningStream_xml = "WS.xml";
			this.VerboseStream_xml = "VS.xml";
			this.ProgressStream_xml = "PS.xml";
			this.DebugStream_xml = "DS.xml";
			this.ErrorException_xml = "EE.xml";
			this.Input_xml = "I.xml";
			this.PSWorkflowCommonParameters_xml = "UI.xml";
			this.JobMetadata_xml = "JM.xml";
			this.PrivateMetadata_xml = "PM.xml";
			this.Timer_xml = "TI.xml";
			this.WorkflowInstanceState_xml = "WS.xml";
			this.WorkflowDefinition_xaml = "WD.xaml";
			this.RuntimeAssembly_dll = "RA.dll";
			this.State_xml = "S.xml";
			this._syncLock = new object();
			if (configuration != null)
			{
				if (PSWorkflowFileInstanceStore.TestMode)
				{
					Interlocked.Increment(ref PSWorkflowFileInstanceStore.ObjectCounter);
				}
				this._configuration = configuration;
				this.firstTimeStoringDefinition = true;
				this.SavedComponentLengths = new Dictionary<InternalStoreComponents, long>();
				bool flag = true;
				this._disablePersistenceLimits = true;
				if (PSSessionConfigurationData.IsServerManager)
				{
					flag = false;
					this._disablePersistenceLimits = false;
				}
				this._version = new PersistenceVersion(this._configuration.PersistWithEncryption, flag);
				Guid id = base.PSWorkflowInstance.Id;
				this._version.load(Path.Combine(this._configuration.InstanceStorePath, id.ToString(), this.Version_xml));
				return;
			}
			else
			{
				throw new ArgumentNullException("configuration");
			}
		}
コード例 #15
0
ファイル: RuntimeBase.cs プロジェクト: dfinke/powershell
        /// <summary>
        /// PSWorkflowInstanceStore
        /// </summary>
        /// <param name="workflowInstance"></param>
        protected PSWorkflowInstanceStore(PSWorkflowInstance workflowInstance)
        {
            if (workflowInstance == null)
                throw new ArgumentNullException("workflowInstance");

            PSWorkflowInstance = workflowInstance;
        }
コード例 #16
0
        private IEnumerable <Job2> CreateJobsFromWorkflows(IEnumerable <Job2> workflowJobs, bool returnParents)
        {
            // Jobs in this collection correspond to the ContainerParentJob objects. PSWorkflowJob objects
            // are children of these.
            var reconstructedParentJobs = new Dictionary <Guid, Job2>();
            var jobs = new List <Job2>();

            if (workflowJobs == null)
            {
                return(jobs);
            }

            // If a workflow instance has incomplete metadata, we do not create the job for it.
            foreach (var job in workflowJobs)
            {
                var wfjob = job as PSWorkflowJob;
                Debug.Assert(wfjob != null, "Job supplied must be of type PSWorkflowJob");
                PSWorkflowInstance instance = wfjob.PSWorkflowInstance;
                Dbg.Assert(instance != null, "PSWorkflowInstance should be reconstructed before attempting to rehydrate job");

                if (!instance.JobStateRetrieved || instance.PSWorkflowContext.JobMetadata == null || instance.PSWorkflowContext.JobMetadata.Count == 0)
                {
                    continue;
                }

                object data;
                string name, command;
                Guid   instanceId;
                if (!GetJobInfoFromMetadata(instance, out command, out name, out instanceId))
                {
                    continue;
                }

                if (!instance.PSWorkflowContext.JobMetadata.TryGetValue(Constants.JobMetadataParentInstanceId, out data))
                {
                    continue;
                }
                var parentInstanceId = (Guid)data;

                // If the parent job is needed, find or create it now so that the ID is sequentially lower.
                if (returnParents && !reconstructedParentJobs.ContainsKey(parentInstanceId))
                {
                    if (!instance.PSWorkflowContext.JobMetadata.TryGetValue(Constants.JobMetadataParentName, out data))
                    {
                        continue;
                    }
                    var parentName = (string)data;

                    if (!instance.PSWorkflowContext.JobMetadata.TryGetValue(Constants.JobMetadataParentCommand, out data))
                    {
                        continue;
                    }
                    var parentCommand = (string)data;

                    JobIdentifier      parentId  = RetrieveJobIdForReuse(parentInstanceId);
                    ContainerParentJob parentJob = parentId != null
                                                       ? new ContainerParentJob(parentCommand, parentName, parentId, AdapterTypeName)
                                                       : new ContainerParentJob(parentCommand, parentName, parentInstanceId, AdapterTypeName);

                    // update job metadata with new parent session Id--needed for filtering.
                    // The pid in the metadata has already been updated at this point.
                    Dbg.Assert(
                        instance.PSWorkflowContext.JobMetadata.ContainsKey(Constants.JobMetadataParentSessionId),
                        "Job Metadata for instance incomplete.");
                    if (instance.PSWorkflowContext.JobMetadata.ContainsKey(Constants.JobMetadataParentSessionId))
                    {
                        instance.PSWorkflowContext.JobMetadata[Constants.JobMetadataParentSessionId] = parentJob.Id;
                    }

                    reconstructedParentJobs.Add(parentInstanceId, parentJob);
                }

                // update job metadata with new session Id--needed for filtering.
                Dbg.Assert(instance.PSWorkflowContext.JobMetadata.ContainsKey(Constants.JobMetadataSessionId), "Job Metadata for instance incomplete.");
                Dbg.Assert(instance.PSWorkflowContext.JobMetadata.ContainsKey(Constants.JobMetadataPid), "Job Metadata for instance incomplete.");
                if (instance.PSWorkflowContext.JobMetadata.ContainsKey(Constants.JobMetadataSessionId))
                {
                    instance.PSWorkflowContext.JobMetadata[Constants.JobMetadataSessionId] = job.Id;
                }
                if (instance.PSWorkflowContext.JobMetadata.ContainsKey(Constants.JobMetadataPid))
                {
                    instance.PSWorkflowContext.JobMetadata[Constants.JobMetadataPid] = Process.GetCurrentProcess().Id;
                }

                job.StartParameters = new List <CommandParameterCollection>();
                CommandParameterCollection commandParameterCollection = new CommandParameterCollection();
                AddStartParametersFromCollection(instance.PSWorkflowContext.WorkflowParameters, commandParameterCollection);
                AddStartParametersFromCollection(instance.PSWorkflowContext.PSWorkflowCommonParameters, commandParameterCollection);

                bool takesPSPrivateMetadata;
                if (instance.PSWorkflowContext.JobMetadata.ContainsKey(Constants.WorkflowTakesPrivateMetadata))
                {
                    takesPSPrivateMetadata = (bool)instance.PSWorkflowContext.JobMetadata[Constants.WorkflowTakesPrivateMetadata];
                }
                else
                {
                    DynamicActivity da = instance.PSWorkflowDefinition != null ? instance.PSWorkflowDefinition.Workflow as DynamicActivity : null;
                    takesPSPrivateMetadata = da != null && da.Properties.Contains(Constants.PrivateMetadata);
                }

                // If there is Private Metadata and it is not included in the "Input" collection, add it now.
                if (instance.PSWorkflowContext.PrivateMetadata != null &&
                    instance.PSWorkflowContext.PrivateMetadata.Count > 0 &&
                    !takesPSPrivateMetadata)
                {
                    Hashtable privateMetadata = new Hashtable();
                    foreach (var pair in instance.PSWorkflowContext.PrivateMetadata)
                    {
                        privateMetadata.Add(pair.Key, pair.Value);
                    }
                    commandParameterCollection.Add(new CommandParameter(Constants.PrivateMetadata, privateMetadata));
                }
                job.StartParameters.Add(commandParameterCollection);

                if (returnParents)
                {
                    ((ContainerParentJob)reconstructedParentJobs[parentInstanceId]).AddChildJob(job);
                }
                else
                {
                    jobs.Add(job);
                }

                if (!wfjob.WorkflowInstanceLoaded)
                {
                    // RestoreFromWorkflowInstance sets the job state. Because we've used AddChildJob, the parent's state will be
                    // updated automatically.
                    wfjob.RestoreFromWorkflowInstance(instance);
                }
            }

            if (returnParents)
            {
                jobs.AddRange(reconstructedParentJobs.Values);
            }

            return(jobs);
        }
コード例 #17
0
ファイル: WorkflowJob2.cs プロジェクト: 40a/PowerShell
        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");
        }
コード例 #18
0
 public virtual PSWorkflowInstanceStore CreatePSWorkflowInstanceStore(PSWorkflowInstance workflowInstance)
 {
     return(new PSWorkflowFileInstanceStore(this, workflowInstance));
 }
コード例 #19
0
ファイル: PSWorkflowJob.cs プロジェクト: nickchal/pash
		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]);
		}
コード例 #20
0
ファイル: WorkflowTimers.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Creates a workflow timer for a workflow instance based on a BLOB
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="deserializedTimers"></param>
        public PSWorkflowTimer(PSWorkflowInstance instance, object deserializedTimers)
        {
            _instance = instance;
            _timers = new Dictionary<WorkflowTimerType, PSTimer>();

            if (deserializedTimers == null) throw new ArgumentNullException("deserializedTimers");
            
            List<object> deserializedTimerList = (List<object>)deserializedTimers;
            foreach (object data in deserializedTimerList)
            {
                Debug.Assert(data != null, "Timer data should not have been null.");
                if (data != null)
                {
                    Debug.Assert(data is Dictionary<string, object>, "The timer data should be of type Dictionary<string, object>.");
                    if (data is Dictionary<string, object>)
                    {
                        PSTimer timer = new PSTimer((Dictionary<string, object>)data, Timer_WorkflowTimerElapsed);
                        _timers.Add(timer.TimerType, timer);
                    }
                }
            }
        }
コード例 #21
0
ファイル: WorkflowTimers.cs プロジェクト: 40a/PowerShell
 /// <summary>
 /// Default Constructor
 /// </summary>
 internal PSWorkflowTimer(PSWorkflowInstance instance)
 {
     _instance = instance;
     _timers = new Dictionary<WorkflowTimerType, PSTimer>();
 }
コード例 #22
0
        private IEnumerable <Job2> CreateJobsFromWorkflows(IEnumerable <Job2> workflowJobs, bool returnParents)
        {
            object                  obj  = null;
            string                  str  = null;
            string                  str1 = null;
            Guid                    guid;
            bool                    item;
            DynamicActivity         workflow;
            bool                    flag;
            ContainerParentJob      containerParentJob;
            Dictionary <Guid, Job2> guids = new Dictionary <Guid, Job2>();
            List <Job2>             job2s = new List <Job2>();

            if (workflowJobs != null)
            {
                foreach (Job2 workflowJob in workflowJobs)
                {
                    PSWorkflowJob      pSWorkflowJob      = workflowJob as PSWorkflowJob;
                    PSWorkflowInstance pSWorkflowInstance = pSWorkflowJob.PSWorkflowInstance;
                    if (!pSWorkflowInstance.JobStateRetrieved || pSWorkflowInstance.PSWorkflowContext.JobMetadata == null || pSWorkflowInstance.PSWorkflowContext.JobMetadata.Count == 0 || !WorkflowJobSourceAdapter.GetJobInfoFromMetadata(pSWorkflowInstance, out str1, out str, out guid) || !pSWorkflowInstance.PSWorkflowContext.JobMetadata.TryGetValue("ParentInstanceId", out obj))
                    {
                        continue;
                    }
                    Guid guid1 = (Guid)obj;
                    if (returnParents && !guids.ContainsKey(guid1))
                    {
                        if (!pSWorkflowInstance.PSWorkflowContext.JobMetadata.TryGetValue("ParentName", out obj))
                        {
                            continue;
                        }
                        string str2 = (string)obj;
                        if (!pSWorkflowInstance.PSWorkflowContext.JobMetadata.TryGetValue("ParentCommand", out obj))
                        {
                            continue;
                        }
                        string        str3          = (string)obj;
                        JobIdentifier jobIdentifier = base.RetrieveJobIdForReuse(guid1);
                        if (jobIdentifier != null)
                        {
                            containerParentJob = new ContainerParentJob(str3, str2, jobIdentifier, "PSWorkflowJob");
                        }
                        else
                        {
                            containerParentJob = new ContainerParentJob(str3, str2, guid1, "PSWorkflowJob");
                        }
                        ContainerParentJob containerParentJob1 = containerParentJob;
                        if (pSWorkflowInstance.PSWorkflowContext.JobMetadata.ContainsKey("ParentSessionId"))
                        {
                            pSWorkflowInstance.PSWorkflowContext.JobMetadata["ParentSessionId"] = containerParentJob1.Id;
                        }
                        guids.Add(guid1, containerParentJob1);
                    }
                    if (pSWorkflowInstance.PSWorkflowContext.JobMetadata.ContainsKey("Id"))
                    {
                        pSWorkflowInstance.PSWorkflowContext.JobMetadata["Id"] = workflowJob.Id;
                    }
                    if (pSWorkflowInstance.PSWorkflowContext.JobMetadata.ContainsKey("ProcessId"))
                    {
                        pSWorkflowInstance.PSWorkflowContext.JobMetadata["ProcessId"] = Process.GetCurrentProcess().Id;
                    }
                    workflowJob.StartParameters = new List <CommandParameterCollection>();
                    CommandParameterCollection commandParameterCollection = new CommandParameterCollection();
                    WorkflowJobSourceAdapter.AddStartParametersFromCollection(pSWorkflowInstance.PSWorkflowContext.WorkflowParameters, commandParameterCollection);
                    WorkflowJobSourceAdapter.AddStartParametersFromCollection(pSWorkflowInstance.PSWorkflowContext.PSWorkflowCommonParameters, commandParameterCollection);
                    if (!pSWorkflowInstance.PSWorkflowContext.JobMetadata.ContainsKey("WorkflowTakesPrivateMetadata"))
                    {
                        if (pSWorkflowInstance.PSWorkflowDefinition != null)
                        {
                            workflow = pSWorkflowInstance.PSWorkflowDefinition.Workflow as DynamicActivity;
                        }
                        else
                        {
                            workflow = null;
                        }
                        DynamicActivity dynamicActivity = workflow;
                        if (dynamicActivity == null)
                        {
                            flag = false;
                        }
                        else
                        {
                            flag = dynamicActivity.Properties.Contains("PSPrivateMetadata");
                        }
                        item = flag;
                    }
                    else
                    {
                        item = (bool)pSWorkflowInstance.PSWorkflowContext.JobMetadata["WorkflowTakesPrivateMetadata"];
                    }
                    if (pSWorkflowInstance.PSWorkflowContext.PrivateMetadata != null && pSWorkflowInstance.PSWorkflowContext.PrivateMetadata.Count > 0 && !item)
                    {
                        Hashtable hashtables = new Hashtable();
                        foreach (KeyValuePair <string, object> privateMetadatum in pSWorkflowInstance.PSWorkflowContext.PrivateMetadata)
                        {
                            hashtables.Add(privateMetadatum.Key, privateMetadatum.Value);
                        }
                        commandParameterCollection.Add(new CommandParameter("PSPrivateMetadata", hashtables));
                    }
                    workflowJob.StartParameters.Add(commandParameterCollection);
                    if (!returnParents)
                    {
                        job2s.Add(workflowJob);
                    }
                    else
                    {
                        ((ContainerParentJob)guids[guid1]).AddChildJob(workflowJob);
                    }
                    if (pSWorkflowJob.WorkflowInstanceLoaded)
                    {
                        continue;
                    }
                    pSWorkflowJob.RestoreFromWorkflowInstance(pSWorkflowInstance);
                }
                if (returnParents)
                {
                    foreach (Job2 value in guids.Values)
                    {
                        PSSQMAPI.InitiateWorkflowStateDataTracking(value);
                    }
                    job2s.AddRange(guids.Values);
                }
                return(job2s);
            }
            else
            {
                return(job2s);
            }
        }
コード例 #23
0
ファイル: PSWorkflowJob.cs プロジェクト: nickchal/pash
		internal void RestoreFromWorkflowInstance(PSWorkflowInstance instance)
		{
			object obj = null;
			Exception error;
			this._tracer.WriteMessage("PSWorkflowJob", "RestoreFromWorkflowInstance", this.WorkflowGuidForTraces, this, "BEGIN", new string[0]);
			if (!instance.PSWorkflowContext.JobMetadata.TryGetValue("Reason", out obj))
			{
				error = instance.Error;
			}
			else
			{
				error = obj as Exception;
			}
			this._workflowParameters = instance.PSWorkflowContext.WorkflowParameters;
			this._psWorkflowCommonParameters = instance.PSWorkflowContext.PSWorkflowCommonParameters;
			this._jobMetadata = instance.PSWorkflowContext.JobMetadata;
			this._privateMetadata = instance.PSWorkflowContext.PrivateMetadata;
			if (instance.PSWorkflowContext.JobMetadata.TryGetValue("Location", out obj))
			{
				this._location = obj as string;
			}
			if (instance.PSWorkflowContext.JobMetadata.TryGetValue("StatusMessage", out obj))
			{
				this._statusMessage = obj as string;
			}
			if (instance.State == JobState.Suspended)
			{
				this._statusMessage = Resources.SuspendedJobRecoveredFromPreviousSession;
			}
			lock (this._syncObject)
			{
				this._hasMoreDataOnDisk = true;
			}
			this.DoSetJobState(instance.State, error);
			this._tracer.WriteMessage("PSWorkflowJob", "RestoreFromWorkflowInstance", this.WorkflowGuidForTraces, this, "END", new string[0]);
		}
コード例 #24
0
        internal void RemoveChildJob(Job2 childWorkflowJob)
        {
            _structuredTracer.RemoveJobStarted(childWorkflowJob.InstanceId);
            PopulateJobRepositoryIfRequired();

            _tracer.WriteMessage(String.Format(CultureInfo.InvariantCulture, "WorkflowJobSourceAdapter: Removing Workflow job with instance id: {0}", childWorkflowJob.InstanceId));

            lock (_syncRemoveChilJob)
            {
                PSWorkflowJob childJob = childWorkflowJob as PSWorkflowJob;
                if (childJob == null)
                {
                    return;
                }

                object             data;
                PSWorkflowInstance instance = childJob.PSWorkflowInstance;

                if (!instance.PSWorkflowContext.JobMetadata.TryGetValue(Constants.JobMetadataParentInstanceId, out data))
                {
                    return;
                }
                var parentInstanceId   = (Guid)data;
                ContainerParentJob job = _jobRepository.GetItem(parentInstanceId);

                job.ChildJobs.Remove(childJob);


                try
                {
                    GetJobManager().RemoveJob(childJob.InstanceId);
                    _structuredTracer.JobRemoved(job.InstanceId,
                                                 childJob.InstanceId, childJob.WorkflowGuid);
                }
                catch (ArgumentException exception)
                {
                    //ignoring the error message and just logging them into ETW
                    _tracer.WriteMessage(String.Format(CultureInfo.InvariantCulture,
                                                       "WorkflowJobSourceAdapter: Ignoring the exception. Exception details: {0}",
                                                       exception));

                    _structuredTracer.JobRemoveError(job.InstanceId,
                                                     childJob.InstanceId, childJob.WorkflowGuid,
                                                     exception.Message);
                }

                if (job.ChildJobs.Count == 0)
                {
                    // remove the container parent job from repository
                    try
                    {
                        _jobRepository.Remove(job);
                    }
                    catch (ArgumentException exception)
                    {
                        //ignoring the error message and just logging them into ETW
                        _tracer.WriteMessage(String.Format(CultureInfo.InvariantCulture,
                                                           "WorkflowJobSourceAdapter: Ignoring the exception. Exception details: {0}",
                                                           exception));
                    }
                    job.Dispose();
                }
            }
        }
コード例 #25
0
ファイル: WorkflowJob2.cs プロジェクト: 40a/PowerShell
        internal void RestoreFromWorkflowInstance(PSWorkflowInstance instance)
        {
            _tracer.WriteMessage(ClassNameTrace, "RestoreFromWorkflowInstance", WorkflowGuidForTraces, this, "BEGIN");
            Dbg.Assert(instance != null, "cannot restore a workflow job with null workflow instance");

            object data;
            Exception reason = null;

            if (instance.PSWorkflowContext.JobMetadata.TryGetValue(Constants.JobMetadataStateReason, out data))
                reason = data as Exception;
            else
                reason = instance.Error;

            // igorse: restore all of the job metadata
            _workflowParameters = instance.PSWorkflowContext.WorkflowParameters;
            _psWorkflowCommonParameters = instance.PSWorkflowContext.PSWorkflowCommonParameters;
            _jobMetadata = instance.PSWorkflowContext.JobMetadata;
            _privateMetadata = instance.PSWorkflowContext.PrivateMetadata;

            if (instance.PSWorkflowContext.JobMetadata.TryGetValue(Constants.JobMetadataLocation, out data)) _location = data as string;
            if (instance.PSWorkflowContext.JobMetadata.TryGetValue(Constants.JobMetadataStatusMessage, out data)) _statusMessage = data as string;
            if (instance.State == JobState.Suspended)
            {
                // Status message cannot be set publicly.
                _statusMessage = Resources.SuspendedJobRecoveredFromPreviousSession;
            }

            // indicate that this job has results on disk. This will ensure
            // that the results are not loaded when doing a get-job
            lock (_syncObject)
            {
                _hasMoreDataOnDisk = true;
            }

            Dbg.Assert(instance.JobStateRetrieved,
                       "Cannot set job state when job state is not retrieved or when there is an error in retrieval");
            // igorse: set job state when job is fully restored as StateChanged event will fire
            DoSetJobState(instance.State, reason);
            _tracer.WriteMessage(ClassNameTrace, "RestoreFromWorkflowInstance", WorkflowGuidForTraces, this, "END");
        }
コード例 #26
0
ファイル: PSWorkflowJob.cs プロジェクト: nickchal/pash
		private void InitializeWithWorkflow(PSWorkflowInstance instance, bool closeStreams = false)
		{
			this._tracer.WriteMessage("PSWorkflowJob", "InitializeWithWorkflow", this.WorkflowGuidForTraces, this, "Setting streams", new string[0]);
			PSWorkflowJob pSWorkflowJob = this;
			PSDataCollection<PSObject> outputStream = instance.Streams.OutputStream;
			PSDataCollection<PSObject> pSObjects = outputStream;
			if (outputStream == null)
			{
				pSObjects = new PSDataCollection<PSObject>();
			}
			pSWorkflowJob.Output = pSObjects;
			PSWorkflowJob pSWorkflowJob1 = this;
			PSDataCollection<ProgressRecord> progressStream = instance.Streams.ProgressStream;
			PSDataCollection<ProgressRecord> progressRecords = progressStream;
			if (progressStream == null)
			{
				progressRecords = new PSDataCollection<ProgressRecord>();
			}
			pSWorkflowJob1.Progress = progressRecords;
			PSWorkflowJob pSWorkflowJob2 = this;
			PSDataCollection<WarningRecord> warningStream = instance.Streams.WarningStream;
			PSDataCollection<WarningRecord> warningRecords = warningStream;
			if (warningStream == null)
			{
				warningRecords = new PSDataCollection<WarningRecord>();
			}
			pSWorkflowJob2.Warning = warningRecords;
			PSWorkflowJob pSWorkflowJob3 = this;
			PSDataCollection<ErrorRecord> errorStream = instance.Streams.ErrorStream;
			PSDataCollection<ErrorRecord> errorRecords = errorStream;
			if (errorStream == null)
			{
				errorRecords = new PSDataCollection<ErrorRecord>();
			}
			pSWorkflowJob3.Error = errorRecords;
			PSWorkflowJob pSWorkflowJob4 = this;
			PSDataCollection<DebugRecord> debugStream = instance.Streams.DebugStream;
			PSDataCollection<DebugRecord> debugRecords = debugStream;
			if (debugStream == null)
			{
				debugRecords = new PSDataCollection<DebugRecord>();
			}
			pSWorkflowJob4.Debug = debugRecords;
			PSWorkflowJob pSWorkflowJob5 = this;
			PSDataCollection<VerboseRecord> verboseStream = instance.Streams.VerboseStream;
			PSDataCollection<VerboseRecord> verboseRecords = verboseStream;
			if (verboseStream == null)
			{
				verboseRecords = new PSDataCollection<VerboseRecord>();
			}
			pSWorkflowJob5.Verbose = verboseRecords;
			if (closeStreams)
			{
				base.Output.Complete();
				base.Progress.Complete();
				base.Warning.Complete();
				base.Error.Complete();
				base.Debug.Complete();
				base.Verbose.Complete();
				return;
			}
			else
			{
				return;
			}
		}
コード例 #27
0
ファイル: WorkflowJob2.cs プロジェクト: 40a/PowerShell
        private void InitializeWithWorkflow(PSWorkflowInstance instance, bool closeStreams = false)
        {
            Dbg.Assert(instance.Streams != null, "Workflow Instance has no stream data.");
            _tracer.WriteMessage(ClassNameTrace, "InitializeWithWorkflow", WorkflowGuidForTraces, this, "Setting streams");
            Output = instance.Streams.OutputStream ?? new PSDataCollection<PSObject>();
            Progress = instance.Streams.ProgressStream ?? new PSDataCollection<ProgressRecord>();
            Warning = instance.Streams.WarningStream ?? new PSDataCollection<WarningRecord>();
            Error = instance.Streams.ErrorStream ?? new PSDataCollection<ErrorRecord>();
            Debug = instance.Streams.DebugStream ?? new PSDataCollection<DebugRecord>();
            Verbose = instance.Streams.VerboseStream ?? new PSDataCollection<VerboseRecord>();
            Information = instance.Streams.InformationStream ?? new PSDataCollection<InformationRecord>();

            if (!closeStreams) return;

            Output.Complete();
            Progress.Complete();
            Warning.Complete();
            Error.Complete();
            Debug.Complete();
            Verbose.Complete();
            Information.Complete();
        }