private static void RecalculateTimetableArchive(IRepository<TimetablePartArchiveRecord> TimetableArchiveRepository, ITimetableAppointmentService TimetableAppointmentService, TimetableAppointmentPart TimetableAppointmentPart) { TimetableArchiveRepository.Flush(); // remove all current Timetable archive records var TimetableArchiveRecords = from bar in TimetableArchiveRepository.Table where bar.TimetablePart == TimetableAppointmentPart.TimetablePart.Record select bar; TimetableArchiveRecords.ToList().ForEach(TimetableArchiveRepository.Delete); // get all Timetable appointments for the current Timetable var appointments = TimetableAppointmentService.Get(TimetableAppointmentPart.TimetablePart, VersionOptions.Published); // create a dictionary of all the year/month combinations and their count of appointments that are published in this Timetable var inMemoryTimetableArchives = new Dictionary<DateTime, int>(appointments.Count()); foreach (var appointment in appointments) { if (!appointment.Has<CommonPart>()) continue; var commonPart = appointment.As<CommonPart>(); var key = new DateTime(commonPart.PublishedUtc.Value.Year, commonPart.PublishedUtc.Value.Month, 1); if (inMemoryTimetableArchives.ContainsKey(key)) inMemoryTimetableArchives[key]++; else inMemoryTimetableArchives[key] = 1; } // create the new Timetable archive records based on the in memory values foreach (KeyValuePair<DateTime, int> item in inMemoryTimetableArchives) { TimetableArchiveRepository.Create(new TimetablePartArchiveRecord {TimetablePart = TimetableAppointmentPart.TimetablePart.Record, Year = item.Key.Year, Month = item.Key.Month, AppointmentCount = item.Value}); } }
private static void RecalculateBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, IBlogPostService blogPostService, BlogPostPart blogPostPart) { blogArchiveRepository.Flush(); // remove all current blog archive records var blogArchiveRecords = from bar in blogArchiveRepository.Table where bar.BlogPart == blogPostPart.BlogPart.Record select bar; blogArchiveRecords.ToList().ForEach(blogArchiveRepository.Delete); // get all blog posts for the current blog var posts = blogPostService.Get(blogPostPart.BlogPart, VersionOptions.Published); // create a dictionary of all the year/month combinations and their count of posts that are published in this blog var inMemoryBlogArchives = new Dictionary<DateTime, int>(); foreach (var post in posts) { if (!post.Has<CommonPart>()) continue; var commonPart = post.As<CommonPart>(); var key = new DateTime(commonPart.CreatedUtc.Value.Year, commonPart.CreatedUtc.Value.Month, 1); if (inMemoryBlogArchives.ContainsKey(key)) inMemoryBlogArchives[key]++; else inMemoryBlogArchives[key] = 1; } // create the new blog archive records based on the in memory values foreach (KeyValuePair<DateTime, int> item in inMemoryBlogArchives) { blogArchiveRepository.Create(new BlogPartArchiveRecord {BlogPart = blogPostPart.BlogPart.Record, Year = item.Key.Year, Month = item.Key.Month, PostCount = item.Value}); } }
public HasTagsHandler(IRepository<Tag> tagsRepository, IRepository<TagsContentItems> tagsContentItemsRepository) { OnLoading<HasTags>((context, tags) => { // provide names of all tags on demand tags._allTags.Loader(list => tagsRepository.Table.ToList()); // populate list of attached tags on demand tags._currentTags.Loader(list => { var tagsContentItems = tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id); foreach (var tagContentItem in tagsContentItems) { var tag = tagsRepository.Get(tagContentItem.TagId); list.Add(tag); } return list; }); }); OnRemoved<HasTags>((context, ht) => { tagsContentItemsRepository.Flush(); HasTags tags = context.ContentItem.As<HasTags>(); foreach (var tag in tags.CurrentTags) { if (!tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id).Any()) { tagsRepository.Delete(tag); } } }); }
private void RecalculateBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, BlogPostPart blogPostPart) { blogArchiveRepository.Flush(); var commonPart = blogPostPart.As<CommonPart>(); if(commonPart == null || !commonPart.CreatedUtc.HasValue) return; // get the time zone for the current request var timeZone = _workContextAccessor.GetContext().CurrentTimeZone; var previousCreatedUtc = _previousCreatedUtc.ContainsKey(blogPostPart) ? _previousCreatedUtc[blogPostPart] : DateTime.MinValue; previousCreatedUtc = TimeZoneInfo.ConvertTimeFromUtc(previousCreatedUtc, timeZone); var previousMonth = previousCreatedUtc.Month; var previousYear = previousCreatedUtc.Year; var newCreatedUtc = commonPart.CreatedUtc; newCreatedUtc = newCreatedUtc.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(newCreatedUtc.Value, timeZone) : newCreatedUtc; var newMonth = newCreatedUtc.HasValue ? newCreatedUtc.Value.Month : 0; var newYear = newCreatedUtc.HasValue ? newCreatedUtc.Value.Year : 0; // if archives are the same there is nothing to do if (previousMonth == newMonth && previousYear == newYear) { return; } // decrement previous archive record var previousArchiveRecord = blogArchiveRepository.Table .Where(x => x.BlogPart == blogPostPart.BlogPart.Record && x.Month == previousMonth && x.Year == previousYear) .FirstOrDefault(); if (previousArchiveRecord != null && previousArchiveRecord.PostCount > 0) { previousArchiveRecord.PostCount--; } // if previous count is now zero, delete the record if (previousArchiveRecord != null && previousArchiveRecord.PostCount == 0) { blogArchiveRepository.Delete(previousArchiveRecord); } // increment new archive record var newArchiveRecord = blogArchiveRepository.Table .Where(x => x.BlogPart == blogPostPart.BlogPart.Record && x.Month == newMonth && x.Year == newYear) .FirstOrDefault(); // if record can't be found create it if (newArchiveRecord == null) { newArchiveRecord = new BlogPartArchiveRecord { BlogPart = blogPostPart.BlogPart.Record, Year = newYear, Month = newMonth, PostCount = 0 }; blogArchiveRepository.Create(newArchiveRecord); } newArchiveRecord.PostCount++; }
private void ReduceBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, BlogPostPart blogPostPart) { blogArchiveRepository.Flush(); var commonPart = blogPostPart.As<CommonPart>(); if (commonPart == null || !commonPart.CreatedUtc.HasValue) return; var timeZone = _workContextAccessor.GetContext().CurrentTimeZone; var datetime = TimeZoneInfo.ConvertTimeFromUtc(commonPart.CreatedUtc.Value, timeZone); var previousArchiveRecord = blogArchiveRepository.Table .FirstOrDefault(x => x.BlogPart == blogPostPart.BlogPart.Record && x.Month == datetime.Month && x.Year == datetime.Year); if(previousArchiveRecord == null) return; if (previousArchiveRecord.PostCount > 0) previousArchiveRecord.PostCount--; else blogArchiveRepository.Delete(previousArchiveRecord); }
private static void RecalculateBlogArchive(IRepository<BlogArchiveRecord> blogArchiveRepository, IRepository<CommonRecord> commonRepository, BlogPost blogPost) { blogArchiveRepository.Flush(); //INFO: (erikpo) Remove all current blog archive records var blogArchiveRecords = from bar in blogArchiveRepository.Table where bar.Blog == blogPost.Blog.Record select bar; blogArchiveRecords.ToList().ForEach(blogArchiveRepository.Delete); //INFO: (erikpo) Get all blog posts for the current blog var postsQuery = from bpr in commonRepository.Table where bpr.ContentItemRecord.ContentType.Name == BlogPostDriver.ContentType.Name && bpr.Container.Id == blogPost.Blog.Record.Id orderby bpr.PublishedUtc select bpr; //INFO: (erikpo) Create a dictionary of all the year/month combinations and their count of posts that are published in this blog var inMemoryBlogArchives = new Dictionary<DateTime, int>(postsQuery.Count()); foreach (var post in postsQuery) { if (!post.PublishedUtc.HasValue) continue; var key = new DateTime(post.PublishedUtc.Value.Year, post.PublishedUtc.Value.Month, 1); if (inMemoryBlogArchives.ContainsKey(key)) inMemoryBlogArchives[key]++; else inMemoryBlogArchives[key] = 1; } //INFO: (erikpo) Create the new blog archive records based on the in memory values foreach (KeyValuePair<DateTime, int> item in inMemoryBlogArchives) { blogArchiveRepository.Create(new BlogArchiveRecord {Blog = blogPost.Blog.Record, Year = item.Key.Year, Month = item.Key.Month, PostCount = item.Value}); } }
private static void CreateCustomersWithAccounts(IGenerationSession session,IRepository repository, Role[] roles) { var customers = session. List<Customer>(CUSTOMERS_COUNT).Get(); for (int i = 0; i < customers.Count; i++) { customers[i].Identification = "00000000" + i; customers[i].PasswordSalt = GenerationUtils.RandomString(5); customers[i].Password = SHA256HashProvider.Instance.Hash("Test" + customers[i].PasswordSalt); repository.Save(customers[i]); AddAccountsAndOperations(customers[i], roles, repository, session); //create some bussiness partners for each customer session.List<BusinessPartner>(5) .Impose(x => x.Customer, customers[i]) .Get().ForEach(x => repository.Save(x)); } repository.Flush(); }
private static Role[] CreateAndSaveRoles(IRepository repository) { Role[] roles = new Role[4]; roles[0] = new Role { Name = "Owner", Permission = Permission.Modify | Permission.Read | Permission.Write | Permission.Transfer }; roles[1] = new Role { Name = "Advisor", Permission = Permission.Modify | Permission.Read | Permission.Write | Permission.Transfer }; roles[2] = new Role { Name = "OperationTagger", Permission = Permission.Read | Permission.TagOperations }; roles[3] = new Role { Name = "Minor", Permission = Permission.Read }; roles.ForEach(x => Repository.Save(x)); repository.Flush(); repository.Clear(); return roles; }
private static void CreateAndSaveOAuthConsumers(IRepository repository) { List<AuthConsumer> authConsumers = new List<AuthConsumer>(); authConsumers.Add(new AuthConsumer { Name = "Account Analysis Solution", ConsumerKey = "key1", Secret = "secret1", Description = "This application allows you to perform analytics on your accounts data." }); authConsumers.Add(new AuthConsumer { Name = "Cool PFM application", ConsumerKey = "key2", Secret = "secret2", Description = "Applications which allows to perform advanced analytics, budget management and predictions" }); authConsumers.ForEach((x) => repository.Save(x)); repository.Flush(); }
private static void AddAccountsAndOperations(Customer customer, Role[] roles, IRepository repository, IGenerationSession session) { //get the transaction data from csv file using (var reader = new StreamReader(@"Data\transactions.csv")) { _categorizedTransactions = CSVProcessing.GetCategorizedTransactionsCreateAndStoreTags(reader, repository, _tagsBag); } Account account = session.Single<Account>().Get(); account.Name = "Savings account"; account.RelatedCustomers.Add(customer, roles[0]); account.Iban = GenerationUtils.GenerateIban(account.Number, "12345", "12345", "FR"); account.Currency = "EUR"; Account account2 = session.Single<Account>().Get(); account2.Name = "Checking account"; account2.RelatedCustomers.Add(customer, roles[1]); account2.Currency = "EUR"; customer.RelatedAccounts.Add(account, roles[0]); customer.RelatedAccounts.Add(account2, roles[1]); repository.Save(account); repository.Save(account2); repository.Save(customer); repository.Flush(); //Get random transactions from the list Random rnd = new Random(); var randomTransactions = _categorizedTransactions.Where(x => x.Tag.Name != "Not set").OrderBy(x => rnd.Next()); //add the first half to the first account SelectForAccount(repository, account, rnd, randomTransactions); SelectForAccount(repository, account2, rnd, randomTransactions); //IList<Operation> operations = session.List<Operation>(20) // .Impose(x => x.TransactionCode, Guid.NewGuid().ToString()) // .Impose(x => x.Currency, "EUR") // .Impose(x=>x.Tag,EmptyTag) // .First(10) // .Impose(x => x.Account, account) // .Next(10) // .Impose(x => x.Account, account2) // .All() // .Get(); //operations.ForEach(x => repository.Save(x)); repository.Flush(); var paymentEvents = session.List<PaymentEvent>(20) .First(10) .Impose(x => x.Account, account) .Impose(x=>x.Customer,customer) .Next(10) .Impose(x => x.Account, account2) .Impose(x=>x.Customer, customer) .All() .Get(); paymentEvents.ForEach(x => repository.Save(x)); repository.Flush(); }
private static void AddAccountsAndOperations(Customer customer, Role[] roles, IRepository repository, IGenerationSession session) { //get the transaction data from csv file using (var reader = new StreamReader(@"Data\transactions.csv")) { _categorizedTransactions = CSVProcessing.GetCategorizedTransactionsCreateAndStoreTags(reader, repository, _tagsBag); } Account account = session.Single <Account>().Get(); account.Name = "Savings account"; account.RelatedCustomers.Add(customer, roles[0]); account.Iban = GenerationUtils.GenerateIban(account.Number, "12345", "12345", "FR"); account.Currency = "EUR"; Account account2 = session.Single <Account>().Get(); account2.Name = "Checking account"; account2.RelatedCustomers.Add(customer, roles[1]); account2.Currency = "EUR"; customer.RelatedAccounts.Add(account, roles[0]); customer.RelatedAccounts.Add(account2, roles[1]); repository.Save(account); repository.Save(account2); repository.Save(customer); repository.Flush(); //Get random transactions from the list Random rnd = new Random(); var randomTransactions = _categorizedTransactions.Where(x => x.Tag.Name != "Not set").OrderBy(x => rnd.Next()); //add the first half to the first account SelectForAccount(repository, account, rnd, randomTransactions); SelectForAccount(repository, account2, rnd, randomTransactions); //IList<Operation> operations = session.List<Operation>(20) // .Impose(x => x.TransactionCode, Guid.NewGuid().ToString()) // .Impose(x => x.Currency, "EUR") // .Impose(x=>x.Tag,EmptyTag) // .First(10) // .Impose(x => x.Account, account) // .Next(10) // .Impose(x => x.Account, account2) // .All() // .Get(); //operations.ForEach(x => repository.Save(x)); repository.Flush(); var paymentEvents = session.List <PaymentEvent>(20) .First(10) .Impose(x => x.Account, account) .Impose(x => x.Customer, customer) .Next(10) .Impose(x => x.Account, account2) .Impose(x => x.Customer, customer) .All() .Get(); paymentEvents.ForEach(x => repository.Save(x)); repository.Flush(); }
public void InsertLocations() { //------------------------------------------- // LOCATION REFERENCE TABLES //------------------------------------------- if (_repository.CountAll <City>() == 0) { //Create Provinces Province provinceNord = new Province(); provinceNord.Label = "Province Nord"; provinceNord.AddCity(new City { LabelUrlPart = "Poya-Nord", Label = "Poya Nord" }); provinceNord.AddCity(new City { LabelUrlPart = "Pouembout", Label = "Pouembout" }); provinceNord.AddCity(new City { LabelUrlPart = "Kone", Label = "Koné" }); provinceNord.AddCity(new City { LabelUrlPart = "Voh", Label = "Voh" }); provinceNord.AddCity(new City { LabelUrlPart = "Kaala-Gomen", Label = "Kaala-Gomen" }); provinceNord.AddCity(new City { LabelUrlPart = "Koumac", Label = "Koumac" }); provinceNord.AddCity(new City { LabelUrlPart = "Poum", Label = "Poum" }); provinceNord.AddCity(new City { LabelUrlPart = "Iles-Belep", Label = "Iles Belep" }); provinceNord.AddCity(new City { LabelUrlPart = "Ouegoa", Label = "Ouégoa" }); provinceNord.AddCity(new City { LabelUrlPart = "Pouebo", Label = "Pouébo" }); provinceNord.AddCity(new City { LabelUrlPart = "Hienghene", Label = "Hienghène" }); provinceNord.AddCity(new City { LabelUrlPart = "Touho", Label = "Touho" }); provinceNord.AddCity(new City { LabelUrlPart = "Poindimie", Label = "Poindimié" }); provinceNord.AddCity(new City { LabelUrlPart = "Ponerihouen", Label = "Ponérihouen" }); provinceNord.AddCity(new City { LabelUrlPart = "Houailou", Label = "Houaïlou" }); provinceNord.AddCity(new City { LabelUrlPart = "Kouaoua", Label = "Kouaoua" }); provinceNord.AddCity(new City { LabelUrlPart = "Canala", Label = "Canala" }); _repository.Save(provinceNord); Province provinceSud = new Province(); provinceSud.Label = "Province Sud"; City noumea = new City(); noumea.Label = "Nouméa"; noumea.LabelUrlPart = "Noumea"; noumea.AddDistrict(new District { Label = "Centre-Ville" }); noumea.AddDistrict(new District { Label = "Nouville" }); noumea.AddDistrict(new District { Label = "Quartier Latin" }); noumea.AddDistrict(new District { Label = "Vallée du Génie" }); noumea.AddDistrict(new District { Label = "Artillerie" }); noumea.AddDistrict(new District { Label = "Orphelinat" }); noumea.AddDistrict(new District { Label = "Baie des Citrons" }); noumea.AddDistrict(new District { Label = "Anse Vata" }); noumea.AddDistrict(new District { Label = "Val Plaisance" }); noumea.AddDistrict(new District { Label = "N'Géa" }); noumea.AddDistrict(new District { Label = "Receiving" }); noumea.AddDistrict(new District { Label = "Motor Pool" }); noumea.AddDistrict(new District { Label = "Trianon" }); noumea.AddDistrict(new District { Label = "Riviere-Salée" }); noumea.AddDistrict(new District { Label = "Ducos" }); noumea.AddDistrict(new District { Label = "Magenta" }); noumea.AddDistrict(new District { Label = "Haut-Magenta" }); noumea.AddDistrict(new District { Label = "Aérodrome" }); noumea.AddDistrict(new District { Label = "PK4" }); noumea.AddDistrict(new District { Label = "PK6" }); noumea.AddDistrict(new District { Label = "PK7" }); noumea.AddDistrict(new District { Label = "Tina" }); noumea.AddDistrict(new District { Label = "Normandie" }); noumea.AddDistrict(new District { Label = "Vallée des Colons" }); noumea.AddDistrict(new District { Label = "Faubourg Blanchot" }); noumea.AddDistrict(new District { Label = "Montravel" }); noumea.AddDistrict(new District { Label = "Montagne Coupée" }); noumea.AddDistrict(new District { Label = "Vallée du Tir" }); noumea.AddDistrict(new District { Label = "Doniambo" }); noumea.AddDistrict(new District { Label = "Ouémo" }); noumea.AddDistrict(new District { Label = "Portes de Fer" }); provinceSud.AddCity(noumea); _repository.Save(noumea); City dumbea = new City(); dumbea.Label = "Dumbéa"; dumbea.LabelUrlPart = "Dumbea"; dumbea.AddDistrict(new District { Label = "Auteuil" }); dumbea.AddDistrict(new District { Label = "Centre" }); dumbea.AddDistrict(new District { Label = "Dumbéa sur Mer" }); dumbea.AddDistrict(new District { Label = "Koghi" }); dumbea.AddDistrict(new District { Label = "Koutio" }); dumbea.AddDistrict(new District { Label = "Nakutakoin" }); dumbea.AddDistrict(new District { Label = "Plaine de Koé" }); dumbea.AddDistrict(new District { Label = "Pointe à la Dorade" }); dumbea.AddDistrict(new District { Label = "ZAC Panda" }); provinceSud.AddCity(dumbea); _repository.Save(dumbea); City montDor = new City(); montDor.Label = "Mont-Dore"; montDor.LabelUrlPart = "Mont-Dore"; montDor.AddDistrict(new District { Label = "Boulari" }); montDor.AddDistrict(new District { Label = "La Conception" }); montDor.AddDistrict(new District { Label = "La Coulée" }); montDor.AddDistrict(new District { Label = "Mont-Dore Sud" }); montDor.AddDistrict(new District { Label = "Plum" }); montDor.AddDistrict(new District { Label = "Pont des Francais" }); montDor.AddDistrict(new District { Label = "Robinson" }); montDor.AddDistrict(new District { Label = "Saint-Louis" }); montDor.AddDistrict(new District { Label = "Saint-Michel" }); montDor.AddDistrict(new District { Label = "Vallon-Dore" }); montDor.AddDistrict(new District { Label = "Yahoué" }); provinceSud.AddCity(montDor); _repository.Save(montDor); City paita = new City(); paita.Label = "Païta"; paita.LabelUrlPart = "Paita"; paita.AddDistrict(new District { Label = "Val Boisé" }); paita.AddDistrict(new District { Label = "Tontouta" }); paita.AddDistrict(new District { Label = "Tamoa" }); paita.AddDistrict(new District { Label = "Savannah" }); paita.AddDistrict(new District { Label = "Centre" }); paita.AddDistrict(new District { Label = "Naia" }); paita.AddDistrict(new District { Label = "Mont Mou" }); paita.AddDistrict(new District { Label = "Beauvallon" }); provinceSud.AddCity(paita); _repository.Save(paita); provinceSud.AddCity(new City { LabelUrlPart = "Thio", Label = "Thio" }); provinceSud.AddCity(new City { LabelUrlPart = "Yate", Label = "Yaté" }); provinceSud.AddCity(new City { LabelUrlPart = "Ile-des-Pins", Label = "Ile des Pins" }); provinceSud.AddCity(new City { LabelUrlPart = "Boulouparis", Label = "Boulouparis" }); provinceSud.AddCity(new City { LabelUrlPart = "La-Foa", Label = "La Foa" }); provinceSud.AddCity(new City { LabelUrlPart = "Sarramea", Label = "Sarraméa" }); provinceSud.AddCity(new City { LabelUrlPart = "Farino", Label = "Farino" }); provinceSud.AddCity(new City { LabelUrlPart = "Moindou", Label = "Moindou" }); provinceSud.AddCity(new City { LabelUrlPart = "Bourail", Label = "Bourail" }); provinceSud.AddCity(new City { LabelUrlPart = "Poya-Sud", Label = "Poya Sud" }); _repository.Save(provinceSud); Province ilesLoyaute = new Province(); ilesLoyaute.Label = "Iles Loyauté"; ilesLoyaute.AddCity(new City { LabelUrlPart = "Ouvea", Label = "Ouvéa" }); ilesLoyaute.AddCity(new City { LabelUrlPart = "Lifou", Label = "Lifou" }); ilesLoyaute.AddCity(new City { LabelUrlPart = "Mare", Label = "Maré" }); _repository.Save(ilesLoyaute); _repository.Flush(); } }