Пример #1
0
        public ICmPossibility CreateFromCanonicalItem(CanonicalItem item)
        {
            if (item.Parent != null)
            {
                // Note that we're throwing away the return value; we want this for its side effects (it will create
                // and populate the parent if the parent didn't exist already).
                FromStringKey(item.Parent.Key);
            }
            ICmPossibility poss = _parentList.FindOrCreatePossibility(item.ORCDelimitedKey, _wsForKeys);

            item.PopulatePossibility(poss);
            PossibilitiesByKey[item.Key] = poss;
            return(poss);
        }
Пример #2
0
        protected ICmPossibility LookupByCanonicalItem(CanonicalItem item)
        {
            if (item == null)
            {
                return(null);
            }
            ICmPossibility result;

            if (!String.IsNullOrEmpty(item.GuidStr))
            {
                Guid guid;
                if (Guid.TryParse(item.GuidStr, out guid))
                {
                    if (_possRepo.TryGetObject(guid, out result))
                    {
                        return(result);
                    }
                }
            }
                        #if false  // Once we are populating Lcm from LF, we might also need to fall back to abbreviation and name for these lookups, because Guids might not be available
            return(FromAbbrevAndName(item.Abbrevs[_wsForKeys], item.Names[_wsForKeys]));
                        #endif
            return(null);
        }
Пример #3
0
        /// <summary>
        /// Update a CmPossibility object from the corresponding LF item. Will draw from canonical sources if available.
        /// Will try very hard to find a CmPossibility item matching the LF OptionList item, but will eventually create
        /// one if nothing remotely matching could be found.
        ///
        /// NOTE: This is currently commented out (via #if false...#endif block) because we currently don't want to update
        /// Lcm from the values of LF option lists. Once that changes, this code can be uncommented.
        /// </summary>
        /// <param name="item">Item.</param>
        /// <param name="wsForOptionListItems">Ws for option list items.</param>
        public void UpdateOrCreatePossibilityFromOptionListItem(LfOptionListItem item, string wsForOptionListItems = null)
        {
            ICmPossibility poss          = null;
            CanonicalItem  canonicalItem = null;

            if (item.Guid != null)
            {
                if (_possRepo.TryGetObject(item.Guid.Value, out poss))
                {
                    // Currently we do NOT want to change the name, abbreviation, etc. in Lcm for already-existing possibility items.
                    // Once we do, uncomment the next line:
                    //PopulateCmPossibilityFromOptionListItem(poss, item, wsForOptionListItems);
                    // For now, however, just return without touching the Lcm CmPossibility object
                    return;
                }
                else
                {
                    if (_canonicalSource != null && _canonicalSource.TryGetByGuid(item.Guid.Value, out canonicalItem))
                    {
                        canonicalItem.PopulatePossibility(poss);
                        return;
                    }
                    // No canonical item? At least set name and abbreviation from LF
                    var factory = _parentList.Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>();
                    poss = factory.Create(item.Guid.Value, _parentList);                      // Note that this does NOT handle "parent" possibilities; new one gets created as a TOP-level item
                    PopulateCmPossibilityFromOptionListItem(poss, item, wsForOptionListItems);
                }
            }
            else
            {
                // Can't look it up by GUID, so search by key. If key not found, fall back to abbreviation and name.
                if (_canonicalSource != null && _canonicalSource.TryGetByKey(item.Key, out canonicalItem))
                {
                    canonicalItem.PopulatePossibility(poss);
                    return;
                }
                // No canonical source? Then we're in fallback-of-fallback land. First try the key, as that's most likely to be found.
                poss = _parentList.FindPossibilityByName(_parentList.PossibilitiesOS, item.Key, _wsForKeys);
                if (poss != null)
                {
                    PopulateCmPossibilityFromOptionListItem(poss, item, wsForOptionListItems);
                    return;
                }
                // Then try the abbreviation, and finally the name -- these, though, should be in the LF user's interface language
                poss = _parentList.FindPossibilityByName(_parentList.PossibilitiesOS, item.Abbreviation, wsForOptionListItems);
                if (poss != null)
                {
                    PopulateCmPossibilityFromOptionListItem(poss, item, wsForOptionListItems);
                    return;
                }
                // In LF, OptionListItems have their name in the "Value" property
                poss = _parentList.FindPossibilityByName(_parentList.PossibilitiesOS, item.Value, wsForOptionListItems);
                if (poss != null)
                {
                    PopulateCmPossibilityFromOptionListItem(poss, item, wsForOptionListItems);
                    return;
                }
                // If we STILL haven't found it, then just create a new item and populate it. This is the final, last-ditch fallback.
                poss = _parentList.FindOrCreatePossibility(item.Value, wsForOptionListItems);
                PopulateCmPossibilityFromOptionListItem(poss, item, wsForOptionListItems);
            }
        }