Exemplo n.º 1
0
        private void GetCollection()
        {
            try
            {
                var d = new OpenFileDialog();
                if (d.ShowDialog() == true)
                {
                    MainText += $"Opening File {d.FileName}";

                    using (var stream = File.OpenRead(d.FileName))
                        using (var reader = new StreamReader(stream))
                            using (var csvReader = new CsvReader(reader))
                            {
                                csvReader.Read();
                                csvReader.ReadHeader();
                                Collection = new Dictionary <string, int>();
                                while (csvReader.Read())
                                {
                                    var cnt  = csvReader.GetField <int>("Count");
                                    var name = csvReader.GetField <string>("Name");

                                    if (!Collection.ContainsKey(name))
                                    {
                                        Collection[name] = 0;
                                    }

                                    Collection[name] += cnt;
                                }

                                CollectionLoaded = true;
                                CalculateDiffCommand.UpdateCanExecute();

                                MainText += $"{Environment.NewLine}{Collection.Count} different cards found";
                                //foreach (var e in Collection)
                                //{
                                //    MainText += $"{Environment.NewLine}{e.Value} {e.Key}";
                                //}
                            }
                }
            }
            catch (Exception e)
            {
                MainText = e.ToString();
            }
        }
Exemplo n.º 2
0
        private void GetRequest()
        {
            try
            {
                var d = new OpenFileDialog();
                if (d.ShowDialog() == true)
                {
                    MainText += $"Opening File {d.FileName}";

                    using (var stream = File.OpenRead(d.FileName))
                        using (var reader = new StreamReader(stream))
                        {
                            Request = new Dictionary <string, int>();

                            for (var line = reader.ReadLine(); line != null; line = reader.ReadLine())
                            {
                                var cnt  = 1;
                                var name = Regex.Replace(line, "\\[.\\] ", "");

                                if (!Request.ContainsKey(name))
                                {
                                    Request[name] = 0;
                                }

                                Request[name] += cnt;
                            }
                            RequestSetLoaded = true;
                            CalculateDiffCommand.UpdateCanExecute();

                            MainText += $"{Environment.NewLine}{Request.Count} different cards found";
                            foreach (var e in Request)
                            {
                                MainText += $"{Environment.NewLine}{e.Value} {e.Key}";
                            }
                        }
                }
            }
            catch (Exception e)
            {
                MainText = e.ToString();
            }
        }