Beispiel #1
0
        public static OffnetServiceDefinition Get(long id)
        {
            OffnetServiceDefinition def;

            def = _Cache.CheckCache(id.ToString());
            if (def == null)
            {
                try
                {
                    def = OffnetDataAccess.GetOffnetServiceDefinition(id.ToString());
                }
                catch (Exception e)
                {
                    string message;
                    switch (e.Message)
                    {
                    case "Sequence contains no elements":
                        message = "Definition does not exist for " + id.ToString() + ",try again with a valid Id.";
                        break;

                    default:
                        message = "Error fetching the service deinition.";
                        break;
                    }
                    throw new ApplicationException(message);
                }
            }
            _Cache.StoreCache(id.ToString(), def);
            return(def);
        }
        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);
        }