Esempio n. 1
0
 public static string GetFileContent(string filePath)
 {
     return(AutoCache.CacheRetrieve(() =>
     {
         return File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath));
     }));
 }
Esempio n. 2
0
        public AopResult Begin(AopEnum action)
        {
            AopResult ar = AopResult.Continue;

            if (outerAop != null && (aopOp == AopOp.OpenAll || aopOp == AopOp.OnlyOuter))
            {
                ar = outerAop.Begin(action, Para);
                if (ar == AopResult.Return)
                {
                    return(ar);
                }
            }
            if (aopOp == AopOp.OpenAll || aopOp == AopOp.OnlyInner)
            {
                if (AppConfig.Cache.IsAutoCache && !IsTxtDataBase)   // 只要不是直接返回
                {
                    isHasCache = AutoCache.GetCache(action, Para);   //找看有没有Cache
                }
                if (isHasCache)                                      //找到Cache
                {
                    if (outerAop == null || ar == AopResult.Default) //不执行End
                    {
                        return(AopResult.Return);
                    }
                    return(AopResult.Break);//外部Aop说:还需要执行End
                }
            }
            return(ar);// 没有Cache,默认返回
        }
Esempio n. 3
0
        public Convolver(double[] kernel, int index, int length)
        {
            if (kernel == null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }
            if (index < 0 || index > kernel.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }
            if (length < 0 || index + length > kernel.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }

            this.kernel = new double[length];
            Array.Copy(kernel, index, this.kernel, 0, length);
            delayData = new AutoCache(0);

            if (length > Threshold)
            {
                fft       = DoubleFFT.Create(length * 2);
                ifft      = DoubleIFFT.Create(length * 2);
                fftIn     = fft.AllocInput();
                fftOut    = fft.AllocOutput();
                fftKernel = fft.AllocOutput();
                Marshal.Copy(this.kernel, 0, fftIn, length);
                for (int i = length; i < length * 2; i++)
                {
                    ((double *)fftIn)[i] = 0;
                }
                fft.Execute(fftIn, fftKernel);
            }
        }
Esempio n. 4
0
        public T BuildStrategyFactory <T>(Enum operation)
        {
            return(AutoCache.CacheRetrieve(() =>
            {
                var strategyType = AppDomain
                                   .CurrentDomain
                                   .GetAssemblies()
                                   .Where(x => x.FullName.StartsWith(Constants.ApplicationGlobalNamespace))
                                   .SelectMany(x => x.GetTypes())
                                   .FirstOrDefault(t => t.Name == operation.ToString() + Constants.StrategySuffix);

                if (strategyType == null)
                {
#if DEBUG
                    throw new NotImplementedException(Constants.MissingStrategyImplementation(operation.ToString() + Constants.StrategySuffix));
#else
                    return default(T);
#endif
                }

                return (T)Activator.CreateInstance(strategyType);
            }, new CacheItemPolicy()
            {
                Priority = CacheItemPriority.NotRemovable
            }));
        }
Esempio n. 5
0
 public static IEnumerable <string> GetFileLines(string filePath)
 {
     return(AutoCache.CacheRetrieve(() =>
     {
         return GetFileContent(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath))
         .Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
     }));
 }
Esempio n. 6
0
    public static Func <A, TR> AsCacheable <A, TR>(this Func <A, TR> function, out IFunctionCache cache)
    {
        var autocache = new AutoCache <A, TR>();

        cache = autocache;
        return(a => autocache.IsCached(a) ?
               autocache.GetCachedValue(a) :
               autocache.AddCachedValue(a, function(a)));
    }
Esempio n. 7
0
 public static IEnumerable <string> GetFileLinesOrdered(string filePath)
 {
     return(AutoCache.CacheRetrieve(() =>
     {
         return GetFileLines(filePath)
         .OrderBy(x => x)
         .ToList();
     }));
 }
Esempio n. 8
0
 public void End(AopEnum action)
 {
     if (outerAop != null)
     {
         outerAop.End(action, Para);
     }
     if (!isHasCache && !IsTxtDataBase)
     {
         AutoCache.SetCache(action, Para); //找看有没有Cache
     }
 }
Esempio n. 9
0
    public static Func <A, B, TR> AsCacheable <A, B, TR>(this Func <A, B, TR> function, out IFunctionCache cache)
    {
        var autocache = new AutoCache <OpaqueKey <A, B>, TR>();

        cache = autocache;
        return((a, b) =>
        {
            var key = new OpaqueKey <A, B>(a, b);
            return autocache.IsCached(key)
                                      ? autocache.GetCachedValue(key)
                                      : autocache.AddCachedValue(key, function(a, b));
        });
    }
Esempio n. 10
0
 public void End(AopEnum action)
 {
     if (outerAop != null && (aopOp == AopOp.OpenAll || aopOp == AopOp.OnlyOuter))
     {
         outerAop.End(action, Para);
     }
     if (aopOp == AopOp.OpenAll || aopOp == AopOp.OnlyInner)
     {
         if (!isHasCache && !IsTxtDataBase && Para.IsSuccess) //Select内部调用了GetCount,GetCount的内部isHasCache为true影响了
         {
             AutoCache.SetCache(action, Para);                //找看有没有Cache
         }
     }
 }
