public static User Load(Int32 userId, bool useCache)
        {
            if (userId == 0)
            {
                return(null);
            }
            User   user = null;
            string key  = "User_" + userId.ToString();

            if (useCache)
            {
                user = ContextCache.GetObject(key) as User;
                if (user != null)
                {
                    return(user);
                }
            }
            user = new User();
            if (user.Load(userId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, user);
                }
                return(user);
            }
            return(null);
        }
        public static Basket Load(Int32 basketId, bool useCache)
        {
            if (basketId == 0)
            {
                return(null);
            }
            Basket basket = null;
            string key    = "Basket_" + basketId.ToString();

            if (useCache)
            {
                basket = ContextCache.GetObject(key) as Basket;
                if (basket != null)
                {
                    return(basket);
                }
            }
            basket = new Basket();
            if (basket.Load(basketId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, basket);
                }
                return(basket);
            }
            return(null);
        }
        public static Role Load(Int32 roleId, bool useCache)
        {
            if (roleId == 0)
            {
                return(null);
            }
            Role   role = null;
            string key  = "Role_" + roleId.ToString();

            if (useCache)
            {
                role = ContextCache.GetObject(key) as Role;
                if (role != null)
                {
                    return(role);
                }
            }
            role = new Role();
            if (role.Load(roleId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, role);
                }
                return(role);
            }
            return(null);
        }
예제 #4
0
        public static GiftCertificateTransaction Load(Int32 giftCertificateTransactionId, bool useCache)
        {
            if (giftCertificateTransactionId == 0)
            {
                return(null);
            }
            GiftCertificateTransaction giftCertificateTransaction = null;
            string key = "GiftCertificateTransaction_" + giftCertificateTransactionId.ToString();

            if (useCache)
            {
                giftCertificateTransaction = ContextCache.GetObject(key) as GiftCertificateTransaction;
                if (giftCertificateTransaction != null)
                {
                    return(giftCertificateTransaction);
                }
            }
            giftCertificateTransaction = new GiftCertificateTransaction();
            if (giftCertificateTransaction.Load(giftCertificateTransactionId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, giftCertificateTransaction);
                }
                return(giftCertificateTransaction);
            }
            return(null);
        }
        public static Special Load(Int32 specialId, bool useCache)
        {
            if (specialId == 0)
            {
                return(null);
            }
            Special special = null;
            string  key     = "Special_" + specialId.ToString();

            if (useCache)
            {
                special = ContextCache.GetObject(key) as Special;
                if (special != null)
                {
                    return(special);
                }
            }
            special = new Special();
            if (special.Load(specialId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, special);
                }
                return(special);
            }
            return(null);
        }
예제 #6
0
        internal NHibernateContext(
            IMetaDataResolver metaDataResolver,
            Identity identity,
            ZetboxConfig config,
            Func <IFrozenContext> lazyCtx,
            InterfaceType.Factory iftFactory,
            NHibernateImplementationType.Factory implTypeFactory,
            global::NHibernate.ISession nhSession,
            INHibernateImplementationTypeChecker implChecker,
            IPerfCounter perfCounter)
            : base(metaDataResolver, identity, config, lazyCtx, iftFactory)
        {
            if (perfCounter == null)
            {
                throw new ArgumentNullException("perfCounter");
            }
            _implTypeFactory = implTypeFactory;
            _nhSession       = nhSession;
            _implChecker     = implChecker;

            _attachedObjects        = new ContextCache <int>(this, item => item.ID);
            _attachedObjectsByProxy = new ContextCache <IProxyObject>(this, item => ((NHibernatePersistenceObject)item).NHibernateProxy);

            _perfCounter = perfCounter;
        }
        public static ProductDigitalGood Load(Int32 productDigitalGoodId, bool useCache)
        {
            if (productDigitalGoodId == 0)
            {
                return(null);
            }
            ProductDigitalGood productDigitalGood = null;
            string             key = "ProductDigitalGood_" + productDigitalGoodId.ToString();

            if (useCache)
            {
                productDigitalGood = ContextCache.GetObject(key) as ProductDigitalGood;
                if (productDigitalGood != null)
                {
                    return(productDigitalGood);
                }
            }
            productDigitalGood = new ProductDigitalGood();
            if (productDigitalGood.Load(productDigitalGoodId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, productDigitalGood);
                }
                return(productDigitalGood);
            }
            return(null);
        }
