Exemple #1
0
        private async Task <AnalyzerResult> LoadResultOrCleanAsync()
        {
            using (await DirectoryAccessor.TryLockAsync())
            {
                var binLog = this.FindLatestBinLog();
                if (binLog != null)
                {
                    var results = await TryLoadAnalyzerResultsAsync(binLog);

                    var result = results?.FirstOrDefault(p => p.ProjectFilePath == _projectFile.FullName);

                    var didCompile = DidPerformCoreCompile(result);
                    if (result != null)
                    {
                        if (result.Succeeded && didCompile)
                        {
                            return(result);
                        }
                    }
                }

                binLog?.DoWhenFileAvailable(() => binLog.Delete());
                var toClean = Directory.GetDirectories("obj");
                foreach (var directoryInfo in toClean)
                {
                    directoryInfo.Delete(true);
                }

                return(null);
            }
        }
Exemple #2
0
        private async Task <AnalyzerResult> BuildProjectAsync(AnalyzerResult result)
        {
            if (result != null)
            {
                return(result);
            }

            using (await DirectoryAccessor.TryLockAsync())
            {
                using (var operation = Log.OnEnterAndConfirmOnExit())
                {
                    try
                    {
                        operation.Info("Building package {name}", Name);
                        await DotnetBuild();

                        operation.Info("Workspace built");
                        operation.Succeed();
                    }
                    catch (Exception exception)
                    {
                        operation.Error("Exception building workspace", exception);
                        throw;
                    }

                    var binLog = this.FindLatestBinLog();

                    if (binLog == null)
                    {
                        throw new InvalidOperationException("Failed to build");
                    }

                    var results = await TryLoadAnalyzerResultsAsync(binLog);

                    if (results?.Count == 0)
                    {
                        throw new InvalidOperationException("The build log seems to contain no solutions or projects");
                    }

                    result = results?.FirstOrDefault(p => p.ProjectFilePath == _projectFile.FullName);

                    if (result?.Succeeded == true)
                    {
                        return(result);
                    }

                    throw new InvalidOperationException("Failed to build");
                }
            }
        }
Exemple #3
0
        private async Task <DirectoryInfo> GetProjectDirectory(string command)
        {
            if (Exists())
            {
                var result = await CommandLine.Execute(FilePath, command, DirectoryAccessor.GetFullyQualifiedRoot());

                var path = string.Join("", result.Output);
                if (result.ExitCode == 0 && !string.IsNullOrEmpty(path))
                {
                    var projectDirectory = new DirectoryInfo(string.Join("", result.Output));
                    if (projectDirectory.Exists)
                    {
                        return(projectDirectory);
                    }
                }
            }

            return(null);
        }
        protected IDirectoryManager FactoryManager(ConfigSettingsDto settings = null, IDbContextFactory <LogContext> logCtxFactory = null, IDbContextFactory <DirectoryContext> dirCtxFactory = null, IDbContextFactory <ExportContext> xprtCtxFactory = null)
        {
            if (settings == null)
            {
                settings = new ConfigSettingsDto
                {
                    StateCacheTtlSeconds       = 1200,
                    TranslationCacheTtlSeconds = 1200
                }
            }
            ;

            if (logCtxFactory == null)
            {
                logCtxFactory = new SqliteInMemoryContextFactory <LogContext>();
            }

            if (dirCtxFactory == null)
            {
                dirCtxFactory = new SqliteInMemoryContextFactory <DirectoryContext>();
            }

            if (xprtCtxFactory == null)
            {
                xprtCtxFactory = new SqliteInMemoryContextFactory <ExportContext>();
            }

            var cacheAccessor  = new CacheAccessor(new MemoryCache(), settings);
            var dirAccessor    = new DirectoryAccessor(dirCtxFactory);
            var logAccessor    = new LogAccessor(logCtxFactory);
            var exportAccessor = new ExportAccessor(xprtCtxFactory);

            var dirEngine = new DirectoryEngine(dirAccessor, cacheAccessor, exportAccessor);

            return(new DirectoryManager(dirEngine, logAccessor));
        }
    }
        private async Task <IAnalyzerResult> BuildProjectAsync(IAnalyzerResult result)
        {
            if (result != null)
            {
                return(result);
            }

            using (await DirectoryAccessor.TryLockAsync())
            {
                {
                    await DotnetBuild();

                    var binLog = this.FindLatestBinLog();

                    if (binLog == null)
                    {
                        throw new InvalidOperationException("Failed to build");
                    }

                    var results = await TryLoadAnalyzerResultsAsync(binLog);

                    if (results?.Count == 0)
                    {
                        throw new InvalidOperationException("The build log seems to contain no solutions or projects");
                    }

                    result = results?.FirstOrDefault(p => p.ProjectFilePath == _projectFile.FullName);

                    if (result?.Succeeded == true)
                    {
                        return(result);
                    }

                    throw new InvalidOperationException("Failed to build");
                }
            }
        }
