/// <summary> /// establish files /// </summary> /// <returns></returns> public override async Task EstablishFilesAsync() { // set up transaction data folder await _coreDriver.RootFolder.CreateFolderAsync(TRANSACTION_DATA_FOLDER , CreationCollisionOption.OpenIfExists); _coreDriver .logDebugInfo( this.GetType(), 125, "Create transaction data root folder.", MessageType.INFO); foreach (MonthIdentity monthId in _coreDriver.MonthIds) { // create transaction file for each available month ledger MonthLedger ledger = new MonthLedger(monthId); _list.Add(monthId, ledger); XDocument xdoc = ledger.toXML(); StorageFile file = await generateFilePath(monthId, true); try { await FileIO.WriteTextAsync(file, xdoc.ToString()); } catch (FileNotFoundException e) { _coreDriver.logDebugInfo(this.GetType(), 530, e.Message, MessageType.ERRO); throw new SystemException(e); } } }
/// <summary> /// store month ledger to file system /// </summary> /// <param name="monthId"></param> /// <exception cref="SystemException"></exception> public async Task StoreAsync(MonthIdentity monthId) { // store master data _coreDriver.logDebugInfo(this.GetType(), 293, String.Format("Start storing %s to disk", monthId), MessageType.INFO); _coreDriver.logDebugInfo(this.GetType(), 297, "Store master data at first.", MessageType.INFO); await this._masterDataMgmt.StoreAsync(); MonthLedger collection = this.GetLedger(monthId); StorageFile file = await this.generateFilePath(monthId, true); _coreDriver.logDebugInfo(this.GetType(), 297, "Generate file path: " + file.Path, MessageType.INFO); if (file == null) { StorageFolder transactionFolder = await _coreDriver.RootFolder .GetFolderAsync(TRANSACTION_DATA_FOLDER); if (transactionFolder == null) { throw new SystemException(null); // bug } String fileName = String.Format("{0}.xml", monthId.ToString()); file = await transactionFolder.CreateFileAsync(fileName , CreationCollisionOption.OpenIfExists); } XDocument xdoc = collection.toXML(); _coreDriver .logDebugInfo(this.GetType(), 297, "Parsed document collections to XML document", MessageType.INFO); try { await FileIO.WriteTextAsync(file, xdoc.ToString()); } catch (FileNotFoundException e) { _coreDriver.logDebugInfo(this.GetType(), 316, e.Message, MessageType.ERRO); throw new SystemException(e); } _coreDriver.logDebugInfo(this.GetType(), 335, "Save document collection successfully.", MessageType.INFO); }
/// <summary> /// establish files /// </summary> /// <returns></returns> public override async Task EstablishFilesAsync() { // set up transaction data folder await _coreDriver.RootFolder.CreateFolderAsync(TRANSACTION_DATA_FOLDER , CreationCollisionOption.OpenIfExists); _coreDriver .logDebugInfo( this.GetType(), 125, "Create transaction data root folder.", MessageType.INFO); foreach (MonthIdentity monthId in _coreDriver.MonthIds) { // create transaction file for each available month ledger MonthLedger ledger = new MonthLedger(monthId); _list.Add(monthId, ledger); XDocument xdoc = ledger.toXML(); StorageFile file = await generateFilePath(monthId, true); try { await FileIO.WriteTextAsync(file, xdoc.ToString()); } catch (FileNotFoundException e) { _coreDriver.logDebugInfo(this.GetType(), 530, e.Message, MessageType.ERRO); throw new SystemException(e); } } }