本文整理汇总了C#中IAsyncDocumentSession.LoadAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IAsyncDocumentSession.LoadAsync方法的具体用法?C# IAsyncDocumentSession.LoadAsync怎么用?C# IAsyncDocumentSession.LoadAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAsyncDocumentSession
的用法示例。
在下文中一共展示了IAsyncDocumentSession.LoadAsync方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAsyncServerClient
public static async Task<AsyncServerClient> CreateAsyncServerClient(IAsyncDocumentSession session, ServerRecord server, ServerCredentials serverCredentials = null)
{
var documentStore = (DocumentStore)session.Advanced.DocumentStore;
var replicationInformer = new ReplicationInformer(new DocumentConvention
{
FailoverBehavior = FailoverBehavior.FailImmediately
});
ICredentials credentials = null;
if (serverCredentials != null)
{
credentials = serverCredentials.GetCredentials();
}
else if (server.CredentialsId != null)
{
serverCredentials = await session.LoadAsync<ServerCredentials>(server.CredentialsId);
if (serverCredentials == null)
{
server.CredentialsId = null;
}
else
{
credentials = serverCredentials.GetCredentials();
}
}
return new AsyncServerClient(server.Url, documentStore.Conventions, credentials,
documentStore.JsonRequestFactory, null, s => replicationInformer, null, new IDocumentConflictListener[0]);
}
示例2: FromDbFormat
internal static async Task<AuthorizationCode> FromDbFormat(StoredAuthorizationCode code, IAsyncDocumentSession s, IScopeStore scopeStore)
{
var result = new AuthorizationCode
{
CreationTime = code.CreationTime,
IsOpenId = code.IsOpenId,
RedirectUri = code.RedirectUri,
WasConsentShown = code.WasConsentShown,
Nonce = code.Nonce,
Client = Data.StoredClient.FromDbFormat(await s.LoadAsync<Data.StoredClient>("clients/" + code.Client)),
CodeChallenge = code.CodeChallenge,
CodeChallengeMethod = code.CodeChallengeMethod,
SessionId = code.SessionId,
RequestedScopes = await scopeStore.FindScopesAsync(code.RequestedScopes)
};
var claimsPrinciple = new ClaimsPrincipal();
foreach (var id in code.Subject)
{
claimsPrinciple.AddIdentity(Data.StoredIdentity.FromDbFormat(id));
}
result.Subject = claimsPrinciple;
return result;
}
示例3: EnsureSubscriptionsExists
private async Task EnsureSubscriptionsExists(IAsyncDocumentSession session)
{
var subscription = await session.LoadAsync<Subscription>(Subscription.Id);
if (subscription == null)
{
subscription = new Subscription();
await session.StoreAsync(subscription);
await session.SaveChangesAsync();
}
}
示例4: InsertOrUpdatePosts
private static async Task InsertOrUpdatePosts(
IAsyncDocumentSession session,
IEnumerable<BlogPost> insertedOrUpdatedPosts)
{
foreach (var post in insertedOrUpdatedPosts)
{
string postId = RavenDbIdConventions.GetBlogPostId(post.BlogKey, post.BlavenId);
var existingPost = await session.LoadAsync<BlogPost>(postId);
if (existingPost == null)
{
existingPost = new BlogPost { BlogKey = post.BlogKey, BlavenId = post.BlavenId };
await session.StoreAsync(existingPost);
}
existingPost.BlogAuthor = post.BlogAuthor;
existingPost.Content = post.Content;
existingPost.Hash = post.Hash;
existingPost.ImageUrl = post.ImageUrl;
existingPost.PublishedAt = post.PublishedAt;
existingPost.SourceId = post.SourceId;
existingPost.SourceUrl = post.SourceUrl;
existingPost.Summary = post.Summary;
existingPost.BlogPostTags = post.BlogPostTags;
existingPost.Title = post.Title;
existingPost.UpdatedAt = post.UpdatedAt;
existingPost.UrlSlug = post.UrlSlug;
}
}
示例5: DeletedPosts
private static async Task DeletedPosts(IAsyncDocumentSession session, IEnumerable<BlogPostBase> deletedPosts)
{
foreach (var deletedPost in deletedPosts)
{
string postId = RavenDbIdConventions.GetBlogPostId(deletedPost.BlogKey, deletedPost.BlavenId);
var existingPost = await session.LoadAsync<BlogPost>(postId);
if (existingPost != null)
{
session.Delete(existingPost);
}
}
}
示例6: SaveCorrelationProperties
async Task<IEnumerable<string>> SaveCorrelationProperties(IAsyncDocumentSession session, ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties, string sagaDataDocumentId)
{
var documentIds = new List<string>();
foreach (var correlationProperty in correlationProperties)
{
var propertyName = correlationProperty.PropertyName;
var value = sagaData.GetType().GetProperty(propertyName).GetValue(sagaData).ToString();
var documentId = SagaCorrelationPropertyDocument.GetIdForCorrelationProperty(correlationProperty.SagaDataType, propertyName,
value);
var existingSagaCorrelationPropertyDocument =
await session.LoadAsync<SagaCorrelationPropertyDocument>(documentId);
if (existingSagaCorrelationPropertyDocument != null)
{
if (existingSagaCorrelationPropertyDocument.SagaDataDocumentId != sagaDataDocumentId)
{
throw new ConcurrencyException(
$"Could not save correlation properties. The following correlation property already exists with the same value for another saga: {propertyName} - {value}");
}
}
else
{
var sagaCorrelationPropertyDocument = new SagaCorrelationPropertyDocument(correlationProperty.SagaDataType, propertyName, value, sagaDataDocumentId);
await session.StoreAsync(sagaCorrelationPropertyDocument, documentId);
}
documentIds.Add(documentId);
}
return documentIds;
}
示例7: DeleteCorrelationProperties
async Task DeleteCorrelationProperties(IEnumerable<string> correlationPropertyIds, IAsyncDocumentSession session)
{
var existingSagaCorrelationPropertyDocuments =
await session.LoadAsync<SagaCorrelationPropertyDocument>(
correlationPropertyIds);
//delete the existing saga correlation documents
foreach (var existingSagaCorrelationPropertyDocument in existingSagaCorrelationPropertyDocuments)
{
session.Delete(existingSagaCorrelationPropertyDocument);
}
}
示例8: HandleDatabaseInServerAsync
private static async Task HandleDatabaseInServerAsync(ServerRecord server, string databaseName, IAsyncDatabaseCommands dbCmds, IAsyncDocumentSession session)
{
var databaseRecord = await session.LoadAsync<DatabaseRecord>(server.Id + "/" + databaseName);
if (databaseRecord == null)
return;
var replicationDocument = await dbCmds.GetAsync(Constants.RavenReplicationDestinations);
if (replicationDocument == null)
return;
databaseRecord.IsReplicationEnabled = true;
var document = replicationDocument.DataAsJson.JsonDeserialization<ReplicationDocument>();
databaseRecord.ReplicationDestinations = document.Destinations;
var replicationStatistics = await dbCmds.Info.GetReplicationInfoAsync();
if (replicationStatistics != null)
{
databaseRecord.ReplicationStatistics = replicationStatistics;
}
// Monitor the replicated destinations
foreach (var replicationDestination in databaseRecord.ReplicationDestinations)
{
if (replicationDestination.Disabled)
continue;
var url = replicationDestination.Url;
var databasesIndex = url.IndexOf("/databases/", StringComparison.OrdinalIgnoreCase);
if (databasesIndex > 0)
{
url = url.Substring(0, databasesIndex);
}
var replicationDestinationServer = await session.LoadAsync<ServerRecord>("serverRecords/" + ReplicationTask.EscapeDestinationName(url));
if (replicationDestinationServer == null)
{
replicationDestinationServer = new ServerRecord
{
Url = url,
};
await session.StoreAsync(replicationDestinationServer);
}
else
{
if (DateTimeOffset.UtcNow - server.LastTriedToConnectAt <= TimeSpan.FromHours(1))
continue;
}
await FetchServerDatabasesAsync(replicationDestinationServer, session);
}
}
示例9: StoreActiveDatabaseNames
private static async Task StoreActiveDatabaseNames(ServerRecord server, AsyncServerClient client, IAsyncDocumentSession session)
{
AdminStatistics adminStatistics = await client.GlobalAdmin.GetStatisticsAsync();
server.IsUnauthorized = false;
server.ClusterName = adminStatistics.ClusterName;
server.ServerName = adminStatistics.ServerName;
server.MemoryStatistics = adminStatistics.Memory;
foreach (var loadedDatabase in adminStatistics.LoadedDatabases)
{
var databaseRecord = await session.LoadAsync<DatabaseRecord>(server.Id + "/" + loadedDatabase.Name);
if (databaseRecord == null)
{
databaseRecord = new DatabaseRecord { Name = loadedDatabase.Name, ServerId = server.Id, ServerUrl = server.Url };
await session.StoreAsync(databaseRecord);
}
databaseRecord.LoadedDatabaseStatistics = loadedDatabase;
}
server.LoadedDatabases = adminStatistics.LoadedDatabases.Select(database => database.Name).ToArray();
}
示例10: StoreDatabaseNames
private static async Task StoreDatabaseNames(ServerRecord server, AsyncServerClient client, IAsyncDocumentSession session)
{
server.Databases = await client.GetDatabaseNamesAsync(1024);
foreach (var databaseName in server.Databases.Concat(new[] {Constants.SystemDatabase}))
{
var databaseRecord = await session.LoadAsync<DatabaseRecord>(server.Id + "/" + databaseName);
if (databaseRecord == null)
{
databaseRecord = new DatabaseRecord {Name = databaseName, ServerId = server.Id, ServerUrl = server.Url};
await session.StoreAsync(databaseRecord);
}
}
}
示例11: DeleteCorrelationPropertyDataForSaga
private async Task DeleteCorrelationPropertyDataForSaga(SagaDataDocument sagaDataDocument,
IAsyncDocumentSession session)
{
var existingSagaCorrelationPropertyDocuments =
await session.LoadAsync<SagaCorrelationPropertyDocument>(
sagaDataDocument.SagaCorrelationPropertyDocumentIds);
//delete the existing saga correlation documents
foreach (var existingSagaCorrelationPropertyDocument in existingSagaCorrelationPropertyDocuments)
{
session.Delete(existingSagaCorrelationPropertyDocument);
}
}
示例12: CredentialsModule
public CredentialsModule(IAsyncDocumentSession session)
: base("/api/servers/credentials")
{
this.session = session;
Post["/save", true] = async (parameters, ct) =>
{
string serverId = Request.Query.ServerId;
var serverRecord = await session.LoadAsync<ServerRecord>(serverId);
if (serverRecord == null)
return new NotFoundResponse();
var credentials = this.Bind<ServerCredentials>();
await session.StoreAsync(credentials);
serverRecord.CredentialsId = credentials.Id;
await HealthMonitorTask.FetchServerDatabasesAsync(serverRecord, session);
return null;
};
Post["/test", true] = async (parameters, ct) =>
{
string serverId = Request.Query.ServerId;
var serverRecord = await session.LoadAsync<ServerRecord>(serverId);
if (serverRecord == null)
return new NotFoundResponse();
var credentials = this.Bind<ServerCredentials>();
var client = await ServerHelpers.CreateAsyncServerClient(session, serverRecord, credentials);
try
{
var adminStatistics = await client.GlobalAdmin.GetStatisticsAsync();
}
catch (AggregateException ex)
{
var exception = ex.ExtractSingleInnerException();
var webException = exception as WebException;
if (webException != null)
{
var response = webException.Response as HttpWebResponse;
if (response != null && response.StatusCode == HttpStatusCode.Unauthorized)
{
var failMessage = "Unauthorized. ";
if (credentials.AuthenticationMode == AuthenticationMode.ApiKey)
{
failMessage += " Check that the Api Kay exists and enabled on the server.";
}
else
{
failMessage += " Check that the username exists in the server (or domain) and the password is correct and was not expired.";
}
return new CredentialsTest
{
Success = false,
Message = failMessage,
Type = "Unauthorized",
Exception = response.ToString(),
};
}
else
{
return new CredentialsTest
{
Success = false,
Message = "Not found. Check that the server is online and that you have access to it.",
Type = "NotFound",
Exception = exception.ToString(),
};
}
}
return new CredentialsTest
{
Success = false,
Message = "An error occurred. See exception for more details.",
Exception = exception.ToString(),
};
}
catch (Exception ex)
{
return new CredentialsTest
{
Success = false,
Message = "An error occurred.",
Exception = ex.ToString(),
};
}
return new CredentialsTest
{
Success = true,
};
};
}