Ejemplo n.º 1
0
        public void Upgrade(EventUpgraderContext ctx) {
            if (ctx.Version > new Version(2, 0))
                return;

            bool isNotFound = ctx.Document.GetPropertyStringValue("Code") == "404";
            if (isNotFound)
                ctx.Document.Remove("Id");
            else
                ctx.Document.RenameOrRemoveIfNullOrEmpty("Id", "ReferenceId");

            ctx.Document.RenameOrRemoveIfNullOrEmpty("OccurrenceDate", "Date");
            ctx.Document.Remove("OrganizationId");
            ctx.Document.Remove("ProjectId");
            ctx.Document.Remove("ErrorStackId");
            ctx.Document.Remove("ExceptionlessClientInfo");
            ctx.Document.Remove("IsFixed");
            ctx.Document.Remove("IsHidden");
            ctx.Document.RemoveIfNullOrEmpty("Tags");
            ctx.Document.RenameOrRemoveIfNullOrEmpty("RequestInfo", "req");
            ctx.Document.RenameOrRemoveIfNullOrEmpty("EnvironmentInfo", "env");

            ctx.Document.RenameAll("ExtendedData", "Data");
            var extendedData = ctx.Document.Property("Data") != null ? ctx.Document.Property("Data").Value as JObject : null;
            if (extendedData != null)
                extendedData.RenameOrRemoveIfNullOrEmpty("TraceLog", "trace");

            var error = new JObject();
            error.MoveOrRemoveIfNullOrEmpty(ctx.Document, "Code");
            error.MoveOrRemoveIfNullOrEmpty(ctx.Document, "Type");
            error.CopyOrRemoveIfNullOrEmpty(ctx.Document, "Message");
            error.MoveOrRemoveIfNullOrEmpty(ctx.Document, "Inner");
            error.MoveOrRemoveIfNullOrEmpty(ctx.Document, "StackTrace");
            error.MoveOrRemoveIfNullOrEmpty(ctx.Document, "TargetMethod");
            error.MoveOrRemoveIfNullOrEmpty(ctx.Document, "Modules");

            MoveExtraExceptionProperties(error, extendedData);
            var inner = error["inner"] as JObject;
            while (inner != null) {
                MoveExtraExceptionProperties(inner);
                inner = inner["inner"] as JObject;
            }

            ctx.Document.Add("Type", new JValue(isNotFound ? "404" : "error"));
            ctx.Document.Add("err", error);

            string emailAddress = ctx.Document.GetPropertyStringValueAndRemove("UserEmail");
            string userDescription = ctx.Document.GetPropertyStringValueAndRemove("UserDescription");
            if (!String.IsNullOrWhiteSpace(emailAddress) && !String.IsNullOrWhiteSpace(userDescription))
                ctx.Document.Add("desc", JObject.FromObject(new UserDescription(emailAddress, userDescription)));

            string identity = ctx.Document.GetPropertyStringValueAndRemove("UserName");
            if (!String.IsNullOrWhiteSpace(identity))
                ctx.Document.Add("user", JObject.FromObject(new UserInfo(identity)));

            ctx.Document.RemoveAllIfNullOrEmpty("Data");
            ctx.Document.RemoveAllIfNullOrEmpty("GenericArguments");
            ctx.Document.RemoveAllIfNullOrEmpty("Parameters");
        }
Ejemplo n.º 2
0
        public void Upgrade(EventUpgraderContext ctx) {
            if (ctx.Version > new Version(2, 0))
                return;

            foreach (var doc in ctx.Documents.OfType<JObject>()) {
                bool isNotFound = doc.GetPropertyStringValue("Code") == "404";

                if (ctx.IsMigration) {
                    doc.Rename("ErrorStackId", "StackId");
                } else {
                    doc.RenameOrRemoveIfNullOrEmpty("Id", "ReferenceId");
                    doc.Remove("OrganizationId");
                    doc.Remove("ProjectId");
                    doc.Remove("ErrorStackId");
                }

                doc.RenameOrRemoveIfNullOrEmpty("OccurrenceDate", "Date");
                doc.Remove("ExceptionlessClientInfo");
                if (!doc.RemoveIfNullOrEmpty("Tags")) {
                    var tags = doc.GetValue("Tags");
                    if (tags.Type == JTokenType.Array) {
                        foreach (JToken tag in tags.ToList()) {
                            string t = tag.ToString();
                            if (String.IsNullOrEmpty(t) || t.Length > 255)
                                tag.Remove();
                        }
                    }
                }

                doc.RenameOrRemoveIfNullOrEmpty("RequestInfo", "@request");
                bool hasRequestInfo = doc["@request"] != null;

                if (!isNotFound)
                    doc.RenameOrRemoveIfNullOrEmpty("EnvironmentInfo", "@environment");
                else
                    doc.Remove("EnvironmentInfo");

                doc.RenameAll("ExtendedData", "Data");

                var extendedData = doc.Property("Data") != null ? doc.Property("Data").Value as JObject : null;
                if (extendedData != null) {
                    if (!isNotFound)
                        extendedData.RenameOrRemoveIfNullOrEmpty("TraceLog", "@trace");
                    else
                        extendedData.Remove("TraceLog");
                }

                if (isNotFound && hasRequestInfo) {
                    doc.RemoveAll("Code", "Type", "Message", "Inner", "StackTrace", "TargetMethod", "Modules");
                    if (extendedData?["__ExceptionInfo"] != null)
                        extendedData.Remove("__ExceptionInfo");

                    doc.Add("Type", new JValue("404"));
                } else {
                    var error = new JObject();

                    if (!doc.RemoveIfNullOrEmpty("Message"))
                        error.Add("Message", doc["Message"].Value<string>());

                    error.MoveOrRemoveIfNullOrEmpty(doc, "Code", "Type", "Inner", "StackTrace", "TargetMethod", "Modules");

                    // Copy the exception info from root extended data to the current errors extended data.
                    if (extendedData?["__ExceptionInfo"] != null) {
                        error.Add("Data", new JObject());
                        ((JObject)error["Data"]).MoveOrRemoveIfNullOrEmpty(extendedData, "__ExceptionInfo");
                    }

                    string id = doc["Id"] != null ? doc["Id"].Value<string>(): null;
                    string projectId = doc["ProjectId"] != null ? doc["ProjectId"].Value<string>() : null;
                    RenameAndValidateExtraExceptionProperties(projectId, id, error);

                    var inner = error["Inner"] as JObject;
                    while (inner != null) {
                        RenameAndValidateExtraExceptionProperties(projectId, id, inner);
                        inner = inner["Inner"] as JObject;
                    }

                    doc.Add("Type", new JValue(isNotFound ? "404" : "error"));
                    doc.Add("@error", error);
                }

                string emailAddress = doc.GetPropertyStringValueAndRemove("UserEmail");
                string userDescription = doc.GetPropertyStringValueAndRemove("UserDescription");
                if (!String.IsNullOrWhiteSpace(emailAddress) && !String.IsNullOrWhiteSpace(userDescription))
                    doc.Add("@user_description", JObject.FromObject(new UserDescription(emailAddress, userDescription)));

                string identity = doc.GetPropertyStringValueAndRemove("UserName");
                if (!String.IsNullOrWhiteSpace(identity))
                    doc.Add("@user", JObject.FromObject(new UserInfo(identity)));

                doc.RemoveAllIfNullOrEmpty("Data", "GenericArguments", "Parameters");
            }
        }