コード例 #1
0
        /// <summary>
        /// Tasks von csv-Datei in die Taskliste einlesen. Auch die Liste der Gäste
        /// mit den Gästen der Taskliste füllen.
        /// </summary>
        /// <param name="guests"></param>
        /// <param name="articles"></param>
        /// <returns>Taskliste</returns>
        private static List <Task> ReadTasksFromCsv(Dictionary <string, Guest> guests, Dictionary <string, Article> articles)
        {
            string[] lines = File.ReadAllLines(
                MyFile.GetFullNameInApplicationTree(TasksFilename),
                Encoding.Default);

            var tasks = new List <Task>();

            for (int i = 1; i < lines.Length; i++)
            {
                var      line        = lines[i].Split(';');
                string   guestName   = line[1];
                string   articleName = line[3];
                TaskType taskType    = (TaskType)Enum.Parse(typeof(TaskType), line[2]);
                int      delay       = int.Parse(line[0]);
                if (!guests.ContainsKey(guestName))
                {
                    guests.Add(guestName, new Guest(guestName));
                }
                // Gast ist genau einmal im Dictionary(Map)
                Guest guest = guests[guestName];
                //bool ok = guests.TryGetValue(guestName, out guest)
                Task task;
                if (string.IsNullOrEmpty(articleName))
                {
                    task = new Task(taskType, delay, guest);
                }
                else
                {
                    task = new Task(taskType, delay, guest, articles[articleName]);
                }
                tasks.Add(task);
            }
            return(tasks);
        }
コード例 #2
0
        private void CreatTasks()
        {
            string taskPath = MyFile.GetFullNameInApplicationTree("Tasks.csv");

            string[]  taskLines = File.ReadAllLines(taskPath, UTF8Encoding.Default);
            OrderType orderType;
            Article   article;

            for (int i = 1; i < taskLines.Length; i++)
            {
                string[] parts     = taskLines[i].Split(';');
                string   guestName = parts[1];
                Guest    guest     = new Guest(guestName);

                if (parts != null && Enum.TryParse(parts[2], out orderType))
                {
                    if (!_guestList.ContainsKey(guestName))
                    {
                        _guestList.Add(guestName, guest);
                    }

                    DateTime taskTime  = FastClock.Instance.Time.AddMinutes(Convert.ToInt32(parts[0]));
                    Task     taskOrder = new Task(taskTime, parts[1], orderType, parts[3]);
                    _tasks.Add(taskOrder);

                    if (orderType == OrderType.Order && _articles.TryGetValue(parts[3], out article))
                    {
                        taskTime = taskTime.AddMinutes(article.TimeToBuild);
                        Task taskReady = new Task(taskTime, taskOrder.Customer, OrderType.Ready, taskOrder.MyArticle);
                        _tasks.Add(taskReady);
                    }
                }
            }
            _tasks.Sort();
        }
