public async Task AddHookValid()
        {
            var config = new TriggrConfig();

            config.Url     = "http://www.triggr.com/";
            config.Webhook = true;

            var repo = new Data.Repository();

            repo.Token     = "1";
            repo.Url       = "http://github.com/lyzerk/TriggrTestProject";
            repo.OwnerName = "lyzerk";
            repo.Name      = "TriggrTestProject";

            var mockResult = new RepositoryHook(1, null, null, null, DateTimeOffset.Now, DateTimeOffset.Now, null, null, false, null);
            var mockConfig = new Mock <IOptions <TriggrConfig> >();
            var mockClient = new Mock <GithubWrapper>();

            mockConfig.Setup(i => i.Value).Returns(config);
            mockClient.Setup(i => i.CreateWebhook(repo.OwnerName, repo.Name, config.Url + "GithubWebhook/HandlerForPush", "1"))
            .ReturnsAsync(mockResult);

            WebhookService service = new WebhookService(null, mockConfig.Object, mockClient.Object);

            var result = await service.AddHookAsync(repo);

            Assert.True(result);
            Assert.True(repo.WebHook);
            Assert.NotNull(repo.WebHookId);
        }
        public void Post()
        {
            var obj = Json.CreateNewObject();

            obj = Json.AddKeyValuePair(obj, "title", "test", true);
            obj = Json.AddKeyValuePair(obj, "author", "test", true);
            obj = Json.AddKeyValuePair(obj, "country", "test", true);
            obj = Json.AddKeyValuePair(obj, "link", "test", true);
            obj = Json.AddKeyValuePair(obj, "language", "test", true);
            obj = Json.AddKeyValuePair(obj, "pages", "10", true);
            obj = Json.AddKeyValuePair(obj, "year", "2020", true);
            obj = Json.AddKeyValuePair(obj, "category", "0", true);
            obj = Json.AddKeyValuePair(obj, "imageLink", "test", true);
            obj = Json.AddKeyValuePair(obj, "lendTime", "1", true);
            obj = Json.AddKeyValuePair(obj, "lendType", "0", true);

            Console.WriteLine(obj);

            var repo = new Data.Repository
                       (
                Data.Actions.Type.cataloguePost,
                obj

                       );

            result = repo.result;
        }
Example #3
0
 public override async Task <IEnumerable <Models.SubverseSubmissionSetting> > ExecuteAsync()
 {
     using (var repo = new Data.Repository(User))
     {
         return(await repo.SubverseSubmissionSettingsSearch(_subverseNameLike, _exactMatch));
     }
 }
Example #4
0
        public void Send(Data.Repository repository, Actuator act, string message)
        {
            SmtpClient client = new SmtpClient(_emailConfig.SmtpServer, _emailConfig.Port);

            client.UseDefaultCredentials = false;
            client.Credentials           = new NetworkCredential(_emailConfig.Username, _emailConfig.Password);

            if (_emailConfig.Ssl)
            {
                client.EnableSsl = true;
            }

            MailMessage mailMessage = new MailMessage();

            mailMessage.From = new MailAddress(_emailConfig.From);

            foreach (var to in act.Emails)
            {
                mailMessage.To.Add(to);
            }

            mailMessage.Body    = message;
            mailMessage.Subject = "Triggr Notification";

            client.Send(mailMessage);
        }
