Esempio n. 1
0
        private void ClearCacheInternal()
        {
            if (_isCalculating)
            {
                return;
            }
            if (_settings == null)
            {
                return;
            }
            if (IsWorking)
            {
                return;
            }

            IsWorking = true;
            BeginOnThreadPool(() =>
            {
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    var fileNames = store.GetFileNames();
                    foreach (var fileName in fileNames)
                    {
                        if (IsValidCacheFileName(fileName))
                        {
                            if (_settings.Photos && IsValidPhotoFileName(fileName))
                            {
                                DeleteFile(store, fileName);
                            }
                            else if (_settings.Music && IsValidMusicFileName(fileName))
                            {
                                DeleteFile(store, fileName);
                            }
                            else if (_settings.Video && IsValidVideoFileName(fileName))
                            {
                                DeleteFile(store, fileName);
                            }
                            else if (_settings.VoiceMessages && IsValidVoiceMessageFileName(fileName))
                            {
                                DeleteFile(store, fileName);
                            }
                            else if (_settings.Documents && IsValidDocumentFileName(fileName))
                            {
                                DeleteFile(store, fileName);
                            }
                            else if (_settings.OtherFiles && IsValidOtherFileName(fileName))
                            {
                                DeleteFile(store, fileName);
                            }
                        }
                    }
                }

                if (_settings.Music ||
                    _settings.Video ||
                    _settings.VoiceMessages ||
                    _settings.Documents ||
                    _settings.OtherFiles)
                {
                    CacheService.ClearLocalFileNames();
                }


                EventAggregator.Publish(new ClearCacheEventArgs());
                var length = _settings.RecalculateLength();
                Status     = FileSizeConverter.Convert(length);
                IsWorking  = false;
            });
        }