예제 #1
0
        public MainWindow()
        {
            var config = XmlLoggingConfiguration.AppConfig ?? new LoggingConfiguration();

            var observableWriter = new ObservableTextWriter();
            var textWriterTarget = new TextWriterTarget(observableWriter);

            config.AddTarget("Output", textWriterTarget);
            config.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, textWriterTarget));

            LogManager.Configuration = config;

            Log.Info("Initializing application...");

            ServiceLocator.Initialize("RazorPad", "RazorPad.UI", "RazorPad.Core");


            var preferencesLoader = ServiceLocator.Get <IPreferencesService>();
            var preferences       = Preferences.Current = preferencesLoader.Load();

            var modelProviders = ServiceLocator.Get <ModelProviders>();

            ModelProviders.DefaultFactory = modelProviders.GetProviderFactory(preferences.ModelProvider);

            var themeLoader = ServiceLocator.Get <ThemeLoader>();
            var themes      = themeLoader.LoadThemes(preferences.Theme);

            ViewModel = ServiceLocator.Get <MainViewModel>();
            ViewModel.GetReferencesThunk = GetReferences;
            ViewModel.Messages           = observableWriter;
            ViewModel.Preferences        = preferences;
            ViewModel.RecentFiles        = new ObservableSet <string>(preferences.RecentFiles ?? Enumerable.Empty <string>());
            ViewModel.Themes             = new ObservableCollection <Theme>(themes ?? Enumerable.Empty <Theme>());

            ViewModel.RecentFiles.CollectionChanged += (sender, args) =>
                                                       preferences.RecentFiles = ViewModel.RecentFiles.Distinct().ToArray();

            ViewModel.LoadAutoSave();

            var globalNamespaceImports = preferences.GlobalNamespaceImports ?? Enumerable.Empty <string>();

            foreach (var @namespace in globalNamespaceImports)
            {
                RazorPadHost.AddGlobalImport(@namespace);
            }

            // Add a demo template if it's enabled there aren't any templates loaded
            if (preferences.ShowDemoTemplate.GetValueOrDefault(true) && !ViewModel.Templates.Any())
            {
                CreateDemoTemplate();
            }

            InitializeComponent();

            Log.Info("Done initializing");
        }
예제 #2
0
        public RazorTemplateViewModel(RazorDocument document = null, ModelBuilders modelBuilderFactory = null, ModelProviders modelProviders = null)
        {
            _document             = document ?? new RazorDocument();
            _modelBuilderFactory  = modelBuilderFactory;
            _modelProviderFactory = modelProviders;
            _savedModels          = new Dictionary <Type, string>();

            var modelProviderNames = _modelProviderFactory.Providers.Select(x => (string)new ModelProviderFactoryName(x.Value));

            AvailableModelProviders = new ObservableCollection <string>(modelProviderNames);
            _selectedModelProvider  = new ModelProviderName(_document.ModelProvider);

            Errors           = new ObservableCollection <RazorPadError>();
            Messages         = new ObservableTextWriter();
            TemplateCompiler = new TemplateCompiler();

            AttachToModelProviderEvents(_document.ModelProvider);
        }