private EntityModelData CreateEntityModelData(IComponentMeta componentMeta)
        {
            ContentModelData standardMeta = new ContentModelData();

            foreach (DictionaryEntry entry in componentMeta.CustomMeta.NameValues)
            {
                standardMeta.Add(entry.Key.ToString(), ((NameValuePair)entry.Value).Value);
            }

            // The semantic mapping requires that some metadata fields exist. This may not be the case so we map some component meta properties onto them
            // if they don't exist.
            if (!standardMeta.ContainsKey("dateCreated"))
            {
                standardMeta.Add("dateCreated", componentMeta.LastPublicationDate);
            }
            if (!standardMeta.ContainsKey("name"))
            {
                standardMeta.Add("name", componentMeta.Title);
            }

            return(new EntityModelData
            {
                Id = componentMeta.Id.ToString(),
                SchemaId = componentMeta.SchemaId.ToString(),
                Metadata = new ContentModelData {
                    { "standardMeta", standardMeta }
                }
            });
        }
Ejemplo n.º 2
0
        protected virtual EntityModelData CreateEntityModelData(Component component)
        {
            ContentModelData standardMeta = new ContentModelData();

            foreach (var meta in component.CustomMetas.Edges)
            {
                standardMeta.Add(meta.Node.Key, meta.Node.Value);
            }

            // The semantic mapping requires that some metadata fields exist. This may not be the case so we map some component meta properties onto them
            // if they don't exist.
            if (!standardMeta.ContainsKey("dateCreated"))
            {
                standardMeta.Add("dateCreated", component.LastPublishDate);
            }
            const string dateTimeFormat = "MM/dd/yyyy HH:mm:ss";

            standardMeta["dateCreated"] = DateTime.ParseExact((string)standardMeta["dateCreated"], dateTimeFormat, null);
            if (!standardMeta.ContainsKey("name"))
            {
                standardMeta.Add("name", component.Title);
            }
            return(new EntityModelData
            {
                Id = component.ItemId.ToString(),
                SchemaId = component.SchemaId.ToString(),
                Metadata = new ContentModelData {
                    { "standardMeta", standardMeta }
                }
            });
        }
        protected virtual EntityModelData CreateEntityModelData(Component component)
        {
            ContentModelData standardMeta = new ContentModelData();
            var groups = component.CustomMetas.Edges.GroupBy(x => x.Node.Key).ToList();

            foreach (var group in groups)
            {
                var values = group.Select(x => x.Node.Value).ToArray();
                if (values.Length == 1)
                {
                    standardMeta.Add(group.Key, values[0]);
                }
                else
                {
                    standardMeta.Add(group.Key, values);
                }
            }

            // The semantic mapping requires that some metadata fields exist. This may not be the case so we map some component meta properties onto them
            // if they don't exist.
            const string dateCreated = "dateCreated";

            if (!standardMeta.ContainsKey(dateCreated))
            {
                standardMeta.Add(dateCreated, component.LastPublishDate);
            }
            else
            {
                if (standardMeta[dateCreated] is string[])
                {
                    standardMeta[dateCreated] = ((string[])standardMeta[dateCreated])[0];
                }
            }
            const string dateTimeFormat = "MM/dd/yyyy HH:mm:ss";

            standardMeta["dateCreated"] = DateTime.ParseExact((string)standardMeta[dateCreated], dateTimeFormat, null);
            if (!standardMeta.ContainsKey("name"))
            {
                standardMeta.Add("name", component.Title);
            }
            return(new EntityModelData
            {
                Id = component.ItemId.ToString(),
                SchemaId = component.SchemaId.ToString(),
                Metadata = new ContentModelData {
                    { "standardMeta", standardMeta }
                }
            });
        }
        protected static ContentModelData MergeFields(ContentModelData primaryFields, ContentModelData secondaryFields, out string[] duplicateFieldNames)
        {
            List <string> duplicates = new List <string>();

            ContentModelData result;

            if (secondaryFields == null)
            {
                result = primaryFields;
            }
            else if (primaryFields == null)
            {
                result = secondaryFields;
            }
            else
            {
                result = primaryFields;
                foreach (KeyValuePair <string, object> field in secondaryFields)
                {
                    if (result.ContainsKey(field.Key))
                    {
                        duplicates.Add(field.Key);
                    }
                    else
                    {
                        result.Add(field.Key, field.Value);
                    }
                }
            }

            duplicateFieldNames = duplicates.ToArray();
            return(result);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Builds a strongly typed Entity Model based on a given DXA R2 Data Model.
 /// </summary>
 /// <param name="entityModel">The strongly typed Entity Model to build. Is <c>null</c> for the first Entity Model Builder in the pipeline.</param>
 /// <param name="entityModelData">The DXA R2 Data Model.</param>
 /// <param name="baseModelType">The base type for the Entity Model to build.</param>
 /// <param name="localization">The context <see cref="Localization"/>.</param>
 public void BuildEntityModel(ref EntityModel entityModel, EntityModelData entityModelData, Type baseModelType, Localization localization)
 {
     using (new Tracer(entityModel, entityModelData, baseModelType, localization))
     {
         IDictionary <string, object> extensionData = entityModel.ExtensionData;
         if (extensionData == null)
         {
             return;
         }
         object contextExpression;
         extensionData.TryGetValue("ContextExpressions", out contextExpression);
         if (contextExpression == null)
         {
             return;
         }
         ContentModelData            contextExpressionData = (ContentModelData)contextExpression;
         ContextExpressionConditions cxConditions          = new ContextExpressionConditions();
         if (contextExpressionData.ContainsKey("Include"))
         {
             if (contextExpressionData["Include"] is string[])
             {
                 cxConditions.Include = (string[])contextExpressionData["Include"];
             }
             else
             {
                 cxConditions.Include = new string[] { (string)contextExpressionData["Include"] };
             }
         }
         if (contextExpressionData.ContainsKey("Exclude"))
         {
             if (contextExpressionData["Exclude"] is string[])
             {
                 cxConditions.Exclude = (string[])contextExpressionData["Exclude"];
             }
             else
             {
                 cxConditions.Exclude = new string[] { (string)contextExpressionData["Exclude"] };
             }
         }
         extensionData.Remove("ContextExpressions");
         extensionData.Add(Constants.ContextExpressionsKey, cxConditions);
     }
 }
Ejemplo n.º 6
0
        private static T GetValue <T>(ContentModelData metadata, string name)
        {
            if (metadata == null || !metadata.ContainsKey(name))
            {
                return(default(T));
            }
            var v = metadata[name];

            if (v == null)
            {
                return(default(T));
            }
            if (typeof(T) == typeof(bool))
            {
                return((T)Convert.ChangeType(v.Equals("Yes"), typeof(T)));
            }
            return((T)Convert.ChangeType(v, typeof(T)));
        }
Ejemplo n.º 7
0
 private static ContentModelData UgcPostFormMetadata(ContentModelData metadata) => metadata != null && metadata.ContainsKey("postFormConfig")
   ? (ContentModelData)metadata["postFormConfig"]
   : null;
Ejemplo n.º 8
0
 private static ContentModelData UgcMetadata(ContentModelData metadata) => metadata != null && metadata.ContainsKey("ugcConfig")
     ? (ContentModelData)metadata["ugcConfig"]
     : null;