当前位置: 首页>>代码示例>>C#>>正文


C# DataItem.LinkTo方法代码示例

本文整理汇总了C#中DataItem.LinkTo方法的典型用法代码示例。如果您正苦于以下问题:C# DataItem.LinkTo方法的具体用法?C# DataItem.LinkTo怎么用?C# DataItem.LinkTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataItem的用法示例。


在下文中一共展示了DataItem.LinkTo方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestSequenceLinkFirstSourceThenTarget

        public void TestSequenceLinkFirstSourceThenTarget()
        {
            string result = "";

            SimplerModel sourceModel = new SimplerModel {Name = "source"};
            sourceModel.Executing += (s, e) => result += ((SimplerModel)s).Name;

            SimplerModel targetModel = new SimplerModel { Name = "target" };
            targetModel.Executing += (s, e) => result += ((SimplerModel)s).Name;

            IDataItem sourceInput = new DataItem { Name = "SI", Value = new object(), Role = DataItemRole.Input };
            IDataItem sourceOutput = new DataItem { Name = "SO", Value = new object(), Role = DataItemRole.Output };
            IDataItem targetInput = new DataItem { Name = "TI", Value = new object(), Role = DataItemRole.Input };
            IDataItem targetOutput = new DataItem { Name = "TO", Value = new object(), Role = DataItemRole.Output };
            sourceModel.DataItems.Add(sourceInput);
            sourceModel.DataItems.Add(sourceOutput);
            targetModel.DataItems.Add(targetInput);
            targetModel.DataItems.Add(targetOutput);

            var compositeModel = new CompositeModel
            {
                Name = "composite model",
                Models = { sourceModel, targetModel }
            };

            targetInput.LinkTo(sourceOutput);

            compositeModel.Initialize();
            compositeModel.Execute();

            Assert.AreEqual("sourcetarget", result);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:32,代码来源:CompositeModelTest.cs

示例2: LinkAndUnlinkTwoDataItems

        public void LinkAndUnlinkTwoDataItems()
        {
            var dataObject1 = new CloneableClassWithThreeProperties();
            var dataObject2 = new CloneableClassWithThreeProperties();

            var dataItem1 = new DataItem(dataObject1, "a1");
            var dataItem2 = new DataItem(dataObject2, "a2");

            dataItem2.LinkTo(dataItem1);
            

            Assert.IsTrue(dataItem2.IsLinked);
            Assert.AreSame(dataItem1, dataItem2.LinkedTo);
            Assert.AreSame(dataItem2, dataItem1.LinkedBy[0]);

            dataItem2.Unlink();

            Assert.AreEqual(null, dataItem2.LinkedTo);
            Assert.AreEqual(0, dataItem1.LinkedBy.Count);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:20,代码来源:DataItemTest.cs

示例3: CloneShouldUpdateLinksWithinModel

        public void CloneShouldUpdateLinksWithinModel()
        {
            //Situation
            // CompositeModel
            //   |-SourceModel
            //   |-LinkedModel (->SourceModel)

            //Clone this composite model and expect the c-linkedmodel to be connected to the cloned-sourcemodel.

            var compositeModel = new CompositeModel();
            IModel sourceModel = new TestModel("source");
            
            IDataItem sourceDataItem = new DataItem(new Url(), "sourceItem");
            sourceModel.DataItems.Add(sourceDataItem);
            compositeModel.Models.Add(sourceModel);

            IModel linkedModel = new TestModel("linked");
            IDataItem linkedDataItem = new DataItem {Name = "linkedItem"};
            
            linkedModel.DataItems.Add(linkedDataItem);
            compositeModel.Models.Add(linkedModel);

            linkedDataItem.LinkTo(sourceDataItem);

            var clonedModel = (CompositeModel) compositeModel.DeepClone();

            IModel clonedSourceModel = clonedModel.Models.Where(m => m.Name == "source").First();
            IModel clonedLinkedModel = clonedModel.Models.Where(m => m.Name == "linked").First();

            IDataItem clonedLinkedItem = clonedLinkedModel.DataItems.Where(d => d.Name == "linkedItem").First();
            IDataItem clonedSourceItem = clonedSourceModel.DataItems.Where(d => d.Name == "sourceItem").First();

            //the cloned sourceitem should not be the the sourcedataitem.
            Assert.AreNotEqual(clonedSourceItem.Value, sourceDataItem.Value);


            Assert.IsTrue(clonedLinkedItem.IsLinked);
            Assert.AreEqual(clonedSourceItem, clonedLinkedItem.LinkedTo);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:39,代码来源:CompositeModelTest.cs

示例4: RemoveExternalLinksAndKeepInternalLinks

        public void RemoveExternalLinksAndKeepInternalLinks()
        {
            var folder = new Folder("folder");
            var internal1 = new DataItem("internal1");
            folder.Items.Add(internal1);
            var internal2 = new DataItem("internal2");
            folder.Items.Add(internal2);

            var external = new DataItem("external2");

            //internalLink
            internal2.LinkTo(internal1);
            //externalLink
            internal1.LinkTo(external);

            folder.GetAllItemsRecursive().OfType<IDataItem>().RemoveOuterDataItemLinks();

            Assert.IsFalse(internal1.IsLinked);
            Assert.IsTrue(internal2.IsLinked);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:20,代码来源:ProjectTest.cs

示例5: RemoveExternalLinks

        public void RemoveExternalLinks()
        {
            var item = new DataItem("item");
            var sourceItem = new DataItem("source");

            item.LinkTo(sourceItem);
            item.GetAllItemsRecursive().OfType<IDataItem>().RemoveOuterDataItemLinks();
            Assert.IsFalse(item.IsLinked);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:9,代码来源:ProjectTest.cs

示例6: CannotDeleteLinkedDataItem

        public void CannotDeleteLinkedDataItem()
        {
            Folder folder = new Folder();
            DataItem dataItem = new DataItem();
            folder.Items.Add(dataItem);

            //create a reference to the dataitem
            DataItem linkedItem = new DataItem();
            linkedItem.LinkTo(dataItem);

            //try to delete the item this should not happen
            folder.Items.RemoveAt(0);
            //todo: find a way to read the message in the log4net logger.
            Assert.AreEqual(1,folder.DataItems.Count());
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:15,代码来源:FolderTest.cs

示例7: LinkAndUnlinkTwoDiscretizationItemsCheckValueAndName

        public void LinkAndUnlinkTwoDiscretizationItemsCheckValueAndName()
        {
            var grid1 = new Discretization { Name = "grid1" };
            var grid2 = new Discretization { Name = "grid2" };

            var dataItem1 = new DataItem(grid1, "a1");
            var dataItem2 = new DataItem(grid2, "a2");

            dataItem2.LinkTo(dataItem1);

            dataItem2.Unlink();

            Assert.AreEqual(typeof(Discretization), dataItem2.Value.GetType());
            Assert.AreEqual(typeof(Discretization), dataItem1.Value.GetType());

            var grid2X = (Discretization)dataItem2.Value;

            Assert.AreEqual("computational grid", grid2X.Name);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:19,代码来源:DataItemTest.cs

示例8: LinkAndUnlinkTwoDiscretizationItems

        public void LinkAndUnlinkTwoDiscretizationItems()
        {
            var dataObject1 = new Discretization();
            var dataObject2 = new Discretization();

            var dataItem1 = new DataItem(dataObject1, "a1");
            var dataItem2 = new DataItem(dataObject2, "a2");

            dataItem2.LinkTo(dataItem1);

            Assert.IsTrue(dataItem2.IsLinked);
            Assert.AreSame(dataItem1, dataItem2.LinkedTo);
            Assert.AreSame(dataItem2, dataItem1.LinkedBy[0]);

            dataItem2.Unlink();

            Assert.AreEqual(null, dataItem2.LinkedTo);
            Assert.AreEqual(0, dataItem1.LinkedBy.Count);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:19,代码来源:DataItemTest.cs

示例9: UnLinkEventIncludesPreviousValue

        public void UnLinkEventIncludesPreviousValue()
        {
            //old value is needed to close views.
            var linkedValue = new Url();
            var sourceDataItem = new DataItem(linkedValue);
            var targetDataItem = new DataItem(new Url());

            int callCount = 0;
            targetDataItem.Unlinked += (s, e) =>
            {
                callCount++;
                Assert.AreEqual(sourceDataItem, e.Source);
                Assert.AreEqual(targetDataItem, e.Target);
                Assert.AreEqual(linkedValue, e.PreviousValue);
            };
            targetDataItem.LinkTo(sourceDataItem);
            
            //action! unlink
            targetDataItem.Unlink();
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:20,代码来源:DataItemTest.cs

示例10: PropertyChangedWorkOnLinkedItems

        public void PropertyChangedWorkOnLinkedItems()
        {
            var propertyChangedClass = new CloneableClassWithThreeProperties();
            var sourceDataItem = new DataItem(propertyChangedClass);
            var linkedDataItem = new DataItem(new CloneableClassWithThreeProperties());

            linkedDataItem.LinkTo(sourceDataItem);

            int callCount = 0;
            ((INotifyPropertyChanged) linkedDataItem).PropertyChanged += (s, e) =>
                                                                             {
                                                                                 callCount++;
                                                                                 Assert.AreEqual(propertyChangedClass, s);
                                                                                 Assert.AreEqual("StringProperty", e.PropertyName);
                                                                             };

            propertyChangedClass.StringProperty = "newName";
            Assert.AreEqual(1,callCount);
               
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:20,代码来源:DataItemTest.cs

示例11: NameShouldChangeWhenLinkedNamedValueNameChanges

        public void NameShouldChangeWhenLinkedNamedValueNameChanges()
        {
            var dataObject1 = new CloneableClassWithThreeProperties();
            var dataObject2 = new CloneableClassWithThreeProperties();

            var dataItem1 = new DataItem(dataObject1, "name1");
            var dataItem2 = new DataItem(dataObject2, "name2");

            dataItem2.LinkTo(dataItem1);

            Assert.AreEqual("name1", dataItem1.Name);
            Assert.AreEqual("name2", dataItem2.Name);
            Assert.AreEqual("name1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual("name1", ((INameable)dataItem2.Value).Name);

            dataObject2.Name = "newName2";
            Assert.AreEqual("name1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual("name1", ((INameable)dataItem2.Value).Name);

            dataObject1.Name = "newName1";
            Assert.AreEqual("newName1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual("newName1", ((INameable)dataItem2.Value).Name);

            dataItem2.Unlink();

            // unlinking results in a new object of the original type as Value in the 
            // item with an uninitialized name. 
            // The original dataObject2 is now an orphan.
            Assert.AreEqual("newName1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual(null, ((INameable)dataItem2.Value).Name);

            ((INameable)dataItem2.Value).Name = "newerName2";
            Assert.AreEqual("newerName2", dataItem2.Name);

            dataItem2.Name = "weereensietsanders";
            Assert.AreEqual("weereensietsanders", ((INameable)dataItem2.Value).Name);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:37,代码来源:DataItemTest.cs

示例12: CloneLinkedDataItem

        public void CloneLinkedDataItem()
        {
            var dataItem = new DataItem();
            dataItem.Value = new CloneableClassWithThreeProperties();
            //TODO: why do we need to set the valuetype. Why is this not Typeof(value)???
            //or (next best) why is this determined at construction time.
            dataItem.ValueType = typeof (CloneableClassWithThreeProperties);

            IDataItem linkedDataItem = new DataItem();
            linkedDataItem.ValueType = typeof(CloneableClassWithThreeProperties);
            linkedDataItem.LinkTo(dataItem);
            Assert.AreEqual(dataItem.ValueType,linkedDataItem.ValueType);

            //action! clone the linked dataitem
            var clonedLinkedDataItem = (DataItem)linkedDataItem.DeepClone();
            Assert.AreEqual(linkedDataItem.ValueType,clonedLinkedDataItem.ValueType );

        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:18,代码来源:DataItemTest.cs


注:本文中的DataItem.LinkTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。