示例#1
0
        public void ParentAttributeTest()
        {
            Startup.LoadSettings();
            // test requirements
            //      service 215
            //          inherits from 300 with parent attributes GPID and PCATProductID

            var key = new ServiceKey();

            key.Id            = 215;
            key.EffectiveDate = DateTime.Now;
            key.AddValue("ValueTest", "8", PCAT.Common.Models.Attribute.AttributeType.Integer);
            key.Relationships = new Dictionary <string, List <ServiceKey> >();

            var parent = new ServiceKey()
            {
                Id            = 212,
                EffectiveDate = DateTime.Now
            };

            parent.AddValue("GPID", "12345", AttributeType.Integer);
            parent.AddValue("PCATProductID", "444", AttributeType.Integer);
            key.ParentServiceKey = parent;

            var results = ServiceAttributes.Get(key, true);
        }
示例#2
0
        public void AddServiceKey(string displayName, byte[] keyValue, string protectionPassword, KeyType keyType, KeyUsage keyUsage)
        {
            try
            {
                var client           = this.CreateManagementServiceClient();
                var defaultStartDate = DateTime.UtcNow;
                var defaultEndDate   = defaultStartDate.AddYears(1);

                var serviceKey = new ServiceKey
                {
                    DisplayName = displayName,
                    Type        = keyType.ToString(),
                    Usage       = keyUsage.ToString(),
                    Value       = keyValue,
                    Password    = string.IsNullOrEmpty(protectionPassword) ? null : new UTF8Encoding().GetBytes(protectionPassword),
                    StartDate   = defaultStartDate,
                    EndDate     = defaultEndDate,
                    IsPrimary   = true
                };

                client.AddToServiceKeys(serviceKey);
                client.SaveChanges();
            }
            catch (Exception ex)
            {
                throw TryGetExceptionDetails(ex);
            }
        }
示例#3
0
        public void KeyNotEqualsOtherType()
        {
            var key1 = new ServiceKey(typeof(Func<IDisposable>), null);

            Assert.AreNotEqual(key1, new object());
            Assert.IsFalse(key1.Equals(new object()));
        }
        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);
                        }
                    }
                }
            }
        }
示例#5
0
        public void SameTypesAndNameValuesInIdentifier_ReturnsAreEqual()
        {
            var identifier1 = new ServiceKey(typeof(Action), typeof(Delegate), "first");
            var identifier2 = new ServiceKey(typeof(Action), typeof(Delegate), "first");

            Assert.AreEqual(identifier1, identifier2);
        }
示例#6
0
        public void DifferentObjectsWithSameValuesShouldBeEqual()
        {
            var key1 = new ServiceKey(typeof(IStub));
            var key2 = new ServiceKey(typeof(IStub));

            AssertionExtensions.Should((object) key2).Be(key1);
        }
示例#7
0
        public void KeyNotEqualsOtherType()
        {
            var key1 = new ServiceKey(typeof(Func <IDisposable>), null);

            Assert.AreNotEqual(key1, new object());
            Assert.IsFalse(key1.Equals(new object()));
        }
示例#8
0
        /// <summary>
        /// 构建服务,保存对象在总线中
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public T BuildUpAndSaveObject <T>(string key, params object[] parameters)
        {
            ServiceKey  servicekey = new ServiceKey(typeof(T), key);
            ServiceDesc desc       = this.packagesearcher.SearchPackage(servicekey);

            return(InternalBuildUp <T>(desc, true, parameters));
        }
示例#9
0
        public static ImpactAttributes GetImpactAttributes(ServiceKey key, List <string> changedAttributes)
        {
            var           attributes        = Get(key, false);
            List <string> impacts           = new List <string>();
            var           serviceId         = key.Id;
            var           serviceInstanceId = key.ServiceInstanceId;

            foreach (var attribute in changedAttributes)
            {
                bool isDesignImpact       = attributes.Where(a => a.Name == attribute).Select(a => a.DesignImpact).FirstOrDefault();
                bool isProvisioningImpact = attributes.Where(a => a.Name == attribute).Select(a => a.ProvisioningImpact).FirstOrDefault();

                if (isDesignImpact && isProvisioningImpact)
                {
                    impacts.Add(attribute + " (DESIGN IMPACT, POVISIONING IMPACT)");
                }
                else if (isDesignImpact && !isProvisioningImpact)
                {
                    impacts.Add(attribute + " (DESIGN IMPACT)");
                }
                else if (!isDesignImpact && isProvisioningImpact)
                {
                    impacts.Add(attribute + " (POVISIONING IMPACT)");
                }
            }
            return(new ImpactAttributes(serviceId, serviceInstanceId, impacts));
        }
