Esempio n. 1
0
 private void FilterByVersion(ref CollationCollection cols)
 {
     if (this.MyInvocation.BoundParameters.ContainsKey("Version"))
     {
         for (int i = cols.Count - 1; i >= 0; i--)
         {
             Collation c = cols[i];
             if (!this.Version.Contains(c.CollationVersion))
             {
                 cols.Remove(c);
             }
         }
     }
 }
Esempio n. 2
0
 private void FilterByLocaleId(ref CollationCollection cols)
 {
     if (this.MyInvocation.BoundParameters.ContainsKey("LocaleID"))
     {
         for (int i = cols.Count - 1; i >= 0; i--)
         {
             Collation c = cols[i];
             if (!this.LocaleID.Contains(c.LocaleID))
             {
                 cols.Remove(c);
             }
         }
     }
 }
Esempio n. 3
0
 private void FilterByName(ref CollationCollection cols)
 {
     if (this.MyInvocation.BoundParameters.ContainsKey("Name"))
     {
         var wcp = new WildcardPattern(this.Name, WildcardOptions.IgnoreCase);
         for (int i = cols.Count - 1; i >= 0; i--)
         {
             Collation c = cols[i];
             if (!wcp.IsMatch(c.Name))
             {
                 cols.Remove(c);
             }
         }
     }
 }
Esempio n. 4
0
        protected override void ProcessRecord()
        {
            var cols = CollationCollection.GetCollations(SmoContext.Connection);

            this.FilterByName(ref cols);
            this.FilterByLocaleId(ref cols);
            this.FilterByVersion(ref cols);

            if (this.MyInvocation.BoundParameters.ContainsKey("SortBy"))
            {
                this.Sort(ref cols);
            }

            WriteObject(cols, true);
        }
Esempio n. 5
0
        public void TestCollation()
        {
            Type colType = typeof(Collation);
            Type colCol  = typeof(CollationCollection);

            // Test constructors
            ConstructorInfo[] constrs = colType.GetConstructors();
            Assert.IsTrue(constrs.Length > 0 &&
                          constrs.Any(
                              x => x.GetParameters().First(
                                  p => p.ParameterType.Equals(DRTYPE)) != null));

            // Test properties can be set.
            Assert.IsTrue(colType.GetProperties(FLAGS).All(x => x.CanWrite));

            Context.Validate();

            var cols = CollationCollection.GetCollations(Context.Connection);

            Assert.IsNotNull(cols);
            Assert.IsInstanceOfType(cols[0], colType);
            if (cols.Count > 1)
            {
                cols.SortByName();
                Assert.IsTrue(cols[0].Name.CompareTo(cols[1].Name) < 0);

                cols.SortByName(true);
                Assert.IsTrue(cols[0].Name.CompareTo(cols[1].Name) > 0);

                Assert.IsInstanceOfType(cols.Clone(), colCol);
                Assert.IsNotNull(cols.Find(x => x.Name.Equals(TEST_COLLATION, StringComparison.CurrentCultureIgnoreCase)));
                Assert.IsTrue(cols.FindAll(x => x.LocaleID.Equals(1033)).Count > 0);
                var newCol = cols.FindByLocaleID(1033);
                Assert.IsNotNull(newCol);
                Assert.IsTrue(newCol.Count > 0);
                Assert.IsInstanceOfType(newCol, colCol);
            }

            Assert.IsNotNull(CollationCollection.GetCollations(Context.Connection, CollationVersion.Version80));
            Assert.IsNotNull(CollationCollection.GetCollations(Context.Connection, 1033));
            Assert.IsNotNull(CollationCollection.GetCollations(Context.Connection, 1033, CollationVersion.Version80));
        }
Esempio n. 6
0
        private void Sort(ref CollationCollection cols)
        {
            switch (this.SortBy)
            {
            case "Name":
            {
                cols.SortByName(_dynLib.ParameterHasValue("Ascending"));
                break;
            }

            case "LocaleID":
            {
                cols.SortByLocaleID();
                break;
            }

            case "Version":
            {
                cols.SortByVersion();
                break;
            }
            }
        }