Example #1
0
 public ModCommander(Message message, IEnumerable <Message> context, MessageProcessor messageProcessor)
 {
     _message          = message;
     _context          = context;
     _messageProcessor = messageProcessor;
     _compiledRegex    = messageProcessor.CompiledRegex;
     LoadCommandDictionary();
 }
Example #2
0
 public MessageProcessor(IClientVisitor client)
 {
     CompiledRegex = new CompiledRegex();
     _client       = client;
     Banner        = new ActionBlock <Message>(m => Ban(m));
     Sender        = new ActionBlock <ISendableVisitable>(m => Send(m));
     _logger       = new ActionBlock <Message>(m => Log(m));
     _commander    = new ActionBlock <Message>(m => Command(m));
     _modCommander = new ActionBlock <Message>(m => ModCommand(m));
 }
Example #3
0
        public bool EvaluateExpression(string ToEvaluate)
        {
            switch (FilterMode)
            {
            case EFilterMode.SubString:
                return(ToEvaluate.Contains(FilterPattern));

            case EFilterMode.StartsWith:
                return(ToEvaluate.StartsWith(FilterPattern));

            case EFilterMode.EndsWith:
                return(ToEvaluate.EndsWith(FilterPattern));

            case EFilterMode.RegEx:
                return(CompiledRegex.Match(ToEvaluate).Success);
            }
            return(false);
        }
Example #4
0
 public void BuildCommonCompiledRegex()
 {
     _context.Pattern = CompiledRegex.BuildFrom(TextSamples.CharacterPatternCommonString);
 }
Example #5
0
        private bool Match()
        {
            // Named Group Match will not set groups not found
            Group sym       = null;
            int   symIndex  = 0;
            int   symLength = 0;
            Group opc       = null;
            int   opcIndex  = 0;
            int   opcLength = 0;
            Group drc       = null;
            int   drcIndex  = 0;
            int   drcLength = 0;

            Symbol    = string.Empty;
            OpCode    = string.Empty;
            Directive = string.Empty;

            //evaluate results of Regex and for each match
            var matches = CompiledRegex.Matches(Code);

            foreach (Match m in matches)
            {
                //loop through all the groups in current match
                for (int x = 1; x < m.Groups.Count; x++)
                {
                    //print the names wherever there is a succesful match
                    if (m.Groups[x].Success)
                    {
                        var group     = m.Groups[x];
                        var groupName = CompiledRegex.GroupNameFromNumber(x);
                        switch (groupName)
                        {
                        case "sym":
                            sym       = group;
                            symIndex  = group.Index;
                            symLength = group.Length;
                            Symbol    = group.Value;
                            break;

                        case "op":
                            opc       = group;
                            opcIndex  = group.Index;
                            opcLength = group.Length;
                            OpCode    = group.Value;
                            break;

                        case "dr":
                            drc       = group;
                            drcIndex  = group.Index;
                            drcLength = group.Length;
                            Directive = group.Value;
                            break;
                        }
                    }
                }
            }

            // This is a hack.  Probably need to master conditional
            // RegEx so when we match an opcode, we don't try to match
            // any directive.  The basic problem is that a directive
            // name could also be the operand of a opcode, as in:
            //  STA PAGE
            // Worse, in a case like PAGE, the code wants to skip
            // the entire line.
            if (OpCode.Length > 0)
            {
                Directive = string.Empty;
                drcIndex  = 0;
                drcLength = 0;
            }

            if (sym != null || drc != null || opc != null)
            {
                // Find beginning of operand
                var startOfOperand = opcIndex + opcLength;
                var otherEnd       = drcIndex + drcLength;
                if (otherEnd > startOfOperand)
                {
                    startOfOperand = otherEnd;
                }
                otherEnd = symIndex + symLength;
                if (otherEnd > startOfOperand)
                {
                    startOfOperand = otherEnd;
                }

                Operand = Code.Substring(startOfOperand);

                return(true);
            }

            return(false);
        }
