Example #1
0
        public bool IsMatch(IModel data, string key)
        {
            bool   result = false;
            string schemaRootElementName = null;

            if (data != null)
            {
                //Ideally we'd have a common interface for these 2 that have a Schema property
                if (data is IComponentPresentation)
                {
                    var definedData = data as IComponentPresentation;
                    schemaRootElementName = definedData.Component.Multimedia == null ? definedData.Component.Schema.RootElementName : definedData.Component.Schema.Title;
                }
                else if (data is IComponent)
                {
                    var definedData = data as IComponent;
                    schemaRootElementName = definedData.Multimedia == null ? definedData.Schema.RootElementName : definedData.Schema.Title;
                }
                else if (data is IEmbeddedFields)
                {
                    var definedData = data as IEmbeddedFields;
                    schemaRootElementName = definedData.EmbeddedSchema.RootElementName;
                }
                if (!String.IsNullOrEmpty(schemaRootElementName))
                {
                    var compare = new ContentModelAttribute(schemaRootElementName, false)
                    {
                        ViewModelKeys = key == null ? null : new string[] { key }
                    };
                    result = this.Equals(compare);
                }
            }
            return(result);
        }
Example #2
0
 public override bool Equals(object obj)
 {
     if (obj != null && obj is ContentModelAttribute)
     {
         ContentModelAttribute key = (ContentModelAttribute)obj;
         if (this.ViewModelKeys != null && key.ViewModelKeys != null)
         {
             //if both have a ViewModelKey set, use both ViewModelKey and schema
             //Check for a match anywhere in both lists
             var match = from i in this.ViewModelKeys.Select(a => a.ToLower())
                         join j in key.ViewModelKeys.Select(a => a.ToLower())
                         on i equals j
                         select i;
             //Schema names match and there is a matching view model ID
             if (this.SchemaRootElementName.Equals(key.SchemaRootElementName, StringComparison.OrdinalIgnoreCase) &&
                 match.Count() > 0)
             {
                 return(true);
             }
         }
         //Note: if the parent of a linked component is using a View Model Key, the View Model
         //for that linked component must either be Default with no View Model Keys, or it must
         //have the View Model Key of the parent View Model
         if (((this.ViewModelKeys == null || this.ViewModelKeys.Length == 0) && key.IsDefault) || //this set of IDs is empty and the input is default
             ((key.ViewModelKeys == null || key.ViewModelKeys.Length == 0) && this.IsDefault))    //input set of IDs is empty and this is default
         //if (key.IsDefault || this.IsDefault) //Fall back to default if the view model key isn't found -- useful for linked components
         {
             //Just compare the schema names
             return(this.SchemaRootElementName.Equals(key.SchemaRootElementName, StringComparison.OrdinalIgnoreCase));
         }
     }
     return(false);
 }
 public bool IsMatch(IModel data, string key)
 {
     bool result = false;
     string schemaRootElementName = null;
     if (data != null)
     {
         //Ideally we'd have a common interface for these 2 that have a Schema property
         if (data is IComponentPresentation)
         {
             var definedData = data as IComponentPresentation;
             schemaRootElementName = definedData.Component.Multimedia == null ? definedData.Component.Schema.RootElementName : definedData.Component.Schema.Title;
         }
         else if (data is IComponent)
         {
             var definedData = data as IComponent;
             schemaRootElementName = definedData.Multimedia == null ? definedData.Schema.RootElementName : definedData.Schema.Title;
         }
         else if (data is IEmbeddedFields)
         {
             var definedData = data as IEmbeddedFields;
             schemaRootElementName = definedData.EmbeddedSchema.RootElementName;
         }
         if (!String.IsNullOrEmpty(schemaRootElementName))
         {
             var compare = new ContentModelAttribute(schemaRootElementName, false)
             {
                 ViewModelKeys = key == null ? null : new string[] { key }
             };
             result = this.Equals(compare);
         }
     }
     return result;
 }