Exemple #1
0
        public static IInformationObject GetTarget_ObjectToDelete(IContainerOwner owner, string objectDomainName, string objectName, string objectId)
        {
            IInformationObject objectToDelete =
                StorageSupport.RetrieveInformationObjectFromDefaultLocation(objectDomainName, objectName, objectId,
                                                                            owner);

            return(objectToDelete);
        }
Exemple #2
0
        public static void SetObjectContent(this IInformationObject rootObject, string containerID,
                                            string containedField, string[] objectIDList)
        {
            List <IInformationObject> containerList = new List <IInformationObject>();

            rootObject.FindObjectsFromTree(containerList, iObj => iObj.ID == containerID, false);
            foreach (var iObj in containerList)
            {
                var type = iObj.GetType();
                var prop = type.GetProperty(containedField);
                if (prop == null)
                {
                    throw new InvalidDataException(String.Format("No property {0} found in type {1}", containedField, type.Name));
                }
                IInformationObject containedObject = (IInformationObject)prop.GetValue(iObj, null);
                if (containedObject == null && objectIDList.Length == 0)
                {
                    continue;
                }
                if (objectIDList.Length == 0)
                {
                    prop.SetValue(iObj, null, null);
                }
                else
                {
                    VirtualOwner owner            = VirtualOwner.FigureOwner(rootObject.RelativeLocation);
                    Type         contentType      = prop.PropertyType;
                    string       contentDomain    = contentType.Namespace;
                    string       contentTypeName  = contentType.Name;
                    bool         isCollectionType = typeof(IInformationCollection).IsAssignableFrom(contentType);
                    if (isCollectionType)
                    {
                        if (containedObject == null)
                        {
                            containedObject = (IInformationObject)Activator.CreateInstance(contentType);
                            prop.SetValue(iObj, containedObject, null);
                        }
                        dynamic dynObj     = containedObject;
                        object  listObject = dynObj.CollectionContent;
                        // Note the below works for List<T>, that we know the type is of ;-)
                        Type collectionItemType = listObject.GetType().GetGenericArguments()[0];
                        // This is assuming collections are referring within same domain only
                        contentTypeName = collectionItemType.Name;
                        IList contentList = (IList)listObject;
                        IEnumerable <IInformationObject> contentEnum     = (IEnumerable <IInformationObject>)listObject;
                        List <IInformationObject>        objectsToRemove = new List <IInformationObject>();
                        foreach (IInformationObject existingObject in contentList)
                        {
                            if (objectIDList.Contains(existingObject.ID) == false)
                            {
                                objectsToRemove.Add(existingObject);
                            }
                        }
                        objectsToRemove.ForEach(obj => contentList.Remove(obj));
                        foreach (string contentObjectID in objectIDList)
                        {
                            if (contentEnum.Any(item => item.ID == contentObjectID))
                            {
                                continue;
                            }
                            IInformationObject contentObject =
                                StorageSupport.RetrieveInformationObjectFromDefaultLocation(contentDomain, contentTypeName, contentObjectID,
                                                                                            owner);
                            if (contentObject == null)
                            {
                                continue;
                            }
                            contentList.Add(contentObject);
                        }
                    }
                    else
                    {
                        if (objectIDList.Length > 1)
                        {
                            throw new InvalidDataException("Object link name " + containedField + " of type " + contentTypeName + " does not allow multiple values");
                        }
                        string             contentObjectID = objectIDList[0];
                        IInformationObject contentObject   =
                            StorageSupport.RetrieveInformationObjectFromDefaultLocation(contentDomain, contentTypeName, contentObjectID,
                                                                                        owner);
                        prop.SetValue(iObj, contentObject, null);
                    }
                    //RetrieveInformationObjectFromDefaultLocation()
                }
            }
        }