Exemple #1
0
        private async Task LaunchCrossViewEditorAsync(string iterationId)
        {
            if (iterationId == string.Empty)
            {
                Logger.Debug("The cross editor workbook cannot be build: the iteration id is empty");
                return;
            }

            var uniqueId  = Guid.Parse(iterationId);
            var iteration = this.Iterations.SingleOrDefault(x => x.Iid == uniqueId);

            if (iteration == null)
            {
                Logger.Debug($"The cross editor workbook cannot be build: iteration {uniqueId} cannot be found");
                return;
            }

            if (!(iteration.Container is EngineeringModel engineeringModel))
            {
                Logger.Error("The cross editor workbook cannot be build: Iteration container object is null");
                return;
            }

            var activeParticipant = engineeringModel.EngineeringModelSetup.Participant.FirstOrDefault(x => x.Person == this.Session.ActivePerson);

            if (this.officeApplicationWrapper.Excel == null)
            {
                Logger.Error("The cross editor workbook cannot be build: The Excel Application object is null");
                return;
            }

            var activeWorkbook = this.ExcelQuery.QueryActiveWorkbook(this.officeApplicationWrapper.Excel);

            var crossViewDialogViewModel = new CrossViewDialogViewModel(this.officeApplicationWrapper.Excel, iteration, this.Session, activeWorkbook);

            this.DialogNavigationService.NavigateModal(crossViewDialogViewModel);

            var dialogResult = crossViewDialogViewModel.DialogResult as WorkbookSelectionDialogResult;

            if (dialogResult?.Result != null && dialogResult.Result.Value)
            {
                var workbook = dialogResult.Workbook;

                var workbookMetadata = new WorkbookMetadata
                {
                    ElementDefinitions = dialogResult.WorkbookElements.Select(x => x.Iid),
                    ParameterTypes     = dialogResult.WorkbookParameterType.Select(x => x.Iid),
                    ParameterValues    = dialogResult.WorkbookChangedValues,
                    PersistValues      = dialogResult.PersistValues
                };

                var workbookOperator = new WorkbookOperator(this.officeApplicationWrapper.Excel, workbook, workbookMetadata);

                await workbookOperator.Rebuild(this.Session, iteration, activeParticipant);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkbookOperator"/> class.
        /// </summary>
        /// <param name="application">
        /// The excel application object that contains the <see cref="Workbook"/> that is being operated on.
        /// </param>
        /// <param name="workbook">
        /// The <see cref="Workbook"/> that is being operated on.
        /// </param>
        /// <param name="workbookMetadata">
        /// The <see cref="WorkbookMetadata"/> that was saved.
        /// </param>
        public WorkbookOperator(Application application, Workbook workbook, WorkbookMetadata workbookMetadata)
        {
            if (application == null)
            {
                Logger.Error("The Excel application may not be null");
                return;
            }

            if (workbook == null)
            {
                Logger.Error("The workbook may not be null");
                return;
            }

            workbook.Activate();

            this.application      = application;
            this.workbook         = workbook;
            this.workbookMetadata = workbookMetadata;
        }