private IEnumerable<PackageDependency> GetAllDependencies() { var pmExtension = dynamoViewModel.Model.GetPackageManagerExtension(); var pkgLoader = pmExtension.PackageLoader; // all workspaces var workspaces = new List<CustomNodeWorkspaceModel>(); foreach (var def in AllDependentFuncDefs()) { CustomNodeWorkspaceModel ws; if (dynamoViewModel.Model.CustomNodeManager.TryGetFunctionWorkspace( def.FunctionId, DynamoModel.IsTestMode, out ws)) { workspaces.Add(ws); } } // get all of dependencies from custom nodes and additional files var allFilePackages = workspaces .Select(x => x.FileName) .Union(AdditionalFiles) .Where(pkgLoader.IsUnderPackageControl) .Select(pkgLoader.GetOwnerPackage) .Where(x => x != null) .Where(x => (x.Name != Name)) .Distinct() .Select(x => new PackageDependency(x.Name, x.VersionName)); workspaces = new List<CustomNodeWorkspaceModel>(); foreach (var def in AllFuncDefs()) { CustomNodeWorkspaceModel ws; if (dynamoViewModel.Model.CustomNodeManager.TryGetFunctionWorkspace( def.FunctionId, DynamoModel.IsTestMode, out ws)) { workspaces.Add(ws); } } // get all of the dependencies from types var allTypePackages = workspaces .SelectMany(x => x.Nodes) .Select(x => x.GetType()) .Where(pkgLoader.IsUnderPackageControl) .Select(pkgLoader.GetOwnerPackage) .Where(x => x != null) .Where(x => (x.Name != Name)) .Distinct() .Select(x => new PackageDependency(x.Name, x.VersionName)); var dsFunctionPackages = workspaces .SelectMany(x => x.Nodes) .OfType<DSFunctionBase>() .Select(x => x.Controller.Definition.Assembly) .Where(pkgLoader.IsUnderPackageControl) .Select(pkgLoader.GetOwnerPackage) .Where(x => x != null) .Where(x => (x.Name != Name)) .Distinct() .Select(x => new PackageDependency(x.Name, x.VersionName)); return allFilePackages.Union(allTypePackages).Union(dsFunctionPackages); }
/// <summary> /// Invoke an API method, using the node's lacing strategy to build lists of arguments /// </summary> /// <param name="node">The node.</param> /// <param name="args">The incoming Values on the node.</param> /// <param name="api_base_type">The API's base type whose method we will invoke.</param> /// <param name="pi">An array of parameter info for the method.</param> /// <param name="mi">The method info for the method.</param> /// <param name="return_type">The expected return type from the method.</param> /// <returns></returns> public static Value InvokeAPIMethod(dynRevitTransactionNode node, FSharpList<Value> args, Type api_base_type, ParameterInfo[] pi, MethodBase mi, Type return_type) { //if any argument are a list, honor the lacing strategy //compile a list of parameter lists to be used in our method invocation List<List<object>> parameters = null; switch (node.ArgumentLacing) { case LacingStrategy.Single: parameters = GetSingleArguments(args, pi); break; case LacingStrategy.Shortest: parameters = GetShortestArguments(args, pi); break; case LacingStrategy.Longest: parameters = GetLongestArguments(args, pi); break; default: parameters = GetSingleArguments(args, pi); break; } var invocationTargetList = new List<object>(); if (api_base_type == typeof(Autodesk.Revit.Creation.Document) || api_base_type == typeof(Autodesk.Revit.Creation.FamilyItemFactory) || api_base_type == typeof(Autodesk.Revit.Creation.ItemFactoryBase)) { if (dynRevitSettings.Doc.Document.IsFamilyDocument) { invocationTargetList.Add(dynRevitSettings.Doc.Document.FamilyCreate); } else { invocationTargetList.Add(dynRevitSettings.Doc.Document.Create); } } else if (api_base_type == typeof(Autodesk.Revit.Creation.Application)) { invocationTargetList.Add(dynRevitSettings.Revit.Application.Create); } else { if (!mi.IsStatic && !mi.IsConstructor) { if (args[0].IsList) { invocationTargetList.AddRange(((Value.List)args[0]).Item.Select(x => DynamoTypeConverter.ConvertInput(x, api_base_type))); } else { //the first input will always hold the instance //whose methods you want to invoke invocationTargetList.Add(DynamoTypeConverter.ConvertInput(args[0], api_base_type)); } } } //object result = null; List<object> results = null; //if the method info is for a constructor, then //call the constructor for each set of parameters //if it's an instance method, then invoke the method for //each instance passed in. results = mi.IsConstructor ? parameters.Select(x => ((ConstructorInfo) mi).Invoke(x.ToArray())).ToList() : invocationTargetList.SelectMany(x => parameters.Select(y => mi.Invoke(x, y.ToArray())).ToList()).ToList(); dynRevitUtils.StoreElements(node, results); return ConvertAllResults(results); }