Esempio n. 1
0
        public static Stack GenerateStack(bool generateId = false, string id = null, string organizationId = null, string projectId = null, string type = null, string title = null, DateTime? dateFixed = null, DateTime? utcFirstOccurrence = null, DateTime? utcLastOccurrence = null, int totalOccurrences = 0, bool isRegressed = false, bool isHidden = false, string signatureHash = null) {
            var stack = new Stack {
                Id = id.IsNullOrEmpty() ? generateId ? ObjectId.GenerateNewId().ToString() : null : id,
                OrganizationId = organizationId.IsNullOrEmpty() ? TestConstants.OrganizationId : organizationId,
                ProjectId = projectId.IsNullOrEmpty() ? TestConstants.ProjectIds.Random() : projectId,
                Title = title ?? RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 50)),
                Type = type ?? Stack.KnownTypes.Error,
                DateFixed = dateFixed,
                FirstOccurrence = utcFirstOccurrence ?? DateTime.MinValue,
                LastOccurrence = utcLastOccurrence ?? DateTime.MinValue,
                TotalOccurrences = totalOccurrences,
                IsRegressed = isRegressed,
                IsHidden = isHidden,
                SignatureHash = signatureHash ?? RandomHelper.GetPronouncableString(10),
                SignatureInfo = new SettingsDictionary()
            };

            for (int i = 0; i < RandomHelper.GetRange(0, 5); i++) {
                string tag = RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 15));
                while (stack.Tags.Contains(tag))
                    tag = RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 15));

                stack.Tags.Add(tag);
            }

            return stack;
        }
        public WebHookDataContext(Version version, Stack stack, Organization organization = null, Project project = null, bool isNew = false, bool isRegression = false)
        {
            if (version == null)
                throw new ArgumentException("Version cannot be null.", "version");

            if (stack == null)
                throw new ArgumentException("Stack cannot be null.", "stack");

            Version = version;
            Organization = organization;
            Project = project;
            Stack = stack;
            IsNew = isNew;
            IsRegression = isRegression;
        }
        public WebHookDataContext(Version version, PersistentEvent ev, Organization organization = null, Project project = null, Stack stack = null, bool isNew = false, bool isRegression = false)
        {
            if (version == null)
                throw new ArgumentException("Version cannot be null.", "version");

            if (ev == null)
                throw new ArgumentException("Event cannot be null.", "ev");

            Version = version;
            Organization = organization;
            Project = project;
            Stack = stack;
            Event = ev;
            IsNew = isNew;
            IsRegression = isRegression;
        }
