예제 #1
0
        public ActionResult SecurityGroupPermissionSelector(IMetaObject model)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            IRepository <SecurityGroup> securityGroupRepository = this.ServiceProvider.GetService <IRepository <SecurityGroup> >();
            List <SecurityGroup>        ToDisplay = new List <SecurityGroup>();

            foreach (IMetaObject o in model.CollectionItems)
            {
                SecurityGroup securityGroup = securityGroupRepository.Find(o.GetValue <System.Guid>(nameof(SecurityGroup.Guid)));

                if (securityGroup != null)
                {
                    ToDisplay.Add(securityGroup);
                }
            }

            model = new MetaObjectHolder(ToDisplay);

            InputListPageModel pageModel = new InputListPageModel(model, nameof(SecurityGroup.ExternalId), nameof(SecurityGroup.Guid), Urls.SEARCH);

            return(this.View("InputList", pageModel));
        }
예제 #2
0
 private void WriteMetaobjectDoc(IMetaObject metaObject, string text)
 {
     if (metaObject.HasDoc)
     {
         doc.AppendLine(metaObject.Doc.Text);
     }
 }
예제 #3
0
 /// <summary>
 /// Constructor that initializes all interface members and derived members, but
 /// Process defaults to true;
 /// </summary>
 /// <param name="dataObject">DataObject to sync.</param>
 /// <param name="identifier">Identifier of the sync action.</param>
 /// <param name="description">Description of the sync action.</param>
 /// <param name="type">Enumerated Type of data sync operations such as CreateUserTable.</param>
 /// <param name="script">SQL Query to be executed in SyncManager type objects.</param>
 public DataSyncAction(IMetaObject dataObject, string identifier, string description, DataSyncOperationType type, Func <string> script)
     : base(identifier, description)
 {
     DataObject   = dataObject;
     Type         = type;
     ScriptAction = script;
 }
예제 #4
0
        public InputListOptionPageModel(string labelProperty, string valueProperty, IMetaObject backingObject) : base(backingObject)
        {
            if (backingObject is null)
            {
                throw new System.ArgumentNullException(nameof(backingObject));
            }

            this.LabelPropertyName = labelProperty;
            this.ValuePropertyName = valueProperty;
            this.SourceType        = backingObject.Type;

            //If we cant find the value for the key on the object, we fall back to "ToString"
            //Generated by the serializer
            if (backingObject.HasProperty(this.ValuePropertyName))
            {
                this.Value = backingObject[this.ValuePropertyName].Value;
            }
            else
            {
                this.Value = backingObject.Value;
            }

            //If we cant find the Display property specified, we fall back on whatever we chose for the value
            if (backingObject.HasProperty(this.LabelPropertyName))
            {
                this.Label = backingObject[this.LabelPropertyName].Value;
            }
            else
            {
                this.Label = this.Value;
            }
        }
        /// <summary>
        /// Gets flags set on an enum property
        /// </summary>
        /// <param name="p">The propertyInfo</param>
        /// <param name="target">The instance of the object</param>
        /// <returns>A list of the set enum values</returns>
        public static IEnumerable <EnumValue> GetFlags(this IMetaProperty p, IMetaObject target)
        {
            if (p is null)
            {
                throw new System.ArgumentNullException(nameof(p));
            }

            if (target is null)
            {
                throw new System.ArgumentNullException(nameof(target));
            }

            if (!p.Type.HasAttribute <FlagsAttribute>())
            {
                throw new ArgumentException($"Property type {p.Type.FullName} does not have flags attribute");
            }

            long l = p.GetValue(target).Convert <long>();

            foreach (EnumValue thisValue in p.Type.Values)
            {
                long thisVal = thisValue.Value.Convert <long>();

                if (TestFlags(l, thisVal))
                {
                    yield return(thisValue);
                }
            }
        }
        private void SetUp(IMetaObject Model)
        {
            this.BackingObject = Model;

            this.SourceType = Model.Type;

            if (Model.GetCoreType() != CoreType.Collection)
            {
                this.ItemType = Model.Type;
                if (!Model.Null)
                {
                    this.SelectedItems.Add(
                        new InputListOptionPageModel(this.LabelPropertyName, this.ValuePropertyName, Model)
                    {
                        ItemType = this.ItemType
                    });
                }
            }
            else if (Model.GetCoreType() == CoreType.Collection)
            {
                //Add all of the currently selected items to the display box
                this.ItemType = Model.Template.Type;
                foreach (IMetaObject thisItem in Model.CollectionItems)
                {
                    InputListOptionPageModel optionModel = new InputListOptionPageModel(this.LabelPropertyName, this.ValuePropertyName, thisItem)
                    {
                        ItemType   = this.ItemType,
                        SourceType = this.SourceType
                    };

                    this.SelectedItems.Add(optionModel);
                }
            }
        }
        /// <summary>
        /// Constructs a new instance of the settings object
        /// </summary>
        /// <param name="o">An IMetaObject instance to render out</param>
        /// <param name="fileProvider">A file provider used for checking for the existence of views</param>
        public DynamicRendererSettings(IMetaObject o, IFileProvider fileProvider)
        {
            Contract.Requires(o != null);

            this.FileProvider = fileProvider;
            this.Type         = o.Type;
            this.TypeFullName = this.Type.FullName;
        }
        /// <summary>
        /// Gets the value of the object as its originally declared type. Probably only works for structs
        /// </summary>
        /// <param name="o">The object to get the value of </param>
        /// <returns>The object value, casted to its original type</returns>
        public static object GetTypedValue(this IMetaObject o)
        {
            if (o is null)
            {
                throw new System.ArgumentNullException(nameof(o));
            }

            return(o.GetValue(System.Type.GetType(o.Type.AssemblyQualifiedName)));
        }
