/// <summary>
 /// Scans the section for Shared and Unversioned changes.
 /// </summary>
 /// <param name="templateItem">The template item.</param>
 /// <param name="section">The section.</param>
 /// <param name="result">The result.</param>
 private static void ScanSection(TemplateItem templateItem,
                                 SectionDefinition section, List<ScanResult> result)
 {
     Assert.ArgumentNotNull((object)templateItem, "templateItem");
     Assert.ArgumentNotNull((object)section, "section");
     Assert.ArgumentNotNull((object)result, "result");
     if (!(section.Deleted != "1") || string.IsNullOrEmpty(section.SectionID))
         return;
     TemplateSectionItem section1 = templateItem.GetSection(ID.Parse(section.SectionID));
     if (section1 == null)
         return;
     foreach (
         FieldDefinition field in
             section.Fields)
         TemplateBuilderForm.ScanField(section1, field, result);
 }
        /// <summary>
        /// Updates the template.
        /// </summary>
        private void UpdateTemplate()
        {
            string @string = StringUtil.GetString(new[] { Context.ClientPage.ClientRequest.Form["Active"] });
            string strB1 = Translate.Text("Add a new section");
            string strB2 = Translate.Text("Add a new field");
            TemplateDefinition templateDefinition = new TemplateDefinition()
                {
                    TemplateID =
                        StringUtil.GetString(new[] { Context.ClientPage.ClientRequest.Form["TemplateID"] })
                };
            string[] strArray =
                StringUtil.GetString(new[] { Context.ClientPage.ClientRequest.Form["Structure"] })
                          .Split(new[] { ',' });
            SectionDefinition sectionDefinition = null;
            foreach (string str1 in strArray)
            {
                string str2 = Context.ClientPage.ClientRequest.Form[str1 + "_section_name"];
                if (str2 != null)
                {
                    sectionDefinition = null;
                    string strA = StringUtil.GetString(new[] { str2 }).Trim();
                    if (!string.IsNullOrEmpty(strA) && string.Compare(strA, strB1, true) != 0)
                    {
                        sectionDefinition = new SectionDefinition()
                            {
                                Name = strA,
                                ControlID = str1,
                                SectionID =
                                    StringUtil.GetString(new[]
                                        {
                                           Context.ClientPage.ClientRequest.Form[str1 + "_section_id"]
                                        }),
                                Deleted =
                                    StringUtil.GetString(new[]
                                        {
                                           Context.ClientPage.ClientRequest.Form[str1 + "_section_deleted"]
                                        }),
                                Sortorder =
                                    StringUtil.GetString(new[]
                                        {
                                           Context.ClientPage.ClientRequest.Form[str1 + "_section_sortorder"]
                                        })
                            };
                        templateDefinition.AddSection(sectionDefinition);
                        if (str1 == @string)
                            sectionDefinition.Active = true;
                    }
                }
                else if (sectionDefinition != null)
                {
                    string strA =
                        StringUtil.GetString(new[] { Context.ClientPage.ClientRequest.Form[str1 + "_field_name"] })
                                  .Trim();
                    if (!string.IsNullOrEmpty(strA) && string.Compare(strA, strB2, true) != 0)
                    {
                        FieldDefinition fieldDefinition = new FieldDefinition()
                            {
                                Name = strA,
                                ControlID = str1,
                                FieldID =
                                    StringUtil.GetString(new[]
                                        {
                                           Context.ClientPage.ClientRequest.Form[str1 + "_field_id"]
                                        }),
                                Type =
                                    StringUtil.GetString(new[]
                                        {
                                           Context.ClientPage.ClientRequest.Form[str1 + "_field_type"]
                                        }),
                                Source =
                                    StringUtil.GetString(new[]
                                        {
                                           Context.ClientPage.ClientRequest.Form[str1 + "_field_source"]
                                        }),
                                Title =
                                    StringUtil.GetString(new[]
                                        {
                                           Context.ClientPage.ClientRequest.Form[str1 + "_field_title"]
                                        }),
                                Description =
                                    StringUtil.GetString(new[]
                                        {
                                           Context.ClientPage.ClientRequest.Form[str1 + "_field_description"]
                                        }),
                                IsUnversioned =
                                    !string.IsNullOrEmpty(
                                        Context.ClientPage.ClientRequest.Form[str1 + "_field_unversioned"])
                                        ? "1"
                                        : "0",
                                IsShared =
                                    !string.IsNullOrEmpty(Context.ClientPage.ClientRequest.Form[str1 + "_field_shared"])
                                        ? "1"
                                        : "0",
                                Deleted =
                                    !string.IsNullOrEmpty(Context.ClientPage.ClientRequest.Form[str1 + "_field_deleted"])
                                        ? "1"
                                        : "0",
                                Sortorder =
                                    StringUtil.GetString(new[]
                                        {
                                           Context.ClientPage.ClientRequest.Form[str1 + "_field_sortorder"]
                                        })
                            };
                        sectionDefinition.AddField(fieldDefinition);
                        if (str1 == @string)
                            fieldDefinition.Active = true;
                    }
                }
            }

            this.Definition = templateDefinition.ToXml();
        }
 /// <summary>
 /// Renders the section.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="section">The section.</param>
 private static void RenderSection(HtmlTextWriter output,
                                   SectionDefinition section)
 {
     Assert.ArgumentNotNull((object)output, "output");
     Assert.ArgumentNotNull((object)section, "section");
     if (section.Deleted == "1")
         return;
     if (string.IsNullOrEmpty(section.ControlID))
         section.ControlID = ID.NewID.ToShortID().ToString();
     TemplateBuilderForm.RenderSection(output, section.ControlID, section.SectionID, section.Name, section.Active,
                                       section.Sortorder);
     foreach (
         FieldDefinition field in
             section.Fields)
         TemplateBuilderForm.RenderField(output, field);
     TemplateBuilderForm.RenderField(output, string.Empty, string.Empty, string.Empty, "Single-Line Text",
                                     string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, false,
                                     "0");
 }
        /// <summary>
        /// Saves the section.
        /// </summary>
        /// <param name="templateItem">The template item.</param>
        /// <param name="section">The section.</param>
        private static void SaveSection(TemplateItem templateItem,
                                        SectionDefinition section)
        {
            Assert.ArgumentNotNull((object)templateItem, "templateItem");
            Assert.ArgumentNotNull((object)section, "section");
            TemplateSectionItem sectionItem = (TemplateSectionItem)null;
            if (!string.IsNullOrEmpty(section.SectionID))
                sectionItem = templateItem.GetSection(ID.Parse(section.SectionID), false);
            if (section.Deleted == "1")
            {
                if (sectionItem == null)
                    return;
                sectionItem.InnerItem.Recycle();
            }
            else
            {
                if (sectionItem == null)
                {
                    sectionItem = templateItem.AddSection(section.Name, false);
                    section.SectionID = sectionItem.ID.ToString();
                }

                sectionItem.InnerItem.Editing.BeginEdit();
                sectionItem.InnerItem.Name = StringUtil.GetString(new[]
                    {
                        section.Name
                    });
                sectionItem.InnerItem.Appearance.Sortorder = MainUtil.GetInt(section.Sortorder, 0);
                sectionItem.InnerItem.Editing.EndEdit();
                foreach (
                    FieldDefinition field in
                        section.Fields)
                    TemplateBuilderForm.SaveField(sectionItem, field);
            }
        }
 /// <summary>
 /// Loads the section.
 /// </summary>
 /// <param name="template">The template.</param>
 /// <param name="section">The section.</param>
 private static void LoadSection(TemplateDefinition template,
                                 TemplateSectionItem section)
 {
     Assert.ArgumentNotNull((object)template, "template");
     Assert.ArgumentNotNull((object)section, "section");
     SectionDefinition sectionDefinition
         = new SectionDefinition()
             {
                 SectionID = section.ID.ToString(),
                 Name = section.Name,
                 Sortorder = section.Sortorder.ToString()
             };
     template.AddSection(sectionDefinition);
     foreach (TemplateFieldItem field in section.GetFields())
         TemplateBuilderForm.LoadField(sectionDefinition, field);
     sectionDefinition.Fields.Sort((IComparer)new FieldComparer());
 }
 /// <summary>
 /// Loads the field.
 /// </summary>
 /// <param name="section">The section.</param>
 /// <param name="field">The field.</param>
 private static void LoadField(
     SectionDefinition section,
     TemplateFieldItem field)
 {
     Assert.ArgumentNotNull((object)section, "section");
     Assert.ArgumentNotNull((object)field, "field");
     FieldDefinition fieldDefinition = new FieldDefinition()
         {
             FieldID = field.ID.ToString(),
             Name = field.Name,
             Type = field.Type,
             Source = field.Source,
             Title = field.Title,
             Description = field.InnerItem["__Short description"],
             IsUnversioned = field.IsUnversioned ? "1" : "0",
             IsShared = field.IsShared ? "1" : "0",
             Sortorder = field.Sortorder.ToString()
         };
     section.AddField(fieldDefinition);
 }
        /// <summary>
        /// Fixups the fields.
        /// </summary>
        /// <param name="section">The section.</param>
        private static void FixupFields(
            SectionDefinition section)
        {
            if (section.Fields.Count < 1)
                return;
            int[] numbers = new int[section.Fields.Count];
            for (int index = 0; index < section.Fields.Count; ++index)
            {
                FieldDefinition fieldDefinition
                    =
                    section.Fields[index] as
                    FieldDefinition;
                numbers[index] = fieldDefinition != null ? MainUtil.GetInt(fieldDefinition.Sortorder, 0) : 0;
            }

            int[] numArray = new TemplateBuilderSorter().FixNumbers(numbers);
            for (int index = 0; index < section.Fields.Count; ++index)
            {
                FieldDefinition fieldDefinition
                    =
                    section.Fields[index] as
                    FieldDefinition;
                if (fieldDefinition != null)
                    fieldDefinition.Sortorder = numArray[index].ToString();
            }
        }
 /// <summary>
 /// Gets the section.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <returns>
 /// The section.
 /// </returns>
 public SectionDefinition GetSection(string id)
 {
     foreach (SectionDefinition sectionDefinition in this.Sections)
     {
         if (sectionDefinition.SectionID == id)
             return sectionDefinition;
     }
     SectionDefinition sectionDefinition1 = new SectionDefinition();
     sectionDefinition1.SectionID = id;
     this.Sections.Add((object)sectionDefinition1);
     return sectionDefinition1;
 }
 /// <summary>
 /// Adds the section.
 /// </summary>
 /// <param name="sectionDefinition">The section definition.</param>
 public void AddSection(SectionDefinition sectionDefinition)
 {
     if (this.Sections == null)
         this.Sections = new ArrayList();
     this.Sections.Add((object)sectionDefinition);
 }