Example #1
0
        public static void Seed(IRepository<Hub> hubRepository, IRepository<Channel> channelRepository, IRepository<ChatMessage> messageRepository)
        {
            hubRepository.Insert(new Hub("scottlogic", "Scott Logic", new List<Channel>()));

            channelRepository.Insert(new Channel("bristol", "scottlogic", "Bristol", DateTime.Now));
            channelRepository.Insert(new Channel("edinburgh", "scottlogic", "Edinburgh", DateTime.Now));
            channelRepository.Insert(new Channel("newcastle", "scottlogic", "Newcastle", DateTime.Now));

            messageRepository.Insert(new ChatMessage("nico", "bristol", "Bristol message", DateTime.Now));
            messageRepository.Insert(new ChatMessage("nico", "edinburgh", "Edinburgh message", DateTime.Now));
            messageRepository.Insert(new ChatMessage("nico", "newcastle", "Newcastle message", DateTime.Now));
        }
        public MemoryRepositorySimpleTests()
        {
            _database = new MemoryDatabase();
            var databaseProvider = Substitute.For<IMemoryDatabaseProvider>();
            databaseProvider.Database.Returns(_database);

            _repository = new MemoryRepository<TestEntity>(databaseProvider);

            // Testing Insert by creating initial data
            _repository.Insert(new TestEntity("test1"));
            _repository.Insert(new TestEntity("test2"));
            _database.Set<TestEntity>().Count.ShouldBe(2);
        }
        public MemoryRepository_Simple_Tests()
        {
            _database = new MemoryDatabase();

            var databaseProvider = Substitute.For<IMemoryDatabaseProvider<int, long>>();
            databaseProvider.Database.Returns(_database);

            _repository = new MemoryRepository<MyEntity, int, long>(databaseProvider);

            //Testing Insert by creating initial data
            _repository.Insert(new MyEntity("test-1"));
            _repository.Insert(new MyEntity("test-2"));
            _database.Set<MyEntity>().Count.ShouldBe(2);
        }
        public static async Task Seed(IRepository<Hub> hubRepository, IRepository<Channel> channelRepository, IRepository<ChatMessage> messageRepository)
        {
            var bristol = new Channel("bristol", "scottlogic", "Bristol", DateTime.Now);
            var edinburgh = new Channel("edinburgh", "scottlogic", "Edinburgh", DateTime.Now);
            var newcastle = new Channel("newcastle", "scottlogic", "Newcastle", DateTime.Now);

            await channelRepository.Insert(bristol);
            await channelRepository.Insert(edinburgh);
            await channelRepository.Insert(newcastle);

            var scottlogic = new Hub("scottlogic", "Scott Logic", new List<Channel>() {
                bristol,
                edinburgh,
                newcastle
            });
            
            await hubRepository.Insert(scottlogic);
        }
        /// <summary>
        /// The create new tags.
        /// </summary>
        /// <param name="tags">
        /// The tags.
        /// </param>
        /// <param name="tagRepository">
        /// The tag repository.
        /// </param>
        /// <returns>
        /// The <see cref="IList"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        private IList<Tag> CreateNewTags(IList<Tag> tags, IRepository<Tag, int> tagRepository)
        {
            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }

            IList<Tag> result = new List<Tag>(tags.Count);
            for (int i = 0; i < tags.Count; ++i)
            {
                string content = tags[i].Content;
                Tag temp =
                    tagRepository.Query()
                                 .Filter(p => p.Content.Equals(content, StringComparison.Ordinal))
                                 .Get()
                                 .FirstOrDefault();
                if (temp == null)
                {
                    tagRepository.Insert(tags[i]);
                    result.Add(tags[i]);
                }
                else
                {
                    result.Add(temp);
                }
            }

            return result;
        }
        private Profile GetProfile(string username, bool isAnonymous, IRepository<Profile> profiles)
        {
            var profile = profiles
                .FirstOrDefault(p =>
                          p.User.UserName == username
                          && p.ApplicationName == ApplicationName
                          && p.IsAnonymous == isAnonymous);

            if (profile == null)
            {
                var membershipUser = UnitOfWork.Current.CreateRepository<User>()
                    .FirstOrDefault(p => p.UserName == username
                    && p.ApplicationName == ApplicationName);

                if (membershipUser == null)
                    throw new ProviderException("Profile cannot be created. There is no membership user");

                profile = new Profile();
                profile.IsAnonymous = isAnonymous;
                profile.LastUpdatedDate = System.DateTime.Now;
                profile.LastActivityDate = System.DateTime.Now;
                profile.ApplicationName = this.ApplicationName;
                profile.UserId = membershipUser.Id;

                profiles.Insert(profile);
            }
            return profile;
        }
        public HomeViewModel(ILog log, IAccount account, ILocalize localize, IApplication application, IHistory history,
                             INavigationService navigationService, IUser user, IRepository repository,
                             IList<IExerciseType> exerciseTypes, ISettings settings)
        {
            _log = log;
            _localize = localize;
            _application = application;
            Account = account;

            _history = history;
            _history.OnHistoryItemsChanged += _history_OnHistoryItemsChanged;
            _NavigationService = navigationService;
            User = user;
            ExerciseTypes = exerciseTypes;
            _repository = repository;
            _settings = settings;
            _settings.OnSettingsChanged += _settings_OnSettingsChanged;
            _settings.Load();
            _history.Load();

            _repository.Single<User>(1).ContinueWith(t =>
                {
                    var foundUser = t.Result;
                    if (foundUser == null)
                    {
                        //this is first load of the app, set it up
                        _repository.Insert<User>(this.User).ContinueWith(task =>
                            {
                                this.User = this.User;
                                Account.AccessToken = this.User.RunkeeperToken;

                            });
                    }
                    else
                    {
                        User = foundUser;
                        Account.AccessToken = foundUser.RunkeeperToken;
                    }
                });

            if (_exerciseTypes == null || _exerciseTypes.Count == 0 ||
                (_exerciseTypes.Count == 1 && _exerciseTypes[0].Id == 0))
            {
                if (HomeViewModel.cachedTypes != null)
                {
                    this.ExerciseTypes = HomeViewModel.cachedTypes;
                    _log.Info("cache hit");
                }
                else
                {
                    _log.Info("cache miss");
                    this.ExerciseTypes = DefaultTypes;
                    _log.Info("default types set, querying");
                    _repository.Query<ExerciseType>("select * from ExerciseType").ContinueWith(t =>
                        {
                            _log.Info("query complete");
                            var types = t.Result;
                            if (types == null || types.Count == 0)
                            {

                                _log.Info("db does not have Exercise types, loading default items");
                                foreach (var e in from tt in this.ExerciseTypes orderby tt.Id select tt)
                                {
                                    _repository.Insert<ExerciseType>(e);
                                }
                            }
                            else
                            {
                                _log.Info("all excecise types retreived from the db, update local data store");
                                this.ExerciseTypes = (from tt in types select tt).ToArray();
                            }
                            _log.Info("cache extypes to static var");
                            HomeViewModel.cachedTypes = ExerciseTypes;

                        });
                }
            }
        }