Esempio n. 11
0
        private async Task <AsyncTryOut <Chapter> > TryFoundIllustration()
        {
            Volume       V      = ReaderPage.CurrentChapter.Volume;
            ChapterImage CImage = Shared.BooksDb.ChapterImages.FirstOrDefault(x => V.Chapters.Contains(x.Chapter));

            if (CImage != null)
            {
                return(new AsyncTryOut <Chapter>(true, CImage.Chapter));
            }

            bool NeedDownload = Shared.BooksDb.Chapters.Any(x => x.Volume == V && x.Content == null);

            if (!NeedDownload)
            {
                Message.Text = "No Image for this volume";
                return(new AsyncTryOut <Chapter>());
            }

            NeedDownload = false;

            StringResources stm = StringResources.Load("Message");

            await Popups.ShowDialog(UIAliases.CreateDialog(
                                        "Not enough information to see if there were any illustrations within this volume. Download this volume?"
                                        , () => NeedDownload = true
                                        , stm.Str("Yes"), stm.Str("No")
                                        ));

            if (!NeedDownload)
            {
                Message.Text = "Not enough information for finding illustrations. Consider downloading a specific chapter";
                return(new AsyncTryOut <Chapter>());
            }

            ChapterList.ItemsSource = V.Chapters.Select(x => new ChapterVModel(x));
            await AutoCache.DownloadVolumeAsync(ReaderPage.CurrentBook, V);

            Chapter ImageChapter = V.Chapters.FirstOrDefault(x => x.Image != null);

            if (ImageChapter == null)
            {
                Worker.UIInvoke(() => Message.Text = "No Illustration available");
                return(new AsyncTryOut <Chapter>());
            }

            return(new AsyncTryOut <Chapter>(true, ImageChapter));
        }
Esempio n. 12
0
        public int Convolve(double *src, int srcLength, double *dst, int dstLength)
        {
            var    input = new UnionBuffer(delayData.Data, delay * Size, (IntPtr)src, srcLength * Size);
            int    kernelLength = kernel.Length, offset = 0, step, copyLength;
            int    outLen = Math.Max(Math.Min(delay + srcLength - (kernelLength - 1), dstLength), 0);
            IntPtr tempInput;
            bool   fast = fft != null;

            if (fast)
            {
                copyLength = fft.FFTSize;
                tempInput  = fftIn;
                step       = kernelLength + 1;
            }
            else
            {
                copyLength = FixedStep + kernelLength - 1;
                tempBuffer.Resize(copyLength * Size);
                tempInput = tempBuffer.data;
                step      = FixedStep;
            }

            for (; outLen >= step; outLen -= step, offset += step)
            {
                input.CopyTo(offset * Size, tempInput, copyLength * Size);
                ConvolveOnce(tempInput, dst + offset, step, fast);
            }
            if (outLen > 0)
            {
                input.CopyTo(offset * Size, tempInput, (outLen + kernelLength - 1) * Size);
                ConvolveOnce(tempInput, dst + offset, outLen, fast);
                offset += outLen;
            }

            delay = Math.Min(Math.Max(kernelLength - 1, delay + srcLength - dstLength), delay + srcLength);
            tempBuffer.Resize(delay * Size);
            input.CopyTo(offset * Size, tempBuffer.Data, delay * Size);

            var temp = tempBuffer;

            tempBuffer = delayData;
            delayData  = temp;

            return(offset);
        }
Esempio n. 13
0
        /// <summary>
        /// 获取缓存,根据周期自动延长缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public TValue Get(TKey key, AutoCache autocache)
        {
            Dictionary <TKey, CacheObject <TValue> > cachedEntities = GetCachedEntities();
            CacheObject <TValue> cachedEntity;

            if (cachedEntities.ContainsKey(key))
            {
                cachedEntity = cachedEntities[key];
                if (autocache == AutoCache.Auto)
                {
                    if (CheckCycle(cachedEntity.CreateTime))
                    {
                        CacheOperate.Insert(cacheKey, CacheMinutes, null, CacheMinutes, System.Web.Caching.CacheItemPriority.Default);
                    }
                }
                return(cachedEntity.Object);
            }
            return(default(TValue));
        }
Esempio n. 14
0
        protected async void DownloadVolume(object sender, RoutedEventArgs e)
        {
            StringResources stx = StringResources.Load("Message", "ContextMenu");

            bool Confirmed = false;

            await Popups.ShowDialog(
                UIAliases.CreateDialog(
                    RightClickedVolume.Title, stx.Text("AutoUpdate", "ContextMenu")
                    , () => Confirmed = true
                    , stx.Str("Yes"), stx.Str("No")
                    ));

            if (!Confirmed)
            {
                return;
            }

            AutoCache.DownloadVolume(ThisBook, RightClickedVolume);
        }