Пример #1
0
        static void Main(string[] args)
        {
            File.Delete("Department.xml");
            File.Delete("Employee.xml");
            IRepository repo = new XmlRepository();

            Populate(repo);

            var employees = repo.Employees;

            PrintEmployees(employees);

            var emplArtur = repo.Employees.First(
                e => e.FirstName.Equals("Artur", StringComparison.InvariantCultureIgnoreCase)
                );

            emplArtur.Promote();
            repo.Save();
            PrintEmployees(repo.Employees);

            var engeneeringDepartment = new Department {
                Id = 4, Name = "Engineering"
            };

            repo.AddDepartment(engeneeringDepartment);
            repo.Save();
            PrintDepartments(repo.Departments);

            emplArtur.ChangeDepartment(engeneeringDepartment);
            repo.Save();
            PrintEmployees(repo.Employees);

            emplArtur.Demote();
            repo.Save();
            PrintEmployees(repo.Employees);

            var marcoCantu = employees.Single(e => e.FirstName.Equals("Marco") && e.SecondName.Equals("Cantu"));

            emplArtur.ChangeChief(marcoCantu);
            repo.Save();
            PrintEmployees(repo.Employees);

            Console.Read();
        }
Пример #2
0
        public void RoundtripRepositorySettingsWithRepo()
        {
            var backupSettings = new BackupSettings(new DirectoryInfo(@"C:\Temp\Gu.Settings\" + GetType().Name + @"\Backup"));
            var directory      = new DirectoryInfo(@"C:\Temp\Gu.Settings\" + GetType().Name);
            var settings       = new XmlRepositorySettings(directory, true, true, backupSettings, ".cfg", ".tmp");
            var repository     = new XmlRepository(settings);

            repository.Save(settings);
            var repositorySettings = repository.Read <XmlRepositorySettings>();
        }
Пример #3
0
        public void XmlSample()
        {
            var repository = new XmlRepository();

            Console.WriteLine(repository.Settings.DirectoryPath);

            Console.WriteLine(_settingsFile.FullName);
            AssertFile.Exists(true, _settingsFile); // using the default constructor bootstraps with a settings file

            var setting = repository.ReadOrCreate(() => new DummySerializable());

            setting.Value++;
            Assert.IsTrue(repository.IsDirty(setting));
            repository.Save(setting);
            Assert.IsFalse(repository.IsDirty(setting));
        }
        public void XmlRepoTests_Can_CRUD_Baum()
        {
            var baum = new Tannenbaum()
            {
                Height = 17
            };
            var newHeight = 452;

            {//INSERT
                var repo = new XmlRepository();
                repo.Add(baum);
                repo.Save();
            }


            {//check Read
                var repo = new XmlRepository();

                Assert.IsTrue(repo.GetAll <Tannenbaum>().Any(x => x.Height == baum.Height));
                var loaded = repo.GetById <Tannenbaum>(baum.Id);
                Assert.IsNotNull(loaded);
                Assert.AreEqual(baum.Height, loaded.Height);

                //UPDATE
                loaded.Height = 452;
                repo.Save();
            }

            {//check UPDATE + DELETE
                var repo   = new XmlRepository();
                var loaded = repo.GetById <Tannenbaum>(baum.Id);
                Assert.AreEqual(newHeight, loaded.Height);

                repo.Delete(loaded);
                repo.Save();
            }

            {//check DELETE
                var repo   = new XmlRepository();
                var loaded = repo.GetById <Tannenbaum>(baum.Id);
                Assert.IsNull(loaded);
            }
        }
Пример #5
0
        public static void LoadAndSave()
        {
            IRepository repo = new XmlRepository();

            repo.Load("TaskPanel.xml", "mara", "1111");

            repo.Save(new Task
            {
                Content = "Newly created task " + DateTime.Now.ToShortTimeString(),
                Group   = repo.Groups.First(g => g.ID == 1),
                State   = repo.TaskStates.First(s => s.ID == 1)
            });

            foreach (ITask item in repo.Tasks)
            {
                Console.WriteLine("Task: [{0}::{1}] {2}", item.Group.Name, item.State.Name, item.Content);
            }
            Console.ReadKey(true);

            repo.Commit();
        }