Example #1
0
    public int TrackPublicationChangesOnCDS()
    {
        var resultFlag = -1;

        try {
            string pubUpdateFileCDSPath   = CommonCalls.PubUpdateFileCDSPath;
            string pubUpdateFileLocalPath = CommonCalls.PubUpdateFileLocalPath;
            if (File.Exists(pubUpdateFileCDSPath))
            {
                File.Copy(pubUpdateFileCDSPath, pubUpdateFileLocalPath, true);
            }
            if (File.Exists(pubUpdateFileLocalPath))
            {
                string[] pubRecords            = File.ReadAllLines(pubUpdateFileLocalPath);
                var      pubRecordsExceptToday = pubRecords.Where(p => !p.Trim().EndsWith(DateTime.Now.ToString("dd/MM/yy"))).ToList();
                resultFlag = diskDeliveryDAO.TrackPublicationChangesOnCDS(pubRecordsExceptToday);
                File.WriteAllText(pubUpdateFileLocalPath, string.Empty);
                string[] pubRecordsCDS      = File.ReadAllLines(pubUpdateFileCDSPath);
                var      pubRecordsTodayCDS = pubRecordsCDS.Where(p => p.Trim().EndsWith(DateTime.Now.ToString("dd/MM/yy"))).ToList();
                File.WriteAllLines(pubUpdateFileCDSPath, pubRecordsTodayCDS);
            }
            return(resultFlag);
        } catch (Exception) {
            return(-1);
        }
    }
            public Scope(IFileSystem fileSystem, string databaseFile)
            {
                _fileSystem = fileSystem;
                _databaseFile = databaseFile;

                _allSeen = _fileSystem.ReadAllLines(SeenPath);
                _allGone = _fileSystem.ReadAllLines(GonePath);
                _currentSnapshot = _fileSystem.ReadAllLines(CurrentPath);
            }
Example #3
0
        /// <summary>
        /// Reads a Git rebase file from disk and returns its details in a <seealso cref="RebaseDocument"/> instance.
        /// </summary>
        /// <param name="filePath">The full path to the Git rebase file. This must not be null or empty.</param>
        /// <returns>A <seealso cref="RebaseDocument"/> object that contains the rebase details.</returns>
        /// <exception cref="ArgumentException">Thrown if filePath is null or empty.</exception>
        /// <exception cref="GitModelException">
        /// Thrown if disk access fails for any reason. Refer to the inner exception for details.
        /// </exception>
        public RebaseDocument FromFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException("File path must not be null or empty", nameof(filePath));
            }

            var allLines    = _fileSystem.ReadAllLines(filePath);
            var rebaseItems = new List <RebaseItem>();

            foreach (string line in allLines)
            {
                int firstSpace  = line.IndexOf(' ');
                int secondSpace = line.IndexOf(' ', firstSpace + 1);

                string firstToken  = line.Substring(0, firstSpace);
                string secondToken = line.Substring(firstSpace + 1, secondSpace - firstSpace - 1);
                string thirdToken  = line.Substring(secondSpace + 1);

                var rebaseItem = new RebaseItem
                {
                    Action     = RebaseActionParser.ToRebaseAction(firstToken),
                    CommitHash = secondToken,
                    Subject    = thirdToken
                };

                rebaseItems.Add(rebaseItem);
            }

            return(new RebaseDocument
            {
                Items = rebaseItems.ToArray()
            });
        }
Example #4
0
        public string Process(string fileContents)
        {
            var lines = fileContents.Replace("\r\n", "\n").Split('\n').ToList();

            for (int i = 0; i < lines.Count; i++)
            {
                var match = Regex.Match(lines[i], "(?<=^@include \").*?(?=\"$)");

                if (match.Success)
                {
                    if (!FileSystem.FileExists(match.Value))
                    {
                        throw new PreprocessorException($"cannot find file at '{match.Value}'");
                    }

                    string[] includedFileLines = FileSystem.ReadAllLines(match.Value);

                    lines.RemoveAt(i);
                    lines.InsertRange(i, includedFileLines);

                    i--;
                }
            }

            lines.RemoveAll(o => o.FirstOrDefault(i => i != ' ') == '#');

            return(string.Join("\n", lines));
        }
