Пример #1
0
        public SettingsViewModel(IMessageBus bus, ISettingsLoader loader, ISettingsSaver saver)
        {
            SettingsCommand = new ReactiveCommand();
            bus.RegisterMessageSource(SettingsCommand.Select(_ => new NavigateMainModuleMessage(ModuleNames.SettingsModule)));
            BackCommand = new ReactiveCommand();
            bus.RegisterMessageSource(BackCommand.Select(_ => new NavigateBackMainModuleMessage()));

            var settings = loader.Load();

            SettingsViewModels = new ISettingsSubPage[] {
                new GeneralSettingsViewModel(settings.General),
                new NetworkSettingsViewModel(settings.Network),
                new NotificationSettingsViewModel(settings.Notification),
                new AboutViewModel(),
            };

            SelectedPage = SettingsViewModels.First();

            bus.RegisterMessageSource(bus.Listen <NavigateSettingsPageMessage>().Do(
                                          msg => SelectedPage = SettingsViewModels.First(vm => vm.GetType().Name.StartsWith(msg.SettingsPage)))
                                      .Select(_ => new NavigateMainModuleMessage(ModuleNames.SettingsModule)));

            SaveCommand = new ReactiveCommand();
            bus.RegisterMessageSource(
                SaveCommand.Do(_ => CommitViewModels()).Do(_ => saver.Save(settings)).Select(_ => new NavigateBackMainModuleMessage()));
        }
Пример #2
0
 public SettingsViewModel(IOptions <WindowSettings> settings, IMainWindowViewModel mainWindowViewModel, ISettingsSaver settingsSaver)
 {
     this.settings       = settings;
     MainWindowViewModel = mainWindowViewModel;
     this.settingsSaver  = settingsSaver;
     mainWindowViewModel.WindowSettings = new WindowSettings();
     CopyWindowSettings(WindowSettings, NewSettings);
 }
Пример #3
0
 public NotepadPresenter(ITextSaver textSaver, ISettingsSaver settingsSaver, INotepadView notepadView)
 {
     _isNew         = true;
     _textSaver     = textSaver;
     _settingsSaver = settingsSaver;
     _notepadView   = notepadView;
     _content       = new Content();
     Plugins        = new Dictionary <string, MethodInfo>();
     LoadSettings();
 }
Пример #4
0
 void IPropellerModule.Init(LoggerBase log, JsonValue settings, ISettingsSaver saver)
 {
     SettingsSaver = saver;
     Log           = log;
     try
     {
         Settings = ClassifyJson.Deserialize <TSettings>(settings) ?? new TSettings();
     }
     catch (Exception e)
     {
         Log.Exception(e);
         Settings = new TSettings();
     }
     SaveSettings();
     Init();
 }
Пример #5
0
        public Game(
            IHighLevelEventsService highLevelEventsService,
            IReaderService readerService,
            IWriterService writerService,
            ISettingsSaver settingsSaver,
            INewPointFactory newPointFactory,
            ILoadSettingsStrategyFactory loadSettingsStrategyFactory)
        {
            _highLevelEventsService      = highLevelEventsService;
            _readerService               = readerService;
            _writerService               = writerService;
            _settingsSaver               = settingsSaver;
            _newPointFactory             = newPointFactory;
            _loadSettingsStrategyFactory = loadSettingsStrategyFactory;

            _highLevelEventsService.SpaceBarPressed += PauseResume;
            _highLevelEventsService.Save            += Save;
            _highLevelEventsService.Exit            += Exit;
            _highLevelEventsService.Move            += Move;
        }
        public EmailBasedLogin(IDialogService dialogService)
        {
            settings = new SettingsSaver(this, ApplicationData.Current.RoamingSettings);

            LoginCommand = ReactiveCommand.CreateFromTask(() => RetrieveCredentials(Email, Password));
            LoginCommand.ThrownExceptions.Subscribe(x =>
            {
                VerifiedUsername = null;
                VerifiedPassword = null;
            });

            LoginCommand.ThrownExceptions.MessageOnException(dialogService);

            LoginCommand.Subscribe(x =>
            {
                VerifiedUsername = x.Username;
                VerifiedPassword = x.Password;
            });

            retriever = new CredentialRetriever(new Uri("https://accounts.parrot.com/V3/logform"));

            isLogged = this.WhenAnyValue(x => x.VerifiedUsername, x => x.VerifiedPassword,
                                         selector: (a, b) => a != null || b != null).ToProperty(this, x => x.IsLogged);
        }
Пример #7
0
 public UserBasedLogin()
 {
     settings = new SettingsSaver(this, ApplicationData.Current.RoamingSettings);
 }
