private static TrainingModuleDocument CreateTrainingModuleDocument(TrainingModule tm)
        {
            tm.TrainingModuleDocument = new TrainingModuleDocument
                                            {
                                                TrainingModule = tm,
                                                Text = tm.Text,
                                                HtmlEditingTool =
                                                    {Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Design}
                                            };

            //tm.TrainingModuleDocument.VisualHtmlEditor.SetDefaultFont();
            HtmlEditingToolHelper.SetDefaultDocumentHtml(tm.TrainingModuleDocument.HtmlEditingTool);
            tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = tm.DocumentHtml;
            tm.TrainingModuleDocument.HtmlEditingTool.SetDefaultHtml();
            // Блокирует команду Undo.
            //tm.TrainingModuleDocument.HtmlEditingTool.Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Preview;
            tm.TrainingModuleDocument.HtmlEditingTool.Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Design;
            tm.TrainingModuleDocument.Show();

            if (tm.Text.Length > 22)
            {
                tm.TrainingModuleDocument.Text = tm.Text.Substring(0, 22) + "...";
            }
            else
            {
                tm.TrainingModuleDocument.Text = tm.Text;
            }

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

            // Создает и добавляет учебный модуль в дерево учебного курса.
            var tm = new TrainingModule();
            TrainingModule.Count++;
            tm.Id = Guid.NewGuid();
            tm.Text = string.Concat("Учебный модуль ", TrainingModule.Count);
            Warehouse.Warehouse.Instance.CourseTree.CurrentNode.Nodes.Add(tm);

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

            // Добавляет учебный модуль в список.
            Warehouse.Warehouse.Instance.TrainingModules.Add(tm);

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

            //tm.TrainingModuleDocument.VisualHtmlEditor.SetDefaultFont();
            HtmlEditingToolHelper.SetDefaultDocumentHtml(tm.TrainingModuleDocument.HtmlEditingTool);
            PreviewObserver.AddDocument(tm.TrainingModuleDocument);
            tm.TrainingModuleDocument.Show();

            // Предлагает переименовать учебный модуль.
            Warehouse.Warehouse.Instance.CourseTree.LabelEdit = true;
            if (!tm.IsEditing)
            {
                tm.BeginEdit();
            }

            Warehouse.Warehouse.Instance.CourseTree.CurrentNode = tm;
            Warehouse.Warehouse.IsProjectModified = true;
        }
        private static string HtmlToXml(TrainingModule trainingModule)
        {
            var html = string.Copy(trainingModule.DocumentHtml);
            var mlp = new MlParser();
            string searchString;
            string value;
            string tag;

            #region Парсинг закладки

            searchString = "class=bookmark";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("id");

                tag = string.Concat("<anchor id=\"", value, "\" name_anchor=\"",
                                    Warehouse.Warehouse.GetBookmarkNameById(new Guid(value)), "\"></anchor>");

                mlp.ShiftLastIndex(ref html);
                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);
            }

            #endregion

            #region Парсинг компетенции

            searchString = "class=concept";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                mlp.ShiftLastIndex(ref html);

                tag = string.Concat("<glossary_definition concept_id=\"#elem{", mlp.GetValue("id").ToUpper(),
                                    "}\" index=\"1\">", mlp.GetInnerHtml(),
                                    "</glossary_definition>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);
            }

            #endregion

            #region Парсинг ссылки на закладку

            searchString = "class=linktobookmark";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                mlp.ShiftLastIndex(ref html);

                tag = string.Concat("<ref type=\"reference\" linkitem_id=\"", ExtractRelativeHref(mlp.GetValue("href")),
                                    "\">", mlp.GetInnerHtml(), "</ref>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);
            }

            #endregion

            #region Парсинг ссылки на внутреннюю компетенцию

            searchString = "class=linktointernalconcept";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                mlp.ShiftLastIndex(ref html);

                tag = string.Concat("<ref type=\"concept\" linkitem_id=\"#elem{", ExtractRelativeHref(mlp.GetValue("href")).ToUpper(),
                                    "}\">", mlp.GetInnerHtml(), "</ref>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);
            }

            #endregion

            #region Парсинг ссылки на внешнюю компетенцию

            // Парсинга не происходит.
            // При нажатии на ссылку выдает сообщение "Ссылка на внешнюю компетенцию не настроена".

            #endregion

            #region Парсинг ссылки на модуль

            searchString = "class=linktotrainingmodule";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                mlp.ShiftLastIndex(ref html);

                tag = string.Concat("<ref type=\"module\" linkitem_id=\"#module{", ExtractRelativeHref(mlp.GetValue("href")).ToUpper(),
                                    "}\">", mlp.GetInnerHtml(), "</ref>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);
            }

            #endregion

            #region Парсинг рисунка, анимации, аудио, видео, ссылки на них, формулы

            searchString = "<IMG";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("src_");
                if (!value.Equals(string.Empty))
                {
                    value = value.Substring(0, value.IndexOf("\\"));
                }
                // value может быть равно Flashes, Images или string.Empty.
                // value равно string.Empty, если обрабатывается рисунок или формула.

                if (value.Equals(Warehouse.Warehouse.RelativeFlashesDirectory))
                {
                    value = mlp.GetValue("sdocument");

                    if (value.Equals("0"))
                    {
                        #region Анимация

                        tag = string.Concat("<flash src=\"" + mlp.GetValue("src_"),
                                            "\" width=\"", "835",
                                            "\" height=\"", "615",
                                            "\" view=\"0\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                    else if (value.Equals("1"))
                    {
                        #region Ссылка на анимацию

                        tag = string.Concat("<flash src=\"" + mlp.GetValue("src_"),
                                            "\" width=\"", "835",
                                            "\" height=\"", "615",
                                            "\" title=\"", mlp.GetValue("alt"),
                                            "\" view=\"1\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                }
                else if (value.Equals(Warehouse.Warehouse.RelativeImagesDirectory) ||
                    value == string.Empty)
                {
                    value = mlp.GetValue("sdocument");

                    if (value.Equals("0"))
                    {
                        #region Рисунок

                        var src = mlp.GetValue("src");
                        src = ExtractRelativeSrc(src);
                        var width = mlp.GetValue("width");
                        var height = mlp.GetValue("height");

                        if (width == string.Empty || height == string.Empty)
                        {
                            var src_ = Path.Combine(Warehouse.Warehouse.ProjectEditorLocation, src);
                            var imageDimension = System.Drawing.Image.FromFile(src_).PhysicalDimension;
                            width = imageDimension.Width.ToString();
                            height = imageDimension.Height.ToString();
                        }

                        tag = string.Concat("<image src=\"", src,
                                            "\" width=\"", width,
                                            "\" height=\"", height);

                        var attribute = mlp.GetValue("style");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" style=\"", attribute);
                        }

                        attribute = mlp.GetValue("title");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" title=\"", attribute);
                        }

                        attribute = mlp.GetValue("align");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" align=\"", attribute);
                        }

                        attribute = mlp.GetValue("border");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" border=\"", attribute);
                        }

                        attribute = mlp.GetValue("hspace");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" hspace=\"", attribute);
                        }

                        attribute = mlp.GetValue("vspace");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" vspace=\"", attribute);
                        }

                        tag += "\" view=\"0\" />";

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                    else if (value.Equals("1"))
                    {
                        #region Ссылка на рисунок

                        var src = mlp.GetValue("src_");
                        var width = mlp.GetValue("width_");
                        var height = mlp.GetValue("height_");

                        if (width == string.Empty || height == string.Empty)
                        {
                            var src_ = Path.Combine(Warehouse.Warehouse.ProjectEditorLocation, src);
                            var imageDimension = System.Drawing.Image.FromFile(src_).PhysicalDimension;
                            width = imageDimension.Width.ToString();
                            height = imageDimension.Height.ToString();
                        }

                        tag = string.Concat("<image title=\"", mlp.GetValue("alt"), "\" src=\"", src, "\" width=\"",
                                            width, "\" height=\"", height);

                        var attribute = mlp.GetValue("align_");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" align=\"", attribute);
                        }

                        attribute = mlp.GetValue("border_");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" border=\"", attribute);
                        }

                        attribute = mlp.GetValue("hspace_");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" hspace=\"", attribute);
                        }

                        attribute = mlp.GetValue("vspace_");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" vspace=\"", attribute);
                        }

                        tag += "\" view=\"1\" />";

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                    else if (value.Equals(string.Empty))
                    {
                        #region Формула

                        var src = mlp.GetValue("src");
                        src = ExtractRelativeSrc(src);

                        tag = string.Concat("<image src=\"", src,"\" align=\"",
                                            mlp.GetValue("align"), "\" longDesc=\"",
                                            mlp.GetValue("longDesc"), "\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                }
                else if (value.Equals(Warehouse.Warehouse.RelativeAudiosDirectory))
                {
                    value = mlp.GetValue("sdocument");

                    if (value.Equals("0"))
                    {
                        #region Аудио

                        tag = string.Concat("<audio src=\"" + mlp.GetValue("src_"),
                                            "\" view=\"0\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                    else if (value.Equals("1"))
                    {
                        #region Ссылка на аудио

                        tag = string.Concat("<audio src=\"" + mlp.GetValue("src_"),
                                            "\" title=\"", mlp.GetValue("alt"),
                                            "\" view=\"1\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                }
                else if (value.Equals(Warehouse.Warehouse.RelativeVideosDirectory))
                {
                    value = mlp.GetValue("sdocument");

                    if (value.Equals("0"))
                    {
                        #region Видео

                        tag = string.Concat("<video src=\"" + mlp.GetValue("src_"),
                                            "\" view=\"0\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                    else if (value.Equals("1"))
                    {
                        #region Ссылка на видео

                        tag = string.Concat("<video src=\"" + mlp.GetValue("src_"),
                                            "\" title=\"", mlp.GetValue("alt"),
                                            "\" view=\"1\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                }
            }

            #endregion

            #region Парсинг греческих символов

            var greekSymbols = Regex.Matches(html, "[Α-Ωα-ω¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿™•∑∏∫∂√∞ƒ≤≥≠≡…′″∃∈∋∧∨∩∪∼≈⊂⊃⊆⊇⊕⊥°→×÷∀]", RegexOptions.IgnoreCase);
            int index;

            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    var symbol = greekSymbols[i - 1].Value;
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, string.Concat("&#", char.ConvertToUtf32(symbol, 0), ";"));
                }
            }

            greekSymbols = Regex.Matches(html, "[Ë]", RegexOptions.IgnoreCase);
            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, "&Euml;");
                }
            }

            greekSymbols = Regex.Matches(html, "[Ï]", RegexOptions.IgnoreCase);
            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, "&Iuml;");
                }
            }

            greekSymbols = Regex.Matches(html, "[Æ]", RegexOptions.IgnoreCase);
            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, "&AElig;");
                }
            }

            greekSymbols = Regex.Matches(html, "[Ä]", RegexOptions.IgnoreCase);
            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, "&Auml;");
                }
            }

            greekSymbols = Regex.Matches(html, "[Þ]", RegexOptions.IgnoreCase);
            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, "&THORN;");
                }
            }

            #endregion

            // POSTPONE: Протестировать.
            //html = Regex.Replace(html, "<[ \n\t]*/[ \n\t]*sup[ \n\t]*>", "</SUP>", RegexOptions.IgnoreCase);

            return html;
        }
 public TrainingModuleXmlWriter(TrainingModule trainingModule)
 {
     this.trainingModule = trainingModule;
 }
 public TrainingModuleXmlReader(TrainingModule trainingModule)
 {
     this.trainingModule = trainingModule;
 }