示例#10
0
        public ICollection <AttributeInfo> GetAttributes(ServiceKey key, SearchOptions searchOptions)
        {
            //Use the rule set to GetAttributes...
            var myRuleSet = new CommonRuleSet();

            foreach (var r in _vvRules)
            {
                myRuleSet.AddRule(null, r);
            }
            foreach (var r in _vfyRules)
            {
                myRuleSet.AddRule(null, r);
            }

            foreach (var pair in key.Values.Where(pair => pair.Value != null))
            {
                myRuleSet.AddRule(pair.Key, new RuleValue(pair.Value));
                var list = new string[1];
                list[0] = pair.Value.Value;
                myRuleSet.AddRule(pair.Key, new ValidValueSet(pair.Key, list));
            }
            myRuleSet.AddAddresses(key);

            var atts = myRuleSet.GetAttributes(searchOptions, null, null);

            return(atts);
        }
示例#11
0
        public void KeyNotEqualsNull()
        {
            var key1 = new ServiceKey(typeof(Func<IDisposable>), null);

            Assert.AreNotEqual(key1, null);
            Assert.IsFalse(key1.Equals(null));
        }
示例#12
0
        public void KeyNotEqualsNull()
        {
            var key1 = new ServiceKey(typeof(Func <IDisposable>), null);

            Assert.AreNotEqual(key1, null);
            Assert.IsFalse(key1.Equals(null));
        }
示例#13
0
        public void ChildAttributeTest()
        {
            Startup.LoadSettings();
            // test requirements
            //      service 219
            //         has Attribute with default rule on Child[MULTIPLE COS SERVICE].
            //          has MULTIPLE COS SERVICE child relationship in Service Hierarchy

            var key = new ServiceKey();

            key.Id            = 219;
            key.EffectiveDate = DateTime.Now;
            key.AddValue("CoS Allocation Type", "Multiple COS", PCAT.Common.Models.Attribute.AttributeType.List);
            key.Children = new Dictionary <string, List <ServiceKey> >();

            var child = new ServiceKey()
            {
                Id            = 228,
                EffectiveDate = DateTime.Now
            };

            child.AddValue("Test Attribute", "6", AttributeType.SimpleText);
            key.Children.Add("MULTIPLE COS SERVICE", new List <ServiceKey>()
            {
                child
            });

            var results = ServiceAttributes.Get(key, true);
        }
示例#14
0
        public void RelatedAttributeTest()
        {
            Startup.LoadSettings();
            // test requirements
            //      service 215
            //          has EBGP Remote Peer ASN attribute of type Relationship, with default rule on Relationship[IPVPN]
            //          has IPVPN relationship

            var key = new ServiceKey();

            key.Id            = 215;
            key.EffectiveDate = DateTime.Now;
            key.AddValue("ValueTest", "8", PCAT.Common.Models.Attribute.AttributeType.Integer);
            key.Relationships = new Dictionary <string, List <ServiceKey> >();

            var ipvpn = new ServiceKey()
            {
                Id            = 217,
                EffectiveDate = DateTime.Now
            };

            ipvpn.AddValue("eBGP Remote Peer ASN", "65123", AttributeType.Integer);
            key.Relationships.Add("IPVPN", new List <ServiceKey>()
            {
                ipvpn
            });

            var results = ServiceAttributes.Get(key, true);
            //int x = 1;
        }
示例#15
0
        public static ServiceKey BuildChild(ServiceKey parent, string childName)
        {
            var        children     = Get(parent, childName);
            ServiceKey childService = null;

            if (children.Count == 0)
            {
                throw new ApplicationException($"{childName} is not a child of service {parent.Id}");
            }
            foreach (var child in children)
            {
                if (child.MaxQuantity == -1 ||
                    ((parent.Children == null || !parent.Children.ContainsKey(childName)) && child.MaxQuantity > 0) ||
                    (parent.Children != null && parent.Children.ContainsKey(childName) && child.MaxQuantity > parent.Children[childName].Count)
                    )
                {
                    childService = new ServiceKey(child.Id)
                    {
                        EffectiveDate    = parent.EffectiveDate,
                        ParentServiceKey = parent
                    };
                    childService.AddMissingAttributes();

                    break;
                }
            }

            if (childService == null)
            {
                throw new ApplicationException($"{childName} can't be created on service {parent.Id}");
            }

            return(childService);
        }
