Beispiel #1
0
 public Username(string username)
 {
     Contract.Assert(!string.IsNullOrWhiteSpace(username));
     _username = username.Trim();
 }
Beispiel #2
0
 /// <summary>
 /// Returns a collection of profiled entries that resulted from evaluation
 /// </summary>
 /// <remarks>
 /// Evaluation should be finished in order to call this function
 /// </remarks>
 public IReadOnlyCollection <ProfiledFunctionCall> GetProfiledEntries()
 {
     Contract.Assert(m_evaluationFinished, "Evaluation should be finished to be able to retrieve the profiled entries");
     return(m_profilerEntries.ToArray());
 }
Beispiel #3
0
 public static void Main(string[] args)
 {
     Contract.Assert(args[0] != null);
     Contract.Assert(args[0] == "");
 }
Beispiel #4
0
        private async Task <Possible <ProjectGraphWithPredictionsResult <AbsolutePath> > > ComputeBuildGraphAsync(
            AbsolutePath responseFile,
            IEnumerable <AbsolutePath> projectEntryPoints,
            AbsolutePath outputFile,
            IEnumerable <AbsolutePath> msBuidSearchLocations,
            IEnumerable <AbsolutePath> dotnetSearchLocations,
            BuildParameters.IBuildParameters buildParameters)
        {
            AbsolutePath dotnetExeLocation = AbsolutePath.Invalid;

            if (m_resolverSettings.ShouldRunDotNetCoreMSBuild())
            {
                if (!TryFindDotNetExe(dotnetSearchLocations, out dotnetExeLocation, out string failure))
                {
                    return(ProjectGraphWithPredictionsResult <AbsolutePath> .CreateFailure(
                               GraphConstructionError.CreateFailureWithoutLocation(failure),
                               CollectionUtilities.EmptyDictionary <string, AbsolutePath>(), AbsolutePath.Invalid));
                }
            }
            SandboxedProcessResult result = await RunMsBuildGraphBuilderAsync(responseFile, projectEntryPoints, outputFile, msBuidSearchLocations, dotnetExeLocation, buildParameters);

            string standardError = result.StandardError.CreateReader().ReadToEndAsync().GetAwaiter().GetResult();

            if (result.ExitCode != 0)
            {
                // In case of a cancellation, the tool may have exited with a non-zero
                // code, but that's expected
                if (!m_context.CancellationToken.IsCancellationRequested)
                {
                    // This should never happen! Report the standard error and exit gracefully
                    Tracing.Logger.Log.GraphConstructionInternalError(
                        m_context.LoggingContext,
                        m_resolverSettings.Location(m_context.PathTable),
                        standardError);
                }

                return(new MsBuildGraphConstructionFailure(m_resolverSettings, m_context.PathTable));
            }

            // If the tool exited gracefully, but standard error is not empty, that
            // is interpreted as a warning. We propagate that to the BuildXL log
            if (!string.IsNullOrEmpty(standardError))
            {
                Tracing.Logger.Log.GraphConstructionFinishedSuccessfullyButWithWarnings(
                    m_context.LoggingContext,
                    m_resolverSettings.Location(m_context.PathTable),
                    standardError);
            }

            TrackFilesAndEnvironment(result.AllUnexpectedFileAccesses, outputFile.GetParent(m_context.PathTable));

            var serializer = JsonSerializer.Create(ProjectGraphSerializationSettings.Settings);

            serializer.Converters.Add(new AbsolutePathJsonConverter(m_context.PathTable));
            serializer.Converters.Add(new ValidAbsolutePathEnumerationJsonConverter());

            using (var sr = new StreamReader(outputFile.ToString(m_context.PathTable)))
                using (var reader = new JsonTextReader(sr))
                {
                    var projectGraphWithPredictionsResult = serializer.Deserialize <ProjectGraphWithPredictionsResult <AbsolutePath> >(reader);

                    // A successfully constructed graph should always have a valid path to MsBuild
                    Contract.Assert(!projectGraphWithPredictionsResult.Succeeded || projectGraphWithPredictionsResult.PathToMsBuild.IsValid);
                    // A successfully constructed graph should always have at least one project node
                    Contract.Assert(!projectGraphWithPredictionsResult.Succeeded || projectGraphWithPredictionsResult.Result.ProjectNodes.Length > 0);
                    // A failed construction should always have a failure set
                    Contract.Assert(projectGraphWithPredictionsResult.Succeeded || projectGraphWithPredictionsResult.Failure != null);

                    // Let's log the paths to the used MsBuild assemblies, just for debugging purposes
                    Tracing.Logger.Log.GraphConstructionToolCompleted(
                        m_context.LoggingContext, m_resolverSettings.Location(m_context.PathTable),
                        string.Join(",\n", projectGraphWithPredictionsResult.MsBuildAssemblyPaths.Select(kvp => I($"[{kvp.Key}]:{kvp.Value.ToString(m_context.PathTable)}"))),
                        projectGraphWithPredictionsResult.PathToMsBuild.ToString(m_context.PathTable));

                    return(m_resolverSettings.ShouldRunDotNetCoreMSBuild() ? projectGraphWithPredictionsResult.WithPathToDotNetExe(dotnetExeLocation) : projectGraphWithPredictionsResult);
                }
        }
