public IonFilesWithCaching(IonConfig config) { _config = config; // Init the data client _dataClient = new DataClient(config); }
/// <summary> /// Used to retrieve a class that inherits from CacheIndex /// </summary> /// <typeparam name="T"></typeparam> /// <param name="requestUrl"></param> /// <param name="collectionIdentifier"></param> /// <returns>First it tries to get a index from memoryCache, then from fileCache and after that returns null, if no index is found</returns> public static async Task <T> retrieve <T>(string requestUrl, IonConfig config) where T : CacheIndex { T index = MemoryCacheIndex.get <T>(requestUrl, config.collectionIdentifier); if (index != null) { IonLogging.log("Index lookup " + requestUrl + " from memory", IonLogMessageTypes.SUCCESS); return(index); } // check isolated storage try { index = await StorageUtils.getIndexAsync <T>(requestUrl, config).ConfigureAwait(false); if (index != null) { IonLogging.log("Index lookup " + requestUrl + " from isolated storage", IonLogMessageTypes.SUCCESS); } } catch (Exception e) { IonLogging.log("Index lookup " + requestUrl + " is not in isolated storage. Message: " + e.Message, IonLogMessageTypes.INFORMATION); } // Save to memory cache, if index is not null if (index != null) { MemoryCacheIndex.put(requestUrl, config.collectionIdentifier, index); } return(index); }
public IonFilesWithCaching( IonConfig config ) { _config = config; // Init the data client _dataClient = new DataClient( config ); }
/// <summary> /// Saves a index file to the isolated storage on the device /// </summary> /// <typeparam name="T"></typeparam> /// <param name="requestURL"></param> /// <param name="cacheIndex"></param> /// <param name="collectionIdentifier"></param> /// <returns></returns> public static async Task saveIndexAsync <T>(string requestURL, T cacheIndex, IonConfig config) where T : CacheIndex { try { // Generate filePath for index string filePath = FilePaths.getCacheIndicesFolderPath(config) + FilePaths.getFileName(requestURL) + IonConstants.JsonFileExtension; using (await fileLocks.ObtainLock(filePath).LockAsync().ConfigureAwait(false)) { // Open an existing file or create a new one StorageFile file = await _localFolder.CreateFileAsync(filePath, CreationCollisionOption.ReplaceExisting); // Serialize cache índex string cacheIndexSerialized = JsonConvert.SerializeObject(cacheIndex); // Write serialzed collection to file await FileIO.WriteTextAsync(file, cacheIndexSerialized); } fileLocks.ReleaseLock(filePath); } catch (Exception e) { IonLogging.log("Error saving cacheIndex to isolated storage. Message: " + e.Message, IonLogMessageTypes.ERROR); } }
/// <summary> /// Gets a index from isolated storage of the device. Returns null, if the index isn't found /// </summary> /// <typeparam name="T"></typeparam> /// <param name="requestURL"></param> /// <param name="collectionIdentifier"></param> /// <returns>The index file or null, if the index file isn't found</returns> public static async Task <T> getIndexAsync <T>(string requestURL, IonConfig config) where T : CacheIndex { try { // Generate filePath for index string filePath = FilePaths.getCacheIndicesFolderPath(config) + FilePaths.getFileName(requestURL) + IonConstants.JsonFileExtension; T cacheIndex = null; using (await fileLocks.ObtainLock(filePath).LockAsync().ConfigureAwait(false)) { // Create file or use existing file StorageFile file = await _localFolder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists); // Read content of the file string content = await FileIO.ReadTextAsync(file); // Deserialize cache index cacheIndex = JsonConvert.DeserializeObject <T>(content); } fileLocks.ReleaseLock(filePath); return(cacheIndex); } catch (Exception e) { IonLogging.log("Error loading cacheIndex " + requestURL + " from isolated storage: " + e.Message, IonLogMessageTypes.ERROR); return(null); } }
/// <summary> /// Saves a page to the isolated storage folder /// </summary> /// <param name="page"></param> /// <returns></returns> public static async Task savePageToIsolatedStorageAsync(IonPage page, IonConfig config) { try { // Generate filePath for page string filePath = FilePaths.getPagesFolderPath(config) + page.identifier + IonConstants.JsonFileExtension; using (await fileLocks.ObtainLock(filePath).LockAsync().ConfigureAwait(false)) { // Create file or use existing file StorageFile file = await _localFolder.CreateFileAsync(filePath, CreationCollisionOption.ReplaceExisting); // Serialize collection string pageSerialized = JsonConvert.SerializeObject(page); // Write serialzed collection to file await FileIO.WriteTextAsync(file, pageSerialized); } fileLocks.ReleaseLock(filePath); } catch (Exception e) { IonLogging.log("Error saving page to isolated storage: " + e.Message, IonLogMessageTypes.ERROR); } }
/// <summary> /// Called to update the config file of all relevant elements /// </summary> /// <param name="config"></param> public void updateConfig(IonConfig config) { _ionPages.updateConfig(config); _ionFiles.updateConfig(config); _ionFts.updateConfig(config); _ionArchive.updateConfig(config); }
/// <summary> /// Constructor with a config file for initialization /// </summary> /// <param name="config"></param> private Ion( IonConfig config ) { _ionPages = new IonPagesWithCaching( config ); _ionFiles = new IonFilesWithCaching( config ); _ionFts = new IonFtsImpl( _ionPages, _ionFiles, config ); _ionArchive = new IonArchiveOperations( config ); }
/// <summary> /// Constructor with a config file for initialization /// </summary> /// <param name="config"></param> private Ion(IonConfig config) { _ionPages = new IonPagesWithCaching(config); _ionFiles = new IonFilesWithCaching(config); _ionFts = new IonFtsImpl(_ionPages, _ionFiles, config); _ionArchive = new IonArchiveOperations(config); }
/// <summary> /// Get local file cache path for media url /// </summary> /// <param name="url"></param> /// <param name="config"></param> /// <param name="tempCollectionFolder"></param> /// <returns></returns> public static String getMediaFilePath(String url, IonConfig config, bool tempCollectionFolder = false) { String mediaFolderPath = getMediaFolderPath(config, tempCollectionFolder); String filename = getFileName(url); return(mediaFolderPath + filename); }
/// <summary> /// Retrieves the path to the archive file for a given url /// </summary> /// <param name="url"></param> /// <param name="config"></param> /// <param name="tempCollectionFolder"></param> /// <returns>File path</returns> public static string getArchiveFilePath(string url, IonConfig config, bool tempCollectionFolder = false) { string archiveFolderPath = getArchiveFolderPath(config, tempCollectionFolder); string filename = getFileName(url); return(archiveFolderPath + filename); }
/// <summary> /// Loads a page from the isolated storage of the device /// </summary> /// <param name="collectionIdentifier"></param> /// <param name="locale"></param> /// <param name="pageIdentifier"></param> /// <returns>The desired page or null, if the page wasn't found in the isolated folder</returns> public static async Task <IonPage> loadPageFromIsolatedStorageAsync(IonConfig config, string pageIdentifier) { try { // Generate filePath for page string filePath = FilePaths.getPagesFolderPath(config) + pageIdentifier + IonConstants.JsonFileExtension; IonPage page = null; using (await fileLocks.ObtainLock(filePath).LockAsync().ConfigureAwait(false)) { // Get file from file Path StorageFile file = await _localFolder.GetFileAsync(filePath); // Read content string string content = await FileIO.ReadTextAsync(file); // Deserialize page page = JsonConvert.DeserializeObject <IonPage>(content); } fileLocks.ReleaseLock(filePath); return(page); } catch (Exception e) { IonLogging.log("Error loading page " + pageIdentifier + " of collection " + config.collectionIdentifier + " from isolated storeage. Message: " + e.Message, IonLogMessageTypes.ERROR); return(null); } }
/// <summary> /// Constructor with configuration file for initialization /// </summary> /// <param name="config"></param> public IonPagesWithCaching( IonConfig config ) { _config = config; // Init the data client _dataClient = new DataClient( config ); // Init memory cache _memoryCache = new MemoryCache( 16000000 ); }
/// <summary> /// Constructor with configuration file for initialization /// </summary> /// <param name="config"></param> public IonPagesWithCaching(IonConfig config) { _config = config; // Init the data client _dataClient = new DataClient(config); // Init memory cache _memoryCache = new MemoryCache(16000000); }
/// <summary> /// Used to save a page to the memory and isolated storage cache /// </summary> /// <param name="page"></param> /// <param name="config"></param> /// <returns></returns> public async Task savePageToCachesAsync(IonPage page, IonConfig config) { // Memory cache _memoryCache.savePage(page, _config); // Local storage cache await StorageUtils.savePageToIsolatedStorageAsync(page, config).ConfigureAwait(false); // Save page cache index await PageCacheIndex.save(page, _config).ConfigureAwait(false); }
// Config testing method requires internet and actually the knauf lookbook server public async Task configEqualsCheck() { string collectionIdentifier = "lookbook"; AuthenticationHeaderValue authorizationHeader = await TokenAuthorization.GetAuthHeaderValue( "*****@*****.**", "Jdt9y9qHt3", "https://lookbook-dev.anfema.com/client/v1/login" ); IonConfig config = new IonConfig( "https://lookbook-dev.anfema.com/client/v1/", "de_DE", collectionIdentifier, "default", authorizationHeader, 120, 100, false ); string collectionIdentifier2 = "lookbook"; AuthenticationHeaderValue authorizationHeader2 = await TokenAuthorization.GetAuthHeaderValue( "*****@*****.**", "Jdt9y9qHt3", "https://lookbook-dev.anfema.com/client/v1/login" ); IonConfig config2 = new IonConfig( "https://lookbook-dev.anfema.com/client/v1/", "de_DE", collectionIdentifier2, "default", authorizationHeader2, 120, 100, false ); Assert.IsTrue( config2.Equals( config ) ); }
/// <summary> /// Constructor with config file for initialization /// </summary> /// <param name="config"></param> public DataClient(IonConfig config) { try { _config = config; _client = new HttpClient(); _client.DefaultRequestHeaders.Authorization = _config.authenticationHeader; } catch (Exception e) { IonLogging.log("Error in configuring the data client: " + e.Message, IonLogMessageTypes.ERROR); } }
/// <summary> /// Constructor with config file for initialization /// </summary> /// <param name="config"></param> public DataClient( IonConfig config ) { try { _config = config; _client = new HttpClient(); _client.DefaultRequestHeaders.Authorization = _config.authenticationHeader; } catch( Exception e ) { IonLogging.log( "Error in configuring the data client: " + e.Message, IonLogMessageTypes.ERROR ); } }
// Config testing method requires internet and actually the knauf lookbook server public async Task configEqualsCheck() { string collectionIdentifier = "lookbook"; AuthenticationHeaderValue authorizationHeader = await TokenAuthorization.GetAuthHeaderValue("*****@*****.**", "Jdt9y9qHt3", "https://lookbook-dev.anfema.com/client/v1/login"); IonConfig config = new IonConfig("https://lookbook-dev.anfema.com/client/v1/", "de_DE", collectionIdentifier, "default", authorizationHeader, 120, 100, false); string collectionIdentifier2 = "lookbook"; AuthenticationHeaderValue authorizationHeader2 = await TokenAuthorization.GetAuthHeaderValue("*****@*****.**", "Jdt9y9qHt3", "https://lookbook-dev.anfema.com/client/v1/login"); IonConfig config2 = new IonConfig("https://lookbook-dev.anfema.com/client/v1/", "de_DE", collectionIdentifier2, "default", authorizationHeader2, 120, 100, false); Assert.IsTrue(config2.Equals(config)); }
/// <summary> /// Saves a FileCacheIndex object to the cache /// </summary> /// <param name="requestUrl"></param> /// <param name="file"></param> /// <param name="config"></param> /// <param name="checksum"></param> public static async Task saveAsync( string requestUrl, Stream file, IonConfig config, string checksum ) { if( file == null ) { return; } if( checksum == null ) { checksum = "sha256:" + HashUtils.GetSHA256Hash( file ); } FileCacheIndex cacheIndex = new FileCacheIndex( requestUrl, checksum, DateTimeUtils.now() ); await CacheIndexStore.save( requestUrl, cacheIndex, config ).ConfigureAwait( false ); }
/// <summary> /// Saves a index to memory and isolated storage cache /// </summary> /// <typeparam name="T"></typeparam> /// <param name="requestURL"></param> /// <param name="cacheIndex"></param> /// <param name="config"></param> public static async Task save <T>(string requestURL, T cacheIndex, IonConfig config) where T : CacheIndex { try { // save to memory cache MemoryCacheIndex.put <T>(requestURL, config.collectionIdentifier, cacheIndex); // save to isolated storage await StorageUtils.saveIndexAsync(requestURL, cacheIndex, config).ConfigureAwait(false); } catch (Exception e) { IonLogging.log("Cache Index " + requestURL + " could not be saved. Message: " + e.Message, IonLogMessageTypes.ERROR); } }
/// <summary> /// Saves a FileCacheIndex object to the cache /// </summary> /// <param name="requestUrl"></param> /// <param name="file"></param> /// <param name="config"></param> /// <param name="checksum"></param> public static async Task saveAsync(string requestUrl, Stream file, IonConfig config, string checksum) { if (file == null) { return; } if (checksum == null) { checksum = "sha256:" + HashUtils.GetSHA256Hash(file); } FileCacheIndex cacheIndex = new FileCacheIndex(requestUrl, checksum, DateTimeUtils.now()); await CacheIndexStore.save(requestUrl, cacheIndex, config).ConfigureAwait(false); }
/// <summary> /// Is used to get a instance of Ion corresponding to the given configuration /// </summary> /// <param name="config"></param> /// <returns></returns> public static Ion getInstance( IonConfig config ) { Ion storedClient; if( instances.TryGetValue( config, out storedClient ) ) { // Eventually update the config file saved in the stored client with the given one that might contain new or updated parameters storedClient.updateConfig( config ); return storedClient; } Ion amp = new Ion( config ); instances.Add( config, amp ); return amp; }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { // Get all the login informations needed for later communication try { _ampConfig = await AppController.instance.loginAsync(); await this.getPageNames(); } catch( Exception exception ) { Debug.WriteLine("Error occured logging in: " + exception.Message); disableProgressIndicator(); } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { // Get all the login informations needed for later communication try { _ampConfig = await AppController.instance.loginAsync(); await this.getPageNames(); } catch (Exception exception) { Debug.WriteLine("Error occured logging in: " + exception.Message); disableProgressIndicator(); } }
public IonFtsImpl( IIonPages ampPages, IIonFiles ampFiles, IonConfig config ) { this._ampPages = ampPages; this._ampFiles = ampFiles; this._config = config; // Init the data client _dataClient = new DataClient( config ); _ftsQuery = new ResourceLoader( "Amp/Resources" ).GetString( "ftsQuery" ); String dbFilePath = Path.Combine( Windows.Storage.ApplicationData.Current.LocalFolder.Path, FilePaths.GetFtsDbFilePath( _config.collectionIdentifier ) ); _connection = new SQLiteAsyncConnection( () => new SQLiteConnectionWithLock( new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), new SQLiteConnectionString( dbFilePath, false, openFlags: SQLite.Net.Interop.SQLiteOpenFlags.ReadOnly ) ) ); }
/// <summary> /// Is used to get a instance of Ion corresponding to the given configuration /// </summary> /// <param name="config"></param> /// <returns></returns> public static Ion getInstance(IonConfig config) { Ion storedClient; if (instances.TryGetValue(config, out storedClient)) { // Eventually update the config file saved in the stored client with the given one that might contain new or updated parameters storedClient.updateConfig(config); return(storedClient); } Ion amp = new Ion(config); instances.Add(config, amp); return(amp); }
public IonFtsImpl(IIonPages ampPages, IIonFiles ampFiles, IonConfig config) { this._ampPages = ampPages; this._ampFiles = ampFiles; this._config = config; // Init the data client _dataClient = new DataClient(config); _ftsQuery = new ResourceLoader("Amp/Resources").GetString("ftsQuery"); String dbFilePath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, FilePaths.GetFtsDbFilePath(_config.collectionIdentifier)); _connection = new SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), new SQLiteConnectionString(dbFilePath, false, openFlags: SQLite.Net.Interop.SQLiteOpenFlags.ReadOnly))); }
public static IonRequestInfo analyze(string url, IonConfig config) { if (isMediaRequestUrl(url)) { return(new IonRequestInfo(IonRequestType.MEDIA, null, null, null, null)); } else { string relativeUrlPath = url.Replace(config.baseUrl, ""); string[] urlPathSegments = relativeUrlPath.Split('/'); if (urlPathSegments.Length < 2 || urlPathSegments.Length > 3) { throw new NoIonPagesRequestException(url); } string[] idPlusVariation = urlPathSegments[urlPathSegments.Length - 1].Split(IonConstants.QueryBegin); if (idPlusVariation.Length > 2) { throw new NoIonPagesRequestException(url); } if (idPlusVariation.Length == 1) { idPlusVariation = new string[] { idPlusVariation[0], IonConstants.DefaultVariationIdentifier }; } string locale = urlPathSegments[0]; string variation = idPlusVariation[1]; string collectionIdentifier; if (urlPathSegments.Length == 2) { collectionIdentifier = idPlusVariation[0]; return(new IonRequestInfo(IonRequestType.COLLECTION, locale, variation, collectionIdentifier, null)); } else // urlPathSegments.length == 3 { collectionIdentifier = urlPathSegments[1]; string pageIdentifier = idPlusVariation[0]; return(new IonRequestInfo(IonRequestType.PAGE, locale, variation, collectionIdentifier, pageIdentifier)); } } }
public static IonRequestInfo analyze( string url, IonConfig config ) { if( isMediaRequestUrl( url ) ) { return new IonRequestInfo( IonRequestType.MEDIA, null, null, null, null ); } else { string relativeUrlPath = url.Replace( config.baseUrl, "" ); string[] urlPathSegments = relativeUrlPath.Split( '/' ); if( urlPathSegments.Length < 2 || urlPathSegments.Length > 3 ) { throw new NoIonPagesRequestException( url ); } string[] idPlusVariation = urlPathSegments[urlPathSegments.Length - 1].Split( IonConstants.QueryBegin ); if( idPlusVariation.Length > 2 ) { throw new NoIonPagesRequestException( url ); } if( idPlusVariation.Length == 1 ) { idPlusVariation = new string[] { idPlusVariation[0], IonConstants.DefaultVariationIdentifier }; } string locale = urlPathSegments[0]; string variation = idPlusVariation[1]; string collectionIdentifier; if( urlPathSegments.Length == 2 ) { collectionIdentifier = idPlusVariation[0]; return new IonRequestInfo( IonRequestType.COLLECTION, locale, variation, collectionIdentifier, null ); } else // urlPathSegments.length == 3 { collectionIdentifier = urlPathSegments[1]; string pageIdentifier = idPlusVariation[0]; return new IonRequestInfo( IonRequestType.PAGE, locale, variation, collectionIdentifier, pageIdentifier ); } } }
public async Task<IonConfig> loginAsync() { if ( !_loggedIn ) { String collectionIdentifier = "lookbook"; AuthenticationHeaderValue authorizationHeader = await TokenAuthorization.GetAuthHeaderValue( "*****@*****.**", "Jdt9y9qHt3", "https://lookbook-dev.anfema.com/client/v1/login" ); // Or using BasicAuth //AuthenticationHeaderValue authorizationHeader = BasicAuth.GetAuthHeaderValue( "*****@*****.**", "Jdt9y9qHt3" ); IonConfig config = new IonConfig( "https://lookbook-dev.anfema.com/client/v1/", "de_DE", collectionIdentifier, "default", authorizationHeader, 120, 100, false); // Only testing purpose TODO: remove _ampConfig = config; // Set the loggedIn bool _loggedIn = authorizationHeader != null; return config; } return _ampConfig; }
public async Task <IonConfig> loginAsync() { if (!_loggedIn) { String collectionIdentifier = "lookbook"; AuthenticationHeaderValue authorizationHeader = await TokenAuthorization.GetAuthHeaderValue("*****@*****.**", "Jdt9y9qHt3", "https://lookbook-dev.anfema.com/client/v1/login"); // Or using BasicAuth //AuthenticationHeaderValue authorizationHeader = BasicAuth.GetAuthHeaderValue( "*****@*****.**", "Jdt9y9qHt3" ); IonConfig config = new IonConfig("https://lookbook-dev.anfema.com/client/v1/", "de_DE", collectionIdentifier, "default", authorizationHeader, 120, 100, false); // Only testing purpose TODO: remove _ampConfig = config; // Set the loggedIn bool _loggedIn = authorizationHeader != null; return(config); } return(_ampConfig); }
/// <summary> /// Saves a pageCacheIndex to cache /// </summary> /// <param name="page"></param> /// <param name="config"></param> public static async Task save( IonPage page, IonConfig config ) { string url = PagesURLs.getPageURL( config, page.identifier ); PageCacheIndex cacheIndex = new PageCacheIndex( url, page.last_changed ); await CacheIndexStore.save<PageCacheIndex>( url, cacheIndex, config ).ConfigureAwait( false ); }
/// <summary> /// Retrieves a FileCacheIndex from cache /// </summary> /// <param name="requestURL"></param> /// <param name="collectionIdentifier"></param> /// <returns>FileCacheIndex object or null, if the index isn't found</returns> public static async Task<FileCacheIndex> retrieveAsync( string requestUrl, IonConfig config ) { return await CacheIndexStore.retrieve<FileCacheIndex>( requestUrl, config ).ConfigureAwait( false ); }
/// <summary> /// Updates the IonConfig file /// </summary> /// <param name="config"></param> public void updateConfig(IonConfig config) { _config = config; }
/// <summary> /// Retrieves a collection cache index either from memory or file cache /// </summary> /// <param name="config"></param> /// <returns>Cache index or null, if no cache index was found</returns> public static async Task<CollectionCacheIndex> retrieve( IonConfig config ) { String requestUrl = PagesURLs.getCollectionURL( config ); return await CacheIndexStore.retrieve<CollectionCacheIndex>( requestUrl, config ).ConfigureAwait( false ); }
/// <summary> /// Get local file cache folder path for an Ion configuration/collection /// </summary> /// <param name="config"></param> /// <param name="tempCollectionFolder"></param> /// <returns></returns> public static String getMediaFolderPath(IonConfig config, bool tempCollectionFolder) { return(getBasicCollectionFolderPath(config) + IonConstants.MediaFolderIdentifier + IonConstants.BackSlash); }
/// <summary> /// Used to get the folder path for the temp folder /// </summary> /// <param name="config"></param> /// <returns>File path</returns> public static string getTempFolderPath(IonConfig config) { return(getBasicCollectionFolderPath(config) + IonConstants.TempFolderIdentifier + IonConstants.BackSlash); }
/// <summary> /// Retrieves a FileCacheIndex from cache /// </summary> /// <param name="requestURL"></param> /// <param name="collectionIdentifier"></param> /// <returns>FileCacheIndex object or null, if the index isn't found</returns> public static async Task <FileCacheIndex> retrieveAsync(string requestUrl, IonConfig config) { return(await CacheIndexStore.retrieve <FileCacheIndex>(requestUrl, config).ConfigureAwait(false)); }
public IonArchiveOperations( IonConfig config ) { this._config = config; }
/// <summary> /// Updates the IonConfig file /// </summary> /// <param name="config"></param> public void updateConfig(IonConfig config) { _dataClient = new DataClient(config); // TODO: check this for intense use of GC _config = config; }
/// <summary> /// Saves a collection to the isolated storage /// </summary> /// <param name="collection"></param> /// <returns></returns> public static async Task saveCollectionToIsolatedStorageAsync(IonCollection collection, IonConfig config) { // Generate filePath for collection file string filePath = FilePaths.getCollectionFolderPath(config) + collection.identifier + IonConstants.JsonFileExtension; using (await fileLocks.ObtainLock(filePath).LockAsync().ConfigureAwait(false)) { // Create file or use existing file StorageFile file = await _localFolder.CreateFileAsync(filePath, CreationCollisionOption.ReplaceExisting); // Serialize collection string collectionSerialized = JsonConvert.SerializeObject(collection); // Write serialzed collection to file await FileIO.WriteTextAsync(file, collectionSerialized); } fileLocks.ReleaseLock(filePath); }
/// <summary> /// Called to update the config file of all relevant elements /// </summary> /// <param name="config"></param> public void updateConfig( IonConfig config ) { _ionPages.updateConfig( config ); _ionFiles.updateConfig( config ); _ionFts.updateConfig( config ); _ionArchive.updateConfig( config ); }
/// <summary> /// Called to recieve a desired page from memory cache /// </summary> /// <param name="pageIdentifier"></param> /// <param name="config"></param> /// <returns></returns> public IonPage getPage( string pageIdentifier , IonConfig config ) { string pageUrl = PagesURLs.getPageURL(config, pageIdentifier); return getPage(pageUrl); }
/// <summary> /// Updates the IonConfig file /// </summary> /// <param name="config"></param> public void updateConfig( IonConfig config ) { _config = config; }
/// <summary> /// Get local file cache folder path for an Ion configuration/collection /// </summary> /// <param name="config"></param> /// <param name="tempCollectionFolder"></param> /// <returns></returns> public static String getMediaFolderPath( IonConfig config, bool tempCollectionFolder ) { return getBasicCollectionFolderPath( config ) + IonConstants.MediaFolderIdentifier + IonConstants.BackSlash; }
/// <summary> /// Checks if this object is older than the given DateTime /// </summary> /// <param name="config"></param> /// <returns></returns> public bool isOutdated( IonConfig config ) { return lastUpdated < ( DateTimeUtils.now().ToUniversalTime().AddMinutes( -config.minutesUntilCollectionRefresh ) ); }
/// <summary> /// Used to get the folder path for this IonConfig including hierarchy info for locale and variation /// </summary> /// <param name="config"></param> /// <returns>FilePath including locale and variation</returns> public static string getCollectionFolderPath( IonConfig config ) { return getBasicCollectionFolderPath( config ) + config.locale + IonConstants.BackSlash + config.variation + IonConstants.BackSlash; }
/// <summary> /// Used to get the folder path for this IonConfig including hierarchy info for locale and variation /// </summary> /// <param name="config"></param> /// <returns>FilePath including locale and variation</returns> public static string getCollectionFolderPath(IonConfig config) { return(getBasicCollectionFolderPath(config) + config.locale + IonConstants.BackSlash + config.variation + IonConstants.BackSlash); }
/// <summary> /// Updates the IonConfig file /// </summary> /// <param name="config"></param> public void updateConfig( IonConfig config ) { _dataClient = new DataClient( config ); // TODO: check this for intense use of GC _config = config; }
/// <summary> /// Get local file cache path for media url /// </summary> /// <param name="url"></param> /// <param name="config"></param> /// <param name="tempCollectionFolder"></param> /// <returns></returns> public static String getMediaFilePath( String url, IonConfig config, bool tempCollectionFolder = false ) { String mediaFolderPath = getMediaFolderPath( config, tempCollectionFolder ); String filename = getFileName( url ); return mediaFolderPath + filename; }
/// <summary> /// Composes a collection URL from a given config /// </summary> /// <param name="config"></param> /// <returns>String representing the link to the collection</returns> public static string getCollectionURL( IonConfig config ) { return config.baseUrl + config.locale + IonConstants.Slash + config.collectionIdentifier; }
/// <summary> /// Returns the folder to which the archives are downloaded /// </summary> /// <param name="url"></param> /// <param name="config"></param> /// <returns>Archive folder</returns> public static string getArchiveFolderPath(IonConfig config, bool tempCollectionFolder) { return(getCollectionFolderPath(config) + IonConstants.ArchiveFolderIdentifier + IonConstants.BackSlash); }
/// <summary> /// Composes a URL to a specific page /// </summary> /// <param name="config"></param> /// <param name="pageIdentifier"></param> /// <returns>String representing the URL to the desired page</returns> public static string getPageURL( IonConfig config, string pageIdentifier ) { return config.baseUrl + config.locale + IonConstants.Slash + config.collectionIdentifier + IonConstants.Slash + pageIdentifier; }
/// <summary> /// Absolut path to the cache indices folder /// </summary> public static string getCacheIndicesFolderPath(IonConfig config) { return(getCollectionFolderPath(config) + IonConstants.CacheIndicesFolderIdentifier + IonConstants.BackSlash); }
/// <summary> /// Saves a page to the memory cache /// </summary> /// <param name="page"></param> /// <param name="config"></param> public void savePage( IonPage page, IonConfig config ) { string pageUrl = PagesURLs.getPageURL(config, page.identifier); _pageMemoryCache.add(pageUrl, page); }
/// <summary> /// Retrieves a collectionCacheIndex from cache /// </summary> /// <param name="requestURL"></param> /// <param name="collectionIdentifier"></param> /// <returns>collectionCacheIndex or null, if the index isn't found</returns> public static async Task<CollectionCacheIndex> retrieve( string requestURL, IonConfig config ) { return await CacheIndexStore.retrieve<CollectionCacheIndex>( requestURL, config ).ConfigureAwait( false ); }
/// <summary> /// Used to save a page to the memory and isolated storage cache /// </summary> /// <param name="page"></param> /// <param name="config"></param> /// <returns></returns> public async Task savePageToCachesAsync( IonPage page, IonConfig config ) { // Memory cache _memoryCache.savePage( page, _config ); // Local storage cache await StorageUtils.savePageToIsolatedStorageAsync( page, config ).ConfigureAwait( false ); // Save page cache index await PageCacheIndex.save( page, _config ).ConfigureAwait( false ); }
/// <summary> /// Saves a collectionCacheIndex to cache /// </summary> /// <param name="config"></param> /// <param name="lastModified"></param> public static async Task save( IonConfig config, DateTime lastModified ) { string collectionURL = PagesURLs.getCollectionURL( config ); CollectionCacheIndex cacheIndex = new CollectionCacheIndex( collectionURL, DateTimeUtils.now().ToUniversalTime(), lastModified ); await CacheIndexStore.save( collectionURL, cacheIndex, config ).ConfigureAwait( false ); }
/// <summary> /// Absolut path to the cache indices folder /// </summary> public static string getCacheIndicesFolderPath( IonConfig config ) { return getCollectionFolderPath( config ) + IonConstants.CacheIndicesFolderIdentifier + IonConstants.BackSlash; }