Example #6
0
        public Payload RunPlugin(Payload Input)
        {
            Payload pData = new Payload();

            pData.FileID = Input.FileID;
            //pData.SegmentID = Input.SegmentID;


            for (int i = 0; i < Input.StringList.Count; i++)
            {
                HashSet <string> speakerListTransient = new HashSet <string>();

                string[] readText_Lines = NewlineClean.Split(Input.StringList[i]);
                int      NumberOfLines  = readText_Lines.Length;

                //loop through all of the lines in each text
                for (int j = 0; j < NumberOfLines; j++)
                {
                    string CurrentLine = readText_Lines[j];

                    if (regexRepl.Length > 0)
                    {
                        CurrentLine = CompiledRegex.Replace(CurrentLine, "").Trim();
                    }
                    else
                    {
                        CurrentLine = CurrentLine.Trim();
                    }


                    int IndexOfDelimiter = CurrentLine.IndexOf(DelimiterString);

                    if (IndexOfDelimiter > -1)
                    {
                        string SpeakerTag = CurrentLine.Substring(0, IndexOfDelimiter + DelimiterLength);


                        if (uniqueTagsOnly)
                        {
                            if (!speakerList.Contains(SpeakerTag) && SpeakerTag.Length <= MaxTagLengthInt)
                            {
                                speakerList.Add(SpeakerTag);
                                pData.StringArrayList.Add(new string[] { SpeakerTag });
                                pData.SegmentNumber.Add(Input.SegmentNumber[i]);
                                if (Input.SegmentID.Count > 0)
                                {
                                    pData.SegmentID.Add(Input.SegmentID[i]);
                                }
                            }
                        }
                        else
                        {
                            if (!speakerListTransient.Contains(SpeakerTag) && SpeakerTag.Length <= MaxTagLengthInt)
                            {
                                speakerListTransient.Add(SpeakerTag);
                                pData.StringArrayList.Add(new string[] { SpeakerTag });
                                pData.SegmentNumber.Add(Input.SegmentNumber[i]);
                                if (Input.SegmentID.Count > 0)
                                {
                                    pData.SegmentID.Add(Input.SegmentID[i]);
                                }
                            }
                        }
                    }


                    //end of for loop through each line
                }
            }

            return(pData);
        }
Example #7
0
 internal string ReplaceWithEscapeSequences(string message)
 {
     return(CompiledRegex.Replace(message, new MatchEvaluator(this.MatchEvaluator)));
 }
Example #8
0
        public Payload RunPlugin(Payload Input)
        {
            Payload pData = new Payload();

            pData.FileID = Input.FileID;



            for (int i = 0; i < Input.StringList.Count; i++)
            {
                //setting everything up
                Dictionary <string, List <string> > Text_Split = new Dictionary <string, List <string> >();
                string[]  readText_Lines  = NewlineClean.Split(Input.StringList[i]);
                int       NumberOfLines   = readText_Lines.Length;
                string    PreviousSpeaker = "";
                GroupData group           = new GroupData();
                Dictionary <ulong, Tuple <string, int> > TurnTracker = new Dictionary <ulong, Tuple <string, int> >();

                ulong turnCounter = 0;

                #region Parse Out Line into Speakers

                for (int j = 0; j < NumberOfLines; j++)
                {
                    string CurrentLine = readText_Lines[j];

                    if (regexRepl.Length > 0)
                    {
                        CurrentLine = CompiledRegex.Replace(CurrentLine, "").Trim();
                    }
                    else
                    {
                        CurrentLine = CurrentLine.Trim();
                    }


                    //if the line is empty, move along... move along
                    if (CurrentLine.Length == 0)
                    {
                        continue;
                    }

                    bool FoundSpeaker = false;

                    //loop through each speaker in list to see if the line starts with their name
                    for (int k = 0; k < SpeakerListLength; k++)
                    {
                        // here's what we do if we find a match
                        if (CurrentLine.StartsWith(SpeakerList[k]))
                        {
                            FoundSpeaker    = true;
                            PreviousSpeaker = SpeakerList[k];

                            //clean up the line to remove the speaker tag from the beginning
                            int Place = CurrentLine.IndexOf(SpeakerList[k]);
                            CurrentLine = CurrentLine.Remove(Place, SpeakerList[k].Length).Insert(Place, "").Trim() + "\r\n";

                            if (Text_Split.ContainsKey(SpeakerList[k]))
                            {
                                Text_Split[SpeakerList[k]].Add(CurrentLine.Trim());
                            }
                            else
                            {
                                Text_Split.Add(SpeakerList[k], new List <string>()
                                {
                                    CurrentLine.Trim()
                                });
                            }

                            //make sure we track where the line is located
                            TurnTracker.Add(turnCounter, new Tuple <string, int>(SpeakerList[k], Text_Split[SpeakerList[k]].Count - 1));
                            turnCounter++;

                            //break to the next line in the text
                            break;
                        }
                    }
                    //what we will do if no speaker was found
                    if ((FoundSpeaker == false) && (PreviousSpeaker != ""))
                    {
                        if (multiLine)
                        {
                            Text_Split[PreviousSpeaker][Text_Split[PreviousSpeaker].Count - 1] += CurrentLine.Trim() + "\r\n";
                        }
                    }

                    //end of for loop through each line
                }
                #endregion

                StringBuilder segID = new StringBuilder();

                foreach (KeyValuePair <string, List <string> > entry in Text_Split)
                {
                    group.People.Add(new Person(entry.Key, entry.Value));
                    segID.Append(entry.Key + ";");
                }

                group.TurnTracker = TurnTracker;

                pData.ObjectList.Add(group);
                pData.SegmentID.Add(segID.ToString());
                pData.SegmentNumber.Add(Input.SegmentNumber[i]);
            }

            return(pData);
        }