本文整理汇总了C#中IAsyncDocumentSession.StoreAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IAsyncDocumentSession.StoreAsync方法的具体用法?C# IAsyncDocumentSession.StoreAsync怎么用?C# IAsyncDocumentSession.StoreAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAsyncDocumentSession
的用法示例。
在下文中一共展示了IAsyncDocumentSession.StoreAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateUsersAsync
private static async Task CreateUsersAsync(IAsyncDocumentSession session)
{
var user1 = new User {Name = "Jane"};
user1.OfficesIds.Add("office/1");
user1.OfficesIds.Add("office/2");
var user2 = new User {Name = "Bill"};
user2.OfficesIds.Add("office/1");
user2.OfficesIds.Add("office/3");
await session.StoreAsync(user1);
await session.StoreAsync(user2);
}
示例2: DiscoveryModule
public DiscoveryModule(IAsyncDocumentSession session)
: base("/api/discovery")
{
this.session = session;
Get["/start"] = parameters =>
{
var discoveryClient = new ClusterDiscoveryClient(SenderId, "http://localhost:9020/api/discovery/notify");
discoveryClient.PublishMyPresenceAsync();
return "started";
};
Post["/notify", true] = async (parameters, ct) =>
{
var input = this.Bind<ServerRecord>("Id");
var server = await session.Query<ServerRecord>().Where(s => s.Url == input.Url).FirstOrDefaultAsync() ?? new ServerRecord();
this.BindTo(server, "Id");
await session.StoreAsync(server);
await HealthMonitorTask.FetchServerDatabases(server, session.Advanced.DocumentStore);
return "notified";
};
}
示例3: SaveEntities
protected static async Task SaveEntities(IEnumerable<IEntity> entities, IAsyncDocumentSession session)
{
foreach (var entity in entities)
{
await session.StoreAsync(entity);
}
await session.SaveChangesAsync();
}
示例4: 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();
}
}
示例5: CreateDefaultData
private static void CreateDefaultData(IAsyncDocumentSession session)
{
var role = new ApplicationRole("Admin");
session.StoreAsync(role);
var hasher = new PasswordHasher();
var passwordHash = hasher.HashPassword("admin");
var superUser = new ApplicationUser("SuperAdmin")
{
Email = "[email protected]",
FirstName = "Super",
LastName = "Admin",
UserName = "superadmin",
PasswordHash = passwordHash,
EmailConfirmed = true,
Roles = {"Admin"}
};
session.StoreAsync(superUser);
session.SaveChangesAsync();
}
示例6: SaveEntity
protected static async Task SaveEntity(IEntity entity, IAsyncDocumentSession session)
{
await session.StoreAsync(entity);
await session.SaveChangesAsync();
}
示例7: 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;
}
}
示例8: 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;
}
示例9: SaveAsync
public static async Task SaveAsync(this Model model, string type, IAsyncDocumentSession session) {
var id = await NextId(type);
await session.StoreAsync(model, id);
(await session.Advanced.GetMetadataForAsync(model))[Constants.RavenEntityName] = type;
}
示例10: 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);
}
}
示例11: 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();
}
示例12: 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);
}
}
}
示例13: StoreDataAsync
public async Task StoreDataAsync(DocumentStore store, IAsyncDocumentSession session)
{
for (var i = 1; i <= Cntr; i++)
{
await session.StoreAsync(new User {Name = "Test User #" + i}, "users/" + i);
}
await session.SaveChangesAsync();
}
示例14: AddUsers
// privates
private static async Task AddUsers(IAsyncDocumentSession ses)
{
await ses.StoreAsync(new RavenUser { UserName = "Tugberk", Roles = new List<RavenUserRole> { new RavenUserRole { Id = "Admin" }, new RavenUserRole { Id = "Guest" } } });
await ses.StoreAsync(new RavenUser { UserName = "Tugberk2", Roles = new List<RavenUserRole> { new RavenUserRole { Id = "Admin" } } });
await ses.StoreAsync(new RavenUser { UserName = "Tugberk2", Roles = new List<RavenUserRole> { new RavenUserRole { Id = "Guest" } } });
await ses.SaveChangesAsync();
}
示例15: 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,
};
};
}