Beispiel #5
0
        public async Task RunAsync(CancellationToken cancellationToken = default)
        {
            if (IsPersistanceEnabled())
            {
                LoadState(_configuration.PersistStatePath);

                // Persist before the run begins, store the reconciliation
                SaveState(_configuration.PersistStatePath);
            }

            _logger.Debug("Starting to monitor");

            Dictionary <State, int> oldStates = null;

            while (!cancellationToken.IsCancellationRequested)
            {
                var now = _clock.UtcNow;

                // Approximate count of rules in each state. They do not necessarily sum to the total, because rules
                // may change state as we are computing the dictionary.
                var states = new Dictionary <State, int>()
                {
                    { State.Running, 0 },
                    { State.Scheduled, 0 },
                    { State.Waiting, 0 },
                    { State.Failed, 0 },
                };

                foreach (var kvp in _schedule)
                {
                    var rule  = kvp.Value.Rule;
                    var entry = kvp.Value;

                    lock (entry.Lock)
                    {
                        states[entry.State] += 1;

                        if (!entry.ShouldSchedule(now, retryOnFailureWaitTime: _configuration.RetryOnFailureAfter))
                        {
                            continue;
                        }

                        Contract.Assert(entry.State != State.Running && entry.State != State.Scheduled);
                        entry.State = State.Scheduled;
                    }

                    _ = Task.Run(async() =>
                    {
                        // NOTE(jubayard): make sure this runs in a different thread than the scheduler.
                        await Task.Yield();

#pragma warning disable ERP022 // Unobserved exception in generic exception handler
                        try
                        {
                            await RunRuleAsync(entry);
                        }
                        catch (Exception exception)
                        {
                            _logger.Fatal($"Scheduler threw an exception while running rule: {exception?.ToString()}");
                        }
#pragma warning restore ERP022 // Unobserved exception in generic exception handler
                    });
                }

                if (oldStates == null || states.Any(kvp => oldStates[kvp.Key] != kvp.Value))
                {
                    var statesString = string.Join(", ", states.Select(kvp => $"{kvp.Key}={kvp.Value}"));
                    _logger.Debug($"Scheduler state: {statesString}");
                    oldStates = states;
                }

                if (IsPersistanceEnabled())
                {
                    SaveState(_configuration.PersistStatePath);
                }

                if (!cancellationToken.IsCancellationRequested)
                {
                    await Task.Delay(_configuration.PollingPeriod);
                }
            }

            // TODO(jubayard): wait until all rules are done executing. Not implemented because it really isn't that
            // important for now. It would be if we were hot-reloading configuration files.
        }
Beispiel #6
0
            //---------------------------------------------------------------------------------------
            // Dispose of resources associated with the underlying enumerator.
            //

            protected override void Dispose(bool disposing)
            {
                Contract.Assert(m_source != null);
                m_source.Dispose();
            }
