public QueryHistoryPaneViewModel(GlobalQueryHistory globalHistory, IEventAggregator eventAggregator, DocumentViewModel currentDocument, IGlobalOptions options)
 {
     Log.Debug("{class} {method} {message}", "QueryHistoryPaneViewModel", "ctor", "start");
     _globalHistory   = globalHistory;
     _globalOptions   = options;
     _eventAggregator = eventAggregator;
     _eventAggregator.Subscribe(this);
     _queryHistory = new ListCollectionView(globalHistory.QueryHistory);
     //_queryHistory.PageSize = 50;
     CurrentDocument      = currentDocument;
     _queryHistory.Filter = HistoryFilter;
     // sort by StartTime Desc by default
     _queryHistory.SortDescriptions.Add(new SortDescription("StartTime", ListSortDirection.Descending));
     Log.Debug("{class} {method} {message}", "QueryHistoryPaneViewModel", "ctor", "end");
 }
Esempio n. 2
0
        public ShellViewModel(IWindowManager windowManager
                              , IEventAggregator eventAggregator
                              , RibbonViewModel ribbonViewModel
                              , StatusBarViewModel statusBar
                              , IConductor conductor
                              , IDaxStudioHost host
                              , IVersionCheck versionCheck
                              , IGlobalOptions options
                              , IAutoSaver autoSaver
                              , IThemeManager themeManager
                              , GlobalQueryHistory queryHistory
                              )
        {
            Log.Debug(Common.Constants.LogMessageTemplate, nameof(ShellViewModel), "ctor", "Starting Constructor");
            utcSessionStart  = DateTime.UtcNow;
            Ribbon           = ribbonViewModel;
            Ribbon.Shell     = this;
            StatusBar        = statusBar;
            Options          = options;
            AutoSaver        = autoSaver;
            ThemeManager     = themeManager;
            _windowManager   = windowManager;
            _eventAggregator = eventAggregator;
            _eventAggregator.Subscribe(this);
            _queryHistory = queryHistory;
            Tabs          = (DocumentTabViewModel)conductor;
            Tabs.ConductWith(this);
            //Tabs.CloseStrategy = new ApplicationCloseStrategy();
            Tabs.CloseStrategy = IoC.Get <ApplicationCloseAllStrategy>();
            _host     = host;
            _app      = Application.Current;
            _username = UserHelper.GetUser();
            var recoveringFiles = false;

            // get master auto save indexes and only get crashed index files...
            var autoSaveInfo   = AutoSaver.LoadAutoSaveMasterIndex();
            var filesToRecover = autoSaveInfo.Values.Where(idx => idx.IsCurrentVersion && idx.ShouldRecover).SelectMany(entry => entry.Files);

            // check for auto-saved files and offer to recover them
            if (filesToRecover.Any())
            {
                Log.Debug(Common.Constants.LogMessageTemplate, nameof(ShellViewModel), "ctor", "Found autosave files, beginning recovery");
                recoveringFiles = true;
                RecoverAutoSavedFiles(autoSaveInfo);
            }
            else
            {
                // if there are no auto-save files to recover, start the auto save timer
                Log.Debug(Common.Constants.LogMessageTemplate, nameof(ShellViewModel), "ctor", "Starting autosave timer");
                eventAggregator.PublishOnUIThreadAsync(new StartAutoSaveTimerEvent());
            }

            // if a filename was passed in on the command line open it
            if (!string.IsNullOrEmpty(_host.CommandLineFileName))
            {
                Log.Debug(Constants.LogMessageTemplate, nameof(ShellViewModel), "ctor", $"Opening file from command line: '{_host.CommandLineFileName}'");
                Tabs.NewQueryDocument(_host.CommandLineFileName);
            }

            // if no tabs are open at this point and we are not recovering autosave file then, open a blank document
            if (Tabs.Items.Count == 0 && !recoveringFiles)
            {
                Log.Debug(Constants.LogMessageTemplate, nameof(ShellViewModel), "ctor", $"Opening a new blank query window");
                NewDocument();
            }


            VersionChecker = versionCheck;

            DisplayName = AppTitle;

            Application.Current.Activated += OnApplicationActivated;


            AutoSaveTimer          = new Timer(Constants.AutoSaveIntervalMs);
            AutoSaveTimer.Elapsed += new ElapsedEventHandler(AutoSaveTimerElapsed);

            Log.Debug("============ Shell Started - v{version} =============", Version.ToString());
        }