예제 #9
0
        public static bool CompareObjectNames(IMetaObject sourceDataObject, IMetaObject targetDataObject, StringComparer stringComparer = null)
        {
            if (stringComparer == null)
            {
                stringComparer = StringComparer.OrdinalIgnoreCase;
            }

            return(stringComparer.Compare(sourceDataObject.ObjectName, targetDataObject.ObjectName) == 0);
        }
예제 #10
0
        public static bool IsRoot(this IMetaObject o)
        {
            if (o is null)
            {
                throw new ArgumentNullException(nameof(o));
            }

            return(o.Parent is null);
        }
        /// <summary>
        /// Gets the value of the object casted to the type variable
        /// </summary>
        /// <param name="o">The source</param>
        /// <param name="t">The type to cast the object as</param>
        /// <returns>The casted value</returns>
        public static object GetValue(this IMetaObject o, System.Type t)
        {
            if (o is null)
            {
                throw new System.ArgumentNullException(nameof(o));
            }

            return(o.Value.Convert(t));
        }
        /// <summary>
        /// Attempts to convert the MetaObject into Json
        /// </summary>
        /// <param name="o">The source object</param>
        /// <returns>A Json string representation of the object</returns>
        public static string ToJson(this IMetaObject o)
        {
            if (o is null)
            {
                throw new System.ArgumentNullException(nameof(o));
            }

            return(o.ToJson(new StringBuilder()).ToString());
        }
        /// <summary>
        /// Checks if a property of a matching IMetaProperty exists
        /// </summary>
        /// <param name="o">The source</param>
        /// <param name="property">The IMetaProperty to match against</param>
        /// <returns>A bool indicating whether or not the property exists</returns>
        public static bool HasProperty(this IMetaObject o, IMetaProperty property)
        {
            if (o is null)
            {
                throw new System.ArgumentNullException(nameof(o));
            }

            return(o.Properties.Any(p => p.Property.Name == property.Name));
        }
        /// <summary>
        /// Gets an IMetaAttribute based on the name (apparently)
        /// </summary>
        /// <param name="o">the source object</param>
        /// <param name="IMetaAttributeName">The attribute name</param>
        /// <returns>The attribute</returns>
        public static IMetaAttribute IMetaAttribute(this IMetaObject o, string IMetaAttributeName)
        {
            if (o is null)
            {
                throw new System.ArgumentNullException(nameof(o));
            }

            return(o.Property?.Attributes?.FirstOrDefault(a => a.Type.Name == IMetaAttributeName) ??
                   o.Type.Attributes.FirstOrDefault(a => a.Type.Name == IMetaAttributeName));
        }
        /// <summary>
        /// Constructs a new instance of the settings object
        /// </summary>
        /// <param name="o">An IMetaObject instance to render out</param>
        /// <param name="fileProvider">A file provider used for checking for the existence of views</param>
        public DynamicRendererSettings(IMetaObject o, IFileProvider fileProvider)
        {
            if (o is null)
            {
                throw new ArgumentNullException(nameof(o));
            }

            this.FileProvider = fileProvider;
            this.Type         = o.Type;
            this.TypeFullName = this.Type.FullName;
        }
        public InputListPageModel(IMetaObject Model, string searchUrl)
        {
            if (Model is null)
            {
                throw new System.ArgumentNullException(nameof(Model));
            }

            this.SearchUrl = searchUrl;

            this.SetUp(Model);
        }