Beispiel #7
0
        /// <summary>
        /// Diffs weak fingerprints.
        /// </summary>
        /// <param name="weakFingerprint">Weak fingerprint.</param>
        /// <param name="weakFingerprintTree">Weak fingerprint tree.</param>
        /// <param name="otherWeakFingerprint">Other weak fingerprint.</param>
        /// <param name="otherWeakFingerprintTree">Other weak fingerprint tree.</param>
        /// <returns></returns>
        public static JObject DiffWeakFingerprints(
            string weakFingerprint,
            JsonNode weakFingerprintTree,
            string otherWeakFingerprint,
            JsonNode otherWeakFingerprintTree)
        {
            JObject result = new JObject();

            if (weakFingerprint == otherWeakFingerprint)
            {
                return(result);
            }

            // {
            //   WeakFingerprint: { Old: old_weak_fingerprint, New: new_weak_fingerprint }
            // }
            AddPropertyIfNotNull(result, RenderSingleValueDiff("WeakFingerprint", weakFingerprint, otherWeakFingerprint));

            using (var weakFingerprintDataPool = JsonNodeMapPool.GetInstance())
                using (var otherWeakFingerprintDataPool = JsonNodeMapPool.GetInstance())
                {
                    var weakFingerprintData      = weakFingerprintDataPool.Instance;
                    var otherWeakFingerprintData = otherWeakFingerprintDataPool.Instance;

                    JsonTree.VisitTree(weakFingerprintTree, wfNode => weakFingerprintData[wfNode.Name]           = wfNode, recurse: false);
                    JsonTree.VisitTree(otherWeakFingerprintTree, wfNode => otherWeakFingerprintData[wfNode.Name] = wfNode, recurse: false);

                    var fields = new HashSet <string>(weakFingerprintData.Keys.Concat(otherWeakFingerprintData.Keys));

                    foreach (var field in fields)
                    {
                        bool getFieldNode      = weakFingerprintData.TryGetValue(field, out JsonNode fieldNode);
                        bool getOtherFieldNode = otherWeakFingerprintData.TryGetValue(field, out JsonNode otherFieldNode);

                        if (getFieldNode != getOtherFieldNode)
                        {
                            string fieldValue = getFieldNode
                            ? (fieldNode.Values != null && fieldNode.Values.Count == 1
                                ? fieldNode.Values[0]
                                : CacheMissAnalysisUtilities.RepeatedStrings.ExistentValue)
                            : CacheMissAnalysisUtilities.RepeatedStrings.UnspecifiedValue;
                            string otherFieldValue = getOtherFieldNode
                            ? (otherFieldNode.Values != null && otherFieldNode.Values.Count == 1
                                ? otherFieldNode.Values[0]
                                : CacheMissAnalysisUtilities.RepeatedStrings.ExistentValue)
                            : CacheMissAnalysisUtilities.RepeatedStrings.UnspecifiedValue;

                            AddPropertyIfNotNull(result, RenderSingleValueDiff(field, fieldValue, otherFieldValue));
                        }
                        else if (getFieldNode && getOtherFieldNode)
                        {
                            Contract.Assert(fieldNode != null);
                            Contract.Assert(otherFieldNode != null);

                            AddPropertyIfNotNull(result, DiffWeakFingerprintField(fieldNode, otherFieldNode));
                        }
                    }
                }

            Contract.Assert(result.Count > 0);

            return(result);
        }
 private BindableVectorToListAdapter()
 {
     Contract.Assert(false, "This class is never instantiated");
 }
 public CompareAttributeAdapter(ModelMetadata metadata, ControllerContext context, DataAnnotationsCompareAttribute attribute)
     : base(metadata, context, attribute)
 {
     Contract.Assert(attribute.GetType() == typeof(DataAnnotationsCompareAttribute));
 }
        private void WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataDeltaWriter writer,
                               ODataSerializerContext writeContext)
        {
            Contract.Assert(writer != null);
            Contract.Assert(writeContext != null);
            Contract.Assert(enumerable != null);
            Contract.Assert(feedType != null);

            IEdmStructuredTypeReference elementType = GetResourceType(feedType);

            if (elementType.IsComplex())
            {
                ODataResourceSet resourceSet = new ODataResourceSet()
                {
                    TypeName = feedType.FullName()
                };

                writer.WriteStart(resourceSet);

                ODataResourceSerializer entrySerializer = SerializerProvider.GetEdmTypeSerializer(elementType) as ODataResourceSerializer;
                if (entrySerializer == null)
                {
                    throw new SerializationException(
                              Error.Format(SRResources.TypeCannotBeSerialized, elementType.FullName(), typeof(ODataMediaTypeFormatter).Name));
                }

                foreach (object entry in enumerable)
                {
                    entrySerializer.WriteDeltaObjectInline(entry, elementType, writer, writeContext);
                }
            }
            else
            {
                ODataDeltaResourceSet deltaFeed = CreateODataDeltaFeed(enumerable, feedType.AsCollection(), writeContext);
                if (deltaFeed == null)
                {
                    throw new SerializationException(Error.Format(SRResources.CannotSerializerNull, DeltaFeed));
                }

                // save this for later to support JSON odata.streaming.
                Uri nextPageLink = deltaFeed.NextPageLink;
                deltaFeed.NextPageLink = null;

                //Start writing of the Delta Feed
                writer.WriteStart(deltaFeed);

                //Iterate over all the entries present and select the appropriate write method.
                //Write method creates ODataDeltaDeletedEntry / ODataDeltaDeletedLink / ODataDeltaLink or ODataEntry.
                foreach (object entry in enumerable)
                {
                    if (entry == null)
                    {
                        throw new SerializationException(SRResources.NullElementInCollection);
                    }

                    IEdmChangedObject edmChangedObject = entry as IEdmChangedObject;
                    if (edmChangedObject == null)
                    {
                        throw new SerializationException(Error.Format(SRResources.CannotWriteType, GetType().Name, enumerable.GetType().FullName));
                    }

                    switch (edmChangedObject.DeltaKind)
                    {
                    case EdmDeltaEntityKind.DeletedEntry:
                        WriteDeltaDeletedEntry(entry, writer, writeContext);
                        break;

                    case EdmDeltaEntityKind.DeletedLinkEntry:
                        WriteDeltaDeletedLink(entry, writer, writeContext);
                        break;

                    case EdmDeltaEntityKind.LinkEntry:
                        WriteDeltaLink(entry, writer, writeContext);
                        break;

                    case EdmDeltaEntityKind.Entry:
                    {
                        ODataResourceSerializer entrySerializer = SerializerProvider.GetEdmTypeSerializer(elementType) as ODataResourceSerializer;
                        if (entrySerializer == null)
                        {
                            throw new SerializationException(
                                      Error.Format(SRResources.TypeCannotBeSerialized, elementType.FullName(), typeof(ODataMediaTypeFormatter).Name));
                        }
                        entrySerializer.WriteDeltaObjectInline(entry, elementType, writer, writeContext);
                        break;
                    }

                    default:
                        break;
                    }
                }

                // Subtle and surprising behavior: If the NextPageLink property is set before calling WriteStart(feed),
                // the next page link will be written early in a manner not compatible with odata.streaming=true. Instead, if
                // the next page link is not set when calling WriteStart(feed) but is instead set later on that feed
                // object before calling WriteEnd(), the next page link will be written at the end, as required for
                // odata.streaming=true support.
                if (nextPageLink != null)
                {
                    deltaFeed.NextPageLink = nextPageLink;
                }
            }

            //End Writing of the Delta Feed
            writer.WriteEnd();
        }
