コード例 #1
0
 public void TestConstructorNullSendDataDelegate()
 {
     Assert.Throws <InternalErrorException>(() =>
     {
         var transportSink = new BuildEventArgTransportSink(null);
     });
 }
コード例 #2
0
 public void TestConsumeNullBuildEvent()
 {
     Assert.Throws <InternalErrorException>(() =>
     {
         BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(PacketProcessor);
         transportSink.Consume(null, 0);
     }
                                            );
 }
コード例 #3
0
        public void PropertyTests()
        {
            BuildEventArgTransportSink sink = new BuildEventArgTransportSink(PacketProcessor);

            Assert.Null(sink.Name);

            const string name = "Test Name";

            sink.Name = name;
            Assert.Equal(0, string.Compare(sink.Name, name, StringComparison.OrdinalIgnoreCase));
        }
コード例 #4
0
        public void TestConsumeBuildStartedEvent()
        {
            bool wentInHandler = false;
            BuildStartedEventArgs buildStarted      = new BuildStartedEventArgs("Start", "Help");
            SendDataDelegate      transportDelegate = delegate(INodePacket packet)
            {
                wentInHandler = true;
            };

            BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(transportDelegate);

            transportSink.Consume(buildStarted, 0);
            Assert.IsTrue(transportSink.HaveLoggedBuildStartedEvent);
            Assert.IsFalse(transportSink.HaveLoggedBuildFinishedEvent);
            Assert.IsFalse(wentInHandler, "Expected not to go into transport delegate");
        }
コード例 #5
0
        public void TestShutDown()
        {
            SendDataDelegate transportDelegate = PacketProcessor;
            var weakTransportDelegateReference = new WeakReference(transportDelegate);
            var transportSink = new BuildEventArgTransportSink(transportDelegate);

            transportSink.ShutDown();

            Assert.NotNull(weakTransportDelegateReference.Target);
            transportDelegate = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();

            // Expected shutdown to null out the sendData delegate, the two garbage collections
            // should have collected the sendDataDelegate causing the weak reference to die.
            Assert.Null(weakTransportDelegateReference.Target);  // " Expected delegate to be dead"
        }
コード例 #6
0
        public void TestConsumeBuildFinishedEvent()
        {
            bool wentInHandler = false;
            BuildFinishedEventArgs buildFinished = new BuildFinishedEventArgs("Finished", "Help", true);

            void TransportDelegate(INodePacket packet)
            {
                wentInHandler = true;
            }

            BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(TransportDelegate);

            transportSink.Consume(buildFinished, 0);
            Assert.False(transportSink.HaveLoggedBuildStartedEvent);
            Assert.True(transportSink.HaveLoggedBuildFinishedEvent);
            Assert.False(wentInHandler); // "Expected not to go into transport delegate"
        }
コード例 #7
0
        public void TestConsumeMessageBuildEvent()
        {
            bool wentInHandler = false;
            BuildMessageEventArgs messageEvent      = new BuildMessageEventArgs("My message", "Help me keyword", "Sender", MessageImportance.High);
            SendDataDelegate      transportDelegate = delegate(INodePacket packet)
            {
                wentInHandler = true;
                LogMessagePacket loggingPacket = packet as LogMessagePacket;
                Assert.IsNotNull(loggingPacket);
                BuildMessageEventArgs messageEventFromPacket = loggingPacket.NodeBuildEvent.Value.Value as BuildMessageEventArgs;
                Assert.IsTrue(messageEventFromPacket == messageEvent);
            };

            BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(transportDelegate);

            transportSink.Consume(messageEvent, 0);
            Assert.IsTrue(wentInHandler, "Expected to go into transport delegate");
        }
