コード例 #1
0
        public override bool Execute()
        {
            var configFilePath = new FileInfo(Path.Combine(ProjectDirectory, FileName));

            if (!configFilePath.Exists)
            {
                Log.LogWarning(configFilePath.Name + " does not exist");
                return(true);
            }

            var sw = new Stopwatch();

            sw.Start();

            BuildEngine3.Yield();
            CancellationToken token = CancellationToken.None;

            Log.LogMessage(MessageImportance.High, Environment.NewLine + Resources.Text.RestoringLibraries);

            var      dependencies = Dependencies.FromTask(this);
            Manifest manifest     = Manifest.FromFileAsync(configFilePath.FullName, dependencies, token).Result;

            IEnumerable <ILibraryInstallationResult> results = manifest.RestoreAsync(token).Result;

            BuildEngine3.Reacquire();

            sw.Stop();

            PopulateFilesWritten(results, dependencies.GetHostInteractions());
            LogResults(sw, results);

            return(!Log.HasLoggedErrors);
        }
コード例 #2
0
        public override bool Execute()
        {
            if (YieldDuringToolExecution)
            {
                BuildEngine3.Yield();
            }

            Initialize();

            var result = true;

            try
            {
                Exception executionErrors = null;
                result = new ParallelExecutor(OutdatedTasks, EndToken).Execute(out executionErrors);
                if (executionErrors is object)
                {
                    throw executionErrors;
                }
            }
            catch (AggregateException e)
            {
                var origin = e.InnerException as OperationCanceledException;

                if (origin is object && result)
                {
                    Log.LogWarning("The build task has been canceled.");
                }
                else
                {
                    var errors = e.InnerExceptions.Where(a => a as OperationCanceledException == null);
                    if (errors.Any())
                    {
                        foreach (var error in errors)
                        {
                            Log.LogErrorFromException(error, true);
                        }
                    }
                    else
                    {
                        Log.LogErrorFromException(e, false);
                    }

                    result = false;
                }
            }
            finally
            {
                result = FinishBuild(0) == 0 && result;
            }

            if (YieldDuringToolExecution)
            {
                BuildEngine3.Reacquire();
            }

            return(result);
        }
コード例 #3
0
ファイル: ZipDirectory.cs プロジェクト: 3F/IeXod
        public override bool Execute()
        {
            DirectoryInfo sourceDirectory = new DirectoryInfo(SourceDirectory.ItemSpec);

            if (!sourceDirectory.Exists)
            {
                Log.LogErrorWithCodeFromResources("ZipDirectory.ErrorDirectoryDoesNotExist", sourceDirectory.FullName);
                return(false);
            }

            FileInfo destinationFile = new FileInfo(DestinationFile.ItemSpec);

            BuildEngine3.Yield();

            try
            {
                if (destinationFile.Exists)
                {
                    if (!Overwrite)
                    {
                        Log.LogErrorWithCodeFromResources("ZipDirectory.ErrorFileExists", destinationFile.FullName);

                        return(false);
                    }

                    try
                    {
                        File.Delete(destinationFile.FullName);
                    }
                    catch (Exception e)
                    {
                        Log.LogErrorWithCodeFromResources("ZipDirectory.ErrorFailed", sourceDirectory.FullName, destinationFile.FullName, e.Message);

                        return(false);
                    }
                }

                try
                {
                    Log.LogMessageFromResources(MessageImportance.High, "ZipDirectory.Comment", sourceDirectory.FullName, destinationFile.FullName);
                    ZipFile.CreateFromDirectory(sourceDirectory.FullName, destinationFile.FullName);
                }
                catch (Exception e)
                {
                    Log.LogErrorWithCodeFromResources("ZipDirectory.ErrorFailed", sourceDirectory.FullName, destinationFile.FullName, e.Message);
                }
            }
            finally
            {
                BuildEngine3.Reacquire();
            }

            return(!Log.HasLoggedErrors);
        }
コード例 #4
0
        public override bool Execute()
        {
            DirectoryInfo sourceDirectory = new DirectoryInfo(SourceDirectory.ItemSpec);

            if (!sourceDirectory.Exists)
            {
                Log.LogError($"Directory doesn't exist: {sourceDirectory.FullName}");
                return(false);
            }

            FileInfo destinationFile = new FileInfo(DestinationFile.ItemSpec);

            BuildEngine3.Yield();

            try
            {
                if (destinationFile.Exists)
                {
                    if (!Overwrite)
                    {
                        Log.LogError($"File exists: {destinationFile.FullName}");
                        return(false);
                    }

                    try
                    {
                        File.Delete(destinationFile.FullName);
                    }
                    catch (Exception e)
                    {
                        Log.LogErrorFromException(e, showStackTrace: true);
                        return(false);
                    }
                }

                try
                {
                    ZipFile.CreateFromDirectory(sourceDirectory.FullName, destinationFile.FullName);
                }
                catch (Exception e)
                {
                    Log.LogErrorFromException(e, showStackTrace: true);
                }
            }
            finally
            {
                BuildEngine3.Reacquire();
            }

            return(!Log.HasLoggedErrors);
        }