Example #5
0
        public static string[] GenerateArguments(
            string[] args,
            IFileSystem fileSystem,
            IEnvironmentVariables environmentVariables)
        {
            List <string> expandedArguments = new List <string>();

            foreach (string argument in args)
            {
                if (!IsResponseFileArgument(argument))
                {
                    expandedArguments.Add(argument);
                    continue;
                }

                string responseFile = argument.Trim('"').Substring(1);

                responseFile = environmentVariables.ExpandEnvironmentVariables(responseFile);
                responseFile = fileSystem.GetFullPath(responseFile);

                string[] responseFileLines = fileSystem.ReadAllLines(responseFile);

                ExpandResponseFile(responseFileLines, expandedArguments);
            }

            return(expandedArguments.ToArray());
        }
Example #6
0
        /// <summary>
        /// Loads the ratings.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>Dictionary{System.StringParentalRating}.</returns>
        private void LoadRatings(string file)
        {
            var dict = _fileSystem.ReadAllLines(file).Select(i =>
            {
                if (!string.IsNullOrWhiteSpace(i))
                {
                    var parts = i.Split(',');

                    if (parts.Length == 2)
                    {
                        int value;

                        if (int.TryParse(parts[1], NumberStyles.Integer, UsCulture, out value))
                        {
                            return(new ParentalRating {
                                Name = parts[0], Value = value
                            });
                        }
                    }
                }

                return(null);
            })
                       .Where(i => i != null)
                       .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);

            var countryCode = _fileSystem.GetFileNameWithoutExtension(file)
                              .Split('-')
                              .Last();

            _allParentalRatings.TryAdd(countryCode, dict);
        }
Example #7
0
        private void RunStartupTasks()
        {
            var path = Path.Combine(ApplicationPaths.CachePath, "startuptasks.txt");

            // ToDo: Fix this shit
            if (!File.Exists(path))
            {
                return;
            }

            List <string> lines;

            try
            {
                lines = _fileSystem.ReadAllLines(path).Where(i => !string.IsNullOrWhiteSpace(i)).Distinct(StringComparer.OrdinalIgnoreCase).ToList();

                foreach (var key in lines)
                {
                    var task = ScheduledTasks.FirstOrDefault(i => string.Equals(i.ScheduledTask.Key, key, StringComparison.OrdinalIgnoreCase));

                    if (task != null)
                    {
                        QueueScheduledTask(task, new TaskOptions());
                    }
                }

                _fileSystem.DeleteFile(path);
            }
            catch
            {
                return;
            }
        }
        public List <string> ParseExcludeFile(string excludeFile)
        {
            var exclusions = new List <string>();

            string[] lines = _fileSystem.ReadAllLines(excludeFile);
            foreach (string line in lines)
            {
                // Strip any comments
                string lineMinusComments = line;
                int    commentStart      = line.IndexOf("//");
                if (commentStart >= 0)
                {
                    lineMinusComments = line.Substring(0, commentStart);
                }

                // If there's anything left after trimming whitespace, add it as an exclusion
                string trimmedLine = lineMinusComments.Trim();
                if (!string.IsNullOrWhiteSpace(trimmedLine))
                {
                    exclusions.Add(trimmedLine);
                }
            }

            return(exclusions);
        }
Example #9
0
        private List <Source> ReadSourcesFromFile(string mappingFile)
        {
            var result = new List <Source>();


            foreach (var line in fileSystem.ReadAllLines(mappingFile))
            {
                result.Add(new Source(line));
            }

            return(result);
        }
Example #10
0
        public IReadOnlyList <string> Load()
        {
            if (!_fileSystem.FileExists(_options.FilePath))
            {
                return(Array.Empty <string>());
            }

            var commands = _fileSystem.ReadAllLines(_options.FilePath, _options.Encoding)
                           .Where(_ => !String.IsNullOrWhiteSpace(_));

            return(commands.ToArray());
        }
        public void Adjust(string slnFile, Guid projectGuid)
        {
            var projectGuidStr = projectGuid.ToString("D").ToUpper();
            var lines          = _fileSystem.ReadAllLines(slnFile)
                                 .Select(
                l => l.Contains(CSProjTypeGuid) && l.Contains(projectGuidStr)
                        ? l.Replace(CSProjTypeGuid, XProjTypeGuid).Replace("csproj", "xproj")
                        : l
                );

            _fileSystem.WriteAllLines(slnFile, lines);
        }
