Ejemplo n.º 1
0
        private void cmdRunAnalysis_Click(object sender, EventArgs e)
        {
            if (txtCoinID.Text.Equals(string.Empty))
            {
                MessageBox.Show("Please enter Coin ID!"); return;
            }
            if (txtSymbol.Text.Equals(string.Empty))
            {
                MessageBox.Show("Please enter Symbol!"); return;
            }
            if (txtGtRoot.Text.Equals(string.Empty))
            {
                MessageBox.Show("Please enter Github Root!"); return;
            }
            if (txtLeadPrj.Text.Equals(string.Empty))
            {
                MessageBox.Show("Please enter Lead Project or '-'!"); return;
            }

            //** Secret Key
            string strGAuth = ConfigurationManager.AppSettings["gthauth"];

            //** get Token GitHub Info
            ProjectInfoBuilder infoBuild = new ProjectInfoBuilder(strGAuth);
            TokenGitHubInfo    inf       = infoBuild.GetProjectInfo(txtCoinID.Text, txtSymbol.Text, txtGtRoot.Text, txtLeadPrj.Text);

            if (inf.ErrNum > 0)
            {
                //** If there is an error - return, no point to search for repos and commits
                MessageBox.Show("Token Info Error - " + inf.ErrNum.ToString() + "::" + inf.ErrMes);
                return;
            }

            //** Get Repo List
            RepoListCompiler repListComp = new RepoListCompiler(strGAuth);

            repListComp.GetRepoList(inf);

            ContribInfoCompiler ctrbListComp = new ContribInfoCompiler(strGAuth);

            Repo        rpRep    = null;
            List <Repo> lstRepos = inf.RepoList;

            for (int i = 0; i < lstRepos.Count; i++)
            {
                rpRep = lstRepos[i];
                ctrbListComp.GetContribCommits(rpRep, inf.GitHubRoot);
                Thread.Sleep(1000);
            }

            ProjectsLoader ldPrj = new ProjectsLoader();

            if (ldPrj.LoadGitHubInfo(inf, chkIsSingle.Checked) > 0)
            {
                MessageBox.Show(ldPrj.ErrMes);
                return;
            }

            MessageBox.Show("Success!");
        }
Ejemplo n.º 2
0
 public static void SetErr100(TokenGitHubInfo inf, string errmes, string url)
 {
     inf.ReposNumber = "0";
     inf.Followers   = "0";
     inf.CreatedAt   = "0";
     inf.UpdatedAt   = "0";
     inf.ErrMes      = "Dictionary Error: " + errmes;
     inf.ErrNum      = 100;
     inf.Url         = url;
 }
Ejemplo n.º 3
0
 public static void SetErr88(TokenGitHubInfo inf, string errmes, string url)
 {
     inf.ReposNumber = "0";
     inf.Followers   = "0";
     inf.CreatedAt   = "0";
     inf.UpdatedAt   = "0";
     inf.Url         = url;
     inf.ErrMes      = "Jason Error: " + errmes;
     inf.ErrNum      = 8888;
 }
        public int LoadGitHubInfo(TokenGitHubInfo inf, bool truncate)
        {
            StringBuilder sbRepo           = new StringBuilder();
            StringBuilder sbContribCommits = new StringBuilder();
            Repo          rpRepo           = null;
            ContribCommit cbcCommits       = null;

            //sb.Append(inf.CoinID + DL)

            //string RootInfo = inf.CoinID + DL + inf.Symbol + DL + inf.GitHubRoot + DL + inf.ReposNumber + DL + inf.Followers + DL +
            //                  inf.CreatedAt + DL + inf.UpdatedAt + DL + inf.ErrNum.ToString() + DL + inf.ErrMes;

            //File.WriteAllText("rootinfo.txt", RootInfo);
            if (inf.ErrNum > 0)
            {
                LoadInfoDB(inf, truncate); return(inf.ErrNum);
            }

            for (int i = 0; i < inf.RepoList.Count; i++)
            {
                rpRepo = inf.RepoList[i];
                sbRepo.Append(inf.CoinID + DL + inf.Symbol + DL + rpRepo.RepoID + DL + rpRepo.RepoName + DL + rpRepo.Created + DL + rpRepo.Updated + DL +
                              rpRepo.Pushed + DL + rpRepo.Size + DL + rpRepo.Language + DL + rpRepo.Forks + DL + rpRepo.ErrNum.ToString() + DL +
                              rpRepo.ErrMes + DL + rpRepo.Cnt.ToString() + DL + rpRepo.Url + "\n");

                if (rpRepo.Contribs == null)
                {
                    continue;
                }

                for (int k = 0; k < rpRepo.Contribs.Count; k++)
                {
                    cbcCommits = rpRepo.Contribs[k];
                    if (cbcCommits == null)
                    {
                        continue;
                    }
                    sbContribCommits.Append(inf.CoinID + DL + inf.Symbol + DL + rpRepo.RepoID + DL + rpRepo.RepoName + DL + cbcCommits.LoginName + DL +
                                            cbcCommits.Additions + DL + cbcCommits.Deletions + DL + cbcCommits.Commits + DL + cbcCommits.CommTime + DL +
                                            cbcCommits.ErrNum.ToString() + DL + cbcCommits.ErrMes + DL + cbcCommits.Cnt.ToString() + DL + cbcCommits.Url + "\n");
                }
            }

            File.WriteAllText("repoinfo.txt", sbRepo.ToString());
            File.WriteAllText("contribinfo.txt", sbContribCommits.ToString());

            if (LoadInfoDB(inf, truncate) > 0)
            {
                return(intErr);
            }

            return(intErr);
        }
