コード例 #1
0
        private string GetFileName(CommandArguments args)
        {
            if (!string.IsNullOrEmpty(args.Script))
            {
                return(TakeExplicitBuildScriptName(args));
            }

            if (_file.Exists("./.flubu"))
            {
                var lines = _file.ReadAllLines("./.flubu");
                if (!string.IsNullOrEmpty(lines[0]) && _file.Exists(lines[0]))
                {
                    return(lines[0]);
                }
            }

            _log.LogInformation("Build script file name was not explicitly specified, searching the default locations:");

            foreach (var defaultScriptLocation in DefaultScriptLocations)
            {
                if (_file.Exists(defaultScriptLocation))
                {
                    _log.LogInformation("Found it, using the build script file '{0}'.", defaultScriptLocation);
                    return(defaultScriptLocation);
                }
            }

            return(null);
        }
コード例 #2
0
        private ProjectFileAnalyzerResult LocateCsproj(string location)
        {
            ProjectFileAnalyzerResult result = new ProjectFileAnalyzerResult();

            if (location == null)
            {
                foreach (var item in _csprojLocations)
                {
                    if (_file.Exists(item))
                    {
                        result.ProjectFileFound    = true;
                        result.ProjectFileLocation = Path.GetFullPath(item);
                        break;
                    }
                }
            }
            else
            {
                if (_file.Exists(location))
                {
                    result.ProjectFileFound    = true;
                    result.ProjectFileLocation = location;
                }
            }

            return(result);
        }
コード例 #3
0
        private void CopyIfDifferent(string sourcePath, IEnumerable <string> destinationDirs)
        {
            Debug.Assert(fileWrapper.Exists(sourcePath),
                         string.Format(CultureInfo.InvariantCulture, "Could not find the loader .targets file at {0}", sourcePath));

            var sourceContent = fileWrapper.ReadAllText(sourcePath);
            var fileName      = Path.GetFileName(sourcePath);

            foreach (var destinationDir in destinationDirs)
            {
                var destinationPath = Path.Combine(destinationDir, fileName);

                if (!fileWrapper.Exists(destinationPath))
                {
                    directoryWrapper.CreateDirectory(destinationDir); // creates all the directories in the path if needed
                    fileWrapper.Copy(sourcePath, destinationPath, overwrite: false);
                    logger.LogDebug(Resources.MSG_InstallTargets_Copy, fileName, destinationDir);
                }
                else
                {
                    var destinationContent = fileWrapper.ReadAllText(destinationPath);

                    if (!string.Equals(sourceContent, destinationContent, StringComparison.Ordinal))
                    {
                        fileWrapper.Copy(sourcePath, destinationPath, overwrite: true);
                        logger.LogDebug(Resources.MSG_InstallTargets_Overwrite, fileName, destinationDir);
                    }
                    else
                    {
                        logger.LogDebug(Resources.MSG_InstallTargets_UpToDate, fileName, destinationDir);
                    }
                }
            }
        }
コード例 #4
0
        public void Initialize(string cfgConverterFilePath)
        {
            if (string.IsNullOrWhiteSpace(cfgConverterFilePath) || !_file.Exists(cfgConverterFilePath))
            {
                throw new ArgumentException("Invalid converter tool file path");
            }

            _cfgConverterFilePath = cfgConverterFilePath;
        }
        public void WriteCodeGeneratorResponse(CodeGeneratorResponse response)
        {
            try
            {
                if (null == response.CodeGeneratorContext || response.Errors.Any())
                {
                    return;
                }

                var codeBehindFileName = _codeBehindFileHelper.GetOrAddCodeBehindFile(
                    response.CodeGeneratorContext.Source.FileName);

                if (codeBehindFileName.IsNullOrEmpty())
                {
                    _log.Error("Code Behind File Helper returned a null or empty CodeBehindFileName. Can not write file.");
                    return;
                }

                _log.InfoFormat("Updating [{0}]", codeBehindFileName);

                if (_fileWrapper.Exists(codeBehindFileName))
                {
                    _log.DebugFormat("Deleting file [{0}]", codeBehindFileName);
                    _fileWrapper.Delete(codeBehindFileName);
                }

                var codeBehindFileSource = response.GeneratedCodeSyntaxTree.GetText();

                if (string.IsNullOrEmpty(codeBehindFileSource))
                {
                    _log.WarnFormat("Writing Empty Code Behind File for [{0}]", codeBehindFileName);
                }

                _fileWrapper.WriteAllText(codeBehindFileName, codeBehindFileSource);

                _fileReader.EvictFromCache(codeBehindFileName);

                var openWindow = _visualStudioOpenDocumentManager.GetOpenDocument(codeBehindFileName);

                if (null != openWindow)
                {
                    openWindow.WriteText(codeBehindFileSource);
                }
            }
            catch (Exception e)
            {
                _log.Error(
                    string.Format("Exception writing Generated Code for Source Class [{0}]: {1}",
                                  response.CodeGeneratorContext.Source.FileName,
                                  e.Message), e);
            }
        }
