Пример #1
0
        public void LoadSession(ICoreWorkspace workspace, string fileFullPath)
        {
            using (var progress = _progressManager.Create())
            {
                progress.Initialize(5);
                progress.IncrementProgress(PKSimConstants.UI.OpeningProjectDatabase);

                verifyProjectNotReadOnly(fileFullPath);
                _databaseSchemaMigrator.MigrateSchema(fileFullPath);

                try
                {
                    _sessionManager.OpenFactoryFor(fileFullPath);

                    using (var session = _sessionManager.OpenSession())
                        using (session.BeginTransaction())
                        {
                            progress.IncrementProgress(PKSimConstants.UI.LoadingHistory);
                            var historyManager = _historyManagerPersistor.Load(session);
                            workspace.HistoryManager = historyManager;

                            progress.IncrementProgress(PKSimConstants.UI.LoadingProject);
                            var project = _projectPersistor.Load(session);
                            if (project == null)
                            {
                                //history was loaded but project load failed
                                workspace.HistoryManager = null;
                                return;
                            }

                            project.Name      = FileHelper.FileNameFromFileFullPath(fileFullPath);
                            workspace.Project = project;

                            _projectClassifiableUpdaterAfterDeserialization.Update(project);

                            progress.IncrementProgress(PKSimConstants.UI.LoadingWorkingJournal);
                            var journal = _journalLoader.Load(project.JournalPath, fileFullPath);
                            workspace.Journal = journal;

                            progress.IncrementProgress(PKSimConstants.UI.LoadingLayout);
                            var workspaceLayout = _workspaceLayoutPersistor.Load(session);
                            // The workspace layout may be null if the workspace was created via CLI. In that case, we simply initialize the workspace layout
                            if (workspace is IWithWorkspaceLayout withWorkspaceLayout)
                            {
                                withWorkspaceLayout.WorkspaceLayout = workspaceLayout ?? new WorkspaceLayout();
                            }
                        }
                }
                catch (Exception)
                {
                    //Exception occurs while opening the project!
                    //close the file and rethrow the exception
                    _sessionManager.CloseFactory();
                    throw;
                }
            }
        }
Пример #2
0
        public void LoadSession(IWorkspace workspace, string fileFullPath)
        {
            using (var progress = _progressManager.Create())
            {
                progress.Initialize(5);
                progress.IncrementProgress(PKSimConstants.UI.OpeningProjectDatabase);

                verifyProjectNotReadOnly(fileFullPath);
                _databaseSchemaMigrator.MigrateSchema(fileFullPath);

                try
                {
                    _sessionManager.OpenFactoryFor(fileFullPath);

                    using (var session = _sessionManager.OpenSession())
                        using (session.BeginTransaction())
                        {
                            progress.IncrementProgress(PKSimConstants.UI.LoadingHistory);
                            var historyManager = _historyManagerPersistor.Load(session);
                            workspace.HistoryManager = historyManager;

                            progress.IncrementProgress(PKSimConstants.UI.LoadingProject);
                            var project = _projectPersistor.Load(session);
                            if (project == null)
                            {
                                //history was loaded but project load failed
                                workspace.HistoryManager = null;
                                return;
                            }

                            project.Name      = FileHelper.FileNameFromFileFullPath(fileFullPath);
                            workspace.Project = project;

                            progress.IncrementProgress(PKSimConstants.UI.LoadingWorkingJournal);
                            var journal = _journalLoader.Load(project.JournalPath, fileFullPath);
                            workspace.Journal = journal;

                            progress.IncrementProgress(PKSimConstants.UI.LoadingLayout);
                            var workspaceLayout = _workspaceLayoutPersistor.Load(session);
                            workspace.WorkspaceLayout = workspaceLayout;
                        }
                }
                catch (Exception)
                {
                    //Exeption occurs while opening the project!
                    //close the file and rethrow the exception
                    _sessionManager.CloseFactory();
                    throw;
                }
            }
        }
        public void Load(IMoBiContext context, string projectFullPath)
        {
            try
            {
                _projectConverterLogger.Clear();
                _sessionManager.OpenFactoryFor(projectFullPath);
                using (_sessionManager.OpenSession())
                {
                    //load history first so that possible conversion command can be added to history
                    context.HistoryManager = _historyManagerPersistor.Load(_sessionManager.CurrentSession) as IMoBiHistoryManager;

                    var project = _projectPersistor.Load(context);

                    if (project == null)
                    {
                        return;
                    }

                    project.FilePath   = projectFullPath;
                    project.Name       = FileHelper.FileNameFromFileFullPath(projectFullPath);
                    project.HasChanged = false;

                    LoadJournal(context, project.JournalPath, projectFullPath);
                }
            }
            catch (Exception)
            {
                // Exeption occurs while opening the project!
                // close the file and rethrow the exception
                _sessionManager.CloseFactory();
                context.Clear();
                throw;
            }

            var notificationMessages = _projectConverterLogger.AllMessages();

            if (notificationMessages.Any())
            {
                _eventPublisher.PublishEvent(new ShowNotificationsEvent(new ReadOnlyCollection <NotificationMessage>(notificationMessages.ToList())));
            }
        }