Example #8
0
        internal static void SeedData(IRepository repository)
        {
            Console.WriteLine("Seeding data...");

            // Seed Persons
            var persons = new List<Person>
                              {
                                  new Person {FirstName = "Arthur", LastName = "Smith", Gender = "M"},
                                  new Person {FirstName = "Bert", LastName = "Jones", Gender = "M"},
                                  new Person {FirstName = "Charlie", LastName = "Robertson", Gender = "M"}
                              };

            persons.ForEach(p => repository.Insert(p));

            // Seed Regions
            var regions = new List<Region>
                              {
                                  new Region {Name = "Banff National Park - South", Description = "Banff National Park"},
                                  new Region {Name = "Jasper National Park"},
                                  new Region {Name = "Kootenay National Park"},
                                  new Region {Name = "Banff National Park - North"},
                                  new Region {Name = "Kananaskis Country"}
                              };
            regions.ForEach(r => repository.Insert(r));

            // Seed Locations
            var locations = new List<Location>
                                {
                                    new Location
                                        {
                                            Name = "Bow Valley Parkway",
                                            Description = "Road from Banff to Lake Louise",
                                            Directions = "Turn left off main highway 2km north of Banff",
                                            Region = regions[0]
                                        },
                                    new Location {Name = "Banff Townsite area", Region = regions[0]},
                                    new Location
                                        {
                                            Name = "Bow Lake area",
                                            Description = "20 minutes north of Lake Louise on IceField Parkway",
                                            Region = regions[3]
                                        },
                                    new Location {Name = "Smith Dorrien Highway", Region = regions[4]}
                                };
            locations.ForEach(l => repository.Insert(l));

            // Seed Difficulty Levels
            var difficulties = new List<Difficulty>
                                   {
                                       new Difficulty {DifficultyType = "Easy"},
                                       new Difficulty {DifficultyType = "Moderate"},
                                       new Difficulty {DifficultyType = "Challenging"},
                                       new Difficulty {DifficultyType = "Difficult"}
                                   };
            difficulties.ForEach(d => repository.Insert(d));

            // Seed TrailType Levels
            var trailTypes = new List<TrailType>
                                 {
                                     new TrailType {TrailTypeName = "Land"},
                                     new TrailType {TrailTypeName = "Air"},
                                     new TrailType {TrailTypeName = "Water"}
                                 };
            trailTypes.ForEach(t => repository.Insert(t));

            // Seed TransportType Levels
            var transportTypes = new List<TransportType>
                                     {
                                         new TransportType {TransportTypeName = "Hike"},
                                         new TransportType {TransportTypeName = "Cycle"},
                                         new TransportType {TransportTypeName = "Canoe"},
                                         new TransportType {TransportTypeName = "Ski"},
                                         new TransportType {TransportTypeName = "Snowshoe"},
                                         new TransportType {TransportTypeName = "Aeroplane"}
                                     };
            transportTypes.ForEach(t => repository.Insert(t));

            // Seed Trails
            var trails = new List<Trail>
                             {
                                 new Trail
                                     {
                                         Name = "Johnstone Canyon",
                                         Description = "Johnstone Canyon",
                                         Distance = 4.8M,
                                         ElevationGain = 200,
                                         EstimatedTime = 2,
                                         Location = locations[0],
                                         TrailType = trailTypes[0],
                                         Difficulty = difficulties[0],
                                         ReturnOnEffort = 9.2M,
                                         OverallGrade = 7.2M,
                                         Notes =
                                             "Good Waterfalls scenery. Good in all seasons. Take crampons in winter/spring",
                                         Longitude = -102,
                                         Latitude = 50
                                     },
                                 new Trail
                                     {
                                         Name = "Burstall Pass",
                                         Description = "Burstall Pass",
                                         Distance = 8.53M,
                                         ElevationGain = 390,
                                         EstimatedTime = 4,
                                         Location = locations[1],
                                         TrailType = trailTypes[0],
                                         Difficulty = difficulties[0],
                                         ReturnOnEffort = 8.1M,
                                         OverallGrade = 8.1M,
                                         Notes = "Excellent view from the pass"
                                     },
                                 new Trail
                                     {
                                         Name = "Helen Lake",
                                         Description = "Helen Lake",
                                         Distance = 8M,
                                         ElevationGain = 480,
                                         EstimatedTime = 4.5M,
                                         Location = locations[2],
                                         TrailType = trailTypes[0],
                                         Difficulty = difficulties[3],
                                         ReturnOnEffort = 7.8M,
                                         OverallGrade = 7.8M,
                                         Notes = "Views across to the Dolomite range."
                                     },
                                 new Trail
                                     {
                                         Name = "Chester Lake",
                                         Description = "Chester Lake",
                                         Distance = 8.11M,
                                         ElevationGain = 520,
                                         EstimatedTime = 4.5M,
                                         Location = locations[2],
                                         TrailType = trailTypes[0],
                                         Difficulty = difficulties[1],
                                         ReturnOnEffort = 6.9M,
                                         OverallGrade = 6.9M,
                                         Notes = "Don't stop at Chester Lake - go on to Three Lake Valley"
                                     }
                             };

            trails.ForEach(t => repository.Insert(t));

            // Seed Trips
            var trips = new List<Trip>
                            {
                                new Trip
                                    {
                                        Date = new DateTime(2001, 9, 1),
                                        TransportType = transportTypes[0],
                                        Trail = trails[0],
                                        Weather = "Cloudy",
                                        TimeTaken = 3.3M,
                                        Notes = "Very slippery - cramps needed.",
                                        Persons = new List<Person>
                                        {
                                            persons[0], persons[1],persons[2]
                                        }
                                    },
                                new Trip
                                    {
                                        Date = new DateTime(2004, 7, 31),
                                        TransportType = transportTypes[1],
                                        Trail = trails[0],
                                        Weather = "Sunny",
                                        TimeTaken = 2.3M,
                                        Notes = "First time on this trail."

                                    }
                            };
            trips.ForEach(t => repository.Insert(t));

            repository.SaveChanges();
        }
        private static bool AddOrUpdateSetting(IRepository<SettingData> repository, SettingKey key, IProxyType<string> value)
        {
            SettingData setting = repository.Query.FirstOrDefault(_ => _.Identifier == key.Identifier && _.Name == key.Name);

            if (setting == null)
            {
                setting = new SettingData();
                setting.Identifier = key.Identifier;
                setting.Name = key.Name;

                repository.Insert(setting);
            }

            string valueToPersist = value.ProxiedValue;
            if (!string.Equals(setting.Value, valueToPersist, StringComparison.Ordinal))
            {
                setting.Value = valueToPersist;

                return true;
            }

            return false;
        }