Пример #1
0
        public bool CanAddProject(Project project) {
            if (project == null || String.IsNullOrWhiteSpace(project.OrganizationId))
                return false;

            var organization = _organizationRepository.GetById(project.OrganizationId);
            return organization.MaxProjects == -1 || organization.ProjectCount < organization.MaxProjects;
        }
Пример #2
0
        public static Project GenerateProject(bool generateId = false, string id = null, string organizationId = null, string name = null, List<string> apiKeys = null, string timeZone = "Central Standard Time", Int64? nextSummaryEndOfDayTicks = null)
        {
            var project = new Project {
                Id = id.IsNullOrEmpty() ? generateId ? ObjectId.GenerateNewId().ToString() : String.Empty : id,
                OrganizationId = organizationId.IsNullOrEmpty() ? TestConstants.OrganizationId : organizationId,
                Name = name ?? String.Format("Project{0}", id),
                TimeZone = timeZone ?? "Central Standard Time"
            };

            if (nextSummaryEndOfDayTicks.HasValue)
                project.NextSummaryEndOfDayTicks = nextSummaryEndOfDayTicks.Value;
            else {
                TimeZoneInfo tzi;
                try {
                    tzi = TimeZoneInfo.FindSystemTimeZoneById(project.TimeZone);
                } catch {
                    tzi = TimeZoneInfo.Local;
                }

                project.NextSummaryEndOfDayTicks = TimeZoneInfo.ConvertTime(DateTime.Today.AddDays(1), tzi).ToUniversalTime().Ticks;
            }

            for (int i = 0; i < RandomHelper.GetRange(0, 5); i++)
                project.Configuration.Settings.Add(RandomHelper.GetPronouncableString(5), RandomHelper.GetPronouncableString(10));

            if (apiKeys != null)
                project.ApiKeys.AddRange(apiKeys);

            for (int i = 0; i < RandomHelper.GetRange(0, 5); i++)
                project.ApiKeys.Add(Guid.NewGuid().ToString());

            return project;
        }
        public static ErrorStack ToProjectLocalTime(this ErrorStack errorStack, Project project) {
            if (errorStack == null)
                return null;

            if (errorStack.DateFixed.HasValue)
                errorStack.DateFixed = TimeZoneInfo.ConvertTime(errorStack.DateFixed.Value, project.DefaultTimeZone());

            errorStack.FirstOccurrence = TimeZoneInfo.ConvertTime(errorStack.FirstOccurrence, project.DefaultTimeZone());
            errorStack.LastOccurrence = TimeZoneInfo.ConvertTime(errorStack.LastOccurrence, project.DefaultTimeZone());

            return errorStack;
        }
        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;
        }
Пример #6
0
        public static Project GenerateProject(bool generateId = false, string id = null, string organizationId = null, string name = null, Int64? nextSummaryEndOfDayTicks = null) {
            var project = new Project {
                Id = id.IsNullOrEmpty() ? generateId ? ObjectId.GenerateNewId().ToString() : String.Empty : id,
                OrganizationId = organizationId.IsNullOrEmpty() ? TestConstants.OrganizationId : organizationId,
                Name = name ?? String.Format("Project{0}", id)
            };

            if (nextSummaryEndOfDayTicks.HasValue)
                project.NextSummaryEndOfDayTicks = nextSummaryEndOfDayTicks.Value;
            else {
                project.NextSummaryEndOfDayTicks = DateTime.UtcNow.Date.AddDays(1).AddHours(1).Ticks;
            }

            for (int i = 0; i < RandomHelper.GetRange(0, 5); i++)
                project.Configuration.Settings.Add(RandomHelper.GetPronouncableString(5), RandomHelper.GetPronouncableString(10));

            return project;
        }