Example #12
0
        public void RunTaskOnNextStartup(string key)
        {
            var path = Path.Combine(ApplicationPaths.CachePath, "startuptasks.txt");

            List <string> lines;

            try
            {
                lines = _fileSystem.ReadAllLines(path).ToList();
            }
            catch
            {
                lines = new List <string>();
            }

            if (!lines.Contains(key, StringComparer.OrdinalIgnoreCase))
            {
                lines.Add(key);
                _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
                _fileSystem.WriteAllLines(path, lines);
            }
        }
Example #13
0
        private IEnumerable <string> GetCommitFileLines(string filePath)
        {
            string[] allLines;

            try
            {
                allLines = _fileSystem.ReadAllLines(filePath);
            }
            catch (Exception ex)
            {
                throw new GitModelException($"Unable to read commit file: {filePath}. Refer to the inner exception for details.", ex);
            }

            return(OmitComments(allLines));
        }
        public IEnumerable <string> ReadFile(
            RelativePath relativePath,
            Func <FullPath, IEnumerable <string>, IEnumerable <string> > postProcessing)
        {
            foreach (var directoryName in PossibleDirectoryNames())
            {
                var path = directoryName.Combine(relativePath);
                if (_fileSystem.FileExists(path))
                {
                    Logger.LogInfo("Using configuration file at \"{0}\"", path);
                    return(postProcessing(path, _fileSystem.ReadAllLines(path)).ToReadOnlyCollection());
                }
            }

            throw new FileLoadException(
                      string.Format("Could not load configuration file \"{0}\" from the following locations:{1}", relativePath,
                                    PossibleDirectoryNames().Aggregate("", (x, y) => x + "\n" + y)));
        }
Example #15
0
        internal bool MakeFixesOnFile(string file, Action eAction, List <string> exclusions)
        {
            if (!ShouldProcessFile(file, exclusions))
            {
                return(false);
            }

            _commenting = false;

            bool madeChanges = false;
            int  lineNumber  = 0;
            var  encoding    = GetEncoding(file);

            string lines = string.Empty;

            foreach (string originalLine in _fileSystem.ReadAllLines(file, encoding))
            {
                lineNumber++;

                string line          = originalLine;
                bool   isWarningLine = FixUpLine(ref line);
                lines += line + Environment.NewLine;

                if (isWarningLine)
                {
                    madeChanges = true;
                    _warningCount++;
                    string firstDirectory = FirstDirectory(file, _directory);
                    string fileName       = Path.GetFileName(file);
                    _consoleAdapter.WriteLine($"{_warningCount}: [{firstDirectory}|{fileName}:{lineNumber}] HCS \"{originalLine.Trim()}\"");
                }
            }

            if (eAction == Action.FixHCS && madeChanges)
            {
                lines = $"using static NeverTranslateNS.NeverTranslateClass;{Environment.NewLine}{lines}";
                _fileSystem.WriteAllText(file, lines, encoding);
            }

            return(madeChanges);
        }
Example #16
0
        public FileWoerterbuch(IFileSystem fileSystem, string directory)
        {
            this.fileSystem = fileSystem;
            var sources = ReadSourcesFromFile(Path.Combine(directory, "SourceMapping.txt"));

            foreach (var source in sources)
            {
                var filePath = Path.Combine(directory, source.FileName);
                if (!fileSystem.FileExists(filePath))
                {
                    continue;
                }


                var lines = fileSystem.ReadAllLines(filePath);
                foreach (var l in lines)
                {
                    AddLine(l, source);
                }
            }
        }
Example #17
0
        private Dictionary <string, List <SourceRootMapping> > LoadSourceRootMapping(string directory)
        {
            var mapping = new Dictionary <string, List <SourceRootMapping> >();

            string mappingFilePath = Path.Combine(directory, MappingFileName);

            if (!_fileSystem.Exists(mappingFilePath))
            {
                return(mapping);
            }

            foreach (string mappingRecord in _fileSystem.ReadAllLines(mappingFilePath))
            {
                int projectFileSeparatorIndex = mappingRecord.IndexOf('|');
                int pathMappingSeparatorIndex = mappingRecord.IndexOf('=');
                if (projectFileSeparatorIndex == -1 || pathMappingSeparatorIndex == -1)
                {
                    _logger.LogWarning($"Malformed mapping '{mappingRecord}'");
                    continue;
                }
                string projectPath  = mappingRecord.Substring(0, projectFileSeparatorIndex);
                string originalPath = mappingRecord.Substring(projectFileSeparatorIndex + 1, pathMappingSeparatorIndex - projectFileSeparatorIndex - 1);
                string mappedPath   = mappingRecord.Substring(pathMappingSeparatorIndex + 1);

                if (!mapping.ContainsKey(mappedPath))
                {
                    mapping.Add(mappedPath, new List <SourceRootMapping>());
                }

                foreach (string path in originalPath.Split(';'))
                {
                    mapping[mappedPath].Add(new SourceRootMapping()
                    {
                        OriginalPath = path, ProjectPath = projectPath
                    });
                }
            }

            return(mapping);
        }
