/// <summary>
        /// Create new ScheduledJobInvocationInfo object with update information and
        /// update the job definition object.
        /// </summary>
        private void UpdateJobInvocationInfo()
        {
            Dictionary <string, object> parameters = UpdateParameters();
            string name = _definition.Name;
            string command;

            if (ScriptBlock != null)
            {
                command = ScriptBlock.ToString();
            }
            else if (FilePath != null)
            {
                command = FilePath;
            }
            else
            {
                command = _definition.InvocationInfo.Command;
            }

            JobDefinition jobDefinition = new JobDefinition(typeof(ScheduledJobSourceAdapter), command, name);

            jobDefinition.ModuleName = ModuleName;
            JobInvocationInfo jobInvocationInfo = new ScheduledJobInvocationInfo(jobDefinition, parameters);

            _definition.UpdateJobInvocationInfo(jobInvocationInfo, false);
        }
		private ScheduledJobDefinition CreateFilePathDefinition()
		{
			JobDefinition jobDefinition = new JobDefinition(typeof(ScheduledJobSourceAdapter), this.FilePath, this._name);
			jobDefinition.ModuleName = "PSScheduledJob";
			Dictionary<string, object> strs = this.CreateCommonParameters();
			if (this.FilePath.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase))
			{
				Collection<PathInfo> resolvedPSPathFromPSPath = base.SessionState.Path.GetResolvedPSPathFromPSPath(this.FilePath);
				if (resolvedPSPathFromPSPath.Count == 1)
				{
					strs.Add("FilePath", resolvedPSPathFromPSPath[0].Path);
					JobInvocationInfo scheduledJobInvocationInfo = new ScheduledJobInvocationInfo(jobDefinition, strs);
					ScheduledJobDefinition scheduledJobDefinition = new ScheduledJobDefinition(scheduledJobInvocationInfo, this.Trigger, this.ScheduledJobOption, this._credential);
					return scheduledJobDefinition;
				}
				else
				{
					string str = StringUtil.Format(ScheduledJobErrorStrings.InvalidFilePath, new object[0]);
					Exception runtimeException = new RuntimeException(str);
					ErrorRecord errorRecord = new ErrorRecord(runtimeException, "InvalidFilePathParameterForRegisterScheduledJobDefinition", ErrorCategory.InvalidArgument, this);
					base.WriteError(errorRecord);
					return null;
				}
			}
			else
			{
				string str1 = StringUtil.Format(ScheduledJobErrorStrings.InvalidFilePathFile, new object[0]);
				Exception exception = new RuntimeException(str1);
				ErrorRecord errorRecord1 = new ErrorRecord(exception, "InvalidFilePathParameterForRegisterScheduledJobDefinition", ErrorCategory.InvalidArgument, this);
				base.WriteError(errorRecord1);
				return null;
			}
		}
        private void UpdateJobInvocationInfo()
        {
            string command;
            Dictionary <string, object> strs = this.UpdateParameters();
            string name = this._definition.Name;

            if (this.ScriptBlock == null)
            {
                if (this.FilePath == null)
                {
                    command = this._definition.InvocationInfo.Command;
                }
                else
                {
                    command = this.FilePath;
                }
            }
            else
            {
                command = this.ScriptBlock.ToString();
            }
            JobDefinition jobDefinition = new JobDefinition(typeof(ScheduledJobSourceAdapter), command, name);

            jobDefinition.ModuleName = "PSScheduledJob";
            JobInvocationInfo scheduledJobInvocationInfo = new ScheduledJobInvocationInfo(jobDefinition, strs);

            this._definition.UpdateJobInvocationInfo(scheduledJobInvocationInfo, false);
        }
		private ScheduledJobDefinition CreateScriptBlockDefinition()
		{
			JobDefinition jobDefinition = new JobDefinition(typeof(ScheduledJobSourceAdapter), this.ScriptBlock.ToString(), this._name);
			jobDefinition.ModuleName = "PSScheduledJob";
			Dictionary<string, object> strs = this.CreateCommonParameters();
			strs.Add("ScriptBlock", this.ScriptBlock);
			JobInvocationInfo scheduledJobInvocationInfo = new ScheduledJobInvocationInfo(jobDefinition, strs);
			ScheduledJobDefinition scheduledJobDefinition = new ScheduledJobDefinition(scheduledJobInvocationInfo, this.Trigger, this.ScheduledJobOption, this._credential);
			return scheduledJobDefinition;
		}
Example #5
0
        private ScheduledJobDefinition CreateScriptBlockDefinition()
        {
            JobDefinition jobDefinition = new JobDefinition(typeof(ScheduledJobSourceAdapter), ScriptBlock.ToString(), _name);

            jobDefinition.ModuleName = ModuleName;
            Dictionary <string, object> parameterCollection = CreateCommonParameters();

            // ScriptBlock, mandatory
            parameterCollection.Add(ScheduledJobInvocationInfo.ScriptBlockParameter, ScriptBlock);

            JobInvocationInfo jobInvocationInfo = new ScheduledJobInvocationInfo(jobDefinition, parameterCollection);

            ScheduledJobDefinition definition = new ScheduledJobDefinition(jobInvocationInfo, Trigger,
                                                                           ScheduledJobOption, _credential);

            return(definition);
        }