コード例 #6
0
        private string GetFileName(CommandArguments args)
        {
            if (!string.IsNullOrEmpty(args.Script))
            {
                return(TakeExplicitBuildScriptName(args));
            }

            if (_file.Exists("./.flubu"))
            {
                var lines = _file.ReadAllLines("./.flubu");
                if (!string.IsNullOrEmpty(lines[0]) && _file.Exists(lines[0]))
                {
                    _log.LogInformation("using the build script file path from .flubu file. '{0}'.", lines[0]);
                    return(lines[0]);
                }
            }

            _log.LogInformation("Script file path was not explicitly specified, searching the default locations.");
            foreach (var defaultScriptLocation in DefaultScriptLocations)
            {
                if (_file.Exists(defaultScriptLocation))
                {
                    _log.LogInformation("Found it, using the build script file '{0}'.", defaultScriptLocation);
                    return(defaultScriptLocation);
                }
            }

            var flubuFile = FindFlubuFile();

            if (flubuFile != null)
            {
                var lines        = _file.ReadAllLines(flubuFile);
                var flubuFileDir = Path.GetDirectoryName(flubuFile);

                if (string.IsNullOrEmpty(lines[0]))
                {
                    return(null);
                }

                var buildScriptFullPath = Path.Combine(flubuFileDir, lines[0]);
                if (_file.Exists(buildScriptFullPath))
                {
                    _log.LogInformation("using the build script file from .flubu file. '{0}'.", lines[0]);
                    return(buildScriptFullPath);
                }
            }

            return(null);
        }
