public void TestIpcResultMerge(IpcResultStatus lhsStatus, IpcResultStatus rhsStatus, IpcResultStatus mergeStatus)
        {
            var lhs    = new IpcResult(lhsStatus, "lhs");
            var rhs    = new IpcResult(rhsStatus, "rhs");
            var merged = IpcResult.Merge(lhs, rhs);

            // contains both payloads
            XAssert.Contains(merged.Payload, lhs.Payload, rhs.Payload);
            // has correct status
            XAssert.AreEqual(merged.ExitCode, mergeStatus);
        }
Exemple #2
0
        /// <summary>
        ///     Performs a functional composition of a number of <see cref="ServerAction"/> functions,
        ///     where the results are merged by calling <see cref="IpcResult.Merge(IIpcResult, IIpcResult)"/>.
        /// </summary>
        internal static ServerAction Compose(params ServerAction[] actions)
        {
            Contract.Requires(actions != null);
            Contract.Requires(actions.Length > 0);

            var first = actions.First();

            return(actions.Skip(1).Aggregate(first, (accumulator, currentAction) => new ServerAction(async(conf, daemon) =>
            {
                var lhsResult = await accumulator(conf, daemon);
                var rhsResult = await currentAction(conf, daemon);
                return IpcResult.Merge(lhsResult, rhsResult);
            })));
        }
Exemple #3
0
        private static async Task <IIpcResult> AddDropItemsAsync(Daemon daemon, IEnumerable <DropItemForBuildXLFile> dropItems)
        {
            (IEnumerable <DropItemForBuildXLFile> dedupedDropItems, string error) = DedupeDropItems(dropItems);

            if (error != null)
            {
                return(new IpcResult(IpcResultStatus.ExecutionError, error));
            }

            var ipcResultTasks = dedupedDropItems.Select(d => daemon.AddFileAsync(d)).ToArray();
            var ipcResults     = await TaskUtilities.SafeWhenAll(ipcResultTasks);

            return(IpcResult.Merge(ipcResults));
        }
Exemple #4
0
        /// <summary>
        /// This is used only for testing, particulary <code>Client.GetSealedDirectoryContent</code>
        /// </summary>
        internal async Task <IIpcResult> AddDirectoryAsync(string directoryPath, string directoryId, string dropDirectoryPath, bool enableChunkDedup, Client apiClient)
        {
            Contract.Requires(!string.IsNullOrEmpty(directoryPath));
            Contract.Requires(!string.IsNullOrEmpty(directoryId));
            Contract.Requires(dropDirectoryPath != null);

            if (apiClient == null)
            {
                return(new IpcResult(
                           IpcResultStatus.ExecutionError,
                           "ApiClient is not initialized"));
            }

            DirectoryArtifact directoryArtifact = DirectoryId.Parse(directoryId);

            var maybeResult = await apiClient.GetSealedDirectoryContent(directoryArtifact, directoryPath);

            if (!maybeResult.Succeeded)
            {
                return(new IpcResult(
                           IpcResultStatus.GenericError,
                           "could not get the directory content from BuildXL server:" + maybeResult.Failure.Describe()));
            }

            List <SealedDirectoryFile> directoryContent = maybeResult.Result;

            var addFileTasks = directoryContent.Select(
                file =>
            {
                var remoteFileName = Inv(
                    "{0}/{1}",
                    dropDirectoryPath,
                    // we need to convert '\' into '/' because this path would be a part of a drop url
                    GetRelativePath(directoryPath, file.FileName).Replace('\\', '/'));

                var dropItem = new DropItemForBuildXLFile(
                    apiClient,
                    file.FileName,
                    FileId.ToString(file.Artifact),
                    enableChunkDedup,
                    file.ContentInfo,
                    remoteFileName);
                return(AddFileAsync(dropItem));
            }).ToArray();

            var ipcResults = await BuildXL.Utilities.Tasks.TaskUtilities.SafeWhenAll(addFileTasks);

            return(IpcResult.Merge(ipcResults));
        }