Ejemplo n.º 1
0
        private void AddProperties(ComplexResourceInstance updateTree, RowComplexType newResource)
        {
            foreach (ResourceInstanceProperty property in updateTree.Properties)
            {
                if (property is ResourceInstanceSimpleProperty)
                {
                    ResourceInstanceSimpleProperty tempProperty = (ResourceInstanceSimpleProperty)property;
                    newResource.Properties.Add(tempProperty.Name, tempProperty.PropertyValue);
                }
                else if (property is ResourceInstanceComplexProperty)
                {
                    ResourceInstanceComplexProperty tempProperty = (ResourceInstanceComplexProperty)property;
                    RowComplexType newComplexType = new RowComplexType(tempProperty.TypeName);
                    AddProperties(tempProperty.ComplexResourceInstance, newComplexType);
                    newResource.Properties.Add(tempProperty.Name, newComplexType);
                }
                else if (property is ResourceInstanceNavRefProperty)
                {
                    ResourceInstanceNavRefProperty tempProperty = (ResourceInstanceNavRefProperty)property;
                    RowEntityType nestedResource = FindRowInstance((KeyedResourceInstance)tempProperty.TreeNode);

                    if (nestedResource == null)
                        nestedResource = AddNewEntity((KeyedResourceInstance)tempProperty.TreeNode, null);

                    newResource.Properties.Add(tempProperty.Name, nestedResource);
                }
                else if (property is ResourceInstanceNavColProperty)
                {
                    ResourceInstanceNavColProperty tempProperty = (ResourceInstanceNavColProperty)property;

                    List<RowEntityType> entityList = new List<RowEntityType>();

                    foreach (ResourceBodyTree entity in tempProperty.Collection.NodeList)
                    {
                        RowEntityType nestedResource = FindRowInstance((KeyedResourceInstance)entity);

                        if (nestedResource == null)
                            nestedResource = AddNewEntity((KeyedResourceInstance)entity, null);

                        entityList.Add(nestedResource);
                    }

                    newResource.Properties.Add(tempProperty.Name, entityList);
                }
                else
                    throw new TestException(TestResult.Failed, "NonClr - Unhandled property type.");
            }
        }
Ejemplo n.º 2
0
        private void ModifyProperties(ComplexResourceInstance updateTree, RowComplexType newResource, bool replace)
        {
            foreach (ResourceInstanceProperty property in updateTree.Properties)
            {
                if (property is ResourceInstanceSimpleProperty)
                {
                    ResourceInstanceSimpleProperty tempProperty = (ResourceInstanceSimpleProperty)property;
                    newResource.Properties[tempProperty.Name] = tempProperty.PropertyValue;
                }
                else if (property is ResourceInstanceComplexProperty)
                {
                    ResourceInstanceComplexProperty tempProperty = (ResourceInstanceComplexProperty)property;
                    RowComplexType newComplexType = new RowComplexType(tempProperty.TypeName);
                    ModifyProperties(tempProperty.ComplexResourceInstance, newComplexType, replace);
                    newResource.Properties[tempProperty.Name] = newComplexType;
                }
            }

            if (replace)
            {
                string[] keys = newResource.Properties.Keys.ToArray();
                foreach (string key in keys)
                {
                    if (updateTree.Properties.Where(p => p.Name == key).Count() == 0)
                    {
                        if (updateTree is KeyedResourceInstance)
                        {
                            KeyedResourceInstance keyedResource = (KeyedResourceInstance)updateTree;
                            if (keyedResource.KeyProperties.Where(p => p.Name == key).Count() == 0)
                                newResource.Properties[key] = null;
                        }
                        else
                            newResource.Properties[key] = null;
                    }
                }
            }
        }
Ejemplo n.º 3
0
 private void ModifyProperty(ResourceInstanceSimpleProperty property, RowComplexType newResource)
 {
     newResource.Properties[property.Name] = property.PropertyValue;
 }
Ejemplo n.º 4
0
 private void ModifyProperty(ResourceInstanceComplexProperty property, RowComplexType newResource)
 {
     ModifyProperties(property.ComplexResourceInstance, (RowComplexType)newResource.Properties[property.Name], false);
 }
Ejemplo n.º 5
0
        private void AddNavigationProperties(ResourceType resourceType, RowComplexType newResource)
        {
            foreach (ResourceProperty property in resourceType.Properties)
            {
                if (property.IsNavigation && !newResource.Properties.ContainsKey(property.Name))
                {
                    newResource.Properties.Add(property.Name, null);

                    if (property.Type is CollectionType)
                        newResource.Properties[property.Name] = new List<RowEntityType>();
                }
            }
        }