Пример #1
0
        private int AddLinkedResources(TreeNode treeNode, IResource selectedResource, int linkID, LinkNode linkNode)
        {
            bool          directed  = _resourceStore.PropTypes [linkID].HasFlag(PropTypeFlags.DirectedLink);
            IResourceList resources = null;

            if (directed)
            {
                if (linkID < 0)
                {
                    resources = selectedResource.GetLinksTo(null, -linkID);
                }
                else
                {
                    resources = selectedResource.GetLinksFrom(null, linkID);
                }
            }
            else
            {
                resources = selectedResource.GetLinksOfType(null, linkID);
            }

            int count = 0;

            foreach (IResource resource in resources)
            {
                if (IsSerializerExists(resource))
                {
                    int iconIndex = GetIcon(resource);
                    Tracer._Trace(resource.DisplayName);
                    TreeNode            treeSubNode  = new TreeNode(GetTypeDisplayName(resource.Type) + ": " + resource.DisplayName, iconIndex, iconIndex);
                    ResourceNode        resourceNode = linkNode.AddResource(resource);
                    IPropertyCollection properties   = resourceNode.Resource.Properties;
                    foreach (IResourceProperty property in properties)
                    {
                        if (property.DataType != PropDataType.Link)
                        {
                            IResourceSerializer serializer = Core.PluginLoader.GetResourceSerializer(resourceNode.Resource.Type);
                            SerializationMode   serMode    = GetSerializationMode(serializer, resourceNode.Resource, property);
                            if (serMode == SerializationMode.NoSerialize)
                            {
                                continue;
                            }
                            resourceNode.AddProperty(property);
                        }
                    }

                    treeSubNode.Tag = new SerializableTag(resourceNode, SerializableTag.Type.LinkedResource);
                    treeNode.Nodes.Add(treeSubNode);
                    _resourceTreeView.SetNodeCheckState(treeSubNode, NodeCheckState.Checked);
                    count++;
                }
            }
            return(count);
        }
Пример #2
0
        private void AddProperty(ResourceNode resourceNode, IResourceProperty property, TreeNode parentNode)
        {
            int      iconIndex       = Core.ResourceIconManager.GetPropTypeIconIndex(property.PropId);
            string   linkDisplayName = _resourceStore.PropTypes.GetPropDisplayName(property.PropId);
            TreeNode treeSubNode     =
                new TreeNode(linkDisplayName, iconIndex, iconIndex);
            PropertyNode propertyNode = resourceNode.AddProperty(property);

            treeSubNode.Tag = new SerializableTag(propertyNode, SerializableTag.Type.Link);
            parentNode.Nodes.Add(treeSubNode);
            _resourceTreeView.SetNodeCheckState(treeSubNode, NodeCheckState.Checked);
        }
Пример #3
0
        public void TestStringListProps()
        {
            ResourceSerializer serializer = new ResourceSerializer();
            IResource          origin     = _storage.NewResource("Email");

            origin.SetProp(_propSize, 100);
            origin.SetProp(_propReceived, DateTime.Now);
            IStringList strLst = origin.GetStringListProp(_propValueList);

            using ( strLst )
            {
                strLst.Add("One");
                strLst.Add("Two");
                strLst.Add("Three");
            }
            origin.SetProp(_propUnread, true);
            origin.SetProp(_propSimilarity, 1.0);
            ResourceNode resNode = serializer.AddResource(origin);

            foreach (IResourceProperty prop in origin.Properties)
            {
                resNode.AddProperty(prop);
            }
            serializer.GenerateXML("SerializationResult.xml");
            origin.Delete();

            StreamReader sr  = new StreamReader("SerializationResult.xml", Encoding.Default);
            string       str = Utils.StreamReaderReadToEnd(sr);

            Console.WriteLine(str);
            sr.Close();

            ResourceDeserializer deserializer = new ResourceDeserializer("SerializationResult.xml");
            ArrayList            list         = deserializer.GetSelectedResources();

            Assert.AreEqual(1, list.Count, "List must contain only one resource. Current count is [" + list.Count + "]");
            ResourceUnpack ru = (ResourceUnpack)list[0];

            origin = ru.Resource;
            Assert.IsTrue(origin.HasProp(_propValueList),
                          "Resource must contain StringList property");
            IStringList stringsList = origin.GetStringListProp(_propValueList);

            Assert.AreEqual(3, stringsList.Count, "StringList must contain three elements. Current count is [" + stringsList.Count + "]");

            Assert.AreEqual("One", stringsList [0], "StringList[ 0 ] must be equal to [One]. Current value is [" + stringsList[0] + "]");
            Assert.AreEqual("Two", stringsList [1], "StringList[ 1 ] must be equal to [Two]. Current value is [" + stringsList[1] + "]");
            Assert.AreEqual("Three", stringsList [2], "StringList[ 2 ] must be equal to [Three]. Current value is [" + stringsList[2] + "]");
        }
Пример #4
0
        private void AddProperties(TreeNode treeNode, ResourceNode resourceNode)
        {
            IResourceSerializer serializer = Core.PluginLoader.GetResourceSerializer(resourceNode.Resource.Type);

            if (serializer == null)
            {
                return;
            }

            IPropertyCollection properties = resourceNode.Resource.Properties;

            foreach (IResourceProperty property in properties)
            {
                SerializationMode serMode = GetSerializationMode(serializer, resourceNode.Resource, property);
                if (serMode == SerializationMode.NoSerialize)
                {
                    continue;
                }

                if (property.DataType == PropDataType.Link)
                {
                    if (serMode == SerializationMode.Serialize || serMode == SerializationMode.AskSerialize)
                    {
                        AddLink(resourceNode, property, treeNode);
                    }
                }
                else
                {
                    if (serMode == SerializationMode.AskSerialize)
                    {
                        AddProperty(resourceNode, property, treeNode);
                    }
                    else
                    {
                        resourceNode.AddProperty(property);
                    }
                }
            }
        }