public override void Execute(object @object)
        {
            if (!Enabled)
            {
                return;
            }

            using (var openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter = "Все типы рисунков (*.gif, *.jpg, *.jpeg, *.png)|" +
                        "*.gif;*.jpg;*.jpeg;*.png|" +
                        "GIF (*.gif)|*.gif|" +
                        "JPEG (*.jpg, *.jpeg)|*.jpg;*.jpeg|" +
                        "PNG (*.png)|*.png";
                openFileDialog.InitialDirectory = AppSettingsHelper.GetInitialDirectory();

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //  sourceTextBox.Text = openFileDialog.FileName;
                    sourceImageSize = Image.FromFile(openFileDialog.FileName).PhysicalDimension;
                    imageSize = new SizeF(sourceImageSize);

                    source = openFileDialog.FileName;
                    var imageName = Guid.NewGuid().ToString();
                    var destPath = Path.Combine(Warehouse.Warehouse.AbsoluteEditorImagesDirectory, imageName);
                    destPath += Path.GetExtension(source);

                    if (!File.Exists(destPath))
                    {
                        try
                        {
                            File.Copy(source, destPath);
                        }
                        catch (Exception exception)
                        {
                            ExceptionManager.Instance.LogException(exception);
                            UIHelper.ShowMessage(operationCantBePerformedMessage, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                            return;
                        }
                    }
                    else
                    {
                        var dr = MessageBox.Show(fileIsAlreadyUsedMessage,
                            System.Windows.Forms.Application.ProductName,
                            MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                        if (dr.Equals(DialogResult.OK))
                        {
                            try
                            {
                                File.Copy(source, destPath, true);
                            }
                            catch (Exception exception)
                            {
                                ExceptionManager.Instance.LogException(exception);
                                UIHelper.ShowMessage(operationCantBePerformedMessage, MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                                return;
                            }

                            // POSTPONE: Реализовать обновление изображения в редакторе.
                            //VisualHtmlEditor.ActiveEditor.Refresh();
                            //VisualHtmlEditor.ActiveEditor.Update();
                        }
                    }

                    var imageNameWithoutExtension = Path.GetFileNameWithoutExtension(source);
                    source = destPath;

                    AppSettingsManager.Instance.SetSettingByName(SettingNames.InitialDirectory,
                        Path.GetDirectoryName(openFileDialog.FileName));
                }
                else { return; }  
            }

            var q = new InteractiveQuestion
                        {
                            Id = Guid.NewGuid()
                        };

            if (Warehouse.Warehouse.Instance.CourseTree.CurrentNode is TestModule)
            {
                var tm = Warehouse.Warehouse.Instance.CourseTree.CurrentNode as TestModule;
                q.Text = string.Concat("Вопрос ", tm.Questions.Count + 1);
            }

            if (Warehouse.Warehouse.Instance.CourseTree.CurrentNode is Group)
            {
                var g = Warehouse.Warehouse.Instance.CourseTree.CurrentNode as Group;
                q.Text = string.Concat("Вопрос ", g.Questions.Count + 1);

                q.TimeRestriction = g.TimeRestriction;
                q.Profile = g.Profile;
                q.Marks = g.Marks;
            }

            
            Warehouse.Warehouse.Instance.CourseTree.CurrentNode.Nodes.Add(q);

            if (!Warehouse.Warehouse.Instance.CourseTree.CurrentNode.IsExpanded)
            {
                Warehouse.Warehouse.Instance.CourseTree.CurrentNode.Toggle();
            }
            /* */

            // Создает и отображает редактор.
            q.QuestionDocument = new QuestionDocument
                                     {
                                         Question = q,
                                         Text = q.Text,
                                         HtmlEditingTool =
                                             {Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Design}
                                     };

            VisualEditor.Logic.Controls.HtmlEditing.HtmlEditingToolHelper.SetDefaultDocumentHtml(q.QuestionDocument.HtmlEditingTool);
            PreviewObserver.AddDocument(q.QuestionDocument);
            q.QuestionDocument.Show();
            

            var flashPlayerAbsolutePath = Path.Combine(System.Windows.Forms.Application.StartupPath, Warehouse.Warehouse.InteractiveFlashRelativePath);
         
                #region Рисунок
           
            source = source.Replace('\\', '/');
            //" + sourceImageSize.Width + "\" height=\"" + sourceImageSize.Height + "
            string i = "<!DOCTYPE HTML><html><head><script type=\"text/javascript\">//<![CDATA[\r\nfunction fl_set(){f.setImage(\"" + source + "\");f.setModeString(\"d\");}\r\nfunction fl_get(m){return (m <= 0) ? f.getSelectString() : ((m == 1) ? f.getModeString() : f.getRegionString());}\r\n//]]></script></head><body onload=\"fl_set()\"><object id=\"f\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"800\" height=\"700\">" +
                          "<param name=\"movie\" value=\"" + flashPlayerAbsolutePath + "\"/></object></body></html>";
            var ahe = EditorObserver.ActiveEditor.Document.CreateElement(TagNames.AnchorTagName);
            ahe.InnerHtml = i;
                try
                {
                   // p.Show();
                   // VisualEditor.Utils.Controls.HtmlEditing.HtmlEditingToolHelper.InsertHtml(EditorObserver.ActiveEditor, i);
                    EditorObserver.ActiveEditor.DocumentText = i;
                }
                catch (Exception exception)
                {
                    ExceptionManager.Instance.LogException(exception);
                    UIHelper.ShowMessage(operationCantBePerformedMessage, MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return;
                }

                #endregion
           // }

            Warehouse.Warehouse.Instance.CourseTree.CurrentNode = q;
            Warehouse.Warehouse.IsProjectModified = true;
        }
Ejemplo n.º 2
0
        public static Question Clone(Question question)
        {
            Question newQuestion = null;

            #region Инициализация вопроса

            if (question is ChoiceQuestion)
            {
                newQuestion = new ChoiceQuestion();
            }
            else if (question is MultichoiceQuestion)
            {
                newQuestion = new MultichoiceQuestion();
            }
            else if (question is InteractiveQuestion)
            {
                newQuestion = new InteractiveQuestion();
            }
            else if (question is OrderingQuestion)
            {
                newQuestion = new OrderingQuestion();
            }
            else if (question is OpenQuestion)
            {
                newQuestion = new OpenQuestion();
            }
            else if (question is CorrespondenceQuestion)
            {
                newQuestion = new CorrespondenceQuestion();
            }
            else if (question is OuterQuestion)
            {
                newQuestion = new OuterQuestion();
                (newQuestion as OuterQuestion).TaskId = (question as OuterQuestion).TaskId;
                (newQuestion as OuterQuestion).TaskName = (question as OuterQuestion).TaskName;
                (newQuestion as OuterQuestion).TestName = (question as OuterQuestion).TestName;
                (newQuestion as OuterQuestion).SubjectName = (question as OuterQuestion).SubjectName;
                (newQuestion as OuterQuestion).Declaration = (question as OuterQuestion).Declaration;
                (newQuestion as OuterQuestion).Url = (question as OuterQuestion).Url;
            }

            #endregion

            newQuestion.LowerBound = question.LowerBound;
            newQuestion.Cardinality = question.Cardinality;
            newQuestion.Text = question.Text;
            newQuestion.Id = Guid.NewGuid();
            newQuestion.DocumentHtml = string.Copy(question.DocumentHtml);
            newQuestion.TimeRestriction = question.TimeRestriction;
            newQuestion.Profile = question.Profile;
            newQuestion.Marks = question.Marks;
            newQuestion.Hint = question.Hint;
            newQuestion.NextQuestion = question.NextQuestion;
            newQuestion.IsAdaptive = question.IsAdaptive;
            newQuestion.BaseType = question.BaseType;
            newQuestion.DefaultValue = question.DefaultValue;
            //newQuestion.Mark = question.Mark;
            newQuestion.IsShuffle = question.IsShuffle;
            newQuestion.MaxChoices = question.MaxChoices;
            //  newQuestion.timeRestriction = question.timeRestriction;
            newQuestion.identifier = question.identifier;    // идентификатор вопроса ("VE-" + questionNumber + questionType)  

            foreach (var questionResponse in question.Responses)
            {
                var response = Response.Clone(questionResponse);
                newQuestion.Nodes.Add(response);
            }

            foreach (ResponseVariant questionResponseVariant in question.ResponseVariants)
            {
                var responseVariant = new ResponseVariant(question);

                if (!(question is OrderingQuestion) && !(question is OpenQuestion))
                {
                    foreach (Response response in questionResponseVariant.Responses)
                    {
                        for (var i = 0; i < question.Responses.Count; i++)
                        {
                            if ((question.Responses[i]).Text.Equals(response.Text))
                            {
                                responseVariant.Responses.Add(question.Responses[i]);

                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (var i = 0; i < questionResponseVariant.Responses.Count; i++)
                    {
                        responseVariant.Responses.Add(questionResponseVariant.Responses[i]);
                    }
                }

                responseVariant.Weight = questionResponseVariant.Weight;
                responseVariant.Hint = questionResponseVariant.Hint;
                responseVariant.NextQuestion = questionResponseVariant.NextQuestion; // моё 


                newQuestion.ResponseVariants.Add(responseVariant);
            }

            return newQuestion;
        }