コード例 #1
0
        private PropertySet EnsurePropertyCache(AttributeColumn column)
        {
            PropertySet properties;

            if (!this.cache.TryGetValue(column.Type, out properties))
            {
                properties = new PropertySet();

                foreach (var name in column.GetNames())
                {
                    var property = new PSAdaptedProperty(PropertyPrefix + name, name);
                    properties.Add(property);
                }

                // Add a property for the numeric value.
                properties.Add(new PSAdaptedProperty(ValueProperty, null));

                // Add the enumeration type to the list of type names.
                properties.TypeName = typeof(AttributeColumn).FullName + "#" + column.Type.Name;

                // Cache the properties to avoid extra allocations.
                this.cache.Add(column.Type, properties);
            }

            return(properties);
        }
コード例 #2
0
        public void ConvertAttributeColumnToString()
        {
            var converter = new AttributeColumnTypeConverter();
            var column    = new AttributeColumn(null, 42);

            Assert.IsFalse(converter.CanConvertTo(column, typeof(string)));
            converter.ConvertTo(column, typeof(string), CultureInfo.InvariantCulture, false);
        }
コード例 #3
0
        public void ConvertAttributeColumnToNullableInteger()
        {
            var converter = new AttributeColumnTypeConverter();
            var column    = new AttributeColumn(null, null);

            Assert.IsTrue(converter.CanConvertTo(column, typeof(int?)));
            int?value = (int?)converter.ConvertTo(column, typeof(int?), CultureInfo.InvariantCulture, false);

            Assert.IsNull(value);
        }
コード例 #4
0
        public void ConvertAttributeColumnToInteger()
        {
            var converter = new AttributeColumnTypeConverter();
            var column    = new AttributeColumn(null, 42);

            Assert.IsTrue(converter.CanConvertTo(column, typeof(int)));
            int value = (int)converter.ConvertTo(column, typeof(int), CultureInfo.InvariantCulture, false);

            Assert.AreEqual <int>(42, value);
        }
コード例 #5
0
        public void ColumnAttributesReadOnly()
        {
            var adapter = new AttributeColumnPropertyAdapter();
            var column = new AttributeColumn(typeof(ComponentAttributes), 260);

            // Validate the specific HasRegistryKeyPath property using case-insensitive search.
            var property = adapter.GetProperty(column, "hasregistrykeypath");
            Assert.IsNotNull(property);
            Assert.IsFalse(adapter.IsSettable(property));
            adapter.SetPropertyValue(property, 260);
        }
コード例 #6
0
        public void ColumnAttributesReadOnly()
        {
            var adapter = new AttributeColumnPropertyAdapter();
            var column  = new AttributeColumn(typeof(ComponentAttributes), 260);

            // Validate the specific HasRegistryKeyPath property using case-insensitive search.
            var property = adapter.GetProperty(column, "hasregistrykeypath");

            Assert.IsNotNull(property);
            Assert.IsFalse(adapter.IsSettable(property));
            adapter.SetPropertyValue(property, 260);
        }
コード例 #7
0
        public void ColumnAttributesTypeAdapted()
        {
            var adapter = new AttributeColumnPropertyAdapter();
            var column  = new AttributeColumn(typeof(ComponentAttributes), 260);

            // Get the names we will expected.
            var expectedNames = Enum.GetNames(column.Type).Select(s => "Has" + s).ToList();

            expectedNames.Add("Value");

            // Make sure all the expected names will be adapted.
            var properties = adapter.GetProperties(column).Select(p => p.Name);

            CollectionAssert.AreEqual(expectedNames.ToArray(), properties.ToArray());

            // Validate the specific HasRegistryKeyPath property using case-insensitive search.
            var property = adapter.GetProperty(column, "hasregistrykeypath");

            Assert.IsNotNull(property);
            Assert.AreEqual("RegistryKeyPath", property.Tag);
            Assert.AreEqual <string>(typeof(bool).FullName, AttributeColumnPropertyAdapter.GetPropertyTypeNameInternal(property, column));
            Assert.IsTrue(adapter.IsGettable(property));
            Assert.IsTrue((bool)AttributeColumnPropertyAdapter.GetPropertyValueInternal(property, column));

            // Validate the specific Value property using case-sensitive search.
            property = adapter.GetProperty(column, "Value");
            Assert.IsNotNull(property);
            Assert.IsNull(property.Tag);
            Assert.AreEqual <string>(typeof(ComponentAttributes).FullName, AttributeColumnPropertyAdapter.GetPropertyTypeNameInternal(property, column));
            Assert.IsTrue(adapter.IsGettable(property));
            Assert.AreEqual <int>(260, (int)AttributeColumnPropertyAdapter.GetPropertyValueInternal(property, column));

            // Validate the PSTypeNames.
            var types         = adapter.GetTypeNameHierarchy(column);
            var expectedTypes = new string[]
            {
                typeof(AttributeColumn).FullName + "#ComponentAttributes",
                typeof(AttributeColumn).FullName,
                typeof(object).FullName,
            };

            CollectionAssert.AreEqual(expectedTypes, types);
        }
