コード例 #1
0
        /// <summary>
        /// Finds the Object that matches the given ID in the Entitie's storage file.
        /// </summary>
        /// <typeparam name="T">The type of Object that should be returned</typeparam>
        /// <param name="id">The ID of the Object</param>
        /// <exception cref="DuplicateDataException">More than one object with this ID was found.</exception>
        /// <returns>Object if ID can be found.
        /// Null if ID cannot be found.</returns>
        public T GetByID <T>(Guid id)
            where T : Storable, new()
        {
            string          path          = du.GetPath(typeof(T));
            Matches         matches       = (x) => x[0].Equals(id.ToString());
            List <string[]> matchingLines = GetAllMatchingLines(matches, path);

            if (matchingLines.Count == 0)
            {
                return(null);
            }
            else if (matchingLines.Count != 1)
            {
                throw new DuplicateDataException("id occured multiple times in the file.");
            }
            return(CreateNew <T>(matchingLines.First(), new T()));
        }
コード例 #2
0
 /// <summary>
 /// Stores objects of the Type Course, Lecturer, Major, Rating, Student, University.
 /// Will return true if successfull and false if an error occured.
 /// </summary>
 /// <param name="o"></param>
 /// <returns>true when storing was successfull. Otherwise false</returns>
 public bool Store(Object o)
 {
     try
     {
         string path = du.GetPath(o);
         string info = o.ToString();
         File.AppendAllText(path, info);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #3
0
        public void DeleteAllTestDataFromTextFiles()
        {
            DataUtility du = new DataUtility();

            File.WriteAllText(du.GetPath(typeof(University)), String.Empty);
            File.WriteAllText(du.GetPath(typeof(Course)), String.Empty);
            File.WriteAllText(du.GetPath(typeof(Lecturer)), String.Empty);
            File.WriteAllText(du.GetPath(typeof(Major)), String.Empty);
            File.WriteAllText(du.GetPath(typeof(Rating)), String.Empty);
            File.WriteAllText(du.GetPath(typeof(Student)), String.Empty);
        }