예제 #8
0
        public static Transaction Load(Int32 transactionId, bool useCache)
        {
            if (transactionId == 0)
            {
                return(null);
            }
            Transaction transaction = null;
            string      key         = "Transaction_" + transactionId.ToString();

            if (useCache)
            {
                transaction = ContextCache.GetObject(key) as Transaction;
                if (transaction != null)
                {
                    return(transaction);
                }
            }
            transaction = new Transaction();
            if (transaction.Load(transactionId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, transaction);
                }
                return(transaction);
            }
            return(null);
        }
예제 #9
0
        public static SharedPersonalization Load(Int32 personalizationPathId, bool useCache)
        {
            if (personalizationPathId == 0)
            {
                return(null);
            }
            SharedPersonalization sharedPersonalization = null;
            string key = "SharedPersonalization_" + personalizationPathId.ToString();

            if (useCache)
            {
                sharedPersonalization = ContextCache.GetObject(key) as SharedPersonalization;
                if (sharedPersonalization != null)
                {
                    return(sharedPersonalization);
                }
            }
            sharedPersonalization = new SharedPersonalization();
            if (sharedPersonalization.Load(personalizationPathId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, sharedPersonalization);
                }
                return(sharedPersonalization);
            }
            return(null);
        }
        public static VolumeDiscount Load(Int32 volumeDiscountId, bool useCache)
        {
            if (volumeDiscountId == 0)
            {
                return(null);
            }
            VolumeDiscount volumeDiscount = null;
            string         key            = "VolumeDiscount_" + volumeDiscountId.ToString();

            if (useCache)
            {
                volumeDiscount = ContextCache.GetObject(key) as VolumeDiscount;
                if (volumeDiscount != null)
                {
                    return(volumeDiscount);
                }
            }
            volumeDiscount = new VolumeDiscount();
            if (volumeDiscount.Load(volumeDiscountId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, volumeDiscount);
                }
                return(volumeDiscount);
            }
            return(null);
        }
예제 #11
0
        /*----------------------------------------------------------------------------------------*/
        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="SingletonBehavior"/> class.
        /// </summary>
        public SingletonBehavior()
        {
            ContextCache = new ContextCache();

            SupportsEagerActivation = true;
            ShouldTrackInstances    = true;
        }
        public static Link Load(Int32 linkId, bool useCache)
        {
            if (linkId == 0)
            {
                return(null);
            }
            Link   link = null;
            string key  = "Link_" + linkId.ToString();

            if (useCache)
            {
                link = ContextCache.GetObject(key) as Link;
                if (link != null)
                {
                    return(link);
                }
            }
            link = new Link();
            if (link.Load(linkId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, link);
                }
                return(link);
            }
            return(null);
        }
        public static DigitalGood Load(Int32 digitalGoodId, bool useCache)
        {
            if (digitalGoodId == 0)
            {
                return(null);
            }
            DigitalGood digitalGood = null;
            string      key         = "DigitalGood_" + digitalGoodId.ToString();

            if (useCache)
            {
                digitalGood = ContextCache.GetObject(key) as DigitalGood;
                if (digitalGood != null)
                {
                    return(digitalGood);
                }
            }
            digitalGood = new DigitalGood();
            if (digitalGood.Load(digitalGoodId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, digitalGood);
                }
                return(digitalGood);
            }
            return(null);
        }
예제 #14
0
        /// <summary>
        /// Loads a Coupon object for the given coupon code
        /// </summary>
        /// <param name="couponCode">Coupon code for which to load the coupon</param>
        /// <returns>The Coupon object loaded</returns>
        public static Coupon LoadForCouponCode(string couponCode)
        {
            couponCode = couponCode.ToUpperInvariant();
            string key    = "Coupon_" + couponCode;
            Coupon coupon = ContextCache.GetObject(key) as Coupon;

            if (coupon != null)
            {
                return(coupon);
            }
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT CouponId");
            selectQuery.Append(" FROM ac_Coupons");
            selectQuery.Append(" WHERE CouponCode = @couponCode");
            selectQuery.Append(" AND StoreId = @storeId");
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@couponCode", System.Data.DbType.String, couponCode);
            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
            int couponId = AlwaysConvert.ToInt(database.ExecuteScalar(selectCommand));

            if (couponId != 0)
            {
                coupon = CouponDataSource.Load(couponId);
                ContextCache.SetObject(key, coupon);
                return(coupon);
            }
            return(null);
        }
