コード例 #1
0
        public static List <OffnetServiceChild> Get(OffnetServiceKey key, string name = null)
        {
            //List<OffnetServiceHierarchy> children = _Cache.CheckCache(key.Id.ToString());
            List <OffnetServiceHierarchy> children = new List <OffnetServiceHierarchy>();
            var kids = new List <OffnetServiceChild>();

            children = OffnetDataAccess.GetOffnetChildren(key);

            // _Cache.StoreCache(key.Id.ToString(), children);

            if (children != null && children.Count > 0)
            {
                var                searchOptions = SearchOptions.DEFAULTS_ONLY;
                string             error;
                RuleValue          quantity;
                OffnetServiceChild kid;

                var ruleSet = new OffnetServiceRuleSet();
                ruleSet.AddDefaults(key);
                ruleSet.AddServiceKey(key);

                foreach (var child in children)
                {
                    if (name == null || name.Equals(child.Name))
                    {
                        kid = new OffnetServiceChild()
                        {
                            Id   = child.Id,
                            Name = child.Name
                        };

                        if (ValueRuleParser.ParseRule(child.MaxQuantityRule).TryGetValue(ruleSet, searchOptions, out quantity, out error))
                        {
                            kid.MaxQuantity = quantity.ToInteger() ?? 0;
                        }
                        if (ValueRuleParser.ParseRule(child.MinQuantityRule).TryGetValue(ruleSet, searchOptions, out quantity, out error))
                        {
                            kid.MinQuantity = quantity.ToInteger() ?? 0;
                        }
                        if (kid.MaxQuantity > 0 || kid.MaxQuantity == -1)
                        {
                            kids.Add(kid);
                        }
                    }
                }
            }
            return(kids);
        }
コード例 #2
0
        public static ICollection <AttributeInfo> Get(OffnetServiceKey key, bool populateLists)
        {
            var config = OffnetServiceConfiguration.Get(key.Id, key.EffectiveDate);

            var list = ValidValueRuleParser.GetRules(config.ValidValueRule);

            var set = new ValidValueRuleSet();

            set.AddRules(list);

            var attributeSet = set.GetAttributes(key, SearchOptions.ALL_FALSE);
            //If we have an attribute with  no valid options, clear the value and try again...
            var emptyAttributes = (from a in attributeSet where a.Values == null || a.Values.Count == 0 select a.Name).ToList();

            if (emptyAttributes.Count > 0)
            {
                foreach (var a in emptyAttributes)
                {
                    key.RemoveAttribute(a);
                }
                attributeSet = set.GetAttributes(key, SearchOptions.ALL_FALSE);
            }

            IDictionary <string, AttributeInfo> tempList = new Dictionary <string, AttributeInfo>();

            foreach (var a in attributeSet)
            {
                tempList[a.Name] = a;
            }

            key.AddMissingAttributes();
            //Next we need to look if there are non-list items that need to be collected.
            foreach (var pair in config.Attributes)
            {
                AttributeInfo a = null;
                if (tempList.ContainsKey(pair.Key))
                {
                    tempList.TryGetValue(pair.Key, out a);
                }

                tempList[pair.Key] = AttributeFactory.CreateAttribute(pair.Value, pair.Key, a, key);
                if ((pair.Value.Type == AttributeType.Parent || pair.Value.Type == AttributeType.Related) &&
                    key.HasAttribute(pair.Key))
                {
                    tempList[pair.Key].SetValue(key.GetAttributeValue(pair.Key, SearchOptions.ALL_TRUE));
                }
            }


            var ruleSet = new OffnetServiceRuleSet();

            ruleSet.AddDefaults(key);  // add defaults so rules such as IsApplicable can use them

            //key doesn't have all the data we have generated so to use the latest we will build a ValueHolder that has what we need...
            string aValue;

            foreach (var a in tempList.Values)
            {
                aValue = a.GetValue();
                if (!string.IsNullOrEmpty(aValue)) // don't add empty values
                {
                    ruleSet.AddValue(a.Name, new RuleValue(aValue));
                }
            }
            //Determine which attributes we don't need
            var finalList = tempList.Values.Where(a => config.IsConfigurableAttribute(a.Name, ruleSet)).ToDictionary(a => a.Name);


            //Last we need to try and add a description to attributes that haven't had them added yet...
            //and flag them as optional or not.  We will also set the default value if there is one.
            foreach (var a in finalList.Values)
            {
                a.Optional = config.IsOptional(a.Name, ruleSet).ToString();

                a.Label = config.GetLabel(a.Name);
                if (config.HasDefault(a.Name))
                {
                    try
                    {
                        a.DefaultValue = config.GetDefaultValue(a.Name, key);
                    }
                    catch (Exception) { }
                }
                a.Hidden              = config.IsHidden(a.Name, key);
                a.MaxRepeats          = config.GetMaxRepeats(a.Name);
                a.RequiresRefresh     = config.GetRequiresRefresh(a.Name);
                a.ReadOnly            = config.IsReadOnly(a.Name, key);
                a.ApplicableForChange = config.GetApplicableForChange(a.Name);
                a.AffectsChildren     = config.AffectsChildren(a.Name);
                a.DesignImpact        = config.IsDesignImpact(a.Name, key);
                a.ProvisioningImpact  = config.IsProvisioningImpact(a.Name, key);

                var attribute = a as ListAttribute;
                if (attribute != null)
                {
                    var la = attribute;
                    if (populateLists && la.GetValue() != null && !la.ReadOnly && !la.Hidden)
                    {
                        //Since the value has been set, the list of options is empty.  If it is asked for, we will determine
                        //the list of options if this was not set.
                        var myKey = key.Clone(false);

                        myKey.AddValue(la.Name, null);
                        var myAtts = set.GetAttributes(myKey, SearchOptions.ALL_FALSE);

                        foreach (var av in
                                 from myAtt in myAtts
                                 where myAtt.Name.Equals(la.Name)
                                 from av in ((ListAttribute)myAtt).GetList()
                                 select av)
                        {
                            la.AddValue(av);
                        }
                    }
                }
            }

            return(config.SortList(finalList.Values));
        }