Example #5
0
        protected override RuleOutcome EvaluateRule(VoatRuleContext context)
        {
            //bool isModerator = context.UserData.Information.Moderates.Any(x => x.Subverse.Equals(context.Subverse.Name, StringComparison.OrdinalIgnoreCase));
            bool isModerator = ModeratorPermission.IsModerator(context.User, context.Subverse.Name, null);

            // check posting quotas if user is posting to subs they do not moderate
            if (!isModerator)
            {
                // reject if user has reached global daily submission quota
                if (UserDailyGlobalPostingQuotaUsed(context))
                {
                    return(CreateOutcome(RuleResult.Denied, "You have reached your daily global submission quota"));
                }

                // reject if user has reached global hourly submission quota
                if (UserHourlyGlobalPostingQuotaUsed(context))
                {
                    return(CreateOutcome(RuleResult.Denied, "You have reached your hourly global submission quota"));
                }

                // check if user has reached hourly posting quota for target subverse
                if (UserHourlyPostingQuotaForSubUsed(context, context.Subverse.Name))
                {
                    return(CreateOutcome(RuleResult.Denied, "You have reached your hourly submission quota for this subverse"));
                }

                // check if user has reached daily posting quota for target subverse
                if (UserDailyPostingQuotaForSubUsed(context, context.Subverse.Name))
                {
                    return(CreateOutcome(RuleResult.Denied, "You have reached your daily submission quota for this subverse"));
                }
                if (context.Subverse.IsAuthorizedOnly)
                {
                    return(CreateOutcome(RuleResult.Denied, "You are not authorized to submit links or start discussions in this subverse. Please contact subverse moderators for authorization"));
                }
            }

            Domain.Models.UserSubmission userSubmission = context.PropertyBag.UserSubmission;
            if (userSubmission.Type == Domain.Models.SubmissionType.Link)
            {
                using (var repo = new Data.Repository())
                {
                    int crossPostCount = repo.FindUserLinkSubmissionCount(context.UserName, userSubmission.Url, TimeSpan.FromDays(1));
                    if (crossPostCount >= VoatSettings.Instance.DailyCrossPostingQuota)
                    {
                        return(CreateOutcome(RuleResult.Denied, "You have reached your daily crossposting quota for this Url"));
                    }
                }

                //Old code
                //if (UserHelper.DailyCrossPostingQuotaUsed(userName, submissionModel.Content))
                //{
                //    // ABORT
                //    return ("You have reached your daily crossposting quota for this URL.");
                //}
            }

            return(Allowed);
        }
Example #6
0
        public void IsTriggrProjectInvalidPath()
        {
            var data = new Data.Repository();

            Container container = new Container("Title", GetPath("repo2"), data);

            Assert.False(container.IsTriggrProject());
        }
Example #7
0
        public string LastUpdatedFiles(Data.Repository data)
        {
            string result = string.Empty;
            var    path   = _storage.Combine(data.Id);

            result = _scriptExecutor.ExecuteCommon("LastUpdatedFiles", path);

            return(result);
        }
Example #8
0
        private async Task <bool> AddHookGithub(Data.Repository repo)
        {
            var createResult = await _client.CreateWebhook(repo.OwnerName, repo.Name, WebhookUrl(), repo.Token);

            repo.WebHook   = createResult.Id != 0;
            repo.WebHookId = createResult.Id.ToString();

            return(repo.WebHook);
        }
Example #9
0
        public void CheckForProbesWithInvalidPath()
        {
            var data = new Data.Repository();

            Container container = new Container("Title", GetPath("repo2"), data);
            Action    action    = () => container.CheckForProbes();

            Assert.ThrowsAny <DirectoryNotFoundException>(action);
        }
Example #10
0
        public void IsTriggrProjectValidPath()
        {
            var data = new Data.Repository();

            Container container = new Container("Title", GetPath("repo1"), data);

            Assert.Equal("Title", container.Name);
            Assert.True(container.IsTriggrProject());
        }
Example #11
0
        public string Update(Data.Repository data)
        {
            bool result = false;

            var path = _storage.Combine(data.Id);

            result = _git.Update(path);

            return(result ? path : string.Empty);
        }
Example #12
0
        public void CheckForProbesWithValidPathProblematicProbe()
        {
            var data = new Data.Repository();

            Container container = new Container("Title", GetPath("repo5"), data);
            var       probes    = container.CheckForProbes();
            var       first     = probes.FirstOrDefault();

            Assert.Null(first);
        }
Example #13
0
        public string Clone(Data.Repository data)
        {
            var path = _storage.Combine(data.Id);

            var cloneResult = _git.Clone(data.Url, path);

            // hotfix: it was returning a path with .git (e.g. 'repositories/1/.git')
            // but we need absolute path of the repository, so I changed it to path from cloneResult

            return(string.IsNullOrEmpty(cloneResult) ? "" : path);
        }
Example #14
0
        public void OnGet(int id)
        {
            var repo = new Data.Repository
                       (
                Data.Actions.Type.catalogueDelete,
                id
                       );

            this.id = id;
            result  = repo.result;
        }
