当前位置: 首页>>代码示例>>C#>>正文


C# BsonDocument.ChangeName方法代码示例

本文整理汇总了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);
        }
开发者ID:arpitgold,项目名称:Exceptionless,代码行数:25,代码来源:v1.0.32.cs

示例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);
        }
开发者ID:aamarber,项目名称:Exceptionless,代码行数:14,代码来源:v1.0.36.cs

示例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);
        }
开发者ID:aamarber,项目名称:Exceptionless,代码行数:44,代码来源:v1.0.32.cs

示例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);
        }
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:43,代码来源:v1.0.31.cs

示例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);
        }
开发者ID:jrheault,项目名称:Exceptionless,代码行数:11,代码来源:v1.0.29.cs

示例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);
        }
开发者ID:aamarber,项目名称:Exceptionless,代码行数:73,代码来源:v1.0.31.cs


注:本文中的BsonDocument.ChangeName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。