private async Task <bool> ForwardCurrentBatch(IAsyncDocumentSession session, CancellationToken cancellationToken) { Log.Debug("Looking for batch to forward"); var nowForwarding = await session.Include <RetryBatchNowForwarding, RetryBatch>(r => r.RetryBatchId) .LoadAsync <RetryBatchNowForwarding>(RetryBatchNowForwarding.Id) .ConfigureAwait(false); if (nowForwarding != null) { Log.DebugFormat("Loading batch {0} for forwarding", nowForwarding.RetryBatchId); var forwardingBatch = await session.LoadAsync <RetryBatch>(nowForwarding.RetryBatchId).ConfigureAwait(false); if (forwardingBatch != null) { Log.InfoFormat("Found batch {0}. Forwarding...", forwardingBatch.Id); Forward(forwardingBatch, session, cancellationToken); Log.DebugFormat("Retry batch {0} forwarded.", forwardingBatch.Id); } else { Log.WarnFormat("Could not find retry batch {0} to forward", nowForwarding.RetryBatchId); } Log.Debug("Removing Forwarding record"); session.Delete(nowForwarding); return(true); } Log.Debug("No batch found to forward"); return(false); }
/// <inheritdoc /> public async Task <T> Get <T, TIncType>(object id, Expression <Func <T, object> > field, Expression <Func <T, TIncType> > targetField, CancellationToken cancellationToken = default) where T : BaseEntity where TIncType : BaseEntity { var res = await Session .Include(field.Cast <T, object, string>()) .LoadAsync <T>((string)id, cancellationToken); var inc = await Session.LoadAsync <TIncType>(res.GetPropertyValue <T, string>(field.Name), cancellationToken); res.SetPropertyValue(targetField, inc); return(res); }
public static async Task <T> LoadByUniqueConstraintAsync <T>(this IAsyncDocumentSession session, Expression <Func <T, object> > keySelector, object value) { var documentStoreListeners = ((AsyncDocumentSession)session).Listeners.StoreListeners; var uniqueConstraintsStoreListener = documentStoreListeners.OfType <UniqueConstraintsStoreListener>().FirstOrDefault(); if (uniqueConstraintsStoreListener == null) { throw new InvalidOperationException("Could not find UniqueConstraintsStoreListener in the session listeners, did you forget to register it?"); } if (value == null) { throw new ArgumentNullException("value", "The unique value cannot be null"); } var typeName = session.Advanced.DocumentStore.Conventions.GetTypeTagName(typeof(T)); var body = GetMemberExpression(keySelector, uniqueConstraintsStoreListener.UniqueConstraintsTypeDictionary); var propertyName = body.Member.Name; var att = (UniqueConstraintAttribute)Attribute.GetCustomAttribute(body.Member, typeof(UniqueConstraintAttribute)); var escapedValue = Util.EscapeUniqueValue(value, att.CaseInsensitive); var uniqueId = "UniqueConstraints/" + typeName.ToLowerInvariant() + "/" + propertyName.ToLowerInvariant() + "/" + escapedValue; var constraintDoc = await session .Include <ConstraintDocument>(x => x.RelatedId) .Include(x => x.Constraints.Values.Select(c => c.RelatedId)) .LoadAsync(uniqueId); if (constraintDoc == null) { return(default(T)); } return(await session.LoadAsync <T>(constraintDoc.GetRelatedIdFor(escapedValue))); }
static async Task <RetryBatch> GetCurrentForwardingBatch(IAsyncDocumentSession session) { var nowForwarding = await session.Include <RetryBatchNowForwarding, RetryBatch>(r => r.RetryBatchId) .LoadAsync <RetryBatchNowForwarding>(RetryBatchNowForwarding.Id) .ConfigureAwait(false); return(nowForwarding == null ? null : await session.LoadAsync <RetryBatch>(nowForwarding.RetryBatchId).ConfigureAwait(false)); }
public async Task <TUser> FindAsync(UserLoginInfo login) { if (login == null) { throw new ArgumentNullException("login"); } string keyToLookFor = RavenUserLogin.GenerateKey(login.LoginProvider, login.ProviderKey); RavenUserLogin ravenUserLogin = await _documentSession .Include <RavenUserLogin, TUser>(usrLogin => usrLogin.UserId) .LoadAsync(keyToLookFor) .ConfigureAwait(false); return((ravenUserLogin != null) ? await _documentSession.LoadAsync <TUser>(ravenUserLogin.UserId).ConfigureAwait(false) : default(TUser)); }
/// <summary> /// Update database provisioning status. /// </summary> /// <param name="databaseProvisioningNotification"> /// A <see cref="DatabaseStatusChanged"/> message describing the change. /// </param> /// <returns> /// A <see cref="Task"/> representing the operation. /// </returns> async Task UpdateDatabaseProvisioningStatus(DatabaseStatusChanged databaseProvisioningNotification) { if (databaseProvisioningNotification == null) { throw new ArgumentNullException(nameof(databaseProvisioningNotification)); } using (IAsyncDocumentSession session = DocumentStore.OpenAsyncSession()) { DatabaseInstance database = await session .Include <DatabaseInstance>(db => db.ServerId) .LoadAsync <DatabaseInstance>(databaseProvisioningNotification.DatabaseId); if (database == null) { Log.Warning("Received DatabaseStatusChanged notification for non-existent database (Id:{DatabaseId}).", databaseProvisioningNotification.DatabaseId ); return; } DatabaseServer server = await session.LoadAsync <DatabaseServer>(database.ServerId); if (server == null) { Log.Warning("Received DatabaseStatusChanged notification for database in non-existent server (Id:{ServerId}).", database.ServerId ); return; } database.Status = databaseProvisioningNotification.Status; switch (database.Status) { case ProvisioningStatus.Ready: case ProvisioningStatus.Error: { database.Action = ProvisioningAction.None; break; } case ProvisioningStatus.Deprovisioned: { server.DatabaseIds.Remove(database.Id); session.Delete(database); break; } } await session.SaveChangesAsync(); } }
/*\ ***** ***** ***** ***** ***** Public Methods ***** ***** ***** ***** ***** \*/ public IAsyncLoaderWithInclude <T> Include <T>(Expression <Func <T, object> > path) where T : IDocument { if (path == null) { throw new ArgumentNullException(nameof(path)); } return(_async.Include(path)); }
public async Task <bool> UserCanAccessProgram(string programId, string userId) { var program = await _session.Include <ChildDTO>(x => x.Id).LoadAsync <ReadingProgramInfoDTO>(programId); var childrenOnProgram = await _session.LoadAsync <ChildDTO>(program.ChildrenIds); var userCanAccess = childrenOnProgram.Select(x => x.Value).SelectMany(x => x.Adults).Any(x => x == userId); return(userCanAccess); }
private async Task <bool> ForwardCurrentBatch(IAsyncDocumentSession session, CancellationToken cancellationToken) { if (Log.IsDebugEnabled) { Log.Debug("Looking for batch to forward."); } var nowForwarding = await session.Include <RetryBatchNowForwarding, RetryBatch>(r => r.RetryBatchId) .LoadAsync <RetryBatchNowForwarding>(RetryBatchNowForwarding.Id) .ConfigureAwait(false); if (nowForwarding != null) { if (Log.IsDebugEnabled) { Log.Debug($"Loading batch {nowForwarding.RetryBatchId} for forwarding."); } var forwardingBatch = await session.LoadAsync <RetryBatch>(nowForwarding.RetryBatchId, cancellationToken).ConfigureAwait(false); if (forwardingBatch != null) { if (Log.IsDebugEnabled) { Log.Info($"Forwarding batch {forwardingBatch.Id}."); } await Forward(forwardingBatch, session, cancellationToken) .ConfigureAwait(false); if (Log.IsDebugEnabled) { Log.DebugFormat("Retry batch {0} forwarded.", forwardingBatch.Id); } } else { Log.Warn($"Could not find retry batch {nowForwarding.RetryBatchId} to forward."); } if (Log.IsDebugEnabled) { Log.Debug("Removing forwarding document."); } session.Delete(nowForwarding); return(true); } Log.Info("No batch found to forward."); return(false); }
public static async Task <UniqueConstraintCheckResult <T> > CheckForUniqueConstraintsAsync <T>(this IAsyncDocumentSession session, T entity) { var properties = session.Advanced.DocumentStore.GetUniquePropertiesForType(typeof(T)); T[] loadedDocs = null; var typeName = session.Advanced.DocumentStore.Conventions.GetTypeTagName(typeof(T)); var constraintsIds = (from property in properties let propertyValue = property.GetValue(entity) where propertyValue != null from item in propertyValue is IEnumerable && propertyValue.GetType() != typeof(string) ? ((IEnumerable)propertyValue).Cast <object>().Where(i => i != null) : new[] { propertyValue } select new { Id = "UniqueConstraints/" + typeName.ToLowerInvariant() + "/" + property.Configuration.Name.ToLowerInvariant() + "/" + Util.EscapeUniqueValue(item.ToString(), property.Configuration.CaseInsensitive), Key = Util.EscapeUniqueValue(item.ToString(), property.Configuration.CaseInsensitive) }).ToList(); var constraintDocs = await session .Include <ConstraintDocument>(x => x.RelatedId) .Include(x => x.Constraints.Values.Select(c => c.RelatedId)) .LoadAsync(constraintsIds.Select(x => x.Id).ToArray()) .ConfigureAwait(false); var existingDocsIds = new List <string>(); for (var i = 0; i < constraintDocs.Length; i++) { var constraintDoc = constraintDocs[i]; if (constraintDoc == null) { continue; } var constraintId = constraintsIds[i]; var relatedId = constraintDoc.GetRelatedIdFor(constraintId.Key); if (!string.IsNullOrEmpty(relatedId)) { existingDocsIds.Add(relatedId); } } if (existingDocsIds.Any()) { loadedDocs = await session.LoadAsync <T>(existingDocsIds).ConfigureAwait(false); } return(new UniqueConstraintCheckResult <T>(entity, properties, loadedDocs)); }
public async Task <Contract.Output> ReadContract(string id, CancellationToken ctk = default) { var entity = await _session .Include <Contract.Store>(x => x.CounterpartyId) .Include <Contract.Store>(x => x.ContractDetails) .LoadAsync <Contract.Store>(id, ctk); if (entity == null) { return(null); } var entityOutput = Mapper.Map(entity).ToANew <Contract.Output>(); entityOutput._ETag = _session.Advanced.GetChangeVectorFor(entity); return(entityOutput); }
public static Task <UniqueConstraintCheckResult <T> > CheckForUniqueConstraintsAsync <T>(this IAsyncDocumentSession session, T entity) { var properties = UniqueConstraintsTypeDictionary.GetProperties(typeof(T)); if (properties != null) { var typeName = session.Advanced.DocumentStore.Conventions.GetTypeTagName(typeof(T)); var constraintsIds = from property in properties let propertyValue = property.GetValue(entity, null) let att = (UniqueConstraintAttribute)Attribute.GetCustomAttribute(property, typeof(UniqueConstraintAttribute)) where propertyValue != null select "UniqueConstraints/" + typeName.ToLowerInvariant() + "/" + property.Name.ToLowerInvariant() + "/" + Raven.Bundles.UniqueConstraints.Util.EscapeUniqueValue(propertyValue.ToString(), att.CaseInsensitive); return(session.Include <ConstraintDocument>(x => x.RelatedId).LoadAsync(constraintsIds.ToArray()) .ContinueWith(task => { var constraintDocs = task.Result; var existingDocsIds = (from constraintDoc in constraintDocs where constraintDoc != null select constraintDoc.RelatedId into id where !string.IsNullOrEmpty(id) select id).ToArray(); if (existingDocsIds.Any() == false) { return new CompletedTask <UniqueConstraintCheckResult <T> >(new UniqueConstraintCheckResult <T>(entity, properties, null)); } return session.LoadAsync <T>(existingDocsIds.ToArray()).ContinueWith(loadTask => { var completedTask = new CompletedTask <UniqueConstraintCheckResult <T> >( new UniqueConstraintCheckResult <T>(entity, properties, loadTask.Result) ); return (Task <UniqueConstraintCheckResult <T> >)completedTask; }).Unwrap(); }).Unwrap()); } return(new CompletedTask <UniqueConstraintCheckResult <T> >(new UniqueConstraintCheckResult <T>(entity, properties, null))); }
public async Task <List <TaskUserVO> > GetAllActiveTask(string projectId) { var project = await asyncDocumentSession.Include("PMId") .LoadAsync <Project>(projectId); var tasklst = project.ProjectTasks.Where(pt => pt.Status > -1); var result = new List <TaskUserVO>(); foreach (var task in tasklst) { var user = await asyncDocumentSession.LoadAsync <PMOUser>(task.TaskOwnerId); result.Add(new TaskUserVO { ProjectId = projectId, UserName = $"{user.FirstName} {user.LastName}", Tasks = task }); } return(result); }
public static Task <T> LoadByUniqueConstraintAsync <T>(this IAsyncDocumentSession session, Expression <Func <T, object> > keySelector, object value) { if (value == null) { throw new ArgumentNullException("value", "The unique value cannot be null"); } var typeName = session.Advanced.DocumentStore.Conventions.GetTypeTagName(typeof(T)); var body = (MemberExpression)keySelector.Body; var propertyName = body.Member.Name; var uniqueId = "UniqueConstraints/" + typeName.ToLowerInvariant() + "/" + propertyName.ToLowerInvariant() + "/" + Raven.Bundles.UniqueConstraints.Util.EscapeUniqueValue(value); return(session.Include <ConstraintDocument>(x => x.RelatedId).LoadAsync(uniqueId) .ContinueWith(x => { if (x.Result == null) { return new CompletedTask <T>(default(T)); } return session.LoadAsync <T>(x.Result.RelatedId); }).Unwrap()); }
public IAsyncLoaderWithInclude <object> Include(string path) { return(_documentSession.Include(path)); }
public IAsyncLoaderWithInclude <object> Include(string path) { return(_inner.Include(path)); }