Ejemplo n.º 5
0
        public int GetRepoList(TokenGitHubInfo inf)
        {
            intErr = 0; strErr = "";

            //** Format URL string
            string input = "https://api.github.com/users/" + inf.GitHubRoot + "/repos?page=1&per_page=200&access_token=" + GthAuth;
            // https://api.github.com/users/input-output-hk/repos?page=1&per_page=200
            WebClient currClient = new WebClient();

            currClient.Headers.Add("user-agent", "karloskolley");
            string jsonInput = "";

            try
            {
                jsonInput = currClient.DownloadString(input);
                Thread.Sleep(200);
            }
            catch (Exception ex)
            {
                Repo.SetErr333(inf, ex.Message, input);
                intErr = 333;
                strErr = "No Repos 404 " + ex.Message;
                currClient.Dispose();
                currClient = null;
                return(intErr);
            }

            try
            {
                JArray RepoList = JArray.Parse(jsonInput);
                Thread.Sleep(200);
                inf.RepoList = GetRepos(RepoList, inf.GitHubRoot, input);
            }
            catch (Exception ex)
            {
                Repo.SetErr444(inf, ex.Message, input);
                intErr = 444;
                strErr = ex.Message;
                currClient.Dispose();
                currClient = null;
                return(intErr);
            }

            currClient.Dispose();
            currClient = null;
            GC.Collect();
            Thread.Sleep(100);
            return(intErr);
        }
        private int LoadInfoDB(TokenGitHubInfo inf, bool truncate)
        {
            DbOper dbo = new DbOper();

            if (truncate)
            {
                dbo.TruncateTables();
            }

            dbo.LoadRoot(inf.CoinID, inf.Symbol, inf.GitHubRoot, inf.GitHubLeadPrj, inf.ReposNumber, inf.Followers, inf.CreatedAt,
                         inf.UpdatedAt, inf.ErrNum.ToString(), inf.ErrMes, inf.Url);
            if (dbo.ErrNum > 0)
            {
                intErr = dbo.ErrNum;
                strErr = dbo.ErrMes;
                dbo.CloseConn();
                return(intErr);
            }

            if (inf.ErrNum > 0)
            {
                return(intErr);
            }

            dbo.LoadHithubInfoTable("RepoInfo", "repoinfo.txt");
            if (dbo.ErrNum > 0)
            {
                intErr = dbo.ErrNum;
                strErr = dbo.ErrMes;
                dbo.CloseConn();
                return(intErr);
            }

            dbo.LoadHithubInfoTable("ContribInfo", "contribinfo.txt");
            if (dbo.ErrNum > 0)
            {
                intErr = dbo.ErrNum;
                strErr = dbo.ErrMes;
                dbo.CloseConn();
                return(intErr);
            }

            //dbo.CloseConn();
            return(intErr);
        }
Ejemplo n.º 7
0
        public static void SetErr444(TokenGitHubInfo inf, string errmes, string url)
        {
            Repo rep = new Repo();

            rep.RepoID   = "0";
            rep.RepoName = "N/A";
            rep.Created  = "0";
            rep.Updated  = "0";
            rep.Pushed   = "0";
            rep.Size     = "0";
            rep.Language = "0";
            rep.Forks    = "0";
            inf.ErrMes   = "Repo Array Error: " + errmes;
            inf.ErrNum   = 444;
            inf.Url      = url;
            List <Repo> lstRepo = new List <Repo>();

            lstRepo.Add(rep);
            inf.RepoList = lstRepo;
        }
