コード例 #1
0
        private bool CreatePresentationWithBackgrounds(PresentationInfo presentationInfo, BackgroundImageDescriptor[] descriptors, DisplayType selectedDisplay)
        {
            PresentationInfo pi;
            string uniqueName = presentationInfo.UniqueName;
            Presentation presentation = PresentationController.NewPresentation(presentationInfo.Name, presentationInfo.Author, descriptors.Count());
            presentation.UniqueName = uniqueName;
            presentation.Comment = presentationInfo.Comment;
            for (int i = 0; i < presentation.SlideList.Count; i++)
            {
                Display display = selectedDisplay.CreateNewDisplay();
                ActiveDisplay activeDisplay = display as ActiveDisplay;
                if (activeDisplay != null)
                {
                    activeDisplay.BackgroundImage = descriptors[i].Id;
                    presentation.SlideList[i].DisplayList.Add(activeDisplay);
                }
            }

            pi = new PresentationInfo(presentation);

            creatingPresentation = pi;
            int[] labelNotExists;

            if (CreatePresentationResult.Ok == DesignerClient.Instance.PresentationWorker.CreatePresentation(pi, out labelNotExists))
            {
                if (!DesignerClient.Instance.IsStandAlone)
                {
                    if (!DesignerClient.Instance.PresentationWorker.AcquireLockForPresentation(pi.UniqueName, RequireLock.ForEdit))
                    {
                        MessageBoxExt.Show("Не удалось заблокировать созданный сценарий для редактирования!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }

                    foreach (Slide slide in presentation.SlideList)
                    {
                        if (!DesignerClient.Instance.PresentationWorker.AcquireLockForSlide(pi.UniqueName, slide.Id, RequireLock.ForEdit))
                        {
                            MessageBoxExt.Show("Не удалось заблокировать созданную сцену для редактирования!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }

                    pi = new PresentationInfoExt(pi, new LockingInfo(identity, RequireLock.ForEdit, new PresentationKey(pi.UniqueName)));
                }
                else
                    pi = new PresentationInfoExt(pi, null);

                int[] notLockedSlide;
                ResourceDescriptor[] notExists;
                DeviceResourceDescriptor[] deviceResourceDescriptorsNotExists;
                if (!DesignerClient.Instance.PresentationWorker.SaveSlideChanges(pi.UniqueName,
                                                                                 presentation.SlideList.ToArray(),
                                                                                 out notLockedSlide,
                                                                                 out notExists,
                                                                                 out
                                                                                         deviceResourceDescriptorsNotExists,
                                                                                 out labelNotExists))
                {
                    MessageBoxExt.Show("Не удалось сохранить созданные сцены!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }

                if (!DesignerClient.Instance.IsStandAlone)
                    foreach (Slide slide in presentation.SlideList)
                    {
                        DesignerClient.Instance.PresentationWorker.ReleaseLockForSlide(pi.UniqueName, slide.Id);
                    }

                ShowJustCreatedPresentation(pi);
            }
            else
                MessageBoxExt.Show("Не удалось создать сценарий!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return true;
        }