Example #1
0
        /// <summary>
        /// 根据模板分析,并且返回已替换内容
        /// </summary>
        /// <param name="content"></param>
        /// <param name="regex"></param>
        /// <param name="modelInfo"></param>
        /// <param name="TransferFactory"></param>
        /// <returns></returns>
        public string AnalyAndReplace(string content, string regex, EntityInfo entity, Object obj, IExTransferFactory TransferFactory)
        {
            string Result = "";

            Dictionary<int, string> expresses = content.RegBaseDic(@regex); ;
            
            Dictionary<int, int> patternS_E = AnaUtil.Instance().GetKeyIndVal(expresses);

            Result += patternS_E.Count > 0 ? content.Substring(0, patternS_E.ElementAt(0).Key) : "";

            KeyValuePair<int, int> S_EPair = new KeyValuePair<int, int>();
            KeyValuePair<int, int> S_EPair2 = new KeyValuePair<int, int>();
            for (int i = 0; i < expresses.Count; i++)
            {
                Result += TransferFactory.CreateTransfer(expresses.ElementAt(i).Value).Transfer(expresses.ElementAt(i).Value, entity, obj);
                S_EPair = patternS_E.ElementAt(i);
                S_EPair2 = patternS_E.Count > (i + 1) ? patternS_E.ElementAt(i + 1) : patternS_E.ElementAt(i);

                Result += S_EPair2.Equals(S_EPair) ? "" : content.Substring(S_EPair.Value, S_EPair2.Key - S_EPair.Value);
            }
            Result += patternS_E.Count > 0 ? content.Substring(S_EPair.Value, content.Length - S_EPair.Value) : "";

            Result = patternS_E.Count == 0 ? content : Result;

            return Result;
        }
    public void callSong(NetworkPlayer player, string name, string subtitle, int step, int difficulty, int level)
    {
        if(!isSearching)
        {
            var theSIP = new SongInfoProfil(name, subtitle, step, (Difficulty)difficulty, level);
            if(lastSongChecked.Equals(default(KeyValuePair<Difficulty, Dictionary<Difficulty, Song>>)) || !lastSongChecked.Value[lastSongChecked.Key].sip.CompareId(theSIP))
            {
                for(int i=0; i < LANManager.Instance.players.Count; i++)
                {
                    LANManager.Instance.players.ElementAt(i).Value.songChecked = 0;
                }
                isSearching = true;
                networkView.RPC("setSearching", RPCMode.Others, true);
                networkView.RPC ("checkSong", RPCMode.Others, name, subtitle, step, difficulty, level);
                playerSearching = player;
                lastSongChecked = LoadManager.Instance.FindSong(theSIP);
                LANManager.Instance.players[Network.player].songChecked = lastSongChecked.Equals(default(KeyValuePair<Difficulty, Dictionary<Difficulty, Song>>)) ? 2 : 1;

            }else
            {
                isSearching = true;
                playerSearching = player;
            }

        }
    }
 void checkSong(string name, string subtitle, int step, int difficulty, int level)
 {
     lastSongChecked = LoadManager.Instance.FindSong(new SongInfoProfil(name, subtitle, step, (Difficulty)difficulty, level));
     var getSong = !lastSongChecked.Equals(default(KeyValuePair<Difficulty, Dictionary<Difficulty, Song>>));
     networkView.RPC("getSongCheckResult", RPCMode.Server, Network.player, getSong);
 }
 public bool ContactKeyValueIsNull(KeyValuePair<string, Contact> contactKeyValue)
 {
     if (contactKeyValue.Equals(new KeyValuePair<string, Contact>())) return true;
     return false;
 }
Example #5
0
        private static bool KeyHasValue(KeyValuePair<string, string> kvp)
        {
            if (!kvp.Equals(default(KeyValuePair<string, string>)) && !string.IsNullOrEmpty(kvp.Value))
            {
                return true;
            }

            return false;
        }
