本文整理汇总了C#中Dynamo.Utilities.CustomNodeInfo类的典型用法代码示例。如果您正苦于以下问题:C# CustomNodeInfo类的具体用法?C# CustomNodeInfo怎么用?C# CustomNodeInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CustomNodeInfo类属于Dynamo.Utilities命名空间,在下文中一共展示了CustomNodeInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanRefactorCustomNodeName
public void CanRefactorCustomNodeName()
{
var nodeName = "TheNoodle";
var catName = "TheCat";
var descr = "TheCat";
var path = @"C:\turtle\graphics.dyn";
var guid1 = Guid.NewGuid();
var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
_search.Add(dummyInfo1);
Assert.AreEqual(1, _search.SearchDictionary.NumElements);
var newNodeName = "TheTurtle";
var newInfo = new CustomNodeInfo(guid1, newNodeName, catName, descr, path);
_search.Refactor(newInfo);
Assert.AreEqual(1, _search.SearchDictionary.NumElements);
// search for new name
_search.SearchAndUpdateResultsSync(newNodeName);
// results are correct
Assert.AreEqual(1, _search.SearchResults.Count);
var res1 = _search.SearchResults[0];
Assert.IsAssignableFrom(typeof(CustomNodeSearchElement), res1);
var node1 = res1 as CustomNodeSearchElement;
Assert.AreEqual(node1.Guid, guid1);
// search for old name
_search.SearchAndUpdateResultsSync(nodeName);
// results are correct
Assert.AreEqual(0, _search.SearchResults.Count);
}
示例2: CanRefactorCustomNodeDescription
public void CanRefactorCustomNodeDescription()
{
var nodeName = "TheNoodle";
var catName = "TheCat";
var descr = "Cool description, man";
var path = @"C:\turtle\graphics.dyn";
var guid1 = Guid.NewGuid();
var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
_search.Add(dummyInfo1);
Assert.AreEqual(1, _search.SearchDictionary.NumElements);
// search for name
_search.SearchAndUpdateResultsSync(nodeName);
// results are correct
Assert.AreEqual(1, _search.SearchResults.Count);
var res1 = _search.SearchResults[0];
Assert.IsAssignableFrom(typeof(CustomNodeSearchElement), res1);
var node1 = res1 as CustomNodeSearchElement;
Assert.AreEqual(node1.Guid, guid1);
Assert.AreEqual(node1.Description, descr);
// refactor description
const string newDescription = "Tickle me elmo";
var newInfo = new CustomNodeInfo(guid1, nodeName, catName, newDescription, path);
_search.Refactor(newInfo);
// num elements is unchanged
Assert.AreEqual(1, _search.SearchDictionary.NumElements);
// search for name
_search.SearchAndUpdateResultsSync(nodeName);
// description is updated
Assert.AreEqual(1, _search.SearchResults.Count);
var res2 = _search.SearchResults[0];
Assert.IsAssignableFrom(typeof(CustomNodeSearchElement), res2);
var node2 = res2 as CustomNodeSearchElement;
Assert.AreEqual( guid1, node2.Guid );
Assert.AreEqual( newDescription, node2.Description);
}
示例3: CanRefactorCustomNodeWhilePreservingDuplicates
public void CanRefactorCustomNodeWhilePreservingDuplicates()
{
var nodeName = "TheNoodle";
var catName = "TheCat";
var descr = "TheCat";
var path = @"C:\turtle\graphics.dyn";
var guid1 = Guid.NewGuid();
var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
var guid2 = Guid.NewGuid();
var dummyInfo2 = new CustomNodeInfo(guid2, nodeName, catName, descr, path);
_search.Add(dummyInfo1);
_search.Add(dummyInfo2);
Assert.AreEqual(2, _search.SearchDictionary.NumElements);
// refactor one of the nodes with newNodeName
var newNodeName = "TheTurtle";
var newInfo = new CustomNodeInfo(guid1, newNodeName, catName, descr, path);
_search.Refactor(newInfo);
// num elements is unchanged
Assert.AreEqual(2, _search.SearchDictionary.NumElements);
// search for new name
_search.SearchAndUpdateResultsSync(newNodeName);
// results are correct - only one result
Assert.AreEqual(1, _search.SearchResults.Count);
var res1 = _search.SearchResults[0];
Assert.IsAssignableFrom(typeof(CustomNodeSearchElement), res1);
var node1 = res1 as CustomNodeSearchElement;
Assert.AreEqual(node1.Guid, guid1);
// search for old name
_search.SearchAndUpdateResultsSync(nodeName);
// results are correct - the first nodes are returned
Assert.AreEqual(1, _search.SearchResults.Count);
var res2 = _search.SearchResults[0];
Assert.IsAssignableFrom(typeof(CustomNodeSearchElement), res2);
var node2 = res2 as CustomNodeSearchElement;
Assert.AreEqual(node2.Guid, guid2);
}
示例4: TryGetNodeInfo
/// <summary>
/// Attempts to retrieve information for the given custom node name. If there are multiple
/// custom nodes matching the given name, this method will return any one of them.
/// </summary>
/// <param name="name">Name of a custom node.</param>
/// <param name="info"></param>
/// <returns></returns>
public bool TryGetNodeInfo(string name, out CustomNodeInfo info)
{
info = NodeInfos.Values.FirstOrDefault(x => x.Name == name);
return info != null;
}
示例5: RegisterCustomNodeWorkspace
private void RegisterCustomNodeWorkspace(
CustomNodeWorkspaceModel newWorkspace, CustomNodeInfo info, CustomNodeDefinition definition)
{
loadedWorkspaceModels[newWorkspace.CustomNodeId] = newWorkspace;
SetFunctionDefinition(definition);
OnDefinitionUpdated(definition);
newWorkspace.DefinitionUpdated += () =>
{
var newDef = newWorkspace.CustomNodeDefinition;
SetFunctionDefinition(newDef);
OnDefinitionUpdated(newDef);
};
SetNodeInfo(info);
newWorkspace.InfoChanged += () =>
{
var newInfo = newWorkspace.CustomNodeInfo;
SetNodeInfo(newInfo);
OnInfoUpdated(newInfo);
};
newWorkspace.FunctionIdChanged += oldGuid =>
{
loadedWorkspaceModels.Remove(oldGuid);
loadedCustomNodes.Remove(oldGuid);
loadOrder.Remove(oldGuid);
loadedWorkspaceModels[newWorkspace.CustomNodeId] = newWorkspace;
};
}
示例6: SetNodeInfo
/// <summary>
/// Stores the path and function definition without initializing a node. Overwrites
/// the existing NodeInfo if necessary
/// </summary>
private void SetNodeInfo(CustomNodeInfo newInfo)
{
var guids = NodeInfos.Where(x =>
{
return !string.IsNullOrEmpty(x.Value.Path) &&
string.Compare(x.Value.Path, newInfo.Path, StringComparison.OrdinalIgnoreCase) == 0;
}).Select(x => x.Key).ToList();
foreach (var guid in guids)
{
NodeInfos.Remove(guid);
}
NodeInfos[newInfo.FunctionId] = newInfo;
OnInfoUpdated(newInfo);
}
示例7: CreateCustomNodeInstance
/// <summary>
/// Creates a new Custom Node Instance.
/// </summary>
/// <param name="id">Identifier referring to a custom node definition.</param>
/// <param name="nickname">
/// Nickname for the custom node to be instantiated, used for error recovery if
/// the given id could not be found.
/// </param>
/// <param name="isTestMode">
/// Flag specifying whether or not this should operate in "test mode".
/// </param>
public Function CreateCustomNodeInstance(
Guid id, string nickname = null, bool isTestMode = false)
{
CustomNodeWorkspaceModel workspace;
CustomNodeDefinition def;
CustomNodeInfo info;
// Try to get the definition, initializing the custom node if necessary
if (TryGetFunctionDefinition(id, isTestMode, out def))
{
// Got the definition, proceed as planned.
info = NodeInfos[id];
}
else
{
// Couldn't get the workspace with the given ID, try a nickname lookup instead.
if (nickname != null && TryGetNodeInfo(nickname, out info))
return CreateCustomNodeInstance(info.FunctionId, nickname, isTestMode);
// Couldn't find the workspace at all, prepare for a late initialization.
Log(
Properties.Resources.UnableToCreateCustomNodeID + id + "\"",
WarningLevel.Moderate);
info = new CustomNodeInfo(id, nickname ?? "", "", "", "");
}
if (def == null)
{
def = CustomNodeDefinition.MakeProxy(id, info.Name);
}
var node = new Function(def, info.Name, info.Description, info.Category);
if (loadedWorkspaceModels.TryGetValue(id, out workspace))
RegisterCustomNodeInstanceForUpdates(node, workspace);
else
RegisterCustomNodeInstanceForLateInitialization(node, id, nickname, isTestMode);
return node;
}
示例8: SetNodeInfo
/// <summary>
/// Stores the path and function definition without initializing a node. Overwrites
/// the existing NodeInfo if necessary
/// </summary>
/// <param name="guid">The unique id for the node.</param>
/// <param name="path">The path for the node.</param>
public void SetNodeInfo(CustomNodeInfo newInfo)
{
var nodeInfo = GetNodeInfo(newInfo.Guid);
if (nodeInfo == null)
{
NodeInfos.Add(newInfo.Guid, newInfo);
}
else
{
NodeInfos[newInfo.Guid] = newInfo;
}
}
示例9: CustomNodeSaveAsAddsNewCustomNodeToSearchAndItCanBeRefactoredWhilePreservingOriginalFromExistingDyf2
public void CustomNodeSaveAsAddsNewCustomNodeToSearchAndItCanBeRefactoredWhilePreservingOriginalFromExistingDyf2()
{
// open custom node
// SaveAs
// two nodes are returned in search on custom node name, difer
var model = Controller.DynamoModel;
var examplePath = Path.Combine(GetTestDirectory(), @"core\custom_node_saving", "Constant2.dyf");
Controller.DynamoViewModel.OpenCommand.Execute(examplePath);
var nodeWorkspace =
model.Workspaces.FirstOrDefault(x => x is CustomNodeWorkspaceModel) as CustomNodeWorkspaceModel;
Assert.IsNotNull(nodeWorkspace);
var oldId = nodeWorkspace.CustomNodeDefinition.FunctionId;
var newPath = this.GetNewFileNameOnTempPath("dyf");
var originalNumElements = Controller.SearchViewModel.SearchDictionary.NumElements;
// save as
nodeWorkspace.SaveAs(newPath); // introduces new function id
var newId = nodeWorkspace.CustomNodeDefinition.FunctionId;
// refactor oldId with new name
var nodeName = "Constant2 Alt";
var catName = "TheCat";
var descr = "TheCat";
var dummyInfo1 = new CustomNodeInfo(newId, nodeName, catName, descr, "");
Controller.CustomNodeManager.Refactor(dummyInfo1);
// num elements is unchanged by refactor
Assert.AreEqual(originalNumElements + 1, Controller.SearchViewModel.SearchDictionary.NumElements);
// search common base name
Controller.SearchViewModel.SearchAndUpdateResultsSync("Constant2");
// results are correct
Assert.AreEqual(2, Controller.SearchViewModel.SearchResults.Count);
var res1 = Controller.SearchViewModel.SearchResults[0];
var res2 = Controller.SearchViewModel.SearchResults[1];
Assert.IsAssignableFrom(typeof(CustomNodeSearchElement), res1);
Assert.IsAssignableFrom(typeof(CustomNodeSearchElement), res2);
var node1 = res1 as CustomNodeSearchElement;
var node2 = res2 as CustomNodeSearchElement;
Assert.IsTrue((node1.Guid == oldId && node2.Guid == newId) ||
(node1.Guid == newId && node2.Guid == oldId));
}
示例10: SetNodeInfo
/// <summary>
/// Stores the path and function definition without initializing a node
/// </summary>
/// <param name="guid">The unique id for the node.</param>
/// <param name="path">The path for the node.</param>
public void SetNodeInfo(CustomNodeInfo info)
{
this.SetNodeName(info.Guid, info.Name);
this.SetNodeCategory(info.Guid, info.Category);
this.SetNodeDescription(info.Guid, info.Description);
this.SetNodePath(info.Guid, info.Path);
}
示例11: SaveFunction
/// <summary>
/// Save a function. This includes writing to a file and compiling the
/// function and saving it to the FSchemeEnvironment
/// </summary>
/// <param name="definition">The definition to save</param>
/// <param name="bool">Whether to write the function to file.</param>
/// <returns>Whether the operation was successful</returns>
public void SaveFunction(FunctionDefinition definition, bool writeDefinition = true, bool addToSearch = false, bool compileFunction = true)
{
if (definition == null)
return;
// Get the internal nodes for the function
var functionWorkspace = definition.Workspace as FuncWorkspace;
// If asked to, write the definition to file
if (writeDefinition)
{
string path = "";
if (String.IsNullOrEmpty(definition.Workspace.FilePath))
{
var pluginsPath = this.Controller.CustomNodeManager.GetDefaultSearchPath();
if (!Directory.Exists(pluginsPath))
Directory.CreateDirectory(pluginsPath);
path = Path.Combine(pluginsPath, dynSettings.FormatFileName(functionWorkspace.Name) + ".dyf");
}
else
{
path = definition.Workspace.FilePath;
}
try
{
dynWorkspaceModel.SaveWorkspace(path, functionWorkspace);
if (addToSearch)
{
Controller.SearchViewModel.Add(functionWorkspace.Name, functionWorkspace.Category, functionWorkspace.Description, definition.FunctionId);
}
var customNodeInfo = new CustomNodeInfo(definition.FunctionId, functionWorkspace.Name, functionWorkspace.Category,
functionWorkspace.Description, path);
Controller.CustomNodeManager.SetNodeInfo(customNodeInfo);
#region Compile Function and update all nodes
IEnumerable<string> inputNames = new List<string>();
IEnumerable<string> outputNames = new List<string>();
dynSettings.Controller.FSchemeEnvironment.DefineSymbol(definition.FunctionId.ToString(), CustomNodeManager.CompileFunction(definition, ref inputNames, ref outputNames));
//Update existing function nodes which point to this function to match its changes
foreach (dynNodeModel el in AllNodes)
{
if (el is dynFunction)
{
var node = (dynFunction)el;
if (node.Definition != definition)
continue;
node.SetInputs(inputNames);
node.SetOutputs(outputNames);
el.RegisterAllPorts();
}
}
//Call OnSave for all saved elements
foreach (dynNodeModel el in functionWorkspace.Nodes)
el.onSave();
#endregion
}
catch (Exception e)
{
Log("Error saving:" + e.GetType());
Log(e);
}
}
}
示例12: CanRemoveSingleCustomNodeByIdWhereThereAreDuplicatesWithDifferentIds
public void CanRemoveSingleCustomNodeByIdWhereThereAreDuplicatesWithDifferentIds()
{
var nodeName = "TheNoodle";
var catName = "TheCat";
var descr = "TheCat";
var path = @"C:\turtle\graphics.dyn";
var guid1 = Guid.NewGuid();
var guid2 = Guid.NewGuid();
var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
var dummyInfo2 = new CustomNodeInfo(guid2, nodeName, catName, descr, path);
_search.Add(dummyInfo1);
_search.Add(dummyInfo2);
Assert.AreEqual(2, _search.SearchDictionary.NumElements);
_search.RemoveNodeAndEmptyParentCategory(guid2);
Assert.AreEqual(1, _search.SearchDictionary.NumElements);
_search.SearchAndUpdateResultsSync(nodeName);
Assert.AreEqual(1, _search.SearchResults.Count);
var res1 = _search.SearchResults[0];
Assert.IsAssignableFrom(typeof(CustomNodeSearchElement), res1);
var node1 = res1 as CustomNodeSearchElement;
Assert.AreEqual(node1.Guid, guid1);
}
示例13: CanAddDuplicateCustomNodeWithDifferentGuidsAndGetBothInResults
public void CanAddDuplicateCustomNodeWithDifferentGuidsAndGetBothInResults()
{
var nodeName = "TheNoodle";
var catName = "TheCat";
var descr = "TheCat";
var path = @"C:\turtle\graphics.dyn";
var guid1 = Guid.NewGuid();
var guid2 = Guid.NewGuid();
var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
var dummyInfo2 = new CustomNodeInfo(guid2, nodeName, catName, descr, path);
_search.Add(dummyInfo1);
_search.Add(dummyInfo2);
Assert.AreEqual(2, _search.SearchDictionary.NumElements);
_search.SearchAndUpdateResultsSync(nodeName);
Assert.AreEqual(2, _search.SearchResults.Count);
var res1 = _search.SearchResults[0];
var res2 = _search.SearchResults[1];
Assert.IsAssignableFrom(typeof(CustomNodeSearchElement), res1);
Assert.IsAssignableFrom(typeof(CustomNodeSearchElement), res2);
var node1 = res1 as CustomNodeSearchElement;
var node2 = res2 as CustomNodeSearchElement;
Assert.AreEqual(node1.Guid, guid1);
Assert.AreEqual(node2.Guid, guid2);
}
示例14: CanRemoveNodeAndCategoryByFunctionId
public void CanRemoveNodeAndCategoryByFunctionId()
{
var nodeName = "TheNoodle";
var catName = "TheCat";
var descr = "TheCat";
var path = @"C:\turtle\graphics.dyn";
var guid1 = Guid.NewGuid();
var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
// add custom node
_search.Add(dummyInfo1);
// confirm it's in the dictionary
Assert.AreEqual(1, _search.SearchDictionary.NumElements);
// remove custom node
_search.RemoveNodeAndEmptyParentCategory(guid1);
// it's gone
Assert.AreEqual(0, _search.SearchDictionary.NumElements);
_search.SearchAndUpdateResultsSync(nodeName);
Assert.AreEqual(0, _search.SearchResults.Count);
}
示例15: GetOwnerPackage
public Package GetOwnerPackage(CustomNodeInfo def)
{
return GetOwnerPackage(def.Path);
}