예제 #15
0
        public static WishlistItem Load(Int32 wishlistItemId, bool useCache)
        {
            if (wishlistItemId == 0)
            {
                return(null);
            }
            WishlistItem wishlistItem = null;
            string       key          = "WishlistItem_" + wishlistItemId.ToString();

            if (useCache)
            {
                wishlistItem = ContextCache.GetObject(key) as WishlistItem;
                if (wishlistItem != null)
                {
                    return(wishlistItem);
                }
            }
            wishlistItem = new WishlistItem();
            if (wishlistItem.Load(wishlistItemId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, wishlistItem);
                }
                return(wishlistItem);
            }
            return(null);
        }
        public static Redirect Load(Int32 redirectId, bool useCache)
        {
            if (redirectId == 0)
            {
                return(null);
            }
            Redirect redirect = null;
            string   key      = "Redirect_" + redirectId.ToString();

            if (useCache)
            {
                redirect = ContextCache.GetObject(key) as Redirect;
                if (redirect != null)
                {
                    return(redirect);
                }
            }
            redirect = new Redirect();
            if (redirect.Load(redirectId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, redirect);
                }
                return(redirect);
            }
            return(null);
        }
        public static TrackingNumber Load(Int32 trackingNumberId, bool useCache)
        {
            if (trackingNumberId == 0)
            {
                return(null);
            }
            TrackingNumber trackingNumber = null;
            string         key            = "TrackingNumber_" + trackingNumberId.ToString();

            if (useCache)
            {
                trackingNumber = ContextCache.GetObject(key) as TrackingNumber;
                if (trackingNumber != null)
                {
                    return(trackingNumber);
                }
            }
            trackingNumber = new TrackingNumber();
            if (trackingNumber.Load(trackingNumberId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, trackingNumber);
                }
                return(trackingNumber);
            }
            return(null);
        }
예제 #18
0
        public static InputChoice Load(Int32 inputChoiceId, bool useCache)
        {
            if (inputChoiceId == 0)
            {
                return(null);
            }
            InputChoice inputChoice = null;
            string      key         = "InputChoice_" + inputChoiceId.ToString();

            if (useCache)
            {
                inputChoice = ContextCache.GetObject(key) as InputChoice;
                if (inputChoice != null)
                {
                    return(inputChoice);
                }
            }
            inputChoice = new InputChoice();
            if (inputChoice.Load(inputChoiceId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, inputChoice);
                }
                return(inputChoice);
            }
            return(null);
        }
        public static Order Load(Int32 orderId, bool useCache)
        {
            if (orderId == 0)
            {
                return(null);
            }
            Order  order = null;
            string key   = "Order_" + orderId.ToString();

            if (useCache)
            {
                order = ContextCache.GetObject(key) as Order;
                if (order != null)
                {
                    return(order);
                }
            }
            order = new Order();
            if (order.Load(orderId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, order);
                }
                return(order);
            }
            return(null);
        }
예제 #20
0
 /// <summary>
 /// Initializes a new instance of the BaseMemoryContext class, using the specified assemblies for interfaces and implementation.
 /// </summary>
 protected BaseMemoryContext(InterfaceType.Factory iftFactory)
 {
     this.objects         = new ContextCache <int>(this, item => item.ID);
     this.iftFactoryCache = new FuncCache <Type, InterfaceType>(t => iftFactory(t));
     this._iftFactory     = t => iftFactoryCache.Invoke(t);
     ZetboxContextDebuggerSingleton.Created(this);
 }
예제 #21
0
        public static UserSetting Load(Int32 userSettingId, bool useCache)
        {
            if (userSettingId == 0)
            {
                return(null);
            }
            UserSetting userSetting = null;
            string      key         = "UserSetting_" + userSettingId.ToString();

            if (useCache)
            {
                userSetting = ContextCache.GetObject(key) as UserSetting;
                if (userSetting != null)
                {
                    return(userSetting);
                }
            }
            userSetting = new UserSetting();
            if (userSetting.Load(userSettingId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, userSetting);
                }
                return(userSetting);
            }
            return(null);
        }
예제 #22
0
        public static StoreSetting Load(Int32 storeSettingId, bool useCache)
        {
            if (storeSettingId == 0)
            {
                return(null);
            }
            StoreSetting storeSetting = null;
            string       key          = "StoreSetting_" + storeSettingId.ToString();

            if (useCache)
            {
                storeSetting = ContextCache.GetObject(key) as StoreSetting;
                if (storeSetting != null)
                {
                    return(storeSetting);
                }
            }
            storeSetting = new StoreSetting();
            if (storeSetting.Load(storeSettingId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, storeSetting);
                }
                return(storeSetting);
            }
            return(null);
        }
