public static void AddMissingParentAttributes(this ServiceKey key)
        {
            if (key.ParentServiceKey != null)
            {
                key.ParentServiceKey.AddMissingAttributes();

                var    childConfig  = ServiceConfiguration.Get(key.Id, key.EffectiveDate);
                var    parentConfig = ServiceConfiguration.Get(key.ParentServiceKey.Id, key.ParentServiceKey.EffectiveDate);
                string value;
                foreach (var attribute in childConfig.Attributes)
                {
                    if (attribute.Value.Type == AttributeType.Parent)
                    {
                        value = key.ParentServiceKey.GetAttributeValue(attribute.Value.Name, SearchOptions.ALL_TRUE);
                        if (value == null)
                        {
                            value = parentConfig.GetDefaultValue(attribute.Value.Name, key.ParentServiceKey);
                        }
                        if (value != null)
                        {
                            key.AddAttribute(attribute.Value.Name, value);
                        }
                    }
                }
            }
        }
Пример #2
0
        public void Validate()
        {
            Startup.LoadSettings();
            // test assumes service 227 has child of 236 named "LAN PORT SERVICE"

            var key = new ServiceKey();

            key.Id            = 227;
            key.EffectiveDate = DateTime.Now;
            key.AddAttribute("Number of LAN Ports", "2");
            key.AddAttribute("GPID", "HelloWorld");
            key.AddAttribute("IsSourceOfProductsServiceAlias", "Yes");

            var result = ServiceHierarchy.Validate(key);

            Assert.IsFalse(result.IsValid);

            key.Children = new Dictionary <string, List <ServiceKey> >();
            key.Children.Add("blah", new List <ServiceKey>());
            result = ServiceHierarchy.Validate(key);
            Assert.IsFalse(result.IsValid); // child name violation

            key.Children.Remove("blah");
            key.Children.Add("LAN PORT SERVICE", new List <ServiceKey>());
            key.Children["LAN PORT SERVICE"].Add(new ServiceKey()
            {
                Id = 236
            });
            result = ServiceHierarchy.Validate(key);
            Assert.IsTrue(result.IsValid); // we good

            key.AddAttribute("Number of LAN Ports", "0");
            key.Children["LAN PORT SERVICE"].Add(new ServiceKey()
            {
                Id = 236
            });
            result = ServiceHierarchy.Validate(key);
            Assert.IsFalse(result.IsValid); // max violation

            key.Children["LAN PORT SERVICE"].Clear();
            key.Children["LAN PORT SERVICE"].Add(new ServiceKey()
            {
                Id = 216
            });
            result = ServiceHierarchy.Validate(key);
            Assert.IsFalse(result.IsValid); // wrong service id for child name
        }
Пример #3
0
        public void Build_ParentDefaultTest()
        {
            Startup.LoadSettings();
            // test assumes service 227 has child of 236 named "LAN PORT SERVICE"

            var key = new ServiceKey()
            {
                Id            = 227,
                EffectiveDate = DateTime.Now
            };

            key.AddAttribute("Number of LAN Ports", "2");
            key.AddAttribute("GPID", "HelloWorld");
            key.AddAttribute("IsSourceOfProductsServiceAlias", "Yes");

            var sh = ServiceHierarchy.BuildChild(key, "LAN PORT SERVICE");

            Assert.IsTrue(sh.ParentServiceKey.GetAttributeValue("GPID", PCAT.Common.Models.SearchOptions.ALL_FALSE).Equals("HelloWorld"));
            Assert.IsTrue(sh.GetAttributeValue("GPID", PCAT.Common.Models.SearchOptions.ALL_FALSE).Equals("HelloWorld"));

            Assert.IsTrue(sh.ParentServiceKey.GetAttributeValue("IsSourceOfProductsServiceAlias", PCAT.Common.Models.SearchOptions.ALL_FALSE).Equals("Yes"));
            Assert.IsTrue(sh.GetAttributeValue("IsSourceOfProductsServiceAlias", PCAT.Common.Models.SearchOptions.ALL_FALSE).Equals("No"));
        }
 public static void AddMissingRelatedAttributes(this ServiceKey key)
 {
     if (key.Relationships != null && key.Relationships.Count > 0)
     {
         var    childConfig = ServiceConfiguration.Get(key.Id, key.EffectiveDate);
         string value;
         foreach (var attribute in childConfig.Attributes)
         {
             if (attribute.Value.Type == AttributeType.Related)
             {
                 value = key.GetAttributeValue(attribute.Value.DefaultValue, SearchOptions.ALL_TRUE);
                 if (value != null)
                 {
                     key.AddAttribute(attribute.Value.Name, value);
                 }
             }
         }
     }
 }
        public static void AddMissingDefaultAttributes(this ServiceKey key)
        {
            var    childConfig = ServiceConfiguration.Get(key.Id, key.EffectiveDate);
            string value;

            foreach (var attribute in childConfig.Attributes)
            {
                if (attribute.Value.Type != AttributeType.List &&
                    key.GetAttributeValue(attribute.Value.Name, SearchOptions.ALL_FALSE) == null &&
                    !childConfig.IsOptional(attribute.Value.Name, key))
                {
                    value = childConfig.GetDefaultValue(attribute.Value.Name, key);
                    if (value != null)
                    {
                        key.AddAttribute(attribute.Value.Name, value);
                    }
                }
            }
        }