Пример #1
0
        /// <summary>
        /// save document
        /// </summary>
        /// <param name="head"></param>
        /// <param name="needStroe"></param>
        /// <exception cref="SystemException"></exception>
        /// <exception cref="SaveClosedLedgerException"></exception>
        internal async Task saveDocumentAsync(HeadEntity head, bool needStroe)
        {
            _coreDriver.logDebugInfo(this.GetType(), 231,
                                     "Call transaction to save the document", MessageType.INFO);

            if (head.IsSaved)
            {
                _coreDriver.logDebugInfo(this.GetType(), 235,
                                         "Document is saved, just to store the update on disk.",
                                         MessageType.INFO);
            }
            else
            {
                _coreDriver.logDebugInfo(this.GetType(), 239,
                                         "Document is never saved", MessageType.INFO);

                MonthIdentity monthId = head.MonthID;
                MonthLedger   ledger  = this.GetLedger(monthId);
                if (ledger == null)
                {
                    _coreDriver.logDebugInfo(this.GetType(), 239,
                                             "Error in document month identity", MessageType.ERRO);
                    throw new SaveClosedLedgerException();
                }

                // set document number
                DocumentNumber    num;
                List <HeadEntity> entities = ledger.Entities;
                if (entities.Count == 0)
                {
                    try
                    {
                        num = new DocumentNumber("1000000001".ToCharArray());
                    }
                    catch (IdentityTooLong e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                                 e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                    catch (IdentityNoData e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                                 e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                    catch (IdentityInvalidChar e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                                 e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                }
                else
                {
                    HeadEntity last = entities[entities.Count - 1];
                    num = last.DocNumber.Next();
                }
                _coreDriver.logDebugInfo(this.GetType(), 239,
                                         "Generate document number " + num.ToString(),
                                         MessageType.INFO);
                head._docNumber = num;

                ledger.Add(head);
            }

            if (needStroe)
            {
                await StoreAsync(head.MonthID);

                _coreDriver.logDebugInfo(this.GetType(), 465,
                                         "Memory has been stored to disk", MessageType.INFO);
            }
            else
            {
                _coreDriver.logDebugInfo(this.GetType(), 465,
                                         "Memory has NOT been stored to disk", MessageType.INFO);
            }

            _coreDriver.logDebugInfo(this.GetType(), 278,
                                     "Call transaction to save the document successfully",
                                     MessageType.INFO);
        }
Пример #2
0
        /// <summary>
        /// load month identity
        /// </summary>
        /// <param name="monthId"></param>
        /// <returns></returns>
        /// <exception cref="TransactionDataFileFormatException"></exception>
        public async Task <MonthLedger> Load(MonthIdentity monthId)
        {
            // construct month ledger
            MonthLedger monthledger = new MonthLedger(monthId);

            _list.Add(monthId, monthledger);

            _coreDriver.logDebugInfo(
                this.GetType(),
                102,
                String.Format("Loading transaction data {0} ...",
                              monthId.ToString()), MessageType.INFO);

            // get file path
            StorageFile file = await generateFilePath(monthId, false);

            if (file == null)
            {// empty
                return(monthledger);
            }
            _coreDriver.logDebugInfo(this.GetType(), 109,
                                     String.Format("Transaction data file: {0} .", file.Path),
                                     MessageType.INFO);
            try
            {
                string text = await FileIO.ReadTextAsync(file);

                XDocument xdoc = XDocument.Parse(text);

                XElement rootElem = xdoc.Element(TransDataUtils.XML_ROOT);
                // no root element
                if (rootElem == null)
                {
                    throw new TransactionDataFileFormatException(file.Path);
                }

                // -------------------------------------------------------------------
                // parse all the documents
                foreach (XElement elem in rootElem.Elements(TransDataUtils.XML_DOCUMENT))
                {
                    HeadEntity head = HeadEntity.Parse(_coreDriver,
                                                       _masterDataMgmt, elem);
                    _coreDriver
                    .logDebugInfo(
                        this.GetType(),
                        172,
                        String.Format(
                            "Document {0} add to list during loading.",
                            head.DocIdentity
                            .ToString()),
                        MessageType.INFO);
                    monthledger.Add(head);

                    // raise load document
                    _coreDriver.ListenerMgmt.LoadDoc(this, head);

                    // raise reverse document
                    if (head.IsReversed)
                    {
                        _coreDriver.ListenerMgmt.ReverseDoc(head);
                    }
                }
                // -----------------------------------------------------------------

                return(monthledger);
            }
            catch (TransactionDataFileFormatException e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 170, e.Message,
                                         MessageType.ERRO);
                throw new TransactionDataFileFormatException(file.Path);
            }
        }
        /// <summary>
        /// load month identity
        /// </summary>
        /// <param name="monthId"></param>
        /// <returns></returns>
        /// <exception cref="TransactionDataFileFormatException"></exception>
        public async Task<MonthLedger> Load(MonthIdentity monthId)
        {
            // construct month ledger
            MonthLedger monthledger = new MonthLedger(monthId);
            _list.Add(monthId, monthledger);

            _coreDriver.logDebugInfo(
                    this.GetType(),
                    102,
                    String.Format("Loading transaction data {0} ...",
                            monthId.ToString()), MessageType.INFO);

            // get file path
            StorageFile file = await generateFilePath(monthId, false);
            if (file == null)
            {// empty
                return monthledger;
            }
            _coreDriver.logDebugInfo(this.GetType(), 109,
                    String.Format("Transaction data file: {0} .", file.Path),
                    MessageType.INFO);
            try
            {
                string text = await FileIO.ReadTextAsync(file);
                XDocument xdoc = XDocument.Parse(text);

                XElement rootElem = xdoc.Element(TransDataUtils.XML_ROOT);
                // no root element
                if (rootElem == null)
                {
                    throw new TransactionDataFileFormatException(file.Path);
                }

                // -------------------------------------------------------------------
                // parse all the documents
                foreach (XElement elem in rootElem.Elements(TransDataUtils.XML_DOCUMENT))
                {
                    HeadEntity head = HeadEntity.Parse(_coreDriver,
                            _masterDataMgmt, elem);
                    _coreDriver
                            .logDebugInfo(
                                    this.GetType(),
                                    172,
                                    String.Format(
                                            "Document {0} add to list during loading.",
                                            head.DocIdentity
                                                    .ToString()),
                                    MessageType.INFO);
                    monthledger.Add(head);

                    // raise load document
                    _coreDriver.ListenerMgmt.LoadDoc(this, head);

                    // raise reverse document
                    if (head.IsReversed)
                        _coreDriver.ListenerMgmt.ReverseDoc(head);
                }
                // -----------------------------------------------------------------

                return monthledger;
            }
            catch (TransactionDataFileFormatException e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 170, e.Message,
                        MessageType.ERRO);
                throw new TransactionDataFileFormatException(file.Path);
            }

        }