本文整理汇总了C#中IJabbrRepository.CommitChanges方法的典型用法代码示例。如果您正苦于以下问题:C# IJabbrRepository.CommitChanges方法的具体用法?C# IJabbrRepository.CommitChanges怎么用?C# IJabbrRepository.CommitChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IJabbrRepository
的用法示例。
在下文中一共展示了IJabbrRepository.CommitChanges方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClearConnectedClients
private static void ClearConnectedClients(IJabbrRepository repository)
{
try
{
repository.RemoveAllClients();
repository.CommitChanges();
}
catch (Exception ex)
{
Elmah.ErrorLog.GetDefault(null).Log(new Error(ex));
}
}
示例2: UpdatePresence
private void UpdatePresence(ILogger logger, IJabbrRepository repo)
{
// Get all connections on this node and update the activity
foreach (var connection in _heartbeat.GetConnections())
{
if (!connection.IsAlive)
{
continue;
}
ChatClient client = repo.GetClientById(connection.ConnectionId);
if (client != null)
{
client.LastActivity = DateTimeOffset.UtcNow;
}
else
{
EnsureClientConnected(logger, repo, connection);
}
}
repo.CommitChanges();
}
示例3: CheckUserStatus
private void CheckUserStatus(ILogger logger, IJabbrRepository repo)
{
var inactiveUsers = new List<ChatUser>();
IQueryable<ChatUser> users = repo.GetOnlineUsers().Where(u =>
SqlFunctions.DateDiff("mi", u.LastActivity, DateTime.UtcNow) > 5);
foreach (var user in users.ToList())
{
user.Status = (int)UserStatus.Inactive;
inactiveUsers.Add(user);
}
if (inactiveUsers.Count > 0)
{
PerformRoomAction(inactiveUsers, async roomGroup =>
{
await _hubContext.Clients.Group(roomGroup.Room.Name).markInactive(roomGroup.Users);
});
repo.CommitChanges();
}
}
示例4: RemoveOfflineUsers
private void RemoveOfflineUsers(ILogger logger, IJabbrRepository repo)
{
var offlineUsers = new List<ChatUser>();
IQueryable<ChatUser> users = repo.GetOnlineUsers();
foreach (var user in users.ToList())
{
if (user.ConnectedClients.Count == 0)
{
logger.Log("{0} has no clients. Marking as offline", user.Name);
// Fix users that are marked as inactive but have no clients
user.Status = (int)UserStatus.Offline;
offlineUsers.Add(user);
}
}
if (offlineUsers.Count > 0)
{
PerformRoomAction(offlineUsers, async roomGroup =>
{
foreach (var user in roomGroup.Users)
{
await _hubContext.Clients.Group(roomGroup.Room.Name).leave(user, roomGroup.Room.Name);
}
});
repo.CommitChanges();
}
}
示例5: EnsureClientConnected
// This is an uber hack to make sure the db is in sync with SignalR
private void EnsureClientConnected(ILogger logger, IJabbrRepository repo, ITrackingConnection connection)
{
var contextField = connection.GetType().GetField("_context",
BindingFlags.NonPublic | BindingFlags.Instance);
if (contextField == null)
{
return;
}
var context = contextField.GetValue(connection) as HostContext;
if (context == null)
{
return;
}
string connectionData = context.Request.QueryString["connectionData"];
if (String.IsNullOrEmpty(connectionData))
{
return;
}
var hubs = JsonConvert.DeserializeObject<HubConnectionData[]>(connectionData);
if (hubs.Length != 1)
{
return;
}
// We only care about the chat hub
if (!hubs[0].Name.Equals("chat", StringComparison.OrdinalIgnoreCase))
{
return;
}
logger.Log("Connection {0} exists but isn't tracked.", connection.ConnectionId);
string userId = context.Request.User.GetUserId();
ChatUser user = repo.GetUserById(userId);
if (user == null)
{
logger.Log("Unable to find user with id {0}", userId);
return;
}
var client = new ChatClient
{
Id = connection.ConnectionId,
User = user,
UserAgent = context.Request.Headers["User-Agent"],
LastActivity = DateTimeOffset.UtcNow,
LastClientActivity = user.LastActivity
};
repo.Add(client);
repo.CommitChanges();
}
示例6: AccountModule
//.........这里部分代码省略.........
var identity = user.Identities.FirstOrDefault(i => i.ProviderName == provider);
if (identity != null)
{
repository.Remove(identity);
this.AddAlertMessage("success", String.Format("Successfully unlinked {0} account.", provider));
return Response.AsRedirect("~/account/#identityProviders");
}
return HttpStatusCode.BadRequest;
};
Post["/newpassword"] = _ =>
{
if (Context.CurrentUser == null)
{
return HttpStatusCode.Forbidden;
}
string password = Request.Form.password;
string confirmPassword = Request.Form.confirmPassword;
ValidatePassword(password, confirmPassword);
ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);
try
{
if (ModelValidationResult.IsValid)
{
membershipService.SetUserPassword(user, password);
repository.CommitChanges();
}
}
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
if (ModelValidationResult.IsValid)
{
this.AddAlertMessage("success", "Successfully added a password.");
return Response.AsRedirect("~/account/#changePassword");
}
return GetProfileView(authService, user);
};
Post["/changepassword"] = _ =>
{
if (Context.CurrentUser == null)
{
return HttpStatusCode.Forbidden;
}
string oldPassword = Request.Form.oldPassword;
string password = Request.Form.password;
string confirmPassword = Request.Form.confirmPassword;
if (String.IsNullOrEmpty(oldPassword))
{
this.AddValidationError("oldPassword", "Old password is required");
}
示例7: ClearConnectedClients
private static void ClearConnectedClients(IJabbrRepository repository)
{
try
{
foreach (var u in repository.Users)
{
if (u.IsAfk)
{
u.Status = (int)UserStatus.Offline;
}
}
repository.RemoveAllClients();
repository.CommitChanges();
}
catch (Exception ex)
{
Elmah.ErrorLog.GetDefault(null).Log(new Error(ex));
}
}
示例8: AccountModule
//.........这里部分代码省略.........
var identity = user.Identities.FirstOrDefault(i => i.ProviderName == provider);
if (identity != null)
{
repository.Remove(identity);
Request.AddAlertMessage("success", String.Format("Successfully unlinked {0} account.", provider));
return Response.AsRedirect("~/account/#identityProviders");
}
return HttpStatusCode.BadRequest;
};
Post["/newpassword"] = _ =>
{
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
string password = Request.Form.password;
string confirmPassword = Request.Form.confirmPassword;
ValidatePassword(password, confirmPassword);
ChatUser user = repository.GetUserById(Principal.GetUserId());
try
{
if (ModelValidationResult.IsValid)
{
membershipService.SetUserPassword(user, password);
repository.CommitChanges();
}
}
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
if (ModelValidationResult.IsValid)
{
Request.AddAlertMessage("success", "Successfully added a password.");
return Response.AsRedirect("~/account/#changePassword");
}
return GetProfileView(authService, user);
};
Post["/changepassword"] = _ =>
{
if (!applicationSettings.AllowUserRegistration)
{
return HttpStatusCode.NotFound;
}
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
string oldPassword = Request.Form.oldPassword;
string password = Request.Form.password;
string confirmPassword = Request.Form.confirmPassword;
示例9: NotificationsModule
public NotificationsModule(IJabbrRepository repository,
IChatService chatService,
IChatNotificationService notificationService)
: base("/notifications")
{
Get["/"] = _ =>
{
if (!IsAuthenticated)
{
return Response.AsRedirect(String.Format("~/account/login?returnUrl={0}", HttpUtility.UrlEncode(Request.Path)));
}
var request = this.Bind<NotificationRequestModel>();
ChatUser user = repository.GetUserById(Principal.GetUserId());
int unreadCount = repository.GetUnreadNotificationsCount(user);
IPagedList<NotificationViewModel> notifications = GetNotifications(repository, user, all: request.All, page: request.Page, roomName: request.Room);
var viewModel = new NotificationsViewModel
{
ShowAll = request.All,
UnreadCount = unreadCount,
Notifications = notifications,
DebugMode = (bool)Context.Items["_debugMode"],
};
return View["index", viewModel];
};
Post["/markasread"] = _ =>
{
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
int notificationId = Request.Form.notificationId;
Notification notification = repository.GetNotificationById(notificationId);
if (notification == null)
{
return HttpStatusCode.NotFound;
}
ChatUser user = repository.GetUserById(Principal.GetUserId());
if (notification.UserKey != user.Key)
{
return HttpStatusCode.Forbidden;
}
notification.Read = true;
repository.CommitChanges();
notificationService.MessageReadStateChanged(user, notification.Message, notification);
UpdateUnreadCountInChat(repository, notificationService, user);
var response = Response.AsJson(new { success = true });
return response;
};
Post["/markallasread"] = _ =>
{
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
ChatUser user = repository.GetUserById(Principal.GetUserId());
IList<Notification> unReadNotifications = repository.GetNotificationsByUser(user).Unread().ToList();
if (!unReadNotifications.Any())
{
return HttpStatusCode.NotFound;
}
foreach (var notification in unReadNotifications)
{
notification.Read = true;
notificationService.MessageReadStateChanged(user, notification.Message, notification);
}
repository.CommitChanges();
UpdateUnreadCountInChat(repository, notificationService, user);
var response = Response.AsJson(new { success = true });
return response;
};
Get["/{key}"] = _ =>
{
if (!IsAuthenticated)
return Response.AsRedirect(String.Format("~/account/login?returnUrl={0}", HttpUtility.UrlEncode(Request.Path)));
var notification = repository.GetNotificationById(_.key);
if (notification == null)
//.........这里部分代码省略.........
示例10: AccountModule
//.........这里部分代码省略.........
repository.Remove(identity);
Request.AddAlertMessage("success", String.Format(LanguageResources.Account_UnlinkCompleted, provider));
return Response.AsRedirect("~/account/#identityProviders");
}
return HttpStatusCode.BadRequest;
};
Post["/newpassword"] = _ =>
{
if (!HasValidCsrfTokenOrSecHeader)
{
return HttpStatusCode.Forbidden;
}
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
string password = Request.Form.password;
string confirmPassword = Request.Form.confirmPassword;
ValidatePassword(password, confirmPassword);
ChatUser user = repository.GetUserById(Principal.GetUserId());
try
{
if (ModelValidationResult.IsValid)
{
membershipService.SetUserPassword(user, password);
repository.CommitChanges();
}
}
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
if (ModelValidationResult.IsValid)
{
Request.AddAlertMessage("success", LanguageResources.Authentication_PassAddSuccess);
return Response.AsRedirect("~/account/#changePassword");
}
return GetProfileView(authService, user);
};
Post["/changepassword"] = _ =>
{
if (!HasValidCsrfTokenOrSecHeader)
{
return HttpStatusCode.Forbidden;
}
if (!applicationSettings.AllowUserRegistration)
{
return HttpStatusCode.NotFound;
}
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}