예제 #17
0
 public static bool IsKey(IMetaObject o)
 {
     if (o?.Parent is IMetaObject parent)
     {
         return(o.Property.Name == GetKeyForType(parent, false));
     }
     else
     {
         return(false);
     }
 }
        public ActionResult EmailHandlerSelector(IMetaObject o)
        {
            if (o is null)
            {
                throw new ArgumentNullException(nameof(o));
            }

            return(this.View(new EmailHandlerSelectorPageModel(this.EmailHandlerService.GetHandlers())
            {
                Selected = o.Value
            }));
        }
        /// <summary>
        /// Gets the value of the property from the speficied source casted to specified type
        /// </summary>
        /// <typeparam name="T">The type to cast the return as</typeparam>
        /// <param name="p">The IMetaProperty defining the value to be returned</param>
        /// <param name="target">The source object</param>
        /// <returns>The source property casted to the specified type</returns>
        public static T GetValue <T>(this IMetaProperty p, IMetaObject target)
        {
            if (p is null)
            {
                throw new System.ArgumentNullException(nameof(p));
            }

            if (target is null)
            {
                throw new System.ArgumentNullException(nameof(target));
            }

            return(target.GetValue <T>(p.Name));
        }
        /// <summary>
        /// Gets the value of the property from the speficied source as a string
        /// </summary>
        /// <param name="p">The IMetaProperty defining the value to be returned</param>
        /// <param name="target">The source object</param>
        /// <returns>The value of the property from the speficied source as a string</returns>
        public static string GetValue(this IMetaProperty p, IMetaObject target)
        {
            if (p is null)
            {
                throw new System.ArgumentNullException(nameof(p));
            }

            if (target is null)
            {
                throw new System.ArgumentNullException(nameof(target));
            }

            return(target[p.Name].Value);
        }
        /// <summary>
        /// Gets the casted value of an object based on its IMetaProperty
        /// </summary>
        /// <typeparam name="T">The type to cast the value as</typeparam>
        /// <param name="o">The source object</param>
        /// <param name="property">The IMetaProperty to get</param>
        /// <returns>The casted value of an object based on its IMetaProperty</returns>
        public static T GetValue <T>(this IMetaObject o, IMetaProperty property)
        {
            if (o is null)
            {
                throw new System.ArgumentNullException(nameof(o));
            }

            if (property is null)
            {
                throw new System.ArgumentNullException(nameof(property));
            }

            return(GetValue <T>(o.GetProperty(property.Name)));
        }
        /// <summary>
        /// Gets flags set on an enum property
        /// </summary>
        /// <param name="p">The propertyInfo</param>
        /// <param name="target">The instance of the object</param>
        /// <param name="otherFlags">returns a long representing the value of all flags on the object value that aren't declared explicitely</param>
        /// <returns>A list of the set enum values</returns>
        public static IList <EnumValue> GetFlags(this IMetaProperty p, IMetaObject target, out long otherFlags)
        {
            otherFlags = p.GetValue(target).Convert <long>();

            List <EnumValue> toReturn = new List <EnumValue>();

            foreach (EnumValue thisValue in p.GetFlags(target))
            {
                toReturn.Add(thisValue);

                otherFlags &= ~thisValue.Value.Convert <long>();
            }

            return(toReturn);
        }
예제 #23
0
 public virtual void WriteDoc(IMetaObject metaObject)
 {
     if (!metaObject.HasDoc)
     {
         return;
     }
     foreach (string line in metaObject.Doc.LabelLines)
     {
         WriteCommentLine(line);
     }
     foreach (string line in metaObject.Doc.TextLines)
     {
         WriteCommentLine(line);
     }
 }
        public InputListPageModel(IMetaObject Model, string labelProperty, string valueProperty, string searchUrl)
        {
            if (Model is null)
            {
                throw new System.ArgumentNullException(nameof(Model));
            }

            this.SearchUrl = searchUrl;

            this.LabelPropertyName = labelProperty;

            this.ValuePropertyName = valueProperty;

            this.SetUp(Model);
        }