Ejemplo n.º 8
0
        public int GetProjectInfo(TokenGitHubInfo inf)
        {
            intErr = 0; strErr = "";
            //** Avoid certificate error
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            //** Format URL string
            WebClient currClient = new WebClient();

            currClient.Headers.Add("user-agent", "karloskolley");
            string input     = "https://api.github.com/users/" + inf.GitHubRoot + "?access_token=" + GthAuth;
            string jsonInput = "";

            try
            {
                jsonInput = currClient.DownloadString(input);
            }
            catch (Exception ex)
            {
                inf.ReposNumber = "0";
                inf.Followers   = "0";
                inf.CreatedAt   = "0";
                inf.UpdatedAt   = "0";
                inf.Url         = input;
                intErr          = 8888;
                strErr          = "No Data - " + ex.Message;
                inf.ErrMes      = "Info Error: " + ex.Message;
                inf.ErrNum      = intErr;
                currClient.Dispose();
                currClient = null;
                return(intErr);
            }

            //** Add brakets for array representation
            jsonInput = "[" + jsonInput + "]";

            try
            {
                Dictionary <string, string>[] ccurData = JsonConvert.DeserializeObject <Dictionary <string, string>[]>(jsonInput);
                inf.ReposNumber = ccurData[0]["public_repos"];
                inf.Followers   = ccurData[0]["followers"];
                inf.CreatedAt   = GetStandardTime(ccurData[0]["created_at"]);
                inf.UpdatedAt   = GetStandardTime(ccurData[0]["updated_at"]);
                inf.Url         = input;
            }
            catch (Exception ex)
            {
                intErr          = 100;
                strErr          = ex.Message;
                inf.ReposNumber = "0";
                inf.Followers   = "0";
                inf.CreatedAt   = "0";
                inf.UpdatedAt   = "0";
                inf.Url         = input;
                inf.ErrMes      = "Info Error: " + ex.Message;
                inf.ErrNum      = intErr;
                inf.Url         = input;

                //** Project has error, stop analyser
                currClient.Dispose();
                currClient = null;
                return(intErr);
            }

            currClient.Dispose();
            currClient = null;
            inf.ErrNum = 0;
            inf.ErrMes = "-";
            return(intErr);
        }
Ejemplo n.º 9
0
        public int GetRepoList(TokenGitHubInfo inf)
        {
            intErr = 0; strErr = "";
            //** Avoid certificate error
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            //** Format URL string
            string input = "https://api.github.com/users/" + inf.GitHubRoot + "/repos?access_token=" + GthAuth;
            // https://api.github.com/users/input-output-hk/repos?page=1&per_page=200
            WebClient currClient = new WebClient();

            currClient.Headers.Add("user-agent", "karloskolley");
            string jsonInput = "";

            try
            {
                jsonInput = currClient.DownloadString(input);
            }
            catch (Exception ex)
            {
                Repo rep = new Repo();
                rep.RepoID   = "0";
                rep.RepoName = "No Repos Available";
                rep.Created  = "0";
                rep.Updated  = "0";
                rep.Pushed   = "0";
                rep.Size     = "0";
                rep.Language = "0";
                rep.Forks    = "0";
                intErr       = 333;
                strErr       = ex.Message;
                inf.ErrMes   = "No Repos 404 " + ex.Message;
                inf.ErrNum   = intErr;
                inf.Url      = input;
                List <Repo> lstRepo = new List <Repo>();
                lstRepo.Add(rep);
                inf.RepoList = lstRepo;
                currClient.Dispose();
                currClient = null;
                return(intErr);
            }

            try
            {
                JArray RepoList = JArray.Parse(jsonInput);
                inf.RepoList = GetRepos(RepoList, inf.GitHubRoot, inf.GitHubLeadPrj, input);
            }
            catch (Exception ex)
            {
                Repo rep = new Repo();
                rep.RepoID   = "0";
                rep.RepoName = "No Repos Available";
                rep.Created  = "0";
                rep.Updated  = "0";
                rep.Pushed   = "0";
                rep.Size     = "0";
                string lang = "0";
                rep.Language = "0";
                rep.Forks    = "0";
                intErr       = 444;
                strErr       = ex.Message;
                inf.ErrMes   = "Repo Array Error: " + ex.Message;
                inf.ErrNum   = intErr;
                inf.Url      = input;
                List <Repo> lstRepo = new List <Repo>();
                lstRepo.Add(rep);
                inf.RepoList = lstRepo;
                currClient.Dispose();
                currClient = null;
                return(intErr);
            }

            currClient.Dispose();
            currClient = null;
            return(intErr);
        }