コード例 #5
0
        /// <inheritdoc cref="Task.Execute"/>
        public override bool Execute()
        {
            DirectoryInfo destinationDirectory;

            try {
                destinationDirectory = Directory.CreateDirectory(DestinationFolder.ItemSpec);
            } catch (Exception e) {
                Log.LogError("MSB3931: Failed to unzip to directory \"{0}\" because it could not be created.  {1}", DestinationFolder.ItemSpec, e.Message);

                return(false);
            }

            BuildEngine3.Yield();

            try {
                foreach (ITaskItem sourceFile in SourceFiles.TakeWhile(i => !_cancellationToken.IsCancellationRequested))
                {
                    if (!File.Exists(sourceFile.ItemSpec))
                    {
                        Log.LogError("MSB3932: Failed to unzip file \"{0}\" because the file does not exist or is inaccessible.", sourceFile.ItemSpec);
                        continue;
                    }

                    try {
                        using (FileStream stream = new FileStream(sourceFile.ItemSpec, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 0x1000, useAsync: false)) {
                            using (ZipArchive zipArchive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: false)) {
                                try {
                                    Extract(zipArchive, destinationDirectory);
                                } catch (Exception e) {
                                    // Unhandled exception in Extract() is a bug!
                                    Log.LogErrorFromException(e, showStackTrace: true);
                                    return(false);
                                }
                            }
                        }
                    } catch (OperationCanceledException) {
                        break;
                    } catch (Exception e) {
                        // Should only be thrown if the archive could not be opened (Access denied, corrupt file, etc)
                        Log.LogError("MSB3933: Failed to open zip file \"{0}\".  {1}", sourceFile.ItemSpec, e.Message);
                    }
                }
            } finally {
                BuildEngine3.Reacquire();
            }

            return(!_cancellationToken.IsCancellationRequested && !Log.HasLoggedErrors);
        }
コード例 #6
0
        protected int ProcessTasks()
        {
            int errCode = -1;

            if (taskScheduler.Count > 0)
            {
                string readTLogFName  = TaskName + ".read.1.tlog";
                string writeTLogFName = TaskName + ".write.1.tlog";
                string readTLog       = Path.Combine(TrackerIntermediateDirectory, readTLogFName);
                string writeTLog      = Path.Combine(TrackerIntermediateDirectory, writeTLogFName);
                if (!File.Exists(readTLog))
                {
                    using (File.Create(readTLog)) { }
                }
                if (!File.Exists(writeTLog))
                {
                    using (File.Create(writeTLog)) { }
                }

                try
                {
                    BuildEngine3.Yield();
                    if (taskScheduler.Run(cts, Log, SchedulerVerbose))
                    {
                        errCode = 0;
                    }
                }
                finally
                {
                    BuildEngine3.Reacquire();
                }
                if (!cts.IsCancellationRequested)
                {
                    _FinishBuild(0);
                }
            }
            else
            {
                errCode = 0;
            }
            return(errCode);
        }
コード例 #7
0
        public override bool Execute()
        {
            DirectoryInfo destinationDirectory;

            try
            {
                destinationDirectory = Directory.CreateDirectory(DestinationFolder.ItemSpec);
            }
            catch (Exception e)
            {
                Log.LogErrorWithCodeFromResources("Unzip.ErrorCouldNotCreateDestinationDirectory", DestinationFolder.ItemSpec, e.Message);

                return(false);
            }

            BuildEngine3.Yield();

            try
            {
                ParseIncludeExclude();

                if (!Log.HasLoggedErrors)
                {
                    foreach (ITaskItem sourceFile in SourceFiles.TakeWhile(i => !_cancellationToken.IsCancellationRequested))
                    {
                        if (!FileSystems.Default.FileExists(sourceFile.ItemSpec))
                        {
                            Log.LogErrorWithCodeFromResources("Unzip.ErrorFileDoesNotExist", sourceFile.ItemSpec);
                            continue;
                        }

                        try
                        {
                            using (FileStream stream = new FileStream(sourceFile.ItemSpec, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 0x1000, useAsync: false))
                            {
                                using (ZipArchive zipArchive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: false))
                                {
                                    try
                                    {
                                        Extract(zipArchive, destinationDirectory);
                                    }
                                    catch (Exception e)
                                    {
                                        // Unhandled exception in Extract() is a bug!
                                        Log.LogErrorFromException(e, showStackTrace: true);
                                        return(false);
                                    }
                                }
                            }
                        }
                        catch (OperationCanceledException)
                        {
                            break;
                        }
                        catch (Exception e)
                        {
                            // Should only be thrown if the archive could not be opened (Access denied, corrupt file, etc)
                            Log.LogErrorWithCodeFromResources("Unzip.ErrorCouldNotOpenFile", sourceFile.ItemSpec, e.Message);
                        }
                    }
                }
            }
            finally
            {
                BuildEngine3.Reacquire();
            }

            return(!_cancellationToken.IsCancellationRequested && !Log.HasLoggedErrors);
        }