Exemplo n.º 1
0
        /// <summary>
        /// Creates a Move Amendment. This will also create a new Operative paragraph at the palce where the amendment should be moved to. Not that this virtual Paragraph
        /// will copy the text once when the amendment is created and once when the amendment is accepted. If the text of the paragraph changed in the mean time the displayed
        /// text of the virtual operative paragraph may differ.
        /// </summary>
        /// <param name="section"></param>
        /// <param name="paragraphId"></param>
        /// <param name="targetIndex"></param>
        /// <param name="parentParagraph"></param>
        /// <returns></returns>
        public static MoveAmendment CreateMoveAmendment(this OperativeSection section, string paragraphId, int targetIndex, OperativeParagraph parentParagraph = null)
        {
            var sourceParagraph = section.FindOperativeParagraph(paragraphId);

            if (sourceParagraph == null)
            {
                throw new MUNity.Exceptions.Resolution.OperativeParagraphNotFoundException();
            }

            var newAmendment = new MoveAmendment
            {
                TargetSectionId = paragraphId
            };
            var virtualParagraph = new OperativeParagraph
            {
                IsLocked  = true,
                IsVirtual = true,
                Text      = sourceParagraph.Text
            };

            newAmendment.NewTargetSectionId = virtualParagraph.OperativeParagraphId;
            section.InsertIntoRealPosition(virtualParagraph, targetIndex, parentParagraph);
            section.PushAmendment(newAmendment);
            return(newAmendment);
        }