Пример #8
0
        public MainWindow(ISettingsLoader settingsLoader, ISettingsSaver settingsSaver, ICommandLoader commandLoader,
                          IProgramListLoader programListLoader)
        {
            if (settingsLoader == null)
            {
                throw new ArgumentNullException(nameof(settingsLoader));
            }
            if (commandLoader == null)
            {
                throw new ArgumentNullException(nameof(commandLoader));
            }
            if (programListLoader == null)
            {
                throw new ArgumentNullException(nameof(programListLoader));
            }
            _settingsSaver = settingsSaver ?? throw new ArgumentNullException(nameof(settingsSaver));

            _validCommands    = new Dictionary <string, Command>(StringComparer.CurrentCultureIgnoreCase);
            _autocompleteList = new List <string>();
            _programPaths     = new Dictionary <string, string>(StringComparer.CurrentCultureIgnoreCase);
            //_programList = new List<string>();

            InitializeComponent();
            Activated           += CommandTb_GotFocus;
            Deactivated         += CommandTb_LostFocus;
            CommandTb.GotFocus  += CommandTb_GotFocus;
            CommandTb.LostFocus += CommandTb_LostFocus;

            try
            {
                _fUiSettings = settingsLoader.LoadSettings();
            }
            catch (SettingsLoadException e)
            {
                MessageBox.Show(
                    "Couldn't load the config/settings.json file, is it valid JSON? Re-download it or fix any JSON formatting errors.\nException: " +
                    e.BuildException());
                Application.Current.Shutdown();
            }

            foreach (var toAdd in commandLoader.GetCommands(_fUiSettings))
            {
                try
                {
                    _validCommands.Add(toAdd.Name, toAdd);
                    _autocompleteList.Add(toAdd.Name);
                }
                catch (CommandLoadException e)
                {
                    MessageBox.Show("Unable to load command.\nException is: " + e.BuildException());
                    CommandError();
                }
            }

            foreach (var cmd in _fUiSettings.Commands)
            {
                _validCommands.Add(cmd.Name, cmd);
                _autocompleteList.Add(cmd.Name);
            }

            foreach (var program in programListLoader.GetProgramList())
            {
                _programPaths[Path.GetFileNameWithoutExtension(program).Trim()] = program;
                _autocompleteList.Add(Path.GetFileNameWithoutExtension(program).Trim());
            }
        }
Пример #9
0
        void IPropellerModule.Init(LoggerBase log, JsonValue settings, ISettingsSaver saver)
        {
            _log      = log;
            _saver    = saver;
            _settings = ClassifyJson.Deserialize <Settings>(settings) ?? new Settings();

            var validPaths = new List <string>();

            foreach (var path in _settings.Paths)
            {
                if (!Directory.Exists(path))
                {
                    _log.Warn(@"DocGen: Warning: The folder ""{0}"" specified in the settings does not exist. Ignoring path.".Fmt(path));
                }
                else
                {
                    validPaths.Add(path);
                }
            }
            _settings.Paths = validPaths.ToArray();

            saver.SaveSettings(ClassifyJson.Serialize(_settings));

            string copyToPath = null;

            if (_settings.DllTempPath != null)
            {
                // Try to clean up old folders we've created before
                var tempPath = _settings.DllTempPath;
                Directory.CreateDirectory(tempPath);
                foreach (var path in Directory.GetDirectories(tempPath, "docgen-tmp-*"))
                {
                    try { Directory.Delete(path, true); }
                    catch { }
                }

                // Find a new folder to put the DLL files into
                int j = 1;
                copyToPath = Path.Combine(tempPath, "docgen-tmp-" + j);
                while (Directory.Exists(copyToPath))
                {
                    j++;
                    copyToPath = Path.Combine(tempPath, "docgen-tmp-" + j);
                }
                Directory.CreateDirectory(copyToPath);
            }

            _docGen = new DocumentationGenerator(_settings.Paths, _settings.RequireAuthentication ? _settings.UsernamePasswordFile ?? "" : null, copyToPath);
            lock (_log)
            {
                _log.Info("DocGen initialised with {0} assemblies: {1}".Fmt(_docGen.AssembliesLoaded.Count, _docGen.AssembliesLoaded.JoinString(", ")));
                if (_docGen.AssemblyLoadErrors.Count > 0)
                {
                    _log.Warn("{0} assembly load errors:".Fmt(_docGen.AssemblyLoadErrors.Count));
                    foreach (var tuple in _docGen.AssemblyLoadErrors)
                    {
                        _log.Warn("{0} error: {1}".Fmt(tuple.Item1, tuple.Item2));
                    }
                }
            }
        }
