public void Initialize(string rootPath, ITheUserExperience userExperience = null) { var pluginPath = Path.Combine(rootPath, ConfigurationManager.AppSettings.Get("PlgDir")); var pluginRepositoryPath = Path.Combine(rootPath, ConfigurationManager.AppSettings.Get("PginRepoPath")); var pluginPickerPath = Path.Combine(rootPath, ConfigurationManager.AppSettings.Get("PluginPickerDirectory")); var theUserExperienceDirectory = Path.Combine(rootPath, ConfigurationManager.AppSettings.Get("UsrExpDir")); // Find The User Experience if available var theUserExperience = Utilities.GetTheUserExperience(theUserExperienceDirectory); // Find Repository factories available... var repositoryFactories = Utilities.GetPluginRepositoryFactories(pluginRepositoryPath); // ... if there are none, then use the fail safe, otherwise pick a random one to use if (repositoryFactories.Length == 0) repositoryFactories = new IPluginRepositoryFactory[] { new FailsafePluginRepositoryFactory() }; if (repositoryFactories.Length == 1) PluginRepository = repositoryFactories[0].GetRepository(); else { var selectedIndex = new Random().Next(pluginRepositoryPath.Length); PluginRepository = repositoryFactories[selectedIndex].GetRepository(); } theUserExperience.Show(); }
private void Load() { // Show Title (give time for it to all sink in) Dispatcher.Invoke(_onShowStoryboard, _titleSplosion); Thread.Sleep(1340); Dispatcher.Invoke(_onShowStoryboard, _showSubtitle); // Figure stuff out... ReceiveMessage("Delving into user settings"); var args = System.Environment.GetCommandLineArgs(); var rootPath = Path.GetDirectoryName(args[0]); if (rootPath == null) { // Not really sure what to do here, but these steps usually work for me ReceiveMessage( "Woops! Uknown Error: Using the list below, proceed to the next item if the previus item does not correct the problem\n" + "1) Restart application\n" + "2) Reinstall application\n" + "3) Reboot computer\n" + "4) Reinstall Windows\n" + "5) Purchase new computer :( \n", 1005); } else { var pluginPath = MethodsAndStuff.GetPath(ConfigurationManager.AppSettings.Get("PlgDir")); var pluginRepositoryPath = MethodsAndStuff.GetPath(ConfigurationManager.AppSettings.Get("PginRepoPath")); var pluginPickerPath = MethodsAndStuff.GetPath(ConfigurationManager.AppSettings.Get("PluginPickerDirectory")); // Find Repository factories available... ReceiveMessage("Finding Repository Factories..."); var repositoryFactories = Utilities.GetPluginRepositoryFactories(pluginRepositoryPath); // ... if there are none, then use the fail safe, otherwise pick a random one to use ReceiveMessage("Building Repository..."); if (repositoryFactories.Length == 0) repositoryFactories = new IPluginRepositoryFactory[] {new FailsafePluginRepositoryFactory()}; if (repositoryFactories.Length == 1) Engine.PluginRepositoryFactory = repositoryFactories[0]; else { // For multiple repository factories, randomly choose one to be the // one we use for this go-around var selectedIndex = Engine.Randomizer.Randomize(repositoryFactories.Length); Engine.PluginRepositoryFactory = repositoryFactories[selectedIndex]; } // Calculate the number of plugins so that the message can be "smart" int pluginCount = Engine.PluginRepository.Plugins.Length; ReceiveMessage(string.Format("Retrieving {0} Plugins...", pluginCount)); // This is a clever trick I discovered on the internet: the plugin collection // can be preloaded here simply by being accessed for the first time! By doing // this here during the loading step, we can save time in the longrun var deleteMe = Engine.PluginRepository.Plugins; } //close the window this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { Close(); }); }