public void AddNewTest(MondayTest pulse)
        {
            // get new uri obj here and set values here
            string cs           = ConfigurationManager.ConnectionStrings["ABTestingConnectionString"].ConnectionString; // encapuslate this or readonly property
            string champPg      = pulse.GetPgValue(pulse.champUrl);
            string challengerPg = pulse.GetPgValue(pulse.challengerUrl);
            bool   isTestEnded  = pulse.status.ToString() == "Complete";
            string pulseUrl     = pulse.CleanUrl(pulse.champUrl);
            string path         = pulse.GetPath(pulse.champUrl);
            string thisWinner   = pulse.DetermineWinner(champPg, challengerPg);

            using (SqlConnection conn = new SqlConnection(cs)) {
                try {
                    using (SqlCommand comm = conn.CreateCommand()) {
                        comm.CommandText = "dbo.sp_SetABTestingInfo";
                        comm.CommandType = CommandType.StoredProcedure;
                        comm.Parameters.AddWithValue("@TestName", pulse.testName);
                        comm.Parameters.AddWithValue("@Src", pulse.srcValue);
                        comm.Parameters.AddWithValue("@ControlPg", champPg);
                        comm.Parameters.AddWithValue("@ChallengerPg", challengerPg);
                        comm.Parameters.AddWithValue("@Domain", pulseUrl);
                        comm.Parameters.AddWithValue("@Path", path);
                        comm.Parameters.AddWithValue("@IsTestEnding", SqlDbType.Bit).Value = isTestEnded;
                        comm.Parameters.AddWithValue("@Winner", thisWinner);
                        conn.Open();
                        comm.ExecuteNonQuery();
                    }
                } catch (Exception ex) {
                    Console.WriteLine(ex);
                }
            }
        }
Пример #2
0
 // POST: api/Monday
 public void Post(MondayTest pulse)
 {
     try {
         threadHelp.VerifyingPulses(pulse);
     } catch (Exception ex) {
         Console.WriteLine(ex.Message);
     }
 }
Пример #3
0
 private bool CheckIfValuesNull(MondayTest pulse)
 {
     foreach (PropertyInfo pi in pulse.GetType().GetProperties())
     {
         Type propType = pi.PropertyType;
         bool isEnum   = propType == typeof(Status) ||
                         propType == typeof(TestType);
         if (propType == typeof(string) || isEnum)
         {
             var value = pi.GetValue(pulse).ToString();
             if (string.IsNullOrEmpty(value) || value == "None")
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #4
0
        public void VerifyingPulses(MondayTest pulse)
        {
            try {
                pulse = ConvertPulseEnum(pulse);
                bool isNull = CheckIfValuesNull(pulse);

                if (!isNull)
                {
                    DbHelpers dbHelpers  = new DbHelpers();
                    string    testType   = pulse.testType.ToString();
                    string    status     = pulse.status.ToString();
                    bool      thisStatus = status == "Complete" || status == "Testing" ? true : false;
                    if (testType == "RMI" && thisStatus == true)
                    {
                        dbHelpers.AddNewTest(pulse);
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
Пример #5
0
        private MondayTest ConvertPulseEnum(MondayTest pulse)
        {
            List <Columns> columnInfo = JsonConvert.DeserializeObject <List <Columns> >(pulse.columnInfo);

            foreach (var item in columnInfo)
            {
                if (item.Id.Contains("status"))
                {
                    foreach (PropertyInfo pi in pulse.GetType().GetProperties())
                    {
                        string piName    = pi.Name;
                        string propName  = FirstLetterToUpper(piName);
                        string propValue = pi.GetValue(pulse).ToString();

                        if (item.Title.Replace(" ", "") == propName)
                        {
                            foreach (var label in item.Labels)
                            {
                                if (label.Key == propValue)
                                {
                                    propValue = label.Value.Replace(" ", "");
                                    switch (piName)
                                    {
                                    case "status":
                                        if (propValue == "")
                                        {
                                            Status newStatus = Status.None;
                                            pulse.status = newStatus;
                                        }
                                        else
                                        {
                                            Status newStatus = (Status)Enum.Parse(typeof(Status), propValue);
                                            pulse.status = newStatus;
                                        }
                                        break;

                                    case "testType":
                                        if (propValue == "")
                                        {
                                            TestType newTestType = TestType.None;
                                            pulse.testType = newTestType;
                                        }
                                        else
                                        {
                                            TestType newTestType = (TestType)Enum.Parse(typeof(TestType), propValue);
                                            pulse.testType = newTestType;
                                        }
                                        break;

                                    case "winner":
                                        if (propValue == "")
                                        {
                                            Winner newWinner = Winner.None;
                                            pulse.winner = newWinner;
                                        }
                                        else
                                        {
                                            Winner newWinner = (Winner)Enum.Parse(typeof(Winner), propValue);
                                            pulse.winner = newWinner;
                                        }
                                        break;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return(pulse);
        }