Exemplo n.º 1
0
        public CatalogueItem ShallowClone(Catalogue into)
        {
            var clone = new CatalogueItem(CatalogueRepository, into, Name);

            CopyShallowValuesTo(clone);
            return(clone);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Copies the descriptive metadata from one <see cref="CatalogueItem"/> (this) into a new <see cref="CatalogueItem"/> in the supplied <paramref name="cataToImportTo"/>
        /// </summary>
        /// <param name="cataToImportTo">The <see cref="Catalogue"/> to import into (cannot be the current <see cref="CatalogueItem"/> parent)</param>
        /// <returns></returns>
        public CatalogueItem CloneCatalogueItemWithIDIntoCatalogue(Catalogue cataToImportTo)
        {
            if (this.Catalogue_ID == cataToImportTo.ID)
            {
                throw new ArgumentException("Cannot clone a CatalogueItem into it's own parent, specify a different catalogue to clone into");
            }

            var clone = new CatalogueItem((ICatalogueRepository)cataToImportTo.Repository, cataToImportTo, this.Name);

            //Get all the properties
            PropertyInfo[] propertyInfo = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            //Assign all source property to taget object 's properties
            foreach (PropertyInfo property in propertyInfo)
            {
                //Check whether property can be written to
                if (property.CanWrite && !property.Name.Equals("ID") && !property.Name.Equals("Catalogue_ID"))
                {
                    if (property.PropertyType.IsValueType || property.PropertyType.IsEnum || property.PropertyType.Equals(typeof(System.String)))
                    {
                        property.SetValue(clone, property.GetValue(this, null), null);
                    }
                }
            }

            clone.SaveToDatabase();

            return(clone);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the maximum Order from all <see cref="ExtractionInformation"/> in the parent <see cref="Catalogue"/> of <paramref name="catalogueItem"/>.  Returns 1 if anything goes wrong or if there are no other ExtractionInformation yet
        /// </summary>
        /// <param name="catalogueItem"></param>
        /// <returns></returns>
        private int GetMaxOrder(CatalogueItem catalogueItem)
        {
            try
            {
                var cata = catalogueItem.Catalogue;
                cata.ClearAllInjections();

                var eiMax = cata.GetAllExtractionInformation(ExtractionCategory.Any).OrderByDescending(ei => ei.Order).FirstOrDefault();

                return(eiMax == null ? 1 : eiMax.Order + 1);
            }
            catch (Exception)
            {
                return(1);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Makes the given <see cref="CatalogueItem"/> which has an underlying column <see cref="ColumnInfo"/> in the data repository database extractable using the
        /// provided SQL code which must be a single line of SELECT sql.
        /// </summary>
        /// <param name="repository">Platform database to store the new object in</param>
        /// <param name="catalogueItem">The virtual column to make extractable (could be a transform e.g. YearOfBirth)</param>
        /// <param name="column">The column underlying the virtual column (e.g. `MyTable`.`DateOfBirth`)</param>
        /// <param name="selectSQL">The fully specified column name or transform SQL to execute as a line of SELECT Sql </param>
        public ExtractionInformation(ICatalogueRepository repository, CatalogueItem catalogueItem, ColumnInfo column, string selectSQL)
        {
            repository.InsertAndHydrate(this, new Dictionary <string, object>
            {
                { "SelectSQL", string.IsNullOrWhiteSpace(selectSQL) ? column.Name : selectSQL },
                { "Order", 1 },
                { "ExtractionCategory", ExtractionCategory.Core.ToString() },
                { "CatalogueItem_ID", catalogueItem.ID }
            });

            if (catalogueItem.ColumnInfo_ID == null)
            {
                repository.SaveSpecificPropertyOnlyToDatabase(catalogueItem, "ColumnInfo_ID", column.ID);
            }
            else
            if (catalogueItem.ColumnInfo_ID != column.ID)
            {
                throw new ArgumentException("Cannot create an ExtractionInformation for CatalogueItem " +
                                            catalogueItem + " with ColumnInfo " + column +
                                            " because the CatalogueItem is already associated with a different ColumnInfo: " +
                                            catalogueItem.ColumnInfo);
            }
            ClearAllInjections();
        }
Exemplo n.º 5
0
 /// <inheritdoc/>
 public void InjectKnown(CatalogueItem instance)
 {
     _knownCatalogueItem = new Lazy <CatalogueItem>(() => instance);
 }