/// <summary>
        /// 返回存储某类型的所有属性和自定义属性(BindingFieldAttribute)的Dic。
        /// </summary>
        /// <param name="objType">类型(类、接口、枚举等)</param>
        /// <returns>属性和自定义属性(BindingFieldAttribute)的集合</returns>
        public static Dictionary <string, PropertyInfo> GetPropertyInfoDic(Type objType)
        {
            string cachekey = string.Format("DIC_{0}", objType.FullName);
            Dictionary <string, PropertyInfo> propDic = (Dictionary <string, PropertyInfo>)DSCache.Get(cachekey);

            if (propDic == null)
            {
                propDic = new Dictionary <string, PropertyInfo>();
                List <PropertyInfo> propList = GetPropertyInfoList(objType);
                foreach (PropertyInfo pi in propList)
                {
                    object[] customAtts = pi.GetCustomAttributes(typeof(BindingFieldAttribute), true);
                    if (customAtts != null && customAtts.Length > 0)
                    {
                        string key = ((BindingFieldAttribute)customAtts[0]).FieldName;
                        if (string.IsNullOrEmpty(key))
                        {
                            key = pi.Name.ToUpper();
                        }
                        propDic.Add(key, pi);
                    }
                }
                DSCache.Insert(cachekey, propDic);
            }
            return(propDic);
        }
Пример #2
0
        /// <summary>
        /// Factory building a cache using to optimize the notification effect
        /// Virtual method (in sub class, define it the order of tables to notify)
        /// </summary>
        /// <param name="schema"></param>
        /// <returns></returns>
        public override DSCache GetCache(DSDatabase schema)
        {
            DSCache cache = base.GetCache(schema);

            // Référentiel

            cache.AddTable("Parameter");

            return cache;
        }
Пример #3
0
        /// <summary>
        /// Factory building a cache using to optimize the notification effect
        /// Virtual method (in sub class, define it the order of tables to notify)
        /// </summary>
        /// <param name="schema"></param>
        /// <returns></returns>
        public override DSCache GetCache(DSDatabase schema)
        {
            DSCache cache = base.GetCache(schema);

            // Administration

            cache.AddTable("Customer");
            cache.AddTable("Language");
            cache.AddTable("User");
            cache.AddTable("Module");
            cache.AddTable("UserModule");

            return(cache);
        }
Пример #4
0
        /// <summary>
        /// Retrieve a list of tuple (DSRecord, Table) attached to a given record (table, id) for the given profile
        /// This function is used to retrieve a list of records attached to the current update
        /// Example :
        ///    The object A is not visible for the user Y
        ///    The user X updates the object A
        ///    The object A becomes visible for the user Y
        ///    In that case, object A must be added and notified to the user Y
        ///    This function builds this case
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="table"></param>
        /// <param name="id"></param>
        /// <param name="customerId"></param>
        /// <param name="userId"></param>
        /// <param name="profile"></param>
        /// <param name="area"></param>
        /// <param name="deepUpdate"></param>
        /// <param name="recordAlreadyRead"></param>
        /// <param name="informationAlreadyRead"></param>
        /// <returns></returns>
        virtual public void GetListRecordsConcernedByUpdate(DSCache cache,
                                                            string table,
                                                            int id,
                                                            int customerId,
                                                            int userId,
                                                            UserProfile.EUserProfile profile,
                                                            string area,
                                                            bool deepUpdate,
                                                            DSRecord recordAlreadyRead,
                                                            InformationRecord informationAlreadyRead)
        {
            if (id < 0 || profile != UserProfile.EUserProfile.None || cache.Is(table, id) != null)
            {
                return;
            }

            cache.Set(table, id, null);
        }
        /// <summary>
        /// 返回存储某类型的所有属性的集合。
        /// </summary>
        /// <param name="objType">类型(类、接口、枚举等)</param>
        /// <returns>属性集合</returns>
        public static List <PropertyInfo> GetPropertyInfoList(Type objType)
        {
            string cachekey = string.Format("LST_{0}", objType.FullName);
            List <PropertyInfo> propList = (List <PropertyInfo>)DSCache.Get(cachekey);

            if (propList == null)
            {
                propList = new List <PropertyInfo>();

                foreach (PropertyInfo objProperty in objType.GetProperties())
                {
                    propList.Add(objProperty);
                }
                DSCache.Insert(cachekey, propList);
            }

            return(propList);
        }