예제 #6
0
        public static TrainingModule GetTrainingModuleById(Guid id)
        {
            trainingModule = null;

            WalkTree(Instance.CourseTree.Nodes, id);

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

            var path = Path.Combine(Warehouse.Warehouse.ProjectEditorLocation, Warehouse.Warehouse.ProjectArchiveName);

            #region Заполнение дерева компетенций

            var ct = Warehouse.Warehouse.Instance.ConceptTree;
            var xmlReader = new XmlTextReader(path);

            try
            {
                while (xmlReader.Read())
                {
                    System.Windows.Forms.Application.DoEvents();

                    if (xmlReader.NodeType == XmlNodeType.Element)
                    {
                        if (xmlReader.Name.Equals("concept"))
                        {
                            var io = xmlReader.GetAttribute("io");

                            // В старых файлах проекта атрибута "io" нет.
                            if (io == null || io.Equals("o"))
                            {
                                var c = new Logic.Course.Items.Concept
                                            {
                                                Id = new Guid(xmlReader.GetAttribute("id").Substring(6, 36)),
                                                Text = xmlReader.GetAttribute("name"),
                                                Type = Enums.ConceptType.Internal,
                                                ImageIndex = 1,
                                                SelectedImageIndex = 1
                                            };
                                ct.Nodes.Add(c);
                            }
                            else if (io.Equals("i"))
                            {
                                var c = new Logic.Course.Items.Concept
                                            {
                                                Id = new Guid(xmlReader.GetAttribute("id").Substring(6, 36)),
                                                Text = xmlReader.GetAttribute("name"),
                                                Type = Enums.ConceptType.External,
                                                ImageIndex = 1,
                                                SelectedImageIndex = 1
                                            };
                                ct.Nodes.Add(c);
                            }
                        }
                        else if (xmlReader.Name.Equals("profile"))
                        {
                            var id = new Guid(xmlReader.GetAttribute("concept_id").Substring(6, 36));

                            foreach (Logic.Course.Items.Concept c in ct.Nodes)
                            {
                                if (c.Id.Equals(id))
                                {
                                    var lb = xmlReader.GetAttribute("min");
                                    var separator = NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator;
                                    lb = lb.Replace(".", separator);
                                    lb = lb.Replace(",", separator);

                                    c.LowerBound = (float)Convert.ToDouble(lb);
                                    c.IsProfile = true;
                                    c.ImageIndex = 0;
                                    c.SelectedImageIndex = 0;

                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch { }
            finally
            {
                xmlReader.Close();
            }

            #endregion

            ////
            RibbonStatusStripEx.Instance.SetProgress(10);
            ////

            #region Определение свойства ModuleId компетенций

            var mid = Guid.Empty;
            xmlReader = new XmlTextReader(path);
            var modulesCount = 0;

            try
            {
                while (xmlReader.Read())
                {
                    System.Windows.Forms.Application.DoEvents();

                    if (xmlReader.NodeType == XmlNodeType.Element)
                    {
                        if (xmlReader.Name.Equals("module"))
                        {
                            if (xmlReader.GetAttribute("type").Equals("text"))
                            {
                                mid = new Guid(xmlReader.GetAttribute("id").Substring(8, 36));
                            }

                            modulesCount++;
                        }
                        else if (xmlReader.Name.Equals("output"))
                        {
                            var id = new Guid(xmlReader.GetAttribute("concept_id").Substring(6, 36));

                            foreach (Logic.Course.Items.Concept c in ct.Nodes)
                            {
                                if (c.Id.Equals(id))
                                {
                                    c.ModuleId = new Guid(mid.ToString());

                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch { }
            finally
            {
                xmlReader.Close();
            }

            RibbonStatusStripEx.Instance.ModulesCount = modulesCount;

            #endregion

            #region Чтение структуры проекта, закладок, контента контролей

            var depth = 1;
            var cst = Warehouse.Warehouse.Instance.CourseTree;
            // Узел, в который добавляется следующий создаваемый узел.
            TreeNode activeNode = null;

            xmlReader = new XmlTextReader(path);

            try
            {
                while (xmlReader.Read())
                {
                    System.Windows.Forms.Application.DoEvents();

                    if (xmlReader.NodeType == XmlNodeType.Element)
                    {
                        if (xmlReader.Name.Equals("project"))
                        {
                            #region Корень учебного курса

                            var cr = new Logic.Course.Items.CourseRoot
                                         {
                                             Text = xmlReader.GetAttribute("name")
                                         };

                            cst.Nodes.Add(cr);
                            activeNode = cr;

                            #endregion
                        }
                        else if (xmlReader.Name.Equals("module"))
                        {
                            if (xmlReader.GetAttribute("type").Equals("text"))
                            {
                                #region Учебный модуль

                                mid = new Guid(xmlReader.GetAttribute("id").Substring(8, 36));
                                var tm = new TrainingModule
                                             {
                                                 Id = mid,
                                                 Text = xmlReader.GetAttribute("name")
                                             };

                                TrainingModule.Count++;
                                Warehouse.Warehouse.Instance.TrainingModules.Add(tm);

                                if (xmlReader.Depth == depth)
                                {
                                    activeNode.Nodes.Add(tm);
                                }
                                else if (xmlReader.Depth - depth > 0)
                                {
                                    activeNode = activeNode.Nodes[activeNode.Nodes.Count - 1];
                                    activeNode.Nodes.Add(tm);
                                }
                                else if (xmlReader.Depth - depth < 0)
                                {
                                    for (var i = 0; i < depth - xmlReader.Depth; i++)
                                    {
                                        activeNode = activeNode.Parent;
                                    }

                                    activeNode.Nodes.Add(tm);
                                }

                                depth = xmlReader.Depth;

                                #endregion
                            }
                            else if (xmlReader.GetAttribute("type").Equals("test", StringComparison.OrdinalIgnoreCase) ||
                                     xmlReader.GetAttribute("type").Equals("training", StringComparison.OrdinalIgnoreCase))
                            {
                                #region Контроль

                                mid = Guid.Empty;
                                var tm = new TestModule
                                             {
                                                 Text = xmlReader.GetAttribute("name"),
                                                 Id = new Guid(xmlReader.GetAttribute("id").Substring(8, 36))
                                             };

                                #region Входной/выходной контроль

                                if (xmlReader.GetAttribute("io") != null)
                                {
                                    if (xmlReader.GetAttribute("io").Equals("i", StringComparison.OrdinalIgnoreCase))
                                    {
                                        tm.TestType = Enums.TestType.InTest;
                                    }
                                    else if (xmlReader.GetAttribute("io").Equals("o", StringComparison.OrdinalIgnoreCase))
                                    {
                                        tm.TestType = Enums.TestType.OutTest;
                                    }
                                }
                                else
                                {
                                    tm.TestType = Enums.TestType.OutTest;
                                }

                                #endregion

                                #region Тренажер

                                if (xmlReader.GetAttribute("type").Equals("test", StringComparison.OrdinalIgnoreCase))
                                {
                                    tm.Trainer = false;
                                }
                                else if (xmlReader.GetAttribute("type").Equals("training",
                                                                               StringComparison.OrdinalIgnoreCase))
                                {
                                    tm.Trainer = true;
                                }

                                #endregion

                                #region Последовательность вопросов

                                if (xmlReader.GetAttribute("order").Equals("natural", StringComparison.OrdinalIgnoreCase))
                                {
                                    tm.QuestionSequence = Enums.QuestionSequence.Natural;
                                }
                                else if (xmlReader.GetAttribute("order").Equals("random",
                                                                                StringComparison.OrdinalIgnoreCase))
                                {
                                    tm.QuestionSequence = Enums.QuestionSequence.Random;
                                }
                                else if (xmlReader.GetAttribute("order").Equals("network",
                                                                                StringComparison.OrdinalIgnoreCase))
                                {
                                    tm.QuestionSequence = Enums.QuestionSequence.Network;
                                }

                                #endregion

                                tm.MistakesNumber = int.Parse(xmlReader.GetAttribute("errlimit"));
                                tm.TimeRestriction = int.Parse(xmlReader.GetAttribute("time"));

                                #region Вложенность контролей

                                if (xmlReader.Depth == depth)
                                {
                                    activeNode.Nodes.Add(tm);
                                }
                                else if (xmlReader.Depth - depth > 0)
                                {
                                    activeNode = activeNode.Nodes[activeNode.Nodes.Count - 1];
                                    activeNode.Nodes.Add(tm);
                                }
                                else if (xmlReader.Depth - depth < 0)
                                {
                                    for (int i = 0; i < depth - xmlReader.Depth; i++)
                                    {
                                        activeNode = activeNode.Parent;
                                    }

                                    activeNode.Nodes.Add(tm);
                                }

                                depth = xmlReader.Depth;

                                #endregion

                                tm.XmlReader.ReadXml(xmlReader);

                                #region Замена q.NextQuestion на реальные, после того, как все вопросы считаны

                                foreach (var q in tm.Questions)
                                {
                                    if (q.NextQuestion != null)
                                    {
                                        q.NextQuestion = Warehouse.Warehouse.GetQuestionById(q.NextQuestion.Id);
                                    }
                                }

                                #endregion

                                #endregion

                                RibbonStatusStripEx.Instance.MakeProgressStep(10);
                            }
                        }
                        else if (xmlReader.Name.Equals("input"))
                        {
                            #region Входная компетенция

                            var id = new Guid(xmlReader.GetAttribute("concept_id").Substring(6, 36));
                            Logic.Course.Items.Concept con = null;

                            foreach (Logic.Course.Items.Concept c in ct.Nodes)
                            {
                                if (c.Id.Equals(id))
                                {
                                    con = c;

                                    break;
                                }
                            }

                            var idc = new InDummyConcept
                            {
                                Text = con.Text,
                                Concept = con
                            };
                            idc.Concept.InDummyConcepts.Add(idc);

                            if (con.Type.Equals(Enums.ConceptType.Internal))
                            {
                                // Добавляет компетенцию-пустышку во входы учебного модуля.
                                var tm = Warehouse.Warehouse.GetTrainingModuleById(mid);
                                tm.InConceptParent.Nodes.Add(idc);
                            }
                            else if (con.Type.Equals(Enums.ConceptType.External))
                            {
                                // Добавляет компетенцию-пустышку во входы учебного курса.
                                cst.InConceptsParent.Nodes.Add(idc);
                            }

                            #endregion
                        }
                        else if (xmlReader.Name.Equals("output"))
                        {
                            #region Выходная компетенция

                            var id = new Guid(xmlReader.GetAttribute("concept_id").Substring(6, 36));
                            Logic.Course.Items.Concept con = null;

                            foreach (Logic.Course.Items.Concept c in ct.Nodes)
                            {
                                if (c.Id.Equals(id))
                                {
                                    con = c;

                                    break;
                                }
                            }

                            var odc = new OutDummyConcept
                                          {
                                              Text = con.Text,
                                              Concept = con
                                          };
                            odc.Concept.OutDummyConcept = odc;

                            // Добавляет компетенцию-пустышку в выходы учебного модуля.
                            var tm = Warehouse.Warehouse.GetTrainingModuleById(mid);
                            tm.OutConceptParent.Nodes.Add(odc);

                            #endregion
                        }
                        else if (xmlReader.Name.Equals("html_text"))
                        {
                            #region Чтение закладок

                            // Разбирает DocumentHtml только учебного модуля.
                            if (!mid.Equals(Guid.Empty))
                            {
                                var documentHtml = xmlReader.ReadElementString();
                                documentHtml = documentHtml.Trim();
                                TrainingModuleXmlReader.ReadBookmarksIds(documentHtml);
                            }

                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Instance.LogException(ex);
            }
            finally
            {
                xmlReader.Close();
            }

            #endregion

            #region Чтение контента учебных модулей

            xmlReader = new XmlTextReader(path);

            try
            {
                while (xmlReader.Read())
                {
                    System.Windows.Forms.Application.DoEvents();

                    if (xmlReader.NodeType == XmlNodeType.Element)
                    {
                        if (xmlReader.Name.Equals("module"))
                        {
                            if (xmlReader.GetAttribute("type").Equals("text"))
                            {
                                #region Учебный модуль

                                mid = new Guid(xmlReader.GetAttribute("id").Substring(8, 36));

                                #endregion
                            }
                            else if (xmlReader.GetAttribute("type").Equals("test", StringComparison.OrdinalIgnoreCase) ||
                                     xmlReader.GetAttribute("type").Equals("training", StringComparison.OrdinalIgnoreCase))
                            {
                                #region Контроль

                                mid = Guid.Empty;

                                #endregion
                            }
                        }
                        else if (xmlReader.Name.Equals("html_text"))
                        {
                            #region Контент документа

                            // Разбирает DocumentHtml только учебного модуля.
                            if (!mid.Equals(Guid.Empty))
                            {
                                var documentHtml = xmlReader.ReadElementString();
                                documentHtml = documentHtml.Trim();
                                var tm = Warehouse.Warehouse.GetTrainingModuleById(mid);
                                documentHtml = tm.XmlReader.XmlToHtml(documentHtml);
                                tm.DocumentHtml = documentHtml;
                            }

                            #endregion

                            RibbonStatusStripEx.Instance.MakeProgressStep(10);
                        }
                    }
                }
            }
            catch { }
            finally
            {
                xmlReader.Close();
            }

            #endregion
        }
        private static void WalkTrainingModulesForInConcepts(TrainingModule trainingModule, List<string> conceptNames)
        {
            for (var i = 0; i < trainingModule.TrainingModules.Count; i++)
            {
                var tm = trainingModule.TrainingModules[i];
                if (tm.TrainingModules.Count != 0)
                {
                    WalkTrainingModulesForInConcepts(tm, conceptNames);
                }

                foreach (var idc in trainingModule.TrainingModules[i].InConceptParent.InDummyConcepts)
                {
                    if (idc.Concept.IsProfile)
                    {
                        conceptNames.Add(idc.Concept.Text);
                    }
                }
            }
        }
        private bool IsConceptCycle(TrainingModule initialTrainingModule, TrainingModule targetTrainingModule)
        {
            if (initialTrainingModule == targetTrainingModule)
            {
                isCycle = true;

                return true;
            }

            if (targetTrainingModule != null)
            {
                if (targetTrainingModule.OutConceptParent.OutDummyConcepts.Count != 0)
                {
                    foreach (var odc in targetTrainingModule.OutConceptParent.OutDummyConcepts)
                    {
                        try
                        {
                            foreach (var idc in odc.Concept.InDummyConcepts)
                            {
                                IsConceptCycle(initialTrainingModule, idc.Parent.Parent as TrainingModule);
                            }
                        }
                        catch { }
                    }
                }
            }

            return isCycle;
        }
예제 #10
0
        private static void DeleteTrainingModule(TrainingModule tm)
        {
            #region Ссылки на модули

            // Удаляет ссылки на модуль.
            foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
            {
                if (lto.ObjectId.Equals(tm.Id))
                {
                    if (lto.TrainingModule.TrainingModuleDocument == null)
                    {
                        #region Документ не создан

                        var html_ = string.Copy(lto.TrainingModule.DocumentHtml);
                        var mlp_ = new MlParser();
                        string searchString_;
                        string innerHtml;

                        searchString_ = lto.ObjectId.ToString();
                        while (html_.Contains(searchString_))
                        {
                            mlp_.GetTagBounds(html_, searchString_);
                            mlp_.ShiftLastIndex(ref html_);

                            innerHtml = mlp_.GetInnerHtml();
                            html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                            html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                        }

                        lto.TrainingModule.DocumentHtml = html_;

                        #endregion
                    }
                    else
                    {
                        #region Документ создан

                        var html_ = string.Copy(lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                        var mlp_ = new MlParser();
                        string searchString_;
                        string innerHtml;

                        searchString_ = lto.ObjectId.ToString();
                        while (html_.Contains(searchString_))
                        {
                            mlp_.GetTagBounds(html_, searchString_);
                            mlp_.ShiftLastIndex(ref html_);

                            innerHtml = mlp_.GetInnerHtml();
                            html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                            html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                        }

                        lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html_;

                        #endregion
                    }
                }
            }

            #endregion

            #region Закладки и ссылки на закладки

            // Список закладок текущего учебного модуля.
            var bookmarks = new List<Bookmark>();

            foreach (var b in Warehouse.Warehouse.Instance.Bookmarks)
            {
                if (b.ModuleId.Equals(tm.Id))
                {
                    bookmarks.Add(b);
                }
            }

            foreach (var b in bookmarks)
            {
                // Удаляет закладку из списка закладок.
                Warehouse.Warehouse.Instance.Bookmarks.Remove(b);

                // Удаляет закладку из Html-кода.
                if (tm.TrainingModuleDocument == null)
                {
                    #region Документ не создан

                    var html = tm.DocumentHtml;
                    var mlp = new MlParser();
                    string searchString;
                    string value;
                    int index;

                    searchString = "class=bookmark";
                    index = 0;
                    while (html.Contains(searchString))
                    {
                        mlp.GetTagBounds(html, searchString, index);
                        value = mlp.GetValue("id");
                        mlp.ShiftLastIndex(ref html);

                        if (value.Equals(b.Id.ToString()))
                        {
                            html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                            index = mlp.StartIndex;
                        }
                        else
                        {
                            index = mlp.LastIndex;
                        }

                        if (index == mlp.StartIndex)
                        {
                            break;
                        }
                    }

                    tm.DocumentHtml = html;

                    #endregion
                }
                else
                {
                    #region Документ создан

                    var html = tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml;
                    var mlp = new MlParser();
                    string searchString;
                    string value;
                    int index;

                    searchString = "class=bookmark";
                    index = 0;
                    while (html.Contains(searchString))
                    {
                        mlp.GetTagBounds(html, searchString, index);
                        value = mlp.GetValue("id");
                        mlp.ShiftLastIndex(ref html);

                        if (value.Equals(b.Id.ToString()))
                        {
                            html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                            index = mlp.StartIndex;
                        }
                        else
                        {
                            index = mlp.LastIndex;
                        }

                        if (index == mlp.StartIndex)
                        {
                            break;
                        }
                    }

                    tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html;

                    #endregion
                }

                // Удаляет ссылки на закладку.
                foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
                {
                    if (lto.ObjectId.Equals(b.Id))
                    {
                        if (lto.TrainingModule.TrainingModuleDocument == null)
                        {
                            #region Документ не создан

                            var html_ = string.Copy(lto.TrainingModule.DocumentHtml);
                            var mlp_ = new MlParser();
                            string searchString_;
                            string innerHtml;

                            searchString_ = lto.ObjectId.ToString();
                            while (html_.Contains(searchString_))
                            {
                                mlp_.GetTagBounds(html_, searchString_);
                                mlp_.ShiftLastIndex(ref html_);

                                innerHtml = mlp_.GetInnerHtml();
                                html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                            }

                            lto.TrainingModule.DocumentHtml = html_;

                            #endregion
                        }
                        else
                        {
                            #region Документ создан

                            var html_ = string.Copy(lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                            var mlp_ = new MlParser();
                            string searchString_;
                            string innerHtml;

                            searchString_ = lto.ObjectId.ToString();
                            while (html_.Contains(searchString_))
                            {
                                mlp_.GetTagBounds(html_, searchString_);
                                mlp_.ShiftLastIndex(ref html_);

                                innerHtml = mlp_.GetInnerHtml();
                                html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                            }

                            lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html_;

                            #endregion
                        }
                    }
                }
            }

            #endregion

            #region Компетенции и ссылки на компетенции

            // Список компетенций текущего учебного модуля.
            var concepts = new List<Logic.Course.Items.Concept>();

            foreach (var odc in tm.OutConceptParent.OutDummyConcepts)
            {
                concepts.Add(odc.Concept);
            }

            foreach (var c in concepts)
            {
                // Удаляет компетенцию из дерева компетенций.
                Warehouse.Warehouse.Instance.ConceptTree.Nodes.Remove(c);

                if (Warehouse.Warehouse.Instance.ConceptTree.Nodes.Count.Equals(0))
                {
                    Warehouse.Warehouse.Instance.ConceptTree.CurrentNode = null;
                }

                if (c.Type.Equals(Enums.ConceptType.Internal))
                {
                    // Удаляет компетенцию из выходов.
                    c.OutDummyConcept.Parent.Nodes.Remove(c.OutDummyConcept);

                    // Удаляет компетенцию из входов.
                    foreach (var idc in c.InDummyConcepts)
                    {
                        idc.Parent.Nodes.Remove(idc);
                    }
                    c.InDummyConcepts.Clear();

                    // Удаляет компетенцию из Html-кода.
                    if (tm.TrainingModuleDocument == null)
                    {
                        #region Документ не создан

                        var html = string.Copy(tm.DocumentHtml);
                        var mlp = new MlParser();
                        string searchString;
                        string innerHtml;

                        searchString = c.Id.ToString();
                        while (html.Contains(searchString))
                        {
                            mlp.GetTagBounds(html, searchString);
                            mlp.ShiftLastIndex(ref html);

                            innerHtml = mlp.GetInnerHtml();
                            html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                            html = html.Insert(mlp.StartIndex, innerHtml);
                        }

                        tm.DocumentHtml = html;

                        #endregion
                    }
                    else
                    {
                        #region Документ создан

                        var html = string.Copy(tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                        var mlp = new MlParser();
                        string searchString;
                        string innerHtml;

                        searchString = c.Id.ToString();
                        while (html.Contains(searchString))
                        {
                            mlp.GetTagBounds(html, searchString);
                            mlp.ShiftLastIndex(ref html);

                            innerHtml = mlp.GetInnerHtml();
                            html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                            html = html.Insert(mlp.StartIndex, innerHtml);
                        }

                        tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html;

                        #endregion
                    }

                    // Удаляет ссылки на компетенцию.
                    foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
                    {
                        if (lto.ObjectId.Equals(c.Id))
                        {
                            if (lto.TrainingModule.TrainingModuleDocument == null)
                            {
                                #region Документ не создан

                                var html_ = string.Copy(lto.TrainingModule.DocumentHtml);
                                var mlp_ = new MlParser();
                                string searchString_;
                                string innerHtml;

                                searchString_ = lto.ObjectId.ToString();
                                while (html_.Contains(searchString_))
                                {
                                    mlp_.GetTagBounds(html_, searchString_);
                                    mlp_.ShiftLastIndex(ref html_);

                                    innerHtml = mlp_.GetInnerHtml();
                                    html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                    html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                                }

                                lto.TrainingModule.DocumentHtml = html_;

                                #endregion
                            }
                            else
                            {
                                #region Документ создан

                                var html_ = string.Copy(lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                                var mlp_ = new MlParser();
                                string searchString_;
                                string innerHtml;

                                searchString_ = lto.ObjectId.ToString();
                                while (html_.Contains(searchString_))
                                {
                                    mlp_.GetTagBounds(html_, searchString_);
                                    mlp_.ShiftLastIndex(ref html_);

                                    innerHtml = mlp_.GetInnerHtml();
                                    html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                    html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                                }

                                lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html_;

                                #endregion
                            }
                        }
                    }
                }
            }

            #endregion

            #region Ссылки

            // Список ссылок из текущего учебного модуля.
            var linksToObjects = new List<LinkToObject>();

            foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
            {
                if (lto.TrainingModule.Equals(tm))
                {
                    linksToObjects.Add(lto);
                }
            }

            foreach (var lto in linksToObjects)
            {
                Warehouse.Warehouse.Instance.LinksToObjects.Remove(lto);
            }

            #endregion

            Warehouse.Warehouse.Instance.TrainingModules.Remove(tm);

            if (tm.TrainingModuleDocument != null)
            {
                tm.TrainingModuleDocument.Hide();
            }
        }