/// <summary>
        /// Loads PreferenceSettings from specified XML file if possible,
        /// else initialises PreferenceSettings with default values.
        /// </summary>
        /// <param name="filePath">Path of the XML File</param>
        /// <returns>
        /// Stored PreferenceSettings from xml file or
        /// Default PreferenceSettings if xml file is not found.
        /// </returns>
        public static PreferenceSettings Load(string filePath)
        {
            var settings = new PreferenceSettings();

            if (String.IsNullOrEmpty(filePath) || (!File.Exists(filePath)))
            {
                return(settings);
            }

            try
            {
                var serializer = new XmlSerializer(typeof(PreferenceSettings));
                using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    settings = serializer.Deserialize(fs) as PreferenceSettings;
                    fs.Close(); // Release file lock
                }
            }
            catch (Exception) { }

            settings.CustomPackageFolders = settings.CustomPackageFolders.Distinct().ToList();
            MigrateStdLibTokenToBuiltInToken(settings);

            return(settings);
        }
 public PackageValidationTest()
 {
     dynamoSettings = new PreferenceSettings()
     {
         CustomPackageFolders = new List<string>()
         {
             Path.Combine(TestDirectory, @"core\userdata\0.8")
         }
     };
 }
Example #3
0
 //migrate old path token to new path token
 private static void MigrateStdLibTokenToBuiltInToken(PreferenceSettings settings)
 {
     for (var i = 0; i < settings.CustomPackageFolders.Count; i++)
     {
         var path = settings.CustomPackageFolders[i];
         if (path == DynamoModel.StandardLibraryToken)
         {
             settings.CustomPackageFolders[i] = DynamoModel.BuiltInPackagesToken;
         }
     }
 }
        public override void Setup()
        {
            base.Setup();
            var settings = new PreferenceSettings();
            var parentFolder = Path.Combine(TestDirectory, "pkgs", "multiple_locations");
            settings.CustomPackageFolders = new List<string>
            {
                Path.Combine(parentFolder, "folder1"),
                @"C:\folder_name_with_invalid_:*?|_characters\foobar",
                @"C:\this_folder_doesn't_exist",
                Path.Combine(parentFolder, "folder2"),
                @"X:\this_drive_doesn't_exist",
                @"\\unreachable_machine\share_packages",
                Path.Combine(parentFolder, "folder3")
            };

            var settingFilePath = Path.Combine(TempFolder, "DynamoSettings.xml");
            settings.Save(settingFilePath);

            var settingsLoadedFromFile = PreferenceSettings.Load(settingFilePath);

            StartDynamo(settingsLoadedFromFile);
        }
Example #5
0
        public override void Setup()
        {
            base.Setup();

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

            var pathResolver = new TestPathResolver();
            pathResolver.AddPreloadLibraryPath("DSCoreNodes.dll");

            var pathManager = new PathManager(new PathManagerParams
            {
                PathResolver = pathResolver
            });

            var settings = new PreferenceSettings();

            libraryServices = new LibraryServices(libraryCore, pathManager, settings);

            RegisterEvents();
        }
Example #6
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);
                }
            }
        }
        /// <summary>
        /// Return PreferenceSettings from XML path if possible,
        /// else return PreferenceSettings with default values
        /// </summary>
        /// <param name="filePath">Path of the XML File</param>
        /// <returns>
        /// Stored PreferenceSettings from xml file or
        /// Default PreferenceSettings if xml file is not found.
        /// </returns>
        public static PreferenceSettings Load(string filePath)
        {
            var settings = new PreferenceSettings();

            if (String.IsNullOrEmpty(filePath) || (!File.Exists(filePath)))
                return settings;

            try
            {
                var serializer = new XmlSerializer(typeof(PreferenceSettings));
                using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    settings = serializer.Deserialize(fs) as PreferenceSettings;
                    fs.Close(); // Release file lock
                }
            }
            catch (Exception) { }

            settings.CustomPackageFolders = settings.CustomPackageFolders.Distinct().ToList();

            return settings;
        }
Example #8
0
        public void PreferenceSettings_ShowEdges_Save()
        {
            // Test if variable can be serialize and deserialize without any issue
            string tempPath = System.IO.Path.GetTempPath();
            tempPath = Path.Combine(tempPath, "userPreference.xml");

            var initalSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            initalSetting.ShowEdges = true;
            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);
            Assert.True(resultSetting.ShowEdges);
        }
Example #9
0
 public void PreferenceSettings_ShowEdges_DefaultFalse()
 {
     var settings = new PreferenceSettings();
     Assert.False(settings.ShowEdges);
 }
