예제 #1
0
        public static void InitCache()
        {
            string t = "VideoLocal";

            ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t, string.Empty);
            VideoLocalRepository repo = new VideoLocalRepository();

            Cache         = new PocoCache <int, VideoLocal>(repo.InternalGetAll(), a => a.VideoLocalID);
            Hashes        = new PocoIndex <int, VideoLocal, string>(Cache, a => a.Hash);
            Paths         = new PocoIndex <int, VideoLocal, string>(Cache, a => a.FilePath);
            Ignored       = new PocoIndex <int, VideoLocal, int>(Cache, a => a.IsIgnored);
            ImportFolders = new PocoIndex <int, VideoLocal, int>(Cache, a => a.ImportFolderID);
            int cnt = 0;
            List <VideoLocal> grps = Cache.Values.Where(a => a.MediaVersion < VideoLocal.MEDIA_VERSION || a.MediaBlob == null).ToList();
            int max = grps.Count;

            foreach (VideoLocal g in grps)
            {
                try
                {
                    if (File.Exists(g.FullServerPath))
                    {
                        repo.Save(g, false);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
                cnt++;
                if (cnt % 10 == 0)
                {
                    ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t,
                                                                            " DbRegen - " + cnt + "/" + max);
                }
            }
            ServerState.Instance.CurrentSetupStatus = string.Format(JMMServer.Properties.Resources.Database_Cache, t,
                                                                    " DbRegen - " + max + "/" + max);
        }