예제 #1
0
        public static void RunMerge <T>(this Hyland.Unity.WorkView.ExecutableFilterQuery query, IEnumerable <T> externalList, Action <Hyland.Unity.WorkView.Object, T> mapper = null)
        {
            // If a mapper wasn't given, create one
            if (mapper == null)
            {
                mapper = (obj, item) =>
                {
                    var avm = obj.CreateAttributeValueModifier();

                    foreach (var prop in item.GetType().GetProperties().Where(prop => WorkViewAttributeAttribute.IsDefined(prop)))
                    {
                        var address = WorkViewAttributeAttribute.GetAttributeAddress(prop);
                        if (address.Depth != 1)
                        {
                            continue;
                        }

                        var attribute = query.Class.Attributes.Find(address.FullPath);

                        avm.SetAttributeValue(attribute, prop.GetValue(item));
                    }

                    avm.ApplyChanges();
                };
            }

            var dictionary = Merge <T>(query, externalList);

            foreach (var item in dictionary.UpdateItemList)
            {
                if (item.ObjectId is long id)
                {
                    mapper(query.Class.GetObjectByID(id), item.Item);
                }
            }

            foreach (var item in dictionary.NewItemList)
            {
                mapper(query.Class.CreateObject(), item.Item);
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="wvObject"></param>
        /// <param name="item"></param>
        /// <param name="matchType"></param>
        /// <returns></returns>
        public static bool IsMatch <T>(this Hyland.Unity.WorkView.Object wvObject, T item, WorkViewMatchType matchType = WorkViewMatchType.OnlyKeys)
        {
            Type itemType          = item.GetType();
            var  definedAttributes = itemType.GetProperties().Where(pi => WorkViewAttributeAttribute.IsDefined(pi));

            List <PropertyInfo> matchableProperties = null;

            switch (matchType)
            {
            case WorkViewMatchType.OnlyKeys:
                matchableProperties = definedAttributes.Where(pi => WorkViewAttributeAttribute.IsKey(pi)).ToList();
                break;

            case WorkViewMatchType.NonOptional:
                matchableProperties = definedAttributes.Where(pi => !WorkViewAttributeAttribute.IsOptional(pi)).ToList();
                break;

            case WorkViewMatchType.AllDefinedAttributes:
                matchableProperties = definedAttributes.ToList();
                break;

            default:
                break;
            }

            //
            foreach (var matchProperty in matchableProperties)
            {
                var attributeValue = wvObject.AttributeValueByAddress(WorkViewAttributeAttribute.GetAttributeAddress(matchProperty));

                if (matchProperty.GetValue(item).ToString() != attributeValue.Value.ToString())
                {
                    return(false);
                }
            }

            return(true);
        }