本文整理汇总了C#中BsonDocument.ChangeName方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.ChangeName方法的具体用法?C# BsonDocument.ChangeName怎么用?C# BsonDocument.ChangeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.ChangeName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document)
{
if (document.Contains("ErrorCount"))
document.ChangeName("ErrorCount", "EventCount");
if (document.Contains("TotalErrorCount"))
document.ChangeName("TotalErrorCount", "TotalEventCount");
if (document.Contains("LastErrorDate"))
document.ChangeName("LastErrorDate", "LastEventDate");
if (document.Contains("MaxErrorsPerMonth"))
document.ChangeName("MaxErrorsPerMonth", "MaxEventsPerMonth");
if (document.Contains("SuspensionCode")) {
var value = document.GetValue("SuspensionCode");
document.Remove("SuspensionCode");
SuspensionCode suspensionCode;
if (value.IsString && Enum.TryParse(value.AsString, true, out suspensionCode))
document.Set("SuspensionCode", suspensionCode);
}
collection.Save(document);
}
示例2: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("OrganizationId"))
document.ChangeName("OrganizationId", "oid");
if (document.Contains("ProjectId"))
document.ChangeName("ProjectId", "pid");
if (document.Contains("Version"))
document.Remove("Version");
document.Set("Version", "1.0.0.0");
collection.Save(document);
}
示例3: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("ErrorCount"))
document.ChangeName("ErrorCount", "EventCount");
if (document.Contains("TotalErrorCount"))
document.ChangeName("TotalErrorCount", "TotalEventCount");
if (document.Contains("LastErrorDate"))
document.ChangeName("LastErrorDate", "LastEventDate");
if (document.Contains("MaxErrorsPerDay")) {
int maxErrorsPerDay = -1;
var maxErrorsPerDayElement = document.GetValue("MaxErrorsPerDay");
if (maxErrorsPerDayElement.IsInt32)
maxErrorsPerDay = maxErrorsPerDayElement.AsInt32;
else if (maxErrorsPerDayElement.IsInt64)
maxErrorsPerDay = (int)maxErrorsPerDayElement.AsInt64;
document.Set("MaxEventsPerMonth", maxErrorsPerDay > 0 ? maxErrorsPerDay * 30 : -1);
document.Remove("MaxErrorsPerDay");
}
if (document.Contains("MaxErrorsPerMonth"))
document.ChangeName("MaxErrorsPerMonth", "MaxEventsPerMonth");
if (document.Contains("SuspensionCode")) {
var value = document.GetValue("SuspensionCode");
document.Remove("SuspensionCode");
SuspensionCode suspensionCode;
if (value.IsString && Enum.TryParse(value.AsString, true, out suspensionCode))
document.Set("SuspensionCode", suspensionCode);
}
if (document.Contains("PlanId")) {
string planId = document.GetValue("PlanId").AsString;
var currentPlan = BillingManager.GetBillingPlan(planId);
document.Set("PlanName", currentPlan != null ? currentPlan.Name : planId);
document.Set("PlanDescription", currentPlan != null ? currentPlan.Description : planId);
}
collection.Save(document);
}
示例4: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document)
{
if (document.Contains("ErrorCount"))
document.ChangeName("ErrorCount", "EventCount");
if (document.Contains("TotalErrorCount"))
document.ChangeName("TotalErrorCount", "TotalEventCount");
if (document.Contains("LastErrorDate"))
document.ChangeName("LastErrorDate", "LastEventDate");
BsonValue keys;
if (document.TryGetValue("ApiKeys", out keys) && keys.IsBsonArray) {
if (!collection.Database.CollectionExists("token"))
collection.Database.CreateCollection("token");
var projectId = document.GetValue("_id").AsObjectId;
var tokenCollection = Database.GetCollection("token");
var tokens = new List<BsonDocument>();
foreach (var key in keys.AsBsonArray) {
var token = new BsonDocument();
token.Set("_id", key);
token.Set("oid", new BsonObjectId(document.GetValue("oid").AsObjectId));
token.Set("pid", new BsonObjectId(projectId));
token.Set("typ", TokenType.Access);
token.Set("scp", new BsonArray(new[] { "client" }));
token.Set("exp", DateTime.UtcNow.AddYears(100));
token.Set("not", "Client api key");
token.Set("dt", projectId.CreationTime.ToUniversalTime());
token.Set("mdt", DateTime.UtcNow);
tokens.Add(token);
}
if (tokens.Count > 0)
tokenCollection.InsertBatch(tokens);
}
document.Remove("ApiKeys");
collection.Save(document);
}
示例5: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("OverageDays"))
document.Remove("OverageDays");
document.ChangeName("MaxErrorsPerDay", "MaxErrorsPerMonth");
var maxErrorsPerMonth = document.GetValue("MaxErrorsPerMonth").AsInt32;
if (maxErrorsPerMonth > 0)
document.Set("MaxErrorsPerMonth", maxErrorsPerMonth * 30);
collection.Save(document);
}
示例6: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("ErrorCount"))
document.ChangeName("ErrorCount", "EventCount");
if (document.Contains("TotalErrorCount"))
document.ChangeName("TotalErrorCount", "TotalEventCount");
if (document.Contains("LastErrorDate"))
document.ChangeName("LastErrorDate", "LastEventDate");
BsonValue value;
if (document.TryGetValue("ApiKeys", out value) && value.IsBsonArray) {
if (!collection.Database.CollectionExists("token"))
collection.Database.CreateCollection("token");
var projectId = document.GetValue("_id").AsObjectId;
var tokenCollection = Database.GetCollection("token");
var tokens = new List<BsonDocument>();
foreach (var key in value.AsBsonArray) {
var token = new BsonDocument();
token.Set("_id", key);
token.Set("oid", new BsonObjectId(document.GetValue("oid").AsObjectId));
token.Set("pid", new BsonObjectId(projectId));
token.Set("typ", TokenType.Access);
token.Set("scp", new BsonArray(new[] { "client" }));
token.Set("exp", DateTime.UtcNow.AddYears(100));
token.Set("not", "Client api key");
token.Set("dt", projectId.CreationTime.ToUniversalTime());
token.Set("mdt", DateTime.UtcNow);
tokens.Add(token);
}
if (tokens.Count > 0)
tokenCollection.InsertBatch(tokens);
}
document.Remove("ApiKeys");
if (document.TryGetValue("NotificationSettings", out value) && value.IsBsonDocument) {
var settings = new BsonDocument();
foreach (BsonElement element in value.AsBsonDocument) {
if (String.IsNullOrEmpty(element.Name) || !element.Value.IsBsonDocument)
continue;
var userSettings = element.Value.AsBsonDocument;
bool isNew = false;
if (userSettings.Contains("Mode")) {
isNew = userSettings.GetValue("Mode").AsInt32 == 1;
userSettings.Remove("Mode");
}
userSettings.Set("ReportNewErrors", new BsonBoolean(isNew));
if (userSettings.Contains("ReportRegressions"))
userSettings.ChangeName("ReportRegressions", "ReportEventRegressions");
if (userSettings.Contains("Report404Errors"))
userSettings.Remove("Report404Errors");
if (userSettings.Contains("ReportKnownBotErrors"))
userSettings.Remove("ReportKnownBotErrors");
settings.Set(element.Name, userSettings);
}
document.Set("NotificationSettings", settings);
}
collection.Save(document);
}