示例#16
0
        public void ReadOnlyRuleAttributeTest()
        {
            Startup.LoadSettings();
            // test requirements
            //      service 215
            //          inherits from 300 with parent attributes GPID and PCATProductID

            var key = new ServiceKey();

            key.Id            = 234;
            key.EffectiveDate = DateTime.Now;

            var parent = new ServiceKey()
            {
                Id            = 217,
                EffectiveDate = DateTime.Now
            };

            parent.AddValue("GPID", "12345", AttributeType.Integer);
            parent.AddValue("PCATProductID", "551", AttributeType.Integer);
            parent.AddValue("Netflow Data Collection to Customer", "Yes", AttributeType.List);
            key.ParentServiceKey = parent;
            var results = ServiceAttributes.Get(key, true);

            Assert.IsFalse(results.First(a => a.Name.Equals("Port")).ReadOnly);

            parent.AddValue("Netflow Data Collection to Customer", "No", AttributeType.List);
            results = ServiceAttributes.Get(key, true);
            Assert.IsTrue(results.First(a => a.Name.Equals("Netflow Data Collection to Customer")).ReadOnly);
        }
示例#17
0
        public static List <long> GetImpactedChildren(ServiceKey key, List <string> changedAttributes)
        {
            var children         = Get(key, null);
            var impactedChildren = new List <long>();

            foreach (var child in children)
            {
                var config = ServiceConfiguration.Get(child.Id, DateTime.Now);

                impactedChildren.AddRange(from a in config.Attributes
                                          where (a.Value.Type.Equals(AttributeType.Parent) &&
                                                 changedAttributes.Contains(a.Value.Name)
                                                 ) ||
                                          (a.Value.DefaultValue != null &&
                                           a.Value.DefaultValue.StartsWith("Parent.") &&
                                           a.Value.DefaultValue.Length > 7 &&
                                           changedAttributes.Contains(a.Value.DefaultValue.Substring(7)
                                                                      )
                                          )
                                          select child.Id);
                var childKey = BuildChild(key, child.Name);
                impactedChildren.AddRange(GetImpactedChildren(childKey, changedAttributes));
            }
            return(impactedChildren.Distinct().ToList());
        }
        public static ICollection <ServiceRelationships> Get(ServiceKey key)
        {
            var config = ServiceConfiguration.Get(key.Id, key.EffectiveDate);
            var svcRel = GetServiceRelationships(key.Id, config.Version);

            return(svcRel);
        }
示例#19
0
        public ValidateResponse FixAttributeNameToLabel(ServiceKey sk, ValidateResponse vr)
        {
            ValidateResponse resp = new ValidateResponse(true);
            var atts   = ServiceAttributes.Get(sk, false);
            var errors = vr.GetErrors();

            if (errors?.Count() > 0)
            {
                resp.IsValid = false;
                foreach (var err in errors)
                {
                    if (err.Description.Contains("[") && err.Description.Contains("]"))
                    {
                        var attName     = Regex.Match(err.Description, @"\[([^)]*)\]")?.Groups[1]?.Value;
                        var info        = atts.FirstOrDefault(x => x.Name == attName);
                        var description = err.Description.Replace("[" + attName + "]", info.Label);
                        resp.AddError(description, err.Category, err.Entity, err.Type, err.Reason, err.ErrorCode);
                    }
                    else
                    {
                        resp.AddError(err.Description, err.Category, err.Entity, err.Type, err.Reason, err.ErrorCode);
                    }
                }
            }
            return(resp);
        }
示例#20
0
        public void KeyNotEqualsByDifferentServiceTypes()
        {
            var keyOne = new ServiceKey (typeof(object), typeof(IFormattable));
            var keyTwo = new ServiceKey (typeof(IFormatProvider), typeof(IFormattable));

            Assert.AreNotEqual (keyOne, keyTwo);
            Assert.AreNotEqual (keyOne.GetHashCode (), keyTwo.GetHashCode ());
        }
        public void KeyEqualsByServiceTypeAndFactoryType()
        {
            var keyOne = new ServiceKey(typeof(IFormatProvider), typeof(IFormattable));
            var keyTwo = new ServiceKey(typeof(IFormatProvider), typeof(IFormattable));

            Assert.AreEqual(keyOne, keyTwo);
            Assert.AreEqual(keyOne.GetHashCode(), keyTwo.GetHashCode());
        }
        public void KeyNotEqualsByDifferentFactoryTypes()
        {
            var keyOne = new ServiceKey(typeof(IFormatProvider), typeof(object));
            var keyTwo = new ServiceKey(typeof(IFormatProvider), typeof(IFormattable));

            Assert.AreNotEqual(keyOne, keyTwo);
            Assert.AreNotEqual(keyOne.GetHashCode(), keyTwo.GetHashCode());
        }