Example #6
0
 public void Test_Find_ShouldReturnEqualKeyValue()
 {
     hashTable.Add(key1, value1);
     var result = hashTable.Find(key1);
     var pair = new KeyValuePair<string, string>(key1, value1);
     Assert.IsTrue(pair.Equals(result), "Hash table find() should return equal key when found.");
 }
        private void AddListItemForPair(XElement xKey, XElement xValue)
        {
            ValueEditor keyEditor = ValueEditor.CreateEditor(dictionaryValueType.KeyType, new ValueValidatorAttribute[0], xDefaultKey);
            keyEditor.ReadFromXElement(xKey);
            keyEditor.ValueChanged += delegate { RaiseValueChanged(); };

            ValueEditor valueEditor = ValueEditor.CreateEditor(dictionaryValueType.ValueType, new ValueValidatorAttribute[0], xDefaultValue);
            valueEditor.ReadFromXElement(xValue);
            valueEditor.ValueChanged += delegate { RaiseValueChanged(); };

            var editorsPair = new KeyValuePair<ValueEditor, ValueEditor>(keyEditor, valueEditor);

            Button uiRemove = new Button {
                Content = new Image {
                    Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/ObjectConfigurator;component/Resources/delete.png")),
                    Width = 12,
                    Margin = new Thickness(1)
                },
                Margin = new Thickness(2, 0, 0, 0)
            };
            uiRemove.Click += delegate {
                Border itemToRemove = uiItems.Children.OfType<Border>().First(i => editorsPair.Equals(i.Tag));
                uiItems.Children.Remove(itemToRemove);
                CheckErrors();
                RaiseValueChanged();
            };
            Grid.SetColumn(uiRemove, 2);

            Grid.SetColumn(valueEditor.Representation, 1);
            valueEditor.Representation.Margin = new Thickness(5, 0, 0, 0);
            Border item = new Border {
                Tag = editorsPair,
                Child = new Grid {
                    ColumnDefinitions = {
                        new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
                        new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
                        new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) },
                    },
                    Children = {
                        keyEditor.Representation,
                        valueEditor.Representation,
                        uiRemove
                    }
                },
                Margin = new Thickness(2, 2, 2, 2)
            };
            uiItems.Children.Insert(uiItems.Children.Count - 1, item);
        }
 private static bool FindOutOfRangePoint(IEnumerable<KeyValuePair<DateTime, double>> dataPoints, double minLevel, double maxLevel, out KeyValuePair<DateTime, double> outOfRangePoint)
 {
     outOfRangePoint = dataPoints.FirstOrDefault(kv => (kv.Value < minLevel) || (kv.Value > maxLevel));
     if (outOfRangePoint.Equals(default(KeyValuePair<DateTime, double>)))
         return false;
     else
         return true;
 }
Example #9
0
        /// <summary>
        /// As the user types we want to filter the processes to those that contain the users search
        /// If its less than two characters, search for title starting with those characters for a "fast switch" type feel
        /// </summary>
        private void filter_Processes(object sender, FilterEventArgs e)
        {
            KeyValuePair<IntPtr, string> p = new KeyValuePair<IntPtr,string>();
            try
            {
                p = (KeyValuePair<IntPtr, string>)e.Item;
            }
            catch
            {
                e.Accepted = false;
                return;
            }

            Debug.Assert(!p.Equals(default(KeyValuePair<IntPtr, string>)));
            if (string.IsNullOrEmpty(ProcessUserInput)) { e.Accepted = true; return; }

            e.Accepted = ProcessUserInput.Length < 2 ? p.Value.ToUpper().StartsWith(ProcessUserInput.ToUpper()) : p.Value.ToUpper().Contains(ProcessUserInput.ToUpper());
        }
