本文整理汇总了C#中IDocumentSession.Load方法的典型用法代码示例。如果您正苦于以下问题:C# IDocumentSession.Load方法的具体用法?C# IDocumentSession.Load怎么用?C# IDocumentSession.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocumentSession
的用法示例。
在下文中一共展示了IDocumentSession.Load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContentPagesAdminModule
public ContentPagesAdminModule(IDocumentSession session)
: base("ContentPages")
{
Get["/"] = p =>
{
var list = session.Advanced.LoadStartingWith<ContentPage>(DocumentPrefix + ContentPage.FullContentPageId(string.Empty), null, 0, 25);
return View["List", list.ToArray()];
};
Get["/create/"] = p => View["Edit", new ContentPage {ContentType = DynamicContentType.Markdown}];
Post["/create/"] = p =>
{
var cp = this.Bind<ContentPage>();
var pageId = ContentPage.FullContentPageId(DynamicContentHelpers.TitleToSlug(cp.Title));
var page = session.Load<ContentPage>(pageId);
if (page != null)
{
//ModelState.AddModelError("Id", "Page already exists for the slug you're trying to create it under");
return View["Edit", cp];
}
session.Store(cp, pageId);
return Response.AsRedirect(string.Concat(AreaRoutePrefix.TrimEnd('/'), "/", cp.Slug));
};
Get["/edit/{slug}"] = p =>
{
var cp = session.Load<ContentPage>(DocumentPrefix + ContentPage.FullContentPageId((string) p.slug));
if (cp == null)
return 404;
return View["Edit", cp];
};
Post["/edit/{slug}"] = p =>
{
var input = this.Bind<ContentPage>();
if (input.Id != (string)p.slug)
return "<h1>Error</h1><p>Slugs mismatch</p>";
var cp = session.Load<ContentPage>(DocumentPrefix + ContentPage.FullContentPageId((string)p.slug));
if (cp == null)
return 404;
cp.Content = input.Content;
cp.ContentType = input.ContentType;
cp.Title = input.Title;
cp.LastChanged = DateTimeOffset.Now;
return Response.AsRedirect(string.Concat(AreaRoutePrefix.TrimEnd('/'), "/", cp.Slug));
};
// Post["/delete/{slug}"] = p =>
// {
//
// };
}
示例2: ContactModule
public ContactModule(IDocumentSession ravenSession)
: base("/api/contact")
{
Get["/"] = parameters =>
{
var contacts = ravenSession.Query<Contact>()
.OrderBy(x => x.LastName)
.Take(15)
.ToList();
return Response.AsJson(contacts);
};
Get["/{id}"] = parameters =>
{
string contactId = "contact/" + parameters.id;
var contact = ravenSession.Load<Contact>(contactId);
return Response.AsJson(contact);
};
Post["/"] = parameters =>
{
Contact newContact = this.Bind();
newContact.DateOfDeath = newContact.DateOfDeath == DateTime.MinValue
? null
: newContact.DateOfDeath;
ravenSession.Store(newContact);
return Response.AsJson(newContact);
};
}
示例3: RobotProjectionModule
public RobotProjectionModule(IDocumentSession documentSession)
{
Get["/robot/{name}"] = parameters =>
{
if (string.IsNullOrWhiteSpace(parameters.name))
return HttpStatusCode.BadRequest;
var robotResult = documentSession.Load<Robot>(Robot.GetRobotIdFromName(parameters.name));
if (robotResult == null)
return HttpStatusCode.NotFound;
return Response.AsJson(robotResult as object);
};
Get["/robot/byowner/{email}"] = parameters =>
{
if (string.IsNullOrWhiteSpace(parameters.email))
return HttpStatusCode.BadRequest;
string email = parameters.email;
var robotResult = documentSession.Query<Robot>().FirstOrDefault(x => x.OwnerEMail.Equals(email, StringComparison.CurrentCultureIgnoreCase));
if (robotResult == null)
return HttpStatusCode.NotFound;
return Response.AsJson(robotResult as object);
};
}
示例4: GetUser
public User GetUser(string userId, IDocumentSession session)
{
if (userId == null) throw new ArgumentNullException("userId");
if (session == null) throw new ArgumentNullException("session");
return session.Load<User>(userId);
}
示例5: DinnerModule
public DinnerModule(IDocumentSession documentSession)
{
this.documentSession = documentSession;
const string basePath = "/dinners";
Get[basePath] = Dinners;
Get[basePath + "/page/{pagenumber}"] = Dinners;
Get[basePath + "/{id}"] = parameters =>
{
if (!parameters.id.HasValue && String.IsNullOrWhiteSpace(parameters.id))
{
return 404;
}
Dinner dinner = documentSession.Load<Dinner>((int)parameters.id);
if (dinner == null)
{
return 404;
}
base.Page.Title = dinner.Title;
base.Model.Dinner = dinner;
return View["Dinners/Details", base.Model];
};
}
示例6: ValidateUser
public static string ValidateUser(IDocumentSession ravenSession, string username, string password)
{
// try to get a user from the database that matches the given username and password
var userRecord = ravenSession.Load<User>("users/" + username);
if (userRecord == null)
{
return null;
}
// verify password
var hashedPassword = GenerateSaltedHash(password, userRecord.Salt);
if (!CompareByteArrays(hashedPassword, userRecord.Password))
return null;
// cleanup expired or unusesd tokens
foreach (var token in ravenSession.Query<ApiKeyToken>().Where(x => x.UserId == userRecord.Id))
{
if (DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(7)) > token.LastActivity)
ravenSession.Delete(token);
}
// now that the user is validated, create an api key that can be used for subsequent requests
var apiKey = Guid.NewGuid().ToString();
ravenSession.Store(new ApiKeyToken { UserId = userRecord.Id, SessionStarted = DateTimeOffset.UtcNow, LastActivity = DateTimeOffset.UtcNow }, GetApiKeyDocumentId(apiKey));
ravenSession.SaveChanges();
return apiKey;
}
示例7: GetSubscriptions
static IEnumerable<Subscription> GetSubscriptions(IEnumerable<MessageType> messageTypes, IDocumentSession session)
{
var ids = messageTypes
.Select(Subscription.FormatId);
return session.Load<Subscription>(ids).Where(s => s != null);
}
示例8: ContentPagesModule
public ContentPagesModule(IDocumentSession session)
: base("ContentPages")
{
Get["/{slug*}"] = p =>
{
var slug = (string)p.slug;
if (string.IsNullOrWhiteSpace(slug))
slug = HomepageSlug;
// For fastest loading, we define the content page ID to be the slug. Therefore, slugs have to be < 50 chars, probably
// much shorter for readability.
var cp = session.Load<ContentPage>(DocumentPrefix + ContentPage.FullContentPageId(slug));
if (cp == null)
return "<p>The requested content page was not found</p>"; // we will return a 404 instead once the system stabilizes...
Model.ContentPage = cp;
((PageModel) Model.Page).Title = cp.Title;
return View["Read", Model];
};
Get["/error"] = o =>
{
throw new NotSupportedException("foo");
};
}
示例9: UpdateExistingMessage
void UpdateExistingMessage(IDocumentSession session, string id, TransportMessage message)
{
var failedMessage = session.Load<Message>(id);
var timeOfFailure = DateTimeExtensions.ToUtcDateTime(message.Headers["NServiceBus.TimeOfFailure"]);
if (failedMessage.FailureDetails.TimeOfFailure == timeOfFailure)
{
return;
}
if (failedMessage.Status == MessageStatus.Successful && timeOfFailure > failedMessage.ProcessedAt)
{
throw new InvalidOperationException("A message can't first be processed successfully and then fail, Id: " + failedMessage.Id);
}
if (failedMessage.Status == MessageStatus.Successful)
{
failedMessage.FailureDetails = new FailureDetails(message);
}
else
{
failedMessage.Status = MessageStatus.RepeatedFailure;
failedMessage.FailureDetails.RegisterException(message);
}
session.SaveChanges();
}
示例10: TemplatesModule
public TemplatesModule(IDocumentSession session, IViewLocator viewLocator)
: base("Templates")
{
Get["/"] = p =>
{
var templates = session.Advanced.LoadStartingWith<ViewTemplate>("NSemble/Views/");
return View["List", templates];
};
Get["/new/"] = p => View["Edit", new ViewTemplate {}];
Get[@"/edit/{viewName*}"] = p =>
{
var viewName = (string) p.viewName;
if (!viewName.StartsWith(Constants.RavenViewDocumentPrefix, StringComparison.InvariantCultureIgnoreCase))
viewName = Constants.RavenViewDocumentPrefix + viewName;
var template = session.Load<ViewTemplate>(viewName);
// Even if we don't have it stored in the DB, it might still exist as a resource. Try loading it from Nancy.
if (template == null)
{
var vlr = viewLocator.LocateView(viewName.Substring(Constants.RavenViewDocumentPrefix.Length), Context);
if (vlr == null)
return 404;
template = new ViewTemplate
{
Location = vlr.Location,
Name = vlr.Name,
Extension = vlr.Extension,
Contents = vlr.Contents.Invoke().ReadToEnd(),
};
}
return View["Edit", template];
};
Post[@"/edit/{viewName*}"] = p =>
{
var template = this.Bind<ViewTemplate>();
var viewName = (string) p.viewName;
if (!viewName.StartsWith(Constants.RavenViewDocumentPrefix, StringComparison.InvariantCultureIgnoreCase))
viewName = Constants.RavenViewDocumentPrefix + viewName;
session.Store(template, string.Concat(Constants.RavenViewDocumentPrefix, template.Location, "/", template.Name, ".", template.Extension));
session.SaveChanges();
return "Success";
};
Post["/new"] = p =>
{
var template = this.Bind<ViewTemplate>();
session.Store(template, string.Concat(Constants.RavenViewDocumentPrefix, template.Location, "/", template.Name, ".", template.Extension));
return Response.AsRedirect("/");
};
}
示例11: Execute
public void Execute(IDocumentSession session, Action reply)
{
var program = session.Load<Program>(_id);
var version = program.Versions.SingleOrDefault(x => x.Version == _version);
if (version != null)
program.Versions.Remove(version);
reply();
}
示例12: LoadFromStore
public void LoadFromStore(IDocumentSession session)
{
var d = session.Load<IDictionary<string, AreaConfigs>>(AreasDocumentName);
AreasByRoute.Clear();
foreach (var areaConfig in d)
{
RegisterArea(areaConfig.Key, areaConfig.Value);
}
}
示例13: GetChallengeName
public static string GetChallengeName(IDocumentSession session, string challengeId)
{
var challenge = session.Load<Challenge>(challengeId);
if (challenge != null)
{
return challenge.Text;
}
return string.Empty;
}
示例14: SubmitToRedditStrategy
public SubmitToRedditStrategy(IDocumentSession session)
{
_session = session;
var blogConfig = _session.Load<BlogConfig>(BlogConfig.Key);
_credentials = RedditHelper.GetCredentials(blogConfig);
_subredditNames = RedditHelper.ParseSubreddits(blogConfig);
InitializeRedditService();
}
示例15: Execute
public void Execute(IDocumentSession session, Action reply)
{
var program = session.Load<Program>(_id);
program.Name = _name;
program.Notes = _notes;
reply();
}