本文整理汇总了C#中IRepository.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# IRepository.Flush方法的具体用法?C# IRepository.Flush怎么用?C# IRepository.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRepository
的用法示例。
在下文中一共展示了IRepository.Flush方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RecalculateTimetableArchive
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});
}
}
示例2: RecalculateBlogArchive
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});
}
}
示例3: HasTagsHandler
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);
}
}
});
}
示例4: RecalculateBlogArchive
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++;
}
示例5: ReduceBlogArchive
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);
}
示例6: RecalculateBlogArchive
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});
}
}
示例7: CreateCustomersWithAccounts
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();
}
示例8: CreateAndSaveRoles
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;
}
示例9: CreateAndSaveOAuthConsumers
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();
}
示例10: AddAccountsAndOperations
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();
}