コード例 #1
0
        private SearchCodeRequest getSearchCodeRequest(Model.SearchCodeRequestParameters parameters)
        {
            SearchCodeRequest codeRequest;

            try
            {
                codeRequest = new SearchCodeRequest(parameters.Term);
            }
            catch (Exception)
            {
                codeRequest = new SearchCodeRequest();
            }

            Language language = (Language)Enum.Parse(typeof(Language), parameters.Language);

            codeRequest.Language  = language;
            codeRequest.Path      = parameters.Path;
            codeRequest.User      = parameters.Owner;
            codeRequest.FileName  = parameters.FileName;
            codeRequest.Extension = parameters.Extension;
            codeRequest.Forks     = getBoolParameter(parameters.ForksIncluded);
            codeRequest.Size      = pickRange(parameters.SizeChoice, parameters.Size);
            codeRequest.In        = getPathIncludedParameter(parameters.PathIncluded, parameters.Term);

            return(codeRequest);
        }
コード例 #2
0
        public async Task <int> getNumberOfPages(Model.SearchCodeRequestParameters requestParameters)
        {
            SearchCodeRequest codeRequest = getSearchCodeRequest(requestParameters);
            SearchCodeResult  result      = await GlobalVariables.client.Search.SearchCode(codeRequest);

            if (result.TotalCount == 0)
            {
                return(0);
            }

            if (result.TotalCount > 1000)
            {
                return(GlobalVariables.MaximumNumberOfPages);
            }

            if (result.TotalCount % codeRequest.PerPage == 0)
            {
                return(result.TotalCount / codeRequest.PerPage);
            }

            return(result.TotalCount / codeRequest.PerPage + 1);
        }
コード例 #3
0
        public async Task <List <File> > searchCode(Model.SearchCodeRequestParameters requestParameters, int firstPage, int lastPage)
        {
            List <File>       files       = new List <File>();
            SearchCodeRequest codeRequest = getSearchCodeRequest(requestParameters);

            for (int i = firstPage; i <= lastPage; i++)
            {
                codeRequest.Page = i;
                SearchCodeResult result = await GlobalVariables.client.Search.SearchCode(codeRequest).ConfigureAwait(false);

                files.AddRange(result.Items.Select(file => new Model.File
                {
                    Name     = file.Name,
                    Path     = file.Path,
                    RepoName = file.Repository.Name,
                    Owner    = file.Repository.Owner.Login,
                    HtmlUrl  = file.HtmlUrl
                }).ToList());
            }

            return(files);
        }