/// <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>
 /// Scans the field.
 /// </summary>
 /// <param name="sectionItem">The section item.</param>
 /// <param name="field">The field.</param>
 /// <param name="result">The result.</param>
 private static void ScanField(TemplateSectionItem sectionItem,
                               FieldDefinition field, List<ScanResult> result)
 {
     Assert.ArgumentNotNull((object)sectionItem, "sectionItem");
     Assert.ArgumentNotNull((object)field, "field");
     Assert.ArgumentNotNull((object)result, "result");
     if (!(field.Deleted != "1") || string.IsNullOrEmpty(field.FieldID))
         return;
     bool shared = StringUtil.GetString(new[]
         {
             field.IsShared
         }) == "1";
     bool unversioned = StringUtil.GetString(new[]
         {
             field.IsUnversioned
         }) == "1";
     TemplateFieldItem field1 = sectionItem.GetField(ID.Parse(field.FieldID));
     if (field1 == null || field1.Shared == shared && field1.Unversioned == unversioned)
         return;
     Template template = TemplateManager.GetTemplate(sectionItem.Template.ID, sectionItem.Database);
     Assert.IsNotNull((object)template, typeof(Template));
     TemplateField field2 = template.GetField(field1.ID);
     Assert.IsNotNull((object)field2, typeof(TemplateField));
     result.Add(new TemplateBuilderForm.ScanResult(field2, field1.DisplayName, shared, unversioned));
 }
        /// <summary>
        /// Saves the field.
        /// </summary>
        /// <param name="sectionItem">The section item.</param>
        /// <param name="field">The field.</param>
        private static void SaveField(TemplateSectionItem sectionItem,
                                      FieldDefinition field)
        {
            Assert.ArgumentNotNull((object)sectionItem, "sectionItem");
            Assert.ArgumentNotNull((object)field, "field");
            TemplateFieldItem templateFieldItem = (TemplateFieldItem)null;
            if (!string.IsNullOrEmpty(field.FieldID))
                templateFieldItem = sectionItem.GetField(ID.Parse(field.FieldID));
            if (field.Deleted == "1")
            {
                if (templateFieldItem == null)
                    return;
                templateFieldItem.InnerItem.Recycle();
            }
            else
            {
                if (templateFieldItem == null)
                {
                    templateFieldItem = sectionItem.AddField(field.Name);
                    field.FieldID = templateFieldItem.ID.ToString();
                }

                templateFieldItem.InnerItem.Editing.BeginEdit();
                templateFieldItem.InnerItem.Name = StringUtil.GetString(new[] { field.Name });
                templateFieldItem.Type = StringUtil.GetString(new[] { field.Type });
                templateFieldItem.Source = StringUtil.GetString(new[] { field.Source });
                templateFieldItem.Title = StringUtil.GetString(new[] { field.Title });
                templateFieldItem.InnerItem["__Short description"] =
                    StringUtil.GetString(new[] { field.Description });
                templateFieldItem.InnerItem[TemplateFieldIDs.Unversioned] =
                    StringUtil.GetString(new[] { field.IsUnversioned }) == "1" ? "1" : string.Empty;
                templateFieldItem.InnerItem[TemplateFieldIDs.Shared] =
                    StringUtil.GetString(new[] { field.IsShared }) == "1" ? "1" : string.Empty;
                templateFieldItem.InnerItem.Appearance.Sortorder = MainUtil.GetInt(field.Sortorder, 0);
                templateFieldItem.InnerItem.Editing.EndEdit();
            }
        }
 /// <summary>
 /// Renders the field.
 /// </summary>
 /// <param name="output">The output.</param>
 /// <param name="field">The field.</param>
 private static void RenderField(HtmlTextWriter output,
                                 FieldDefinition field)
 {
     Assert.ArgumentNotNull((object)output, "output");
     Assert.ArgumentNotNull((object)field, "field");
     if (field.Deleted == "1")
         return;
     if (string.IsNullOrEmpty(field.ControlID))
         field.ControlID = ID.NewID.ToShortID().ToString();
     TemplateBuilderForm.RenderField(output, field.ControlID, field.FieldID, field.Name, field.Type, field.Source,
                                     field.Title, field.Description, field.IsUnversioned, field.IsShared,
                                     field.Active, field.Sortorder);
 }
 /// <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>
 /// Adds the field.
 /// </summary>
 /// <param name="fieldDefinition">The field definition.</param>
 public void AddField(FieldDefinition fieldDefinition)
 {
     if (this.Fields == null)
         this.Fields = new ArrayList();
     this.Fields.Add((object)fieldDefinition);
 }