示例#23
0
        public void KeyEqualsByServiceTypeAndFactoryType()
        {
            var keyOne = new ServiceKey (typeof(IFormatProvider), typeof(IFormattable));
            var keyTwo = new ServiceKey (typeof(IFormatProvider), typeof(IFormattable));

            Assert.AreEqual (keyOne, keyTwo);
            Assert.AreEqual (keyOne.GetHashCode (), keyTwo.GetHashCode ());
        }
        public void Func_Container_Hash_provider_is_Equal()
        {
            var source = new ServiceKey(typeof(Func <Container, IHashProvider>), string.Empty);
            var other  = new ServiceKey(typeof(Func <Container, IHashProvider>), string.Empty);

            Assert.IsTrue(source.Equals(other));
            Assert.That(source, Is.EqualTo(other));
        }
        /// <summary>
        /// Fetches an instance of <paramref name="contractType"/> in the current graph, or asks the container for a new instance 
        /// </summary>
        /// <param name="contractType">Type of service required</param>
        /// <param name="lifetime"></param>
        /// <returns>Instance of <paramref name="contractType"/></returns>
        public object Get(Type contractType, AbstractLifeTime lifetime)
        {
            var key = new ServiceKey(contractType);
            var instance = _container.ResolveAndBuildService(contractType, lifetime, this);
            Instances[key] = instance;

            return instance;
        }
示例#26
0
        public void SameTypesAndNameValuesInIdentifier_ReturnsAreEqual()
        {
            var identifier1 = new ServiceKey(typeof(Action), typeof(Delegate), "first");
            var identifier2 = new ServiceKey(typeof(Action), typeof(Delegate), "first");


            Assert.AreEqual(identifier1, identifier2);
        }
示例#27
0
 /// <summary>
 /// 查找服务包,根据关键字查找
 /// </summary>
 /// <param name="key">服务关键字</param>
 /// <returns></returns>
 public ServiceDesc SearchPackage(ServiceKey key)
 {
     if (dicPackage.ContainsKey(key))
     {
         return(dicPackage[key]);
     }
     return(null);
 }
示例#28
0
 public ObjectResult ImpactAttributes(ImpactedServiceKeyWeb postData)
 {
     return(WebFunction.Execute <ImpactedServiceKeyWeb, ImpactAttributes>(this, postData, (k) =>
     {
         var key = new ServiceKey(k.Key);
         var impactAttributes = ServiceAttributes.GetImpactAttributes(key, k.ChangedAttributes);
         return new WebResult <ImpactAttributes>(impactAttributes);
     }));
 }
示例#29
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
        /// </returns>
        public bool Equals(KeyedService other)
        {
            if (other == null)
            {
                return(false);
            }

            return(ServiceKey.Equals(other.ServiceKey) && ServiceType == other.ServiceType);
        }
示例#30
0
        public void KeyEqualsSameReference()
        {
            var key1 = new ServiceKey(typeof(Func<IDisposable>), null);
            var key2 = key1;

            Assert.AreSame(key1, key2);
            Assert.IsTrue(ServiceKey.Equals(key1, key2));
            Assert.IsTrue(key1.Equals(key2));
        }
示例#31
0
        public void KeyEqualsSameReference()
        {
            var key1 = new ServiceKey(typeof(Func <IDisposable>), null);
            var key2 = key1;

            Assert.AreSame(key1, key2);
            Assert.IsTrue(ServiceKey.Equals(key1, key2));
            Assert.IsTrue(key1.Equals(key2));
        }
示例#32
0
 public ObjectResult ImpactedChildren(ImpactedServiceKeyWeb postData)
 {
     return(WebFunction.Execute <ImpactedServiceKeyWeb, List <long> >(this, postData, (k) =>
     {
         var key = new ServiceKey(k.Key);
         var children = ServiceHierarchy.GetImpactedChildren(key, k.ChangedAttributes);
         return new WebResult <List <long> >(children);
     }));
 }
示例#33
0
        public void KeysNotEqualByName()
        {
            var key1 = new ServiceKey(typeof(Func<IDisposable>), "foo");
            var key2 = new ServiceKey(typeof(Func<IDisposable>), "bar");

            Assert.AreNotEqual(key1, key2);
            Assert.AreNotEqual(key1.GetHashCode(), key2.GetHashCode());
            Assert.IsFalse(ServiceKey.Equals(key1, key2));
        }
示例#34
0
        public void KeysNotEqualByName()
        {
            var key1 = new ServiceKey(typeof(Func <IDisposable>), "foo");
            var key2 = new ServiceKey(typeof(Func <IDisposable>), "bar");

            Assert.AreNotEqual(key1, key2);
            Assert.AreNotEqual(key1.GetHashCode(), key2.GetHashCode());
            Assert.IsFalse(ServiceKey.Equals(key1, key2));
        }
