#region "Header" /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #endregion // using System.Collections.Generic; using System.Text; // namespace DeviceMap { /// /// Device Pattern data /// /// eberhard speer jr. /// Apache DeviceMap Project .Net version /// ported from Reza Naghibi's Pattern.java internal sealed class Pattern { // private IList> patternList; #region "Properties" /// /// List of Patterns which all must occur in User-Agent string for a match /// /// - public IList AndPattern { set { patternList.Add(value); } } /// /// List of Patterns of which at least one must occur in User-Agent string for a match /// /// - public IList OrPattern { set { foreach (string patternString in value) { AddPattern = patternString; } } } /// /// List of Patterns to match with User-Agent string /// /// - public string AddPattern { set { IList subList = new List(); subList.Add(value); patternList.Add(subList); } } /// /// List of Patterns Lists to match with User-Agent string /// /// IList(Of IList(Of String)) /// public IList> Patterns { get { return patternList; } } #endregion #region "Constructor" /// /// Default new Device Pattern data /// /// - public Pattern() { patternList = new List>(); } #endregion #region "Functions" /// /// Returns true if one of the patterns in patternList occurs in Device Pattern data /// /// List(Of String) /// Boolean /// - public bool isValid(List patternList) { bool found = false; foreach (IList patternset in Patterns) { foreach (string pattern in patternset) { if (!patternList.Contains(pattern)) { goto patternsContinue; } } found = true; break; patternsContinue: ; } return found; } /// /// To String override /// /// String /// - public override string ToString() { StringBuilder builder = new StringBuilder(); foreach (List sublist in patternList) { builder.AppendFormat("'{0}',", string.Join(",", sublist.ToArray())); } return builder.ToString().TrimEnd(','); } #endregion } }