Beispiel #11
0
 internal StreamAsyncHelper(Stream stream)
 {
     Contract.Assert(stream != null);
     _stream = stream;
 }
Beispiel #12
0
 internal static void ContractAssertMonitorStatus(object syncObj, bool held)
 {
     Contract.Requires(syncObj != null, "The monitor object to check must be provided.");
     Contract.Assert(Monitor.IsEntered(syncObj) == held, "The locking scheme was not correctly followed.");
 }
 internal EnumTypeConfiguration(EnumTypeConfiguration configuration)
 {
     Contract.Assert(configuration != null);
     Contract.Assert(configuration.ClrType == typeof(TEnumType));
     this._configuration = configuration;
 }
Beispiel #14
0
 public CompleteTaskOnCloseStream(Stream innerStream, TaskCompletionSource <bool> serializeToStreamTask)
     : base(innerStream)
 {
     Contract.Assert(serializeToStreamTask != null);
     _serializeToStreamTask = serializeToStreamTask;
 }
        public static ODataPathTemplate ParseTemplate(this IODataPathTemplateHandler handler, IEdmModel model, string odataPathTemplate)
        {
            Contract.Assert(handler != null);

            return(handler.ParseTemplate(odataPathTemplate, new MockContainer(model)));
        }
        private static string FormatPropertyForClientValidation(string property)
        {
            Contract.Assert(property != null);

            return("*." + property);
        }
        public override bool CanHandle(MethodCallExpression expression)
        {
            Contract.Assert(expression.Method != null);

            return(expression.Method.DeclaringType == typeof(Math) && expression.Method.Name == "Floor");
        }
 public FaultingHttpContent(Exception exception)
 {
     Contract.Assert(exception != null);
     _exception = exception;
 }
Beispiel #19
0
        /// <summary>
        /// Diffs strong fingerprints.
        /// </summary>
        /// <param name="pathSetHash">Pathset hash.</param>
        /// <param name="pathSetTree">Pathset tree.</param>
        /// <param name="strongFingerprintInputTree">Strong fingerprint input tree.</param>
        /// <param name="otherPathSetHash">Other pathset hash.</param>
        /// <param name="otherPathSetTree">Other pathset tree.</param>
        /// <param name="otherStrongFingerprintInputTree">Other strong fingerprint input tree.</param>
        /// <param name="getDirectoryMembership">Delegate for getting directory membership.</param>
        /// <param name="getOtherDirectoryMembership">Delegate for getting other directory membership.</param>
        /// <returns></returns>
        public static JObject DiffPathSets(
            string pathSetHash,
            JsonNode pathSetTree,
            JsonNode strongFingerprintInputTree,
            string otherPathSetHash,
            JsonNode otherPathSetTree,
            JsonNode otherStrongFingerprintInputTree,
            Func <string, IReadOnlyList <string> > getDirectoryMembership,
            Func <string, IReadOnlyList <string> > getOtherDirectoryMembership)
        {
            JObject result = new JObject();

            if (pathSetHash == otherPathSetHash)
            {
                return(result);
            }

            // {
            //   PathSetHash: { Old: old_path_set_hash, New: new_path_set_hash }
            // }
            AddPropertyIfNotNull(result, RenderSingleValueDiff("PathSetHash", pathSetHash, otherPathSetHash));

            JsonNode unsafeOptionsNode      = JsonTree.FindNodeByName(pathSetTree, ObservedPathSet.Labels.UnsafeOptions);
            JsonNode otherUnsafeOptionsNode = JsonTree.FindNodeByName(otherPathSetTree, ObservedPathSet.Labels.UnsafeOptions);

            // {
            //   UnsafeOptions:
            //   {
            //        <property_Name>:
            //        {
            //           Old: old_value,
            //           New: new_value
            //        }
            //        PreserveOutputInfo:
            //        {
            //            <property_Name>:
            //            {
            //               Old: old_value,
            //               New: new_value
            //            }
            //        }
            //   }
            AddPropertyIfNotNull(result, DiffUnsafeOptions(unsafeOptionsNode, otherUnsafeOptionsNode));

            AddPropertyIfNotNull(
                result,
                DiffObservedPaths(
                    pathSetTree,
                    strongFingerprintInputTree,
                    otherPathSetTree,
                    otherStrongFingerprintInputTree,
                    getDirectoryMembership,
                    getOtherDirectoryMembership));

            JsonNode obsFileNameNode      = JsonTree.FindNodeByName(pathSetTree, ObservedPathSet.Labels.ObservedAccessedFileNames);
            JsonNode otherObsFileNameNode = JsonTree.FindNodeByName(otherPathSetTree, ObservedPathSet.Labels.ObservedAccessedFileNames);

            bool hasDiff = ExtractUnorderedListDiff(obsFileNameNode.Values, otherObsFileNameNode.Values, out var addedFileNames, out var removedFileName);

            if (hasDiff)
            {
                result.Add(new JProperty(
                               ObservedPathSet.Labels.ObservedAccessedFileNames,
                               RenderUnorderedListDiff(addedFileNames, removedFileName, RenderPath)));
            }

            Contract.Assert(result.Count > 0);

            return(result);
        }
