/// <summary> /// Serialize / deserialize this item. /// </summary> private void TranslateITaskItemArray(INodePacketTranslator translator) { if (!TranslateNullable(translator, _wrappedParameter)) { return; } if (translator.Mode == TranslationDirection.WriteToStream) { ITaskItem[] wrappedItems = (ITaskItem[])_wrappedParameter; int length = wrappedItems.Length; translator.Translate(ref length); foreach (ITaskItem wrappedItem in wrappedItems) { WriteITaskItem(translator, wrappedItem); } } else { int length = 0; translator.Translate(ref length); ITaskItem[] wrappedItems = new ITaskItem[length]; for (int i = 0; i < length; i++) { ReadITaskItem(translator, ref wrappedItems[i]); } _wrappedParameter = wrappedItems; } }
/// <summary> /// Translates the packet to/from binary form. /// </summary> /// <param name="translator">The translator to use.</param> public void Translate(INodePacketTranslator translator) { translator.Translate(ref _nodeId); translator.Translate(ref _buildParameters, BuildParameters.FactoryForDeserialization); translator.TranslateArray(ref _forwardingLoggers, LoggerDescription.FactoryForTranslation); translator.TranslateDotNet(ref _appDomainSetup); }
/// <summary> /// Translates a PropertyDictionary of ProjectPropertyInstances. /// </summary> /// <param name="translator">The tranlator doing the translating</param> /// <param name="value">The dictionary to translate.</param> public static void TranslateProjectPropertyInstanceDictionary(this INodePacketTranslator translator, ref PropertyDictionary <ProjectPropertyInstance> value) { if (!translator.TranslateNullable(value)) { return; } if (translator.Mode == TranslationDirection.ReadFromStream) { int count = 0; translator.Translate(ref count); value = new PropertyDictionary <ProjectPropertyInstance>(count); for (int i = 0; i < count; i++) { ProjectPropertyInstance instance = null; translator.Translate(ref instance, ProjectPropertyInstance.FactoryForDeserialization); value[instance.Name] = instance; } } else // TranslationDirection.WriteToStream { int count = value.Count; translator.Translate(ref count); foreach (ProjectPropertyInstance instance in value) { ProjectPropertyInstance instanceForSerialization = instance; translator.Translate(ref instanceForSerialization, ProjectPropertyInstance.FactoryForDeserialization); } } }
void INodePacketTranslatable.Translate(INodePacketTranslator translator) { translator.Translate(ref _name); translator.Translate(ref _value); translator.Translate(ref _condition); translator.Translate(ref _location, ElementLocation.FactoryForDeserialization); translator.Translate(ref _conditionLocation, ElementLocation.FactoryForDeserialization); }
void INodePacketTranslatable.Translate(INodePacketTranslator translator) { translator.Translate(ref _loggerClassName); translator.Translate(ref _loggerSwitchParameters); translator.Translate(ref _loggerAssembly, AssemblyLoadInfo.FactoryForTranslation); translator.TranslateEnum(ref _verbosity, (int)_verbosity); translator.Translate(ref _loggerId); }
public void Translate(INodePacketTranslator translator) { ErrorUtilities.VerifyThrow(translator.Mode == TranslationDirection.WriteToStream, "write only"); string assemblyName = AssemblyName; string assemblyFile = AssemblyFile; translator.Translate(ref assemblyName); translator.Translate(ref assemblyFile); }
/// <summary> /// Translates the packet to/from binary form. /// </summary> /// <param name="translator">The translator to use.</param> public void Translate(INodePacketTranslator translator) { translator.TranslateEnum(ref _taskResult, (int)_taskResult); translator.TranslateException(ref _taskException); translator.Translate(ref _taskExceptionMessage); translator.Translate(ref _taskExceptionMessageArgs); translator.TranslateDictionary(ref _taskOutputParameters, StringComparer.OrdinalIgnoreCase, TaskParameter.FactoryForDeserialization); translator.TranslateDictionary(ref _buildProcessEnvironment, StringComparer.OrdinalIgnoreCase); }
/// <summary> /// Translates the packet to/from binary form. /// </summary> /// <param name="translator">The translator to use.</param> public void Translate(INodePacketTranslator translator) { translator.Translate(ref _nodeId); translator.Translate(ref _buildParameters, BuildParameters.FactoryForDeserialization); translator.TranslateArray(ref _forwardingLoggers, LoggerDescription.FactoryForTranslation); #if FEATURE_BINARY_SERIALIZATION && FEATURE_APPDOMAIN translator.TranslateDotNet(ref _appDomainSetup); #endif }
/// <summary> /// Serialization method. /// </summary> public void Translate(INodePacketTranslator translator) { translator.Translate(ref _blockedGlobalRequestId); translator.Translate(ref _targetsInProgress); translator.Translate(ref _blockingGlobalRequestId); translator.Translate(ref _blockingTarget); translator.TranslateEnum(ref _yieldAction, (int)_yieldAction); translator.TranslateArray(ref _buildRequests); }
static public AssemblyLoadInfo FactoryForTranslation(INodePacketTranslator translator) { string assemblyName = null; string assemblyFile = null; translator.Translate(ref assemblyName); translator.Translate(ref assemblyFile); return(Create(assemblyName, assemblyFile)); }
/// <summary> /// ExternalProjectStartedEvent /// </summary> private void WriteExternalProjectStartedEventToStream(ExternalProjectStartedEventArgs externalProjectStartedEventArgs, INodePacketTranslator translator) { string projectFile = externalProjectStartedEventArgs.ProjectFile; translator.Translate(ref projectFile); string targetNames = externalProjectStartedEventArgs.TargetNames; translator.Translate(ref targetNames); }
/// <summary> /// Reads or writes the packet to the serializer. /// </summary> void INodePacketTranslatable.Translate(INodePacketTranslator translator) { ErrorUtilities.VerifyThrow(translator.Mode == TranslationDirection.WriteToStream, "write only"); translator.Translate(ref _name); translator.Translate(ref _escapedValue); bool isImmutable = IsImmutable; translator.Translate(ref isImmutable); }
/// <summary> /// Serialization method. /// </summary> public void Translate(INodePacketTranslator translator) { translator.Translate(ref _blockedGlobalRequestId); translator.Translate(ref _targetsInProgress); translator.Translate(ref _blockingGlobalRequestId); translator.Translate(ref _blockingTarget); translator.TranslateEnum(ref _yieldAction, (int)_yieldAction); translator.TranslateArray(ref _buildRequests); translator.Translate(ref _partialBuildResult, packetTranslator => BuildResult.FactoryForDeserialization(packetTranslator)); }
/// <summary> /// Serialize ExternalProjectFinished Event Argument to the stream /// </summary> private void WriteExternalProjectFinishedEventToStream(ExternalProjectFinishedEventArgs externalProjectFinishedEventArgs, INodePacketTranslator translator) { string projectFile = externalProjectFinishedEventArgs.ProjectFile; translator.Translate(ref projectFile); bool succeeded = externalProjectFinishedEventArgs.Succeeded; translator.Translate(ref succeeded); }
/// <summary> /// Reads or writes the packet to the serializer. /// </summary> public void Translate(INodePacketTranslator translator) { if (translator.Mode == TranslationDirection.WriteToStream && _transferredProperties == null) { // When writing, we will transfer the state of any loaded project instance if we aren't transferring a limited subset. _transferredState = _project; } translator.Translate(ref _translateEntireProjectInstanceState); translator.Translate(ref _configId); translator.Translate(ref _projectFullPath); translator.Translate(ref _transferredState, ProjectInstance.FactoryForDeserialization); translator.Translate(ref _transferredProperties, ProjectPropertyInstance.FactoryForDeserialization); translator.Translate(ref _resultsNodeId); translator.Translate(ref _toolsVersion); translator.Translate(ref _explicitToolsVersionSpecified); translator.TranslateDictionary <PropertyDictionary <ProjectPropertyInstance>, ProjectPropertyInstance>(ref _globalProperties, ProjectPropertyInstance.FactoryForDeserialization); translator.Translate(ref _savedCurrentDirectory); translator.TranslateDictionary(ref _savedEnvironmentVariables, StringComparer.OrdinalIgnoreCase); // if the entire state is translated, then the transferred state, if exists, represents the full evaluation data if (_translateEntireProjectInstanceState && translator.Mode == TranslationDirection.ReadFromStream && _transferredState != null) { SetProjectBasedState(_transferredState); } }
/// <summary> /// Writes the logging packet to the translator. /// </summary> internal void WriteToStream(INodePacketTranslator translator) { #if FEATURE_BINARY_SERIALIZATION if (_eventType != LoggingEventType.CustomEvent) { MethodInfo methodInfo = null; lock (s_writeMethodCache) { if (!s_writeMethodCache.TryGetValue(_eventType, out methodInfo)) { Type eventDerivedType = _buildEvent.GetType(); methodInfo = eventDerivedType.GetMethod("WriteToStream", BindingFlags.NonPublic | BindingFlags.Instance); s_writeMethodCache.Add(_eventType, methodInfo); } } int packetVersion = s_defaultPacketVersion; // Make sure the other side knows what sort of serialization is coming translator.Translate(ref packetVersion); bool eventCanSerializeItself = methodInfo != null; translator.Translate(ref eventCanSerializeItself); if (eventCanSerializeItself) { // 3.5 or later -- we have custom serialization methods, so let's use them. ArgsWriterDelegate writerMethod = (ArgsWriterDelegate)CreateDelegateRobust(typeof(ArgsWriterDelegate), _buildEvent, methodInfo); writerMethod(translator.Writer); if (_eventType == LoggingEventType.TargetFinishedEvent && _targetFinishedTranslator != null) { _targetFinishedTranslator(translator, (TargetFinishedEventArgs)_buildEvent); } } else { WriteEventToStream(_buildEvent, _eventType, translator); } } else { #if FEATURE_ASSEMBLY_LOCATION string assemblyLocation = _buildEvent.GetType().GetTypeInfo().Assembly.Location; translator.Translate(ref assemblyLocation); #else string assemblyName = _buildEvent.GetType().GetTypeInfo().Assembly.FullName; translator.Translate(ref assemblyName); #endif translator.TranslateDotNet(ref _buildEvent); } #else translator.TranslateBuildEventArgs(ref _buildEvent); #endif }
/// <summary> /// Reads or writes the packet to the serializer. /// </summary> void INodePacketTranslatable.Translate(INodePacketTranslator translator) { // Read implementation is directly in the constructor so that fields can be read-only ErrorUtilities.VerifyThrow(translator.Mode == TranslationDirection.WriteToStream, "write only"); string mutableName = _name; string mutableValue = _escapedValue; translator.Translate(ref mutableName); translator.Translate(ref mutableValue); }
/// <summary> /// Writes the packet to the serializer. /// Always send as ints, even if ushorts are being used: otherwise it'd /// need a byte to discriminate and the savings would be microscopic. /// </summary> void INodePacketTranslatable.Translate(INodePacketTranslator translator) { ErrorUtilities.VerifyThrow(translator.Mode == TranslationDirection.WriteToStream, "write only"); string file = File; int line = Line; int column = Column; translator.Translate(ref file); translator.Translate(ref line); translator.Translate(ref column); }
/// <summary> /// Factory for serialization. /// Custom factory is needed because this class is abstract and uses a factory pattern. /// </summary> internal static ElementLocation FactoryForDeserialization(INodePacketTranslator translator) { string file = null; int line = 0; int column = 0; translator.Translate(ref file); translator.Translate(ref line); translator.Translate(ref column); return(Create(file, line, column)); }
void INodePacketTranslatable.Translate(INodePacketTranslator translator) { if (translator.Mode == TranslationDirection.WriteToStream) { var typeName = this.GetType().FullName; translator.Translate(ref typeName); } translator.Translate(ref _condition); translator.Translate(ref _properties, ProjectPropertyGroupTaskPropertyInstance.FactoryForDeserialization); translator.Translate(ref _location, ElementLocation.FactoryForDeserialization); translator.Translate(ref _conditionLocation, ElementLocation.FactoryForDeserialization); }
/// <summary> /// Write Task Command Line log message into the translator /// </summary> private void WriteTaskCommandLineEventToStream(TaskCommandLineEventArgs taskCommandLineEventArgs, INodePacketTranslator translator) { MessageImportance importance = taskCommandLineEventArgs.Importance; translator.TranslateEnum(ref importance, (int)importance); string commandLine = taskCommandLineEventArgs.CommandLine; translator.Translate(ref commandLine); string taskName = taskCommandLineEventArgs.TaskName; translator.Translate(ref taskName); }
/// <summary> /// Factory for serialization /// </summary> internal static ProjectPropertyInstance FactoryForDeserialization(INodePacketTranslator translator) { ErrorUtilities.VerifyThrow(translator.Mode == TranslationDirection.ReadFromStream, "read only"); string name = null; string escapedValue = null; bool isImmutable = false; translator.Translate(ref name); translator.Translate(ref escapedValue); translator.Translate(ref isImmutable); return(Create(name, escapedValue, mayBeReserved: true, isImmutable: isImmutable)); }
/// <summary> /// Translates an items store. /// </summary> public void Translate(INodePacketTranslator translator) { if (_compressedItems == null && translator.Mode == TranslationDirection.WriteToStream) { CompressItemsIfNecessary(); } // Note we only translate the serialized buffer (which contains the compressed and interned // representation of the items.) If the actual items are needed (for instance on child nodes) // then the Items accessor will reconstitute them at the point they are needed. ErrorUtilities.VerifyThrow((translator.Mode == TranslationDirection.ReadFromStream) || ((_compressedItems == null) ^ (_uncompressedItems == null)), "One of the compressed or uncompressed items arrays should be null."); translator.Translate(ref _itemsCount); translator.Translate(ref _compressedItems); translator.TranslateArray(ref _uncompressedItems, TaskItem.FactoryForDeserialization); }
public void Translate(INodePacketTranslator translator) { translator.Translate(ref _buildEventContext); translator.Translate(ref _elementLocation, ElementLocation.FactoryForDeserialization); translator.Translate(ref _minimumVersion); translator.Translate(ref _name); translator.Translate(ref _projectPath); translator.Translate(ref _solutionPath); translator.Translate(ref _submissionId); translator.Translate(ref _version); translator.Translate(ref _interactive); }
/// <summary> /// Writes out the boolean which says if this object is null or not. /// </summary> /// <typeparam name="T">The nullable type to translate.</typeparam> private bool TranslateNullable <T>(INodePacketTranslator translator, T value) { bool haveRef = false; if (translator.Mode == TranslationDirection.WriteToStream) { haveRef = (value != null); translator.Translate(ref haveRef); } else // TranslationDirection.ReadFromStream { translator.Translate(ref haveRef); } return(haveRef); }
/// <summary> /// Reads/writes this packet /// </summary> public void Translate(INodePacketTranslator translator) { translator.Translate(ref _submissionId); translator.Translate(ref _configurationId); translator.Translate(ref _globalRequestId); translator.Translate(ref _parentGlobalRequestId); translator.Translate(ref _nodeRequestId); translator.Translate(ref _targets); translator.Translate(ref _parentBuildEventContext); translator.Translate(ref _buildEventContext); translator.TranslateEnum(ref _buildRequestDataFlags, (int)_buildRequestDataFlags); translator.Translate(ref _skipNonexistentTargets); translator.Translate(ref _requestedProjectState); // UNDONE: (Compat) Serialize the host object. }
/// <summary> /// Decompresses the items. /// </summary> private void DecompressItems() { ErrorUtilities.VerifyThrow(_uncompressedItems == null, "Items already decompressed."); using (MemoryStream serializedStream = new MemoryStream(_compressedItems, 0, _compressedItems.Length, writable: false, publiclyVisible: true)) { using (DeflateStream inflateStream = new DeflateStream(serializedStream, CompressionMode.Decompress)) { INodePacketTranslator serializedBufferTranslator = NodePacketTranslator.GetReadTranslator(inflateStream, null); LookasideStringInterner interner = new LookasideStringInterner(serializedBufferTranslator); byte[] buffer = null; serializedBufferTranslator.Translate(ref buffer); ErrorUtilities.VerifyThrow(buffer != null, "Unexpected null items buffer during decompression."); using (MemoryStream itemsStream = new MemoryStream(buffer, 0, buffer.Length, writable: false, publiclyVisible: true)) { INodePacketTranslator itemTranslator = NodePacketTranslator.GetReadTranslator(itemsStream, null); _uncompressedItems = new TaskItem[_itemsCount]; for (int i = 0; i < _uncompressedItems.Length; i++) { _uncompressedItems[i] = TaskItem.FactoryForDeserialization(itemTranslator, interner); } } } } _compressedItems = null; }
/// <summary> /// Cache the items. /// </summary> internal void CacheItems(int configId, string targetName) { lock (_result) { if (_itemsStore == null) { // Already cached. return; } if (_itemsStore.ItemsCount == 0) { // Nothing to cache. return; } INodePacketTranslator translator = GetResultsCacheTranslator(configId, targetName, TranslationDirection.WriteToStream); // If the translator is null, it means these results were cached once before. Since target results are immutable once they // have been created, there is no point in writing them again. if (translator != null) { try { translator.Translate(ref _itemsStore, ItemsStore.FactoryForDeserialization); _itemsStore = null; _cacheInfo = new CacheInfo(configId, targetName); } finally { translator.Writer.BaseStream.Close(); } } } }
/// <summary> /// Serialize / deserialize this item. /// </summary> public void Translate(INodePacketTranslator translator) { translator.TranslateEnum <TaskParameterType>(ref _parameterType, (int)_parameterType); switch (_parameterType) { case TaskParameterType.Null: _wrappedParameter = null; break; case TaskParameterType.String: string stringParam = (string)_wrappedParameter; translator.Translate(ref stringParam); _wrappedParameter = stringParam; break; case TaskParameterType.StringArray: string[] stringArrayParam = (string[])_wrappedParameter; translator.Translate(ref stringArrayParam); _wrappedParameter = stringArrayParam; break; #if FEATURE_BINARY_SERIALIZATION case TaskParameterType.ValueType: case TaskParameterType.ValueTypeArray: translator.TranslateDotNet(ref _wrappedParameter); break; #endif case TaskParameterType.ITaskItem: TranslateITaskItem(translator); break; case TaskParameterType.ITaskItemArray: TranslateITaskItemArray(translator); break; case TaskParameterType.Invalid: Exception exceptionParam = (Exception)_wrappedParameter; translator.TranslateException(ref exceptionParam); _wrappedParameter = exceptionParam; break; default: ErrorUtilities.ThrowInternalErrorUnreachable(); break; } }
/// <summary> /// Given a build event that is presumed to be 2.0 (due to its lack of a "ReadFromStream" method) and its /// LoggingEventType, read that event from the stream. /// </summary> private BuildEventArgs ReadEventFromStream(LoggingEventType eventType, INodePacketTranslator translator) { string message = null; string helpKeyword = null; string senderName = null; translator.Translate(ref message); translator.Translate(ref helpKeyword); translator.Translate(ref senderName); BuildEventArgs buildEvent = null; switch (eventType) { case LoggingEventType.TaskCommandLineEvent: buildEvent = ReadTaskCommandLineEventFromStream(translator, message, helpKeyword, senderName); break; case LoggingEventType.BuildErrorEvent: buildEvent = ReadTaskBuildErrorEventFromStream(translator, message, helpKeyword, senderName); break; case LoggingEventType.ProjectStartedEvent: buildEvent = ReadExternalProjectStartedEventFromStream(translator, message, helpKeyword, senderName); break; case LoggingEventType.ProjectFinishedEvent: buildEvent = ReadExternalProjectFinishedEventFromStream(translator, message, helpKeyword, senderName); break; case LoggingEventType.BuildMessageEvent: buildEvent = ReadBuildMessageEventFromStream(translator, message, helpKeyword, senderName); break; case LoggingEventType.BuildWarningEvent: buildEvent = ReadBuildWarningEventFromStream(translator, message, helpKeyword, senderName); break; default: ErrorUtilities.ThrowInternalError("Not Supported LoggingEventType {0}", eventType.ToString()); break; } return(buildEvent); }
/// <summary> /// Translate the TargetOutputs for the target finished event. /// </summary> private static void TranslateTargetFinishedEvent(INodePacketTranslator translator, TargetFinishedEventArgs finishedEvent) { List<TaskItem> targetOutputs = null; if (translator.Mode == TranslationDirection.WriteToStream) { if (finishedEvent.TargetOutputs != null) { targetOutputs = new List<TaskItem>(); foreach (TaskItem item in finishedEvent.TargetOutputs) { targetOutputs.Add(item); } } } translator.Translate<TaskItem>(ref targetOutputs, TaskItem.FactoryForDeserialization); if (translator.Mode == TranslationDirection.ReadFromStream) { finishedEvent.TargetOutputs = targetOutputs; } }
/// <summary> /// Function for serialization. /// </summary> void INodePacketTranslatable.Translate(INodePacketTranslator translator) { translator.Translate(ref _toolsVersion); translator.Translate(ref _toolsPath); translator.TranslateProjectPropertyInstanceDictionary(ref _properties); translator.TranslateProjectPropertyInstanceDictionary(ref _environmentProperties); translator.TranslateProjectPropertyInstanceDictionary(ref _globalProperties); translator.TranslateDictionary(ref _subToolsets, StringComparer.OrdinalIgnoreCase, SubToolset.FactoryForDeserialization); translator.Translate(ref _overrideTasksPath); translator.Translate(ref _defaultOverrideToolsVersion); }
/// <summary> /// Reads/writes this packet /// </summary> public void Translate(INodePacketTranslator translator) { translator.Translate(ref _submissionId); translator.Translate(ref _configurationId); translator.Translate(ref _globalRequestId); translator.Translate(ref _parentGlobalRequestId); translator.Translate(ref _nodeRequestId); translator.Translate(ref _targets); translator.Translate(ref _parentBuildEventContext); translator.Translate(ref _buildEventContext); translator.TranslateEnum(ref _buildRequestDataFlags, (int)_buildRequestDataFlags); // UNDONE: (Compat) Serialize the host object. }
/// <summary> /// Translates the packet to/from binary form. /// </summary> /// <param name="translator">The translator to use.</param> public void Translate(INodePacketTranslator translator) { translator.Translate(ref _nodeId); translator.Translate(ref _startupDirectory); translator.TranslateDictionary(ref _buildProcessEnvironment, StringComparer.OrdinalIgnoreCase); translator.TranslateCulture(ref _culture); translator.TranslateCulture(ref _uiCulture); translator.TranslateDotNet(ref _appDomainSetup); translator.Translate(ref _lineNumberOfTask); translator.Translate(ref _columnNumberOfTask); translator.Translate(ref _projectFileOfTask); translator.Translate(ref _taskName); translator.Translate(ref _taskLocation); translator.TranslateDictionary(ref _taskParameters, StringComparer.OrdinalIgnoreCase, TaskParameter.FactoryForDeserialization); translator.Translate(ref _continueOnError); }
/// <summary> /// Reads the logging packet from the translator. /// </summary> internal void ReadFromStream(INodePacketTranslator translator) { if (LoggingEventType.CustomEvent != _eventType) { _buildEvent = GetBuildEventArgFromId(); // The other side is telling us whether the event knows how to log itself, or whether we're going to have // to do it manually int packetVersion = s_defaultPacketVersion; translator.Translate(ref packetVersion); bool eventCanSerializeItself = true; translator.Translate(ref eventCanSerializeItself); if (eventCanSerializeItself) { MethodInfo methodInfo = null; lock (s_readMethodCache) { if (!s_readMethodCache.TryGetValue(_eventType, out methodInfo)) { Type eventDerivedType = _buildEvent.GetType(); methodInfo = eventDerivedType.GetMethod("CreateFromStream", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod); s_readMethodCache.Add(_eventType, methodInfo); } } ArgsReaderDelegate readerMethod = (ArgsReaderDelegate)CreateDelegateRobust(typeof(ArgsReaderDelegate), _buildEvent, methodInfo); readerMethod(translator.Reader, packetVersion); if (_eventType == LoggingEventType.TargetFinishedEvent && _targetFinishedTranslator != null) { _targetFinishedTranslator(translator, (TargetFinishedEventArgs)_buildEvent); } } else { _buildEvent = ReadEventFromStream(_eventType, translator); } } else { string fileLocation = null; translator.Translate(ref fileLocation); bool resolveAssembly = false; lock (s_lockObject) { if (!s_customEventsLoaded.Contains(fileLocation)) { resolveAssembly = true; } // If we are to resolve the assembly add it to the list of assemblies resolved if (resolveAssembly) { s_customEventsLoaded.Add(fileLocation); } } if (resolveAssembly) { s_resolver = new TaskEngineAssemblyResolver(); s_resolver.InstallHandler(); s_resolver.Initialize(fileLocation); } try { translator.TranslateDotNet(ref _buildEvent); } finally { if (resolveAssembly) { s_resolver.RemoveHandler(); s_resolver = null; } } } _eventType = GetLoggingEventId(_buildEvent); }
/// <summary> /// Reads or writes the packet to the serializer. /// </summary> void INodePacketTranslatable.Translate(INodePacketTranslator translator) { translator.Translate(ref _submissionId); translator.Translate(ref _configurationId); translator.Translate(ref _globalRequestId); translator.Translate(ref _parentGlobalRequestId); translator.Translate(ref _nodeRequestId); translator.Translate(ref _initialTargets); translator.Translate(ref _defaultTargets); translator.Translate(ref _circularDependency); translator.TranslateDotNet(ref _requestException); translator.TranslateDictionary<ConcurrentDictionary<string, TargetResult>, TargetResult>(ref _resultsByTarget, TargetResult.FactoryForDeserialization, CreateTargetResultDictionary); translator.Translate(ref _baseOverallResult); translator.Translate(ref _projectStateAfterBuild, ProjectInstance.FactoryForDeserialization); translator.Translate(ref _savedCurrentDirectory); translator.TranslateDictionary(ref _savedEnvironmentVariables, StringComparer.OrdinalIgnoreCase); }
/// <summary> /// Translates the sub-toolset. /// </summary> void INodePacketTranslatable.Translate(INodePacketTranslator translator) { translator.Translate(ref _subToolsetVersion); translator.TranslateProjectPropertyInstanceDictionary(ref _properties); }
/// <summary> /// Read and reconstruct a BuildErrorEventArgs from the stream /// </summary> private BuildErrorEventArgs ReadTaskBuildErrorEventFromStream(INodePacketTranslator translator, string message, string helpKeyword, string senderName) { string code = null; translator.Translate(ref code); int columnNumber = -1; translator.Translate(ref columnNumber); int endColumnNumber = -1; translator.Translate(ref endColumnNumber); int endLineNumber = -1; translator.Translate(ref endLineNumber); string file = null; translator.Translate(ref file); int lineNumber = -1; translator.Translate(ref lineNumber); string subCategory = null; translator.Translate(ref subCategory); BuildErrorEventArgs buildEvent = new BuildErrorEventArgs( subCategory, code, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, helpKeyword, senderName); return buildEvent; }
/// <summary> /// Read and reconstruct a ProjectStartedEventArgs from the stream /// </summary> private ExternalProjectStartedEventArgs ReadExternalProjectStartedEventFromStream(INodePacketTranslator translator, string message, string helpKeyword, string senderName) { string projectFile = null; translator.Translate(ref projectFile); string targetNames = null; translator.Translate(ref targetNames); ExternalProjectStartedEventArgs buildEvent = new ExternalProjectStartedEventArgs( message, helpKeyword, senderName, projectFile, targetNames); return buildEvent; }
/// <summary> /// Read and reconstruct a ProjectFinishedEventArgs from the stream /// </summary> private ExternalProjectFinishedEventArgs ReadExternalProjectFinishedEventFromStream(INodePacketTranslator translator, string message, string helpKeyword, string senderName) { string projectFile = null; translator.Translate(ref projectFile); bool succeeded = true; translator.Translate(ref succeeded); ExternalProjectFinishedEventArgs buildEvent = new ExternalProjectFinishedEventArgs( message, helpKeyword, senderName, projectFile, succeeded); return buildEvent; }
/// <summary> /// Given a build event that is presumed to be 2.0 (due to its lack of a "ReadFromStream" method) and its /// LoggingEventType, read that event from the stream. /// </summary> private BuildEventArgs ReadEventFromStream(LoggingEventType eventType, INodePacketTranslator translator) { string message = null; string helpKeyword = null; string senderName = null; translator.Translate(ref message); translator.Translate(ref helpKeyword); translator.Translate(ref senderName); BuildEventArgs buildEvent = null; switch (eventType) { case LoggingEventType.TaskCommandLineEvent: buildEvent = ReadTaskCommandLineEventFromStream(translator, message, helpKeyword, senderName); break; case LoggingEventType.BuildErrorEvent: buildEvent = ReadTaskBuildErrorEventFromStream(translator, message, helpKeyword, senderName); break; case LoggingEventType.ProjectStartedEvent: buildEvent = ReadExternalProjectStartedEventFromStream(translator, message, helpKeyword, senderName); break; case LoggingEventType.ProjectFinishedEvent: buildEvent = ReadExternalProjectFinishedEventFromStream(translator, message, helpKeyword, senderName); break; case LoggingEventType.BuildMessageEvent: buildEvent = ReadBuildMessageEventFromStream(translator, message, helpKeyword, senderName); break; case LoggingEventType.BuildWarningEvent: buildEvent = ReadBuildWarningEventFromStream(translator, message, helpKeyword, senderName); break; default: ErrorUtilities.ThrowInternalError("Not Supported LoggingEventType {0}", eventType.ToString()); break; } return buildEvent; }
/// <summary> /// Implementation of the serialization mechanism. /// </summary> void INodePacketTranslatable.Translate(INodePacketTranslator translator) { translator.Translate(ref _buildId); /* No build thread priority during translation. We specifically use the default (which is ThreadPriority.Normal) */ translator.TranslateDictionary(ref _buildProcessEnvironment, StringComparer.OrdinalIgnoreCase); translator.TranslateCulture(ref _culture); translator.Translate(ref _defaultToolsVersion); translator.Translate(ref _disableInProcNode); translator.Translate(ref _enableNodeReuse); translator.TranslateProjectPropertyInstanceDictionary(ref _environmentProperties); /* No forwarding logger information sent here - that goes with the node configuration */ translator.TranslateProjectPropertyInstanceDictionary(ref _globalProperties); /* No host services during translation */ /* No loggers during translation */ translator.Translate(ref _maxNodeCount); translator.Translate(ref _memoryUseLimit); translator.Translate(ref _nodeExeLocation); /* No node id during translation */ translator.Translate(ref _onlyLogCriticalEvents); translator.Translate(ref s_startupDirectory); translator.TranslateCulture(ref _uiCulture); translator.Translate(ref _toolsetProvider, Microsoft.Build.Evaluation.ToolsetProvider.FactoryForDeserialization); translator.Translate(ref _useSynchronousLogging); translator.Translate(ref _shutdownInProcNodeOnBuildFinish); translator.Translate(ref _logTaskInputs); translator.Translate(ref _logInitialPropertiesAndItems); // ProjectRootElementCache is not transmitted. // ResetCaches is not transmitted. // LegacyThreadingSemantics is not transmitted. }
static public AssemblyLoadInfo FactoryForTranslation(INodePacketTranslator translator) { string assemblyName = null; string assemblyFile = null; translator.Translate(ref assemblyName); translator.Translate(ref assemblyFile); return Create(assemblyName, assemblyFile); }
/// <summary> /// Given a build event that is presumed to be 2.0 (due to its lack of a "WriteToStream" method) and its /// LoggingEventType, serialize that event to the stream. /// </summary> private void WriteEventToStream(BuildEventArgs buildEvent, LoggingEventType eventType, INodePacketTranslator translator) { string message = buildEvent.Message; string helpKeyword = buildEvent.HelpKeyword; string senderName = buildEvent.SenderName; translator.Translate(ref message); translator.Translate(ref helpKeyword); translator.Translate(ref senderName); // It is essential that you translate in the same order during writing and reading switch (eventType) { case LoggingEventType.BuildMessageEvent: WriteBuildMessageEventToStream((BuildMessageEventArgs)buildEvent, translator); break; case LoggingEventType.TaskCommandLineEvent: WriteTaskCommandLineEventToStream((TaskCommandLineEventArgs)buildEvent, translator); break; case LoggingEventType.BuildErrorEvent: WriteBuildErrorEventToStream((BuildErrorEventArgs)buildEvent, translator); break; case LoggingEventType.BuildWarningEvent: WriteBuildWarningEventToStream((BuildWarningEventArgs)buildEvent, translator); break; case LoggingEventType.ProjectStartedEvent: WriteExternalProjectStartedEventToStream((ExternalProjectStartedEventArgs)buildEvent, translator); break; case LoggingEventType.ProjectFinishedEvent: WriteExternalProjectFinishedEventToStream((ExternalProjectFinishedEventArgs)buildEvent, translator); break; default: ErrorUtilities.ThrowInternalError("Not Supported LoggingEventType {0}", eventType.ToString()); break; } }
/// <summary> /// Translates the packet to/from binary form. /// </summary> /// <param name="translator">The translator to use.</param> public void Translate(INodePacketTranslator translator) { translator.Translate(ref _prepareForReuse); }
/// <summary> /// Writes the logging packet to the translator. /// </summary> internal void WriteToStream(INodePacketTranslator translator) { if (_eventType != LoggingEventType.CustomEvent) { MethodInfo methodInfo = null; lock (s_writeMethodCache) { if (!s_writeMethodCache.TryGetValue(_eventType, out methodInfo)) { Type eventDerivedType = _buildEvent.GetType(); methodInfo = eventDerivedType.GetMethod("WriteToStream", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod); s_writeMethodCache.Add(_eventType, methodInfo); } } int packetVersion = s_defaultPacketVersion; // Make sure the other side knows what sort of serialization is coming translator.Translate(ref packetVersion); bool eventCanSerializeItself = methodInfo != null; translator.Translate(ref eventCanSerializeItself); if (eventCanSerializeItself) { // 3.5 or later -- we have custom serialization methods, so let's use them. ArgsWriterDelegate writerMethod = (ArgsWriterDelegate)CreateDelegateRobust(typeof(ArgsWriterDelegate), _buildEvent, methodInfo); writerMethod(translator.Writer); if (_eventType == LoggingEventType.TargetFinishedEvent && _targetFinishedTranslator != null) { _targetFinishedTranslator(translator, (TargetFinishedEventArgs)_buildEvent); } } else { WriteEventToStream(_buildEvent, _eventType, translator); } } else { string assemblyLocation = _buildEvent.GetType().Assembly.Location; translator.Translate(ref assemblyLocation); translator.TranslateDotNet(ref _buildEvent); } }
/// <summary> /// Reads or writes the packet to the serializer. /// </summary> public void Translate(INodePacketTranslator translator) { translator.Translate(ref registryPath); }
/// <summary> /// Reads/writes this packet /// </summary> public void Translate(INodePacketTranslator translator) { translator.Translate(ref _nodeConfigId); translator.Translate(ref _globalConfigId); translator.Translate(ref _resultsNodeId); }
/// <summary> /// The translator, for serialization. /// </summary> public void Translate(INodePacketTranslator translator) { translator.Translate(ref _strings); }
/// <summary> /// Read and reconstruct a TaskCommandLineEventArgs from the stream /// </summary> private TaskCommandLineEventArgs ReadTaskCommandLineEventFromStream(INodePacketTranslator translator, string message, string helpKeyword, string senderName) { MessageImportance importance = MessageImportance.Normal; translator.TranslateEnum(ref importance, (int)importance); string commandLine = null; translator.Translate(ref commandLine); string taskName = null; translator.Translate(ref taskName); TaskCommandLineEventArgs buildEvent = new TaskCommandLineEventArgs(commandLine, taskName, importance); return buildEvent; }
/// <summary> /// Reads/writes this packet /// </summary> public void Translate(INodePacketTranslator translator) { translator.TranslateEnum(ref _eventType, (int)_eventType); translator.Translate(ref _sinkId); if (translator.Mode == TranslationDirection.ReadFromStream) { ReadFromStream(translator); } else { WriteToStream(translator); } }
public void Translate(INodePacketTranslator translator) { translator.Translate(ref PropertyName); translator.Translate(ref MsBuildPropertyFormat); translator.Translate(ref SearchPaths); }
/// <summary> /// Factory for serialization. /// Custom factory is needed because this class is abstract and uses a factory pattern. /// </summary> internal static IElementLocation FactoryForDeserialization(INodePacketTranslator translator) { string file = null; int line = 0; int column = 0; translator.Translate(ref file); translator.Translate(ref line); translator.Translate(ref column); return Create(file, line, column); }
/// <summary> /// Write a Build Error message into the translator /// </summary> private void WriteBuildErrorEventToStream(BuildErrorEventArgs buildErrorEventArgs, INodePacketTranslator translator) { string code = buildErrorEventArgs.Code; translator.Translate(ref code); int columnNumber = buildErrorEventArgs.ColumnNumber; translator.Translate(ref columnNumber); int endColumnNumber = buildErrorEventArgs.EndColumnNumber; translator.Translate(ref endColumnNumber); int endLineNumber = buildErrorEventArgs.EndLineNumber; translator.Translate(ref endLineNumber); string file = buildErrorEventArgs.File; translator.Translate(ref file); int lineNumber = buildErrorEventArgs.LineNumber; translator.Translate(ref lineNumber); string subCategory = buildErrorEventArgs.Subcategory; translator.Translate(ref subCategory); }