예제 #23
0
        public static Currency Load(Int32 currencyId, bool useCache)
        {
            if (currencyId == 0)
            {
                return(null);
            }
            Currency currency = null;
            string   key      = "Currency_" + currencyId.ToString();

            if (useCache)
            {
                currency = ContextCache.GetObject(key) as Currency;
                if (currency != null)
                {
                    return(currency);
                }
            }
            currency = new Currency();
            if (currency.Load(currencyId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, currency);
                }
                return(currency);
            }
            return(null);
        }
        public static Vendor Load(Int32 vendorId, bool useCache)
        {
            if (vendorId == 0)
            {
                return(null);
            }
            Vendor vendor = null;
            string key    = "Vendor_" + vendorId.ToString();

            if (useCache)
            {
                vendor = ContextCache.GetObject(key) as Vendor;
                if (vendor != null)
                {
                    return(vendor);
                }
            }
            vendor = new Vendor();
            if (vendor.Load(vendorId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, vendor);
                }
                return(vendor);
            }
            return(null);
        }
예제 #25
0
        internal ClientContext CloneContext(string url)
        {
            var context = ContextCache.FirstOrDefault(c => new Uri(c.Url).AbsoluteUri == new Uri(url).AbsoluteUri);

            if (context == null)
            {
                context = Context.Clone(url);
                try
                {
                    context.ExecuteQueryRetry();
                }
                catch (Exception ex)
                {
#if !ONPREMISES && !NETSTANDARD2_0
                    if ((ex is WebException || ex is NotSupportedException) && CurrentConnection.PSCredential != null)
                    {
                        // legacy auth?
                        var authManager = new OfficeDevPnP.Core.AuthenticationManager();
                        context = authManager.GetAzureADCredentialsContext(url.ToString(), CurrentConnection.PSCredential.UserName, CurrentConnection.PSCredential.Password);
                        context.ExecuteQueryRetry();
                    }
                    else
                    {
#endif
                    throw;
#if !ONPREMISES && !NETSTANDARD2_0
                }
#endif
                }
                ContextCache.Add(context);
            }
            Context = context;
            return(context);
        }
예제 #26
0
		/*----------------------------------------------------------------------------------------*/
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the <see cref="SingletonBehavior"/> class.
		/// </summary>
		public SingletonBehavior()
		{
			ContextCache = new ContextCache();

			SupportsEagerActivation = true;
			ShouldTrackInstances = true;
		}
        public static Manufacturer Load(Int32 manufacturerId, bool useCache)
        {
            if (manufacturerId == 0)
            {
                return(null);
            }
            Manufacturer manufacturer = null;
            string       key          = "Manufacturer_" + manufacturerId.ToString();

            if (useCache)
            {
                manufacturer = ContextCache.GetObject(key) as Manufacturer;
                if (manufacturer != null)
                {
                    return(manufacturer);
                }
            }
            manufacturer = new Manufacturer();
            if (manufacturer.Load(manufacturerId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, manufacturer);
                }
                return(manufacturer);
            }
            return(null);
        }
        public static PaymentMethod Load(Int32 paymentMethodId, bool useCache)
        {
            if (paymentMethodId == 0)
            {
                return(null);
            }
            PaymentMethod paymentMethod = null;
            string        key           = "PaymentMethod_" + paymentMethodId.ToString();

            if (useCache)
            {
                paymentMethod = ContextCache.GetObject(key) as PaymentMethod;
                if (paymentMethod != null)
                {
                    return(paymentMethod);
                }
            }
            paymentMethod = new PaymentMethod();
            if (paymentMethod.Load(paymentMethodId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, paymentMethod);
                }
                return(paymentMethod);
            }
            return(null);
        }