Пример #7
0
        private ProjectModel PopulateProjectModel(Project project) {
            ProjectModel proj = Mapper.Map<Project, ProjectModel>(project);
            NotificationSettings notificationSettings = project.GetNotificationSettings(User.UserEntity.Id) ?? new NotificationSettings();
            proj.Mode = notificationSettings.Mode;
            proj.SendDailySummary = notificationSettings.SendDailySummary;
            proj.ReportCriticalErrors = notificationSettings.ReportCriticalErrors;
            proj.ReportRegressions = notificationSettings.ReportRegressions;
            proj.Report404Errors = notificationSettings.Report404Errors;
            proj.ReportKnownBotErrors = notificationSettings.ReportKnownBotErrors;
            proj.OrganizationName = _organizationRepository.GetByIdCached(project.OrganizationId).Name;
            proj.UserId = User.UserEntity.Id;

            return proj;
        }
Пример #8
0
        public ActionResult Add(ProjectModel model) {
            ViewBag.Organizations = Organizations;
            ViewBag.HasOrganizations = Organizations.Any();
            ViewBag.TimeZones = TimeZoneInfo.GetSystemTimeZones();

            #region Validation

            Organization organization = null;

            if (!String.IsNullOrEmpty(model.OrganizationName)) {
                Organization existing = Organizations.FirstOrDefault(o => o.Name == model.OrganizationName);
                organization = existing ?? new Organization { Name = model.OrganizationName.Trim() };
            } else if (!String.IsNullOrEmpty(model.OrganizationId)) {
                organization = Organizations.FirstOrDefault(o => o.Id == model.OrganizationId);
                ModelState state = ModelState["OrganizationName"];
                if (state != null)
                    state.Errors.Clear();
            }

            if (!ModelState.IsValid)
                return View(model);

            if (organization == null) {
                ModelState.AddModelError("OrganizationName", "Organization Name is required.");
                return View(model);
            }

            if (!String.IsNullOrEmpty(organization.Id) && Projects.Count(p => p.OrganizationId == organization.Id && String.Equals(p.Name, model.Name, StringComparison.OrdinalIgnoreCase)) > 0) {
                ModelState.AddModelError("Name", "A project with this name already exists.");
                return View(model);
            }

            #endregion

            if (String.IsNullOrEmpty(organization.Id)) {
                if (!_billingManager.CanAddOrganization(User.UserEntity)) {
                    ModelState.AddModelError(String.Empty, "Please upgrade your plan to add an additional organization.");
                    return View(model);
                }

                _billingManager.ApplyBillingPlan(organization, Settings.Current.EnableBilling ? BillingManager.FreePlan : BillingManager.UnlimitedPlan, User.UserEntity);
                organization = _organizationRepository.Add(organization, true);

                User user = _userRepository.GetById(User.UserEntity.Id);
                user.OrganizationIds.Add(organization.Id);
                _userRepository.Update(user);

                _notificationSender.OrganizationUpdated(organization.Id);
            }

            var project = new Project { Name = model.Name, TimeZone = model.TimeZone, OrganizationId = organization.Id };
            project.NextSummaryEndOfDayTicks = TimeZoneInfo.ConvertTime(DateTime.Today.AddDays(1), project.DefaultTimeZone()).ToUniversalTime().Ticks;
            project.ApiKeys.Add(Guid.NewGuid().ToString("N").ToLower());
            project.AddDefaultOwnerNotificationSettings(User.UserEntity.Id);

            if (!_billingManager.CanAddProject(project)) {
                ModelState.AddModelError(String.Empty, "Please upgrade your plan to add an additional project.");
                return View(model);
            }

            project = _projectRepository.Add(project);

            _organizationRepository.IncrementStats(project.OrganizationId, projectCount: 1);
            _notificationSender.ProjectUpdated(organization.Id, project.Id);

            return RedirectToAction("Configure", "Project", new { id = project.Id });
        }
Пример #9
0
        public bool CanAddIntegration(Project project) {
            if (project == null || String.IsNullOrWhiteSpace(project.OrganizationId))
                return false;

            return HasPremiumFeatures(project.OrganizationId);
        }
