Ejemplo n.º 1
0
 private void ValidateAllFragmentsHasValidValue()
 {
     if (Fragments.Any(fragment => !fragment.IsValid))
     {
         ErrorMessages.Add("Message contain one or more hashes with missing number in front.");
     }
 }
Ejemplo n.º 2
0
 void ValidateAllFragmentsHasValue()
 {
     if (Fragments.Any(fragment => !fragment.HasValue))
     {
         _errorMessages.Add("Message contain one or more hashes with missing number in front or after");
     }
 }
Ejemplo n.º 3
0
            public CSSFragmentSet(IEnumerable <ICSSFragment> fragments)
            {
                if (fragments == null)
                {
                    throw new ArgumentNullException("fragments");
                }

                Fragments = fragments.ToList().AsReadOnly();
                if (Fragments.Any(f => f == null))
                {
                    throw new ArgumentException("Null reference encountered in fragments set");
                }

                TotalSelectorCount = GetSelectors(Fragments).Select(s => s.Selectors.Count()).Sum();
            }
Ejemplo n.º 4
0
        /// <summary>
        /// Called to process key events.
        /// </summary>
        /// <param name="e">The key event.</param>
        public override bool DispatchKeyEvent(KeyEvent e)
        {
            //
            // If we are in the middle of a transition, ignore all keys.
            //
            if (InFragmentTransition == true)
            {
                return(true);
            }

            //
            // If we are currently loading a new action then disable everything
            // except the Back button.
            //
            if (LoadingCancellationTokenSource != null)
            {
                if (e.KeyCode == Keycode.Back)
                {
                    if (!Fragments.Any())
                    {
                        return(base.DispatchKeyEvent(e));
                    }

                    LoadingCancellationTokenSource.Cancel();
                    LoadingCancellationTokenSource = null;
                    HideLoading();
                }

                return(true);
            }

            if (Fragments.Any())
            {
                if (Fragments.Last().DispatchKeyEvent(e))
                {
                    return(true);
                }
            }

            return(base.DispatchKeyEvent(e));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Return the items in <param name="items"/> that match this itemspec
 /// </summary>
 public IEnumerable <I> FilterItems(IEnumerable <I> items)
 {
     return(items.Where(i => Fragments.Any(f => f.ItemMatches(i.EvaluatedInclude) > 0)));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Return true if the given <paramref name="item"/> matches this itemspec
 /// </summary>
 /// <param name="item">The item to attempt to find a match for.</param>
 /// <returns></returns>
 public bool MatchesItem(I item)
 {
     return(Fragments.Any(f => f.MatchCount(item.EvaluatedInclude) > 0));
 }
Ejemplo n.º 7
0
        private string GenerateMatch(MatcherEngineGenerator generator)
        {
            return($@"
        public override MatcherResult Match(string code, string fragmentMatcher, bool matchFullText = true)
        {{
            FragmentMatchData matchData = new FragmentMatchData
            {{
                StartIndex = 0
            }};
            
			{(IndexingMode == IndexingMode.Lazy ? $"Span<int> checkFlags = stackalloc int[{Patterns.Count + 1}];" : null)}

            State state = new State()
            {{
                Code = code{(IndexingMode != IndexingMode.None ? @",
				DistinctStringMatches = new List<StringMatchData>(2000)" : null)}{(IndexingMode == IndexingMode.Lazy ? @",
				CheckFlags = checkFlags" : null)}{(Fragments.Any(fragment => fragment.Cacheable) ? @",
				MatchCache = new Dictionary<ValueTuple<string, int>, FragmentMatchData>()" : null)}{(LogMatches ? $@",
				MatchLogBuilder = new StringBuilder()" : null)}
            }};
            
			{(IndexingMode == IndexingMode.Eager ? "PreMatchPatterns(ref state);" : null)}

			bool success = false;
            switch (fragmentMatcher) 
            {{
                {string.Join("\n", Fragments.Where(matcher => !matcher.FallThrough && !matcher.IsNoise).Select(matcher => $@"
                case ""{HttpUtility.JavaScriptStringEncode(matcher.Name)}"":
                        success = {matcher.Generate(generator)};
                    break;
                "))}
            }}

			IMatchData resultMatchData = matchData.Parts.FirstOrDefault();
			int? failureIndex = success ? null : state.FailureIndex;

			if (success && matchFullText && state.CurrentIndex != state.Code.Length)
			{{
				success = false;
				failureIndex = state.CurrentIndex;
			}}

			return new MatcherResult(resultMatchData, success, state.CurrentIndex, failureIndex, state.MatchLogBuilder?.ToString());
        }}

        public override MatcherResult Match(string code, bool matchFullText = true)
        {{
            FragmentMatchData matchData = new FragmentMatchData
            {{
                StartIndex = 0
            }};
            
			{(IndexingMode == IndexingMode.Lazy ? $"Span<int> checkFlags = stackalloc int[{Patterns.Count + 1}];" : null)}

            State state = new State()
            {{
                Code = code{(IndexingMode != IndexingMode.None ? @",
				DistinctStringMatches = new List<StringMatchData>(2000)" : null)}{(IndexingMode == IndexingMode.Lazy ? @",
				CheckFlags = checkFlags" : null)}{(Fragments.Any(fragment => fragment.Cacheable) ? @",
				MatchCache = new Dictionary<ValueTuple<string, int>, FragmentMatchData>()" : null)}{(LogMatches ? $@",
				MatchLogBuilder = new StringBuilder()" : null)}
            }};
            
			{(IndexingMode == IndexingMode.Eager ? "PreMatchPatterns(ref state);" : null)}

            bool success = {StartingFragment.Generate(generator)};

			IMatchData resultMatchData = matchData?.Parts.FirstOrDefault();
			int? failureIndex = success ? null : state.FailureIndex;

			if (success && matchFullText && state.CurrentIndex != state.Code.Length)
			{{
				success = false;
				failureIndex = Math.Max(state.FailureIndex ?? 0, state.CurrentIndex);
			}}

			return new MatcherResult(resultMatchData, success, state.CurrentIndex, failureIndex, state.MatchLogBuilder?.ToString());
        }}

		{(IndexingMode == IndexingMode.Eager ? $@"private bool PreMatchPatterns(ref State state)
		{{
			int codeLength = state.Code.Length;
			bool success = true;
			bool previousNoise = false;
			StringMatchData matchData = null;
			int currentIndex = 0;
			while ((currentIndex = state.CurrentIndex) < codeLength)
			{{
				success = {string.Join(" ||\n", Patterns.Select(pattern => $@"{string.Format(GenerateMatchPattern(generator, pattern), "matchData", "true", "false")}"))};
				if (!success)
				{{
					break;
				}}
				else {{
					{(generator.LanguageMatcher.LogMatches ? $@"state.MatchLogBuilder.AppendLine($""{{currentIndex}}. Prematched {{matchData.Name}}: {{matchData.Text}}"");" : null)}
					if (matchData.IsNoise)
					{{
						previousNoise = true;
					}}
					else if (previousNoise)
					{{
						if (state.DistinctIndex > 1)
						{{
							StringMatchData previousMatchData = state.DistinctStringMatches[state.DistinctIndex - 2];
							if (previousMatchData.Name == matchData.Name && previousMatchData.Mergable)
							{{
								previousMatchData.Text += matchData.Text;
								previousMatchData.Length = state.CurrentIndex - previousMatchData.StartIndex;
								state.DistinctIndex--;
								state.MaxDistinctIndex--;
								state.DistinctStringMatches.RemoveAt(state.DistinctIndex);
							}}
						}}
						previousNoise = false;
					}}
				}}
			}}
			state.CurrentIndex = 0;
			{(IndexingMode != IndexingMode.None ? "state.DistinctIndex = 0;" : null)}
			return success;
		}}" : null)}"        );
        }