本文整理汇总了C#中IDocumentSession.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# IDocumentSession.Delete方法的具体用法?C# IDocumentSession.Delete怎么用?C# IDocumentSession.Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocumentSession
的用法示例。
在下文中一共展示了IDocumentSession.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: delete_documents
// SAMPLE: deletes
public void delete_documents(IDocumentSession session)
{
var user = new User();
session.Delete(user);
session.SaveChanges();
// OR
session.Delete(user.Id);
session.SaveChanges();
}
示例2: 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;
}
示例3: Delete
public static void Delete(this Project project, IDocumentSession session)
{
session.Query<Activity>()
.Where(a => a.Project == project.Id).ToList().ForEach(a => a.Delete(session));
session.Query<Discussion>()
.Where(d => d.Entity == project.Id).ToList().ForEach(d => d.Delete(session));
session.Delete(project);
}
示例4: DeleteProcessAndChildren
/// <summary>
/// delete an HRProcess and any assocoiated child tasks and meetings
/// </summary>
/// <param name="process"></param>
/// <param name="session"></param>
public static void DeleteProcessAndChildren(HRProcess process, IDocumentSession session)
{
var subject = session.Load<User>(process.Subject.UserId);
subject.CurrentState = string.Empty;
session.Delete(process);
var childtasks = session.Query<Task>().Where(t => t.ParentItemId == process.Id);
foreach (var t in childtasks)
{
session.Delete(t);
}
var childmeetings = session.Query<Meeting>().Where(t => t.ParentItemId == process.Id);
foreach (var t in childmeetings)
{
session.Delete(t);
}
}
示例5: DeleteUser
/// <summary>
/// Deletes the user.
/// </summary>
/// <param name="ravenSession">The raven session.</param>
/// <param name="id">The identifier.</param>
/// <returns>The identifier of the deleted user.</returns>
public string DeleteUser(IDocumentSession ravenSession, string id)
{
var currentDbModel = ravenSession.Load<User>(id);
if (currentDbModel == null)
{
return null;
}
ravenSession.Delete<User>(currentDbModel);
ravenSession.SaveChanges();
return id;
}
示例6: GetUserFromApiKey
public static IUserIdentity GetUserFromApiKey(IDocumentSession ravenSession, string apiKey)
{
if (apiKey == null)
return null;
var activeKey = ravenSession.Include<ApiKeyToken>(x => x.UserId).Load(GetApiKeyDocumentId(apiKey));
if (activeKey == null)
return null;
if (DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(7)) > activeKey.LastActivity)
{
ravenSession.Delete(activeKey);
ravenSession.SaveChanges();
return null;
}
activeKey.LastActivity = DateTimeOffset.Now;
ravenSession.SaveChanges();
return ravenSession.Load<User>(activeKey.UserId);
}
示例7: TodoModule
public TodoModule(IDocumentStore documentStore, IDocumentSession documentSession)
: base("todo")
{
_documentStore = documentStore;
_documentSession = documentSession;
Get["/"] = _ =>
{
return Response.AsJson<List<Todo>>(_documentSession.Query<Todo>().ToList());
};
Post["/"] = _ =>
{
var todo = this.Bind<Todo>();
_documentSession.Store(todo);
return Response.AsJson<Todo>(todo, HttpStatusCode.Created);
};
Put["/"] = _ =>
{
var todo = this.Bind<Todo>();
_documentSession.Store(todo);
return Response.AsJson<Todo>(todo);
};
Delete["/"] = _ =>
{
var todo = this.Bind<Todo>();
todo = _documentSession.Load<Todo>(todo.Id);
_documentSession.Delete<Todo>(todo);
return Response.AsJson<Todo>(todo);
};
}
示例8: HomeModule
public HomeModule(DataUploadHelper dataUploadHelper, IDocumentSession session, DropboxHelper dropboxHelper)
{
_dataUploadHelper = dataUploadHelper;
_session = session;
_dropboxHelper = dropboxHelper;
Get["/"] = x =>
{
TaskExecutor.DropboxHelper = _dropboxHelper;
TaskExecutor.ExecuteTask(new DeleteDataMoreThanDayTask());
return View["index.html"];
};
Post["/fileupload"] = x =>
{
var file = this.Request.Files.FirstOrDefault();
string dataId;
try
{
if (file == null)
{
var str = Request.Form["data"].Value as string;
dataId = _dataUploadHelper.UploadData(Request.Form["data"].Value as string);
}
else
{
dataId = _dataUploadHelper.UploadData(file.ContentType, file.Value, Path.GetExtension(file.Name));
}
}
catch (FileLoadException)
{
return HttpStatusCode.InsufficientStorage;
}
return dataId;
};
Get["/view/datas/{Id}"] = x =>
{
string id = x.Id.Value;
Data data = _session.Load<Data>("datas/" + id);
if (data == null)
{
return View["expire.html"];
}
data.TimesView--;
if (data.TimesView == 0)
{
if (data.Url != null && data.Url != string.Empty)
{
_dropboxHelper.DeleteFile(data.Url);
}
session.Delete<Data>(data);
return View["expire.html"];
}
if (data.ContentType == "text/plain" && data.Url == null || data.Url == string.Empty)
return View["view", new { Data = data.Text, SessionId = Guid.NewGuid().ToString() }];
var fileBytes = _dropboxHelper.GetFile(data.Url);
var memoryStream = new MemoryStream(fileBytes);
return Response.FromStream(memoryStream, data.ContentType);
};
}
示例9: ProcessBatches
bool ProcessBatches(IDocumentSession session)
{
var nowForwarding = session.Include<RetryBatchNowForwarding, RetryBatch>(r => r.RetryBatchId)
.Load<RetryBatchNowForwarding>(RetryBatchNowForwarding.Id);
if (nowForwarding != null)
{
var forwardingBatch = session.Load<RetryBatch>(nowForwarding.RetryBatchId);
if (forwardingBatch != null)
{
Forward(forwardingBatch, session);
}
session.Delete(nowForwarding);
return true;
}
isRecoveringFromPrematureShutdown = false;
var stagingBatch = session.Query<RetryBatch>()
.Customize(q => q.Include<RetryBatch, FailedMessageRetry>(b => b.FailureRetries))
.FirstOrDefault(b => b.Status == RetryBatchStatus.Staging);
if (stagingBatch != null)
{
if (Stage(stagingBatch, session))
{
session.Store(new RetryBatchNowForwarding { RetryBatchId = stagingBatch.Id }, RetryBatchNowForwarding.Id);
}
return true;
}
return false;
}
示例10: Stage
bool Stage(RetryBatch stagingBatch, IDocumentSession session)
{
var stagingId = Guid.NewGuid().ToString();
var matchingFailures = session.Load<FailedMessageRetry>(stagingBatch.FailureRetries)
.Where(r => r != null && r.RetryBatchId == stagingBatch.Id)
.ToArray();
var messageIds = matchingFailures.Select(x => x.FailedMessageId).ToArray();
if (!messageIds.Any())
{
Log.InfoFormat("Retry batch {0} cancelled as all matching unresolved messages are already marked for retry as part of another batch", stagingBatch.Id);
session.Delete(stagingBatch);
return false;
}
var messages = session.Load<FailedMessage>(messageIds);
foreach (var message in messages)
{
StageMessage(message, stagingId);
}
bus.Publish<MessagesSubmittedForRetry>(m =>
{
m.FailedMessageIds = messages.Select(x => x.UniqueMessageId).ToArray();
m.Context = stagingBatch.Context;
});
stagingBatch.Status = RetryBatchStatus.Forwarding;
stagingBatch.StagingId = stagingId;
stagingBatch.FailureRetries = matchingFailures.Select(x => x.Id).ToArray();
Log.InfoFormat("Retry batch {0} staged {1} messages", stagingBatch.Id, messages.Length);
return true;
}
示例11: DinnerModuleAuth
public DinnerModuleAuth(IDocumentSession documentSession)
: base("/dinners")
{
this.RequiresAuthentication();
Get["/create"] = parameters =>
{
Dinner dinner = new Dinner()
{
EventDate = DateTime.Now.AddDays(7)
};
base.Page.Title = "Host a Nerd Dinner";
base.Model.Dinner = dinner;
return View["Create", base.Model];
};
Post["/create"] = parameters =>
{
var dinner = this.Bind<Dinner>();
var result = this.Validate(dinner);
if (result.IsValid)
{
UserIdentity nerd = (UserIdentity)this.Context.CurrentUser;
dinner.HostedById = nerd.UserName;
dinner.HostedBy = nerd.FriendlyName;
RSVP rsvp = new RSVP();
rsvp.AttendeeNameId = nerd.UserName;
rsvp.AttendeeName = nerd.FriendlyName;
dinner.RSVPs = new List<RSVP>();
dinner.RSVPs.Add(rsvp);
documentSession.Store(dinner);
documentSession.SaveChanges();
return this.Response.AsRedirect("/dinners/" + dinner.DinnerID);
}
else
{
base.Page.Title = "Host a Nerd Dinner";
base.Model.Dinner = dinner;
foreach (var item in result.Errors)
{
foreach (var member in item.MemberNames)
{
base.Page.Errors.Add(new ErrorModel() { Name = member, ErrorMessage = item.GetMessage(member) });
}
}
}
return View["Create", base.Model];
};
Get["/delete/" + Route.AnyIntAtLeastOnce("id")] = parameters =>
{
Dinner dinner = documentSession.Load<Dinner>((int)parameters.id);
if (dinner == null)
{
base.Page.Title = "Nerd Dinner Not Found";
return View["NotFound", base.Model];
}
if (!dinner.IsHostedBy(this.Context.CurrentUser.UserName))
{
base.Page.Title = "You Don't Own This Dinner";
return View["InvalidOwner", base.Model];
}
base.Page.Title = "Delete Confirmation: " + dinner.Title;
base.Model.Dinner = dinner;
return View["Delete", base.Model];
};
Post["/delete/" + Route.AnyIntAtLeastOnce("id")] = parameters =>
{
Dinner dinner = documentSession.Load<Dinner>((int)parameters.id);
if (dinner == null)
{
base.Page.Title = "Nerd Dinner Not Found";
return View["NotFound", base.Model];
}
if (!dinner.IsHostedBy(this.Context.CurrentUser.UserName))
{
base.Page.Title = "You Don't Own This Dinner";
return View["InvalidOwner", base.Model];
}
documentSession.Delete(dinner);
documentSession.SaveChanges();
//.........这里部分代码省略.........
示例12: PurgeSystemLog
private static void PurgeSystemLog(IDocumentSession session)
{
bool done = false;
int batchSize = 100;
int totalDeleted = 0;
while(!done)
{
var list = session.Query<SystemLog>()
//.Customize(i=>i.WaitForNonStaleResultsAsOfNow())
.Take(batchSize);
if(list.Count() < batchSize)
{
done = true;
}
foreach(var item in list)
{
session.Delete(item);
totalDeleted++;
}
session.SaveChanges();
Console.WriteLine(totalDeleted.ToString() + " records deleted");
Debug.WriteLine(totalDeleted.ToString() + " records deleted");
}
}
示例13: Delete
public static void Delete(this Discussion discussion, IDocumentSession session)
{
session.Delete(discussion);
}
示例14: Leave
public void Leave(string roomName, IDocumentSession session = null)
{
//using (var session = store.OpenSession())
var isExternalSession = session == null;
if (session == null)
session = store.OpenSession();
try
{
if (!joinedRooms.Any(r => r.Name.Equals(roomName, StringComparison.InvariantCultureIgnoreCase)))
{
Console.WriteLine("Cannot leave because not joined..");
return;
}
var roomToLeave = session.Load<Room>($"rooms/{roomName}");
if (roomToLeave != null)
{
roomToLeave.Users.Remove($"users/{username}");
if (roomToLeave.Users.Count == 0) //room is empty - no need to keep it
{
var idsToDelete = new List<string>();
using (var stream = session.Advanced.Stream(
session.Query<Message, MessagesByRoomIndex>()))
{
do
{
if(stream.Current != null)
session.Delete(stream.Current.Key);
} while (stream.MoveNext());
}
session.Delete(roomToLeave);
}
}
joinedRooms.RemoveAt(joinedRooms.FindIndex(r => r.Id == roomToLeave.Id));
session.SaveChanges();
Console.WriteLine($"Left room {roomName}");
}
finally
{
if (isExternalSession)
session.Dispose();
}
}
示例15: Forward
void Forward(RetryBatch forwardingBatch, IDocumentSession session)
{
var messageCount = forwardingBatch.FailureRetries.Count;
if (isRecoveringFromPrematureShutdown)
{
returnToSender.Run(IsPartOfStagedBatch(forwardingBatch.StagingId));
}
else if(messageCount > 0)
{
returnToSender.Run(IsPartOfStagedBatch(forwardingBatch.StagingId), messageCount);
}
session.Delete(forwardingBatch);
Log.InfoFormat("Retry batch {0} done", forwardingBatch.Id);
}