/// <summary> /// Gets the property value. /// </summary> /// <param name="property">The property.</param> /// <returns>The value of the property.</returns> public object GetPropertyValue(TaskPropertyInfo property) { dynamic res; dynamic variable = this.scope.GetVariable(RubyUtils.HasMangledName(property.Name) ? RubyUtils.TryMangleName(property.Name) : property.Name); variable.TryGetValue(out res); return res; }
public TaskPropertyInfo[] GetTaskParameters() { PropertyInfo[] properties = this.TaskType.GetProperties(BindingFlags.Public | BindingFlags.Instance); TaskPropertyInfo[] infoArray2 = new TaskPropertyInfo[properties.Length]; for (int i = 0; i < properties.Length; i++) { infoArray2[i] = new TaskPropertyInfo(properties[i].Name, properties[i].PropertyType, properties[i].GetCustomAttributes(typeof(OutputAttribute), false).Length > 0, properties[i].GetCustomAttributes(typeof(RequiredAttribute), false).Length > 0); } return infoArray2; }
/// <summary> /// Gets all of the parameters on the task. /// </summary> public TaskPropertyInfo[] GetTaskParameters() { PropertyInfo[] infos = TaskType.GetProperties(BindingFlags.Instance | BindingFlags.Public); var propertyInfos = new TaskPropertyInfo[infos.Length]; for (int i = 0; i < infos.Length; i++) { propertyInfos[i] = new ReflectableTaskPropertyInfo(infos[i]); } return propertyInfos; }
public object GetPropertyValue(TaskPropertyInfo property) { var propertyName = property.Name; Log.LogMessage(MessageImportance.Low, "Requesting property '{0}'", propertyName); if (_parameters.ContainsKey(propertyName)) { return _parameters[propertyName]; } Log.LogError("Property '{0}' not found", propertyName); return string.Empty; }
/// <summary> /// Sets a value on a property of this task instance. /// </summary> /// <param name="property">The property to set.</param> /// <param name="value">The value to set. The caller is responsible to type-coerce this value to match the property's <see cref="TaskPropertyInfo.PropertyType"/>.</param> /// <remarks> /// All exceptions from this method will be caught in the taskExecution host and logged as a fatal task error /// </remarks> public void SetPropertyValue(TaskPropertyInfo property, object value) { GetType().GetProperty(property.Name).SetValue(this, value, null); }
/// <summary> /// Gets the outputs (as an array of string values) from the specified output parameter. /// </summary> private string[] GetValueOutputs(TaskPropertyInfo parameter, ElementLocation parameterLocation) { object outputs = _taskFactoryWrapper.GetPropertyValue(_taskInstance, parameter); Array convertibleOutputs = parameter.PropertyType.IsArray ? (Array)outputs : new object[] { outputs }; if (convertibleOutputs == null) { return null; } string[] stringOutputs = new string[convertibleOutputs.Length]; for (int i = 0; i < convertibleOutputs.Length; i++) { object output = convertibleOutputs.GetValue(i); if (output != null) { stringOutputs[i] = (string)Convert.ChangeType(output, typeof(string), CultureInfo.InvariantCulture); } } return stringOutputs; }
/// <summary> /// Called on the local side. /// </summary> private bool SetParameterArray(TaskPropertyInfo parameter, Type parameterType, IList<TaskItem> taskItems, ElementLocation parameterLocation) { TaskItem currentItem = null; try { // Loop through all the TaskItems in our arraylist, and convert them. ArrayList finalTaskInputs = new ArrayList(); if (parameterType != typeof(ITaskItem[])) { foreach (TaskItem item in taskItems) { currentItem = item; if (parameterType == typeof(string[])) { finalTaskInputs.Add(item.ItemSpec); } else if (parameterType == typeof(bool[])) { finalTaskInputs.Add(ConversionUtilities.ConvertStringToBool(item.ItemSpec)); } else { finalTaskInputs.Add(Convert.ChangeType(item.ItemSpec, parameterType.GetElementType(), CultureInfo.InvariantCulture)); } } } else { foreach (TaskItem item in taskItems) { // if we've been asked to remote these items then // remember them so we can disconnect them from remoting later RecordItemForDisconnectIfNecessary(item); finalTaskInputs.Add(item); } } return InternalSetTaskParameter(parameter, finalTaskInputs.ToArray(parameterType.GetElementType())); } catch (Exception ex) { if (ex is InvalidCastException || // invalid type ex is ArgumentException || // can't convert to bool ex is FormatException || // bad string representation of a type ex is OverflowException) // overflow when converting string representation of a numerical type { ProjectErrorUtilities.ThrowInvalidProject ( parameterLocation, "InvalidTaskParameterValueError", currentItem.ItemSpec, parameter.Name, parameterType.FullName, _taskName ); } throw; } }
/// <summary> /// Called on the local side. /// </summary> private bool SetTaskItemParameter(TaskPropertyInfo parameter, ITaskItem item, ElementLocation parameterLocation) { return InternalSetTaskParameter(parameter, item); }
/// <summary> /// Given an instantiated task, this helper method sets the specified parameter /// </summary> private bool InternalSetTaskParameter ( TaskPropertyInfo parameter, object parameterValue ) { bool success = false; // Logging currently enabled only by an env var. if (_logTaskInputs && !_taskLoggingContext.LoggingService.OnlyLogCriticalEvents) { // If the type is a list, we already logged the parameters if (!(parameterValue is IList)) { _taskLoggingContext.LogCommentFromText( MessageImportance.Low, ResourceUtilities.FormatResourceString("TaskParameterPrefix") + parameter.Name + "=" + ItemGroupLoggingHelper.GetStringFromParameterValue(parameterValue)); } } try { _taskFactoryWrapper.SetPropertyValue(_taskInstance, parameter, parameterValue); success = true; } catch (LoggerException) { // if a logger has failed, abort immediately // Polite logger failure throw; } catch (InternalLoggerException) { // Logger threw arbitrary exception throw; } catch (TargetInvocationException e) { // handle any exception thrown by the task's setter itself // At this point, the interesting stack is the internal exception. // Log the task line number, whatever the value of ContinueOnError; // because this will be a hard error anyway. // Exception thrown by the called code itself // Log the stack, so the task vendor can fix their code _taskLoggingContext.LogFatalTaskError ( new BuildEventFileInfo(_taskLocation), e.InnerException, _taskName ); } catch (Exception e) { // Catching Exception, but rethrowing unless it's a well-known exception. if (ExceptionHandling.NotExpectedReflectionException(e)) { throw; } _taskLoggingContext.LogFatalTaskError ( new BuildEventFileInfo(_taskLocation), e, _taskName ); } return success; }
public object GetPropertyValue(TaskPropertyInfo property) { return this.pipeline.Runspace.SessionStateProxy.GetVariable(property.Name); }
/// <summary> /// Sets the property value. /// </summary> /// <param name="property">The property.</param> /// <param name="value">The value to set.</param> public void SetPropertyValue(TaskPropertyInfo property, object value) { _taskScope.SetProperty((object)TaskInstance, property.Name, value); }
public object GetPropertyValue(TaskPropertyInfo property) { return _taskScope.GetProperty((object) TaskInstance, property.Name, property.PropertyType); }
/// <summary> /// Initializes a new instance of the <see cref="ReflectableTaskPropertyInfo"/> class. /// </summary> /// <param name="taskPropertyInfo">The original property info that generated this instance.</param> /// <param name="taskType">The type to reflect over to get the reflection propertyinfo later.</param> internal ReflectableTaskPropertyInfo(TaskPropertyInfo taskPropertyInfo, Type taskType) : base(taskPropertyInfo.Name, taskPropertyInfo.PropertyType, taskPropertyInfo.Output, taskPropertyInfo.Required) { ErrorUtilities.VerifyThrowArgumentNull(taskType, "taskType"); _taskType = taskType; }
} // func GetPropertyValue public void SetPropertyValue(TaskPropertyInfo property, object value) { global[property.Name] = value; } // proc SetPropertyValue
} // proc Dispose public object GetPropertyValue(TaskPropertyInfo property) { return Lua.RtConvertValue(global[property.Name], property.PropertyType); } // func GetPropertyValue
/// <summary> /// Given an instantiated task, this helper method sets the specified vector parameter. Vector parameters can be composed /// of multiple item vectors. The semicolon is the only separator allowed, and white space around the semicolon is /// ignored. Any item separator strings are not allowed, and embedded item vectors are not allowed. /// </summary> /// <remarks>This method is marked "internal" for unit-testing purposes only -- it should be "private" ideally.</remarks> /// <example> /// If @(CPPFiles) is a vector for the files a.cpp and b.cpp, and @(IDLFiles) is a vector for the files a.idl and b.idl: /// /// "@(CPPFiles)" converts to { a.cpp, b.cpp } /// /// "@(CPPFiles); c.cpp; @(IDLFiles); c.idl" converts to { a.cpp, b.cpp, c.cpp, a.idl, b.idl, c.idl } /// /// "@(CPPFiles,';')" converts to <error> /// /// "xxx@(CPPFiles)xxx" converts to <error> /// </example> private bool InitializeTaskVectorParameter ( TaskPropertyInfo parameter, Type parameterType, string parameterValue, ElementLocation parameterLocation, bool isRequired, out bool taskParameterSet ) { ErrorUtilities.VerifyThrow(parameterValue != null, "Didn't expect null parameterValue in InitializeTaskVectorParameter"); taskParameterSet = false; bool success = false; IList<TaskItem> finalTaskItems = _batchBucket.Expander.ExpandIntoTaskItemsLeaveEscaped(parameterValue, ExpanderOptions.ExpandAll, parameterLocation); // If there were no items, don't change the parameter's value. EXCEPT if it's marked as a required // parameter, in which case we made an explicit decision to pass in an empty array. This is // to avoid project authors having to add Conditions on all their tasks to avoid calling them // when a particular item list is empty. This way, we just call the task with an empty list, // the task will loop over an empty list, and return quickly. if ((finalTaskItems.Count > 0) || isRequired) { // If the task parameter is not a ITaskItem[], then we need to convert // all the TaskItem's in our arraylist to the appropriate datatype. success = SetParameterArray(parameter, parameterType, finalTaskItems, parameterLocation); taskParameterSet = true; } else { success = true; } return success; }
/// <summary> /// Variation to handle arrays, to help with logging the parameters. /// </summary> /// <remarks> /// Logging currently enabled only by an env var. /// </remarks> private bool InternalSetTaskParameter(TaskPropertyInfo parameter, IList parameterValue) { if (_logTaskInputs && !_taskLoggingContext.LoggingService.OnlyLogCriticalEvents && parameterValue.Count > 0) { string parameterText = ResourceUtilities.FormatResourceString("TaskParameterPrefix"); parameterText = ItemGroupLoggingHelper.GetParameterText(parameterText, parameter.Name, parameterValue); _taskLoggingContext.LogCommentFromText(MessageImportance.Low, parameterText); } return InternalSetTaskParameter(parameter, (object)parameterValue); }
public void SetPropertyValue(TaskPropertyInfo property, object value) { this.pipeline.Runspace.SessionStateProxy.SetVariable(property.Name, value); }
/// <summary> /// Gather task outputs in array form /// </summary> private void GatherArrayStringAndValueOutputs(bool outputTargetIsItem, string outputTargetName, TaskPropertyInfo parameter, string[] outputs, ElementLocation parameterLocation) { // if the task has generated outputs (if it didn't, don't do anything) if (outputs != null) { if (outputTargetIsItem) { // to store the outputs as items, use the string representations of the outputs as item-specs foreach (string output in outputs) { // if individual outputs in the array are null, ignore them if (output != null) { // attempting to put an empty string into an item is a no-op. if (output.Length > 0) { _batchBucket.Lookup.AddNewItem(new ProjectItemInstance(_projectInstance, outputTargetName, EscapingUtilities.Escape(output), EscapingUtilities.Escape(parameterLocation.File))); } } } if (_logTaskInputs && !_taskLoggingContext.LoggingService.OnlyLogCriticalEvents && outputs.Length > 0) { string parameterText = ItemGroupLoggingHelper.GetParameterText(ResourceUtilities.FormatResourceString("OutputItemParameterMessagePrefix"), outputTargetName, outputs); _taskLoggingContext.LogCommentFromText(MessageImportance.Low, parameterText); } } else { // to store an object array in a property, join all the string representations of the objects with // semi-colons to make the property value // // An empty ITaskItem[] should create a blank value property, for compatibility. StringBuilder joinedOutputs = (outputs.Length == 0) ? new StringBuilder() : null; foreach (string output in outputs) { // if individual outputs in the array are null, ignore them if (output != null) { joinedOutputs = joinedOutputs ?? new StringBuilder(); if (joinedOutputs.Length > 0) { joinedOutputs.Append(';'); } joinedOutputs.Append(EscapingUtilities.Escape(output)); } } if (joinedOutputs != null) { var outputString = joinedOutputs.ToString(); if (_logTaskInputs && !_taskLoggingContext.LoggingService.OnlyLogCriticalEvents) { _taskLoggingContext.LogComment(MessageImportance.Low, "OutputPropertyLogMessage", outputTargetName, outputString); } _batchBucket.Lookup.SetProperty(ProjectPropertyInstance.Create(outputTargetName, outputString, parameterLocation, _projectInstance.IsImmutable)); } } } }
/// <summary> /// Get a list of parameters for the task. /// </summary> public TaskPropertyInfo[] GetTaskParameters() { PropertyInfo[] infos = TaskType.GetProperties(BindingFlags.Instance | BindingFlags.Public); var propertyInfos = new TaskPropertyInfo[infos.Length]; for (int i = 0; i < infos.Length; i++) { propertyInfos[i] = new TaskPropertyInfo( infos[i].Name, infos[i].PropertyType, infos[i].GetCustomAttributes(typeof(OutputAttribute), false).Length > 0, infos[i].GetCustomAttributes(typeof(RequiredAttribute), false).Length > 0); } return propertyInfos; }
/// <summary> /// Called on the local side. /// </summary> private bool SetValueParameter(TaskPropertyInfo parameter, Type parameterType, string expandedParameterValue, ElementLocation parameterLocation) { if (parameterType == typeof(bool)) { // Convert the string to the appropriate datatype, and set the task's parameter. return InternalSetTaskParameter(parameter, ConversionUtilities.ConvertStringToBool(expandedParameterValue)); } else if (parameterType == typeof(string)) { return InternalSetTaskParameter(parameter, expandedParameterValue); } else { return InternalSetTaskParameter(parameter, Convert.ChangeType(expandedParameterValue, parameterType, CultureInfo.InvariantCulture)); } }
/// <summary> /// Sets the given property on the task. /// </summary> internal void SetPropertyValue(ITask task, TaskPropertyInfo property, object value) { ErrorUtilities.VerifyThrowArgumentNull(task, "task"); ErrorUtilities.VerifyThrowArgumentNull(property, "property"); IGeneratedTask generatedTask = task as IGeneratedTask; if (generatedTask != null) { generatedTask.SetPropertyValue(property, value); } else { ReflectableTaskPropertyInfo propertyInfo = (ReflectableTaskPropertyInfo)property; propertyInfo.Reflection.SetValue(task, value, null); } }
/// <summary> /// Gets the outputs (as an array of ITaskItem) from the specified output parameter. /// </summary> private ITaskItem[] GetItemOutputs(TaskPropertyInfo parameter, ElementLocation parameterLocation) { object outputs = _taskFactoryWrapper.GetPropertyValue(_taskInstance, parameter); ITaskItem[] taskItemOutputs = outputs as ITaskItem[]; if (null == taskItemOutputs) { taskItemOutputs = new ITaskItem[] { (ITaskItem)outputs }; } return taskItemOutputs; }
/// <summary> /// Gets the value of a given property on the given task. /// </summary> internal object GetPropertyValue(ITask task, TaskPropertyInfo property) { ErrorUtilities.VerifyThrowArgumentNull(task, "task"); ErrorUtilities.VerifyThrowArgumentNull(property, "property"); IGeneratedTask generatedTask = task as IGeneratedTask; if (generatedTask != null) { return generatedTask.GetPropertyValue(property); } else { ReflectableTaskPropertyInfo propertyInfo = property as ReflectableTaskPropertyInfo; if (propertyInfo != null) { return propertyInfo.Reflection.GetValue(task, null); } else { ErrorUtilities.ThrowInternalError("Task does not implement IGeneratedTask and we don't have {0} either.", typeof(ReflectableTaskPropertyInfo).Name); throw new InternalErrorException(); // unreachable } } }
private static void CreateProperty(CodeTypeDeclaration codeTypeDeclaration, TaskPropertyInfo propInfo, object defaultValue) { CreateProperty(codeTypeDeclaration, propInfo.Name, propInfo.PropertyType, defaultValue); }
public TaskPropertyInfo[] GetTaskParameters() { TaskPropertyInfo[] array = new TaskPropertyInfo[this.taskParameterTypeInfo.Count]; this.taskParameterTypeInfo.Values.CopyTo(array, 0); return array; }
public void SetPropertyValue(TaskPropertyInfo property, object value) { _parameters.Add(property.Name, value); }
/// <summary> /// Given an instantiated task, this helper method sets the specified scalar parameter based on its type. /// </summary> private bool InitializeTaskScalarParameter ( TaskPropertyInfo parameter, Type parameterType, string parameterValue, ElementLocation parameterLocation, out bool taskParameterSet ) { taskParameterSet = false; bool success = false; try { if (parameterType == typeof(ITaskItem)) { // We don't know how many items we're going to end up with, but we'll // keep adding them to this arraylist as we find them. IList<TaskItem> finalTaskItems = _batchBucket.Expander.ExpandIntoTaskItemsLeaveEscaped(parameterValue, ExpanderOptions.ExpandAll, parameterLocation); if (finalTaskItems.Count == 0) { success = true; } else { if (finalTaskItems.Count != 1) { // We only allow a single item to be passed into a parameter of ITaskItem. // Some of the computation (expansion) here is expensive, so don't make the above // "if" statement directly part of the first param to VerifyThrowInvalidProject. ProjectErrorUtilities.VerifyThrowInvalidProject ( false, parameterLocation, "CannotPassMultipleItemsIntoScalarParameter", _batchBucket.Expander.ExpandIntoStringAndUnescape(parameterValue, ExpanderOptions.ExpandAll, parameterLocation), parameter.Name, parameterType.FullName, _taskName ); } RecordItemForDisconnectIfNecessary(finalTaskItems[0]); success = SetTaskItemParameter(parameter, finalTaskItems[0], parameterLocation); taskParameterSet = true; } } else { // Expand out all the metadata, properties, and item vectors in the string. string expandedParameterValue = _batchBucket.Expander.ExpandIntoStringAndUnescape(parameterValue, ExpanderOptions.ExpandAll, parameterLocation); if (expandedParameterValue.Length == 0) { success = true; } else { success = SetValueParameter(parameter, parameterType, expandedParameterValue, parameterLocation); taskParameterSet = true; } } } catch (Exception ex) { if (ex is InvalidCastException || // invalid type ex is ArgumentException || // can't convert to bool ex is FormatException || // bad string representation of a type ex is OverflowException) // overflow when converting string representation of a numerical type { ProjectErrorUtilities.ThrowInvalidProject ( parameterLocation, "InvalidTaskParameterValueError", _batchBucket.Expander.ExpandIntoStringAndUnescape(parameterValue, ExpanderOptions.ExpandAll, parameterLocation), parameter.Name, parameterType.FullName, _taskName ); } throw; } return success; }
/// <summary> /// Sets the property value. /// </summary> /// <param name="property">The property.</param> /// <param name="value">The value to set.</param> public void SetPropertyValue(TaskPropertyInfo property, object value) { ((ScriptScope)this.scope).SetVariable(property.Name, value); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="property">The property to get.</param> /// <returns> /// The value of the property, the value's type will match the type given by <see cref="TaskPropertyInfo.PropertyType"/>. /// </returns> /// <remarks> /// MSBuild calls this method after executing the task to get output parameters. /// All exceptions from this method will be caught in the taskExecution host and logged as a fatal task error /// </remarks> public object GetPropertyValue(TaskPropertyInfo property) { return GetType().GetProperty(property.Name).GetValue(this, null); }