Esempio n. 1
0
        public void TestInitialize()
        {
            Queue <string> queue = new Queue <string>(new string[] { "first" });

            GithubContext context = new GithubContext(queue);

            issuesApi = new IssuesApi(context);
        }
Esempio n. 2
0
 /// <summary>
 /// 保存一组数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="datas"></param>
 public void SaveRangeData <T>(IEnumerable <T> datas) where T : IRepo
 {
     using (GithubContext github = new GithubContext())
     {
         if (typeof(T) == typeof(TrendingRepo))
         {
             github.TrendingEntities.AddRange(datas as IEnumerable <TrendingRepo>);
         }
         else if (typeof(T) == typeof(ThemeRepo))
         {
             github.ThemeEntities.AddRange(datas as IEnumerable <ThemeRepo>);
         }
         github.SaveChanges();
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 保存一条数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 public void SaveData <T>(T data) where T : IRepo
 {
     using (GithubContext github = new GithubContext())
     {
         if (typeof(T) == typeof(TrendingRepo))
         {
             github.TrendingEntities.Add(data as TrendingRepo);
         }
         else if (typeof(T) == typeof(ThemeRepo))
         {
             github.ThemeEntities.Add(data as ThemeRepo);
         }
         github.SaveChanges();
     }
 }
        /// <summary>
        /// Implements the <see cref="ProcessRecord"/> method for <see cref="RemoveGithubCredentialsCmdlet"/>.
        /// </summary>
        protected override void ProcessRecord()
        {
            try
            {
                GithubContext.Dispose();

                if (DeletePermanent.IsPresent)
                {
                    AuthService.RemoveConfig();
                }
            }
            catch (Exception e)
            {
                ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to remove credentials with error: {e.Message}", e), null, ErrorCategory.OperationStopped, null));
            }
        }
Esempio n. 5
0
        private async void btnStart_Click(object sender, EventArgs e)
        {
            txtProgressCount.Text  = "0";
            progressBarPages.Value = progressBarPages.Minimum;

            GetAccessTokens();

            string issuesFolderPath = IssuesFolderPath();

            Uri           uri           = new Uri(string.Format("https://api.github.com/repos/{0}/{1}/issues?page=1&state={2}", tbxRepoOwner.Text, tbxRepoName.Text, GetStateString()));
            GithubContext githubContext = new GithubContext(accessTokens);

            int numPages = await githubContext.GetNumPagesAsync(uri);

            progressBarPages.Maximum = numPages;


            var progress = new Progress <ProgressBundle>();

            progress.ProgressChanged += Progress_ProgressChanged;

            await Task.Run(() => GetIssuesWorker(0, numPages, issuesFolderPath, githubContext, progress));
        }
Esempio n. 6
0
 public Gitcontroller(GithubContext context)//the database context
 {
     _context = context;
 }
Esempio n. 7
0
        private void GetIssuesWorker(int pageFrom, int pageTo, string issuesFolderPath, GithubContext githubContext, IProgress <ProgressBundle> progress)
        {
            GithubApi githubApi = new GithubApi(githubContext);

            var queryStringDict = new Dictionary <string, string>();

            queryStringDict.Add("page", pageFrom.ToString());
            string fetchTypeString = GetStateString();

            queryStringDict.Add("state", fetchTypeString);

            ParallelOptions optionsPages  = new ParallelOptions();
            ParallelOptions optionsIssues = new ParallelOptions();

            optionsPages.MaxDegreeOfParallelism  = 2;
            optionsIssues.MaxDegreeOfParallelism = 2;
            Parallel.For(pageFrom, pageTo, optionsPages, (page, loopState) =>
            {
                var localDict     = new Dictionary <string, string>(queryStringDict);
                localDict["page"] = page.ToString();

                List <Issue> issues = githubApi.IssuesApi.Get(tbxRepoOwner.Text, tbxRepoName.Text, localDict);

                if (issues.Count == 0)
                {
                    loopState.Break();
                }

                Parallel.ForEach(issues, optionsIssues, issue =>
                {
                    List <Comment> comments = null;
                    if (cbxFetchComments.Checked)
                    {
                        comments = githubApi.CommentsApi.Get(issue);
                    }

                    SaveIssue(issue, comments, issuesFolderPath, page);

                    progress.Report(new ProgressBundle {
                        RequestsRemaining = githubContext.RequestsRemaining, UpdatePagesProgressBar = false, CountTokens = githubContext.CountTokens
                    });
                });

                progress.Report(new ProgressBundle {
                    RequestsRemaining = githubContext.RequestsRemaining, UpdatePagesProgressBar = true, CountTokens = githubContext.CountTokens
                });
            });
        }
Esempio n. 8
0
 public GithubApi(GithubContext githubContext)
 {
     this.githubContext = githubContext;
 }
Esempio n. 9
0
 public GithubController(GithubContext context)
 {
     _context = context;
 }