Ejemplo n.º 10
0
        private void cmdRunAll_Click(object sender, EventArgs e)
        {
            int    smallset = 0;
            DbOper dbo      = new DbOper();

            if (chkClean.Checked)
            {
                dbo.TruncateTables();
            }
            if (chkSmall.Checked)
            {
                smallset = 1;
            }

            DataTable dtCoins = dbo.GetCoinsForGitHub(smallset);

            //** Secret Key
            string strGAuth = ConfigurationManager.AppSettings["gthauth"];

            TokenGitHubInfo     inf          = null;
            ProjectInfoBuilder  infoBuild    = new ProjectInfoBuilder(strGAuth);
            RepoListCompiler    repListComp  = new RepoListCompiler(strGAuth);
            ContribInfoCompiler ctrbListComp = new ContribInfoCompiler(strGAuth);
            ProjectsLoader      ldPrj        = new ProjectsLoader();
            Repo        rpRep    = null;
            List <Repo> lstRepos = null;;
            string      lprj     = "";

            foreach (DataRow dr in dtCoins.Rows)
            {
                lprj = dr[3].ToString().Replace("/", "");
                if (lprj.Length > 20)
                {
                    lprj = "-";
                }
                if (lprj.Equals(""))
                {
                    lprj = "-";
                }
                inf = infoBuild.GetProjectInfo(dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), lprj);

                //** Get Repo List
                repListComp.GetRepoList(inf);

                lstRepos = inf.RepoList;

                for (int i = 0; i < lstRepos.Count; i++)
                {
                    rpRep = lstRepos[i];
                    ctrbListComp.GetContribCommits(rpRep, inf.GitHubRoot);
                    Thread.Sleep(3000);
                }

                ldPrj.LoadGitHubInfo(inf, false);

                //if (ldPrj.LoadGitHubInfo(inf, false) > 0)
                //{
                //    //MessageBox.Show(ldPrj.ErrMes);
                //    //continue;
                //}

                Thread.Sleep(2000);
            }

            MessageBox.Show("Success!");
        }
        public TokenGitHubInfo GetProjectInfo(string coinid, string symbol, string githubroot, string leadproj)
        {
            intErr = 0; strErr = "";
            //** Avoid certificate error
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            //** Format URL string
            WebClient currClient = new WebClient();

            currClient.Headers.Add("user-agent", "karloskolley");
            string input     = "https://api.github.com/users/" + githubroot + "?access_token=" + GthAuth;
            string jsonInput = "";

            TokenGitHubInfo inf = new TokenGitHubInfo();

            inf.CoinID        = coinid;
            inf.Symbol        = symbol;
            inf.GitHubRoot    = githubroot;
            inf.GitHubLeadPrj = leadproj;

            try
            {
                jsonInput = currClient.DownloadString(input);
            }
            catch (Exception ex)
            {
                TokenGitHubInfo.SetErr88(inf, ex.Message, input);
                intErr = 8888;
                strErr = "Jason Error - " + ex.Message;
                currClient.Dispose();
                currClient = null;
                return(inf);
            }

            //** Add brakets for array representation
            jsonInput = "[" + jsonInput + "]";

            try
            {
                Dictionary <string, string>[] ccurData = JsonConvert.DeserializeObject <Dictionary <string, string>[]>(jsonInput);
                inf.ReposNumber = ccurData[0]["public_repos"];
                inf.Followers   = ccurData[0]["followers"];
                inf.CreatedAt   = TimeConverter.GetStandardTime(ccurData[0]["created_at"]);
                inf.UpdatedAt   = TimeConverter.GetStandardTime(ccurData[0]["updated_at"]);
                inf.Url         = input;
            }
            catch (Exception ex)
            {
                TokenGitHubInfo.SetErr100(inf, ex.Message, input);
                intErr = 100;
                strErr = ex.Message;
                currClient.Dispose();
                currClient = null;
                return(inf);
            }

            currClient.Dispose();
            currClient = null;
            inf.ErrNum = 0;
            inf.ErrMes = "-";
            return(inf);
        }