コード例 #7
0
        public bool Process(AnalyserResult analyserResult, string line, int lineIndex)
        {
            if (!line.TrimStart().StartsWith("//#ass", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            int dllIndex = line.IndexOf(" ", StringComparison.Ordinal);

            if (dllIndex < 0)
            {
                return(true);
            }

            string dll       = line.Substring(dllIndex);
            string pathToDll = Path.GetFullPath(dll.Trim());
            string extension = _pathWrapper.GetExtension(pathToDll);

            if (!extension.Equals(".dll", StringComparison.OrdinalIgnoreCase))
            {
                if (!extension.Equals(".exe", StringComparison.OrdinalIgnoreCase))
                {
                    throw new ScriptException($"File doesn't have dll extension. {pathToDll}");
                }
            }

            if (!_file.Exists(pathToDll))
            {
                throw new ScriptException($"Assembly not found at location: {pathToDll}");
            }

            analyserResult.References.Add(pathToDll);
            return(true);
        }
コード例 #8
0
        public bool Open(string filepath)
        {
            lock (SyncLock)
            {
                try
                {
                    if (_fileWrapper.Exists(filepath))
                    {
                        var json = _fileWrapper.Read(filepath);
                        var list = JsonConvert.DeserializeObject <List <CpuInfo> >(json);
                        _cpuLookup.Clear();
                        foreach (var cpu in list)
                        {
                            AddOrUpdate(cpu);
                        }
                    }
                }
                catch
                {
                    throw;
                }
            }

            return(true);
        }
コード例 #9
0
        private void LoadIgnoreList(string ignoreListFileName)
        {
            if (!_fileWrapper.Exists(ignoreListFileName))
            {
                return;
            }

            var lines = _fileWrapper.ReadLines(ignoreListFileName);

            foreach (var line in lines)
            {
                if (string.IsNullOrEmpty(line) ||
                    line.Trim().StartsWith("--"))
                {
                    continue;
                }

                var entry = line.Split('.');

                if (entry.Length < 2)
                {
                    continue;
                }

                var db     = entry[0].Trim();
                var schema = entry[1].Trim();

                var schemaToIgnore = new IgnoreSchemaEntry(db.ToLower(), schema.ToLower());
                IgnoreSchemas.Add(schemaToIgnore);
            }
        }
コード例 #10
0
        private void AddOtherCsFilesToBuildScriptCode(ScriptAnalyzerResult analyzerResult, List <AssemblyInfo> assemblyReferenceLocations, List <string> code)
        {
            foreach (var file in analyzerResult.CsFiles)
            {
                if (_file.Exists(file))
                {
                    _log.LogInformation($"File found: {file}");
                    List <string> additionalCode = _file.ReadAllLines(file);

                    ScriptAnalyzerResult additionalCodeAnalyzerResult = _scriptAnalyzer.Analyze(additionalCode);
                    if (additionalCodeAnalyzerResult.CsFiles.Count > 0)
                    {
                        throw new NotSupportedException("//#imp is only supported in main buildscript .cs file.");
                    }

                    var usings = additionalCode.Where(x => x.StartsWith("using"));

                    assemblyReferenceLocations.AddOrUpdateAssemblyInfo(additionalCodeAnalyzerResult.AssemblyReferences);
                    code.InsertRange(1, usings);
                    code.AddRange(additionalCode.Where(x => !x.StartsWith("using")));
                }
                else
                {
                    _log.LogInformation($"File was not found: {file}");
                }
            }
        }
コード例 #11
0
ファイル: FileHelperTests.cs プロジェクト: Maaak/academy13
        public void FileShouldBeDetectedAsImageFile()
        {
            // setup
            var imageWithTxtExtension = string.Format(@"{0}\{1}", "Content", "imageAsText.txt");
            var normalImageFile       = string.Format(@"{0}\{1}", "Content", "img.jpg");

            fileWrapper.Exists(null).ReturnsForAnyArgs(true);

            // body
            var realImageFileWithTextExtension   = fileHelper.IsImageFile(imageWithTxtExtension);
            var realImageFileWithNormalExtension = fileHelper.IsImageFile(normalImageFile);

            // tear down
            realImageFileWithTextExtension.Should().BeTrue();
            realImageFileWithNormalExtension.Should().BeTrue();
        }
コード例 #12
0
        private void SetAppConfigIfExists()
        {
            var targetAssembly = _assemblyLoader.AssembliesReferencingGaugeLib.FirstOrDefault();

            if (targetAssembly == null)
            {
                return;
            }

            var configFile = string.Format("{0}.config", targetAssembly.Location);

            if (!_fileWrapper.Exists(configFile))
            {
                return;
            }

            if (Type.GetType("Mono.Runtime") != null)
            {
                LogManager.GetLogger("Sandbox")
                .Warn("Located {0}, but cannot load config dynamically in Mono. Skipping..", configFile);
                return;
            }

            AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configFile);
        }
コード例 #13
0
        private void ProcessBaseClass(ScriptAnalyzerResult analyzerResult, string line)
        {
            var baseClassIndex = line.IndexOf(":", StringComparison.Ordinal);

            if (baseClassIndex < 1)
            {
                return;
            }

            var baseClassName = line.Substring(baseClassIndex + 1);

            baseClassName = baseClassName.TrimStart();
            var baseClassEndIndex = baseClassName.IndexOf(" ", StringComparison.Ordinal);

            if (baseClassEndIndex != -1)
            {
                baseClassName = baseClassName.Substring(0, baseClassEndIndex);
            }

            analyzerResult.BaseClassName = baseClassName.TrimEnd();

            var baseClassfileName = $"{baseClassName}.cs";

            if (baseClassName != nameof(DefaultBuildScript) && _file.Exists(baseClassfileName))
            {
                analyzerResult.CsFiles.Add(_path.GetFullPath(baseClassfileName));
            }
        }
コード例 #14
0
 public void Delete(string filePath)
 {
     if (_fileWrapper.Exists(filePath))
     {
         _fileWrapper.Delete(filePath);
     }
 }
コード例 #15
0
 private void AddFile(string path, List <string> assemblies)
 {
     if (!_fileWrapper.Exists(path))
     {
         return;
     }
     assemblies.Add(path);
 }
コード例 #16
0
 public virtual void DeleteFile()
 {
     if (!_fileWrapper.Exists(FilePath))
     {
         return;
     }
     _fileWrapper.Delete(FilePath);
 }
コード例 #17
0
        private void ProcessAddedCsFilesToBuildScript(ScriptAnalyzerResult analyzerResult, List <string> code)
        {
            List <string> csFiles = new List <string>();

            foreach (var csDirectory in analyzerResult.CsDirectories)
            {
                if (Directory.Exists(csDirectory.Item1.path))
                {
                    var searchOption = csDirectory.Item1.includeSubDirectories
                        ? SearchOption.AllDirectories
                        : SearchOption.TopDirectoryOnly;

                    csFiles.AddRange(Directory.GetFiles(csDirectory.Item1.path, "*.cs", searchOption));
                }
                else
                {
                    _log.LogInformation($"Directory not found: '{csDirectory.Item1.path}'.");
                }
            }

            csFiles.AddRange(analyzerResult.CsFiles);
            List <string> namespaces = new List <string>();

            foreach (var file in csFiles)
            {
                if (_file.Exists(file))
                {
                    _log.LogInformation($"File found: {file}");
                    List <string> additionalCode = _file.ReadAllLines(file);

                    ScriptAnalyzerResult additionalCodeAnalyzerResult = _scriptAnalyzer.Analyze(additionalCode);
                    if (additionalCodeAnalyzerResult.CsFiles.Count > 0)
                    {
                        throw new NotSupportedException("//#imp is only supported in main buildscript .cs file.");
                    }

                    namespaces.Add(additionalCodeAnalyzerResult.Namespace);

                    var usings = additionalCode.Where(x => x.StartsWith("using"));

                    analyzerResult.AssemblyReferences.AddRange(additionalCodeAnalyzerResult.AssemblyReferences);

                    code.InsertRange(1, usings);
                    code.AddRange(additionalCode.Where(x => !x.StartsWith("using")));
                }
                else
                {
                    _log.LogInformation($"File was not found: {file}");
                }
            }

            namespaces = namespaces.Distinct().ToList();
            foreach (var ns in namespaces)
            {
                var usng = $"using {ns};";
                code.Remove(usng);
            }
        }
コード例 #18
0
ファイル: EventRepository.cs プロジェクト: mary2786/Eventos
        public string[] GetEvents(string path)
        {
            if (!_fileWrapper.Exists(path))
            {
                throw new DirectoryNotFoundException("No se encontró el archivo");
            }

            return(_fileWrapper.ReadFile(path));
        }
コード例 #19
0
 private void AddFile(string path, List <string> assemblies)
 {
     if (!_fileWrapper.Exists(path))
     {
         Logger.Warn("Path does not exist: {0}", path);
         return;
     }
     assemblies.Add(path);
 }
コード例 #20
0
 internal void ExistsAndCopy(string file, string moveTo, string folder1)
 {
     // Checks that the file does not already exists
     // Passes directory location then concatenates the file name onto it
     // Also passes target directory and concatenates file name
     if (!fileWrapper.Exists($"{moveTo}\\{file}"))
     {
         fileWrapper.Copy($"{folder1}\\{file}", $"{moveTo}\\{file}");
     }
 }
コード例 #21
0
        public IEnumerable <StockQuote> GetStockQuotes(string sourcePath)
        {
            if (!fileWrapper.Exists(sourcePath))
            {
                throw new InvalidOperationException("File does not exist");
            }

            var lines = fileWrapper.ReadAllLines(sourcePath);

            return(contentMapper.MapContentsToTrades(lines).ToList());
        }
コード例 #22
0
 public void Process(string path)
 {
     if (_fileWrapper.Exists(path))
     {
         ProcessDirectory(path);
     }
     else
     {
         Console.WriteLine("{0} is not a valid file or directory.", path);
     }
 }
コード例 #23
0
        public IEnumerable <SolutionFileProjectReference> ReadProjectReferences(FilePath solutionFileName)
        {
            if (!_fileWrapper.Exists(solutionFileName))
            {
                throw new FileNotFoundException("Solution FileName", solutionFileName.FullPath);
            }

            if (solutionFileName.IsNullOrEmpty())
            {
                throw new ArgumentNullException("solutionFileName");
            }

            var directory = Path.GetDirectoryName(solutionFileName.FullPath);

            if (null == directory)
            {
                throw new FormatException(string.Format("Path.GetDirectoryName returned null for solution file [{0}]", solutionFileName));
            }

            _log.InfoFormat("Reading Projects from Solution File [{0}]", solutionFileName.FullPath);

            foreach (Match match in ProjectLinePattern.Matches(_fileReader.ReadAllText(solutionFileName)))
            {
                if (!match.Success)
                {
                    continue;
                }

                string typeGuid = match.Groups["TypeGuid"].Value;
                string title    = match.Groups["Title"].Value;
                string location = match.Groups["Location"].Value;

                switch (typeGuid.ToUpperInvariant())
                {
                case "{2150E333-8FDC-42A3-9474-1A3956D46DE8}":     // Solution Folder
                    // ignore folders
                    break;

                case "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}":     // C# project
                    yield return(new SolutionFileProjectReference
                    {
                        ProjectFileName = new FilePath(directory, location),
                        Title = title
                    });

                    break;

                default:
                    _log.InfoFormat("Project {0} has unsupported type {1}", location, typeGuid);
                    break;
                }
            }
        }
コード例 #24
0
 private string GetFirstFileLineOrDefault(string filePath, string defaultValue)
 {
     if (_fileWrapper.Exists(filePath))
     {
         var firstLine = _fileWrapper.ReadAllLines(filePath).FirstOrDefault();
         if (!string.IsNullOrEmpty(firstLine))
         {
             return(firstLine.Trim());
         }
     }
     return(defaultValue.Trim());
 }
コード例 #25
0
 public DeleteFileOnClose(string filePath, IFileWrapper fileWrapper)
 {
     _fileWrapper = fileWrapper;
     if (string.IsNullOrWhiteSpace(filePath))
     {
         throw new ArgumentException(filePath);
     }
     if (!_fileWrapper.Exists(filePath))
     {
         throw new FileNotFoundException(filePath);
     }
     FilePath = filePath;
 }
コード例 #26
0
        private void LoadTargetLibAssembly()
        {
            var targetLibLocation = Path.GetFullPath(Path.Combine(Utils.GetGaugeBinDir(), string.Concat(GaugeLibAssembleName, ".dll")));

            if (!_fileWrapper.Exists(targetLibLocation))
            {
                var message = string.Format("Unable to locate Gauge Lib at: {0}", targetLibLocation);
                Logger.Error(message);
                throw new FileNotFoundException(message);
            }
            _targetLibAssembly = _assemblyWrapper.LoadFrom(targetLibLocation);
            Logger.Debug("Target Lib loaded : {0}, from {1}", _targetLibAssembly.FullName, _targetLibAssembly.Location);
        }
コード例 #27
0
        private ProjectFileAnalyzerResult LocateCsproj(string location)
        {
            ProjectFileAnalyzerResult result = new ProjectFileAnalyzerResult();

            if (location == null)
            {
                if (_file.Exists("./.flubu"))
                {
                    var lines = _file.ReadAllLines("./.flubu");
                    if (lines.Count > 1 && !string.IsNullOrEmpty(lines[1]) && _file.Exists(lines[1]))
                    {
                        result.ProjectFileFound    = true;
                        result.ProjectFileLocation = Path.GetFullPath(lines[1]);
                        return(result);
                    }
                }

                foreach (var item in _defaultCsprojLocations)
                {
                    if (_file.Exists(item))
                    {
                        result.ProjectFileFound    = true;
                        result.ProjectFileLocation = Path.GetFullPath(item);
                        break;
                    }
                }
            }
            else
            {
                if (_file.Exists(location))
                {
                    result.ProjectFileFound    = true;
                    result.ProjectFileLocation = location;
                }
            }

            return(result);
        }
コード例 #28
0
        public UserSettings(IFileWrapper file, IDirectoryWrapper directory, IGameSettings gameSettings)
        {
            this.file         = file;
            this.directory    = directory;
            this.gameSettings = gameSettings;

            data = file.Exists(Filename)
                ? JsonConvert.DeserializeObject <UserSettingsData>(file.ReadAllText(Filename))
                : new UserSettingsData();

            GameStartedCount++;

            Save();
        }
コード例 #29
0
ファイル: InputService.cs プロジェクト: arsz/EscapeMines
        public IAsyncEnumerator <string> ReadInputTextFileLinesAsync(CancellationToken cancellationToken)
        {
            var filePath = fileDialogOpener.GetFilePathFromDialog();

            if (string.IsNullOrEmpty(filePath))
            {
                throw new FileLoadException("Input cannot be loaded.");
            }

            if (fileWrapper.Exists(filePath) == false)
            {
                throw new FileNotFoundException("Input file not found.");
            }

            return(fileReader.ReadLinesAsync(filePath).GetAsyncEnumerator(cancellationToken));
        }
コード例 #30
0
        public WebConfigManager(
            IFileWrapper fileWrapper,
            IXmlDocumentWrapper xmlDocumentWrapper,
            string configFile = "web.config")
        {
            _fileWrapper        = fileWrapper ?? throw new ArgumentNullException(nameof(fileWrapper), "File wrapper is required");
            _xmlDocumentWrapper = xmlDocumentWrapper ?? throw new ArgumentNullException(nameof(xmlDocumentWrapper), "Xml document wrapper is required");

            if (!_fileWrapper.Exists(configFile))
            {
                throw new ArgumentNullException(nameof(configFile), "Web config file does not exist. Exiting the program.");
            }

            _configFile   = configFile;
            _configXmlDoc = _xmlDocumentWrapper.CreateXmlDocFromFile(_configFile);
            BackupConfig();
        }