예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Adds a new Amendment into the Amendment list.
        /// </summary>
        /// <param name="section"></param>
        /// <param name="amendment"></param>
        private static void PushAmendment(this OperativeSection section, AbstractAmendment amendment)
        {
            // For now every Amendment has a TargetSectionId this could maybe be different one day
            // Remember to move this function if this day ever comes.
            if (section.FirstOrDefault(n => n.OperativeParagraphId == amendment.TargetSectionId) == null)
            {
                throw new MUNity.Exceptions.Resolution.OperativeParagraphNotFoundException();
            }

            if (amendment is AddAmendment addAmendment)
            {
                section.AddAmendments.Add(addAmendment);
            }
            else if (amendment is ChangeAmendment changeAmendment)
            {
                section.ChangeAmendments.Add(changeAmendment);
            }
            else if (amendment is DeleteAmendment deleteAmendment)
            {
                section.DeleteAmendments.Add(deleteAmendment);
            }
            else if (amendment is MoveAmendment moveAmendment)
            {
                section.MoveAmendments.Add(moveAmendment);
            }
            else
            {
                throw new MUNity.Exceptions.Resolution.UnsupportedAmendmentTypeException();
            }
        }
예제 #3
0
 /// <summary>
 /// Removes an amentment from its list. Note that this is not the same
 /// as Deny. This will just remove the given instance of the amendment.
 /// </summary>
 /// <param name="section"></param>
 /// <param name="amendment"></param>
 public static void RemoveAmendment(this OperativeSection section, AbstractAmendment amendment)
 {
     if (amendment is AddAmendment addAmendment)
     {
         section.AddAmendments.RemoveAll(n => n.TargetSectionId == amendment.TargetSectionId);
         section.Paragraphs.RemoveAll(n => n.OperativeParagraphId == amendment.TargetSectionId);
     }
     else if (amendment is ChangeAmendment changeAmendment)
     {
         section.ChangeAmendments.Remove(changeAmendment);
     }
     else if (amendment is DeleteAmendment deleteAmendment)
     {
         section.DeleteAmendments.Remove(deleteAmendment);
     }
     else if (amendment is MoveAmendment moveAmendment)
     {
         section.MoveAmendments.Remove(moveAmendment);
         section.Paragraphs.RemoveAll(n => moveAmendment.NewTargetSectionId == n.OperativeParagraphId);
     }
     else
     {
         throw new MUNity.Exceptions.Resolution.UnsupportedAmendmentTypeException();
     }
 }
예제 #4
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);
        }
예제 #5
0
        /// <summary>
        /// Returns all the Amendments for the operative paragraph with the given Id.
        /// </summary>
        /// <param name="section"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List <AbstractAmendment> AmendmentsForOperativeParagraph(this OperativeSection section, string id)
        {
            var result = new List <AbstractAmendment>();

            result.AddRange(section.AddAmendments.Where(n => n.TargetSectionId == id));
            result.AddRange(section.ChangeAmendments.Where(n => n.TargetSectionId == id));
            result.AddRange(section.DeleteAmendments.Where(n => n.TargetSectionId == id));
            result.AddRange(section.MoveAmendments.Where(n => n.TargetSectionId == id));
            return(result);
        }
예제 #6
0
        /// <summary>
        /// Creates a new Amendment to delete an operative paragraph.
        /// </summary>
        /// <param name="section"></param>
        /// <param name="paragraphId"></param>
        /// <returns></returns>
        public static DeleteAmendment CreateDeleteAmendment(this OperativeSection section, string paragraphId)
        {
            if (section.FindOperativeParagraph(paragraphId) == null)
            {
                throw new MUNity.Exceptions.Resolution.OperativeParagraphNotFoundException();
            }

            DeleteAmendment newAmendment = new DeleteAmendment
            {
                TargetSectionId = paragraphId
            };

            section.PushAmendment(newAmendment);
            return(newAmendment);
        }
예제 #7
0
        /// <summary>
        /// Returns the Path of a Operative Paragraph as a List where every paragraph is an element to get to the last.
        /// For Example
        /// HeadParagraph > ChildParagraph1 > TargetParagraph.
        /// </summary>
        /// <param name="section"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List <OperativeParagraph> GetOperativeParagraphPath(this OperativeSection section, string id)
        {
            var path = new List <OperativeParagraph>();

            foreach (var paragraph in section.Paragraphs)
            {
                var result = FindOperativeParagraphPathRecursive(paragraph, id, path);
                if (result != null)
                {
                    path.Reverse();
                    return(path);
                }
            }
            return(null);
        }
예제 #8
0
        /// <summary>
        /// Creates a new Amendment for a TextChange of a paragraph with a given Id.
        /// </summary>
        /// <param name="section">The operative Section of the resolution that this Admendment should be created in and also where the operative paragraph can be found.</param>
        /// <param name="paragraphId">The OperativeParagraphId of the target paragraph that the text should be changed in.</param>
        /// <param name="newText">The new Text that the paragraph should be set to if the created Amendment is Accepted/Applied.</param>
        /// <returns></returns>
        public static ChangeAmendment CreateChangeAmendment(this OperativeSection section, string paragraphId, string newText = "")
        {
            if (section.FindOperativeParagraph(paragraphId) == null)
            {
                throw new MUNity.Exceptions.Resolution.OperativeParagraphNotFoundException();
            }

            var newAmendment = new ChangeAmendment
            {
                TargetSectionId = paragraphId,
                NewText         = newText
            };

            section.PushAmendment(newAmendment);
            return(newAmendment);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
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);
        }
예제 #12
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);
            }
        }
예제 #13
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);
예제 #14
0
 public static int GetIndexOfParagraph(this OperativeSection section, OperativeParagraph paragraph)
 {
     return(section.Paragraphs.IndexOf(paragraph));
 }
예제 #15
0
 public static IEnumerable <AbstractAmendment> AmendmentsOrdered(this OperativeSection section)
 {
     return(section.GetOrderedAmendments());
 }
예제 #16
0
 public OperativeSectionChangedEventArgs(string resolutionId, OperativeSection section)
 {
     this.ResolutionId = resolutionId;
     this.Section      = section;
 }
예제 #17
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);
예제 #18
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);
예제 #19
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);
예제 #20
0
 /// <summary>
 /// Will search for an Operative Paragraph with the given id. Will return null if the paragraph was not found.
 /// </summary>
 /// <param name="section"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public static OperativeParagraph FindOperativeParagraph(this OperativeSection section, string id)
 {
     return(section.FirstOrDefault(n => n.OperativeParagraphId == id));
 }
예제 #21
0
 public static int AmendmentCount(this OperativeSection section)
 {
     return(section.AddAmendments.Count + section.ChangeAmendments.Count + section.DeleteAmendments.Count + section.MoveAmendments.Count);
 }