コード例 #3
0
ファイル: OffnetBiz.cs プロジェクト: shiva166431/FSC_Clone5
        public static PartnerServicePackage ResolveOffnet(PartnerServicePackage oldPackage, out string error)
        {
            var NewPackage        = new PartnerServicePackage();
            var partnerAttributes = new PartnerAtrributes();

            var _e = new Exception();

            error = null;
            var validInput = oldPackage.Partner.IsValidInput();

            if (oldPackage.Partner == null)
            {
                _e.Data.Add("Custom Msg", "Partner key is cannot be null");
                throw (_e);
            }
            try
            {
                //Fetch and populate Partner key if Partner does not exist
                if (oldPackage.Partner.PartnerOrderId == 0 || String.IsNullOrEmpty(oldPackage.Partner.PartnerOrderName))
                {
                    if (!validInput.valid)
                    {
                        _e.Data.Add("Custom Msg", validInput.message);
                        throw (_e);
                    }
                    partnerAttributes.FromWeb(oldPackage.Partner);
                    NewPackage.Partner = partnerAttributes.Get(partnerAttributes.VendorId, partnerAttributes.Name, partnerAttributes.Source);
                }
                //Verify if all the partner attributes values are set correctly
                else if (!oldPackage.Partner.HasAllAttributes().valid)
                {
                    partnerAttributes.FromWeb(oldPackage.Partner);
                    NewPackage.Partner = partnerAttributes.Get(partnerAttributes.VendorId, partnerAttributes.Name, partnerAttributes.Source);
                }
                else
                {
                    NewPackage.Partner = oldPackage.Partner;
                }

                //Parse rules and get services and Populate the service key
                if (oldPackage.Services != null)
                {
                    {
                        //We need to make sure that each service attribute has its type assigned.
                        foreach (var sk in oldPackage.Services.Values)
                        {
                            var sc = GetServiceConfiguration(sk);
                            foreach (var name in sk.Values.Keys)
                            {
                                var a = sk.Values[name];
                                if (a.Type == null)
                                {
                                    a.Type = sc.GetAttributeType(name);
                                }
                            }
                        }

                        List <string> removedAttributes = new List <string>();
                        //It is possible that some service attributes have invalid values.  We need to remove their value if they are not valid.
                        foreach (var sk in oldPackage.Services.Values)
                        {
                            var listAttributes = OffnetServiceAttributes.Get(sk, true);
                            // GetAttributes(sk, ValidationStage.Design).Where(a => a.Type.Equals(AttributeType.List)).ToList();
                            foreach (var la in listAttributes)
                            {
                                var currentValue = sk.GetAttributeValue("la", SearchOptions.ALL_FALSE);
                                if (currentValue != null && !la.Values.Contains(new AttributeValue(currentValue)))
                                {
                                    sk.RemoveAttribute(la.Name);
                                    removedAttributes.Add(la.Name);
                                }
                            }

                            var names = listAttributes.Select(la => la.Name).ToList();
                            var currentListAttributes = sk.Values.Where(v => AttributeType.List.Equals(v.Value.Type)).Select(v => v.Key).ToList();
                            foreach (var name in currentListAttributes)
                            {
                                if (!names.Contains(name))
                                {
                                    sk.RemoveAttribute(name);
                                    removedAttributes.Add(name);
                                }
                            }

                            if (removedAttributes.Count > 0)
                            {
                                // add removed attributes back with default values
                                listAttributes = OffnetServiceAttributes.Get(sk, true);
                                listAttributes = listAttributes.Where(a => a.Type.Equals(AttributeType.List)).ToList();
                                //GetAttributes(sk, ValidationStage.Design).Where(a => a.Type.Equals(AttributeType.List)).ToList();
                                foreach (string name in removedAttributes)
                                {
                                    var la = (ListAttribute)listAttributes.FirstOrDefault(a => a.Name.Equals(name) && a.Type.Equals(AttributeType.List) && ((ListAttribute)a).GetList().Count == 1);
                                    if (la != null)
                                    {
                                        sk.AddValue(name, la.GetAttributeValue());
                                    }
                                }
                            }
                        }
                    }
                }
                //When No services in the initial call
                var set = new OffnetServiceRuleSet();
                set.ApplyRules(NewPackage);

                if (NewPackage.Services != null)
                {
                    foreach (var service in NewPackage.Services.Values)
                    {
                        var attributes = OffnetServiceAttributes.Get(service, false);
                        foreach (var la in from attribute in attributes
                                 where
                                 service.GetAttributeValue(attribute.Name, SearchOptions.ALL_FALSE) == null &&
                                 attribute.Type.Equals(AttributeType.List)
                                 select(ListAttribute) attribute
                                 into la
                                 where la.GetList().Count == 1
                                 select la)
                        {
                            service.AddValue(la.Name, la.GetAttributeValue());
                        }
                    }
                }

                if (NewPackage.Services != null)
                {
                    //It is possible that the service keys have picked up some extra fields.  We need to remove them as they could cause problems with downstream applications
                    foreach (var sk in NewPackage.Services.Values)
                    {
                        var c     = GetServiceConfiguration(sk);
                        var names = sk.Values.Keys.Where(a => !c.IsConfigurableAttribute(a, sk)).ToList();
                        foreach (var n in names)
                        {
                            sk.RemoveAttribute(n);
                        }
                        // Make sure all the attributes have a type associated with them...
                        foreach (var name in sk.Values.Keys)
                        {
                            if (c.IsConfigurableAttribute(name, sk) && sk.Values[name].Type == null)
                            {
                                sk.Values[name].Type = c.GetAttributeType(name);
                            }
                        }
                    }

                    //It is possible that some service attributes have invalid values.  We need to remove their value if they are not valid.
                    foreach (var sk in oldPackage.Services.Values)
                    {
                        var listAttributes = OffnetServiceAttributes.Get(sk, false).Where(a => a.Type.Equals(AttributeType.List)).ToList();
                        //GetAttributes(sk, ValidationStage.Design).Where(a => a.Type.Equals(AttributeType.List)).ToList();
                        foreach (var la in listAttributes)
                        {
                            var currentValue = sk.GetAttributeValue(la.Name, SearchOptions.ALL_FALSE);
                            if (currentValue != null && !la.Values.Contains(new AttributeValue(currentValue)))
                            {
                                sk.RemoveAttribute(la.Name);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
            return(NewPackage);
        }