Пример #10
0
        public void CreateSampleOrganizationAndProject(string userId) {
            if (_projectRepository.GetByApiKey(SAMPLE_API_KEY) != null)
                return;

            User user = _userRepository.GetByIdCached(userId);
            var organization = new Organization { Name = "Acme" };
            _billingManager.ApplyBillingPlan(organization, BillingManager.UnlimitedPlan, user);
            organization = _organizationRepository.Add(organization);

            var project = new Project { Name = "Disintegrating Pistol", TimeZone = TimeZone.CurrentTimeZone.StandardName, OrganizationId = organization.Id };
            project.NextSummaryEndOfDayTicks = TimeZoneInfo.ConvertTime(DateTime.Today.AddDays(1), project.DefaultTimeZone()).ToUniversalTime().Ticks;
            project.ApiKeys.Add(SAMPLE_API_KEY);
            project.Configuration.Settings.Add("IncludeConditionalData", "true");
            project.AddDefaultOwnerNotificationSettings(userId);
            project = _projectRepository.Add(project);

            _organizationRepository.IncrementStats(project.OrganizationId, projectCount: 1);

            user.OrganizationIds.Add(organization.Id);
            _userRepository.Update(user);
        }
Пример #11
0
        public void CreateSampleOrganizationAndProject(string userId) {
            if (_tokenRepository.GetById(SAMPLE_API_KEY) != null)
                return;

            User user = _userRepository.GetById(userId, true);
            var organization = new Organization { Id = "537650f3b77efe23a47914f3", Name = "Acme" };
            _billingManager.ApplyBillingPlan(organization, BillingManager.UnlimitedPlan, user);
            organization = _organizationRepository.Add(organization);

            var project = new Project { Id = "537650f3b77efe23a47914f4", Name = "Disintegrating Pistol", TimeZone = TimeZone.CurrentTimeZone.StandardName, OrganizationId = organization.Id };
            project.NextSummaryEndOfDayTicks = TimeZoneInfo.ConvertTime(DateTime.Today.AddDays(1), project.DefaultTimeZone()).ToUniversalTime().Ticks;
            project.Configuration.Settings.Add("IncludeConditionalData", "true");
            project.AddDefaultOwnerNotificationSettings(userId);
            project = _projectRepository.Add(project);

            _tokenRepository.Add(new Token {
                Id = SAMPLE_API_KEY,
                OrganizationId = organization.Id,
                ProjectId = project.Id,
                ExpiresUtc = DateTime.UtcNow.AddYears(100),
                CreatedUtc = DateTime.UtcNow,
                ModifiedUtc = DateTime.UtcNow,
                Type = TokenType.Access
            });

            _tokenRepository.Add(new Token {
                Id = SAMPLE_USER_API_KEY,
                OrganizationId = organization.Id,
                UserId = user.Id,
                ExpiresUtc = DateTime.UtcNow.AddYears(100),
                CreatedUtc = DateTime.UtcNow,
                ModifiedUtc = DateTime.UtcNow,
                Type = TokenType.Access
            });

            _organizationRepository.IncrementStats(project.OrganizationId, projectCount: 1);

            user.OrganizationIds.Add(organization.Id);
            _userRepository.Save(user);
        }
        private ProjectModel PopulateProjectModel(Project project) {
            var user = GetUser();
            ProjectModel p = Mapper.Map<Project, ProjectModel>(project);
            NotificationSettings notificationSettings = project.GetNotificationSettings(user.Id) ?? new NotificationSettings();
            p.Mode = notificationSettings.Mode;
            p.SendDailySummary = notificationSettings.SendDailySummary;
            p.ReportCriticalErrors = notificationSettings.ReportCriticalErrors;
            p.ReportRegressions = notificationSettings.ReportRegressions;
            p.Report404Errors = notificationSettings.Report404Errors;
            p.ReportKnownBotErrors = notificationSettings.ReportKnownBotErrors;
            p.OrganizationName = _organizationRepository.GetById(project.OrganizationId, true).Name;
            p.UserId = user.Id;

            return p;
        }
 public ExceptionlessPrincipal(Project project) {
     Project = project;
     Identity = new GenericIdentity(project.Id, "ApiKey");
     _roles.Add(AuthorizationRoles.Client);
 }