Пример #6
0
        /// <summary>
        /// Retrieve a list of tuple (DSRecord, Table) attached to a given record (table, id) for the given profile
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="table"></param>
        /// <param name="id"></param>
        /// <param name="customerId"></param>
        /// <param name="userId"></param>
        /// <param name="profile"></param>
        /// <param name="area"></param>
        /// <param name="deepUpdate"></param>
        /// <param name="recordAlreadyRead"></param>
        /// <param name="informationAlreadyRead"></param>
        /// <returns></returns>
        public override void GetListRecordsConcernedByUpdate(DSCache cache,
                                                             string table,
                                                             int id,
                                                             int customerId,
                                                             int userId,
                                                             UserProfile.EUserProfile profile,
                                                             string area,
                                                             bool deepUpdate,
                                                             DSRecord recordAlreadyRead,
                                                             InformationRecord informationAlreadyRead)
        {
            if (id < 0 || profile == UserProfile.EUserProfile.None || cache.Is(table, id) != null)
            {
                return;
            }

            // Retrieve the current record

            DSRecord currentRecord = null;
            Tuple <DSRecord, InformationRecord> currentRecordFromCache = cache.GetRecord(this, table, id);

            if (currentRecordFromCache == null && recordAlreadyRead == null)
            {
                switch (table)
                {
                case "Customer":
                    currentRecord = Customer.Find(id);
                    break;

                case "Language":
                    currentRecord = Language.Find(id);
                    break;

                case "User":
                    currentRecord = User.Find(id);
                    break;

                case "Module":
                    currentRecord = Module.Find(id);
                    break;

                case "UserModule":
                    currentRecord = UserModule.Find(id);
                    break;

                default:
                    base.GetListRecordsConcernedByUpdate(cache, table, id, customerId, userId, profile, area, deepUpdate, recordAlreadyRead, informationAlreadyRead);
                    return;
                }

                if (currentRecord == null)
                {
                    cache.Set(table, id, null);
                    return;
                }

                currentRecordFromCache = cache.SetRecord(this, table, id, currentRecord, null);
            }
            else if (currentRecordFromCache == null && recordAlreadyRead != null)
            {
                currentRecordFromCache = cache.SetRecord(this, table, id, recordAlreadyRead, informationAlreadyRead);
            }

            if (currentRecordFromCache != null)
            {
                currentRecord = currentRecordFromCache.Item1;
            }

            // Check if the record is concerned by the current update

            if (currentRecord is DSRecordWithCustomerId currentCustomerRecord)
            {
                if (currentCustomerRecord.CustomerId != customerId)
                {
                    cache.Set(table, id, null);
                    return;
                }
            }

            if (currentRecord is CustomerRecord customer)
            {
                cache.Set(table, id, customer.Id != customerId ? null : currentRecord);
                return;
            }

            if (currentRecord as LanguageRecord != null ||
                currentRecord as ModuleRecord != null ||
                currentRecord as UserModuleRecord != null ||
                currentRecord as UserRecord != null)
            {
                cache.Set(table, id, currentRecord);
                return;
            }

            base.GetListRecordsConcernedByUpdate(cache, table, id, customerId, userId, profile, area, deepUpdate, recordAlreadyRead, informationAlreadyRead);
        }
Пример #7
0
 /// <summary>
 /// Method called before starting the execution of the transaction
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="userId"></param>
 /// <param name="table"></param>
 /// <param name="action"></param>
 /// <param name="record"></param>
 /// <param name="identity"></param>
 virtual public void PrepareRequest(DSCache cache, int userId, string table, string action, JObject record, JObject identity)
 {
 }