Beispiel #20
0
        public void Test1()
        {
            var path = Dijkstra <int> .FindPath(new[] { 3 }, i => new[] { i + 1 }, i => i == 10);

            Contract.Assert(path.SequenceEqual(Enumerable.Range(3, 10 + 1 - 3)));
        }
Beispiel #21
0
        private static void TraversePathSetPaths(
            JsonNode pathSetPathsNode,
            JsonNode observedInputs,
            Action <ObservedInputData> action)
        {
            string path    = null;
            string flags   = null;
            string pattern = null;

            string hashMarker = null;
            string hash       = null;

            var obIt = observedInputs?.Children.First;

            for (var it = pathSetPathsNode.Children.First; it != null; it = it.Next)
            {
                var elem = it.Value;
                switch (elem.Name)
                {
                case ObservedPathEntryConstants.Path:
                    if (path != null)
                    {
                        action(new ObservedInputData(path, flags, pattern, hashMarker, hash));
                        path       = null;
                        flags      = null;
                        pattern    = null;
                        hashMarker = null;
                        hash       = null;
                    }

                    path = elem.Values[0];

                    if (obIt != null)
                    {
                        hashMarker = obIt.Value.Name;
                        hash       = obIt.Value.Values[0];
                        obIt       = obIt.Next;
                    }

                    break;

                case ObservedPathEntryConstants.Flags:
                    Contract.Assert(path != null);
                    flags = elem.Values[0];
                    break;

                case ObservedPathEntryConstants.EnumeratePatternRegex:
                    Contract.Assert(path != null);
                    pattern = elem.Values[0];
                    break;

                default:
                    break;
                }
            }

            if (path != null)
            {
                action(new ObservedInputData(path, flags, pattern, hashMarker, hash));
            }
        }
Beispiel #22
0
        public void Test2()
        {
            var path = Dijkstra <int> .FindPath(new[] { 1 }, i => new[] { i + 1, i * 2 }, i => i == 10);

            Contract.Assert(path.SequenceEqual(new[] { 1, 2, 4, 5, 10 }));
        }
Beispiel #23
0
        private Task <SandboxedProcessResult> RunMsBuildGraphBuilderAsync(
            AbsolutePath responseFile,
            IEnumerable <AbsolutePath> projectEntryPoints,
            AbsolutePath outputFile,
            IEnumerable <AbsolutePath> msBuildSearchLocations,
            AbsolutePath dotnetExeLocation,
            BuildParameters.IBuildParameters buildParameters)
        {
            Contract.Assert(!m_resolverSettings.ShouldRunDotNetCoreMSBuild() || dotnetExeLocation.IsValid);

            AbsolutePath toolDirectory    = m_configuration.Layout.BuildEngineDirectory.Combine(m_context.PathTable, RelativePathToGraphConstructionTool).GetParent(m_context.PathTable);
            string       outputDirectory  = outputFile.GetParent(m_context.PathTable).ToString(m_context.PathTable);
            string       outputFileString = outputFile.ToString(m_context.PathTable);
            IReadOnlyCollection <string> entryPointTargets = m_resolverSettings.InitialTargets ?? CollectionUtilities.EmptyArray <string>();

            var requestedQualifiers = m_requestedQualifiers.Select(qualifierId => MsBuildResolverUtils.CreateQualifierAsGlobalProperties(qualifierId, m_context)).ToList();

            var arguments = new MSBuildGraphBuilderArguments(
                projectEntryPoints.Select(entryPoint => entryPoint.ToString(m_context.PathTable)).ToList(),
                outputFileString,
                new GlobalProperties(m_resolverSettings.GlobalProperties ?? CollectionUtilities.EmptyDictionary <string, string>()),
                msBuildSearchLocations.Select(location => location.ToString(m_context.PathTable)).ToList(),
                entryPointTargets,
                requestedQualifiers,
                m_resolverSettings.AllowProjectsToNotSpecifyTargetProtocol == true,
                m_resolverSettings.ShouldRunDotNetCoreMSBuild());

            var responseFilePath = responseFile.ToString(m_context.PathTable);

            SerializeResponseFile(responseFilePath, arguments);

            string graphConstructionToolPath = m_configuration.Layout.BuildEngineDirectory.Combine(m_context.PathTable, RelativePathToGraphConstructionTool).ToString(m_context.PathTable);
            string pathToTool;
            string toolArguments;

            // if we should call the dotnet core version of MSBuild, we need to actually call dotnet.exe and pass the tool itself as its first argument
            if (m_resolverSettings.ShouldRunDotNetCoreMSBuild())
            {
                pathToTool    = dotnetExeLocation.ToString(m_context.PathTable);
                toolArguments = I($"\"{graphConstructionToolPath}\" \"{responseFilePath}\"");
            }
            else
            {
                pathToTool    = graphConstructionToolPath;
                toolArguments = I($"\"{responseFilePath}\"");
            }

            Tracing.Logger.Log.LaunchingGraphConstructionTool(m_context.LoggingContext, m_resolverSettings.Location(m_context.PathTable), arguments.ToString(), pathToTool);

            // Just being defensive, make sure there is not an old output file lingering around
            File.Delete(outputFileString);

            return(FrontEndUtilities.RunSandboxedToolAsync(
                       m_context,
                       pathToTool,
                       buildStorageDirectory: outputDirectory,
                       fileAccessManifest: GenerateFileAccessManifest(toolDirectory, outputFile),
                       arguments: toolArguments,
                       workingDirectory: outputDirectory,
                       description: "MsBuild graph builder",
                       buildParameters,
                       beforeLaunch: () => ConnectToServerPipeAndLogProgress(outputFileString)));
        }
