public async Task CreateOrganizationAndProjectAsync(string userId) {
            if (await _tokenRepository.GetByIdAsync(TEST_API_KEY).AnyContext() != null)
                return;

            User user = await _userRepository.GetByIdAsync(userId, true).AnyContext();
            var organization = new Organization { Id = TEST_ORG_ID, Name = "Acme" };
            BillingManager.ApplyBillingPlan(organization, BillingManager.UnlimitedPlan, user);
            organization = await _organizationRepository.AddAsync(organization, true).AnyContext();

            var project = new Project { Id = TEST_PROJECT_ID, Name = "Disintegrating Pistol", OrganizationId = organization.Id };
            project.NextSummaryEndOfDayTicks = DateTime.UtcNow.Date.AddDays(1).AddHours(1).Ticks;
            project.Configuration.Settings.Add("IncludeConditionalData", "true");
            project.AddDefaultOwnerNotificationSettings(userId);
            project = await _projectRepository.AddAsync(project, true).AnyContext();

            await _tokenRepository.AddAsync(new Token {
                Id = TEST_API_KEY,
                OrganizationId = organization.Id,
                ProjectId = project.Id,
                CreatedUtc = DateTime.UtcNow,
                ModifiedUtc = DateTime.UtcNow,
                Type = TokenType.Access
            }).AnyContext();

            await _tokenRepository.AddAsync(new Token {
                Id = TEST_USER_API_KEY,
                UserId = user.Id,
                CreatedUtc = DateTime.UtcNow,
                ModifiedUtc = DateTime.UtcNow,
                Type = TokenType.Access
            }).AnyContext();

            user.OrganizationIds.Add(organization.Id);
            await _userRepository.SaveAsync(user, true).AnyContext();
        }
Esempio n. 2
0
        public async Task<bool> CanAddProjectAsync(Project project) {
            if (String.IsNullOrWhiteSpace(project?.OrganizationId))
                return false;

            var organization = await _organizationRepository.GetByIdAsync(project.OrganizationId).AnyContext();
            if (organization == null)
                return false;

            long projectCount = await _projectRepository.GetCountByOrganizationIdAsync(project.OrganizationId).AnyContext();
            return organization.MaxProjects == -1 || projectCount < organization.MaxProjects;
        }
Esempio n. 3
0
        public bool CanAddProject(Project project) {
            if (project == null || String.IsNullOrWhiteSpace(project.OrganizationId))
                return false;

            var organization = _organizationRepository.GetById(project.OrganizationId);
            if (organization == null)
                return false;

            long projectCount = _projectRepository.GetCountByOrganizationId(project.OrganizationId);
            return organization.MaxProjects == -1 || projectCount < organization.MaxProjects;
        }
        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. 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 < RandomData.GetInt(0, 5); i++) {
                string key = RandomData.GetWord();
                while (project.Configuration.Settings.ContainsKey(key))
                    key = RandomData.GetWord();

                project.Configuration.Settings.Add(key, RandomData.GetWord());
            }

            return project;
        }
        public async Task CreateInternalOrganizationAndProjectAsync(string userId) {
            if (await _tokenRepository.GetByIdAsync(INTERNAL_API_KEY).AnyContext() != null)
                return;

            User user = await _userRepository.GetByIdAsync(userId, true).AnyContext();
            var organization = new Organization { Name = "Exceptionless" };
            BillingManager.ApplyBillingPlan(organization, BillingManager.UnlimitedPlan, user);
            organization = await _organizationRepository.AddAsync(organization, true).AnyContext();

            var project = new Project { Id = INTERNAL_PROJECT_ID, Name = "API", OrganizationId = organization.Id };
            project.NextSummaryEndOfDayTicks = DateTime.UtcNow.Date.AddDays(1).AddHours(1).Ticks;
            project.AddDefaultOwnerNotificationSettings(userId);
            project = await _projectRepository.AddAsync(project, true).AnyContext();

            await _tokenRepository.AddAsync(new Token {
                Id = INTERNAL_API_KEY,
                OrganizationId = organization.Id,
                ProjectId = project.Id,
                CreatedUtc = DateTime.UtcNow,
                ModifiedUtc = DateTime.UtcNow,
                Type = TokenType.Access
            }).AnyContext();

            user.OrganizationIds.Add(organization.Id);
            await _userRepository.SaveAsync(user, true).AnyContext();
        }
Esempio n. 8
0
        public string CreateDefaultOrganizationAndProject(User user) {
            string organizationId = user.OrganizationIds.FirstOrDefault();
            if (!String.IsNullOrEmpty(organizationId)) {
                var defaultProject = _projectRepository.GetByOrganizationId(user.OrganizationIds.First(), useCache: true).Documents.FirstOrDefault();
                if (defaultProject != null)
                    return defaultProject.Id;
            } else {
                var organization = new Organization {
                    Name = "Default Organization"
                };
                BillingManager.ApplyBillingPlan(organization, Settings.Current.EnableBilling ? BillingManager.FreePlan : BillingManager.UnlimitedPlan, user);
                _organizationRepository.Add(organization);
                organizationId = organization.Id;
            }

            var project = new Project { Name = "Default Project", OrganizationId = organizationId };
            project.NextSummaryEndOfDayTicks = DateTime.UtcNow.Date.AddDays(1).AddHours(1).Ticks;
            project.AddDefaultOwnerNotificationSettings(user.Id);
            project = _projectRepository.Add(project);
            
            _tokenRepository.Add(new Token {
                Id = StringExtensions.GetNewToken(),
                OrganizationId = organizationId,
                ProjectId = project.Id,
                CreatedUtc = DateTime.UtcNow,
                ModifiedUtc = DateTime.UtcNow,
                Type = TokenType.Access
            });

            if (!user.OrganizationIds.Contains(organizationId)) {
                user.OrganizationIds.Add(organizationId);
                _userRepository.Save(user, true);
            }

            return project.Id;
        }
Esempio n. 9
0
 public static void SetProject(this HttpRequestMessage message, Project project) {
     message?.GetOwinContext().Set("Project", project);
 }