Example #15
0
        public void UpdateWithNoUpdate()
        {
            var data         = new Data.Repository();
            var mockProvider = new Mock <IProvider>();

            mockProvider.Setup(i => i.Update(data)).Returns(string.Empty);
            Container container = new Container("Title", GetPath("repo1"), data);

            var result = container.Update(mockProvider.Object);

            Assert.Equal(0, result.Count());
        }
Example #16
0
        public async Task <bool> AddHookAsync(Data.Repository repo)
        {
            bool result = false;
            Uri  uri    = new Uri(repo.Url);

            if (uri.Host.Contains("github"))
            {
                result = await AddHookGithub(repo);
            }

            return(result);
        }
Example #17
0
        public void DistributeLoadTest()
        {
            var repository    = new Data.Repository(new Data.CathedraDBDataContext());
            var plan          = repository.GetTableLoadInCoursePlan().Where(x => x.SortLoad.Algorithm == 1);
            var planSumHourse = plan.Sum(x => x.CountHours);
            var classTest     = new DistributeLoadIsOwner(repository);
            var saveData      = false;

            var result          = classTest.DistributeLoad(plan, saveData);
            var resultSumHourse = result.Sum(x => x.CountHours);

            Assert.AreEqual(resultSumHourse, planSumHourse);
        }
Example #18
0
        public void CheckForProbesWithValidPathCodeChangesProbe()
        {
            var data = new Data.Repository();

            Container container = new Container("Title", GetPath("repo3"), data);
            var       probes    = container.CheckForProbes();
            var       first     = probes.FirstOrDefault();

            Assert.NotNull(first);
            Assert.NotNull(first.Id);
            Assert.NotNull(first.Object);
            Assert.Equal(ProbeType.CodeChanges, first.ProbeType);
        }
Example #19
0
        public void CheckForProbesWithValidPathStaticProbe()
        {
            var data = new Data.Repository();

            Container container = new Container("Title", GetPath("repo1"), data);
            var       probes    = container.CheckForProbes();
            var       first     = probes.FirstOrDefault();

            Assert.NotNull(first);
            Assert.NotNull(first.Id);
            Assert.NotNull(first.Object);
            Assert.Equal(ProbeType.StaticAnalysis, first.ProbeType);
            Assert.NotNull(first.Metrics);
        }
Example #20
0
        public void UpdateWithFileList()
        {
            var data         = new Data.Repository();
            var mockProvider = new Mock <IProvider>();

            mockProvider.Setup(i => i.Update(data)).Returns("/");
            mockProvider.Setup(i => i.LastUpdatedFiles(data)).Returns($"test.js{Environment.NewLine}hello.js2{Environment.NewLine}{Environment.NewLine}");
            Container container = new Container("Title", GetPath("repo1"), data);

            var result = container.Update(mockProvider.Object);

            Assert.Equal(2, result.Count());
            Assert.Contains("test.js", result);
            Assert.Contains("hello.js2", result);
        }
Example #21
0
        public bool Exist(Data.Repository data)
        {
            var path = _storage.Combine(data.Id);

            // ensure the directory is created
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                return(false);
            }
            else
            {
                return(_git.IsValid(path));
            }
        }
Example #22
0
        public virtual Task <Issue> CreateIssue(Data.Repository repo, string title, string message, string assigns)
        {
            _client.Credentials = new Credentials(repo.Token);
            var issue = new NewIssue(title);

            issue.Body = message;

            var users = assigns.Split(',');

            foreach (var item in users)
            {
                issue.Assignees.Add(item);
            }

            return(_client.Issue.Create(repo.OwnerName, repo.Name, issue));
        }