コード例 #3
0
        public static IEnumerable <Game> ReadFromCsv()
        {
            var path = MyFile.GetFullNameInApplicationTree(fileToReadFrom);
            Dictionary <string, Team> teams = File.ReadAllLines(path)
                                              .Select(s => s.Split(';'))
                                              .Select(s => s[1])
                                              .Distinct()
                                              .ToDictionary(s => s, s => new Team {
                Name = s
            });

            return(File.ReadAllLines(path)
                   .Select(s => s.Split(';'))
                   .Select(s => new Game()
            {
                Round = int.Parse(s?[0]),
                HomeTeam = teams.TryGetValue(s?[1], out Team teamH) ? teamH : new Team {
                    Name = s[1]
                },
                GuestTeam = teams.TryGetValue(s?[2], out Team teamA) ? teamA : new Team {
                    Name = s[2]
                },
                HomeGoals = int.Parse(s?[3]),
                GuestGoals = int.Parse(s?[4])
            }));
        /// <summary>
        /// Daten der Rennen werden aus der
        /// XML-Datei ausgelesen und in die Races-Collection gespeichert.
        /// Grund: Races werden nicht aus den Results geladen, weil sonst die
        /// Rennen in der Zukunft fehlen
        /// </summary>
        public static IEnumerable <Race> LoadRacesFromRacesXml()
        {
            List <Race> races     = new List <Race>();
            string      racesPath = MyFile.GetFullNameInApplicationTree("Races.xml");
            var         xElement  = XDocument.Load(racesPath).Root;

            if (xElement != null)
            {
                races =
                    xElement.Elements("Race")
                    .Select(race =>
                            new Race
                {
                    Number  = (int)race.Attribute("round"),
                    Date    = (DateTime)race.Element("Date"),
                    Country = race.Element("Circuit")
                              ?.Element("Location")
                              ?.Element("Country")?.Value,
                    City = race.Element("Circuit")
                           ?.Element("Location")
                           ?.Element("Locality")?.Value
                })
                    .ToList();
            }
            return(races);
        }
        /// <summary>
        /// Liefert die Movies mit den dazugehörigen Kategorien
        /// </summary>
        public static IEnumerable <Movie> ReadFromCsv()
        {
            string filePath = MyFile.GetFullNameInApplicationTree(Filename);

            string[]      lines  = File.ReadAllLines(filePath, Encoding.UTF8);
            IList <Movie> movies = new List <Movie>();

            for (int i = 1; i < lines.Length; i++)
            {
                string   item     = lines[i];
                string[] parts    = item.Split(';');
                string   title    = parts[0];
                int      year     = Convert.ToInt32(parts[1]);
                Category category = new Category
                {
                    CategoryName = parts[2]
                };
                int   duration   = Convert.ToInt32(parts[3]);
                Movie movieToAdd = new Movie
                {
                    Title    = title,
                    Year     = year,
                    Category = category,
                    Duration = duration
                };
                movies.Add(movieToAdd);
            }
            return(movies.ToArray());
        }
コード例 #6
0
        /// <summary>
        /// Liefert die Movies mit den dazugehörigen Kategorien
        /// </summary>
        public static IEnumerable <Movie> ReadFromCsv()
        {
            //var path = MyFile.GetFullFolderNameInApplicationTree(Filename);
            var path = MyFile.GetFullNameInApplicationTree(Filename);
            Dictionary <string, Category> categories = File.ReadAllLines(path)
                                                       .Skip(1)
                                                       .Select(s => s.Split(';'))
                                                       .Select(s => s?[2])
                                                       .Distinct()
                                                       .ToDictionary(s => s, s => new Category {
                CategoryName = s
            });

            return(File.ReadAllLines(path)
                   .Skip(1)
                   .Select(s => s.Split(';'))
                   .Select(s => new Movie()
            {
                Title = s?[0],
                Duration = int.Parse(s?[3]),
                Year = int.Parse(s?[1]),
                Category = categories.TryGetValue(s?[2], out Category category) ? category : new Category {
                    CategoryName = s[2]
                }
            })
コード例 #7
0
        private List <Order> FillOrders()
        {
            string path = MyFile.GetFullNameInApplicationTree("Tasks.csv");

            string[]     lines  = File.ReadAllLines(path, Encoding.Default);
            List <Order> result = new List <Order>();

            for (int i = 1; i < lines.Length; i++)
            {
                string[]  fields = lines[i].Split(';');
                int       delay  = Convert.ToInt32(fields[0]);
                string    name   = fields[1];
                OrderType type   = new OrderType();
                type = (OrderType)Enum.Parse(type.GetType(), fields[2], true);
                Article article = null;

                for (int j = 0; j < _articles.Count; j++)
                {
                    if (_articles[j].Name == fields[3])
                    {
                        article = _articles[j];
                    }
                }

                result.Add(new Order(delay, name, type, article));
            }

            return(result);
        }
        public static Commit[] ReadFromTxt()
        {
            string path = MyFile.GetFullNameInApplicationTree(Filename);

            string[]    lines      = File.ReadAllLines(path);
            List <char> removeText = new List <char>()
            {
                'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '(', ')', '+', '-', '#', ','
            };

            var devs = lines.Where(l => !String.IsNullOrEmpty(l) && !Char.IsWhiteSpace(l[0]))
                       .Select(_ => _.Split(","))
                       .GroupBy(_ => _[1])
                       .Select(_ => new Developer()
            {
                Name = _.Key, Commits = new List <Commit>()
            })
                       .ToDictionary(_ => _.Name);

            var result = lines.Where(l => !String.IsNullOrEmpty(l) && !Char.IsWhiteSpace(l[0]))
                         .Select(_ => _.Split(","))
                         .Select(_ => new Commit()
            {
                HashCode  = _[0],
                Developer = devs[_[1]],
                Date      = DateTime.Parse(_[2]),
                Message   = _[3]
            })
                         .ToList();

            foreach (var r in result)
            {
                string[] data = lines.SkipWhile(l => !l.Contains(r.HashCode))
                                .SkipWhile(_ => !_.Contains("Merge") && !_.Contains("|"))
                                .SkipWhile(l => l.Contains("|"))
                                .Select(_ => _.Split(","))
                                .FirstOrDefault();

                r.FilesChanges = data.SkipWhile(_ => !_.Contains("changed"))
                                 .Select(_ => _.Filter(removeText))
                                 .Select(_ => int.Parse(_))
                                 .FirstOrDefault();

                r.Insertions = data.SkipWhile(_ => !_.Contains("insertion"))
                               .Select(_ => _.Filter(removeText))
                               .Select(_ => int.Parse(_))
                               .FirstOrDefault();

                r.Deletions = data.SkipWhile(_ => !_.Contains("deletion"))
                              .Select(_ => _.Filter(removeText))
                              .Select(_ => int.Parse(_))
                              .FirstOrDefault();

                r.Developer.Commits.Add(r);
            }

            return(result.ToArray());
        }
        /// <summary>
        /// Liefert die Messwerte mit den dazugehörigen Sensoren
        /// </summary>
        public static IEnumerable <Measurement> ReadFromCsv()
        {
            string                      filePath     = MyFile.GetFullNameInApplicationTree(Filename);
            List <Measurement>          measurements = new List <Measurement>();
            Dictionary <string, Sensor> sensors      = new Dictionary <string, Sensor>();
            int id = 1;

            if (File.Exists(filePath) == false)
            {
                throw new Exception("File does not exist");
            }

            string[] lines = File.ReadAllLines(filePath);

            foreach (string line in lines)
            {
                string[] data = line.Split(';');
                DateTime date;
                DateTime time;
                double   value;

                if (data != null &&
                    data.Length >= 4 &&
                    DateTime.TryParse(data[0], out date) &&
                    DateTime.TryParse(data[1], out time) &&
                    Double.TryParse(data[3], out value))
                {
                    string   sensorName    = data[2];
                    string[] location_type = sensorName.Split('_');
                    if (location_type.Length == 2)
                    {
                        string location = location_type[0];
                        string type     = location_type[1];

                        Sensor sensor;
                        if (sensors.TryGetValue(sensorName, out sensor) == false)
                        {
                            sensor = new Sensor
                            {
                                Name     = type,
                                Location = location,
                                Unit     = "unknown"
                            };
                            sensors.Add(sensorName, sensor);
                        }

                        measurements.Add(new Measurement
                        {
                            Sensor = sensor,
                            Time   = date.AddSeconds(time.TimeOfDay.TotalSeconds),
                            Value  = value
                        });
                    }
                }
            }
            return(measurements);
        }
        /// <summary>
        /// Liefert die Messwerte mit den dazugehörigen Sensoren
        /// </summary>
        public static Commit[] ReadFromCsv()
        {
            List <Commit> commits = new List <Commit>();

            string[]           lines  = System.IO.File.ReadAllLines(MyFile.GetFullNameInApplicationTree(Filename));
            List <CommitBlock> blocks = GetBlocks(lines);

            return(GetCommits(blocks));
        }
        /// <summary>
        /// Liefert die Commits mit dem dazugehörigen Developer
        /// </summary>
        public static Commit[] ReadFromCsv()
        {
            string        filePath = MyFile.GetFullNameInApplicationTree(Filename);
            List <Commit> commits  = new List <Commit>();
            Dictionary <string, Developer> developers = new Dictionary <string, Developer>();

            if (File.Exists(filePath) == false)
            {
                throw new Exception("File does not exist");
            }

            string[]  lines     = File.ReadAllLines(filePath, Encoding.UTF8);
            HeaderDto headerDto = null;
            FooterDto footerDto = null;

            foreach (string line in lines)
            {
                string[] data = line.Split(',');

                headerDto = MyParser.TryParseCommitHeader(line);
                if (headerDto != null)
                {
                    Developer developer;
                    if (developers.TryGetValue(headerDto.DeveloperName, out developer) == false)
                    {
                        developer = new Developer
                        {
                            Name = headerDto.DeveloperName
                        };
                        developers[headerDto.DeveloperName] = developer;
                    }

                    commits.Add(new Commit
                    {
                        HashCode     = headerDto.HashCode,
                        Developer    = developer,
                        Date         = headerDto.CommitDate,
                        Message      = headerDto.Message,
                        FilesChanges = 0,
                        Insertions   = 0,
                        Deletions    = 0
                    });
                }

                footerDto = MyParser.TryParseCommitFooter(line);
                if (footerDto != null && commits.Count > 0)
                {
                    Commit lastCommit = commits.Last();
                    lastCommit.FilesChanges = footerDto.FilesChanges;
                    lastCommit.Insertions   = footerDto.Insertions;
                    lastCommit.Deletions    = footerDto.Deletions;
                }
            }
            return(commits.ToArray());
        }
コード例 #12
0
        private void InitializeArticlesTasksFromCSV()
        {
            string articleFileName = MyFile.GetFullNameInApplicationTree("Articles.csv");
            string tasksFileName   = MyFile.GetFullNameInApplicationTree("Tasks.csv");

            string[] articleLines = File.ReadAllLines(articleFileName, Encoding.Default);
            string[] taskLines    = File.ReadAllLines(tasksFileName, Encoding.Default);

            CreateArticleList(articleLines);
            CreateTaskList(taskLines);
        }
コード例 #13
0
ファイル: Waiter.cs プロジェクト: maHlavacek/Restaurant
        /// <summary>
        /// CsvFile wird eingelesen
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public string[] ReadLinesFromCsvFile(string filename)
        {
            string path = MyFile.GetFullNameInApplicationTree(filename);

            if (!File.Exists(path))
            {
                return(null);
            }
            string[] lines = File.ReadAllLines(path, Encoding.Default);
            return(lines);
        }
コード例 #14
0
        /// <summary>
        /// Liefert die Movies mit den dazugehörigen Kategorien
        /// </summary>
        public static IEnumerable <Movie> ReadFromCsv()
        {
            bool   isFirstRow = true;
            string filePath   = MyFile.GetFullNameInApplicationTree(Filename);

            string[]      lines  = File.ReadAllLines(filePath, Encoding.UTF8);
            IList <Movie> movies = new List <Movie>();
            IDictionary <string, Category> categories = new Dictionary <string, Category>();

            foreach (var item in lines)
            {
                if (!isFirstRow)
                {
                    string[] parts        = item.Split(';');
                    string   tile         = parts[0];
                    int      year         = Convert.ToInt32(parts[1]);
                    string   categoryName = parts[2];
                    int      duration     = Convert.ToInt32(parts[3]);
                    Movie    movie        = new Movie
                    {
                        Title    = tile,
                        Duration = duration,
                        Year     = year
                    };

                    Category tmp;
                    if (categories.TryGetValue(categoryName, out tmp))
                    {
                        tmp.Movies.Add(movie);
                        movie.Category = tmp;
                    }
                    else
                    {
                        Category newCategory = new Category
                        {
                            CategoryName = categoryName
                        };
                        categories.Add(categoryName, newCategory);
                        movie.Category = newCategory;
                        newCategory.Movies.Add(movie);
                    }
                    movies.Add(movie);
                }
                else
                {
                    isFirstRow = false;
                }
            }
            return(movies);
        }
コード例 #15
0
        private void ReadAllArticles()
        {
            string path = MyFile.GetFullNameInApplicationTree("Articles.csv");

            string[] lines = File.ReadAllLines(path, UTF8Encoding.Default);

            for (int i = 1; i < lines.Length; i++)
            {
                string[] parts       = lines[i].Split(';');
                string   articleName = parts[0];
                Article  article     = new Article(articleName, Convert.ToDouble(parts[1]), Convert.ToInt32(parts[2]));
                _articles.Add(articleName, article);
            }
        }
コード例 #16
0
        public void GetOrder()
        {
            string pfad = MyFile.GetFullNameInApplicationTree(_pfadTasks);

            string[] lines = File.ReadAllLines(pfad, Encoding.Default);
            for (int i = 1; i < lines.Length; i++)
            {
                string[] line                  = lines[i].Split(';');
                double   delayMinutes          = double.Parse(line[0]);
                string   displayDelayedMinutes = FastClock.Instance.Time.AddMinutes(delayMinutes).ToShortTimeString();
                Order    order                 = new Order(displayDelayedMinutes, line[1], line[2], line[3]);
                _ordersOrdered.Enqueue(order);
            }
            ManageOrder();
        }
コード例 #17
0
        /// <summary>
        /// Artikel aus der csv-Datei in die Artikel-Map einlesen.
        /// </summary>
        /// <returns></returns>
        private static Dictionary <string, Article> ReadArticlesFromCsv()
        {
            string[] lines = File.ReadAllLines(path:
                                               MyFile.GetFullNameInApplicationTree(ArticlesFilename),
                                               Encoding.Default);
            var articles = new Dictionary <string, Article>();

            for (int i = 1; i < lines.Length; i++)
            {
                var     line    = lines[i].Split(';');
                Article article = new Article(line[0], double.Parse(line[1]), int.Parse(line[2]));
                articles.Add(line[0], article);
            }
            return(articles);
        }
        /// <summary>
        /// Liefert die Messwerte mit den dazugehörigen Sensoren
        /// </summary>
        public static IEnumerable <Measurement> ReadFromCsv()
        {
            bool   isFirstRow = true;
            string filePath   = MyFile.GetFullNameInApplicationTree(Filename);

            string[]                     lines        = File.ReadAllLines(filePath, Encoding.UTF8);
            IList <Measurement>          measurements = new List <Measurement>();
            IDictionary <string, Sensor> sensors      = new Dictionary <string, Sensor>();

            foreach (var item in lines)
            {
                if (!isFirstRow)
                {
                    string[]    parts       = item.Split(";");
                    string      location    = parts[2].Split("_")[0];
                    string      name        = parts[2].Split("_")[1];
                    DateTime    dateTime    = DateTime.Parse($"{parts[0]} {parts[1]}");
                    Measurement measurement = new Measurement()
                    {
                        Time = dateTime, Value = Convert.ToDouble(parts[3])
                    };
                    Sensor tmp;
                    if (!sensors.TryGetValue(parts[2], out tmp))
                    {
                        Sensor newSensor = new Sensor()
                        {
                            Name = name, Location = location
                        };
                        measurement.Sensor = newSensor;
                        newSensor.Measurements.Add(measurement);
                        sensors.Add(parts[2], newSensor);
                    }
                    else
                    {
                        measurement.Sensor = tmp;
                        tmp.Measurements.Add(measurement);
                    }
                    measurements.Add(measurement);
                }
                if (isFirstRow)
                {
                    isFirstRow = false;
                }
            }
            return(measurements);
        }
コード例 #19
0
        private List <Article> GetArticles()
        {
            string path = MyFile.GetFullNameInApplicationTree("Articles.csv");

            string[]       lines  = File.ReadAllLines(path, Encoding.Default);
            List <Article> result = new List <Article>();

            for (int i = 1; i < lines.Length; i++)
            {
                string[] fields      = lines[i].Split(';');
                string   name        = fields[0];
                double   price       = Convert.ToDouble(fields[1]);
                int      timeToBuild = Convert.ToInt32(fields[2]);
                result.Add(new Article(name, price, timeToBuild));
            }

            return(result);
        }
コード例 #20
0
        /// <summary>
        /// Liefert die Movies mit den dazugehörigen Kategorien
        /// </summary>
        public static IEnumerable <Movie> ReadFromCsv()
        {
            bool   isFirstLine = true;
            string filePath    = MyFile.GetFullNameInApplicationTree(Filename);

            string[] lines = File.ReadAllLines(filePath);
            Dictionary <string, Category> categories = new Dictionary <string, Category>();
            List <Movie> movies = new List <Movie>();

            foreach (var item in lines)
            {
                if (!isFirstLine)
                {
                    string[] parts         = item.Split(";");
                    string   movieName     = parts[0];
                    int      year          = Convert.ToInt32(parts[1]);
                    string   categoryName  = parts[2];
                    int      movieDuration = Convert.ToInt32(parts[3]);

                    Movie newMovie = new Movie {
                        Title = movieName, Year = year, Duration = movieDuration
                    };

                    if (!categories.ContainsKey(categoryName))
                    {
                        Category newCategory = new Category {
                            CategoryName = categoryName
                        };
                        categories.Add(categoryName, newCategory);
                        newCategory.Movies.Add(newMovie);
                        newMovie.Category = newCategory;
                    }
                    else
                    {
                        categories.TryGetValue(categoryName, out Category existingCategory);
                        newMovie.Category = existingCategory;
                        existingCategory.Movies.Add(newMovie);
                    }
                    movies.Add(newMovie);
                }
                isFirstLine = false;
            }
            return(movies);
        }
コード例 #21
0
        /// <summary>
        /// Liefert die Movies mit den dazugehörigen Kategorien
        /// </summary>
        public static IEnumerable <Movie> ReadFromCsv()
        {
            string[] lines = File.ReadAllLines(MyFile.GetFullNameInApplicationTree(Filename), Encoding.UTF8);

            IDictionary <string, Category> categories = new Dictionary <string, Category>();
            List <Movie> movies = new List <Movie>();

            for (int i = 1; i < lines.Length; i++)
            {
                string[] splitted = lines[i].Split(";");

                string title    = splitted[0];
                int    year     = Convert.ToInt32(splitted[1]);
                string category = splitted[2];
                int    duration = Convert.ToInt32(splitted[3]);

                Category newCat;

                Movie movie = new Movie
                {
                    Title    = title,
                    Duration = duration,
                    Year     = year
                };

                Category cat;
                if (categories.TryGetValue(category, out cat))
                {
                    movie.Category = cat;
                }
                else
                {
                    newCat = new Category
                    {
                        CategoryName = category,
                    };
                    categories.Add(category, newCat);

                    movie.Category = newCat;
                }
                movies.Add(movie);
            }
            return(movies.ToArray());
        }
コード例 #22
0
        /// <summary>
        /// Liefert die Messwerte mit den dazugehörigen Sensoren
        /// </summary>
        public static Commit[] ReadFromCsv()
        {
            string[] lines = File.ReadAllLines(MyFile.GetFullNameInApplicationTree(Filename));
            Dictionary <string, Developer> developers = new Dictionary <string, Developer>();

            foreach (string line in lines)
            {
                string[] parts = line.Split(';');
                string   name  = parts[0];

                if (!developers.ContainsKey(name))
                {
                    Developer developer = new Developer(name);
                    developers.Add(name, developer);
                }
            }


            return(lines
                   .Select(line =>
            {
                string[] parts = line.Split(';');
                string name = parts[0];
                DateTime date = DateTime.Parse(parts[1]);
                string message = parts[2];
                string hashcode = parts[3];
                int filesChanges = int.Parse(parts[4]);
                int insertions = int.Parse(parts[5]);
                int deletions = int.Parse(parts[6]);

                if (developers.ContainsKey(name))
                {
                    return new Commit()
                    {
                        Developer = developers[name], Date = date, Message = message, HashCode = hashcode, FilesChanges = filesChanges, Insertions = insertions, Deletions = deletions
                    };
                }
                else
                {
                    return null;
                }
            }).ToArray());
        }
        //habe mir den code von einem Mitschüler genommen da ich nicht ganz
        //wusste wie ich die Textdatei einlesen soll und den ImportController
        //aber brauchte um weiter zu arbeiten
        //der ImportController funktioniert allerdings nicht ganz bei mir

        /*  private static string newString = null;
         *
         * public static bool Header(string[] array)
         * {
         *    if (array.Length > 4)
         *    {
         *        foreach (var item in array)
         *        {
         *
         *            newString = newString + item + ';';
         *        }
         *    }
         *    return true;
         * }
         * public static bool Body(string[] array)
         * {
         *    if (Header(array) == true)
         *    {
         *        foreach (var item in array)
         *        {
         *
         *            newString = newString + item + ';';
         *        }
         *    }
         *    return true;
         * }*/



        /// <summary>
        /// Liefert die Messwerte mit den dazugehörigen Sensoren
        /// </summary>
        public static Commit[] ReadFromCsv()
        {
            List <Commit> commits = new List <Commit>();

            string[]           lines  = System.IO.File.ReadAllLines(MyFile.GetFullNameInApplicationTree(Filename));
            List <CommitBlock> blocks = GetBlocks(lines);

            return(GetCommits(blocks));

            /* List<Developer> dev = new List<Developer>();
             * List<Commit> com = new List<Commit>();
             * string[] txt = File.ReadAllLines(MyFile.GetFullNameInApplicationTree(Filename));
             *
             * foreach (var a in txt)
             * {
             *
             *   if (Header(txt) == true && Body(txt) == false)
             *   {
             *       Commit commit;
             *      // Developer deve;
             *
             *       string[] commits = newString.Split(';');
             *       com.Add(commit = new Commit
             *       {
             *           Developer = new Developer
             *           {
             *               Name = commits[1]
             *           },
             *
             *           Date = DateTime.Parse(commits[2]),
             *           FilesChanges = Convert.ToInt32(commits[4]),
             *           Insertions  = Convert.ToInt32(commits[5]),
             *
             *       });
             *
             *
             *   }
             *
             * }
             * return com.ToArray();*/
        }
        /// <summary>
        /// Liefert die Messwerte mit den dazugehörigen Sensoren
        /// </summary>
        public static IEnumerable <Measurement> ReadFromCsv()
        {
            List <Measurement> measurements = new List <Measurement>();
            List <Sensor>      sensors      = new List <Sensor>();

            string filePath = MyFile.GetFullNameInApplicationTree(Filename);

            string[] lines = File.ReadAllLines(filePath);


            for (int i = 0; i < lines.Length; i++)
            {
                string[] line = lines[i].Split(";");

                if (line[0] != "Date")
                {
                    string[] locationAndName = line[2].Split("_");
                    DateTime time            = new DateTime();
                    DateTime.TryParse(line[0] + " " + line[1], out time);
                    Sensor current = new Sensor
                    {
                        Name     = locationAndName[1],
                        Location = locationAndName[0]
                    };

                    if (!sensors.Contains(current))
                    {
                        sensors.Add(current);
                    }

                    measurements.Add(new Measurement
                    {
                        Sensor = sensors.Find(searched => searched.Location.Equals(current.Location) && searched.Name.Equals(current.Name)),
                        Time   = time,
                        Value  = double.Parse(line[3], System.Globalization.CultureInfo.InvariantCulture)
                    });
                }
            }

            return(measurements);
        }
コード例 #25
0
        /// <summary>
        /// Aus den Results werden alle Collections, außer Races gefüllt.
        /// Races wird extra behandelt, um auch Rennen ohne Results zu verwalten
        /// </summary>
        public static IEnumerable <Result> LoadResultsFromXmlIntoCollections()
        {
            LoadRacesFromRacesXml();
            Results = new List <Result>();
            string resultPath = MyFile.GetFullNameInApplicationTree("Results.xml");
            var    xElement   = XDocument.Load(resultPath).Root;

            if (xElement != null)
            {
                Results = xElement.Elements("Race")?.Elements("ResultsList")?.Elements("Result")
                          .Select(result => new Result
                {
                    Race     = GetRace(result),
                    Driver   = GetDriver(result),
                    Team     = GetTeam(result),
                    Position = (int)result.Attribute("position"),
                    Points   = (int)result.Attribute("points")
                }).ToList();
            }
            return(Results);
        }
コード例 #26
0
            /// <summary>
            ///     Liest die Daten aus einer CSV-Datei in einen IEnumerable des gewünschten Typs ein.
            ///     Grundsätzlich wird der Propertyname des einzulesenden Typs auf den Spaltennamen gemappt. Die
            ///     Typumwandlung erfolgt auf Basis des Propertytyps.
            ///     Für spezielle Mappings kann die Methode specialMapping verwendet werden. Dieser wird das zu befüllende
            ///     Objekt, die Headerzeile und die aktuelle Datenzeile mitgegeben. Die Methode kann dann ein oder mehrere
            ///     Properties sehr flexibel belegen
            /// </summary>
            /// <typeparam name="T">Typ des Zielobjekts</typeparam>
            /// <param name="fileName">Name der csv-Datei ohne Pfad. Es wird im Anwendungspfad gesucht</param>
            /// <param name="seperator">Trennzeichen in der csv-Datei (default: ;</param>
            /// <param name="specialMapping">Mappingmethode für spezielle Anforderungen</param>
            /// <returns></returns>
            public static IEnumerable <T> CsvFileToEnumerable <T>(string fileName, char seperator = DefaultSeperator,
                                                                  Action <T, string[], string[]> specialMapping = null) where T : class, new()
            {
                if (string.IsNullOrEmpty(fileName))
                {
                    throw new ArgumentNullException("The parameter 'fileName' can not be null or empty!");
                }
                string fullFileName = MyFile.GetFullNameInApplicationTree(fileName);

                if (string.IsNullOrEmpty(fullFileName))
                {
                    throw new FileNotFoundException("The file could not be found i  application tree");
                }
                string[] lines = File.ReadAllLines(fullFileName, Encoding.Default);
                if (lines == null || lines.Length == 0)
                {
                    throw new ApplicationException("csv-file is empty");
                }
                string[] csvPropertyNames = lines[0].Split(seperator);
                if (csvPropertyNames == null || csvPropertyNames.Length == 0)
                {
                    throw new ApplicationException("there are no propertynames in the headerline");
                }
                var dataObjects = new T[lines.Length - 1];

                // Alle Properties des Zieltyps mit Daten aus gleichnamiger Spalte der CSV-Datei übernehmen
                for (int i = 1; i < lines.Length; i++)
                {
                    dataObjects[i - 1] = CsvLineTo <T>(lines[i], csvPropertyNames, seperator);
                }
                // spezielle Zuordnungen einer Zeile zu einem oder mehreren Properties werden im Anschluss extra behandelt
                if (specialMapping != null)
                {
                    for (int i = 1; i < lines.Length; i++)
                    {
                        specialMapping(dataObjects[i - 1], csvPropertyNames, lines[i].Split(seperator));
                    }
                }
                return(dataObjects);
            }
コード例 #27
0
        public static IEnumerable <Game> ReadFromCsv()
        {
            string filePath = MyFile.GetFullNameInApplicationTree(Filename);

            teams = new Dictionary <string, Team>();
            List <Game> games = new List <Game>();

            if (!File.Exists(filePath))
            {
                throw new Exception("File does not exist");
            }

            string[] lines = File.ReadAllLines(filePath, Encoding.UTF8);

            foreach (string line in lines)
            {
                string[] data = line.Split(Separator);
                //1;Manchester United;Tottenham Hotspur;1;0
                int    round         = int.Parse(data[0]);
                string homeTeamName  = data[1];
                string guestTeamName = data[2];
                int    homeGoals     = int.Parse(data[3]);
                int    guestGoals    = int.Parse(data[4]);
                Team   homeTeam      = GetTeam(homeTeamName);
                Team   awayTeam      = GetTeam(guestTeamName);

                Game newGame = new Game
                {
                    Round      = round,
                    HomeTeam   = homeTeam,
                    GuestTeam  = awayTeam,
                    HomeGoals  = homeGoals,
                    GuestGoals = guestGoals
                };
                games.Add(newGame);
            }
            return(games);
        }
コード例 #28
0
        /// <summary>
        /// Aus den Results werden alle Collections, außer Races gefüllt.
        /// Races wird extra behandelt, um auch Rennen ohne Results zu verwalten
        /// </summary>
        public static IEnumerable <Result> LoadResultsFromXmlIntoCollections()
        {
            List <Race>   races     = LoadRacesFromRacesXml().ToList();
            List <Driver> drivers   = new List <Driver>();
            List <Team>   teams     = new List <Team>();
            List <Result> results   = null;
            string        racesPath = MyFile.GetFullNameInApplicationTree("Results.xml");
            var           xElement  = XDocument.Load(racesPath).Root;

            if (xElement != null)
            {
                results = xElement.Elements("Race").Elements("ResultsList").Elements("Result")
                          .Select(result => new Result
                {
                    Race     = GetRace(result, races),
                    Driver   = GetDriver(result, drivers),
                    Team     = GetTeam(result, teams),
                    Position = (int)result.Attribute("position"),
                    Points   = (int)result.Attribute("points"),
                }).ToList();
            }
            return(results);
        }
コード例 #29
0
        /// <summary>
        /// Reads the txt file and return the commits as an array
        /// </summary>
        public static Commit[] ReadFromCsv()
        {
            string path = MyFile.GetFullNameInApplicationTree(Filename);

            string[] lines = File.ReadAllLines(path, Encoding.Default);

            _developers = new List <Developer>();
            _blocks     = new List <string[]>();
            int range = 0;

            while (range < lines.Length)
            {
                var block = lines.Skip(range).TakeWhile(tw => !string.IsNullOrEmpty(tw)).ToArray();
                range += block.Count() + 1;
                _blocks.Add(block);
            }
            List <Commit> commits = new List <Commit>();

            foreach (string[] block in _blocks)
            {
                commits.AddRange(CreateCommitsFromBlock(block));
            }
            return(commits.ToArray());
        }
コード例 #30
0
        /// <summary>
        /// Liefert die Messwerte mit den dazugehörigen Sensoren
        /// </summary>
        public static Commit[] ReadFromTxt()
        {
            string path = MyFile.GetFullNameInApplicationTree(Filename);
            string text = File.ReadAllText(path, Encoding.Default);

            List <Commit> commits         = new List <Commit>();
            List <Commit> returnedCommits = new List <Commit>();

            //Split read in text into blocks
            string[] block = text.Split("\n\r\n");

            for (int i = 0; i < block.Length; i++)
            {
                //get each line out of the block
                string lineOfBlock = block[i];
                returnedCommits = GetCommitOfEachBlock(lineOfBlock);

                foreach (Commit currentCommit in returnedCommits)
                {
                    commits.Add(currentCommit);
                }
            }
            return(commits.ToArray());
        }