Example #18
0
        public List <IContentExcludeRule> Parse(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"Cannot find {path} file.");
            }

            var rules = new List <IContentExcludeRule>();
            var lines = _fileSystem.ReadAllLines(path);
            var line  = 0;

            foreach (var rule in lines)
            {
                line++;
                if (string.IsNullOrWhiteSpace(rule))
                {
                    // ignore empty lines
                    continue;
                }

                if (rule.StartsWith("//"))
                {
                    // ignore comments
                    continue;
                }

                try
                {
                    rules.Add(ContentExcludeExcludeRule.Parse(rule));
                }
                catch (FormatException e)
                {
                    Console.WriteLine($"{e.Message} line {line}");
                    throw;
                }
            }

            return(rules);
        }
Example #19
0
        private IEnumerable <string> GetValues(string file)
        {
            // already read, so just return values without re-read
            if (_cache.ContainsKey(file))
            {
                return(_cache[file]);
            }

            // we don't cache non existing file
            if (!_filesystem.FileExists(file))
            {
                Trace.WriteLine(
                    $"cannot get values from file '{file}' because file does not exist. returning empty array. nothing added to cache");
                return(Enumerable.Empty <string>());
            }

            // lets get the data, cache it and return it
            var fileContent = _filesystem.ReadAllLines(file);

            _cache.Add(file, fileContent);
            return(fileContent);
        }
Example #20
0
 private void FetchShortcutInfo(BaseItem item)
 {
     item.ShortcutPath = _fileSystem.ReadAllLines(item.Path)
                         .Select(NormalizeStrmLine)
                         .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i) && !i.StartsWith("#", StringComparison.OrdinalIgnoreCase));
 }
Example #21
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var vendorEID = request.Data.GetOrDefault <long>(k.vendorEID);
                var marketEID = request.Data.GetOrDefault <long>(k.marketEID);
                var isSell    = request.Data.GetOrDefault <int>(k.isSell) == 1;
                var quantity  = request.Data.GetOrDefault <int>(k.quantity);
                var clear     = request.Data.GetOrDefault <string>(k.clear);     //none, sell, buy, both
                var duration  = request.Data.GetOrDefault <int>(k.duration);
                var price     = (long)request.Data.GetOrDefault <int>(k.price);  //!! >> defined as int to avoid hex conversion

                var category   = request.Data.GetOrDefault <string>(k.category); //optional
                var fileName   = request.Data.GetOrDefault <string>(k.file);     //optional
                var addNamed   = request.Data.GetOrDefault <int>(k.addNamed) == 1;
                var nameFilter = request.Data.GetOrDefault <string>(k.filter);

                Market market;

                if (vendorEID == 0 || marketEID == 0)
                {
                    var character   = request.Session.Character;
                    var dockingBase = character.GetCurrentDockingBase();

                    market    = dockingBase.GetMarket();
                    vendorEID = market.GetVendorEid();
                }
                else
                {
                    market = Market.GetOrThrow(marketEID);
                }

                //do clear
                switch (clear)
                {
                case "sell":
                    Market.ClearVendorItems(vendorEID, true);
                    break;

                case "buy":
                    Market.ClearVendorItems(vendorEID, false);
                    break;

                case "both":
                    Market.ClearVendorItems(vendorEID, true);
                    Market.ClearVendorItems(vendorEID, false);
                    break;
                }

                if (category != null)
                {
                    //category flag defined as string
                    market.AddCategoryToMarket(vendorEID, category, duration, price, isSell, quantity, addNamed, nameFilter);
                }

                if (fileName != null)
                {
                    var linez   = _fileSystem.ReadAllLines(fileName);
                    var trimmed = from l in linez select l.Trim();

                    foreach (var categoryName in trimmed)
                    {
                        market.AddCategoryToMarket(vendorEID, categoryName, duration, price, isSell, quantity, addNamed, nameFilter);
                    }
                }

                Message.Builder.FromRequest(request).WithOk().Send();

                scope.Complete();
            }
        }
