本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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 );
}