コード例 #1
0
        /// <summary>
        /// Returns all categories that match the filter
        /// </summary>
        /// <param name="filter">Categories filter</param>
        /// <returns>List of categories that match the filter</returns>
        public List <Update> GetCategories(MetadataFilter filter)
        {
            var filteredCategories = new List <Update>();

            // Apply the title filter
            if (!string.IsNullOrEmpty(filter.TitleFilter))
            {
                var filterTokens = filter.TitleFilter.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                filteredCategories.AddRange(Categories.Values.Where(category => category.MatchTitle(filterTokens)));
            }
            else
            {
                filteredCategories.AddRange(Categories.Values);
            }

            // Apply the id filter
            if (filter.IdFilter.Count() > 0)
            {
                // Remove all updates that don't match the ID filter
                filteredCategories.RemoveAll(u => !filter.IdFilter.Contains(u.Identity.Raw.UpdateID));
            }

            return(filteredCategories);
        }
        public void TestForSpecialBuild()
        {
            var blacklist = new Dictionary <string, SortedSet <string> >
            {
                { "fixedLine", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "tollFree", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "premiumRate", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "sharedCost", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "personalNumber", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "voip", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "pager", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "uan", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "emergency", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "voicemail", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "shortCode", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "standardRate", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "carrierSpecific", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "smsServices", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                {
                    "noInternationalDialling",
                    new SortedSet <string>(MetadataFilter.ExcludableChildFields)
                },
                { "preferredInternationalPrefix", new SortedSet <string>() },
                { "nationalPrefix", new SortedSet <string>() },
                { "preferredExtnPrefix", new SortedSet <string>() },
                { "nationalPrefixTransformRule", new SortedSet <string>() },
                { "sameMobileAndFixedLinePattern", new SortedSet <string>() },
                { "mainCountryForCode", new SortedSet <string>() },
                { "leadingZeroPossible", new SortedSet <string>() },
                { "mobileNumberPortableRegion", new SortedSet <string>() }
            };

            Assert.Equal(MetadataFilter.ForSpecialBuild(), new MetadataFilter(blacklist));
        }
コード例 #3
0
        public void ToStringTest(string key, string value)
        {
            MetadataFilter <ITestDescriptor> filter = new MetadataFilter <ITestDescriptor>(key,
                                                                                           new EqualityFilter <string>(value));

            Assert.AreEqual("Metadata('" + key + "', Equality('" + value + "'))", filter.ToString());
        }
        public void TestFilterMetadata_LiteBuild()
        {
            var metadata = FakeArmeniaPhoneMetadata();

            MetadataFilter.ForLiteBuild().FilterMetadata(metadata);

            // id, country_code, and international_prefix should never be cleared.
            Assert.Equal(metadata.Id, ID);
            Assert.Equal(metadata.CountryCode, COUNTRY_CODE);
            Assert.Equal(metadata.InternationalPrefix, INTERNATIONAL_PREFIX);

            // preferred_international_prefix should not be cleared in liteBuild.
            Assert.Equal(metadata.PreferredInternationalPrefix, PREFERRED_INTERNATIONAL_PREFIX);

            // All PhoneNumberDescs must have only example_number cleared.
            foreach (var desc in new List <PhoneNumberDesc> {
                metadata.GeneralDesc,
                metadata.FixedLine,
                metadata.Mobile,
                metadata.TollFree
            })
            {
                Assert.Equal(desc.NationalNumberPattern, NATIONAL_NUMBER_PATTERN);
                Assert.True(ContentsEqual(desc.PossibleLengthList.ToList(), PossibleLengths));
                Assert.True(ContentsEqual(desc.PossibleLengthLocalOnlyList.ToList(), PossibleLengthsLocalOnly));
                Assert.False(desc.HasExampleNumber);
            }
        }
        public void TestFilterMetadata_EmptyFilter()
        {
            var metadata = FakeArmeniaPhoneMetadata();

            MetadataFilter.EmptyFilter().FilterMetadata(metadata);

            // None of the fields should be cleared.
            Assert.Equal(metadata.Id, ID);
            Assert.Equal(metadata.CountryCode, COUNTRY_CODE);
            Assert.Equal(metadata.InternationalPrefix, INTERNATIONAL_PREFIX);
            Assert.Equal(metadata.PreferredInternationalPrefix, PREFERRED_INTERNATIONAL_PREFIX);
            foreach (var desc in new List <PhoneNumberDesc> {
                metadata.GeneralDesc,
                metadata.FixedLine,
                metadata.Mobile,
                metadata.TollFree
            })
            {
                Assert.Equal(desc.NationalNumberPattern, NATIONAL_NUMBER_PATTERN);
                Assert.True(ContentsEqual(desc.PossibleLengthList.ToList(), PossibleLengths));
                Assert.True(ContentsEqual(desc.PossibleLengthLocalOnlyList.ToList(), PossibleLengthsLocalOnly));
            }

            Assert.False(metadata.GeneralDesc.HasExampleNumber);
            Assert.Equal(metadata.FixedLine.ExampleNumber, EXAMPLE_NUMBER);
            Assert.Equal(metadata.Mobile.ExampleNumber, EXAMPLE_NUMBER);
            Assert.Equal(metadata.TollFree.ExampleNumber, EXAMPLE_NUMBER);
        }
コード例 #6
0
        public void A()
        {
            var meta = MetadataFilter.Parse("metadata(width,height)");

            Assert.Equal("width", meta.Properties[0]);
            Assert.Equal("height", meta.Properties[1]);
        }
コード例 #7
0
        /// <summary>
        /// Initialize a new instance of UpstreamServerStartup.
        /// </summary>
        /// <param name="config">
        /// <para>ASP.NET configuration.</para>
        ///
        /// <para>Must contain a string entry "metadata-path" with the path to the metadata source to use</para>
        ///
        /// <para>Must contain a string entry "updates-filter" with a JSON serialized updates metadata filter</para>
        ///
        /// <para>Must contain a string entry "service-config-path" with the path to the service configuration JSON</para>
        ///
        /// <para>Can contain a string entry "content-path" with the path to the content store to use if serving update content</para>
        /// </param>
        public UpstreamServerStartup(IConfiguration config)
        {
            // Get the metadata source path from the configuration
            var sourcePath = config.GetValue <string>("metadata-path");

            var contentPath = config.GetValue <string>("content-path");

            // Get the filteres to apply to updates; restricts which updates are shared with downstream servers
            Filter = MetadataFilter.FromJson(config.GetValue <string>("updates-filter"));

            // Open the updates metadata source. It must exist
            LocalMetadataSource = CompressedMetadataStore.Open(sourcePath);
            if (LocalMetadataSource == null)
            {
                throw new System.Exception($"Cannot open the specified metadata source at {sourcePath}");
            }

            var serviceConfigPath = config.GetValue <string>("service-config-path");

            ServiceConfiguration = JsonConvert.DeserializeObject <ServerSyncConfigData>(
                File.OpenText(serviceConfigPath).ReadToEnd());

            if (!string.IsNullOrEmpty(contentPath))
            {
                LocalContentSource = new FileSystemContentStore(contentPath);
                ServiceConfiguration.CatalogOnlySync = false;
            }
            else
            {
                ServiceConfiguration.CatalogOnlySync = true;
            }
        }
コード例 #8
0
        public MetadataFilterForm(MetadataFilter filter)
            : this()
        {
            _originalFilter = filter;
            _filter.Assign(_originalFilter);

            filterControl.MetadataFilter = _filter;
        }
コード例 #9
0
        public void B()
        {
            var meta = MetadataFilter.Parse("metadata(width,height,colors(count:10))");

            Assert.Equal("width", meta.Properties[0]);
            Assert.Equal("height", meta.Properties[1]);
            Assert.Equal("colors(count:10)", meta.Properties[2]);
        }
        public void testParseFieldMapFromString_childlessFieldAsGroup()
        {
            var fieldMap = new Dictionary <string, SortedSet <string> >
            {
                { "nationalPrefix", new SortedSet <string>() }
            };

            Assert.Equal(MetadataFilter.ParseFieldMapFromString("nationalPrefix"), fieldMap);
        }
        public void TestForLiteBuild()
        {
            var blacklist = new Dictionary <string, SortedSet <string> >
            {
                { "fixedLine", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "mobile", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "tollFree", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "premiumRate", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "sharedCost", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "personalNumber", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "voip", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "pager", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "uan", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "emergency", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "voicemail", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "shortCode", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "standardRate", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "carrierSpecific", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "smsServices", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "noInternationalDialling", new SortedSet <string> {
                      "exampleNumber"
                  } }
            };

            Assert.Equal(MetadataFilter.ForLiteBuild(), new MetadataFilter(blacklist));
        }
        public void testParseFieldMapFromString_childAsGroup()
        {
            var fieldMap = new Dictionary <string, SortedSet <string> >
            {
                { "fixedLine", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "mobile", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "tollFree", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "premiumRate", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "sharedCost", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "personalNumber", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "voip", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "pager", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "uan", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "emergency", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "voicemail", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "shortCode", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "standardRate", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "carrierSpecific", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "smsServices", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "noInternationalDialling", new SortedSet <string> {
                      "exampleNumber"
                  } }
            };

            Assert.Equal(MetadataFilter.ParseFieldMapFromString("exampleNumber"), fieldMap);
        }
        public void testParseFieldMapFromString_parentWithOneChildAsGroup()
        {
            var fieldMap = new Dictionary <string, SortedSet <string> >
            {
                { "fixedLine", new SortedSet <string> {
                      "exampleNumber"
                  } }
            };

            Assert.Equal(MetadataFilter.ParseFieldMapFromString("fixedLine(exampleNumber)"), fieldMap);
        }
コード例 #14
0
        /// <summary>
        /// Instantiate the server and serve updates from the local repo
        /// </summary>
        /// <param name="metadataSource">The update metadata source to serve updates from</param>
        /// <param name="filter">The filter for which updates to serve.</param>
        /// <param name="serviceConfig">Service configuration.</param>
        public ServerSyncWebService(IMetadataSource metadataSource, MetadataFilter filter, ServerSyncConfigData serviceConfig)
        {
            MetadataSource       = metadataSource;
            ServiceConfiguration = serviceConfig;

            UpdatesFilter = filter;

            Categories      = metadataSource.GetCategories();
            FilteredUpdates = metadataSource.GetUpdates(filter).ToDictionary(u => u.Identity);

            // If an update contains bundled updates, those bundled updates must also be made available to downstream servers
            var bundledUpdates = FilteredUpdates.Values.Where(u => u.IsBundle).SelectMany(u => u.BundledUpdates).Distinct().ToList();

            foreach (var bundledUpdateId in bundledUpdates)
            {
                if (!FilteredUpdates.ContainsKey(bundledUpdateId))
                {
                    FilteredUpdates.Add(bundledUpdateId, metadataSource.GetUpdate(bundledUpdateId));
                }
            }

            // Build the lookup tables by products and classifications
            ProductsIndex        = new Dictionary <Guid, List <Update> >();
            ClassificationsIndex = new Dictionary <Guid, List <Update> >();

            foreach (var update in FilteredUpdates.Values)
            {
                if (update.HasProduct)
                {
                    foreach (var productId in update.ProductIds)
                    {
                        if (!ProductsIndex.ContainsKey(productId))
                        {
                            ProductsIndex[productId] = new List <Update>();
                        }

                        ProductsIndex[productId].Add(update);
                    }
                }

                if (update.HasClassification)
                {
                    foreach (var classificationId in update.ClassificationIds)
                    {
                        if (!ClassificationsIndex.ContainsKey(classificationId))
                        {
                            ClassificationsIndex[classificationId] = new List <Update>();
                        }

                        ClassificationsIndex[classificationId].Add(update);
                    }
                }
            }
        }
コード例 #15
0
        public MetadataFilterForm(MetadataFilter filter)
            : this()
        {
            _originalFilter = filter;
            _filter.Assign(_originalFilter);

            MFilterControl.MetadataFilter = _filter;

            var langProperty = DependencyPropertyDescriptor.FromProperty(LanguageProperty, GetType());

            langProperty.AddValueChanged(this, LanguageChanged);
        }
コード例 #16
0
        /// <summary>
        /// Exports the selected updates from the metadata source
        /// </summary>
        /// <param name="filter">Export filter</param>
        /// <param name="exportFile">Export file path</param>
        /// <param name="format">Export format</param>
        /// <param name="serverConfiguration">Server configuration.</param>
        /// <returns>List of categories that match the filter</returns>
        public void Export(MetadataFilter filter, string exportFile, RepoExportFormat format, ServerSyncConfigData serverConfiguration)
        {
            var updatesToExport = GetUpdates(filter);

            if (format == RepoExportFormat.WSUS_2016)
            {
                var exporter = new WsusExport(this, serverConfiguration);
                exporter.ExportProgress += Exporter_ExportProgress;
                exporter.Export(updatesToExport, exportFile);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #17
0
        public static MetadataFilter MetadataFilterFromCommandLine(IMetadataFilterOptions filterOptions)
        {
            var filter = new MetadataFilter()
            {
                TitleFilter      = filterOptions.TitleFilter,
                HardwareIdFilter = filterOptions.HardwareIdFilter,
                KbArticleFilter  = filterOptions.KbArticleFilter.ToList()
            };

            if (!string.IsNullOrEmpty(filterOptions.ComputerHardwareIdFilter))
            {
                if (!Guid.TryParse(filterOptions.ComputerHardwareIdFilter, out Guid computerHardwareIdFilterGuid))
                {
                    ConsoleOutput.WriteRed($"The computer hardware id must be a GUID. It was {filterOptions.ComputerHardwareIdFilter}");
                    return(null);
                }
                else
                {
                    filter.ComputerHardwareIdFilter = computerHardwareIdFilterGuid;
                }
            }

            filter.ClassificationFilter = StringGuidsToGuids(filterOptions.ClassificationsFilter);
            if (filter.ClassificationFilter == null)
            {
                ConsoleOutput.WriteRed("The classification filter must contain only GUIDs!");
                return(null);
            }

            filter.ProductFilter = StringGuidsToGuids(filterOptions.ProductsFilter);
            if (filter.ProductFilter == null)
            {
                ConsoleOutput.WriteRed("The product ID filter must contain only GUIDs!");
                return(null);
            }

            filter.IdFilter = StringGuidsToGuids(filterOptions.IdFilter);
            if (filter.IdFilter == null)
            {
                ConsoleOutput.WriteRed("The update ID filter must contain only GUIDs!");
                return(null);
            }

            filter.SkipSuperseded = filterOptions.SkipSuperseded;

            return(filter);
        }
        public void testParseFieldMapFromString_parentWithTwoChildrenAsGroup()
        {
            var fieldMap = new Dictionary <string, SortedSet <string> >
            {
                {
                    "fixedLine",
                    new SortedSet <string>(new List <string>
                    {
                        "exampleNumber",
                        "possibleLength"
                    })
                }
            };

            Assert.Equal(
                MetadataFilter.ParseFieldMapFromString("fixedLine(exampleNumber,possibleLength)"),
                fieldMap);
        }
        public void testParseFieldMapFromString_parentAsGroup()
        {
            var fieldMap = new Dictionary <string, SortedSet <string> >
            {
                {
                    "fixedLine",
                    new SortedSet <string>(new List <string>
                    {
                        "nationalNumberPattern",
                        "possibleLength",
                        "possibleLengthLocalOnly",
                        "exampleNumber"
                    })
                }
            };

            Assert.Equal(MetadataFilter.ParseFieldMapFromString("fixedLine"), fieldMap);
        }
        public void TestFilterMetadata_SpecialBuild()
        {
            var metadata = FakeArmeniaPhoneMetadata();

            MetadataFilter.ForSpecialBuild().FilterMetadata(metadata);

            // id, country_code, and international_prefix should never be cleared.
            Assert.Equal(metadata.Id, ID);
            Assert.Equal(metadata.CountryCode, COUNTRY_CODE);
            Assert.Equal(metadata.InternationalPrefix, INTERNATIONAL_PREFIX);

            // preferred_international_prefix should be cleared in specialBuild.
            Assert.False(metadata.HasPreferredInternationalPrefix);

            // general_desc should have all fields but example_number; mobile should have all fields.
            foreach (var desc in new List <PhoneNumberDesc>
            {
                metadata.GeneralDesc,
                metadata.Mobile
            })
            {
                Assert.Equal(desc.NationalNumberPattern, NATIONAL_NUMBER_PATTERN);
                Assert.True(ContentsEqual(desc.PossibleLengthList.ToList(), PossibleLengths));
                Assert.True(ContentsEqual(desc.PossibleLengthLocalOnlyList.ToList(), PossibleLengthsLocalOnly));
            }

            Assert.False(metadata.GeneralDesc.HasExampleNumber);
            Assert.Equal(metadata.Mobile.ExampleNumber, EXAMPLE_NUMBER);

            // All other PhoneNumberDescs must have all fields cleared.
            foreach (var desc in new List <PhoneNumberDesc>
            {
                metadata.FixedLine,
                metadata.TollFree
            })
            {
                Assert.False(desc.HasNationalNumberPattern);
                Assert.Equal(0, desc.PossibleLengthList.Count);
                Assert.Equal(0, desc.PossibleLengthLocalOnlyList.Count);
                Assert.False(desc.HasExampleNumber);
            }
        }
コード例 #21
0
        public static MetadataFilter QueryFilterFromCommandLineFilter(ISyncQueryFilter filterOptions)
        {
            var filter = new MetadataFilter();

            filter.ClassificationFilter = StringGuidsToGuids(filterOptions.ClassificationsFilter);
            if (filter.ClassificationFilter == null)
            {
                ConsoleOutput.WriteRed("The classification filter must contain only GUIDs!");
                return(null);
            }

            filter.ProductFilter = StringGuidsToGuids(filterOptions.ProductsFilter);
            if (filter.ProductFilter == null)
            {
                ConsoleOutput.WriteRed("The product ID filter must contain only GUIDs!");
                return(null);
            }

            return(filter);
        }
コード例 #22
0
        /// <summary>
        /// Converts array of metadata, array of sources and corresponding join operations to Language Service input format - an object of <see cref="Filters"/>.
        /// </summary>
        /// <param name="metadata">Array of <see cref="Metadata"/>.</param>
        /// <param name="metadataFiltersJoinOperation">Metadata Compound Operation.</param>
        /// <remarks>Required for bot codes working with legacy metadata filters.</remarks>
        /// <returns>An object of <see cref="Filters"/>.</returns>
        public static Filters GetFilters(Metadata[] metadata, string metadataFiltersJoinOperation = "AND")
        {
            if (metadata == null)
            {
                return(null);
            }

            var metadataFilter = new MetadataFilter()
            {
                LogicalOperation = metadataFiltersJoinOperation
            };

            metadataFilter.Metadata.AddRange(metadata.Select(m => { return(new KeyValuePair <string, string>(key: m.Name, value: m.Value)); }).ToList());

            return(new Filters()
            {
                MetadataFilter = metadataFilter,
                LogicalOperation = JoinOperator.OR.ToString()
            });
        }
        public MetadataFilterItemControl()
        {
            InitializeComponent();

            var filter = new MetadataFilter();

            _filterItem = new MetadataFilterItem(filter);

            TextBoxServer.TextChanged += TextBoxServer_TextChanged;

            ComboBoxDatabase.AddHandler(TextBoxBase.TextChangedEvent,
                                        new TextChangedEventHandler(ComboBoxDatabase_TextChanged));
            ComboBoxSchema.AddHandler(TextBoxBase.TextChangedEvent,
                                      new TextChangedEventHandler(ComboBoxSchema_TextChanged));

            TextBoxPackage.TextChanged    += TextBoxPackage_TextChanged;
            TextBoxObjectName.TextChanged += TextBlockObjectName_TextChanged;

            CheckBoxUserObject.Checked   += CheckBoxUserObject_CheckedChanged;
            CheckBoxUserObject.Unchecked += CheckBoxUserObject_CheckedChanged;

            CheckBoxSystemObject.Checked   += CheckBoxSystemObject_CheckedChanged;
            CheckBoxSystemObject.Unchecked += CheckBoxSystemObject_CheckedChanged;

            CheckBoxTable.Checked   += CheckBoxTable_CheckedChanged;
            CheckBoxTable.Unchecked += CheckBoxTable_CheckedChanged;

            CheckBoxView.Checked   += CheckBoxView_CheckedChanged;
            CheckBoxView.Unchecked += CheckBoxView_CheckedChanged;

            CheckBoxProcedure.Checked   += CheckBoxProcedure_CheckedChanged;
            CheckBoxProcedure.Unchecked += CheckBoxProcedure_CheckedChanged;

            CheckBoxSynonym.Checked   += CheckBoxSynonym_CheckedChanged;
            CheckBoxSynonym.Unchecked += CheckBoxSynonym_CheckedChanged;

            TextBoxField.TextChanged += TextBoxField_TextChanged;

            BindLocalization();
        }
        public MetadataFilterItemControl()
        {
            InitializeComponent();

            _filter     = new MetadataFilter();
            _filterItem = new MetadataFilterItem(_filter);

            tbServer.TextChanged       += tbServer_TextChanged;
            cmbDatabases.TextChanged   += cmbDatabases_TextChanged;
            cmbSchemas.TextChanged     += cmbSchemas_TextChanged;
            tbPackage.TextChanged      += tbPackage_TextChanged;
            tbObject.TextChanged       += tbObject_TextChanged;
            cbUser.CheckedChanged      += cbUser_CheckedChanged;
            cbSystem.CheckedChanged    += cbSystem_CheckedChanged;
            cbTable.CheckedChanged     += cbTable_CheckedChanged;
            cbView.CheckedChanged      += cbView_CheckedChanged;
            cbProcedure.CheckedChanged += cbProcedure_CheckedChanged;
            cbSynonym.CheckedChanged   += cbSynonym_CheckedChanged;
            tbField.TextChanged        += tbField_TextChanged;

            BindLocalization();
        }
        public void testComputeComplement_allAndNothing()
        {
            var map1 = new Dictionary <string, SortedSet <string> >
            {
                { "fixedLine", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "mobile", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "tollFree", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "premiumRate", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "sharedCost", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "personalNumber", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "voip", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "pager", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "uan", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "emergency", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "voicemail", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "shortCode", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "standardRate", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "carrierSpecific", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "smsServices", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                {
                    "noInternationalDialling",
                    new SortedSet <string>(MetadataFilter.ExcludableChildFields)
                },
                { "preferredInternationalPrefix", new SortedSet <string>() },
                { "nationalPrefix", new SortedSet <string>() },
                { "preferredExtnPrefix", new SortedSet <string>() },
                { "nationalPrefixTransformRule", new SortedSet <string>() },
                { "sameMobileAndFixedLinePattern", new SortedSet <string>() },
                { "mainCountryForCode", new SortedSet <string>() },
                { "leadingZeroPossible", new SortedSet <string>() },
                { "mobileNumberPortableRegion", new SortedSet <string>() }
            };

            var map2 = new Dictionary <string, SortedSet <string> >();

            Assert.Equal(MetadataFilter.ComputeComplement(map1), map2);
            Assert.Equal(MetadataFilter.ComputeComplement(map2), map1);
        }
コード例 #26
0
 /// <summary>
 /// Finds all language services of the corresponding type across all supported languages that match the filter criteria.
 /// </summary>
 public abstract IEnumerable <TLanguageService> FindLanguageServices <TLanguageService>(MetadataFilter filter);
コード例 #27
0
 public void ToStringTest(string key, string value)
 {
     MetadataFilter<ITestDescriptor> filter = new MetadataFilter<ITestDescriptor>(key,
         new EqualityFilter<string>(value));
     Assert.AreEqual("Metadata('" + key + "', Equality('" + value + "'))", filter.ToString());
 }
        public void TestShouldDrop()
        {
            var blacklist = new Dictionary <string, SortedSet <string> >
            {
                { "fixedLine", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "mobile", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "tollFree", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "premiumRate", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "emergency", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                {
                    "voicemail",
                    new SortedSet <string>(new List <string>
                    {
                        "possibleLength",
                        "exampleNumber"
                    })
                },
                { "shortCode", new SortedSet <string> {
                      "exampleNumber"
                  } },
                { "standardRate", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "carrierSpecific", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                { "smsServices", new SortedSet <string>(MetadataFilter.ExcludableChildFields) },
                {
                    "noInternationalDialling",
                    new SortedSet <string>(MetadataFilter.ExcludableChildFields)
                },
                { "nationalPrefixTransformRule", new SortedSet <string>() },
                { "sameMobileAndFixedLinePattern", new SortedSet <string>() },
                { "mainCountryForCode", new SortedSet <string>() },
                { "leadingZeroPossible", new SortedSet <string>() },
                { "mobileNumberPortableRegion", new SortedSet <string>() }
            };

            var filter = new MetadataFilter(blacklist);

            Assert.True(filter.ShouldDrop("fixedLine", "exampleNumber"));
            Assert.False(filter.ShouldDrop("sharedCost", "exampleNumber"));
            Assert.False(filter.ShouldDrop("emergency", "exampleNumber"));
            Assert.True(filter.ShouldDrop("emergency", "nationalNumberPattern"));
            Assert.False(filter.ShouldDrop("preferredInternationalPrefix"));
            Assert.True(filter.ShouldDrop("mobileNumberPortableRegion"));
            Assert.True(filter.ShouldDrop("smsServices", "nationalNumberPattern"));

            // Integration tests starting with flag values.
            Assert.True(BuildMetadataFromXml.GetMetadataFilter(true, false)
                        .ShouldDrop("fixedLine", "exampleNumber"));

            // Integration tests starting with blacklist strings.
            Assert.True(new MetadataFilter(MetadataFilter.ParseFieldMapFromString("fixedLine"))
                        .ShouldDrop("fixedLine", "exampleNumber"));
            Assert.False(new MetadataFilter(MetadataFilter.ParseFieldMapFromString("uan"))
                         .ShouldDrop("fixedLine", "exampleNumber"));

            // Integration tests starting with whitelist strings.
            Assert.False(new MetadataFilter(MetadataFilter.ComputeComplement(
                                                MetadataFilter.ParseFieldMapFromString("exampleNumber")))
                         .ShouldDrop("fixedLine", "exampleNumber"));
            Assert.True(new MetadataFilter(MetadataFilter.ComputeComplement(
                                               MetadataFilter.ParseFieldMapFromString("uan"))).ShouldDrop("fixedLine", "exampleNumber"));

            // Integration tests with an empty blacklist.
            Assert.False(new MetadataFilter(new Dictionary <string, SortedSet <string> >())
                         .ShouldDrop("fixedLine", "exampleNumber"));
        }
        public void testParseFieldMapFromString_RuntimeExceptionCases()
        {
            // Null input.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString(null));

            // Empty input.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString(""));

            // Whitespace input.
            try
            {
                MetadataFilter.ParseFieldMapFromString(" ");
                Assert.True(false);
            }
            catch (Exception)
            {
                // Test passed.
            }

            // Bad token given as only group.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("something_else"));

            // Bad token given as last group.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine:something_else"));

            // Bad token given as middle group.
            try
            {
                MetadataFilter.ParseFieldMapFromString(
                    "pager:nationalPrefix:something_else:nationalNumberPattern");
                Assert.True(false);
            }
            catch (Exception)
            {
                // Test passed.
            }

            // Childless field given as parent.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("nationalPrefix(exampleNumber)"));

            // Child field given as parent.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("possibleLength(exampleNumber)"));

            // Bad token given as parent.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("something_else(exampleNumber)"));

            // Parent field given as only child.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(uan)"));

            // Parent field given as first child.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(uan,possibleLength)"));

            // Parent field given as last child.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(possibleLength,uan)"));

            // Parent field given as middle child.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(possibleLength,uan,exampleNumber)"));

            // Childless field given as only child.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(nationalPrefix)"));

            // Bad token given as only child.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(something_else)"));

            // Bad token given as last child.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("uan(possibleLength,something_else)"));

            // Empty parent.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("(exampleNumber)"));

            // Whitespace parent.
            try
            {
                MetadataFilter.ParseFieldMapFromString(" (exampleNumber)");
                Assert.True(false);
            }
            catch (Exception)
            {
                // Test passed.
            }

            // Empty child.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine()"));

            // Whitespace child.
            try
            {
                MetadataFilter.ParseFieldMapFromString("fixedLine( )");
                Assert.True(false);
            }
            catch (Exception)
            {
                // Test passed.
            }

            // Empty parent and child.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("()"));

            // Whitespace parent and empty child.
            try
            {
                MetadataFilter.ParseFieldMapFromString(" ()");
                Assert.True(false);
            }
            catch (Exception)
            {
                // Test passed.
            }

            // Parent field given as a group twice.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine:uan:fixedLine"));

            // Parent field given as the parent of a group and as a group by itself.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(exampleNumber):fixedLine"));

            // Parent field given as the parent of one group and then as the parent of another group.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(exampleNumber):fixedLine(possibleLength)"));

            // Childless field given twice as a group.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("nationalPrefix:uan:nationalPrefix"));

            // Child field given twice as a group.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("exampleNumber:uan:exampleNumber"));

            // Child field given first as the only child in a group and then as a group by itself.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(exampleNumber):exampleNumber"));

            // Child field given first as a child in a group and then as a group by itself.
            Assert.Throws <Exception>(() =>
                                      MetadataFilter.ParseFieldMapFromString(
                                          "uan(nationalNumberPattern,possibleLength,exampleNumber)"
                                          + ":possibleLengthLocalOnly"
                                          + ":exampleNumber"));

            // Child field given twice as children of the same parent.
            Assert.Throws <Exception>(() =>
                                      MetadataFilter.ParseFieldMapFromString(
                                          "fixedLine(possibleLength,exampleNumber,possibleLength)"));

            // Child field given as a group by itself while it's covered by all parents explicitly.
            Assert.Throws <Exception>(() =>
                                      MetadataFilter.ParseFieldMapFromString(
                                          "fixedLine(exampleNumber)"
                                          + ":mobile(exampleNumber)"
                                          + ":tollFree(exampleNumber)"
                                          + ":premiumRate(exampleNumber)"
                                          + ":sharedCost(exampleNumber)"
                                          + ":personalNumber(exampleNumber)"
                                          + ":voip(exampleNumber)"
                                          + ":pager(exampleNumber)"
                                          + ":uan(exampleNumber)"
                                          + ":emergency(exampleNumber)"
                                          + ":voicemail(exampleNumber)"
                                          + ":shortCode(exampleNumber)"
                                          + ":standardRate(exampleNumber)"
                                          + ":carrierSpecific(exampleNumber)"
                                          + ":noInternationalDialling(exampleNumber)"
                                          + ":exampleNumber"));

            // Child field given as a group by itself while it's covered by all parents, some implicitly and
            // some explicitly.
            Assert.Throws <Exception>(() =>
                                      MetadataFilter.ParseFieldMapFromString(
                                          "fixedLine"
                                          + ":mobile"
                                          + ":tollFree"
                                          + ":premiumRate"
                                          + ":sharedCost"
                                          + ":personalNumber"
                                          + ":voip"
                                          + ":pager(exampleNumber)"
                                          + ":uan(exampleNumber)"
                                          + ":emergency(exampleNumber)"
                                          + ":voicemail(exampleNumber)"
                                          + ":shortCode(exampleNumber)"
                                          + ":standardRate(exampleNumber)"
                                          + ":carrierSpecific(exampleNumber)"
                                          + ":smsServices"
                                          + ":noInternationalDialling(exampleNumber)"
                                          + ":exampleNumber"));

            // Missing right parenthesis in only group.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(exampleNumber"));

            // Missing right parenthesis in first group.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(exampleNumber:pager"));

            // Missing left parenthesis in only group.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLineexampleNumber)"));

            // Early right parenthesis in only group.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(example_numb)er"));

            // Extra right parenthesis at end of only group.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(exampleNumber))"));

            // Extra right parenthesis between proper parentheses.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(example_numb)er)"));

            // Extra left parenthesis in only group.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine((exampleNumber)"));

            // Extra level of children.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(exampleNumber(possibleLength))"));

            // Trailing comma in children.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(exampleNumber,)"));

            // Leading comma in children.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(,exampleNumber)"));

            // Empty token between commas.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("fixedLine(possibleLength,,exampleNumber)"));

            // Trailing colon.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("uan:"));

            // Leading colon.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString(":uan"));

            // Empty token between colons.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("uan::fixedLine"));

            // Missing colon between groups.
            Assert.Throws <Exception>(() => MetadataFilter.ParseFieldMapFromString("uan(possibleLength)pager"));
        }
        public void TestParseFieldMapFromString_EquivalentExpressions()
        {
            // Listing all excludable parent fields is equivalent to listing all excludable child fields.
            Assert.Equal(
                MetadataFilter.ParseFieldMapFromString(
                    "fixedLine"
                    + ":mobile"
                    + ":tollFree"
                    + ":premiumRate"
                    + ":sharedCost"
                    + ":personalNumber"
                    + ":voip"
                    + ":pager"
                    + ":uan"
                    + ":emergency"
                    + ":voicemail"
                    + ":shortCode"
                    + ":standardRate"
                    + ":carrierSpecific"
                    + ":smsServices"
                    + ":noInternationalDialling"),
                MetadataFilter.ParseFieldMapFromString(
                    "nationalNumberPattern"
                    + ":possibleLength"
                    + ":possibleLengthLocalOnly"
                    + ":exampleNumber"));

            // Order and whitespace don't matter.
            Assert.Equal(
                MetadataFilter.ParseFieldMapFromString(
                    " nationalNumberPattern "
                    + ": uan ( exampleNumber , possibleLengthLocalOnly,     possibleLength ) "
                    + ": nationalPrefix "
                    + ": fixedLine "
                    + ": pager ( exampleNumber ) "),
                MetadataFilter.ParseFieldMapFromString(
                    "uan(possibleLength,exampleNumber,possibleLengthLocalOnly)"
                    + ":pager(exampleNumber)"
                    + ":fixedLine"
                    + ":nationalPrefix"
                    + ":nationalNumberPattern"));

            // Parent explicitly listing all possible children.
            Assert.Equal(
                MetadataFilter.ParseFieldMapFromString(
                    "uan(nationalNumberPattern,possibleLength,exampleNumber,possibleLengthLocalOnly)"),
                MetadataFilter.ParseFieldMapFromString("uan"));

            // All parent's children covered, some implicitly and some explicitly.
            Assert.Equal(
                MetadataFilter.ParseFieldMapFromString(
                    "uan(nationalNumberPattern,possibleLength,exampleNumber):possibleLengthLocalOnly"),
                MetadataFilter.ParseFieldMapFromString("uan:possibleLengthLocalOnly"));

            // Child field covered by all parents explicitly.
            // It seems this will always be better expressed as a wildcard child, but the check is complex
            // and may not be worth it.
            Assert.Equal(
                MetadataFilter.ParseFieldMapFromString(
                    "fixedLine(exampleNumber)"
                    + ":mobile(exampleNumber)"
                    + ":tollFree(exampleNumber)"
                    + ":premiumRate(exampleNumber)"
                    + ":sharedCost(exampleNumber)"
                    + ":personalNumber(exampleNumber)"
                    + ":voip(exampleNumber)"
                    + ":pager(exampleNumber)"
                    + ":uan(exampleNumber)"
                    + ":emergency(exampleNumber)"
                    + ":voicemail(exampleNumber)"
                    + ":shortCode(exampleNumber)"
                    + ":standardRate(exampleNumber)"
                    + ":carrierSpecific(exampleNumber)"
                    + ":smsServices(exampleNumber)"
                    + ":noInternationalDialling(exampleNumber)"),
                MetadataFilter.ParseFieldMapFromString("exampleNumber"));

            // Child field given as a group by itself while it's covered by all parents implicitly.
            // It seems this will always be better expressed without the wildcard child, but the check is
            // complex and may not be worth it.
            Assert.Equal(
                MetadataFilter.ParseFieldMapFromString(
                    "fixedLine"
                    + ":mobile"
                    + ":tollFree"
                    + ":premiumRate"
                    + ":sharedCost"
                    + ":personalNumber"
                    + ":voip"
                    + ":pager"
                    + ":uan"
                    + ":emergency"
                    + ":voicemail"
                    + ":shortCode"
                    + ":standardRate"
                    + ":carrierSpecific"
                    + ":smsServices"
                    + ":noInternationalDialling"
                    + ":exampleNumber"),
                MetadataFilter.ParseFieldMapFromString(
                    "fixedLine"
                    + ":mobile"
                    + ":tollFree"
                    + ":premiumRate"
                    + ":sharedCost"
                    + ":personalNumber"
                    + ":voip"
                    + ":pager"
                    + ":uan"
                    + ":emergency"
                    + ":voicemail"
                    + ":shortCode"
                    + ":standardRate"
                    + ":carrierSpecific"
                    + ":smsServices"
                    + ":noInternationalDialling"));
        }
        public void testParseFieldMapFromString_mixOfGroups()
        {
            var fieldMap = new Dictionary <string, SortedSet <string> >
            {
                {
                    "uan",
                    new SortedSet <string>(new List <string>
                    {
                        "possibleLength",
                        "exampleNumber",
                        "possibleLengthLocalOnly",
                        "nationalNumberPattern"
                    })
                },
                {
                    "pager",
                    new SortedSet <string>(new List <string>
                    {
                        "exampleNumber",
                        "nationalNumberPattern"
                    })
                },
                {
                    "fixedLine",
                    new SortedSet <string>(new List <string>
                    {
                        "nationalNumberPattern",
                        "possibleLength",
                        "possibleLengthLocalOnly",
                        "exampleNumber"
                    })
                },
                { "nationalPrefix", new SortedSet <string>() },
                { "mobile", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                { "tollFree", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                { "premiumRate", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                { "sharedCost", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                { "personalNumber", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                { "voip", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                { "emergency", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                { "voicemail", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                { "shortCode", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                { "standardRate", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                { "carrierSpecific", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                { "smsServices", new SortedSet <string> {
                      "nationalNumberPattern"
                  } },
                {
                    "noInternationalDialling",
                    new SortedSet <string>(new List <string>
                    {
                        "nationalNumberPattern"
                    })
                }
            };

            Assert.Equal(MetadataFilter.ParseFieldMapFromString(
                             "uan(possibleLength,exampleNumber,possibleLengthLocalOnly)"
                             + ":pager(exampleNumber)"
                             + ":fixedLine"
                             + ":nationalPrefix"
                             + ":nationalNumberPattern"),
                         fieldMap);
        }