Esempio n. 4
0
        public static Stack GenerateStack(bool generateId = false, string id = null, string organizationId = null, string projectId = null) {
            var stack = new Stack {
                Id = id.IsNullOrEmpty() ? generateId ? ObjectId.GenerateNewId().ToString() : null : id,
                OrganizationId = organizationId.IsNullOrEmpty() ? TestConstants.OrganizationId : organizationId,
                ProjectId = projectId.IsNullOrEmpty() ? TestConstants.ProjectIds.Random() : projectId,
                Title = RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 50))
            };

            for (int i = 0; i < RandomHelper.GetRange(0, 5); i++) {
                string tag = RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 15));
                while (stack.Tags.Contains(tag))
                    tag = RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 15));

                stack.Tags.Add(tag);
            }

            return stack;
        }
        public override void Process(EventContext ctx) {
            if (String.IsNullOrEmpty(ctx.Event.StackId)) {
                if (_stackRepository == null)
                    throw new InvalidOperationException("You must pass a non-null stackRepository parameter to the constructor.");

                // only add default signature info if no other signature info has been added
                if (ctx.StackSignatureData.Count == 0) {
                    ctx.StackSignatureData.Add("Type", ctx.Event.Type);
                    if (!String.IsNullOrEmpty(ctx.Event.Source))
                        ctx.StackSignatureData.Add("Source", ctx.Event.Source);
                }

                string signatureHash = ctx.StackSignatureData.Values.Any(v => v != null) ? ctx.StackSignatureData.Values.ToSHA1() : null;
                ctx.SetProperty("__SignatureHash", signatureHash);

                ctx.StackInfo = _stackRepository.GetStackInfoBySignatureHash(ctx.Event.ProjectId, signatureHash);
                if (ctx.StackInfo == null) {
                    Log.Trace().Message("Creating new error stack.").Write();
                    ctx.IsNew = true;
                    var stack = new Stack {
                        OrganizationId = ctx.Event.OrganizationId,
                        ProjectId = ctx.Event.ProjectId,
                        SignatureInfo = new SettingsDictionary(ctx.StackSignatureData),
                        SignatureHash = signatureHash,
                        Title = _pluginManager.GetStackTitle(ctx.Event),
                        SummaryHtml = _pluginManager.GetStackSummaryHtml(ctx.Event),
                        Tags = ctx.Event.Tags ?? new TagSet(),
                        TotalOccurrences = 1,
                        FirstOccurrence = ctx.Event.Date.UtcDateTime,
                        LastOccurrence = ctx.Event.Date.UtcDateTime
                    };

                    ctx.Stack = _stackRepository.Add(stack, true);
                    ctx.StackInfo = new StackInfo {
                        Id = stack.Id,
                        DateFixed = stack.DateFixed,
                        OccurrencesAreCritical = stack.OccurrencesAreCritical
                    };

                    // new 404 stack id added, invalidate 404 id cache
                    if (ctx.Event.IsNotFound())
                        _stackRepository.InvalidateNotFoundIdsCache(ctx.Event.ProjectId);
                }

                Log.Trace().Message("Updating error's ErrorStackId to: {0}", ctx.StackInfo.Id).Write();
                ctx.Event.StackId = ctx.StackInfo.Id;
            } else {
                ctx.Stack = _stackRepository.GetById(ctx.Event.StackId);

                // TODO: Update unit tests to work with this check.
                //if (stack == null || stack.ProjectId != error.ProjectId)
                //    throw new InvalidOperationException("Invalid ErrorStackId.");
                if (ctx.Stack == null)
                    return;

                ctx.SetProperty("__SignatureHash", ctx.Stack.SignatureHash);

                if (ctx.Event.Tags != null && ctx.Event.Tags.Count > 0) {
                    if (ctx.Stack.Tags == null)
                        ctx.Stack.Tags = new TagSet();

                    List<string> newTags = ctx.Event.Tags.Where(t => !ctx.Stack.Tags.Contains(t)).ToList();
                    if (newTags.Count > 0) {
                        ctx.Stack.Tags.AddRange(newTags);
                        _stackRepository.Save(ctx.Stack);
                    }
                }

                ctx.StackInfo = new StackInfo {
                    Id = ctx.Stack.Id,
                    DateFixed = ctx.Stack.DateFixed,
                    OccurrencesAreCritical = ctx.Stack.OccurrencesAreCritical,
                    IsHidden = ctx.Stack.IsHidden,
                };
            }

            // sync the fixed and hidden flags to the error occurrence
            ctx.Event.IsFixed = ctx.StackInfo.DateFixed.HasValue;
            ctx.Event.IsHidden = ctx.StackInfo.IsHidden;

            ctx.Event.SummaryHtml = _pluginManager.GetEventSummaryHtml(ctx.Event);
        }
        public override void Process(EventContext ctx) {
            if (String.IsNullOrEmpty(ctx.Event.StackId)) {
                if (_stackRepository == null)
                    throw new InvalidOperationException("You must pass a non-null stackRepository parameter to the constructor.");

                // only add default signature info if no other signature info has been added
                if (ctx.StackSignatureData.Count == 0) {
                    ctx.StackSignatureData.Add("Type", ctx.Event.Type);
                    if (!String.IsNullOrEmpty(ctx.Event.Source))
                        ctx.StackSignatureData.Add("Source", ctx.Event.Source);
                }

                string signatureHash = ctx.StackSignatureData.Values.Any(v => v != null) ? ctx.StackSignatureData.Values.ToSHA1() : null;
                ctx.SetProperty("__SignatureHash", signatureHash);

                ctx.Stack = _stackRepository.GetStackBySignatureHash(ctx.Event.ProjectId, signatureHash);
                if (ctx.Stack == null) {
                    Log.Trace().Message("Creating new error stack.").Write();
                    ctx.IsNew = true;
                    ctx.Event.IsFirstOccurrence = true;

                    string title = _formattingPluginManager.GetStackTitle(ctx.Event);
                    var stack = new Stack {
                        OrganizationId = ctx.Event.OrganizationId,
                        ProjectId = ctx.Event.ProjectId,
                        SignatureInfo = new SettingsDictionary(ctx.StackSignatureData),
                        SignatureHash = signatureHash,
                        Title = title != null ? title.Truncate(1000) : null,
                        Tags = ctx.Event.Tags ?? new TagSet(),
                        Type = ctx.Event.Type,
                        TotalOccurrences = 1,
                        FirstOccurrence = ctx.Event.Date.UtcDateTime,
                        LastOccurrence = ctx.Event.Date.UtcDateTime
                    };

                    ctx.Stack = _stackRepository.Add(stack, true);
                }

                Log.Trace().Message("Updating error's StackId to: {0}", ctx.Stack.Id).Write();
                ctx.Event.StackId = ctx.Stack.Id;
            } else {
                ctx.Stack = _stackRepository.GetById(ctx.Event.StackId, true);

                if (ctx.Stack == null || ctx.Stack.ProjectId != ctx.Event.ProjectId)
                    throw new ApplicationException("Invalid StackId.");

                ctx.SetProperty("__SignatureHash", ctx.Stack.SignatureHash);
            }

            if (!ctx.IsNew && ctx.Event.Tags != null && ctx.Event.Tags.Count > 0) {
                if (ctx.Stack.Tags == null)
                    ctx.Stack.Tags = new TagSet();

                List<string> newTags = ctx.Event.Tags.Where(t => !ctx.Stack.Tags.Contains(t)).ToList();
                if (newTags.Count > 0) {
                    ctx.Stack.Tags.AddRange(newTags);
                    _stackRepository.Save(ctx.Stack, true);
                }
            }

            // sync the fixed and hidden flags to the error occurrence
            ctx.Event.IsFixed = ctx.Stack.DateFixed.HasValue;
            ctx.Event.IsHidden = ctx.Stack.IsHidden;
        }