Beispiel #24
0
        public void Test5()
        {
            var path = Dijkstra <int> .FindPath(new[] { 10 }, i => new[] { i + 2, i * 3 - 1 }, i => i == 10);

            Contract.Assert(path.SequenceEqual(new[] { 10 }));
        }
Beispiel #25
0
        private async Task RunRuleAsync(Entry entry)
        {
            Contract.AssertNotNull(entry);

            var         rule      = entry.Rule;
            var         stopwatch = new Stopwatch();
            var         failed    = false;
            RuleContext context   = null;
            Exception   exception = null;

            try
            {
                await _runGate.WaitAsync();

                lock (entry.Lock)
                {
                    Contract.Assert(entry.State == State.Scheduled);
                    entry.State = State.Running;
                }

                _logger.Debug($"Running rule `{rule.Identifier}`. `{_runGate.CurrentCount}` more allowed to run");

                context = new RuleContext(Guid.NewGuid(), _clock.UtcNow);
                stopwatch.Restart();
                await rule.Run(context);
            }
            catch (Exception thrownException)
            {
                failed    = true;
                exception = thrownException;
            }
            finally
            {
                stopwatch.Stop();

                _runGate.Release();

                lock (entry.Lock)
                {
                    entry.LastRunTimeUtc = _clock.UtcNow;

                    Contract.Assert(entry.State == State.Running);
                    entry.State = failed ? State.Failed : State.Waiting;


                    var logMessage = $"Rule `{rule.Identifier}` finished running @ `{entry.LastRunTimeUtc}`, took {stopwatch.Elapsed} to run";
                    if (!failed)
                    {
                        _logger.Debug(logMessage);
                    }
                    else
                    {
                        _logger.Error($"{logMessage}. An exception has been caught and the rule has been disabled. Exception: {exception?.ToString() ?? "N/A"}");
                    }
                }

                _notifier?.Emit(new LogEntry
                {
                    RunTimeUtc     = context?.RunTimeUtc ?? _clock.UtcNow,
                    RuleIdentifier = rule.Identifier,
                    RunGuid        = context?.RunGuid ?? Guid.Empty,
                    Elapsed        = stopwatch.Elapsed,
                    ErrorMessage   = failed ? exception?.ToString() : "",
                });
            }
        }
Beispiel #26
0
        public void TestFail()
        {
            var path = Dijkstra <int> .FindPath(new[] { 1 }, i => new[] { (i * 3 - 1) % 20 }, i => i == 10);

            Contract.Assert(path == null);
        }
Beispiel #27
0
        private static ParserState ParseNameValuePairs(
            byte[] buffer,
            int bytesReady,
            ref int bytesConsumed,
            ref NameValueState nameValueState,
            long maximumLength,
            ref long totalBytesConsumed,
            CurrentNameValuePair currentNameValuePair,
            ICollection <KeyValuePair <string, string> > nameValuePairs)
        {
            Contract.Assert((bytesReady - bytesConsumed) >= 0, "ParseNameValuePairs()|(inputBufferLength - bytesParsed) < 0");
            Contract.Assert(maximumLength <= 0 || totalBytesConsumed <= maximumLength, "ParseNameValuePairs()|Headers already read exceeds limit.");

            // Remember where we started.
            int initialBytesParsed = bytesConsumed;
            int segmentStart;

            // Set up parsing status with what will happen if we exceed the buffer.
            ParserState parseStatus  = ParserState.DataTooBig;
            long        effectiveMax = maximumLength <= 0 ? Int64.MaxValue : maximumLength - totalBytesConsumed + initialBytesParsed;

            if (bytesReady < effectiveMax)
            {
                parseStatus  = ParserState.NeedMoreData;
                effectiveMax = bytesReady;
            }

            Contract.Assert(bytesConsumed < effectiveMax, "We have already consumed more than the max buffer length.");

            switch (nameValueState)
            {
            case NameValueState.Name:
                segmentStart = bytesConsumed;
                while (buffer[bytesConsumed] != '=' && buffer[bytesConsumed] != '&')
                {
                    if (++bytesConsumed == effectiveMax)
                    {
                        string name = Encoding.UTF8.GetString(buffer, segmentStart, bytesConsumed - segmentStart);
                        currentNameValuePair.Name.Append(name);
                        goto quit;
                    }
                }

                if (bytesConsumed > segmentStart)
                {
                    string name = Encoding.UTF8.GetString(buffer, segmentStart, bytesConsumed - segmentStart);
                    currentNameValuePair.Name.Append(name);
                }

                // Check if we got name=value or just name
                if (buffer[bytesConsumed] == '=')
                {
                    // Move part the '='
                    nameValueState = NameValueState.Value;
                    if (++bytesConsumed == effectiveMax)
                    {
                        goto quit;
                    }

                    goto case NameValueState.Value;
                }
                else
                {
                    // Copy parsed name-only to collection
                    currentNameValuePair.CopyNameOnlyTo(nameValuePairs);

                    // Move past the '&' but stay in same state
                    if (++bytesConsumed == effectiveMax)
                    {
                        goto quit;
                    }

                    goto case NameValueState.Name;
                }

            case NameValueState.Value:
                segmentStart = bytesConsumed;
                while (buffer[bytesConsumed] != '&')
                {
                    if (++bytesConsumed == effectiveMax)
                    {
                        string value = Encoding.UTF8.GetString(buffer, segmentStart, bytesConsumed - segmentStart);
                        currentNameValuePair.Value.Append(value);
                        goto quit;
                    }
                }

                if (bytesConsumed > segmentStart)
                {
                    string value = Encoding.UTF8.GetString(buffer, segmentStart, bytesConsumed - segmentStart);
                    currentNameValuePair.Value.Append(value);
                }

                // Copy parsed name value pair to collection
                currentNameValuePair.CopyTo(nameValuePairs);

                // Move past the '&'
                nameValueState = NameValueState.Name;
                if (++bytesConsumed == effectiveMax)
                {
                    goto quit;
                }

                goto case NameValueState.Name;
            }

quit:
            totalBytesConsumed += bytesConsumed - initialBytesParsed;
            return(parseStatus);
        }
