/// <summary> /// Determine if a field is not present in the excluded field set /// </summary> public bool IsFieldIncluded(TemplateFieldItem field) { if (_excludedFields == null) { RefreshSpecTargets(); } return(!_excludedFields.Contains(field.ID)); }
public TemplateField(TemplateFieldItem fieldItem) { FieldItem = fieldItem; FieldClassName = DomUtil.ConvertCaseString(fieldItem.Name); FieldConstantName = DomUtil.ConvertCaseString(fieldItem.Name, "_").ToUpperInvariant(); FieldId = fieldItem.ID.ToString(); FieldName = fieldItem.Name; FieldType = fieldItem.Type; }
public static Type GetFieldType(this TemplateFieldItem field) { FieldType fieldType = FieldTypeManager.GetFieldType(field.Type); Type result; if (field.Type == "Number") { result = typeof(double); } else { if (field.Type == "Integer") { result = typeof(int); } else { if (fieldType != null) { string fullName = fieldType.Type.FullName; switch (fullName) { case "Sitecore.Data.Fields.TextField": case "Sitecore.Data.Fields.HtmlField": case "Sitecore.Data.Fields.ValueLookupField": result = typeof(string); return(result); case "Sitecore.Data.Fields.DateField": result = typeof(DateTime); return(result); case "Sitecore.Data.Fields.LookupField": case "Sitecore.Data.Fields.ReferenceField": case "Sitecore.Data.Fields.GroupedDroplinkField": case "Sitecore.Data.Fields.GroupedDroplistField": result = typeof(Item); return(result); case "Sitecore.Data.Fields.MultilistField": result = typeof(IEnumerable <Item>); return(result); case "Sitecore.Data.Fields.CheckboxField": result = typeof(bool); return(result); } result = fieldType.Type; } else { result = typeof(string); } } } return(result); }
private static void AddCommentsToFieldProperty(CodeMemberProperty property, TemplateFieldItem field) { if (!string.IsNullOrEmpty(field.Description)) { property.Comments.Add(new CodeCommentStatement("<summary>" + field.Description + "</summary>", true)); } else { property.Comments.Add(new CodeCommentStatement(string.Format("<summary>Represents the {0} field</summary>", field.DisplayName), true)); } }
/// <summary> /// Renders the rendering. /// /// </summary> /// <param name="output">The output.</param><param name="rendering">The rendering.</param><param name="renderingDefinition">The rendering definition.</param><param name="index">The index.</param> private void RenderRendering(HtmlTextWriter output, Item rendering, RenderingDefinition renderingDefinition, int index) { Assert.ArgumentNotNull((object)output, "output"); Assert.ArgumentNotNull((object)rendering, "rendering"); Assert.ArgumentNotNull((object)renderingDefinition, "renderingDefinition"); string str1 = rendering.DisplayName; if (rendering.ID == RenderingIDs.FieldRenderer) { string @string = StringUtil.GetString(new string[1] { WebUtil.ParseQueryString(StringUtil.GetString(new string[1] { renderingDefinition.Parameters }))["FieldName"] }); if (!string.IsNullOrEmpty(@string)) { TemplateFieldItem templateFieldItem = (TemplateFieldItem)rendering.Database.GetItem(@string); if (templateFieldItem != null) { str1 = "\"" + StringUtil.GetString(new string[2] { templateFieldItem.Title, templateFieldItem.Name }) + "\" " + Translate.Text("Field"); } else { str1 = Translate.Text("[unknown field]"); } } else { str1 = Translate.Text("[unknown field]"); } } string str2 = string.Empty; string qualifiedKey = this.GetQualifiedKey(); Item placeholderItem = Sitecore.Context.Page.GetPlaceholderItem(this, Sitecore.Context.Database); if (placeholderItem != null) { str2 = placeholderItem["Allowed Controls"]; } string str3 = "javascript:return window.parent.scForm.postEvent(this,event,'pagedesigner:editplaceholder(placeholdername=" + (object)qualifiedKey + ",allowedrenderings=" + str2 + ",index=" + (string)(object)index + ")')"; output.Write("<a href=\"#\" style=\"display:block;color:black;background:#e2ebf8;border:1px solid #97b3e1;font:8pt tahoma;padding:4px;margin:3px 0px 0px 0px;text-decoration:none\" onclick=\"" + str3 + "\" onmouseover=\"javascript:this.style.textDecoration='underline'\" onmouseout=\"javascript:this.style.textDecoration='none'\">"); output.Write(ItemTileService.RenderTile(rendering, TileView.IconOnly, ImageDimension.id16x16)); output.Write(' '); output.Write(str1); output.Write("</a>"); }
private bool CreateItemProperty(string propertyName, TemplateFieldItem sitecoreField, CodeTypeMemberCollection members) { var type = _fieldMappingProvider.GetFieldType(sitecoreField.Type); if (type == null) { Log.Warn("Synthesis: Field type resolution for " + sitecoreField.InnerItem.Parent.Parent.Name + "::" + sitecoreField.Name + " failed; no mapping found for field type " + sitecoreField.Type, this); return(false); } var backingFieldName = "_" + propertyName[0].ToString(CultureInfo.InvariantCulture).ToLower() + propertyName.Substring(1); var backingField = new CodeMemberField(new CodeTypeReference(type), backingFieldName); backingField.Attributes = MemberAttributes.Private; var property = new CodeMemberProperty { // ReSharper disable BitwiseOperatorOnEnumWithoutFlags Attributes = MemberAttributes.Public | MemberAttributes.Final, // ReSharper restore BitwiseOperatorOnEnumWithoutFlags Type = new CodeTypeReference(type), Name = propertyName, HasGet = true }; // add [IndexField] attribute property.CustomAttributes.Add(GetIndexFieldAttribute(sitecoreField.Name)); // if(backingField == null) // backingField = new SynthesisFieldType(new Lazy<Field>(() => InnerItem.Fields["xxx"], GetSearchFieldValue("index-field-name")); var initializerLambda = new CodeSnippetExpression(string.Format("new global::System.Lazy<global::Sitecore.Data.Fields.Field>(() => InnerItem.Fields[\"{0}\"])", sitecoreField.ID)); var initializerSearchReference = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "GetSearchFieldValue", new CodePrimitiveExpression(_indexFieldNameTranslator.GetIndexFieldName(sitecoreField.Name))); var backingFieldNullCheck = new CodeConditionStatement(); backingFieldNullCheck.Condition = new CodeSnippetExpression(string.Format("{0} == null", backingFieldName)); backingFieldNullCheck.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression(backingFieldName), new CodeObjectCreateExpression(property.Type, initializerLambda, initializerSearchReference))); property.GetStatements.Add(backingFieldNullCheck); // return backingField; property.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression(backingFieldName))); AddCommentsToFieldProperty(property, sitecoreField); members.Add(backingField); members.Add(property); return(true); }
/// <summary> /// Using the sitecore settings, return the proper return type for the passed in /// field. /// </summary> /// <param name="field">The field.</param> /// <returns></returns> public static string GetFieldReturnType(TemplateFieldItem field) { string fieldType = field.Type.ToLower(); CustomItemSettings settings = new CustomItemSettings(HttpContext.Current); foreach (FieldMapping fieldMapping in settings.FieldMappings) { if (fieldMapping.SitecoreFieldType.ToLower() != fieldType) continue; return fieldMapping.FieldReturnType; } return string.Empty; }
/// <summary> /// Using the sitecore settings, return the proper return type for the passed in /// field. /// </summary> /// <param name="field">The field.</param> /// <returns></returns> public static string GetFieldReturnType(TemplateFieldItem field) { string fieldType = field.Type.ToLower(); CustomItemSettings settings = new CustomItemSettings(HttpContext.Current); foreach (FieldMapping fieldMapping in settings.FieldMappings) { if (fieldMapping.SitecoreFieldType.ToLower() != fieldType) { continue; } return(fieldMapping.FieldReturnType); } return(string.Empty); }
public virtual void Process([NotNull] ProcessSharepointItemArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.IsNotNullOrEmpty(args.SourceIntegrationItemName, "args.SourceIntegrationItemName"); Assert.IsNotNull(args.SourceIntegrationItemTemplateID, "args.SourceIntegrationItemTemplateID"); Assert.IsNotNull(args.SynchContext, "args.SynchContext"); TemplateItem templateItem = args.SynchContext.Database.GetTemplate(args.SourceIntegrationItemTemplateID); if (templateItem == null) { return; } TemplateFieldItem blobTemplateField = templateItem.GetField(FieldNames.Blob); if (blobTemplateField != null && blobTemplateField.Type.ToLower() == "attachment") { try { var sourceItem = args.SourceIntegrationItem; args.SharepointItem = SharepointItemProvider.CreateDocumentItem(args.SourceIntegrationItemName, args.SynchContext, sourceItem.Fields[FieldNames.Blob].GetBlobStream()); using (new EditContext(sourceItem)) { if (sourceItem.Fields[FieldNames.SharepointDataModified] != null) { DateTime owsModified = Convert.ToDateTime(args.SharepointItem["ows_Modified"]); sourceItem[FieldNames.SharepointDataModified] = DateUtil.ToIsoDate(owsModified); } } } catch (Exception e) { args.AddMessage(e.Message); args.AbortPipeline(); } } if (args.SourceIntegrationItemTemplateID == TemplateIDs.IntegrationFolder) { args.SharepointItem = SharepointItemProvider.CreateFolderItem(args.SourceIntegrationItemName, args.SynchContext); } }
private CodeMemberProperty CreateInterfaceProperty(string propertyName, TemplateFieldItem sitecoreField) { var type = _fieldMappingProvider.GetFieldType(sitecoreField.Type); if (type == null) { Log.Warn("Synthesis: Field type resolution (interface) for " + sitecoreField.InnerItem.Parent.Parent.Name + "::" + sitecoreField.Name + " failed; no mapping found for field type " + sitecoreField.Type, this); return(null); } var property = new CodeMemberProperty { Type = new CodeTypeReference(type), Name = propertyName, HasGet = true }; // add [IndexField] attribute property.CustomAttributes.Add(GetIndexFieldAttribute(sitecoreField.Name)); AddCommentsToFieldProperty(property, sitecoreField); return(property); }
public FieldInformation(TemplateFieldItem fieldItem) : this(fieldItem.Name, TemplateUtil.GetFieldReturnType(fieldItem), fieldItem.ID.ToString()) { }
/// <summary> /// Determine if a field is not present in the excluded field set /// </summary> public bool IsFieldIncluded(TemplateFieldItem field) { if (_excludedFields == null) RefreshSpecTargets(); // ReSharper disable PossibleNullReferenceException return !_excludedFields.Contains(field.ID); // ReSharper restore PossibleNullReferenceException }
private static bool IsEditableField(TemplateFieldItem x) { return(!x.Name.StartsWith("__")); }
private void OnClickTemplatize(object source, LinkLabelLinkClickedEventArgs e) { if (this._propChangesPending) { this.SaveFieldProperties(); } TemplateField templateField = this._currentFieldItem.GetTemplateField(this.Control); TemplateFieldItem item = new TemplateFieldItem(this, templateField); item.LoadFieldInfo(); this._selFieldsList.Items[this._currentFieldItem.Index] = item; this._currentFieldItem = item; this._currentFieldItem.Selected = true; this.UpdateEnabledVisibleState(); }
/// <summary> /// Renders the sublayout. /// /// </summary> /// <param name="output">The output.</param><param name="rendering">The rendering.</param><param name="renderingDefinition">The rendering definition.</param><param name="index">The index.</param> private void RenderSublayout(HtmlTextWriter output, Item rendering, RenderingDefinition renderingDefinition, int index) { Assert.ArgumentNotNull((object)output, "output"); Assert.ArgumentNotNull((object)rendering, "rendering"); Assert.ArgumentNotNull((object)renderingDefinition, "renderingDefinition"); foreach (Control control in this.Controls) { Sublayout sublayout = control as Sublayout; if (sublayout != null && string.Compare(sublayout.Path, rendering["Path"], StringComparison.InvariantCulture) == 0) { output.Write("<table width=\"100%\" style=\"table-layout:fixed;background:#e2ebf8;border:1px solid #97b3e1;margin:3px 0px 0px 0px\" cellpadding=\"2\" cellspacing=\"0\" border=\"0\">"); output.Write("<tr><td>"); string str1 = rendering.DisplayName; if (rendering.ID == RenderingIDs.FieldRenderer) { string @string = StringUtil.GetString(new string[1] { WebUtil.ParseQueryString(renderingDefinition.Parameters)["FieldName"] }); if (!string.IsNullOrEmpty(@string)) { TemplateFieldItem templateFieldItem = (TemplateFieldItem)rendering.Database.GetItem(@string); if (templateFieldItem != null) { str1 = "\"" + StringUtil.GetString(new string[2] { templateFieldItem.Title, templateFieldItem.Name }) + "\" " + Translate.Text("Field"); } else { str1 = Translate.Text("[unknown field]"); } } else { str1 = Translate.Text("[unknown field]"); } } string str2 = string.Empty; string qualifiedKey = this.GetQualifiedKey(); Item placeholderItem = Sitecore.Context.Page.GetPlaceholderItem(this, Sitecore.Context.Database); if (placeholderItem != null) { str2 = placeholderItem["Allowed Controls"]; } string str3 = "javascript:return window.parent.scForm.postEvent(this,event,'pagedesigner:editplaceholder(placeholdername=" + (object)qualifiedKey + ",allowedrenderings=" + str2 + ",index=" + (string)(object)index + ")')"; output.Write("<a href=\"#\" style=\"display:block;color:black;font:8pt tahoma;padding:2px 2px 0px 2px;text-decoration:none\" onclick=\"" + str3 + "\" onmouseover=\"javascript:this.style.textDecoration='underline'\" onmouseout=\"javascript:this.style.textDecoration='none'\">"); output.Write(ItemTileService.RenderTile(rendering, TileView.IconOnly, ImageDimension.id16x16)); output.Write(' '); output.Write(str1); output.Write("</a>"); output.Write("</td></tr>"); output.Write("<tr><td>"); ((Control)sublayout).RenderControl(output); output.Write("</td></tr></table>"); break; } } }
public ItemTemplateFieldInfo(TemplateFieldItem field) { Assert.ArgumentNotNull(field, "field"); _field = field; }
public FieldComparisonInfo(TemplateFieldItem tfi) : this() { this.ID = tfi.ID.ToString(); this.Name = tfi.Name; }
public ItemTemplateFieldInfo(TemplateFieldItem field) { Assert.ArgumentNotNull(field, "field"); _field = field; }
/// <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); }
private static void AddCommentsToFieldProperty(CodeMemberProperty property, TemplateFieldItem field) { if (!string.IsNullOrEmpty(field.Description)) property.Comments.Add(new CodeCommentStatement("<summary>" + field.Description + "</summary>", true)); else property.Comments.Add(new CodeCommentStatement(string.Format("<summary>Represents the {0} field</summary>", field.DisplayName), true)); }
public ItemTemplateFieldInfo(TemplateFieldItem field, ITemplateInfo template) : this(field) { Assert.ArgumentNotNull(template, "template"); Template = template; }
public FieldInformation(TemplateFieldItem fieldItem) : this(fieldItem.Name, TemplateUtil.GetFieldReturnType(fieldItem), fieldItem.ID.ToString()) { }
private void LoadFields() { DataControlFieldCollection fieldCollection = this.FieldCollection; if (fieldCollection != null) { int count = fieldCollection.Count; IDataSourceViewSchema viewSchema = this.GetViewSchema(); for (int i = 0; i < count; i++) { DataControlField runtimeField = fieldCollection[i]; FieldItem item = null; System.Type key = runtimeField.GetType(); if (key == typeof(CheckBoxField)) { item = new CheckBoxFieldItem(this, (CheckBoxField) runtimeField); } else if (key == typeof(BoundField)) { item = new BoundFieldItem(this, (BoundField) runtimeField); } else if (key == typeof(ButtonField)) { item = new ButtonFieldItem(this, (ButtonField) runtimeField); } else if (key == typeof(HyperLinkField)) { item = new HyperLinkFieldItem(this, (HyperLinkField) runtimeField); } else if (key == typeof(TemplateField)) { item = new TemplateFieldItem(this, (TemplateField) runtimeField); } else if (key == typeof(CommandField)) { item = new CommandFieldItem(this, (CommandField) runtimeField); } else if (key == typeof(ImageField)) { item = new ImageFieldItem(this, (ImageField) runtimeField); } else if (this._customFieldDesigners.ContainsKey(key)) { item = new DataControlFieldDesignerItem(this._customFieldDesigners[key], runtimeField); } else { item = new CustomFieldItem(this, runtimeField); } item.LoadFieldInfo(); IDataSourceViewSchemaAccessor accessor = item.RuntimeField; if (accessor != null) { accessor.DataSourceViewSchema = viewSchema; } this._selFieldsList.Items.Add(item); } if (this._selFieldsList.Items.Count != 0) { this._currentFieldItem = (FieldItem) this._selFieldsList.Items[0]; this._currentFieldItem.Selected = true; } } }
private CodeMemberProperty CreateInterfaceProperty(string propertyName, TemplateFieldItem sitecoreField) { var type = _fieldMappingProvider.GetFieldType(sitecoreField); if (type == null) { Log.Warn("Synthesis: Field type resolution (interface) for " + sitecoreField.InnerItem.Parent.Parent.Name + "::" + sitecoreField.Name + " failed; no mapping found for field type " + sitecoreField.Type, this); return null; } var property = new CodeMemberProperty { Type = new CodeTypeReference(type.PublicFieldType), Name = propertyName, HasGet = true }; // add [IndexField] attribute property.CustomAttributes.Add(GetIndexFieldAttribute(sitecoreField.Name)); AddCommentsToFieldProperty(property, sitecoreField); return property; }
public ItemTemplateFieldInfo(TemplateFieldItem field, ITemplateInfo template) : this(field) { Assert.ArgumentNotNull(template, "template"); Template = template; }
/// <summary> /// Gets the values. /// </summary> /// <param name="field">The field.</param> /// <param name="datasource">The datasource.</param> /// <returns>Returns the values.</returns> private string GetValues(TemplateFieldItem field, string datasource) { if (string.IsNullOrEmpty(datasource)) { return string.Empty; } var root = field.InnerItem.Database.GetItem(datasource); if (root == null) { return string.Empty; } return "Values: " + string.Join(", ", root.Children.Select(i => "<code>" + i.Name + "</code>")); }
private bool CreateItemProperty(string propertyName, TemplateFieldItem sitecoreField, CodeTypeMemberCollection members) { var type = _fieldMappingProvider.GetFieldType(sitecoreField); if(type == null) { Log.Warn("Synthesis: Field type resolution for " + sitecoreField.InnerItem.Parent.Parent.Name + "::" + sitecoreField.Name + " failed; no mapping found for field type " + sitecoreField.Type, this); return false; } var backingFieldName = "_" + propertyName[0].ToString(CultureInfo.InvariantCulture).ToLower() + propertyName.Substring(1); var backingField = new CodeMemberField(new CodeTypeReference(type.InternalFieldType), backingFieldName); backingField.Attributes = MemberAttributes.Private; var property = new CodeMemberProperty { // ReSharper disable BitwiseOperatorOnEnumWithoutFlags Attributes = MemberAttributes.Public | MemberAttributes.Final, // ReSharper restore BitwiseOperatorOnEnumWithoutFlags Type = new CodeTypeReference(type.PublicFieldType), Name = propertyName, HasGet = true }; // add [IndexField] attribute property.CustomAttributes.Add(GetIndexFieldAttribute(sitecoreField.Name)); // if(backingField == null) // backingField = new SynthesisFieldType(new Lazy<Field>(() => InnerItem.Fields["xxx"], GetSearchFieldValue("index-field-name")); var initializerLambda = new CodeSnippetExpression(string.Format("new global::Synthesis.FieldTypes.LazyField(() => InnerItem.Fields[\"{0}\"], \"{1}\", \"{2}\")", sitecoreField.ID, sitecoreField.Template.InnerItem.Paths.FullPath, sitecoreField.Name)); var initializerSearchReference = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "GetSearchFieldValue", new CodePrimitiveExpression(_indexFieldNameTranslator.GetIndexFieldName(sitecoreField.Name))); var backingFieldNullCheck = new CodeConditionStatement(); backingFieldNullCheck.Condition = new CodeSnippetExpression(string.Format("{0} == null", backingFieldName)); backingFieldNullCheck.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression(backingFieldName), new CodeObjectCreateExpression(type.InternalFieldType, initializerLambda, initializerSearchReference))); property.GetStatements.Add(backingFieldNullCheck); // return backingField; property.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression(backingFieldName))); AddCommentsToFieldProperty(property, sitecoreField); members.Add(backingField); members.Add(property); return true; }