Ejemplo n.º 1
0
        /// <summary>
        /// Deletes the property item
        /// </summary>
        /// <param name="MappingHolder">Mappings holder</param>
        /// <param name="Object">Object</param>
        /// <param name="PropertyID">Property ID</param>
        /// <returns>The result</returns>
        public override bool DeleteValue(MappingHolder MappingHolder, dynamic Object, string PropertyID)
        {
            if (MappingHolder == null)
            {
                return(false);
            }
            ClassType TempItem = Object;

            if (TempItem == null)
            {
                return(false);
            }
            var Mapping = (IAPIMapping <DataType>)MappingHolder[typeof(DataType).Name];

            if (Mapping == null)
            {
                return(false);
            }
            dynamic  TempValue = Mapping.Any(PropertyID, MappingHolder);
            DataType Value     = TempValue;

            if (!Mapping.CanDelete(Value))
            {
                return(false);
            }
            return(Mapping.Delete(PropertyID));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the value of the property from an object
        /// </summary>
        /// <param name="Object">Object to get the property from</param>
        /// <param name="Mappings">Mappings</param>
        /// <returns>The property specified</returns>
        public override dynamic GetValue(MappingHolder Mappings, dynamic Object)
        {
            if (Mappings == null || CompiledExpression == null)
            {
                return(false);
            }
            ClassType TempItem = Object;

            if (TempItem == null)
            {
                return(null);
            }
            var Mapping = (IAPIMapping <DataType>)Mappings[typeof(DataType).Name];

            if (Mapping == null)
            {
                return(new Dynamo(CompiledExpression(TempItem)));
            }
            var ReturnValue = new List <Dynamo>();

            foreach (DataType Item in CompiledExpression(TempItem))
            {
                if (Mapping.CanGet(Item))
                {
                    var ReturnItem = new Dynamo(Item);
                    ReturnValue.Add(ReturnItem.SubSet(Mapping.Properties.Where(x => x is IReference || x is IID)
                                                      .Select(x => x.Name)
                                                      .ToArray()));
                }
            }
            return(ReturnValue);
        }
        /// <summary>
        /// Gets the item specified of the mapped type
        /// </summary>
        /// <param name="ID">ID of the item</param>
        /// <param name="Mappings">Mappings</param>
        /// <param name="EmbeddedProperties">Properties to embed</param>
        /// <returns>The item specified</returns>
        public Dynamo Any(string ID, MappingHolder Mappings, params string[] EmbeddedProperties)
        {
            if (string.IsNullOrEmpty(ID))
            {
                throw new ArgumentNullException(nameof(ID));
            }
            ClassType Object = AnyFunc(ID);

            if (!CanGetFunc(Object))
            {
                return(null);
            }
            var    TempItem    = new Dynamo(Object);
            Dynamo ReturnValue = TempItem.SubSet(Properties.Where(x => x is IReference || x is IID)
                                                 .Select(x => x.Name)
                                                 .ToArray());
            string AbsoluteUri = HttpContext.Current != null?HttpContext.Current.Request.Url.AbsoluteUri.Left(HttpContext.Current.Request.Url.AbsoluteUri.IndexOf('?')) : "";

            if (!AbsoluteUri.EndsWith("/", StringComparison.Ordinal))
            {
                AbsoluteUri += "/";
            }
            foreach (IAPIProperty Property in Properties.Where(x => x is IMap))
            {
                ReturnValue[Property.Name] = EmbeddedProperties.Contains(Property.Name) ?
                                             (object)Property.GetValue(Mappings, TempItem) :
                                             (object)(AbsoluteUri + Property.Name);
            }
            return(ReturnValue);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the value of the property from an object
        /// </summary>
        /// <param name="Object">Object to get the property from</param>
        /// <param name="Mappings">Mappings</param>
        /// <returns>The property specified</returns>
        public override dynamic GetValue(MappingHolder Mappings, dynamic Object)
        {
            if (Mappings == null)
            {
                return(false);
            }
            ClassType TempItem = Object;

            if (TempItem == null)
            {
                return(null);
            }
            var Mapping = (IAPIMapping <DataType>)Mappings[typeof(DataType).Name];

            if (Mapping == null)
            {
                return(new Dynamo(CompiledExpression(TempItem)));
            }
            DataType Value = CompiledExpression(TempItem);

            if (!Mapping.CanGet(Value))
            {
                return(null);
            }
            var ReturnValue = new Dynamo(Value);

            return(ReturnValue.SubSet(Mapping.Properties.Where(x => x is IReference || x is IID)
                                      .Select(x => x.Name)
                                      .ToArray()));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Deletes the property item
        /// </summary>
        /// <param name="MappingHolder">Mappings holder</param>
        /// <param name="Object">Object</param>
        /// <param name="PropertyID">Property ID</param>
        /// <returns>The result</returns>
        public override bool DeleteValue(MappingHolder MappingHolder, dynamic Object, string PropertyID)
        {
            if (MappingHolder == null)
            {
                return(false);
            }
            ClassType TempItem = Object;

            if (TempItem == null)
            {
                return(false);
            }
            var Mapping = (IAPIMapping <DataType>)MappingHolder[typeof(DataType).Name];

            if (Mapping == null)
            {
                return(false);
            }
            var Value = CompiledExpression(TempItem);

            if (!Mapping.CanDelete(Value))
            {
                return(false);
            }
            return(Mapping.Delete(PropertyID));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Saves the property item
        /// </summary>
        /// <param name="MappingHolder">Mapping holder</param>
        /// <param name="Object">Object</param>
        /// <param name="Models">Models</param>
        /// <returns>True if it is saved, false otherwise</returns>
        public override bool SaveValue(MappingHolder MappingHolder, dynamic Object, IEnumerable <Dynamo> Models)
        {
            if (MappingHolder == null || CompiledExpression == null)
            {
                return(false);
            }
            ClassType TempItem = Object;

            if (TempItem == null)
            {
                return(false);
            }
            if (AssignExpression == null)
            {
                return(false);
            }
            var Mapping      = (IAPIMapping <DataType>)MappingHolder[typeof(DataType).Name];
            var ClassMapping = (IAPIMapping <ClassType>)MappingHolder[typeof(ClassType).Name];

            if (Mapping == null)
            {
                return(false);
            }
            if (Models == null)
            {
                return(false);
            }
            if (CompiledExpression(TempItem) == null)
            {
                AssignExpression(TempItem, new List <DataType>());
            }
            List <DataType> ListValues = CompiledExpression(TempItem).ToList <DataType>();

            foreach (Dynamo Model in Models)
            {
                if (Model == null)
                {
                    return(false);
                }
                dynamic TempModel = Model.SubSet(Mapping.Properties.Where(x => x is IReference || x is IID)
                                                 .Select(x => x.Name)
                                                 .ToArray());
                DataType Property = TempModel;
                DataType Value    = ListValues.FirstOrDefault(x => x.Equals(Property));
                if (Value == null)
                {
                    ListValues.Add(Property);
                    Mapping.SaveFunc(Property);
                }
                else
                {
                    TempModel.CopyTo(Value);
                    return(Mapping.SaveFunc(Value));
                }
            }
            AssignExpression(TempItem, ListValues);
            return(ClassMapping.SaveFunc(TempItem));
        }
        /// <summary>
        /// Gets the value of the property from an object
        /// </summary>
        /// <param name="Object">Object to get the property from</param>
        /// <param name="Mappings">Mappings</param>
        /// <returns>The property specified</returns>
        public override dynamic GetValue(MappingHolder Mappings, dynamic Object)
        {
            ClassType TempItem = Object;

            if (TempItem == null)
            {
                return(null);
            }
            return(CompiledExpression(TempItem));
        }
        /// <summary>
        /// Saves an item to a specific property item
        /// </summary>
        /// <param name="ID">Model ID</param>
        /// <param name="PropertyName">Property name</param>
        /// <param name="Models">Models</param>
        /// <param name="MappingHolder">Mapping holder</param>
        /// <returns>True if it is saved, false otherwise</returns>
        public bool SaveProperty(string ID, MappingHolder MappingHolder, string PropertyName, IEnumerable <Dynamo> Models)
        {
            if (string.IsNullOrEmpty(ID))
            {
                throw new ArgumentNullException(nameof(ID));
            }
            IAPIProperty PropertyObject = Properties.FirstOrDefault(x => string.Equals(x.Name, PropertyName, StringComparison.InvariantCultureIgnoreCase));

            if (PropertyObject == null)
            {
                return(false);
            }
            ClassType Object = AnyFunc(ID);

            if (!CanGetFunc(Object))
            {
                return(false);
            }
            return(PropertyObject.SaveValue(MappingHolder, Object, Models));
        }
        /// <summary>
        /// Gets a specific property from an object
        /// </summary>
        /// <param name="ID">ID of the item</param>
        /// <param name="EmbeddedProperties">Properties to embed</param>
        /// <param name="Mappings">Mappings</param>
        /// <param name="Property">Property name</param>
        /// <returns>The property specified</returns>
        public dynamic GetProperty(string ID, MappingHolder Mappings, string Property, params string[] EmbeddedProperties)
        {
            if (string.IsNullOrEmpty(ID))
            {
                throw new ArgumentNullException(nameof(ID));
            }
            IAPIProperty PropertyObject = Properties.FirstOrDefault(x => string.Equals(x.Name, Property, StringComparison.InvariantCultureIgnoreCase));

            if (PropertyObject == null)
            {
                return(null);
            }
            ClassType Object = AnyFunc(ID);

            if (!CanGetFunc(Object))
            {
                return(null);
            }
            return(PropertyObject.GetValue(Mappings, Object));
        }
        /// <summary>
        /// Deletes a specific property item
        /// </summary>
        /// <param name="ID">Model ID</param>
        /// <param name="MappingHolder">Mapping holder</param>
        /// <param name="PropertyName">Property name</param>
        /// <param name="PropertyID">Property ID</param>
        /// <returns>True if it is deleted, false otherwise</returns>
        public bool DeleteProperty(string ID, MappingHolder MappingHolder, string PropertyName, string PropertyID)
        {
            if (string.IsNullOrEmpty(ID))
            {
                throw new ArgumentNullException(nameof(ID));
            }
            var PropertyObject = Properties.FirstOrDefault(x => string.Equals(x.Name, PropertyName, StringComparison.InvariantCultureIgnoreCase));

            if (PropertyObject == null)
            {
                return(false);
            }
            var Object = AnyFunc(ID);

            if (!CanGetFunc(Object))
            {
                return(false);
            }
            return(PropertyObject.DeleteValue(MappingHolder, Object, PropertyID));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets all items of the mapped type
        /// </summary>
        /// <param name="EmbeddedProperties">Properties to embed</param>
        /// <param name="Mappings">Mappings</param>
        /// <returns>All items of the mapped type</returns>
        public IEnumerable <Dynamo> All(MappingHolder Mappings, params string[] EmbeddedProperties)
        {
            IEnumerable <ClassType> Objects = AllFunc();

            if (Objects == null)
            {
                Objects = new List <ClassType>();
            }
            var ReturnValue = new List <Dynamo>();

            foreach (ClassType Object in Objects)
            {
                if (CanGetFunc(Object))
                {
                    var    TempItem   = new Dynamo(Object);
                    Dynamo ReturnItem = TempItem.SubSet(Properties.Where(x => x is IReference || x is IID)
                                                        .Select(x => x.Name)
                                                        .ToArray());
                    string AbsoluteUri = HttpContext.Current != null?HttpContext.Current.Request.Url.AbsoluteUri.Left(HttpContext.Current.Request.Url.AbsoluteUri.IndexOf('?')) : "";

                    AbsoluteUri = AbsoluteUri.Check("");
                    if (!AbsoluteUri.EndsWith("/", StringComparison.Ordinal))
                    {
                        AbsoluteUri += "/";
                    }
                    AbsoluteUri += Properties.FirstOrDefault(x => x is IID).GetValue(Mappings, Object).ToString() + "/";
                    foreach (IAPIProperty Property in Properties.Where(x => x is IMap))
                    {
                        ReturnItem[Property.Name] = EmbeddedProperties.Contains(Property.Name) ?
                                                    (object)Property.GetValue(Mappings, TempItem) :
                                                    (object)(AbsoluteUri + Property.Name);
                    }
                    ReturnValue.Add(ReturnItem);
                }
            }
            return(ReturnValue);
        }
 /// <summary>
 /// Saves the property item
 /// </summary>
 /// <param name="MappingHolder">Mapping holder</param>
 /// <param name="Object">Object</param>
 /// <param name="Models">Models</param>
 /// <returns>True if it is saved, false otherwise</returns>
 public abstract bool SaveValue(MappingHolder MappingHolder, dynamic Object, IEnumerable <Dynamo> Models);
Ejemplo n.º 13
0
        /// <summary>
        /// Gets all items of the mapped type
        /// </summary>
        /// <param name="Mappings">The mapping holder</param>
        /// <param name="PageSize">Size of the page.</param>
        /// <param name="Page">The page specified</param>
        /// <param name="OrderBy">The order by clause</param>
        /// <param name="EmbeddedProperties">Properties to embed</param>
        /// <returns>All items of the mapped type</returns>
        public IEnumerable <Dynamo> Paged(MappingHolder Mappings, int PageSize, int Page, string[] OrderBy, string[] EmbeddedProperties)
        {
            if (OrderBy == null)
            {
                OrderBy = new string[0];
            }
            string OrderByClauseFinal = "";
            string Splitter           = "";

            foreach (string OrderByClause in OrderBy)
            {
                string[] SplitValues = OrderByClause.Split(' ');
                if (SplitValues.Length > 0)
                {
                    if (Properties.Where(x => x is IReference || x is IID).Any(x => string.Equals(x.Name, SplitValues[0], StringComparison.InvariantCulture)))
                    {
                        OrderByClauseFinal += Splitter + SplitValues[0];
                        if (SplitValues.Length > 1)
                        {
                            SplitValues[1]      = SplitValues[1].Equals("DESC", StringComparison.InvariantCultureIgnoreCase) ? "DESC" : "ASC";
                            OrderByClauseFinal += " " + SplitValues[1];
                        }
                        Splitter = ",";
                    }
                }
            }
            IEnumerable <ClassType> Objects = PagedFunc(PageSize, Page, OrderByClauseFinal);

            if (Objects == null)
            {
                Objects = new List <ClassType>();
            }
            var ReturnValue = new List <Dynamo>();

            foreach (ClassType Object in Objects)
            {
                if (CanGetFunc(Object))
                {
                    var    TempItem   = new Dynamo(Object);
                    Dynamo ReturnItem = TempItem.SubSet(Properties.Where(x => x is IReference || x is IID)
                                                        .Select(x => x.Name)
                                                        .ToArray());
                    string AbsoluteUri = HttpContext.Current != null?HttpContext.Current.Request.Url.AbsoluteUri.Left(HttpContext.Current.Request.Url.AbsoluteUri.IndexOf('?')) : "";

                    AbsoluteUri = AbsoluteUri.Check("");
                    if (!AbsoluteUri.EndsWith("/", StringComparison.Ordinal))
                    {
                        AbsoluteUri += "/";
                    }
                    AbsoluteUri += Properties.FirstOrDefault(x => x is IID).GetValue(Mappings, Object).ToString() + "/";
                    foreach (IAPIProperty Property in Properties.Where(x => x is IMap))
                    {
                        ReturnItem[Property.Name] = EmbeddedProperties.Contains(Property.Name) ?
                                                    (object)Property.GetValue(Mappings, TempItem) :
                                                    (object)(AbsoluteUri + Property.Name);
                    }
                    ReturnValue.Add(ReturnItem);
                }
            }
            return(ReturnValue);
        }
 /// <summary>
 /// Deletes the property item
 /// </summary>
 /// <param name="MappingHolder">Mappings holder</param>
 /// <param name="Object">Object</param>
 /// <param name="PropertyID">Property ID</param>
 /// <returns>The result</returns>
 public override bool DeleteValue(MappingHolder MappingHolder, dynamic Object, string PropertyID)
 {
     return(false);
 }
 /// <summary>
 /// Saves the property item
 /// </summary>
 /// <param name="MappingHolder">Mapping holder</param>
 /// <param name="Object">Object</param>
 /// <param name="Models">Models</param>
 /// <returns>True if it is saved, false otherwise</returns>
 public override bool SaveValue(MappingHolder MappingHolder, dynamic Object, IEnumerable <Dynamo> Models)
 {
     return(false);
 }
 /// <summary>
 /// Deletes the property item
 /// </summary>
 /// <param name="MappingHolder">Mappings holder</param>
 /// <param name="Object">Object</param>
 /// <param name="PropertyID">Property ID</param>
 /// <returns>The result</returns>
 public abstract bool DeleteValue(MappingHolder MappingHolder, dynamic Object, string PropertyID);
 /// <summary>
 /// Gets the value of the property from an object
 /// </summary>
 /// <param name="Object">Object to get the property from</param>
 /// <param name="Mappings">Mappings</param>
 /// <returns>The property specified</returns>
 public abstract dynamic GetValue(MappingHolder Mappings, dynamic Object);
Ejemplo n.º 18
0
 /// <summary>
 /// Gets the page count
 /// </summary>
 /// <param name="mappingHolder">The mapping holder.</param>
 /// <param name="PageSize">Size of the page.</param>
 /// <returns>The page count</returns>
 public int PageCount(MappingHolder mappingHolder, int PageSize)
 {
     return(PageCountFunc(PageSize));
 }