Exemple #6
0
        public ProjectAsset(IDirectoryAccessor directoryAccessor, string csprojFileName = null) : base(directoryAccessor)
        {
            if (directoryAccessor == null)
            {
                throw new ArgumentNullException(nameof(directoryAccessor));
            }

            if (string.IsNullOrWhiteSpace(csprojFileName))
            {
                var firstProject = DirectoryAccessor.GetAllFiles().Single(f => f.Extension == ".csproj");
                _projectFile = DirectoryAccessor.GetFullyQualifiedFilePath(firstProject.FileName);
            }
            else
            {
                _projectFile = DirectoryAccessor.GetFullyQualifiedFilePath(csprojFileName);
            }

            Directory = DirectoryAccessor.GetFullyQualifiedRoot();
            Name      = _projectFile?.Name ?? Directory?.Name;
            _lastBuildErrorLogFile = directoryAccessor.GetFullyQualifiedFilePath(".trydotnet-builderror");
            _cleanupStep           = new PipelineStep <AnalyzerResult>(LoadResultOrCleanAsync);
            _projectBuildStep      = _cleanupStep.Then(BuildProjectAsync);
            _workspaceStep         = _projectBuildStep.Then(BuildWorkspaceAsync);
        }
Exemple #7
0
        public DirectoryHandle OpenDirectory(string path, OpenDirectoryMode mode)
        {
            FindFileSystem(path.AsSpan(), out FileSystemAccessor fileSystem, out ReadOnlySpan <char> subPath)
            .ThrowIfFailure();

            DirectoryHandle handle;

            if (IsEnabledAccessLog() && fileSystem.IsAccessLogEnabled)
            {
                TimeSpan          startTime = Time.GetCurrent();
                DirectoryAccessor dir       = fileSystem.OpenDirectory(subPath.ToString(), mode);
                handle = new DirectoryHandle(dir);
                TimeSpan endTime = Time.GetCurrent();

                OutputAccessLog(startTime, endTime, handle, $", path: \"{path}\", open_mode: {mode}");
            }
            else
            {
                DirectoryAccessor dir = fileSystem.OpenDirectory(subPath.ToString(), mode);
                handle = new DirectoryHandle(dir);
            }

            return(handle);
        }
Exemple #8
0
 public bool Exists()
 {
     return(DirectoryAccessor.FileExists(Name.ExecutableName()));
 }
Exemple #9
0
 public Task Prepare()
 {
     return(CommandLine.Execute(FilePath, MLS.PackageTool.PackageToolConstants.PreparePackage, DirectoryAccessor.GetFullyQualifiedRoot()));
 }
Exemple #10
0
 private string GetFilePath()
 {
     return(DirectoryAccessor.GetFullyQualifiedFilePath(Name.ExecutableName()).FullName);
 }
Exemple #11
0
        public async Task <WebAssemblyAsset> LocateWasmAsset()
        {
            var result = await CommandLine.Execute(GetFilePath(), MLS.PackageTool.PackageToolConstants.LocateWasmAsset, DirectoryAccessor.GetFullyQualifiedRoot());

            var projectDirectory = new DirectoryInfo(string.Join("", result.Output));

            if (!projectDirectory.Exists)
            {
                return(null);
            }

            return(new WebAssemblyAsset(new FileSystemDirectoryAccessor(projectDirectory)));
        }
Exemple #12
0
 internal DirectoryHandle(DirectoryAccessor directory)
 {
     Directory = directory;
 }