Example #10
0
        public void PreferenceSetting()
        {
            // Test Case to ensure that the link for these persistent variable
            // between DynamoViewModel, Model is not broken or replaced.
            #region BackgroundPreviewActive
            bool expectedValue = !ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive;
            ViewModel.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive);

            expectedValue = !ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive;
            ViewModel.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive);
            #endregion

            #region ConsoleHeight
            int expectedHeight = 100; ;
            ViewModel.ToggleConsoleShowing(null);
            Assert.AreEqual(expectedHeight, ViewModel.Model.PreferenceSettings.ConsoleHeight);

            expectedHeight = 0;
            ViewModel.ToggleConsoleShowing(null);
            Assert.AreEqual(expectedHeight, ViewModel.Model.PreferenceSettings.ConsoleHeight);
            #endregion

            #region ConnectorType
            ConnectorType expectedConnector = ConnectorType.BEZIER;
            ViewModel.SetConnectorType("BEZIER");
            Assert.AreEqual(expectedConnector, ViewModel.Model.PreferenceSettings.ConnectorType);

            expectedConnector = ConnectorType.POLYLINE;
            ViewModel.SetConnectorType("POLYLINE");
            Assert.AreEqual(expectedConnector, ViewModel.Model.PreferenceSettings.ConnectorType);
            #endregion

            #region Collect Information Option
            {
                // Backup the value of Dynamo.IsTestMode and restore it later. The 
                // reason for this is 'IsUsageReportingApproved' only returns the 
                // actual value when not running in test mode.
                var isTestMode = DynamoModel.IsTestMode;

                // First time run, check if dynamo did set it back to false after running
                Assert.AreEqual(false, UsageReportingManager.Instance.FirstRun);

                // CollectionInfoOption To TRUE
                UsageReportingManager.Instance.SetUsageReportingAgreement(true);
                RestartTestSetup(startInTestMode: false);
                Assert.AreEqual(true, UsageReportingManager.Instance.IsUsageReportingApproved);

                // CollectionInfoOption To FALSE
                UsageReportingManager.Instance.SetUsageReportingAgreement(false);
                RestartTestSetup(startInTestMode: false);
                Assert.AreEqual(false, UsageReportingManager.Instance.IsUsageReportingApproved);

                DynamoModel.IsTestMode = isTestMode; // Restore the orignal value.
            }
            #endregion

            #region Save And Load of PreferenceSettings
            // Test if variable can be serialize and deserialize without any issue
            string tempPath = System.IO.Path.GetTempPath();
            tempPath = Path.Combine(tempPath, "userPreference.xml");

            // Force inital state
            PreferenceSettings initalSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            #region First Test

            initalSetting.ConnectorType = ConnectorType.BEZIER;
            initalSetting.ConsoleHeight = 100;
            initalSetting.IsBackgroundPreviewActive = true;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.IsBackgroundPreviewActive, initalSetting.IsBackgroundPreviewActive);
            Assert.AreEqual(resultSetting.ConnectorType, initalSetting.ConnectorType);
            Assert.AreEqual(resultSetting.ConsoleHeight, initalSetting.ConsoleHeight);
            #endregion

            #region Second Test
            initalSetting.ConnectorType = ConnectorType.POLYLINE;
            initalSetting.ConsoleHeight = 0;
            initalSetting.IsBackgroundPreviewActive = false;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.IsBackgroundPreviewActive, initalSetting.IsBackgroundPreviewActive);
            Assert.AreEqual(resultSetting.ConnectorType, initalSetting.ConnectorType);
            Assert.AreEqual(resultSetting.ConsoleHeight, initalSetting.ConsoleHeight);
            #endregion

            #endregion

            View.Close();
        }
Example #11
0
        public void PreferenceSetting_BackgroundPreview_1_0API()
        {
            bool expectedValue = !ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive;
            ViewModel.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive);
          

            expectedValue = !ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive;
            ViewModel.ToggleFullscreenWatchShowing(null);
            Assert.AreEqual(expectedValue, ViewModel.Model.PreferenceSettings.IsBackgroundPreviewActive);

            #region Save And Load of PreferenceSettings

            // Test if variable can be serialize and deserialize without any issue
            string tempPath = System.IO.Path.GetTempPath();
            tempPath = Path.Combine(tempPath, "userPreference.xml");

            // Force inital state
            PreferenceSettings initalSetting = new PreferenceSettings();
            PreferenceSettings resultSetting;

            initalSetting.IsBackgroundPreviewActive = true;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.IsBackgroundPreviewActive, initalSetting.IsBackgroundPreviewActive);
            #endregion

            #region Second Test
            initalSetting.IsBackgroundPreviewActive = false;

            initalSetting.Save(tempPath);
            resultSetting = PreferenceSettings.Load(tempPath);

            Assert.AreEqual(resultSetting.IsBackgroundPreviewActive, initalSetting.IsBackgroundPreviewActive);
            #endregion
        }