예제 #25
0
        public static IMetaObject GetRoot(this IMetaObject o)
        {
            if (o is null)
            {
                throw new ArgumentNullException(nameof(o));
            }

            IMetaObject parent = o;

            while (parent.Parent != null)
            {
                parent = parent.Parent;
            }

            return(parent !);
        }
예제 #26
0
        public static T FromDatabase <T>(this IMetaObject o, IServiceProvider serviceProvider) where T : KeyedObject
        {
            if (o is null)
            {
                throw new ArgumentNullException(nameof(o));
            }

            if (serviceProvider is null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            IKeyedObjectRepository <T> repo = (IKeyedObjectRepository <T>)serviceProvider.GetService(typeof(IRepository <T>));

            return(repo.Find(o[nameof(KeyedObject._Id)].GetValue <int>()));
        }
예제 #27
0
        //This should be merged with the function that takes an IType
        //but in order to do so, property attribute information needs to be added in the reflector
        //for the type object itself, which its not. It wouldn't be hard but this is a quick fix
        public static string?GetKeyForType(IMetaObject o, bool throwError = true)
        {
            if (o is null)
            {
                throw new ArgumentNullException(nameof(o));
            }

            if (o.Properties != null && o.Properties.Any(p => p.Property.HasAttribute <KeyAttribute>()))
            {
                return(o.Properties.First(p => p.Property.HasAttribute <KeyAttribute>()).Property.Name);
            }
            else
            {
                return(GetKeyForType(o.Type, throwError));
            }
        }
예제 #28
0
        public static Guid GetGuid(IMetaObject o)
        {
            if (o is null)
            {
                return(Guid.Empty);
            }

            if (o.Type.Is(typeof(Entity)))
            {
                return(Guid.Parse(o["Guid"].Value));
            }

            using MD5 md5 = MD5.Create();
            byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes($"{o.Type.FullName}_{o[GetKeyForType(o.Type)].Value}"));
            return(new Guid(hash));
        }
        /// <summary>
        /// Gets the view result containing editor view information for the current metaObject
        /// </summary>
        /// <param name="metaObject">The MetaObject to get view information for</param>
        /// <param name="requestContext">The current RequestContext</param>
        /// <param name="displayType">The type to be used when finding the view, if not the MetaObject type</param>
        /// <returns>A result containing editor view information</returns>
        protected DynamicViewResult?GetView(IMetaObject metaObject, DisplayContexts requestContext, IMetaType?displayType = null)
        {
            if (metaObject is null)
            {
                throw new ArgumentNullException(nameof(metaObject));
            }

            string BasePath = $"/Areas/Admin/Views/{requestContext}/";

            if (metaObject.IsRoot())
            {
                return(null);
            }

            IMetaProperty property = metaObject.Property;

            displayType ??= GetDisplayType(metaObject);

            string Key = $"{displayType.AssemblyQualifiedName}+{property?.Name}+{requestContext}";

            if (!Views.TryGetValue(Key, out string?path))
            {
                DynamicRenderer renderer = new DynamicRenderer(new DynamicRendererSettings(displayType, property, this.FileProvider)
                {
                    BasePath = BasePath
                });

                if (renderer.IsDynamic)
                {
                    Views.TryAdd(Key, null);
                }
                else
                {
                    path = renderer.MatchedPath;
                    Views.TryAdd(Key, path);
                }
            }

            if (string.IsNullOrWhiteSpace(path))
            {
                return(null);
            }
            else
            {
                return(new DynamicViewResult(path));
            }
        }
예제 #30
0
 public override void WriteDoc(IMetaObject metaObject)
 {
     if (!metaObject.HasDoc)
     {
         return;
     }
     WriteLine("/// <summary>");
     foreach (string line in metaObject.Doc.LabelLines)
     {
         WriteLine("/// {0}", line);
     }
     foreach (string line in metaObject.Doc.TextLines)
     {
         WriteLine("/// {0}", line);
     }
     WriteLine("/// </summary>");
 }