コード例 #8
0
ファイル: OutOfProcNode.cs プロジェクト: pmisik/msbuild
        private void HandleNodeConfiguration(NodeConfiguration configuration)
        {
            // Grab the system parameters.
            _buildParameters = configuration.BuildParameters;

            _buildParameters.ProjectRootElementCache = s_projectRootElementCacheBase;

            // Snapshot the current environment
            _savedEnvironment = CommunicationsUtilities.GetEnvironmentVariables();

            // Change to the startup directory
            try
            {
                NativeMethodsShared.SetCurrentDirectory(BuildParameters.StartupDirectory);
            }
            catch (DirectoryNotFoundException)
            {
                // Somehow the startup directory vanished. This can happen if build was started from a USB Key and it was removed.
                NativeMethodsShared.SetCurrentDirectory(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory);
            }

            // Replicate the environment.  First, unset any environment variables set by the previous configuration.
            if (_currentConfiguration != null)
            {
                foreach (string key in _currentConfiguration.BuildParameters.BuildProcessEnvironment.Keys)
                {
                    Environment.SetEnvironmentVariable(key, null);
                }
            }

            // Now set the new environment
            foreach (KeyValuePair <string, string> environmentPair in _buildParameters.BuildProcessEnvironment)
            {
                Environment.SetEnvironmentVariable(environmentPair.Key, environmentPair.Value);
            }

            // We want to make sure the global project collection has the toolsets which were defined on the parent
            // so that any custom toolsets defined can be picked up by tasks who may use the global project collection but are
            // executed on the child node.
            ICollection <Toolset> parentToolSets = _buildParameters.ToolsetProvider.Toolsets;

            if (parentToolSets != null)
            {
                ProjectCollection.GlobalProjectCollection.RemoveAllToolsets();

                foreach (Toolset toolSet in parentToolSets)
                {
                    ProjectCollection.GlobalProjectCollection.AddToolset(toolSet);
                }
            }

            // Set the culture.
            CultureInfo.CurrentCulture   = _buildParameters.Culture;
            CultureInfo.CurrentUICulture = _buildParameters.UICulture;

            // Get the node ID.
            _buildParameters.NodeId      = configuration.NodeId;
            _buildParameters.IsOutOfProc = true;

#if FEATURE_APPDOMAIN
            // And the AppDomainSetup
            _buildParameters.AppDomainSetup = configuration.AppDomainSetup;
#endif

            // Set up the logging service.
            LoggingServiceFactory loggingServiceFactory = new LoggingServiceFactory(LoggerMode.Asynchronous, configuration.NodeId);
            _componentFactories.ReplaceFactory(BuildComponentType.LoggingService, loggingServiceFactory.CreateInstance);

            _loggingService = _componentFactories.GetComponent(BuildComponentType.LoggingService) as ILoggingService;

            BuildEventArgTransportSink sink = new BuildEventArgTransportSink(SendPacket);

            _shutdownException = null;

            if (configuration.LoggingNodeConfiguration.IncludeEvaluationMetaprojects)
            {
                _loggingService.IncludeEvaluationMetaprojects = true;
            }

            if (configuration.LoggingNodeConfiguration.IncludeEvaluationProfiles)
            {
                _loggingService.IncludeEvaluationProfile = true;
            }

            if (configuration.LoggingNodeConfiguration.IncludeTaskInputs)
            {
                _loggingService.IncludeTaskInputs = true;
            }

            if (configuration.LoggingNodeConfiguration.IncludeEvaluationPropertiesAndItems)
            {
                _loggingService.IncludeEvaluationPropertiesAndItems = true;
            }

            try
            {
                // If there are no node loggers to initialize dont do anything
                if (configuration.LoggerDescriptions?.Length > 0)
                {
                    _loggingService.InitializeNodeLoggers(configuration.LoggerDescriptions, sink, configuration.NodeId);
                }
            }
            catch (Exception ex) when(!ExceptionHandling.IsCriticalException(ex))
            {
                OnEngineException(ex);
            }

            _loggingService.OnLoggingThreadException += OnLoggingThreadException;

            string   forwardPropertiesFromChild = Environment.GetEnvironmentVariable("MSBUILDFORWARDPROPERTIESFROMCHILD");
            string[] propertyListToSerialize    = null;

            // Get a list of properties which should be serialized
            if (!String.IsNullOrEmpty(forwardPropertiesFromChild))
            {
                propertyListToSerialize = forwardPropertiesFromChild.Split(MSBuildConstants.SemicolonChar, StringSplitOptions.RemoveEmptyEntries);
            }

            _loggingService.PropertiesToSerialize = propertyListToSerialize;
            _loggingService.RunningOnRemoteNode   = true;

            string forwardAllProperties = Environment.GetEnvironmentVariable("MSBUILDFORWARDALLPROPERTIESFROMCHILD");
            if (String.Equals(forwardAllProperties, "1", StringComparison.OrdinalIgnoreCase) || _buildParameters.LogInitialPropertiesAndItems)
            {
                _loggingService.SerializeAllProperties = true;
            }
            else
            {
                _loggingService.SerializeAllProperties = false;
            }

            // Now prep the buildRequestEngine for the build.
            _loggingContext = new NodeLoggingContext(_loggingService, configuration.NodeId, false /* inProcNode */);

            if (_shutdownException != null)
            {
                HandleShutdown(out Exception exception);
                throw exception;
            }

            _buildRequestEngine.InitializeForBuild(_loggingContext);

            // Finally store off this configuration packet.
            _currentConfiguration = configuration;
        }
コード例 #9
0
        public void TestConsumeNullBuildEvent()
        {
            BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(PacketProcessor);

            transportSink.Consume(null, 0);
        }
コード例 #10
0
 public void TestConstructorNullSendDataDelegate()
 {
     BuildEventArgTransportSink transportSink = new BuildEventArgTransportSink(null);
 }