示例#1
0
        /// <summary>
        /// Writes the file to the specified target.
        /// </summary>
        /// <param name="entries">The entries to write.</param>
        /// <param name="target">The target to write to.</param>
        /// <exception cref="NotImplementedException"></exception>
        private static async Task WriteFile(CsvGamesList entries, string target)
        {
            using (var output = new StreamWriter(target, false)) {
                // header line
                await output.WriteLineAsync(entries.GetHeaderLine(nameColumn, defaultDelimiter));

                // entries
                foreach (var entry in entries.Games)
                {
                    await output.WriteLineAsync(entry.ToCSVString(defaultDelimiter));
                }
            }
        }
示例#2
0
        /// <summary>
        /// Removes entries in the main file that are in the secondary
        /// </summary>
        /// <param name="main">The path to the main file.</param>
        /// <param name="secondary">The path to the secondary file.</param>
        /// <param name="target">The path to the target file.</param>
        /// <param name="messageHandler">The message handler.</param>
        /// <returns></returns>
        public async Task Remove(string main, string secondary, string target, IMessageHandler messageHandler)
        {
            await WorkOnTwoFiles(main, secondary, target, messageHandler, "", (main, sec) => {
                var result = new CsvGamesList();

                foreach (var me in main.Games)
                {
                    if (!sec.Games.Any(se => se.Name.Equals(me.Name, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        result.Add(me);
                    }
                }

                return(result);
            });
        }
示例#3
0
        /// <summary>
        /// Keeps files that are listed in both files
        /// </summary>
        /// <param name="main">The path to the main file.</param>
        /// <param name="secondary">The path to the secondary file.</param>
        /// <param name="target">The path to the target file.</param>
        /// <param name="messageHandler">The message handler.</param>
        public async Task Keep(string main, string secondary, string target, IMessageHandler messageHandler)
        {
            await WorkOnTwoFiles(main, secondary, target, messageHandler, "Filter entries in a CSV files", (main, sec) => {
                var result = new CsvGamesList();

                foreach (var me in main.Games)
                {
                    // keep entries from the main file that also exist in the secondary
                    if (sec.Games.Any(se => se.Name == me.Name))
                    {
                        result.Add(me);
                    }
                }

                return(result);
            });
        }
示例#4
0
        /// <summary>
        /// Merges the specified main and secondary files to the target file.
        /// </summary>
        /// <param name="main">The path to the main file.</param>
        /// <param name="secondary">The path to the secondary file.</param>
        /// <param name="target">The path to the target file.</param>
        /// <param name="messageHandler">The message handler.</param>
        public async Task Merge(string main, string secondary, string target, IMessageHandler messageHandler)
        {
            await WorkOnTwoFiles(main, secondary, target, messageHandler, "Merge two CSV files", (main, sec) => {
                var result = new CsvGamesList(main.Games);

                foreach (var secg in sec.Games)
                {
                    var maing = main.Games.Where(me => me.Name == secg.Name).FirstOrDefault();
                    if (maing == null)
                    {
                        // entry is in secondary but not main file: copy to result
                        result.Add(secg);
                    }
                    else
                    {
                        // entry is already in main: copy additional data
                        result.CopyEntry(secg);
                    }
                }

                return(result);
            });
        }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameEntry" /> class.
 /// </summary>
 /// <param name="list">The reference to the main games list.</param>
 /// <param name="name">The name.</param>
 /// <param name="values">The values.</param>
 public GameEntry(CsvGamesList list, string name, IDictionary <string, string> values)
 {
     this.listRef = list ?? throw new ArgumentNullException(nameof(list));
     this.Name    = name;
     this.Values  = new SortedDictionary <string, string>(values);
 }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameEntry"/> class.
 /// </summary>
 /// <param name="list">The reference list.</param>
 /// <param name="copyFrom">The entry to copy from.</param>
 public GameEntry(CsvGamesList list, GameEntry copyFrom)
 {
     this.listRef = list;
     this.Name    = copyFrom.Name;
     this.Values  = copyFrom.Values;
 }