示例#35
0
    public static bool Equals(ServiceKey obj1, ServiceKey obj2)
    {
        if (object.Equals(null, obj1) || object.Equals(null, obj2) || obj1._factoryType != obj2._factoryType)
        {
            return(false);
        }

        return(obj1._name == obj2._name);
    }
示例#36
0
 public ObjectResult ImpactedRelatoinships(ImpactedServiceKeyWeb postData)
 {
     return(WebFunction.Execute <ImpactedServiceKeyWeb, ServiceRelationshipWeb[]>(this, postData, (si) =>
     {
         var key = new ServiceKey(si.Key);
         var rel = ServiceRelationships.GetImpactedRelationhips(key, si.ChangedAttributes).ToList().ToArray();
         return new WebResult <ServiceRelationshipWeb[]>(rel.Select(i => i.ToWeb()).ToArray());
     }));
 }
示例#37
0
        public ObjectResult Children(ServiceKeyWeb postData)
        {
            return(WebFunction.Execute <ServiceKeyWeb, List <ServiceChildWeb> >(this, postData, (sv) =>
            {
                var key = new ServiceKey(sv);
                var children = ServiceHierarchy.Get(key);

                return new WebResult <List <ServiceChildWeb> >(children.Select(c => c.ToWeb()).ToList());
            }));
        }
示例#38
0
        public void KeysAreEqualByTypeAndName()
        {
            var key1 = new ServiceKey(typeof(Func <IDisposable>), "foo");
            var key2 = new ServiceKey(typeof(Func <IDisposable>), "foo");

            Assert.AreEqual(key1, key2);
            Assert.AreEqual(key1.GetHashCode(), key2.GetHashCode());
            Assert.IsTrue(ServiceKey.Equals(key1, key2));
            Assert.IsTrue(key1.Equals(key2));
        }
示例#39
0
        public void KeysAreEqualByTypeAndName()
        {
            var key1 = new ServiceKey(typeof(Func<IDisposable>), "foo");
            var key2 = new ServiceKey(typeof(Func<IDisposable>), "foo");

            Assert.AreEqual(key1, key2);
            Assert.AreEqual(key1.GetHashCode(), key2.GetHashCode());
            Assert.IsTrue(ServiceKey.Equals(key1, key2));
            Assert.IsTrue(key1.Equals(key2));
        }
示例#40
0
        /// <summary>
        /// 构造消息头
        /// </summary>
        /// <param name="uiSeqID">消息序列号</param>
        /// <param name="mcCategory">消息分类</param>
        /// <param name="skServiceKey">消息服务健</param>
        /// <param name="uiBodyLen">消息体长度</param>
        public Packet_Head(uint uiSeqID, Msg_Category mcCategory, ServiceKey skServiceKey, uint uiBodyLen)
        {
            this.m_uiSeqID       = uiSeqID;
            this.m_mcCategory    = mcCategory;
            this.m_skServiceKey  = skServiceKey;
            this.m_dtMsgDateTime = System.DateTime.Now;
            this.m_uiBodyLen     = uiBodyLen;

            this.IsValidHead = this.PutToBuffer();
        }
示例#41
0
        public void DifferentTypesInIdentifier_ReturnsNotSameObject()
        {
            var identifier1 = new ServiceKey(typeof(Action), typeof(Action), "first");
            var identifier2 = new ServiceKey(typeof(Delegate), typeof(Action), "first");
            var identifier3 = new ServiceKey(typeof(Action), typeof(Action), "second");
            var identifier4 = new ServiceKey(typeof(Delegate), typeof(Action), "second");

            Assert.IsTrue(!identifier1.Equals(identifier2) &&
                          !identifier1.Equals(identifier3) &&
                          !identifier1.Equals(identifier4) &&
                          !identifier2.Equals(identifier3) &&
                          !identifier2.Equals(identifier4) &&
                          !identifier3.Equals(identifier4));
        }
 public void AddToServiceKeys(ServiceKey serviceKey)
 {
     base.AddObject("ServiceKeys", serviceKey);
 }
 public static ServiceKey CreateServiceKey(long ID, bool isPrimary, bool systemReserved, global::System.DateTime startDate, global::System.DateTime endDate)
 {
     ServiceKey serviceKey = new ServiceKey();
     serviceKey.Id = ID;
     serviceKey.IsPrimary = isPrimary;
     serviceKey.SystemReserved = systemReserved;
     serviceKey.StartDate = startDate;
     serviceKey.EndDate = endDate;
     return serviceKey;
 }