Esempio n. 1
0
        /// <summary>
        /// Deserialize from an XML stream to an Account.
        /// </summary>
        /// <param name="xmlReader"></param>
        /// <returns></returns>
        internal static XmlAccount Deserialize( XmlReader xmlReader, Version version )
        {
            if( xmlReader.NodeType != XmlNodeType.Element || xmlReader.Name.ToLower() != ElementName  )
                throw new ApplicationException( "Needs an Account node to deserialize an account object." );

            XmlAccount account = new XmlAccount();

            if( xmlReader.GetAttribute( "id" ) != null )
                account.Id = Int32.Parse( xmlReader.GetAttribute( "id" ) );

            while( xmlReader.Read() )
            {
                switch( xmlReader.NodeType )
                {
                    case XmlNodeType.Element:
                        switch( xmlReader.Name )
                        {
                            case "name":
                                account.Name = xmlReader.ReadString();
                                break;
                            case "type":
                                string value = xmlReader.ReadString();
                                switch( value )
                                {
                                    case "Checking":
                                        account.AccountType = AccountType.Asset;
                                        account.SubAccountType = SubAccountType.Checking;
                                        break;
                                    case "Savings":
                                        account.AccountType = AccountType.Asset;
                                        account.SubAccountType = SubAccountType.Savings;
                                        break;
                                    case "CreditCard":
                                        account.AccountType = AccountType.Liability;
                                        account.SubAccountType = SubAccountType.CreditCard;
                                        break;
                                    default:
                                        account.AccountType = (AccountType)Enum.Parse( typeof( AccountType ), value );
                                        break;
                                }
                                break;
                            case "subtype":
                                account.SubAccountType = (SubAccountType)Enum.Parse( typeof( SubAccountType ), xmlReader.ReadString() );
                                break;
                            case "startingDate":
                                account.StartingDate = DateTime.Parse( xmlReader.ReadString() );
                                break;
                            case "startingBalance":
                                account.StartingBalance = Decimal.Parse( xmlReader.ReadString() );
                                break;
                            case "onlineSource":
                                account.OnlineSource = xmlReader.ReadString();
                                break;
                            default:
                                break;
                        }
                        break;
                    case XmlNodeType.EndElement:
                        if( xmlReader.Name == ElementName )
                            return account;
                        break;
                }
            }

            return account;
        }
Esempio n. 2
0
 /// <summary>Create a new Account object.</summary>
 public IAccount NewAccount()
 {
     XmlAccount account = new XmlAccount();
     account.Provider = this;
     account.Id = this.nextAccountId++;
     this.accounts.Add( account.Id, account );
     return account;
 }