Exemplo n.º 2
0
        public void TestRemoveOperativeParagraphNotFoundException()
        {
            var resolution    = new Resolution();
            var fakeParagraph = new OperativeParagraph();

            Assert.Throws <OperativeParagraphNotFoundException>(() => resolution.OperativeSection.RemoveOperativeParagraph(fakeParagraph));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new Operative paragraph inside a given OperativeSection.
        /// </summary>
        /// <param name="section"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static OperativeParagraph CreateOperativeParagraph(this OperativeSection section, string text = "")
        {
            var paragraph = new OperativeParagraph
            {
                Text = text
            };

            section.Paragraphs.Add(paragraph);
            return(paragraph);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new Child paragraph in a given Resolution.
        /// </summary>
        /// <param name="section"></param>
        /// <param name="parentId"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static OperativeParagraph CreateChildParagraph(this OperativeSection section, string parentId, string text = "")
        {
            var parentParagraph = section.FindOperativeParagraph(parentId);

            if (parentParagraph == null)
            {
                throw new MUNity.Exceptions.Resolution.OperativeParagraphNotFoundException();
            }

            var newParagraph = new OperativeParagraph
            {
                Text = text
            };

            parentParagraph.Children.Add(newParagraph);
            return(newParagraph);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a new Add Amendment to add a new operative paragraph at a certain position. This will also create a virtual Paragraph at the stop where
        /// the new paragraph may be when it is accepted.
        /// </summary>
        /// <param name="section">The operative Section of the Resolution where this paragraph should be added.</param>
        /// <param name="targetIndex">The index where the paragraph should be added.</param>
        /// <param name="text">The Text of the new paragraph</param>
        /// <param name="parentParagraph">Use this parent paragraph if the new paragraph should be a sub point</param>
        /// <returns></returns>
        public static AddAmendment CreateAddAmendment(this OperativeSection section, int targetIndex, string text = "", OperativeParagraph parentParagraph = null)
        {
            var virtualParagraph = new OperativeParagraph(text)
            {
                IsVirtual = true,
                Visible   = false
            };

            section.InsertIntoRealPosition(virtualParagraph, targetIndex, parentParagraph);
            var amendment = new AddAmendment
            {
                TargetSectionId = virtualParagraph.OperativeParagraphId
            };

            section.PushAmendment(amendment);
            return(amendment);
        }
Exemplo n.º 6
0
    public static OperativeParagraph ToModel(this ResaOperativeParagraph sourceParagraph)
    {
        if (sourceParagraph.Children == null)
        {
            sourceParagraph.Children = new List <ResaOperativeParagraph>();
        }
        var model = new OperativeParagraph()
        {
            Children             = sourceParagraph.Children.Select(n => n.ToModel()).ToList(),
            Comment              = sourceParagraph.Comment,
            Corrected            = sourceParagraph.Corrected,
            IsLocked             = sourceParagraph.IsLocked,
            IsVirtual            = sourceParagraph.IsVirtual,
            Name                 = sourceParagraph.Name,
            OperativeParagraphId = sourceParagraph.ResaOperativeParagraphId,
            Text                 = sourceParagraph.Text,
            Visible              = sourceParagraph.Visible
        };

        return(model);
    }
Exemplo n.º 7
0
 /// <summary>
 /// An internal function to go throw all operative paragraphs and their child paragraphs and get the path of the paragraph.
 /// </summary>
 /// <param name="paragraph"></param>
 /// <param name="targetId"></param>
 /// <param name="path"></param>
 /// <returns></returns>
 private static OperativeParagraph FindOperativeParagraphPathRecursive(OperativeParagraph paragraph, string targetId, List <OperativeParagraph> path)
 {
     if (paragraph.OperativeParagraphId == targetId)
     {
         path.Add(paragraph);
         return(paragraph);
     }
     if (paragraph.Children != null && paragraph.Children.Any())
     {
         foreach (var child in paragraph.Children)
         {
             var result = FindOperativeParagraphPathRecursive(child, targetId, path);
             if (result != null)
             {
                 path.Add(paragraph);
                 return(result);
             }
         }
     }
     return(null);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Removes an Operative Paragraph from the Operative Section. Will also remove all the amendments that
        /// are targeting this paragraph.
        /// </summary>
        /// <param name="section"></param>
        /// <param name="paragraph"></param>
        public static void RemoveOperativeParagraph(this OperativeSection section, OperativeParagraph paragraph)
        {
            var path = section.GetOperativeParagraphPath(paragraph.OperativeParagraphId);

            if (path == null || !path.Any())
            {
                throw new MUNity.Exceptions.Resolution.OperativeParagraphNotFoundException();
            }

            if (path.Count == 1)
            {
                section.Paragraphs.Remove(paragraph);
            }
            else
            {
                path[path.Count - 1].Children.Remove(paragraph);
            }

            // TODO: Remove all Amendments of this paragraph and all its child paragraphs!
            foreach (var amendment in section.AddAmendments.Where(n => n.TargetSectionId == paragraph.OperativeParagraphId).ToList())
            {
                section.RemoveAmendment(amendment);
            }

            foreach (var changeAmendment in section.ChangeAmendments.Where(n => n.TargetSectionId == paragraph.OperativeParagraphId).ToList())
            {
                section.RemoveAmendment(changeAmendment);
            }

            foreach (var deleteAmendment in section.DeleteAmendments.Where(n => n.TargetSectionId == paragraph.OperativeParagraphId).ToList())
            {
                section.RemoveAmendment(deleteAmendment);
            }

            foreach (var moveAmendment in section.MoveAmendments.Where(n => n.TargetSectionId == paragraph.OperativeParagraphId).ToList())
            {
                section.RemoveAmendment(moveAmendment);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Only works on one level
        /// </summary>
        /// <param name="section"></param>
        /// <param name="paragraph"></param>
        /// <returns></returns>
        public static int GetIndexOfParagraphNonVirtual(this OperativeSection section, OperativeParagraph paragraph)
        {
            int index = 0;

            foreach (var p in section.Paragraphs)
            {
                if (!p.IsVirtual)
                {
                    if (p == paragraph || p.OperativeParagraphId == paragraph.OperativeParagraphId)
                    {
                        break;
                    }
                    index++;
                }
            }
            return(index);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Creates a new Text change amendment.
 /// </summary>
 /// <param name="section"></param>
 /// <param name="paragraph"></param>
 /// <param name="newText"></param>
 /// <returns></returns>
 public static ChangeAmendment CreateChangeAmendment(this OperativeSection section, OperativeParagraph paragraph, string newText = "") => section.CreateChangeAmendment(paragraph.OperativeParagraphId, newText);
Exemplo n.º 11
0
 /// <summary>
 /// Creates a new Move Amendment. The given targetIndex is the position the new Virtual Paragraph will be located.
 /// Type in 0 to move it to the beginning of the list. Note that 1 will also move it to the start!
 /// When you have two Paragraphs (A and B) and want A to move behind B (B, A) you need to set the targetIndex to 2!
 /// </summary>
 /// <param name="section">The Operative Section that you want to crate the Move Amendment at.</param>
 /// <param name="paragraph"></param>
 /// <param name="targetIndex"></param>
 /// <param name="parentParagraph"></param>
 /// <returns></returns>
 public static MoveAmendment CreateMoveAmendment(this OperativeSection section, OperativeParagraph paragraph, int targetIndex, OperativeParagraph parentParagraph = null) =>
 section.CreateMoveAmendment(paragraph.OperativeParagraphId, targetIndex, parentParagraph);
Exemplo n.º 12
0
 /// <summary>
 /// Creates a new amendment to delete a certain operative paragraph.
 /// </summary>
 /// <param name="section"></param>
 /// <param name="paragraph"></param>
 /// <returns></returns>
 public static DeleteAmendment CreateDeleteAmendment(this OperativeSection section, OperativeParagraph paragraph) => section.CreateDeleteAmendment(paragraph.OperativeParagraphId);
Exemplo n.º 13
0
 /// <summary>
 /// Will also create a Child paragraph by calling the CreateChildParagraph function and pass the Id to it.
 /// </summary>
 /// <param name="section"></param>
 /// <param name="parent"></param>
 /// <param name="text"></param>
 /// <returns></returns>
 public static OperativeParagraph CreateChildParagraph(this OperativeSection section, OperativeParagraph parent, string text = "")
 => section.CreateChildParagraph(parent.OperativeParagraphId, text);
Exemplo n.º 14
0
 public static int GetIndexOfParagraph(this OperativeSection section, OperativeParagraph paragraph)
 {
     return(section.Paragraphs.IndexOf(paragraph));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Recursive function used by GetRealOperativeParagraphsInfo
 /// </summary>
 /// <param name="prePath"></param>
 /// <param name="paragraph"></param>
 /// <param name="list"></param>
 private static void AddRealOperativeParagraphInfoRec(string prePath, OperativeParagraph paragraph, List <(string id, string path, string text)> list)
Exemplo n.º 16
0
 public OperativeParagraphChangedEventArgs(string tan, string resolutionId, OperativeParagraph paragraph)
 {
     Tan          = tan;
     ResolutionId = resolutionId;
     Paragraph    = paragraph;
 }
Exemplo n.º 17
0
 public OperativeParagraphChangedEventArgs(string resolutionId, OperativeParagraph paragraph)
 {
     this.ResolutionId = resolutionId;
     this.Paragraph    = paragraph;
 }