예제 #29
0
		/*----------------------------------------------------------------------------------------*/
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the <see cref="OnePerRequestBehavior"/> class.
		/// </summary>
		public OnePerRequestBehavior()
		{
			ContextCache = new ContextCache();

			SupportsEagerActivation = true;
			ShouldTrackInstances = false;
		}
        public static WrapGroup Load(Int32 wrapGroupId, bool useCache)
        {
            if (wrapGroupId == 0)
            {
                return(null);
            }
            WrapGroup wrapGroup = null;
            string    key       = "WrapGroup_" + wrapGroupId.ToString();

            if (useCache)
            {
                wrapGroup = ContextCache.GetObject(key) as WrapGroup;
                if (wrapGroup != null)
                {
                    return(wrapGroup);
                }
            }
            wrapGroup = new WrapGroup();
            if (wrapGroup.Load(wrapGroupId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, wrapGroup);
                }
                return(wrapGroup);
            }
            return(null);
        }
        public AssemblyExplorer(MSpecUnitTestProvider provider,
#if RESHARPER_61
                                IUnitTestElementManager manager,
                                PsiModuleManager psiModuleManager,
                                CacheManager cacheManager,
#endif
                                IMetadataAssembly assembly,
                                IProject project,
                                UnitTestElementConsumer consumer)
        {
            _assembly = assembly;
            _consumer = consumer;

            using (ReadLockCookie.Create())
            {
                var projectEnvoy = new ProjectModelElementEnvoy(project);

                var cache = new ContextCache();
#if RESHARPER_61
                _contextFactory = new ContextFactory(provider, manager, psiModuleManager, cacheManager, project, projectEnvoy, _assembly.Location.FullPath, cache);
                _contextSpecificationFactory  = new ContextSpecificationFactory(provider, manager, psiModuleManager, cacheManager, project, projectEnvoy, cache);
                _behaviorFactory              = new BehaviorFactory(provider, manager, psiModuleManager, cacheManager, project, projectEnvoy, cache);
                _behaviorSpecificationFactory = new BehaviorSpecificationFactory(provider, manager, psiModuleManager, cacheManager, project, projectEnvoy);
#else
#if RESHARPER_6
                _contextFactory = new ContextFactory(provider, project, projectEnvoy, _assembly.Location.FullPath, cache);
#else
                _contextFactory = new ContextFactory(provider, project, projectEnvoy, _assembly.Location, cache);
#endif
                _contextSpecificationFactory  = new ContextSpecificationFactory(provider, project, projectEnvoy, cache);
                _behaviorFactory              = new BehaviorFactory(provider, project, projectEnvoy, cache);
                _behaviorSpecificationFactory = new BehaviorSpecificationFactory(provider, project, projectEnvoy);
#endif
            }
        }
예제 #32
0
        public static Store Load(Int32 storeId, bool useCache)
        {
            if (storeId == 0)
            {
                return(null);
            }
            Store  store = null;
            string key   = "Store_" + storeId.ToString();

            if (useCache)
            {
                store = ContextCache.GetObject(key) as Store;
                if (store != null)
                {
                    return(store);
                }
            }
            store = new Store();
            if (store.Load(storeId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, store);
                }
                return(store);
            }
            return(null);
        }
        protected DurableInstanceContextProvider(ServiceHostBase serviceHostBase, bool isPerCall)
        {
            if (serviceHostBase == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceHostBase");
            }

            this.serviceHostBase = serviceHostBase;

            if (serviceHostBase.Description.Behaviors.Find<ServiceThrottlingBehavior>() == null)
            {
                serviceHostBase.ServiceThrottle.MaxConcurrentInstances = (new ServiceThrottlingBehavior()).MaxConcurrentInstances;
            }
            this.contextCache = new ContextCache();
            this.isPerCall = isPerCall;
        }
예제 #34
0
		/*----------------------------------------------------------------------------------------*/
		#region Public Methods
		/// <summary>
		/// Resolves an instance of the type based on the rules of the behavior.
		/// </summary>
		/// <param name="context">The context in which the instance is being activated.</param>
		/// <returns>An instance of the type associated with the behavior.</returns>
		public override object Resolve(IContext context)
		{
			Ensure.NotDisposed(this);

			// Get the instance map from the thread-local storage block, creating it if necessary.
			Dictionary<IBinding, ContextCache> map = GetInstanceMap();
			ContextCache cache;

			if (map.ContainsKey(context.Binding))
			{
				cache = map[context.Binding];

				if (cache.Contains(context.Implementation))
					return cache[context.Implementation].Instance;
			}
			else
			{
				cache = new ContextCache();
				map.Add(context.Binding, cache);
			}

			context.Binding.Components.Activator.Activate(context);
			cache.Add(context);

			_references.Add(context);

			return context.Instance;
		}