Example #23
0
        public bool Restore(Data.Repository data, string fileName, bool previousFile)
        {
            bool result = false;
            // HEAD = last commit, HEAD^ = previous commit of last commit
            var head = previousFile ? "HEAD^" : "HEAD";

            var path = _storage.Combine(data.Id);

            //script returns error messages or empty string.
            var commandResult = _scriptExecutor.ExecuteCommon("Restore", path, head, fileName);

            // if it is empty, no problem with restore process
            result = string.IsNullOrEmpty(commandResult);

            return(result);
        }
        public async Task AddHookInvalid()
        {
            var config = new TriggrConfig();

            config.Url     = "http://www.triggr.com/";
            config.Webhook = true;

            var mock = new Mock <IOptions <TriggrConfig> >();

            mock.Setup(i => i.Value).Returns(config);

            WebhookService service = new WebhookService(null, mock.Object, null);
            var            repo    = new Data.Repository();

            repo.Token = "1";
            repo.Url   = "http://githu1b.com/lyzerk/TriggrTestProject";
            var result = await service.AddHookAsync(repo);

            Assert.False(result);
        }
        public async Task <IActionResult> AddRepository([FromBody] Models.AddRepositoryViewModel model)
        {
            bool result       = false;
            var  providerType = _providerFactory.GetProviderType(model.Url);

            if (ModelState.IsValid && !string.IsNullOrEmpty(providerType))
            {
                var service = _webhookFactory.GetService(model.Url);
                if (service != null)
                {
                    var dbRecord = await _context.Repositories.FirstOrDefaultAsync(i => i.Name.Equals(model.Name) &&
                                                                                   i.OwnerName.Equals(model.Owner));

                    if (dbRecord == null)
                    {
                        Data.Repository repository = new Data.Repository();
                        repository.Provider    = providerType;
                        repository.UpdatedTime = DateTimeOffset.Now;
                        repository.Url         = model.Url;
                        repository.Name        = model.Name;
                        repository.OwnerName   = model.Owner;
                        repository.Token       = model.Token;

                        if (await service.AddHookAsync(repository))
                        {
                            _context.Add(repository);
                            var affected = await _context.SaveChangesAsync();

                            result = affected > 0;
                        }
                    }
                    else
                    {
                        //return already exist
                    }
                }
            }

            return(Json(result));
        }
        public void LoadAllFacilityLocationCriterias()
        {
            Data.Repository respository = new Data.Repository();

            try
            {
                ObservableCollection<FacilityLocationCriteria> facilityLocationCriterias = respository.GetAllFacilityLocationCriterias();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            try
            {
                this.FacilityLocationCriterias = facilityLocationCriterias.ToViewModels();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void LoadAllClientAudits()
        {
            Data.Repository respository = new Data.Repository();

            try
            {
                ObservableCollection<ClientAudit> clientAudits = respository.GetAllClientAudits();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            try
            {
                this.ClientAudits = clientAudits.ToViewModels();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void LoadAllCityStateZips()
        {
            Data.Repository respository = new Data.Repository();

            try
            {
                ObservableCollection<CityStateZip> cityStateZips = respository.GetAllCityStateZips();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            try
            {
                this.CityStateZips = cityStateZips.ToViewModels();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void LoadAllPaymentInfos()
        {
            Data.Repository respository = new Data.Repository();

            try
            {
                ObservableCollection<PaymentInfo> paymentInfos = respository.GetAllPaymentInfos();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            try
            {
                this.PaymentInfos = paymentInfos.ToViewModels();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void LoadAllListingTypes()
        {
            Data.Repository respository = new Data.Repository();

            try
            {
                ObservableCollection<ListingType> listingTypes = respository.GetAllListingTypes();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            try
            {
                this.ListingTypes = listingTypes.ToViewModels();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void LoadAllOfferings()
        {
            Data.Repository respository = new Data.Repository();

            try
            {
                ObservableCollection<Offering> offerings = respository.GetAllOfferings();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            try
            {
                this.Offerings = offerings.ToViewModels();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #32
0
        public void OnGet(int id)
        {
            this.id = id;

            if (id >= 1)
            {
                var repo = new Data.Repository
                           (
                    Data.Actions.Type.catalogueGet,
                    id
                           );
                jsonString = string.Empty;
                product    = repo.product;
            }
            else if (id == 0)
            {
                var repo = new Data.Repository(Data.Actions.Type.catalogueGet);
                products = repo.products;
            }
            else
            {
                jsonString = "Diese ID ist ungültig.";
            }
        }
Example #33
0
 private void btnCreateDb_Click(object sender, EventArgs e)
 {
     var repo = new Data.Repository <Movie>();
 }
Example #34
0
 public void Send(Data.Repository repository, Actuator act, string message)
 {
     _client.CreateIssue(repository, "Triggr Issue", message, act.Assign);
 }
Example #35
0
 public Entities.aspnet_Users GetUserByUserName(string UserName)
 {
     Data.Repository data = new Data.Repository();
     return data.GetUserByUserName(UserName);
 }