Example #1
0
        /// <summary>
        /// Attempt to extract properties from the lookup metadata.
        /// The result of this operation is cached.
        /// </summary>
        /// <param name="lookupName"></param>
        /// <param name="entityTypeName"></param>
        /// <returns></returns>
        internal static LookupPropertyCollection GetLookupProperties(String lookupName, String entityTypeName)
        {
            LookupPropertyCollection result = null;

            if (HttpContext.Current != null &&
                ((result = HttpContext.Current.Cache["LookupProperties$" + entityTypeName + "$" + lookupName] as LookupPropertyCollection) != null))
            {
                return(result);
            }
            result = new LookupPropertyCollection();

            using (var sess = new SessionScopeWrapper())
            {
                Type entityType = Type.GetType(entityTypeName);
                if (entityType == null)
                {
                    throw new ArgumentException("Unable to locate type " + entityTypeName);
                }
                if (entityType.IsInterface)
                {
                    throw new ArgumentException("Must use the concrete class as EntityTypeName (e.g., Sage.SalesLogix.Entities.Contact)");
                }
                String entityName = ((SessionFactoryImpl)sess.SessionFactory).TryGetGuessEntityName(entityType);
                if (entityName == null)
                {
                    throw new ArgumentException("Unable to locate persister for entity type " + entityType.FullName);
                }
                AbstractEntityPersister persister = (AbstractEntityPersister)((SessionFactoryImpl)sess.SessionFactory).GetEntityPersister(entityName);
                foreach (LookupLayoutField lookupField in GetLookupFields(sess, persister.TableName, lookupName))
                {
                    String[] tableField = lookupField.Path.Split(new char[] { ':' });
                    if (persister == null || persister.TableName != tableField[0])
                    {
                        throw new ArgumentException("Invalid lookup data - table name does not match persister table (" + persister.TableName + " vs " + tableField[0] + ") - check EntityName setting");
                    }
                    String propName = DecomposePath((SessionFactoryImpl)sess.SessionFactory, persister, tableField[1], lookupField.Format);
                    if (propName != null)
                    {
                        result.Add(new LookupProperty(propName, lookupField.Caption));
                        // TODO: we should set the property format here
                    }
                }
            }
            if (LOG.IsDebugEnabled)
            {
                foreach (LookupProperty prop in result)
                {
                    LOG.Debug("Using property '" + prop.PropertyName + "' with header '" + prop.PropertyHeader + "'");
                }
            }
            if (HttpContext.Current != null)
            {
                HttpContext.Current.Cache["LookupProperties$" + entityTypeName + "$" + lookupName] = result;
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Attempt to extract properties from the lookup metadata.
        /// The result of this operation is cached.
        /// </summary>
        /// <param name="lookupName"></param>
        /// <param name="entityTypeName"></param>
        /// <returns></returns>
        internal static LookupPropertyCollection GetLookupProperties(String lookupName, String entityTypeName)
        {
            LookupPropertyCollection result = null;
            if (HttpContext.Current != null &&
                ((result = HttpContext.Current.Cache["LookupProperties$" + entityTypeName + "$" + lookupName] as LookupPropertyCollection) != null))
            {
                return result;
            }
            result = new LookupPropertyCollection();

            using (var sess = new SessionScopeWrapper())
            {
                Type entityType = Type.GetType(entityTypeName);
                if (entityType == null)
                    throw new ArgumentException("Unable to locate type " + entityTypeName);
                if (entityType.IsInterface)
                    throw new ArgumentException("Must use the concrete class as EntityTypeName (e.g., Sage.SalesLogix.Entities.Contact)");
                String entityName = ((SessionFactoryImpl)sess.SessionFactory).TryGetGuessEntityName(entityType);
                if (entityName == null)
                    throw new ArgumentException("Unable to locate persister for entity type " + entityType.FullName);
                AbstractEntityPersister persister = (AbstractEntityPersister)((SessionFactoryImpl)sess.SessionFactory).GetEntityPersister(entityName);
                foreach (LookupLayoutField lookupField in GetLookupFields(sess, persister.TableName, lookupName))
                {
                    String[] tableField = lookupField.Path.Split(new char[] { ':' });
                    if (persister == null || persister.TableName != tableField[0])
                    {
                        throw new ArgumentException("Invalid lookup data - table name does not match persister table (" + persister.TableName + " vs " + tableField[0] + ") - check EntityName setting");
                    }
                    String propName = DecomposePath((SessionFactoryImpl)sess.SessionFactory, persister, tableField[1], lookupField.Format);
                    if (propName != null)
                    {
                        result.Add(new LookupProperty(propName, lookupField.Caption));
                        // TODO: we should set the property format here
                    }
                }
            }
            if (LOG.IsDebugEnabled)
            {
                foreach (LookupProperty prop in result)
                {
                    LOG.Debug("Using property '" + prop.PropertyName + "' with header '" + prop.PropertyHeader + "'");
                }
            }
            if(HttpContext.Current != null)
                HttpContext.Current.Cache["LookupProperties$" + entityTypeName + "$" + lookupName] = result;
            return result;
        }