本文整理汇总了C#中IDocumentSession类的典型用法代码示例。如果您正苦于以下问题:C# IDocumentSession类的具体用法?C# IDocumentSession怎么用?C# IDocumentSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IDocumentSession类属于命名空间,在下文中一共展示了IDocumentSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddUser
public void AddUser(User user, IDocumentSession session)
{
if (user == null) throw new ArgumentNullException("user");
if (session == null) throw new ArgumentNullException("session");
try
{
session.Advanced.UseOptimisticConcurrency = true;
session.Store(user);
var facebookId = new FacebookId
{
Id = FacebookId.MakeKey(user.FacebookId),
UserId = user.Id
};
session.Store(facebookId);
session.SaveChanges();
}
finally
{
session.Advanced.UseOptimisticConcurrency = false;
}
}
示例2: PCNarration
public static PostHandlerOutput[] PCNarration(
IDocumentSession documentSession,
IMember sender,
IRoom room,
string source)
{
documentSession.Ensure("documentSession");
sender.Ensure("sender");
room.Ensure("room");
source.Ensure("source");
source = source.Trim();
if (source.StartsWith("/", StringComparison.OrdinalIgnoreCase))
return null;
if (!sender.IsRoomPlayer(room))
return null;
var player = room.Players.SingleOrDefault(x => x.MemberId == sender.Id);
if (player == null)
return null;
var text = string.Concat(
player.CharacterName,
": ",
source);
documentSession.CreatePost(room.Id, sender.Id, null, source, "pc-narration", text);
return PostHandlerOutput.Empty;
}
示例3: ScanRobotsModule
public ScanRobotsModule(IDocumentSession documentSession)
{
Get["/scanRobots/"] = parameters =>
{
var inputModel = this.Bind<CreateScanRobotsInputModule>();
var robotsScanResult =
documentSession.Advanced.LuceneQuery<RobotPosition>("RobotPositions/ByNameAndLocation")
.WhereEquals("Online", true)
.WhereGreaterThan("LastUpdate", DateTime.Now.AddMinutes(-1))
.WithinRadiusOf(radius: 10, latitude: inputModel.Latitude, longitude: inputModel.Longitude)
.ToList();
return Response.AsJson(robotsScanResult.Where(r => r.RobotName != inputModel.RobotName).ToArray());
};
Get["/scanAllRobots/"] = parameters =>
{
var robotsScanResult =
documentSession.Query<RobotPosition>().Customize(x => x.WaitForNonStaleResultsAsOfNow()).Where(
r => r.Online && r.LastUpdate > DateTime.Now.AddMinutes(-1)).ToList();
var response = Response.AsJson(robotsScanResult.ToArray());
response.Headers.Add("Access-Control-Allow-Origin", "*");
return response;
};
}
示例4: WelcomeModule
public WelcomeModule(IDocumentSession session)
: base("Welcome")
{
Get["/"] = p => View["Welcome"];
Post["/"] = p =>
{
var user = this.Bind<User>("Password", "Salt", "Claims");
user.Claims = new List<string> {"admin"};
NSembleUserAuthentication.SetUserPassword(user, Request.Form.Password);
session.Store(user, "users/" + user.Email);
session.Store(new Dictionary<string, AreaConfigs>
{
//{"/blog", new AreaConfigs { AreaName = "MyBlog", ModuleName = "Blog" }},
//{"/content", new AreaConfigs { AreaName = "MyContent", ModuleName = "ContentPages" }},
{"/auth", new AreaConfigs { AreaName = "Auth", ModuleName = "Membership" }}
}, Constants.AreasDocumentName);
session.SaveChanges();
// Refresh the Areas configs
AreasResolver.Instance.LoadFromStore(session);
return Response.AsRedirect("/");
};
}
示例5: EntryToEntryViewModelMapper
public EntryToEntryViewModelMapper(
IDocumentSession session,
UrlHelper urlHelper)
{
this.session = session;
this.urlHelper = urlHelper;
}
示例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: DeleteMember
static object DeleteMember(
NancyContext context,
IDocumentSession documentSession,
string alias)
{
if (context == null) throw new ArgumentNullException("context");
if (documentSession == null) throw new ArgumentNullException("documentSession");
if (String.IsNullOrEmpty(alias))
return 404;
if (!context.IsSignedUp())
return 403;
var memberToDelete = documentSession.GetMemberByAlias(alias);
if (memberToDelete == null)
return 404;
var currentMember = context.GetCurrentMember(documentSession);
Debug.Assert(currentMember != null, "`requireSignedUp()` should ensure the current member is not null.");
if (!memberToDelete.Alias.Equals(currentMember.Alias, StringComparison.OrdinalIgnoreCase))
return 403;
documentSession.DeleteMember(memberToDelete.Id);
context.SetAlert("Your membership was deleted.", type: AlertType.Success);
context.SignOutOfTwitter();
return context.Redirect(Paths.Home());
}
示例8: CommandsToPickUpBehaviour
public CommandsToPickUpBehaviour(IFubuRequest request,IOutputWriter writer,IDocumentSession session)
: base(PartialBehavior.Ignored)
{
this.request = request;
this.writer = writer;
this.session = session;
}
示例9: StubDocumentStoreWithSession
public static IDocumentStore StubDocumentStoreWithSession(IDocumentSession session)
{
var store = MockRepository.GenerateStub<IDocumentStore>();
store.Stub(x => x.OpenSession()).Return(session);
return store;
}
示例10: RecordPhonecall
public RecordPhonecall(IPayAsYouGoAccountRepository payAsYouGoAccountRepository,
IDocumentSession unitOfWork, IClock clock)
{
_payAsYouGoAccountRepository = payAsYouGoAccountRepository;
_unitOfWork = unitOfWork;
_clock = clock;
}
示例11: RavenFileRepository
public RavenFileRepository(IDocumentSession documentSession, IFileStorage fileStorage, IUserIdentity userIdentity, ILog logger)
{
_documentSession = DIHelper.VerifyParameter(documentSession);
_fileStorage = DIHelper.VerifyParameter(fileStorage);
_userIdentity = DIHelper.VerifyParameter(userIdentity);
_logger = DIHelper.VerifyParameter(logger);
}
示例12: GMNarration
public static PostHandlerOutput[] GMNarration(
IDocumentSession documentSession,
IMember sender,
IRoom room,
string source)
{
documentSession.Ensure("documentSession");
sender.Ensure("sender");
room.Ensure("room");
source.Ensure("source");
if (!sender.IsRoomOwner(room))
return null;
source = source.Trim();
if (source.StartsWith("/", StringComparison.OrdinalIgnoreCase))
return null;
var text = string.Concat(
"GM: ",
source);
documentSession.CreatePost(room.Id, sender.Id, null, source, "gm-narration", text);
return PostHandlerOutput.Empty;
}
示例13: 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);
}
示例14: Run
public bool? Run(IDocumentSession openSession)
{
Initialize(openSession);
try
{
Execute();
DocumentSession.SaveChanges();
TaskExecutor.StartExecuting();
return true;
}
catch (ConcurrencyException e)
{
OnError(e);
return null;
}
catch (Exception e)
{
OnError(e);
return false;
}
finally
{
TaskExecutor.Discard();
}
}
示例15: DoCommit
private void DoCommit(IDocumentSession session)
{
foreach (IAggregateRoot root in _trackedObjects)
{
Store(session, root);
}
}