コード例 #1
0
ファイル: PageDelta.cs プロジェクト: cgavieta/WORKPAC2016-poc
 /// <summary>
 /// Initializes a new instance of the <see cref="PageDelta"/> class.
 /// </summary>
 /// <param name="original">The original page.</param>
 /// <param name="revision">The revised page.</param>
 public PageDelta(Page original, Page revision)
 {
     this.Original = original;
     this.Revision = revision;
     this.RemovedControls = new List<Control>();
     this.DetermineDelta();
 }
コード例 #2
0
        /// <summary>
        /// Determines the correct position in the control tree of <paramref name="targetPage"/>
        /// and inserts <paramref name="control"/>.
        /// </summary>
        /// <param name="control">The control to add.</param>
        /// <param name="targetPage">The page to add control to.</param>
        /// <param name="targetVariations">The product variations.</param>
        /// <param name="nextId">The next available control id to be used in the case of a clash.</param>
        private void AddControl(Control control, Page targetPage, ProductVariation targetVariations, int nextId)
        {
            if (control.ParentId.HasValue && targetVariations.RemovedControls.Contains(control.ParentId.Value))
            {
                targetVariations.RemovedControls.Add(control.Id);
                return;
            }

            var addedIndex = targetVariations.AddedControls.IndexOf(control.Id);
            if (addedIndex != -1)
            {
                targetPage.Controls.FindRecursive(control.Id).Id = nextId;
                targetVariations.AddedControls[addedIndex] = nextId;
            }

            if (control.Type == ControlType.Group || control.Type == ControlType.Repeater)
            {
                ContainerControl container = control as ContainerControl;
                this.subControls.Add(control.Id, container.Controls);
                container.Controls = new ControlList();
            }

            this.InsertIntoList(control, targetPage, targetVariations.AddedControls);
        }
コード例 #3
0
        /// <summary>
        /// Updates a linked control in <paramref name="targetPage"/> by <paramref name="control"/>.
        /// </summary>
        /// <param name="control">The control to add.</param>
        /// <param name="targetPage">The page to add control to.</param>
        /// <param name="targetVariations">The product variations.</param>
        private void EditControl(Control control, Page targetPage, ProductVariation targetVariations)
        {
            if (!targetVariations.UnlinkedControls.Contains(control.Id))
            {
                Control childControl = targetPage.Controls.FindRecursive(c => c.Id == control.Id);
                ControlList parent = childControl.GetParentControlList(targetPage.Controls);
                int index = parent.IndexOf(childControl);
                control = control.Clone();

                if (control.Type == ControlType.Group || control.Type == ControlType.Repeater)
                {
                    ContainerControl newContainerControl = control as ContainerControl;
                    ContainerControl oldContainerControl = parent[index] as ContainerControl;
                    newContainerControl.Controls = oldContainerControl.Controls;
                }

                if (childControl.ParentId != control.ParentId || childControl.Position != control.Position)
                {
                    if (control.ParentId.HasValue && targetVariations.RemovedControls.Contains(control.ParentId.Value))
                    {
                        targetVariations.EditedControls.Add(childControl.Id);
                        return;
                    }

                    targetPage.Controls.RecursiveRemove(control.Id);
                    childControl.ParentId = control.ParentId;
                    this.InsertIntoList(control, targetPage, targetVariations.AddedControls);
                }
                else
                {
                    parent[index] = control;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Determines the correct position in the control tree of <paramref name="targetPage"/>
        /// and inserts <paramref name="control"/>.
        /// </summary>
        /// <param name="control">The control to add.</param>
        /// <param name="targetPage">The page to add control to.</param>
        /// <param name="addedControls">The control ids that have been added to the target.</param>
        private void InsertIntoList(Control control, Page targetPage, List<int> addedControls)
        {
            ControlList sourceList;

            if (control.ParentId != null && this.subControls.ContainsKey(control.ParentId.Value))
            {
                sourceList = this.subControls[control.ParentId.Value];
            }
            else
            {
                sourceList = control.GetParentControlList(this.delta.Revision.FormDefinition.Pages.FindByPageId(targetPage.PageId).Controls);
            }

            ControlList targetList = !control.ParentId.HasValue ? targetPage.Controls : targetPage.Controls.FindRecursive<ContainerControl>(control.ParentId.Value).Controls;
            int index = this.DetermineTargetIndex(sourceList, targetList, control, addedControls);

            if (index >= targetList.Count)
            {
                targetList.Add(control);
            }
            else
            {
                targetList.Insert(index, control);
            }
        }
コード例 #5
0
 /// <summary>
 /// Determines if a page has a summary control.
 /// </summary>
 /// <param name="page">Target page.</param>
 /// <returns><see langword="true"/> if the page has a summary control, otherwise <see langword="false"/>.</returns>
 private static bool PageHasSummaryControl(Page page)
 {
     return page.Controls.Any(c => c.Type == ControlType.Summary);
 }