Exemple #1
0
        private OpResult getLibraryStats()
        {
            OpResult opResult = new OpResult();
            opResult.StatusCode = OpStatusCode.Json;

            int[] list_codes = new int[] {MusicCmd.LIST_ALBUMS, MusicCmd.LIST_ALBUM_ARTISTS, MusicCmd.LIST_ARTISTS, MusicCmd.LIST_GENRES,
                MusicCmd.LIST_DETAILS, MusicCmd.LIST_PLAYLISTS};

            LibraryStats library_stats = new LibraryStats();

            foreach (int i in list_codes)
            {
                MusicCmd cmd = new MusicCmd(i);
                cmd.setStatsOnly();
                switch (i)
                {
                    case MusicCmd.LIST_ALBUMS:
                        library_stats.albums = cmd.Execute("").ResultCount;
                        break;
                    case MusicCmd.LIST_ALBUM_ARTISTS:
                        library_stats.album_artists = cmd.Execute("").ResultCount;
                        break;
                    case MusicCmd.LIST_ARTISTS:
                        library_stats.artists = cmd.Execute("").ResultCount;
                        break;
                    case MusicCmd.LIST_GENRES:
                        library_stats.genres = cmd.Execute("").ResultCount;
                        break;
                    case MusicCmd.LIST_DETAILS:
                        library_stats.songs = cmd.Execute("").ResultCount;
                        break;
                    case MusicCmd.LIST_PLAYLISTS:
                        library_stats.playlists = cmd.Execute("").ResultCount;
                        break;
                }
            }
            opResult.ContentText = JsonConvert.SerializeObject(library_stats, Newtonsoft.Json.Formatting.Indented);
            return opResult;
        }
        public void ExecuteCacheBuild(XmlDocument doc, Logger logger)
        {
            lock (cacheLock)
            {
                this.isCacheBuilding = true;

                DateTime now = DateTime.Now;
                XmlNode lastCacheTimeNode = doc.DocumentElement.SelectSingleNode("lastCacheTime");
                if (lastCacheTimeNode != null)
                {
                    lastCacheTimeNode.InnerText = Convert.ToString(now);
                    //Save settings
                    doc.PreserveWhitespace = true;
                    doc.Save(AddInModule.DATA_DIR + "\\settings.xml");
                }

                logger.Write("Updating cache now in progress");

                //Build caches for rebuilding the library in Emote
                MusicCmd music = new MusicCmd(MusicCmd.LIST_DETAILS, true);
                music.Execute("");
                music = new MusicCmd(MusicCmd.LIST_ARTISTS, true);
                music.Execute("");
                music = new MusicCmd(MusicCmd.LIST_GENRES, true);
                music.Execute("");
                logger.Write("Cache update finished");

                this.isCacheBuilding = false;
            }
        }