public void ExtensionsAreExtracted()
        {
            var extensionManager = new ExtensionManager();
            var extensions = extensionManager.ExtensionLoader.LoadDirectory(extensionsPath);
            Assert.Greater(extensions.Count(), 0);

            Assert.AreEqual(extensions.OfType<PackageManagerExtension>().Count(), 1);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Default constructor for DynamoModel
        /// </summary>
        /// <param name="config">Start configuration</param>
        protected DynamoModel(IStartConfiguration config)
        {
            ClipBoard = new ObservableCollection<ModelBase>();

            pathManager = new PathManager(new PathManagerParams
            {
                CorePath = config.DynamoCorePath,
                HostPath = config.DynamoHostPath,
                PathResolver = config.PathResolver
            });

            // Ensure we have all directories in place.
            var exceptions = new List<Exception>();
            pathManager.EnsureDirectoryExistence(exceptions);

            Context = config.Context;
            IsTestMode = config.StartInTestMode;

            var config2 = config as IStartConfiguration2;
            IsHeadless = (config2 != null) ? config2.IsHeadless : false;

            DebugSettings = new DebugSettings();
            Logger = new DynamoLogger(DebugSettings, pathManager.LogDirectory);

            foreach (var exception in exceptions)
            {
                Logger.Log(exception); // Log all exceptions.
            }

            MigrationManager = new MigrationManager(DisplayFutureFileMessage, DisplayObsoleteFileMessage);
            MigrationManager.MessageLogged += LogMessage;
            MigrationManager.MigrationTargets.Add(typeof(WorkspaceMigrations));

            var thread = config.SchedulerThread ?? new DynamoSchedulerThread();
            Scheduler = new DynamoScheduler(thread, config.ProcessMode);
            Scheduler.TaskStateChanged += OnAsyncTaskStateChanged;

            geometryFactoryPath = config.GeometryFactoryPath;

            IPreferences preferences = CreateOrLoadPreferences(config.Preferences);
            var settings = preferences as PreferenceSettings;
            if (settings != null)
            {
                PreferenceSettings = settings;
                PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged;
            }

            InitializeInstrumentationLogger();

            if (!IsTestMode && PreferenceSettings.IsFirstRun)
            {
                DynamoMigratorBase migrator = null;

                try
                {
                    var dynamoLookup = config.UpdateManager != null && config.UpdateManager.Configuration != null
                        ? config.UpdateManager.Configuration.DynamoLookUp : null;

                    migrator = DynamoMigratorBase.MigrateBetweenDynamoVersions(pathManager, dynamoLookup);
                }
                catch (Exception e)
                {
                    Logger.Log(e.Message);
                }

                if (migrator != null)
                {
                    var isFirstRun = PreferenceSettings.IsFirstRun;
                    PreferenceSettings = migrator.PreferenceSettings;

                    // Preserve the preference settings for IsFirstRun as this needs to be set
                    // only by UsageReportingManager
                    PreferenceSettings.IsFirstRun = isFirstRun;
                }
            }
            InitializePreferences(PreferenceSettings);

            // At this point, pathManager.PackageDirectories only has 1 element which is the directory
            // in AppData. If list of PackageFolders is empty, add the folder in AppData to the list since there
            // is no additional location specified. Otherwise, update pathManager.PackageDirectories to include
            // PackageFolders
            if (PreferenceSettings.CustomPackageFolders.Count == 0)
                PreferenceSettings.CustomPackageFolders = new List<string> {pathManager.UserDataDirectory};

            //Make sure that the default package folder is added in the list if custom packages folder.
            var userDataFolder = pathManager.GetUserDataFolder(); //Get the default user data path
            if (Directory.Exists(userDataFolder) && !PreferenceSettings.CustomPackageFolders.Contains(userDataFolder))
            {
                PreferenceSettings.CustomPackageFolders.Add(userDataFolder);
            }

            pathManager.Preferences = PreferenceSettings;


            SearchModel = new NodeSearchModel();
            SearchModel.ItemProduced +=
                node => ExecuteCommand(new CreateNodeCommand(node, 0, 0, true, true));

            NodeFactory = new NodeFactory();
            NodeFactory.MessageLogged += LogMessage;

            CustomNodeManager = new CustomNodeManager(NodeFactory, MigrationManager);
            InitializeCustomNodeManager();

            extensionManager = new ExtensionManager();
            extensionManager.MessageLogged += LogMessage;
            var extensions = config.Extensions ?? LoadExtensions();

            Loader = new NodeModelAssemblyLoader();
            Loader.MessageLogged += LogMessage;

            // Create a core which is used for parsing code and loading libraries
            var libraryCore = new ProtoCore.Core(new Options());

            libraryCore.Compilers.Add(Language.Associative, new Compiler(libraryCore));
            libraryCore.Compilers.Add(Language.Imperative, new ProtoImperative.Compiler(libraryCore));
            libraryCore.ParsingMode = ParseMode.AllowNonAssignment;

            LibraryServices = new LibraryServices(libraryCore, pathManager, PreferenceSettings);
            LibraryServices.MessageLogged += LogMessage;
            LibraryServices.LibraryLoaded += LibraryLoaded;

            ResetEngineInternal();

            AddHomeWorkspace();

            AuthenticationManager = new AuthenticationManager(config.AuthProvider);

            UpdateManager = config.UpdateManager ?? new DefaultUpdateManager(null);

            // config.UpdateManager has to be cast to IHostUpdateManager in order to extract the HostVersion and HostName
            // see IHostUpdateManager summary for more details 
            var hostUpdateManager = config.UpdateManager as IHostUpdateManager;
          
            if (hostUpdateManager != null)
            {
                HostName = hostUpdateManager.HostName;
                HostVersion = hostUpdateManager.HostVersion == null ? null : hostUpdateManager.HostVersion.ToString();
            }
            else
            {
                HostName = string.Empty;
                HostVersion = null;
            }
            
            UpdateManager.Log += UpdateManager_Log;
            if (!IsTestMode && !IsHeadless)
            {
                DefaultUpdateManager.CheckForProductUpdate(UpdateManager);
            }

            Logger.Log(string.Format("Dynamo -- Build {0}",
                                        Assembly.GetExecutingAssembly().GetName().Version));

            InitializeNodeLibrary(PreferenceSettings);

            if (extensions.Any())
            {
                var startupParams = new StartupParams(config.AuthProvider,
                    pathManager, new ExtensionLibraryLoader(this), CustomNodeManager,
                    GetType().Assembly.GetName().Version, PreferenceSettings);

                foreach (var ext in extensions)
                {
                    var logSource = ext as ILogSource;
                    if (logSource != null)
                        logSource.MessageLogged += LogMessage;

                    try
                    {
                        ext.Startup(startupParams);
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(ex.Message);
                    }

                    ExtensionManager.Add(ext);
                }
            }

            LogWarningMessageEvents.LogWarningMessage += LogWarningMessage;

            StartBackupFilesTimer();

            TraceReconciliationProcessor = this;

            foreach (var ext in ExtensionManager.Extensions)
            {
                try
                {
                    ext.Ready(new ReadyParams(this));
                }
                catch (Exception ex)
                {
                    Logger.Log(ex.Message);
                }
            }
        }
Exemplo n.º 3
0
        protected DynamoModel(IStartConfiguration config)
        {
            ClipBoard = new ObservableCollection<ModelBase>();

            pathManager = new PathManager(new PathManagerParams
            {
                CorePath = config.DynamoCorePath,
                PathResolver = config.PathResolver
            });

            // Ensure we have all directories in place.
            pathManager.EnsureDirectoryExistence();

            Context = config.Context;
            IsTestMode = config.StartInTestMode;
            DebugSettings = new DebugSettings();
            Logger = new DynamoLogger(DebugSettings, pathManager.LogDirectory);

            MigrationManager = new MigrationManager(DisplayFutureFileMessage, DisplayObsoleteFileMessage);
            MigrationManager.MessageLogged += LogMessage;
            MigrationManager.MigrationTargets.Add(typeof(WorkspaceMigrations));

            var thread = config.SchedulerThread ?? new DynamoSchedulerThread();
            Scheduler = new DynamoScheduler(thread, IsTestMode);
            Scheduler.TaskStateChanged += OnAsyncTaskStateChanged;

            geometryFactoryPath = config.GeometryFactoryPath;

            IPreferences preferences = CreateOrLoadPreferences(config.Preferences);
            var settings = preferences as PreferenceSettings;
            if (settings != null)
            {
                PreferenceSettings = settings;
                PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged;
            }

            InitializePreferences(preferences);
            InitializeInstrumentationLogger();

            if (!isTestMode && this.PreferenceSettings.IsFirstRun)
            {
                DynamoMigratorBase migrator = null;

                try
                {
                    migrator = DynamoMigratorBase.MigrateBetweenDynamoVersions(pathManager, config.PathResolver);
                }
                catch (Exception e)
                {
                    Logger.Log(e.Message);
                }

                if (migrator != null)
                {
                    var isFirstRun = this.PreferenceSettings.IsFirstRun;
                    this.PreferenceSettings = migrator.PreferenceSettings;

                    // Preserve the preference settings for IsFirstRun as this needs to be set 
                    // only by UsageReportingManager
                    this.PreferenceSettings.IsFirstRun = isFirstRun;
                }
            }

            SearchModel = new NodeSearchModel();
            SearchModel.ItemProduced +=
                node => ExecuteCommand(new CreateNodeCommand(node, 0, 0, true, true));

            NodeFactory = new NodeFactory();
            NodeFactory.MessageLogged += LogMessage;

            CustomNodeManager = new CustomNodeManager(NodeFactory, MigrationManager);
            InitializeCustomNodeManager();

            extensionManager = new ExtensionManager();
            extensionManager.MessageLogged += LogMessage;
            var extensions = config.Extensions ?? ExtensionManager.ExtensionLoader.LoadDirectory(pathManager.ExtensionsDirectory);

            if (extensions.Any())
            {
                var startupParams = new StartupParams(config.AuthProvider,
                    pathManager, CustomNodeManager);

                foreach (var ext in extensions)
                {
                    ext.Startup(startupParams);
                    ext.Load(preferences, pathManager);
                    ext.RequestLoadNodeLibrary += LoadNodeLibrary;
                    ExtensionManager.Add(ext);
                }
            }

            Loader = new NodeModelAssemblyLoader();
            Loader.MessageLogged += LogMessage;

            DisposeLogic.IsShuttingDown = false;

            // Create a core which is used for parsing code and loading libraries
            var libraryCore =
                new ProtoCore.Core(new Options { RootCustomPropertyFilterPathName = string.Empty });

            libraryCore.Compilers.Add(Language.kAssociative, new Compiler(libraryCore));
            libraryCore.Compilers.Add(Language.kImperative, new ProtoImperative.Compiler(libraryCore));
            libraryCore.ParsingMode = ParseMode.AllowNonAssignment;

            LibraryServices = new LibraryServices(libraryCore, pathManager);
            LibraryServices.MessageLogged += LogMessage;
            LibraryServices.LibraryLoaded += LibraryLoaded;

            ResetEngineInternal();

            AddHomeWorkspace();

            AuthenticationManager = new AuthenticationManager(config.AuthProvider);

            UpdateManager = config.UpdateManager ?? new DefaultUpdateManager(null);
            UpdateManager.Log += UpdateManager_Log;
            if (!IsTestMode)
            {
                DefaultUpdateManager.CheckForProductUpdate(UpdateManager);
            }
            
            Logger.Log(string.Format("Dynamo -- Build {0}", 
                                        Assembly.GetExecutingAssembly().GetName().Version));

            InitializeNodeLibrary(preferences);

            LogWarningMessageEvents.LogWarningMessage += LogWarningMessage;

            StartBackupFilesTimer();

            TraceReconciliationProcessor = this; 
            
            foreach (var ext in ExtensionManager.Extensions)
            {
                try
                {
                    ext.Ready(new ReadyParams());
                }
                catch (Exception ex)
                {
                    Logger.Log(ex.Message);
                }
            }
        }