コード例 #8
0
        public void ColumnAttributesTypeAdapted()
        {
            var adapter = new AttributeColumnPropertyAdapter();
            var column = new AttributeColumn(typeof(ComponentAttributes), 260);

            // Get the names we will expected.
            var expectedNames = Enum.GetNames(column.Type).Select(s => "Has" + s).ToList();
            expectedNames.Add("Value");

            // Make sure all the expected names will be adapted.
            var properties = adapter.GetProperties(column).Select(p => p.Name);
            CollectionAssert.AreEqual(expectedNames.ToArray(), properties.ToArray());

            // Validate the specific HasRegistryKeyPath property using case-insensitive search.
            var property = adapter.GetProperty(column, "hasregistrykeypath");
            Assert.IsNotNull(property);
            Assert.AreEqual("RegistryKeyPath", property.Tag);
            Assert.AreEqual<string>(typeof(bool).FullName, AttributeColumnPropertyAdapter.GetPropertyTypeNameInternal(property, column));
            Assert.IsTrue(adapter.IsGettable(property));
            Assert.IsTrue((bool)AttributeColumnPropertyAdapter.GetPropertyValueInternal(property, column));

            // Validate the specific Value property using case-sensitive search.
            property = adapter.GetProperty(column, "Value");
            Assert.IsNotNull(property);
            Assert.IsNull(property.Tag);
            Assert.AreEqual<string>(typeof(ComponentAttributes).FullName, AttributeColumnPropertyAdapter.GetPropertyTypeNameInternal(property, column));
            Assert.IsTrue(adapter.IsGettable(property));
            Assert.AreEqual<int>(260, (int)AttributeColumnPropertyAdapter.GetPropertyValueInternal(property, column));

            // Validate the PSTypeNames.
            var types = adapter.GetTypeNameHierarchy(column);
            var expectedTypes = new string[]
            {
                typeof(AttributeColumn).FullName + "#ComponentAttributes",
                typeof(AttributeColumn).FullName,
                typeof(object).FullName,
            };
            CollectionAssert.AreEqual(expectedTypes, types);
        }
コード例 #9
0
        internal static object GetPropertyValueInternal(PSAdaptedProperty adaptedProperty, AttributeColumn column)
        {
            if (null != column)
            {
                var name = (string)adaptedProperty.Tag;
                if (!string.IsNullOrEmpty(name) && Enum.IsDefined(column.Type, name))
                {
                    return(column.HasValue(name));
                }
                else if (ValueProperty.Equals(adaptedProperty.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return(column.Value);
                }
            }

            return(0);
        }
コード例 #10
0
        private void GetColumnProperties()
        {
            var sw = new Stopwatch();

            sw.Start();

            var loaded    = false;
            var iteration = 0;

            while (!loaded && iteration++ < 5)
            {
                try
                {
                    //var allAtts = (from ei in _entities
                    //    from ed in ei.EntityDatas
                    //    where ed.Active
                    //    group ed by ed.Attribute.AttributeName.ToLower()
                    //    into grp
                    //    select grp.First().Attribute).ToList();

                    //var attGroups = (from ei in _entities
                    //    let ed = ei.EntityDatas.FirstOrDefault(d => d.Active)
                    //    where ed != null
                    //    group ei by ed.Attribute).ToList();

                    var attIds = (from ei in _entities
                                  from ed in ei.EntityDatas
                                  where ed.Active
                                  select ed.AttributeID
                                  ).Distinct().ToList();

                    var atts = from att in AryaTools.Instance.InstanceData.Dc.Attributes
                               where attIds.Contains(att.ID)
                               select att;

                    //_dsAttributes = allAtts.Select(att => new AttributeColumn(att, _taxonomyNodes)).ToList();
                    _dsAttributes =
                        atts.Select(att => new AttributeColumn(att, _taxonomyNodes, GetEntities(_entities, att)))
                        .ToList();

                    AttributeColumn.RefreshAttributeColumnPositions(_dsAttributes,
                                                                    atts.ToDictionary(att => att.AttributeName),
                                                                    _taxonomyNodes,
                                                                    true);

                    //var currentTaxIDs = _taxonomyNodes.Select(p => p.ID).ToList();

                    //_multiValuedAttributes = (from ei in _entities
                    //                          from ed in ei.EntityDatas
                    //                          where ed.Active
                    //                          group ed by new {ed.EntityInfo.SkuID, ed.AttributeID}
                    //                          into attrGrp
                    //                          where attrGrp.Count() > 1
                    //                          select attrGrp.Key.AttributeID).Distinct().ToHashSet();

                    //CacheRanks(currentTaxIDs);

                    loaded = true;
                }
                catch (NullReferenceException)
                {
                    Thread.Sleep(100);
                }
                catch (InvalidCastException)
                {
                    Thread.Sleep(100);
                }
            }

            sw.Stop();
            Diagnostics.WriteMessage("Getting Column Properties", "GetColumnProperties()", sw.Elapsed);
            sw.Reset();
        }