Пример #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);
        }
Пример #3
0
 public ObjectDictionary()
 {
     _items = new Dictionary <string, CustomObject <T> >();
     _cachedKeyLocations = WorkViewAttributeAttribute.GetKeys <T>().ToArray();
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="wvObject"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static object DeserializeWorkViewObject(Hyland.Unity.WorkView.Object wvObject, Type type)
        {
            if (wvObject is null)
            {
                throw new ArgumentNullException(nameof(wvObject));
            }

            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            // Create new instance of the desired object, item must have a constructor that takes 0 arguments
            var newItem = Activator.CreateInstance(type);

            var properties = type.GetProperties().Where(prop => WorkViewAttributeAttribute.IsDefined(prop));

            // Loop through properties
            foreach (var prop in properties)
            {
                // Initialize string address
                string stringAddress = WorkViewAttributeAttribute.GetStringAddress(prop);

                // Try and get a value by the address
                var attributeValue = wvObject?.AttributeValueByAddress(stringAddress);

                // If the value could not be found or does not have a value
                if (attributeValue == null || !attributeValue.HasValue)
                {
                    // If item is optional, skip
                    if (!WorkViewAttributeAttribute.IsOptional(prop))
                    {
                        throw new InvalidStringAddressException(stringAddress);
                    }

                    continue;
                }

                prop.SetValue(newItem, attributeValue.Value);
            }

            var systemProps = type.GetProperties().Where(prop => WorkViewSystemAttributeAttribute.IsDefined(prop));

            foreach (var prop in systemProps)
            {
                object value = null;

                switch (WorkViewSystemAttributeAttribute.GetSystemAttribute(prop))
                {
                case WorkViewSystemAttribute.ID:
                    value = wvObject.ID;
                    break;

                case WorkViewSystemAttribute.CreatedDate:
                    value = wvObject.CreatedDate;
                    break;

                case WorkViewSystemAttribute.CreatedByID:
                    value = wvObject.CreatedBy.ID;
                    break;

                case WorkViewSystemAttribute.CreatedByName:
                    value = wvObject.CreatedBy.Name;
                    break;

                case WorkViewSystemAttribute.CreatedByRealName:
                    value = wvObject.CreatedBy.RealName;
                    break;

                case WorkViewSystemAttribute.CreatedByDisplayName:
                    value = wvObject.CreatedBy.DisplayName;
                    break;

                case WorkViewSystemAttribute.CreatedByEmailAddress:
                    value = wvObject.CreatedBy.EmailAddress;
                    break;

                case WorkViewSystemAttribute.RevisionDate:
                    value = wvObject.RevisionDate;
                    break;

                case WorkViewSystemAttribute.RevisionByID:
                    value = wvObject.RevisionBy.ID;
                    break;

                case WorkViewSystemAttribute.RevisionByName:
                    value = wvObject.RevisionBy.Name;
                    break;

                case WorkViewSystemAttribute.RevisionByRealName:
                    value = wvObject.RevisionBy.RealName;
                    break;

                case WorkViewSystemAttribute.RevisionByDisplayName:
                    value = wvObject.RevisionBy.DisplayName;
                    break;

                case WorkViewSystemAttribute.RevisionByEmailAddress:
                    value = wvObject.RevisionBy.EmailAddress;
                    break;

                case WorkViewSystemAttribute.ClassID:
                    value = wvObject.Class.ID;
                    break;

                case WorkViewSystemAttribute.ClassName:
                    value = wvObject.Class.Name;
                    break;

                case WorkViewSystemAttribute.BaseClassID:
                    value = wvObject.BaseClassID;
                    break;

                case WorkViewSystemAttribute.Name:
                    value = wvObject.Name;
                    break;

                default:
                    continue;
                }

                prop.SetValue(newItem, value);
            }

            // Return item
            return(newItem);
        }