Beispiel #28
0
        private void EndStep(RunnablePip runnablePip, PipExecutionStep step, TimeSpan duration)
        {
            var pipId           = runnablePip.PipId;
            var loggingContext  = runnablePip.LoggingContext;
            var pip             = runnablePip.Pip;
            var description     = runnablePip.Description;
            var executionResult = runnablePip.ExecutionResult;

            var completionData = m_pendingPipCompletions[pipId];

            completionData.SerializedData.ExecuteStepTicks = duration.Ticks;

            switch (step)
            {
            case PipExecutionStep.MaterializeInputs:
                if (!runnablePip.Result.HasValue ||
                    !runnablePip.Result.Value.Status.IndicatesFailure())
                {
                    m_workerPipStateManager.Transition(pipId, WorkerPipState.Prepped);
                }

                break;

            case PipExecutionStep.ExecuteProcess:
            case PipExecutionStep.ExecuteNonProcessPip:
                executionResult.Seal();
                m_workerPipStateManager.Transition(pipId, WorkerPipState.Executed);

                if (!executionResult.Result.IndicatesFailure())
                {
                    foreach (var outputContent in executionResult.OutputContent)
                    {
                        Tracing.Logger.Log.DistributionWorkerPipOutputContent(
                            loggingContext,
                            pip.SemiStableHash,
                            description,
                            outputContent.fileArtifact.Path.ToString(m_environment.Context.PathTable),
                            outputContent.fileInfo.Hash.ToHex());
                    }
                }

                break;

            case PipExecutionStep.CacheLookup:
                var runnableProcess = (ProcessRunnablePip)runnablePip;

                executionResult = new ExecutionResult();
                var cacheResult = runnableProcess.CacheResult;

                executionResult.SetResult(
                    loggingContext,
                    status: cacheResult == null ? PipResultStatus.Failed : PipResultStatus.Succeeded);

                if (cacheResult != null)
                {
                    executionResult.WeakFingerprint = cacheResult.WeakFingerprint;

                    if (cacheResult.CanRunFromCache)
                    {
                        var cacheHitData = cacheResult.GetCacheHitData();
                        if (m_environment.State.Cache.IsNewlyAdded(cacheHitData.PathSetHash))
                        {
                            executionResult.PathSet = cacheHitData.PathSet;
                        }

                        executionResult.PipCacheDescriptorV2Metadata = cacheHitData.Metadata;
                        executionResult.TwoPhaseCachingInfo          = new TwoPhaseCachingInfo(
                            weakFingerprint: cacheResult.WeakFingerprint,
                            pathSetHash: cacheHitData.PathSetHash,
                            strongFingerprint: cacheHitData.StrongFingerprint,

                            // NOTE: This should not be used so we set it to default values except the metadata hash (it is used for HistoricMetadataCache).
                            cacheEntry: new CacheEntry(cacheHitData.MetadataHash, "unused", ArrayView <ContentHash> .Empty));
                    }
                }

                executionResult.CacheLookupPerfInfo = runnableProcess.CacheLookupPerfInfo;
                executionResult.Seal();

                break;

            case PipExecutionStep.PostProcess:
                // Execution result is already computed during ExecuteProcess.
                Contract.Assert(executionResult != null);
                break;
            }

            if (executionResult == null)
            {
                executionResult = new ExecutionResult();

                // If no result is set, the step succeeded
                executionResult.SetResult(loggingContext, runnablePip.Result?.Status ?? PipResultStatus.Succeeded);
                executionResult.Seal();
            }

            completionData.StepExecutionCompleted.SetResult(executionResult);
        }