Пример #10
0
        private static int _appDomainCount = 0;     // only used to give each AppDomain a unique name

        public AppDomainInfo(LoggerBase log, PropellerSettings settings, PropellerModuleSettings moduleSettings, ISettingsSaver saver)
        {
            ModuleSettings     = moduleSettings;
            Saver              = saver;
            _log               = log;
            _activeConnections = 0;

            // Determine the temporary folder that DLLs will be copied to
            var tempFolder = settings.TempFolder ?? Path.GetTempPath();

            Directory.CreateDirectory(tempFolder);

            // Find a new folder to put the DLL/EXE files into
            int j = 1;

            do
            {
                TempPathUsed = Path.Combine(tempFolder, "propeller-tmp-" + (j++));
            }while (Directory.Exists(TempPathUsed));
            Directory.CreateDirectory(TempPathUsed);

            // Copy all the DLLs/EXEs to the temporary folder
            foreach (var sourceFile in
                     new[] { typeof(PropellerEngine), typeof(IPropellerModule), typeof(HttpServer), typeof(Ut) }.Select(type => type.Assembly.Location).Concat(
                         new[] { "*.exe", "*.dll", "*.pdb" }.SelectMany(ext => Directory.EnumerateFiles(Path.GetDirectoryName(moduleSettings.ModuleDll), ext))))
            {
                var destFile = Path.Combine(TempPathUsed, Path.GetFileName(sourceFile));
                if (File.Exists(destFile))
                {
                    _log.Warn(2, "Skipping file {0} because destination file {1} already exists.".Fmt(sourceFile, destFile));
                }
                else
                {
                    _log.Info(2, "Copying file {0} to {1}".Fmt(sourceFile, destFile));
                    File.Copy(sourceFile, destFile);
                }
            }

            // Create an AppDomain
            var setup = new AppDomainSetup {
                ApplicationBase = TempPathUsed, PrivateBinPath = TempPathUsed
            };

            AppDomain   = AppDomain.CreateDomain("Propeller AppDomain #{0}, module {1}".Fmt(_appDomainCount++, moduleSettings.ModuleName), null, setup);
            RunnerProxy = (AppDomainRunner)AppDomain.CreateInstanceAndUnwrap("Propeller", "RT.Propeller.AppDomainRunner");
            RunnerProxy.Init(
                Path.Combine(TempPathUsed, Path.GetFileName(moduleSettings.ModuleDll)),
                moduleSettings.ModuleType,
                moduleSettings.ModuleName,
                moduleSettings.Settings,
                _log,
                saver);

            IEnumerable <string> filters = moduleSettings.MonitorFilters ?? Enumerable.Empty <string>();

            if (RunnerProxy.FileFiltersToBeMonitoredForChanges != null)
            {
                filters = filters.Concat(RunnerProxy.FileFiltersToBeMonitoredForChanges);
            }
            foreach (var filter in filters.Concat(moduleSettings.ModuleDll))
            {
                addFileSystemWatcher(Path.GetDirectoryName(filter), Path.GetFileName(filter));
            }

            UrlMappings = moduleSettings.Hooks.Select(hook => new UrlMapping(hook, Handle, true)).ToArray();

            _log.Info("Module {0} URLs: {1}".Fmt(moduleSettings.ModuleName, moduleSettings.Hooks.JoinString("; ")));
        }
Пример #11
0
        public void Init(string modulePath, string moduleClrType, string moduleName, JsonValue moduleSettings, LoggerBase log, ISettingsSaver saver)
        {
            _log        = log;
            _moduleName = moduleName;

            var  assembly = Assembly.LoadFile(modulePath);
            Type moduleType;

            if (moduleClrType != null)
            {
                moduleType = Type.GetType(moduleClrType);
                if (moduleType == null)
                {
                    throw new ModuleInitializationException("The specified CLR type {0} is invalid.".Fmt(moduleClrType));
                }
            }
            else
            {
                var candidates = assembly.GetExportedTypes().Where(type => typeof(IPropellerModule).IsAssignableFrom(type) && !type.IsAbstract).Take(2).ToArray();
                if (candidates.Length == 0)
                {
                    throw new ModuleInitializationException("The file {0} does not contain a Propeller module.".Fmt(modulePath));
                }
                else if (candidates.Length == 2)
                {
                    throw new ModuleInitializationException("The file {0} contains multiple Propeller modules ({1} and {2}). Specify the desired module type explicitly.".Fmt(modulePath, candidates[0].FullName, candidates[1].FullName));
                }
                moduleType = candidates[0];
            }

            _module = (IPropellerModule)Activator.CreateInstance(moduleType);
            _module.Init(log, moduleSettings, saver);
        }
Пример #12
0
 public NotifyIconViewModel(IOptions <WindowSettings> options, ISettingsSaver settingsSaver, IServiceProvider serviceProvider)
 {
     this.options         = options;
     this.settingsSaver   = settingsSaver;
     this.serviceProvider = serviceProvider;
 }