Пример #1
0
        /// <remarks>
        /// Lazy storing... fired on app shut down. Note that items with CacheItemPriority.NotRemovable are not removed when the cache is emptied.
        /// We're beyond infrastructure and cannot use IOC objects here. It would lead to ComponentNotRegisteredException from autofac.
        /// </remarks>
        private static void OnDataRemoved(string key, object value, CacheItemRemovedReason reason)
        {
            try
            {
                if (key == Key)
                {
                    var cacheData = value as List <WebApiUserCacheData>;

                    if (cacheData != null)
                    {
                        var dataToStore = cacheData.Where(x => x.LastRequest.HasValue && x.IsValid);

                        if (dataToStore.Count() > 0)
                        {
                            if (DataSettings.Current.IsValid())
                            {
                                var dbContext = new SmartObjectContext(DataSettings.Current.DataConnectionString);

                                foreach (var user in dataToStore)
                                {
                                    try
                                    {
                                        dbContext.Execute("Update GenericAttribute Set Value = {1} Where Id = {0}", user.GenericAttributeId, user.ToString());
                                    }
                                    catch (Exception exc)
                                    {
                                        exc.Dump();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                exc.Dump();
            }
        }