//Check if the text is in a valid format and create the appropriate pair public static bool TryParse(string text, out Pair pair) { pair = null; var dispatchedText = text.Split('='); if (dispatchedText.Length == 2) { string name = dispatchedText[0].Trim(); string value = dispatchedText[1].Trim(); if (PairHelper.ValidFormat(name) && PairHelper.ValidFormat(value)) { pair = new Pair(name, value); return(true); } } return(false); }
/// <summary> /// 获取Pairs /// </summary> /// <param name="conn">指定的数据库</param> protected virtual IEnumerable <Model.Pair> FetchPairsHelper(Predicate <Model.Pair> predicate) { SQLiteCommand cmd = new SQLiteCommand(DataBase); cmd.CommandText = $@"Select * From {APM.PairsTable} Where {APM.PairContainer} == {ContainerUID} "; using (SQLiteDataReader results = cmd.ExecuteReader()) { while (results.Read()) { Model.Pair pair = PairHelper.FetchFrom(results); if (predicate(pair)) { yield return(pair); } } } }
public ConfigurationTransaction this[string transactionName] { get { return(Transactions.First(tran => tran.TransactionName == transactionName).ConfigurationTransaction); } set { int index = Transactions.FindIndex(tran => tran.TransactionName == transactionName); if (index >= 0) { Transactions[index] = new PairHelper { TransactionName = transactionName, ConfigurationTransaction = value } } ; else { Transactions.Add(new PairHelper { TransactionName = transactionName, ConfigurationTransaction = value }); } } }
public bool Check(Card[] cards) { return(PairHelper.GetCountSameRankCard(cards).Contains(4)); }
/// <summary> /// 添加到数据库 /// </summary> /// <param name="conn">目标数据库</param> /// <returns>受影响的记录数</returns> protected override UpdateInformation InsertInto() { return(PairHelper.Insert(_dataSource, DataBase)); }
/// <summary> /// 从数据库中删除 /// </summary> /// <param name="conn">指定数据库</param> /// <returns>受影响的记录数</returns> protected override UpdateInformation DeleteFrom() { return(PairHelper.Delete(_dataSource, DataBase)); }
/// <summary> /// 从数据库中修改 /// </summary> /// <param name="conn">目标数据库</param> /// <returns>受影响的记录数</returns> protected override UpdateInformation UpdateTo() { return(PairHelper.Update(_dataSource, DataBase)); }
private bool FilterPairsView(object item) { Pair pair = item as Pair; return(PairHelper.FilterPair(pair, _pairFilter)); }
public bool PairFilterValid(string textBoxValue) { return(PairHelper.ValidFilterFormat(textBoxValue)); }
public bool Check(Card[] cards) { return(PairHelper.GetCountSameRankCard(cards).Count(c => c == 2) > 1); }
/// <summary> /// For each dive schedule run each algorithm and calculate safety measure sum for each dive /// After that choose algorithm with smallest safety measure sum because it represents highest level of safety /// </summary> /// <param name="algorithms">Array of algorithm names</param> private void TestAlgorithms(List <string> algorithms) { AlgorithmFactoryAbstract diveFactory = new DiveAlgorithmFactory(); // We'll save generated diver groups into dictionary with algorithm name as key Dictionary <String, List <PairHelper> > diverGroupsByAlgorithm = new Dictionary <string, List <PairHelper> >(); // Test each algorithm for each dive for (int i = 0; i < diveSchedule.Count(); i++) { // safety measure sum for dive float safetyMeasureMax = 0; float safetyMeasureForDive; string chosenAlgorithmName = ""; // Max dive depth float maxDiveDepth = diveSchedule[i].maxDepth; foreach (string algorithm in algorithms) { DiveAlgorithmProductAbstract currentAlgorithm = diveFactory.createAlgorithm(algorithm); // Generate dive groups with passed algorithm List <PairHelper> diveGroup = currentAlgorithm.GetDivePairs(diveSchedule[i].divers, diveSchedule[i]); // Add dive group to dictionary diverGroupsByAlgorithm.Add(algorithm, diveGroup); // Calculate safety measure sum for group safetyMeasureForDive = PairHelper.CalculateSafetyMeasureSum(diveGroup); // If safetyMeasureForGroup is greater than currently max safetyMeasureSum then safetyMeasureForGroup is max if (safetyMeasureForDive > safetyMeasureMax) { safetyMeasureMax = safetyMeasureForDive; chosenAlgorithmName = algorithm; } } // Add dive groups to dive diveSchedule[i].diveGroups = diverGroupsByAlgorithm[chosenAlgorithmName]; // Add safety measure to dive diveSchedule[i].safetyMeasure = safetyMeasureMax; // Add used algorithm name to dive diveSchedule[i].algorithmName = chosenAlgorithmName; // Add dive to each diver foreach (Diver d in diveSchedule[i].divers) { d.AddDive(diveSchedule[i]); } // Add dive to dive club and to national diving association divingClub.SetDive(diveSchedule[i]); // Clear dictionary with dive groups because it needs to be empty for next iteration diverGroupsByAlgorithm.Clear(); } }
public void TestValidFormatFilter(string text, bool expValidation) { bool validationResult = PairHelper.ValidFilterFormat(text); Assert.AreEqual(expValidation, validationResult); }