private void LoadAssembliesIntoDynamo(DynamoLoader loader, ILogger logger, LibraryServices libraryServices) { var assemblies = LoadAssembliesInBinDirectory(logger); // filter the assemblies var zeroTouchAssemblies = new List <Assembly>(); var nodeModelAssemblies = new List <Assembly>(); foreach (var assem in assemblies) { if (loader.ContainsNodeModelSubType(assem)) { nodeModelAssemblies.Add(assem); } else { zeroTouchAssemblies.Add(assem); } } // load the zero touch assemblies foreach (var zeroTouchAssem in zeroTouchAssemblies) { libraryServices.ImportLibrary(zeroTouchAssem.Location, logger); } // load the node model assemblies foreach (var nodeModelAssem in nodeModelAssemblies) { var nodes = loader.LoadNodesFromAssembly(nodeModelAssem); nodes.ForEach(x => LoadedTypes.Add(x)); } }
public PackageLoader(DynamoLoader dynamoLoader, ILogger logger, string overridePackageDirectory) { this.loader = dynamoLoader; this.logger = logger; this.RootPackagesDirectory = overridePackageDirectory; if (!Directory.Exists(this.RootPackagesDirectory)) { Directory.CreateDirectory(this.RootPackagesDirectory); } }
private void dynBench_Activated(object sender, EventArgs e) { this.WorkspaceTabs.SelectedIndex = 0; _vm = (DataContext as DynamoViewModel); _vm.RequestLayoutUpdate += vm_RequestLayoutUpdate; _vm.PostUIActivationCommand.Execute(); _timer.Stop(); dynSettings.Controller.DynamoViewModel.Log(string.Format("{0} elapsed for loading Dynamo main window.", _timer.Elapsed)); DynamoLoader.LoadSamplesMenu(dynSettings.Bench); }
/// <summary> /// Class constructor /// </summary> public DynamoController(ExecutionEnvironment env, Type viewModelType, string context, string commandFilePath) { DynamoLogger.Instance.StartLogging(); dynSettings.Controller = this; this.Context = context; //Start heartbeat reporting Services.InstrumentationLogger.Start(); //create the view model to which the main window will bind //the DynamoModel is created therein this.DynamoViewModel = (DynamoViewModel)Activator.CreateInstance( viewModelType, new object[] { this, commandFilePath }); // custom node loader string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string pluginsPath = Path.Combine(directory, "definitions"); CustomNodeManager = new CustomNodeManager(pluginsPath); SearchViewModel = new SearchViewModel(); dynSettings.PackageLoader = new PackageLoader(); dynSettings.PackageLoader.DoCachedPackageUninstalls(); dynSettings.PackageLoader.LoadPackages(); FSchemeEnvironment = env; DynamoViewModel.Model.CurrentWorkspace.X = 0; DynamoViewModel.Model.CurrentWorkspace.Y = 0; DynamoLogger.Instance.Log(String.Format( "Dynamo -- Build {0}", Assembly.GetExecutingAssembly().GetName().Version)); DynamoLoader.ClearCachedAssemblies(); DynamoLoader.LoadBuiltinTypes(); //run tests if (FScheme.RunTests(DynamoLogger.Instance.Log)) { DynamoLogger.Instance.Log("All Tests Passed. Core library loaded OK."); } this.InfoBubbleViewModel = new InfoBubbleViewModel(); AddPythonBindings(); }
public bool RegisterWithHost() { dynSettings.Bench.Dispatcher.BeginInvoke((Action)(() => { dynSettings.PackageLoader.AppendBinarySearchPath(); DynamoLoader.LoadBuiltinTypes(); dynSettings.PackageLoader.AppendCustomNodeSearchPaths(dynSettings.CustomNodeLoader); DynamoLoader.LoadCustomNodes(); })); return(false); }
/// <summary> /// Class constructor /// </summary> public DynamoController(ExecutionEnvironment env, Type viewModelType, string context) { dynSettings.Controller = this; this.Context = context; //Start heartbeat reporting Services.InstrumentationLogger.Start(); //create the view model to which the main window will bind //the DynamoModel is created therein this.DynamoViewModel = (DynamoViewModel)Activator.CreateInstance(viewModelType, new object[] { this }); // custom node loader string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string pluginsPath = Path.Combine(directory, "definitions"); CustomNodeManager = new CustomNodeManager(pluginsPath); SearchViewModel = new SearchViewModel(); PackageManagerClient = new PackageManagerClient(); dynSettings.PackageManagerClient = PackageManagerClient; PublishPackageViewModel = new PublishPackageViewModel(PackageManagerClient); dynSettings.PackageLoader = new PackageLoader(); dynSettings.PackageLoader.DoCachedPackageUninstalls(); dynSettings.PackageLoader.LoadPackages(); FSchemeEnvironment = env; DynamoViewModel.Model.CurrentSpace.X = DynamoView.CANVAS_OFFSET_X; DynamoViewModel.Model.CurrentSpace.Y = DynamoView.CANVAS_OFFSET_Y; dynSettings.Controller.DynamoViewModel.Log(String.Format( "Dynamo -- Build {0}", Assembly.GetExecutingAssembly().GetName().Version)); DynamoLoader.ClearCachedAssemblies(); DynamoLoader.LoadBuiltinTypes(); //run tests if (FScheme.RunTests(dynSettings.Controller.DynamoViewModel.Log)) { dynSettings.Controller.DynamoViewModel.Log("All Tests Passed. Core library loaded OK."); } NodeSubmittedForRendering += new EventHandler(Controller_NodeSubmittedForRendering); NodeRemovedFromRendering += new EventHandler(Controller_NodeRemovedFromRendering); }
public void Load() { try { GetAssemblies().Select(DynamoLoader.LoadNodesFromAssembly).SelectMany(x => x).ToList().ForEach(x => LoadedTypes.Add(x)); DynamoLoader.LoadCustomNodes(CustomNodeDirectory).ForEach(x => LoadedCustomNodes.Add(x)); Loaded = true; } catch (Exception e) { dynSettings.DynamoLogger.Log("Exception when attempting to load package " + this.Name + " from " + this.RootDirectory); dynSettings.DynamoLogger.Log(e.GetType() + ": " + e.Message); } }
public void LoadIntoDynamo(DynamoLoader loader, ILogger logger, LibraryServices libraryServices) { try { this.LoadAssembliesIntoDynamo(loader, logger, libraryServices); this.LoadCustomNodesIntoDynamo(loader); this.EnumerateAdditionalFiles(); Loaded = true; } catch (Exception e) { logger.Log("Exception when attempting to load package " + this.Name + " from " + this.RootDirectory); logger.Log(e.GetType() + ": " + e.Message); } }
private void LoadAssembliesIntoDynamo(DynamoLoader loader, LibraryServices libraryServices, string context) { var assemblies = LoadAssembliesInBinDirectory(); // filter the assemblies var zeroTouchAssemblies = new List <Assembly>(); var nodeModelAssemblies = new List <Assembly>(); // categorize the assemblies to load, skipping the ones that are not identified as node libraries foreach (var assem in assemblies.Where(x => x.IsNodeLibrary).Select(x => x.Assembly)) { if (loader.ContainsNodeModelSubType(assem)) { nodeModelAssemblies.Add(assem); } else { zeroTouchAssemblies.Add(assem); } } // load the zero touch assemblies foreach (var zeroTouchAssem in zeroTouchAssemblies) { libraryServices.ImportLibrary(zeroTouchAssem.Location); } // load the node model assemblies var nodes = nodeModelAssemblies.SelectMany( assem => { var assemblyNodes = new List <TypeLoadData>(); loader.LoadNodesFromAssembly(assem, context, assemblyNodes, new List <TypeLoadData>()); return(assemblyNodes); }); foreach (var node in nodes) { LoadedTypes.Add(node.Type); } }
/// <summary> /// Scan the PackagesDirectory for packages and attempt to load all of them. Beware! Fails silently for duplicates. /// </summary> public void LoadPackagesIntoDynamo( IPreferences preferences, LibraryServices libraryServices, DynamoLoader loader, string context, bool isTestMode, CustomNodeManager customNodeManager) { ScanAllPackageDirectories(preferences); foreach (var pkg in LocalPackages) { DynamoPathManager.Instance.AddResolutionPath(pkg.BinaryDirectory); } foreach (var pkg in LocalPackages) { pkg.LoadIntoDynamo( loader, AsLogger(), libraryServices, context, isTestMode, customNodeManager); } }
/// <summary> /// Load the Package into Dynamo. /// </summary> /// <param name="loader"></param> /// <param name="logger"></param> /// <param name="libraryServices"></param> /// <param name="context"></param> /// <param name="isTestMode"></param> /// <param name="customNodeManager"></param> public void LoadIntoDynamo( DynamoLoader loader, ILogger logger, LibraryServices libraryServices, string context, bool isTestMode, CustomNodeManager customNodeManager) { // Prevent duplicate loads if (Loaded) { return; } try { LoadAssembliesIntoDynamo(loader, libraryServices, context); LoadCustomNodesIntoDynamo(customNodeManager, isTestMode); EnumerateAdditionalFiles(); Loaded = true; } catch (Exception e) { Log("Exception when attempting to load package " + Name + " from " + RootDirectory); Log(e.GetType() + ": " + e.Message); } }
private void LoadCustomNodesIntoDynamo(DynamoLoader loader) { loader.LoadCustomNodes(CustomNodeDirectory).ForEach(x => LoadedCustomNodes.Add(x)); }
/// <summary> /// Class constructor /// </summary> public DynamoController(string context, IUpdateManager updateManager, IWatchHandler watchHandler, IPreferences preferences) { DebugSettings = new DebugSettings(); IsCrashing = false; dynSettings.Controller = this; Context = context; //Start heartbeat reporting InstrumentationLogger.Start(); PreferenceSettings = preferences; ((PreferenceSettings)PreferenceSettings).PropertyChanged += PreferenceSettings_PropertyChanged; SIUnit.LengthUnit = PreferenceSettings.LengthUnit; SIUnit.AreaUnit = PreferenceSettings.AreaUnit; SIUnit.VolumeUnit = PreferenceSettings.VolumeUnit; SIUnit.NumberFormat = PreferenceSettings.NumberFormat; UpdateManager = updateManager; UpdateManager.UpdateDownloaded += updateManager_UpdateDownloaded; UpdateManager.ShutdownRequested += updateManager_ShutdownRequested; UpdateManager.CheckForProductUpdate(new UpdateRequest(new Uri(Configurations.UpdateDownloadLocation), dynSettings.DynamoLogger, UpdateManager.UpdateDataAvailable)); WatchHandler = watchHandler; //create the model DynamoModel = new DynamoModel(); DynamoModel.AddHomeWorkspace(); DynamoModel.CurrentWorkspace = DynamoModel.HomeSpace; DynamoModel.CurrentWorkspace.X = 0; DynamoModel.CurrentWorkspace.Y = 0; // custom node loader string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string pluginsPath = Path.Combine(directory, "definitions"); CustomNodeManager = new CustomNodeManager(pluginsPath); SearchViewModel = new SearchViewModel(); dynSettings.PackageLoader = new PackageLoader(); dynSettings.PackageLoader.DoCachedPackageUninstalls(); dynSettings.PackageLoader.LoadPackages(); DisposeLogic.IsShuttingDown = false; EngineController = new EngineController(this); //This is necessary to avoid a race condition by causing a thread join //inside the vm exec //TODO(Luke): Push this into a resync call with the engine controller ResetEngine(); dynSettings.DynamoLogger.Log(String.Format( "Dynamo -- Build {0}", Assembly.GetExecutingAssembly().GetName().Version)); DynamoLoader.ClearCachedAssemblies(); DynamoLoader.LoadNodeModels(); MigrationManager.Instance.MigrationTargets.Add(typeof(WorkspaceMigrations)); Runner = new DynamoRunner(); }
public PackageLoader(DynamoLoader dynamoLoader, ILogger logger) : this(dynamoLoader, logger, Path.Combine(DynamoPathManager.Instance.MainExecPath, DynamoPathManager.Instance.Packages)) { }
/// <summary> /// Class constructor /// </summary> public DynamoController(ExecutionEnvironment env, Type viewModelType, string context, string commandFilePath, IUpdateManager updateManager, IUnitsManager units, IWatchHandler watchHandler, IPreferences preferences) { DynamoLogger.Instance.StartLogging(); dynSettings.Controller = this; this.Context = context; //Start heartbeat reporting Services.InstrumentationLogger.Start(); PreferenceSettings = preferences; ((PreferenceSettings)PreferenceSettings).PropertyChanged += PreferenceSettings_PropertyChanged; UnitsManager = units; UnitsManager.LengthUnit = PreferenceSettings.LengthUnit; UnitsManager.AreaUnit = PreferenceSettings.AreaUnit; UnitsManager.VolumeUnit = PreferenceSettings.VolumeUnit; UnitsManager.NumberFormat = PreferenceSettings.NumberFormat; UpdateManager = updateManager; UpdateManager.UpdateDownloaded += updateManager_UpdateDownloaded; UpdateManager.ShutdownRequested += updateManager_ShutdownRequested; UpdateManager.CheckForProductUpdate(new UpdateRequest(new Uri(Configurations.UpdateDownloadLocation), DynamoLogger.Instance, UpdateManager.UpdateDataAvailable)); WatchHandler = watchHandler; //create the view model to which the main window will bind //the DynamoModel is created therein this.DynamoViewModel = (DynamoViewModel)Activator.CreateInstance( viewModelType, new object[] { this, commandFilePath }); // custom node loader string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string pluginsPath = Path.Combine(directory, "definitions"); CustomNodeManager = new CustomNodeManager(pluginsPath); SearchViewModel = new SearchViewModel(); dynSettings.PackageLoader = new PackageLoader(); dynSettings.PackageLoader.DoCachedPackageUninstalls(); dynSettings.PackageLoader.LoadPackages(); FSchemeEnvironment = env; DynamoViewModel.Model.CurrentWorkspace.X = 0; DynamoViewModel.Model.CurrentWorkspace.Y = 0; DynamoLogger.Instance.Log(String.Format( "Dynamo -- Build {0}", Assembly.GetExecutingAssembly().GetName().Version)); DynamoLoader.ClearCachedAssemblies(); DynamoLoader.LoadBuiltinTypes(); //run tests if (FScheme.RunTests(DynamoLogger.Instance.Log)) { DynamoLogger.Instance.Log("All Tests Passed. Core library loaded OK."); } this.InfoBubbleViewModel = new InfoBubbleViewModel(); AddPythonBindings(); MigrationManager.Instance.MigrationTargets.Add(typeof(WorkspaceMigrations)); }
public PackageLoader() : this( Path.Combine (DynamoLoader.GetDynamoDirectory(), DefaultRelativePackagesDirectory) ) { }
private List <Type> LoadNodesFromAssembly(Assembly assembly) { if (assembly == null) { throw new ArgumentNullException("assembly"); } var searchViewModel = DynamoViewModel.Model.SearchModel; var types = new List <Type>(); try { var loadedTypes = assembly.GetTypes(); foreach (var t in loadedTypes) { //only load types that are in the right namespace, are not abstract //and have the elementname attribute var attribs = t.GetCustomAttributes(typeof(NodeNameAttribute), false); var isDeprecated = t.GetCustomAttributes(typeof(NodeDeprecatedAttribute), true).Any(); var isMetaNode = t.GetCustomAttributes(typeof(IsMetaNodeAttribute), false).Any(); var isDSCompatible = t.GetCustomAttributes(typeof(IsDesignScriptCompatibleAttribute), true).Any(); bool isHidden = false; var attrs = t.GetCustomAttributes(typeof(IsVisibleInDynamoLibraryAttribute), true); if (null != attrs && attrs.Any()) { var isVisibleAttr = attrs[0] as IsVisibleInDynamoLibraryAttribute; if (null != isVisibleAttr && isVisibleAttr.Visible == false) { isHidden = true; } } if (!DynamoLoader.IsNodeSubType(t) && t.Namespace != "Dynamo.Nodes") /*&& attribs.Length > 0*/ { continue; } //if we are running in revit (or any context other than NONE) //use the DoNotLoadOnPlatforms attribute, //if available, to discern whether we should load this type if (!DynamoViewModel.Model.Context.Equals(Context.NONE)) { object[] platformExclusionAttribs = t.GetCustomAttributes(typeof(DoNotLoadOnPlatformsAttribute), false); if (platformExclusionAttribs.Length > 0) { string[] exclusions = (platformExclusionAttribs[0] as DoNotLoadOnPlatformsAttribute).Values; //if the attribute's values contain the context stored on the controller //then skip loading this type. if (exclusions.Reverse().Any(e => e.Contains(DynamoViewModel.Model.Context))) { continue; } //utility was late for Vasari release, //but could be available with after-post RevitAPI.dll if (t.Name.Equals("dynSkinCurveLoops")) { MethodInfo[] specialTypeStaticMethods = t.GetMethods(BindingFlags.Static | BindingFlags.Public); const string nameOfMethodCreate = "noSkinSolidMethod"; bool exclude = true; foreach (MethodInfo m in specialTypeStaticMethods) { if (m.Name == nameOfMethodCreate) { var argsM = new object[0]; exclude = (bool)m.Invoke(null, argsM); break; } } if (exclude) { continue; } } } } string typeName; if (attribs.Length > 0 && !isDeprecated && !isMetaNode && isDSCompatible && !isHidden) { //searchViewModel.Add(t); typeName = (attribs[0] as NodeNameAttribute).Name; } else { typeName = t.Name; } types.Add(t); var data = new TypeLoadData(t); } } catch (Exception e) { DynamoViewModel.Model.Logger.Log("Could not load types."); DynamoViewModel.Model.Logger.Log(e); } return(types); }