Example #6
0
        private ScheduledJobDefinition CreateFilePathDefinition()
        {
            JobDefinition jobDefinition = new JobDefinition(typeof(ScheduledJobSourceAdapter), FilePath, _name);

            jobDefinition.ModuleName = ModuleName;
            Dictionary <string, object> parameterCollection = CreateCommonParameters();

            // FilePath, mandatory
            if (!FilePath.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase))
            {
                string      msg         = StringUtil.Format(ScheduledJobErrorStrings.InvalidFilePathFile);
                Exception   reason      = new RuntimeException(msg);
                ErrorRecord errorRecord = new ErrorRecord(reason, "InvalidFilePathParameterForRegisterScheduledJobDefinition", ErrorCategory.InvalidArgument, this);
                WriteError(errorRecord);

                return(null);
            }

            Collection <PathInfo> pathInfos = SessionState.Path.GetResolvedPSPathFromPSPath(FilePath);

            if (pathInfos.Count != 1)
            {
                string      msg         = StringUtil.Format(ScheduledJobErrorStrings.InvalidFilePath);
                Exception   reason      = new RuntimeException(msg);
                ErrorRecord errorRecord = new ErrorRecord(reason, "InvalidFilePathParameterForRegisterScheduledJobDefinition", ErrorCategory.InvalidArgument, this);
                WriteError(errorRecord);

                return(null);
            }

            parameterCollection.Add(ScheduledJobInvocationInfo.FilePathParameter, pathInfos[0].Path);

            JobInvocationInfo jobInvocationInfo = new ScheduledJobInvocationInfo(jobDefinition, parameterCollection);

            ScheduledJobDefinition definition = new ScheduledJobDefinition(jobInvocationInfo, Trigger,
                                                                           ScheduledJobOption, _credential);

            return(definition);
        }
Example #7
0
        /// <summary>
        /// Create new ScheduledJobInvocationInfo object with update information and 
        /// update the job definition object.
        /// </summary>
        private void UpdateJobInvocationInfo()
        {
            Dictionary<string, object> parameters = UpdateParameters();
            string name = _definition.Name;
            string command;
            
            if (ScriptBlock != null)
            {
                command = ScriptBlock.ToString();
            }
            else if (FilePath != null)
            {
                command = FilePath;
            }
            else
            {
                command = _definition.InvocationInfo.Command;
            }

            JobDefinition jobDefinition = new JobDefinition(typeof(ScheduledJobSourceAdapter), command, name);
            jobDefinition.ModuleName = ModuleName;
            JobInvocationInfo jobInvocationInfo = new ScheduledJobInvocationInfo(jobDefinition, parameters);

            _definition.UpdateJobInvocationInfo(jobInvocationInfo, false);
        }
        private ScheduledJobDefinition CreateFilePathDefinition()
        {
            JobDefinition jobDefinition = new JobDefinition(typeof(ScheduledJobSourceAdapter), FilePath, _name);
            jobDefinition.ModuleName = ModuleName;
            Dictionary<string, object> parameterCollection = CreateCommonParameters();

            // FilePath, mandatory
            if (!FilePath.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase))
            {
                string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidFilePathFile);
                Exception reason = new RuntimeException(msg);
                ErrorRecord errorRecord = new ErrorRecord(reason, "InvalidFilePathParameterForRegisterScheduledJobDefinition", ErrorCategory.InvalidArgument, this);
                WriteError(errorRecord);

                return null;
            }
            Collection<PathInfo> pathInfos = SessionState.Path.GetResolvedPSPathFromPSPath(FilePath);
            if (pathInfos.Count != 1)
            {
                string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidFilePath);
                Exception reason = new RuntimeException(msg);
                ErrorRecord errorRecord = new ErrorRecord(reason, "InvalidFilePathParameterForRegisterScheduledJobDefinition", ErrorCategory.InvalidArgument, this);
                WriteError(errorRecord);

                return null;
            }
            parameterCollection.Add(ScheduledJobInvocationInfo.FilePathParameter, pathInfos[0].Path);

            JobInvocationInfo jobInvocationInfo = new ScheduledJobInvocationInfo(jobDefinition, parameterCollection);

            ScheduledJobDefinition definition = new ScheduledJobDefinition(jobInvocationInfo, Trigger, 
                ScheduledJobOption, _credential);

            return definition;
        }
        private ScheduledJobDefinition CreateScriptBlockDefinition()
        {
            JobDefinition jobDefinition = new JobDefinition(typeof(ScheduledJobSourceAdapter), ScriptBlock.ToString(), _name);
            jobDefinition.ModuleName = ModuleName;
            Dictionary<string, object> parameterCollection = CreateCommonParameters();

            // ScriptBlock, mandatory
            parameterCollection.Add(ScheduledJobInvocationInfo.ScriptBlockParameter, ScriptBlock);

            JobInvocationInfo jobInvocationInfo = new ScheduledJobInvocationInfo(jobDefinition, parameterCollection);

            ScheduledJobDefinition definition = new ScheduledJobDefinition(jobInvocationInfo, Trigger, 
                ScheduledJobOption, _credential);

            return definition;
        }
Example #10
0
		private void UpdateJobInvocationInfo()
		{
			string command;
			Dictionary<string, object> strs = this.UpdateParameters();
			string name = this._definition.Name;
			if (this.ScriptBlock == null)
			{
				if (this.FilePath == null)
				{
					command = this._definition.InvocationInfo.Command;
				}
				else
				{
					command = this.FilePath;
				}
			}
			else
			{
				command = this.ScriptBlock.ToString();
			}
			JobDefinition jobDefinition = new JobDefinition(typeof(ScheduledJobSourceAdapter), command, name);
			jobDefinition.ModuleName = "PSScheduledJob";
			JobInvocationInfo scheduledJobInvocationInfo = new ScheduledJobInvocationInfo(jobDefinition, strs);
			this._definition.UpdateJobInvocationInfo(scheduledJobInvocationInfo, false);
		}