Example #10
0
        public Task<Message[]> FindClosestBirthday(Channel channel)
        {
            Server s = channel.Server;
            if (Miku_Bot.birthdays[s].Count == 0)
            {
                return client.SendMessage(channel, "No birthday has been added for this server");
            }

            else
            {
                DateTime today = DateTime.Today;
                List<KeyValuePair<string, DateTime>> same = new List<KeyValuePair<string, DateTime>>();
                List<KeyValuePair<string, DateTime>> same2 = new List<KeyValuePair<string, DateTime>>();
                KeyValuePair<string, DateTime> next = new KeyValuePair<string, DateTime>("", DateTime.MaxValue);
                KeyValuePair<string, DateTime> min = new KeyValuePair<string, DateTime>("", DateTime.MaxValue);

                foreach (KeyValuePair<string, DateTime> bday in Miku_Bot.birthdays[s])
                {
                    DateTime temp = new DateTime(today.Year, bday.Value.Month, bday.Value.Day);
                    Console.Write($"{bday.Key}");
                    if (temp.Month > today.Month)
                    {

                        if (temp.Month == next.Value.Month && temp.Day == next.Value.Day)
                        {
                            same.Add(bday);
                        }

                        else if (temp.Month < next.Value.Month)
                        {
                            next = bday;
                            same.Clear();
                            same.Add(next);
                        }

                        else if (temp.Month == next.Value.Month && temp.Day < next.Value.Day)
                        {
                            next = bday;
                            same.Clear();
                            same.Add(next);
                        }
                    }

                    else if (temp.Month == today.Month && temp.Day > today.Day)
                    {
                        if (temp.Month == next.Value.Month && temp.Day == next.Value.Day)
                        {
                            same.Add(bday);
                        }

                        else if (temp.Month < next.Value.Month)
                        {
                            next = bday;
                            same.Clear();
                            same.Add(next);
                        }

                        else if (temp.Month == next.Value.Month && temp.Day < next.Value.Day)
                        {
                            next = bday;
                            same.Clear();
                            same.Add(next);
                        }
                    }

                    if (temp.Month == min.Value.Month && temp.Day == min.Value.Day)
                    {
                        same2.Add(bday);
                    }

                    else if (temp.Month < min.Value.Month)
                    {
                        min = bday;
                        same2.Clear();
                        same2.Add(min);
                    }

                    else if (temp.Month == min.Value.Month && temp.Day < min.Value.Day)
                    {
                        min = bday;
                        same2.Clear();
                        same2.Add(min);
                    }
                }

                if (next.Value == DateTime.MaxValue)
                {
                    next = min;
                }

                string message = "Next birthday is";
                if (!next.Equals(min))
                {
                    if (same2.Count == 1)
                    {
                        message += $" {same2[0].Key} on {same2[0].Value.Month}/{same2[0].Value.Day}";
                    }
                    else
                    {
                        message += ":";
                        foreach (KeyValuePair<string, DateTime> s1 in same2)
                        {
                            message += "\n";
                            message += $"・{s1.Key} on {s1.Value.Month}/{s1.Value.Day}";
                        }
                    }
                }
                else
                {
                    if (same.Count == 1)
                    {
                        message += $" {same[0].Key} on {same[0].Value.Month}/{same[0].Value.Day}";
                    }
                    else
                    {
                        message += ":";
                        foreach (KeyValuePair<string, DateTime> s1 in same)
                        {
                            message += "\n";
                            message += $"・{s1.Key} on {s1.Value.Month}/{s1.Value.Day}";
                        }
                    }
                }

                return client.SendMessage(channel, message);
            }

        }
Example #11
0
        private List<string> GetReferencedVariablesForStatement(KeyValuePair<int, List<VariableLine>> statementLinesMapping)
        {
            if (statementLinesMapping.Equals(null))
                throw new ArgumentNullException("statementLinesMapping");

            List<string> referencedVariable = new List<string>();
            foreach (VariableLine statementLine in statementLinesMapping.Value)
                referencedVariable.Add(statementLine.variable);
            return referencedVariable;
        }
Example #12
0
        private bool TryFindByKey( string key, out KeyValuePair<string, string> header )
        {
            header = default( KeyValuePair<string, string> );

            if ( _headers != null )
            {
                header =
                    _headers.FirstOrDefault(
                        s => s.Key.Equals( key, StringComparison.InvariantCultureIgnoreCase ) );
            }

            return !header.Equals( default( KeyValuePair<string, string> ) );
        }
 //=======================================================================
 // Support functions
 //=======================================================================
 /// <summary>
 /// Test if the item is last in the collection
 /// </summary>
 /// <returns>True if it is last</returns>
 private bool Last( 
     KeyValuePair<string, string> item, 
     KeyValuePair<string, string>[] collection )
 {
     int collectionCount = collection.Length;
     if ( item.Equals( collection[ collectionCount - 1 ] ) )
         return true;
     return false;
 }
        private static bool HaveCodeMatch(string codeToMatch, KeyValuePair<string, string> codeResponse)
        {
            if (!codeResponse.Equals(default(KeyValuePair<string, string>)))
            {
                return codeResponse.Key.Equals(codeToMatch, StringComparison.InvariantCultureIgnoreCase) || codeResponse.Value.Equals(codeToMatch, StringComparison.InvariantCultureIgnoreCase);
            }

            return false;
        }