Beispiel #1
0
        public async Task <IHttpActionResult> PostStatsUpdateforPullRequest(AcceptStatsLog acceptLog)
        {
            int currentPullRequestID  = acceptLog.PullRequestId;
            int acceptedPullRequestID = acceptLog.StatsPullRequestId;

            try
            {
                Utilities.WriteToLogFile("  ");
                Utilities.WriteToLogFile("==========================================================");
                Utilities.WriteToLogFile(string.Format("Updating Pull Request ID: {0}, to compare stats FROM Pull Request ID: {1}!", currentPullRequestID, acceptedPullRequestID));

                string authenCode = Utilities.GetStatsAcceptedToken();
                if (acceptLog.LogPerson == authenCode)
                {
                    using (SqlConnection connection = new SqlConnection(Utilities.GetConnectionString()))
                    {
                        connection.Open();
                        DBFunctions.UpdateAsStatsAccepted(connection, "Update", acceptLog);
                    }
                    UpdateAcceptedStatsforPullRequest(currentPullRequestID, acceptedPullRequestID);
                }
            }
            catch (Exception ex)
            {
                Utilities.WriteToLogFile(string.Format("ERROR:  Pull Request Id {0}, unable to update Accepted Stats from Pull Request{1}: {2}.", currentPullRequestID.ToString(), acceptedPullRequestID.ToString(), ex.Message.ToString()));;
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
        protected void btnOk_Click(object sender, EventArgs e)
        {
            AcceptStatsLog acceptlog = new AcceptStatsLog();

            acceptlog.PullRequestId = int.Parse(txtPullRequestID.Text);
            acceptlog.SubmitDate    = DateTime.ParseExact(txtSubmitDate.Text, "dd/MM/yyyy HH:mm", CultureInfo.CurrentCulture, DateTimeStyles.AssumeLocal);

            acceptlog.SubmitPerson = txtSubmitPerson.Text;
            string fileInfo = txtFileCount.Text.Trim();
            int    posn     = fileInfo.IndexOf('.');

            if (posn > 0)
            {
                acceptlog.FileCount = int.Parse(fileInfo.Substring(0, posn));
            }
            else
            {
                acceptlog.FileCount = int.Parse(txtFileCount.Text);
            }

            acceptlog.LogPerson     = txtName.Text;
            acceptlog.LogReason     = txtDetails.Text;
            acceptlog.LogAcceptDate = DateTime.ParseExact(txtAcceptDate.Text, "dd/MM/yyyy HH:mm", CultureInfo.CurrentCulture, DateTimeStyles.AssumeLocal);
            acceptlog.LogStatus     = true;

            bool doAcceptStats = false;
            bool doUpdateStats = false;

            if (lblTitle.Text.StartsWith("Update"))
            {
                int pullRequestId2 = 0;
                if (int.TryParse(txtPullRequestId2.Text, out pullRequestId2) == true)
                {
                    acceptlog.StatsPullRequestId = pullRequestId2;
                    acceptlog.LogReason          = "Update 'Accepted' Stats to Pull Request Id: " + pullRequestId2.ToString();
                    acceptlog.LogStatus          = false;
                    doUpdateStats = true;
                }
            }
            else
            {
                doAcceptStats = true;
            }

            txtName.Text           = string.Empty;
            txtDetails.Text        = string.Empty;
            txtPullRequestId2.Text = string.Empty;
            this.ModalPopupExtender1.Hide();

            if (doAcceptStats == true)
            {
                WebAP_Interactions.UpdatePullRequestStats("Accept", acceptlog);
            }
            else if (doUpdateStats == true)
            {
                WebAP_Interactions.UpdatePullRequestStats("Update", acceptlog);
            }

            Response.Redirect(Request.RawUrl);
        }
Beispiel #3
0
        public static void UpdatePullRequestStats(string updateType, AcceptStatsLog apsimLog)
        {
            HttpClient httpClient = new HttpClient();

            string serviceUrl = ConfigurationManager.AppSettings["serviceAddress"].ToString() + "APSIM.PerformanceTests.Service/";

            httpClient.BaseAddress = new Uri(serviceUrl);

            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = new HttpResponseMessage();

            if (updateType == "Accept")
            {
                response = httpClient.PostAsJsonAsync("api/acceptStats", apsimLog).Result;
            }
            else if (updateType == "Update")
            {
                response = httpClient.PostAsJsonAsync("api/updateStats", apsimLog).Result;
                response.EnsureSuccessStatusCode();
                if (response.IsSuccessStatusCode)
                {
                }

                //This will check the status of the updates above, and notify Git
                response = httpClient.GetAsync("api/acceptstats/" + apsimLog.PullRequestId.ToString()).Result;
            }

            response.EnsureSuccessStatusCode();
            if (response.IsSuccessStatusCode)
            {
            }
        }
        public void TestAcceptStats()
        {
            foreach (DbConnection connection in populousConnections)
            {
                AcceptStatsLog log = new AcceptStatsLog()
                {
                    FileCount          = 1,
                    LogAcceptDate      = new DateTime(2020, 2, 1),
                    LogPerson          = "Chazza",
                    LogReason          = "felt like it",
                    LogStatus          = true,
                    PullRequestId      = 1,
                    StatsPullRequestId = -1,
                    SubmitDate         = new DateTime(2020, 1, 1),
                    SubmitPerson       = "Bazza",
                };

                DBFunctions.UpdateAsStatsAccepted(connection, "Accept", log);

                // Need to check AcceptStatsLogs and ApsimFiles.
                DataTable acceptStatsLog = new DataTable();
                using (DbCommand command = connection.CreateCommand("SELECT * FROM AcceptStatsLogs"))
                    using (DbDataReader reader = command.ExecuteReader())
                        acceptStatsLog.Load(reader);

                Assert.AreEqual(1, acceptStatsLog.Rows.Count);
                Assert.AreEqual(10, acceptStatsLog.Columns.Count);
                DataRow row = acceptStatsLog.Rows[0];

                Assert.AreEqual(1, row["ID"]);
                Assert.AreEqual(log.PullRequestId, row["PullRequestId"]);
                Assert.AreEqual(log.SubmitPerson, row["SubmitPerson"]);
                Assert.AreEqual(log.SubmitDate, row["SubmitDate"]);
                Assert.AreEqual(log.LogPerson, row["LogPerson"]);
                Assert.AreEqual(log.LogReason, row["LogReason"]);
                Assert.AreEqual(log.LogStatus, row["LogStatus"]);
                Assert.AreEqual(log.LogAcceptDate, row["LogAcceptDate"]);
                Assert.AreEqual(log.StatsPullRequestId, row["StatsPullRequestId"]);
                Assert.AreEqual(log.FileCount, row["FileCount"]);

                DataTable apsimFiles = new DataTable();
                using (DbCommand command = connection.CreateCommand("SELECT * FROM ApsimFiles"))
                    using (DbDataReader reader = command.ExecuteReader())
                        apsimFiles.Load(reader);

                Assert.AreEqual(1, apsimFiles.Rows.Count);
                row = apsimFiles.Rows[0];

                // Accepting the stats currently doesn't update the AcceptedPullRequestID of
                // any existing apsim files.
                Assert.AreEqual(-1, row["AcceptedPullRequestId"]);
            }
        }
        private void BindApsimFilesGrid()
        {
            ApsimFileList = ApsimFilesDS.GetPullRequestsWithStatus();
            ApsimFileDT   = Genfuncs.ToDataTable(ApsimFileList);

            Session["ApsimFileDT"]  = ApsimFileDT;
            gvApsimFiles.DataSource = ApsimFileDT;
            gvApsimFiles.DataBind();

            AcceptStatsLog acceptedPR = AcceptStatsLogDS.GetLatestAcceptedStatsLog();

            if (acceptedPR != null)
            {
                lblAcceptedDetails.Text   = string.Format("Current Accepted Stats are for Pull Request Id {0}, submitted by {1}, accepted on {2}.", acceptedPR.PullRequestId, acceptedPR.SubmitPerson, acceptedPR.LogAcceptDate.ToString("dd-MMM-yyyy HH:MM tt"));
                hfAcceptedFileCount.Value = acceptedPR.FileCount.ToString();
            }
        }
Beispiel #6
0
        public async Task <IHttpActionResult> PostAcceptStats(AcceptStatsLog acceptLog)
        {
            try
            {
                string authenCode = Utilities.GetStatsAcceptedToken();
                if (acceptLog.LogPerson == authenCode)
                {
                    //update the 'Stats accepted column from here
                    DBFunctions.UpdateAsStatsAccepted("Accept", acceptLog);
                    CallGitHubWithPassFail(acceptLog.PullRequestId, acceptLog.LogStatus);
                    Utilities.WriteToLogFile(string.Format("   Pull Request Id {0}, AcceptedStats has been confirmed and Github updated.", acceptLog.PullRequestId.ToString()));;
                }
            }

            catch (Exception ex)
            {
                Utilities.WriteToLogFile(string.Format("ERROR:  Pull Request Id {0}, Unable to update AcceptedStats status: {1}", acceptLog.PullRequestId.ToString(), ex.Message.ToString()));;
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #7
0
        /// <summary>
        /// UPdate the AcceptStats Log file
        /// </summary>
        /// <param name="acceptLog"></param>
        public static void UpdateAsStatsAccepted(string StatsType, AcceptStatsLog acceptLog)
        {
            string connectStr = Utilities.GetConnectionString();

            Utilities.WriteToLogFile("-----------------------------------");

            //make sure this is 0 if we are updating as 'Accepted'
            if (StatsType == "Accept")
            {
                acceptLog.StatsPullRequestId = 0;
                //acceptLog.FileCount = 0;
            }

            //need to authenticate the process
            int statsAccepted = Convert.ToInt32(acceptLog.LogStatus);

            using (SqlConnection sqlCon = new SqlConnection(connectStr))
            {
                sqlCon.Open();

                try
                {
                    string strSQL = "INSERT INTO AcceptStatsLogs (PullRequestId, SubmitPerson, SubmitDate, FileCount, LogPerson, LogReason, LogStatus, LogAcceptDate, StatsPullRequestId) "
                                    + " Values ( @PullRequestId, @SubmitPerson, @SubmitDate, @FileCount, @LogPerson, @LogReason, @LogStatus, @LogAcceptDate, @StatsPullRequestId )";
                    using (SqlCommand commandENQ = new SqlCommand(strSQL, sqlCon))
                    {
                        commandENQ.CommandType = CommandType.Text;
                        commandENQ.Parameters.AddWithValue("@PullRequestId", acceptLog.PullRequestId);
                        commandENQ.Parameters.AddWithValue("@SubmitPerson", acceptLog.SubmitPerson);
                        commandENQ.Parameters.AddWithValue("@SubmitDate", acceptLog.SubmitDate);
                        commandENQ.Parameters.AddWithValue("@FileCount", acceptLog.FileCount);
                        commandENQ.Parameters.AddWithValue("@LogPerson", acceptLog.LogPerson);
                        commandENQ.Parameters.AddWithValue("@LogReason", acceptLog.LogReason);
                        commandENQ.Parameters.AddWithValue("@LogStatus", acceptLog.LogStatus);
                        commandENQ.Parameters.AddWithValue("@LogAcceptDate", acceptLog.LogAcceptDate);
                        commandENQ.Parameters.AddWithValue("@StatsPullRequestId", acceptLog.StatsPullRequestId);

                        //commandENQ.ExecuteNonQuery();
                        Comms.SendQuery(commandENQ, "nonquery");
                    }

                    if (StatsType == "Accept")
                    {
                        strSQL = "UPDATE ApsimFiles SET StatsAccepted = @StatsAccepted, IsMerged = @IsMerged WHERE PullRequestId = @PullRequestId";
                        using (SqlCommand commandENQ = new SqlCommand(strSQL, sqlCon))
                        {
                            commandENQ.CommandType = CommandType.Text;
                            commandENQ.Parameters.AddWithValue("@StatsAccepted", statsAccepted);
                            commandENQ.Parameters.AddWithValue("@IsMerged", statsAccepted);        //do this the same to during changeover
                            commandENQ.Parameters.AddWithValue("@PullRequestId", acceptLog.PullRequestId);

                            //commandENQ.ExecuteNonQuery();
                            Comms.SendQuery(commandENQ, "nonquery");
                        }
                    }
                    //Utilities.WriteToLogFile(string.Format("    Accept Stats Status updated to {0} by {1} on {2}. Reason: {3}", acceptLog.LogStatus, acceptLog.LogPerson, acceptLog.SubmitDate, acceptLog.LogReason));
                }
                catch (Exception ex)
                {
                    Utilities.WriteToLogFile(string.Format("ERROR in UpdateAsStatsAccepted:  Pull Request Id {0}, Failed to update as 'Stats Accepted': {1}", acceptLog.PullRequestId.ToString(), ex.Message.ToString()));
                }
            }
        }