Beispiel #29
0
        //-----------------------------------------------------------------------------------
        // Initializes a new enumerator with the specified group state.
        //

        protected MergeEnumerator(QueryTaskGroupState taskGroupState)
        {
            Contract.Assert(taskGroupState != null);
            _taskGroupState = taskGroupState;
        }
        public Func <SerializationContext, PolymorphismSchema, MessagePackSerializer> CreateObjectConstructor(AssemblyBuilderEmittingContext context, AssemblyBuilderSerializerBuilder builder, SerializationTarget targetInfo)
        {
            var hasPackActions        = targetInfo != null && !typeof(IPackable).IsAssignableFrom(builder.TargetType);
            var hasUnpackActions      = targetInfo != null && !typeof(IUnpackable).IsAssignableFrom(builder.TargetType);
            var hasUnpackActionTables = hasUnpackActions && targetInfo.Members.Any(m => m.Member != null);               // Except tuples

#if FEATURE_TAP
            var hasPackAsyncActions        = targetInfo != null && !typeof(IAsyncPackable).IsAssignableFrom(builder.TargetType);
            var hasUnpackAsyncActions      = targetInfo != null && !typeof(IAsyncUnpackable).IsAssignableFrom(builder.TargetType);
            var hasUnpackAsyncActionTables = hasUnpackAsyncActions && targetInfo.Members.Any(m => m.Member != null);               // Except tuples
#endif // FEATURE_TAP
            // ReSharper disable RedundantDelegateCreation
            Func <bool, Func <ILConstruct> > packActionsInitialization =
                isAsync =>
                new Func <ILConstruct>(() => builder.EmitPackOperationListInitialization(context, targetInfo, isAsync));
            Func <bool, Func <ILConstruct> > packActionTableInitialization =
                isAsync =>
                new Func <ILConstruct>(() => builder.EmitPackOperationTableInitialization(context, targetInfo, isAsync));
            Func <bool, Func <ILConstruct> > unpackActionsInitialization =
                isAsync => new Func <ILConstruct>(() => builder.EmitUnpackOperationListInitialization(context, targetInfo, isAsync));
            Func <bool, Func <ILConstruct> > unpackActionTableInitialization =
                isAsync => new Func <ILConstruct>(() => builder.EmitUnpackOperationTableInitialization(context, targetInfo, isAsync));
            // ReSharper restore RedundantDelegateCreation

            var contextfulConstructor =
                this.CreateConstructor(
                    MethodAttributes.Public,
                    ConstructorParameterTypes,
                    (type, il) =>
                    this.CreateContextfulObjectConstructor(
                        context,
                        type,
                        il,
                        hasPackActions
                                                                ? packActionsInitialization(false)
                                                                : default(Func <ILConstruct>),
                        hasPackActions
                                                                ? packActionTableInitialization(false)
                                                                : default(Func <ILConstruct>),
                        hasUnpackActions
                                                                ? unpackActionsInitialization(false)
                                                                : default(Func <ILConstruct>),
                        hasUnpackActionTables
                                                                ? unpackActionTableInitialization(false)
                                                                : default(Func <ILConstruct>),
#if FEATURE_TAP
                        hasPackAsyncActions&& context.SerializationContext.SerializerOptions.WithAsync
                                                                ? packActionsInitialization(true)
                                                                : default(Func <ILConstruct>),
                        hasPackAsyncActions && context.SerializationContext.SerializerOptions.WithAsync
                                                                ? packActionTableInitialization(true)
                                                                : default(Func <ILConstruct>),
                        hasUnpackAsyncActions && context.SerializationContext.SerializerOptions.WithAsync
                                                                ? unpackActionsInitialization(true)
                                                                : default(Func <ILConstruct>),
                        hasUnpackAsyncActionTables && context.SerializationContext.SerializerOptions.WithAsync
                                                                ? unpackActionTableInitialization(true)
                                                                : default(Func <ILConstruct>),
#endif // FEATURE_TAP
                        (
                            hasUnpackActions
#if FEATURE_TAP
                            || hasUnpackAsyncActions
#endif // FEATURE_TAP
                        ) ? () => builder.EmitMemberListInitialization(context, targetInfo)
                                                                : default(Func <ILConstruct>),
                        context.IsUnpackToUsed
                                                                ? () => builder.EmitUnpackToInitialization(context)
                                                                : default(Func <ILConstruct>)
                        )
                    );
            this.CreateConstructor(
                MethodAttributes.Public,
                ReflectionAbstractions.EmptyTypes,
                (_, il) => CreateDefaultObjectConstructor(contextfulConstructor, il)
                );

#if !NETSTANDARD1_1 && !NETSTANDARD1_3
            var ctor = this._typeBuilder.CreateType().GetConstructor(ConstructorParameterTypes);
#else
            var ctor = this._typeBuilder.CreateTypeInfo().GetConstructor(ConstructorParameterTypes);
#endif // !NETSTANDARD1_1 && !NETSTANDARD1_3
            var contextParameter = Expression.Parameter(typeof(SerializationContext), "context");
            var schemaParameter  = Expression.Parameter(typeof(PolymorphismSchema), "schema");
#if DEBUG
            Contract.Assert(ctor != null, "ctor != null");
#endif
            return
                (Expression.Lambda <Func <SerializationContext, PolymorphismSchema, MessagePackSerializer> >(
                     Expression.New(
                         ctor,
                         contextParameter
                         ),
                     contextParameter,
                     schemaParameter
                     ).Compile());
        }