public XmlAccount XmlAccountFromPlan1Account(Plan1Account account) { XmlAccount xAccount = new XmlAccount(); xAccount.accountMoney = account.AccountMoney; xAccount.accountPercent = account.AccountPercent; foreach (Transaction tr in account.Transactions) { XmlTransaction tmpTrans = new XmlTransaction(); tmpTrans.amount = tr.Amount; tmpTrans.description = tr.Description; tmpTrans.transactionType = tr.TransactionType; tmpTrans.dateTime = Transaction.DateTimeSecondsFromEpochFor(tr.DateTime); tmpTrans.id = tr.ID; xAccount.transactions.Add(tmpTrans); } return(xAccount); }
public void saveAccounts(string filename, string keyword) { string PasswordEncryptKey; XmlAccount[] config = new XmlAccount[AccountData.Count]; PasswordEncryptKey = setKeyword(keyword); IEnumerator ienum = AccountData.GetEnumerator(); int i = 0; while (ienum.MoveNext()) { Accounts.AccountProperties acprop = (Accounts.AccountProperties)ienum.Current; config[i] = new XmlAccount(); config[i].ID = acprop.ID; config[i].Password = Common.EncryptString(acprop.Password, keyword); config[i].Site = (int)acprop.Site; i++; } XmlMyAccounts accountdatas = new XmlMyAccounts(); accountdatas.AccountList = config; accountdatas.EncryptKey = PasswordEncryptKey; XmlTricksterRoot XmlRoot = new XmlTricksterRoot(); XmlRoot.MyAccount = accountdatas; string filepath = ""; if (Path.IsPathRooted(filename)) { filepath = filename; filename = Path.GetFileName(filename); } else { filepath = Path.GetFullPath(Environment.CurrentDirectory + @"\" + filename); } if (!File.Exists(filepath)) { // ファイルがなければ作成 FileStream fs = new FileStream(filepath, FileMode.Create); fs.Close(); } FileInfo fi = new FileInfo(filepath); if (fi.IsReadOnly) { SimpleLogger.WriteLine("could not write to file \"" + filepath + "\""); MessageBox.Show("アカウント情報ファイルは読み取り専用のため、保存できません。", "TricksterTools", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (AccountData.Count > 0) { try { System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(XmlTricksterRoot)); FileStream fs = new FileStream(filepath, FileMode.Create); serializer.Serialize(fs, XmlRoot); fs.Close(); } /* * catch (System.Security.SecurityException se) * { * SimpleLogger.WriteLine(se.GetType().ToString() + Environment.NewLine + se.Message); * //MessageBox.Show("例外エラー:\nセキュリティエラーです。", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); * throw se; * } */ catch (System.IO.IOException ioe) { SimpleLogger.WriteLine(ioe.GetType().ToString() + Environment.NewLine + ioe.Message); //MessageBox.Show("例外エラー:\n入出力時にエラーが発生しました。", "IOException error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw ioe; } catch (System.Xml.XmlException xe) { SimpleLogger.WriteLine(xe.GetType().ToString() + Environment.NewLine + xe.Message); //MessageBox.Show("例外エラー:\nアカウント情報読み込みエラー", "XmlException error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw xe; } catch (System.Exception e) { SimpleLogger.WriteLine(e.GetType().ToString() + Environment.NewLine + e.Message); //MessageBox.Show("例外エラー:\n原因の特定ができませんでした。", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw e; } } }
public void saveAccounts(string filename, string keyword) { string PasswordEncryptKey; XmlAccount[] config = new XmlAccount[AccountData.Count]; PasswordEncryptKey = setKeyword(keyword); IEnumerator ienum = AccountData.GetEnumerator(); int i = 0; while(ienum.MoveNext()) { Accounts.AccountProperties acprop = (Accounts.AccountProperties)ienum.Current; config[i] = new XmlAccount(); config[i].ID = acprop.ID; config[i].Password = Common.EncryptString(acprop.Password, keyword); config[i].Site = (int)acprop.Site; i++; } XmlMyAccounts accountdatas = new XmlMyAccounts(); accountdatas.AccountList = config; accountdatas.EncryptKey = PasswordEncryptKey; XmlTricksterRoot XmlRoot = new XmlTricksterRoot(); XmlRoot.MyAccount = accountdatas; string filepath = ""; if (Path.IsPathRooted(filename)) { filepath = filename; filename = Path.GetFileName(filename); } else { filepath = Path.GetFullPath(Environment.CurrentDirectory + @"\" + filename); } if (!File.Exists(filepath)) { // �t�@�C�����Ȃ���쐬 FileStream fs = new FileStream(filepath, FileMode.Create); fs.Close(); } FileInfo fi = new FileInfo(filepath); if (fi.IsReadOnly) { SimpleLogger.WriteLine("could not write to file \"" + filepath + "\""); MessageBox.Show("�A�J�E���g���t�@�C���͓ǂݎ���p�̂��߁A�ۑ��ł��܂���B", "TricksterTools", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (AccountData.Count > 0) { try { System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(XmlTricksterRoot)); FileStream fs = new FileStream(filepath, FileMode.Create); serializer.Serialize(fs, XmlRoot); fs.Close(); } /* catch (System.Security.SecurityException se) { SimpleLogger.WriteLine(se.GetType().ToString() + Environment.NewLine + se.Message); //MessageBox.Show("��O�G���[:\n�Z�L�����e�B�G���[�ł��B", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw se; } */ catch (System.IO.IOException ioe) { SimpleLogger.WriteLine(ioe.GetType().ToString() + Environment.NewLine + ioe.Message); //MessageBox.Show("��O�G���[:\n���o�͎��ɃG���[���������܂����B", "IOException error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw ioe; } catch (System.Xml.XmlException xe) { SimpleLogger.WriteLine(xe.GetType().ToString() + Environment.NewLine + xe.Message); //MessageBox.Show("��O�G���[:\n�A�J�E���g���ǂݍ��݃G���[", "XmlException error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw xe; } catch (System.Exception e) { SimpleLogger.WriteLine(e.GetType().ToString() + Environment.NewLine + e.Message); //MessageBox.Show("��O�G���[:\n�����̓��肪�ł��܂���ł����B", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw e; } } }