// Can throw FormatException or ArgumentException public Version(string input) { // Performance note: after considering // https://docs.microsoft.com/en-us/dotnet/standard/base-types/best-practices?view=netframework-4.7.2 // I have concluded that an interpreted rather than compiled regex is the better choice here, // as version strings are parsed infrequently. string pattern = @"^(?<major>\d+).(?<minor>\d+).(?<patch>\d+)(-(?<phase>[a-z]+)(?<iteration>\d+))?$"; Match match = Regex.Match(input, pattern); GroupCollection matchGroups = match.Groups; major = int.Parse(matchGroups["major"].Value); minor = int.Parse(matchGroups["minor"].Value); patch = int.Parse(matchGroups["patch"].Value); string phaseStr = matchGroups["phase"].Value; // special handling for final version strings if (String.IsNullOrEmpty(phaseStr)) { phase = TestPhase.final; iteration = 0; } else { phase = (TestPhase)Enum.Parse(typeof(TestPhase), phaseStr); iteration = int.Parse(matchGroups["iteration"].Value); } }
public static void ReportErrors(ILogger logger, TestPhase phase, bool isDebugModeEnabled) { IList <string> errors = logger.GetMessages(Severity.Error, Severity.Warning); if (errors.Count == 0) { return; } bool hasErrors = logger.GetMessages(Severity.Error).Count > 0; string phaseString = (phase == TestPhase.TestDiscovery) ? Resources.TestDiscovery : Resources.TestExecution; string hint = isDebugModeEnabled ? "" : Resources.EnableDebugMode; string jointErrors = string.Join(Environment.NewLine, errors); string message = $"{Environment.NewLine}================{Environment.NewLine}" + String.Format(Resources.ErrorAndWarning, phaseString, hint, Environment.NewLine) + jointErrors; if (hasErrors) { logger.LogError(message); } else { logger.LogWarning(message); } }
// can throw ArgumentException for an invalid phase public Version(int major, int minor, int patch, string phase, int iteration) { this.major = major; this.minor = minor; this.patch = patch; this.phase = (TestPhase)Enum.Parse(typeof(TestPhase), phase); this.iteration = iteration; }
public readonly int iteration; // not printed for final // this is the most efficient constructor as it doesn't need to do any parsing public Version(int major, int minor, int patch, TestPhase phase = TestPhase.final, int iteration = 0) { this.major = major; this.minor = minor; this.patch = patch; this.phase = phase; this.iteration = iteration; }
public TestState(TestPhase phase, int seed, int size, List <object> values, List <List <object> > shrunkValues) { Phase = phase; Random = new Random(seed); Size = size; Values = values ?? new List <object>(); ShrunkValues = shrunkValues; }
public static void BeforeTestHandler() { if (ms_tp == TestPhase.Nonstarted) { SetSyntaxDocumentText(ms_domain.PreparationScript); ms_task = new LocalPreparationVBAScriptTask(ms_domain.DomainGUID, ms_vbaobjects); ms_task.AfterScript += new EventHandler(AfterTestHandler); ms_tp = TestPhase.Preparation; ms_task.Run(); } }
public TestState(TestPhase phase, int seed, int size, string label, List <object> values, List <IEnumerable <object> > shrunkValues) { Phase = phase; Random = new Random(seed); Seed = seed; Size = size; Label = label; Values = values ?? new List <object>(); ShrunkValues = shrunkValues; }
public static bool IsTester(string username, TestPhase phase) { object obj = SqlHelper.ExecuteScalar(_connectionString, "SELECT 1 FROM dbo.lg_perenthia_testers WHERE UserName = @UserName AND IsAlphaTester = @IsAlphaTester AND IsBetaTester = @IsBetaTester", CommandType.Text, SqlHelper.CreateInputParam("@UserName", SqlDbType.NVarChar, username), SqlHelper.CreateInputParam("@IsAlphaTester", SqlDbType.Bit, (phase == TestPhase.Alpha)), SqlHelper.CreateInputParam("@IsBetaTester", SqlDbType.Bit, (phase == TestPhase.Beta))); if (obj != null && obj != DBNull.Value) { return(true); } return(false); }
private static void StartPersistantTest(Domain d) { lock (TestProccessStatusLocker) { if (ms_tps == TestProcessStatus.Ready) { //Domain ms_domain = d; //清空log区 ms_dgv.Rows.Clear(); //重置Close Flag ms_IsClosed = false; //准备vba脚本对象 ms_vbaobjects = new Dictionary <string, IVBAObject>(); IVBAObject ivo = new VBATask(); ms_vbaobjects.Add(ivo.Name, ivo); //小心处理伪Log对象 ms_testlog = new VBATestLog(false); ms_testlog.MessageEvent += new VBATestLog.ScriptPauseEventHandler(MessageHandler); ms_vbaobjects.Add(ms_testlog.Name, ms_testlog); ivo = new VBATestIE(); ms_vbaobjects.Add(ivo.Name, ivo); ivo = new VBAUtility(); ms_vbaobjects.Add(ivo.Name, ivo); ivo = new VBAHtml(); ms_vbaobjects.Add(ivo.Name, ivo); ms_tp = TestPhase.Nonstarted; Thread t = new Thread(BeforeTestHandler); t.Name = "Thread For Persistant Test"; t.Start(); } else if (ms_tps == TestProcessStatus.Singlestep_Pause) { //改成持续运行模式 ms_testlog.TurnPersistance(); //放行 ms_testlog.PulseOne(); } ms_tps = TestProcessStatus.Persistence; RefreshTestToolButtons(); } }
public static void AfterTestHandler(object sender, EventArgs e) { BaseVBAScriptTask whichtask = (BaseVBAScriptTask)sender; if (whichtask.Status == TaskStatus.Succeed && ms_IsClosed == false) { switch (ms_tp) { case TestPhase.Preparation: SetSyntaxDocumentText(ms_domain.ParserScript); ms_task = new LocalParserVBAScriptTask(ms_domain.DomainGUID, whichtask.TaskChainGUID, ms_vbaobjects); whichtask.VBAObjs = null; ms_task.AfterScript += new EventHandler(AfterTestHandler); ms_task.Run(); ms_tp = TestPhase.Parser; whichtask.Dispose(); break; case TestPhase.Parser: SetSyntaxDocumentText(ms_domain.StorageScript); ms_task = new LocalStorageVBAScriptTask(ms_domain.DomainGUID, whichtask.TaskChainGUID, ms_vbaobjects); whichtask.VBAObjs = null; ms_task.AfterScript += new EventHandler(AfterTestHandler); ms_task.Run(); ms_tp = TestPhase.Storage; whichtask.Dispose(); break; case TestPhase.Storage: MessageBox.Show("测试结束,请检查日志以确定代码是否正确", "通知", MessageBoxButtons.OK, MessageBoxIcon.Information); whichtask.Dispose(); ms_task = null; ms_tps = TestProcessStatus.Ready; RefreshTestToolButtons(); break; } } else { whichtask.Dispose(); ms_task = null; ms_tps = TestProcessStatus.Ready; RefreshTestToolButtons(); } }
private void setTestPhase(TestPhase tp) { switch (tp.ToString().ToLower()) { case "Resistance": radioButton1.Checked = true; break; case "Sweep": radioButton2.Checked = true; break; case "None": radioButton3.Checked = true; break; default: break; } }
public static void ReportErrors(ILogger logger, TestPhase phase, OutputMode outputMode, SummaryMode summaryMode) { if (summaryMode == SummaryMode.Never) { return; } bool hasErrors = logger.GetMessages(Severity.Error).Count > 0; if (!hasErrors && summaryMode == SummaryMode.Error) { return; } IList <string> errors = logger.GetMessages(Severity.Error, Severity.Warning); if (!errors.Any()) { return; } string hint = outputMode > OutputMode.Info ? "" : Resources.EnableDebugMode; string jointErrors = string.Join(Environment.NewLine, errors); string phaseString = (phase == TestPhase.TestDiscovery) ? Resources.TestDiscovery : Resources.TestExecution; string message = $"{Environment.NewLine}================{Environment.NewLine}" + String.Format(Resources.ErrorAndWarning, phaseString, hint, Environment.NewLine) + jointErrors; if (hasErrors) { logger.LogError(message); } else { logger.LogWarning(message); } }
public static bool AddUser(string username, TestPhase phase, out string message) { if (IsTester(username, phase)) { message = String.Format("You are already registered for the Perenthia {0}.", phase); return(false); } else { try { MembershipUser user = Membership.GetUser(username); if (user != null) { Notification.SendEmail("*****@*****.**", user.Email, String.Format("Perenthia {0} Registration Confirmation", phase), String.Format("You have successfully registered for the Perenthia {0}. You may visit http://alpha.perenthia.com to begin playing!{1}{1}Perenthia PBBG", phase, Environment.NewLine)); SqlHelper.ExecuteNonQuery(_connectionString, "INSERT INTO dbo.lg_perenthia_testers (UserName, IsAlphaTester, IsBetaTester) VALUES (@UserName, @IsAlphaTester, @IsBetaTester);", CommandType.Text, SqlHelper.CreateInputParam("@UserName", SqlDbType.NVarChar, user.UserName), SqlHelper.CreateInputParam("@IsAlphaTester", SqlDbType.Bit, (phase == TestPhase.Alpha)), SqlHelper.CreateInputParam("@IsBetaTester", SqlDbType.Bit, (phase == TestPhase.Beta))); message = String.Format("You have successfully registered for the Perenthia {0}. You may visit http://alpha.perenthia.com to begin playing.", phase); return(true); } else { message = String.Format("Authentication is required in order to register for the Perenthia {0}.", phase); return(false); } } catch (Exception ex) { Log.Write(ex.ToString(), true); message = "An error occurred during registration. Technical Support has bee notified of the issue and will work to resolve it ASAP. Please try back again later."; return(false); } } }
/* ### Constructors ###We provide two simple constructors. They initialize all the fields ###according to specified values or to their default values. */ public TestState(TestPhase phase, int seed, int size, string label) : this(phase, seed, size, label, null, null) { }
public TestState(TestPhase phase, int seed, int size) : this(phase, seed, size, null, null) { }
private static void StartPersistantTest(Domain d) { lock (TestProccessStatusLocker) { if (ms_tps == TestProcessStatus.Ready) { //Domain ms_domain = d; //清空log区 ms_dgv.Rows.Clear(); //重置Close Flag ms_IsClosed = false; //准备vba脚本对象 ms_vbaobjects = new Dictionary<string, IVBAObject>(); IVBAObject ivo = new VBATask(); ms_vbaobjects.Add(ivo.Name, ivo); //小心处理伪Log对象 ms_testlog = new VBATestLog(false); ms_testlog.MessageEvent += new VBATestLog.ScriptPauseEventHandler(MessageHandler); ms_vbaobjects.Add(ms_testlog.Name, ms_testlog); ivo = new VBATestIE(); ms_vbaobjects.Add(ivo.Name, ivo); ivo = new VBAUtility(); ms_vbaobjects.Add(ivo.Name, ivo); ivo = new VBAHtml(); ms_vbaobjects.Add(ivo.Name, ivo); ms_tp = TestPhase.Nonstarted; Thread t = new Thread(BeforeTestHandler); t.Name = "Thread For Persistant Test"; t.Start(); } else if (ms_tps == TestProcessStatus.Singlestep_Pause) { //改成持续运行模式 ms_testlog.TurnPersistance(); //放行 ms_testlog.PulseOne(); } ms_tps = TestProcessStatus.Persistence; RefreshTestToolButtons(); } }