Example #22
0
 public AssemblyList Readfile(string path)
 {
     Root = Path.GetDirectoryName(path);
     return(ReadText(_fs.ReadAllLines(path)));
 }
Example #23
0
        private List <string> GetUrlsFromFile(string arg2)
        {
            var fileContent = fileSystem.ReadAllLines(arg2);

            return(fileContent.ToList());
        }
Example #24
0
 private IList <string> ReadFileLines()
 {
     return(_fileSystem.ReadAllLines(_filename));
 }
Example #25
0
        private void Load()
        {
            string[] contents    = null;
            var      licenseFile = Filename;

            lock (_fileLock)
            {
                try
                {
                    contents = _fileSystem.ReadAllLines(licenseFile);
                }
                catch (FileNotFoundException)
                {
                    lock (_fileLock)
                    {
                        _fileSystem.WriteAllBytes(licenseFile, new byte[] { });
                    }
                }
                catch (IOException)
                {
                    lock (_fileLock)
                    {
                        _fileSystem.WriteAllBytes(licenseFile, new byte[] { });
                    }
                }
            }
            if (contents != null && contents.Length > 0)
            {
                //first line is reg key
                RegKey = contents[0];

                //next is legacy key
                if (contents.Length > 1)
                {
                    // Don't need this anymore
                }

                //the rest of the lines should be pairs of features and timestamps
                for (var i = 2; i < contents.Length; i = i + 2)
                {
                    var line = contents[i];
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    Guid feat;
                    if (Guid.TryParse(line, out feat))
                    {
                        var lineParts = contents[i + 1].Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                        long ticks;
                        if (long.TryParse(lineParts[0], out ticks))
                        {
                            var info = new FeatureRegInfo
                            {
                                LastChecked = new DateTime(ticks)
                            };

                            if (lineParts.Length > 1 && long.TryParse(lineParts[1], out ticks))
                            {
                                info.ExpirationDate = new DateTime(ticks);
                            }

                            SetUpdateRecord(feat, info);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Executes the changes recorded for the associated file in chronological order.
        /// </summary>
        public override void ExecuteChanges(IFileSystem fileSystem)
        {
            string newPath;

            if (fileSystem.IsDirectory(AssociatedPath) && _newName != null)
            {
                string tmp = AssociatedPath.Substring(0, AssociatedPath.Length - FileSystem.PathSeparator.Length);
                newPath = "\\" + tmp.Substring(0, tmp.LastIndexOf("\\")) + "\\" + _newName;
                newPath = newPath.Replace("\\\\", "\\");
                fileSystem.Move(AssociatedPath, newPath);
                return;
            }

            String[] fileContent = fileSystem.ReadAllLines(AssociatedPath);
            IList<String> updatedFileContent = new List<String>();

            if (_newName != null)
            {
                newPath = AssociatedPath.Substring(0, AssociatedPath.LastIndexOf("\\")) + "\\" + _newName;
                newPath = newPath.Replace("\\\\", "\\");
                fileSystem.Move(AssociatedPath, newPath);
            }
            else
            {
                newPath = AssociatedPath;
            }

            if (_modificationList.Count > 0)
            {
                int contentPointer = 0;
                foreach (AbstractModification modification in _modificationList)
                {
                    for (; contentPointer < modification.LineNumber && contentPointer < fileContent.Length; contentPointer++)
                    {
                        updatedFileContent.Add(fileContent[contentPointer]);
                    }
                    if (modification is DeletionModification)
                    {
                        if (modification.LineNumber != contentPointer)
                            Debug.WriteLine("modification.LineNumber != contentPointer => " + modification.LineNumber + ", " +
                                            contentPointer);

                        contentPointer++;
                    }
                    else if (modification is InsertionModification)
                    {
                        InsertionModification insertion = modification as InsertionModification;
                        updatedFileContent.Add(insertion.Line);
                    }
                }
                fileContent = updatedFileContent.ToArray();
            }
            fileSystem.WriteAllLines(newPath, fileContent);
        }
Example #27
0
 public string[] ReadAllLines(NPath path)
 {
     return(fileSystem.ReadAllLines(path.ToProcessDirectory().ToString()));
 }