Esempio n. 1
0
        public static async Task <T> GetOrAdd <T>(this ICacheItem <T> self, ICacheItemLock lockObj, Func <Task <T> > getProc, bool continueOnCapturedContext = false)
        {
            var cacheValue = await self.Get().ConfigureAwait(continueOnCapturedContext);

            if (cacheValue.HasValue)
            {
                return(cacheValue.Value);
            }

            await lockObj.Acquire().ConfigureAwait(continueOnCapturedContext);;

            try
            {
                cacheValue = await self.Get().ConfigureAwait(continueOnCapturedContext);

                if (cacheValue.HasValue)
                {
                    return(cacheValue.Value);
                }

                var value = await getProc().ConfigureAwait(continueOnCapturedContext);

                await self.Set(value).ConfigureAwait(continueOnCapturedContext);

                return(value);
            }
            finally
            {
                await lockObj.Release().ConfigureAwait(continueOnCapturedContext);
            }
        }
Esempio n. 2
0
        public static object SetProperty(
            [ExcelArgument(Name = "ObjectHandle", Description = "Handle to an object.")] string h,
            [ExcelArgument(Name = "Property", Description = "Name of property to which data will be assigned.")] string p,
            [ExcelArgument(Name = "PropertyData", Description = "Data to be assiged.")] object o)
        {
            object res = ExcelError.ExcelErrorNA;

            if (_cache.ContainsKey(h))
            {
                ICacheItem handle = _cache.Lookup(h) as CacheItem;

                CacheItemProperty cip = handle.CacheType.Property(p);
                if (handle.CacheType.Exception == null)
                {
                    Exception e = null;
                    o = ParameterCleaner.Arg(o, cip.Type, out e);

                    if (e == null)
                    {
                        handle.Set(p, o);
                        if (handle.Exception != null)
                        {
                            res = handle.Exception.Message;
                        }
                        else
                        {
                            res = string.Format("SET {0}", p);
                        }
                    }
                    else
                    {
                        res = e.Message;
                    }
                }
                else
                {
                    res = handle.CacheType.Exception.Message;
                }
            }

            return(res);
        }