示例#1
0
        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
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        public override void UpdateDocument(MongoCollection <BsonDocument> collection, BsonDocument document)
        {
            if (!document.Contains(ErrorRepository.FieldNames.ExceptionlessClientInfo))
            {
                return;
            }

            BsonDocument clientInfo = document.GetElement(ErrorRepository.FieldNames.ExceptionlessClientInfo).Value.AsBsonDocument;

            if (clientInfo.Contains("SubmissionMethod"))
            {
                clientInfo.ChangeName("SubmissionMethod", ErrorRepository.FieldNames.SubmissionMethod);
            }

            if (clientInfo.Contains(ErrorRepository.FieldNames.InstallDate))
            {
                BsonValue installDateValue = clientInfo.GetElement(ErrorRepository.FieldNames.InstallDate).Value;
                if (installDateValue.IsBsonArray)
                {
                    return;
                }

                DateTime installDate = installDateValue.ToUniversalTime();
                clientInfo.AsBsonDocument.Set(ErrorRepository.FieldNames.InstallDate, new BsonArray(new BsonValue[] { new BsonInt64(installDate.Ticks), new BsonInt32(-360) }));
            }

            collection.Save(document);
        }
示例#5
0
        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);
                }
            }

            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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
        public void ChangeName()
        {
            var doc = new BsonDocument();

            doc.Add("old", "SPG");
            doc.Add("untouched", "leave it");
            doc.ChangeName("old", "new");
            doc.Should().BeEquivalentTo(
                new BsonDocument((IEnumerable <BsonElement>) new[]
            {
                new BsonElement("new", "SPG"),
                new BsonElement("untouched", "leave it")
            })
                );
        }
示例#12
0
        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);
        }
示例#13
0
        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);
        }
示例#14
0
        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);
        }