/// <summary>
        /// t_snapshotから取得されたAuditLogデータをChangeLogデータに変換する
        /// </summary>
        /// <param name="aItem"></param>
        /// <returns></returns>
        private ChangeLogItem transToChangeLog(AuditLogItem aItem)
        {
            ChangeLogItem chItem = new ChangeLogItem();

            chItem.snapshotId = aItem.snapshotId;
            chItem.seriesId   = aItem.seriesId;
            chItem.notes      = aItem.notes;

            // 変更タイプ(INSERT/UPDATE/DELETE) = t_snapshot.style
            chItem.changeType = aItem.style;
            // 変更テーブル名 = t_auditlog.SnapshotName;
            chItem.changeItemName = aItem.snapshotName;
            // notes項目から ElementGuid項目の取得を試みる
            chItem.elementGuid = getElementGuidFromNotes(aItem);

            // メタデータ(更新されたテーブルのキー項目などが設定) = t_auditlog.BinContent2
            chItem.metadata = rtrim(enc.GetString(aItem.binContent2));

            // ログ項目(更新内容の実際値(From-To)) = t_auditlog.BinContent1 を unzip したもの
            chItem.logItem = getUnzippedString(aItem.binContent1);

            // metadataタグの中身からトラッカー情報(更新者、更新日時)を取得
            Tracker trc = MetadataXmlReader.readXmlMetaData(chItem.metadata);

            chItem.changeUser     = trc.user;
            chItem.changeDateTime = trc.dateTime;

            return(chItem);
        }
        private AuditLogItem readRowNode(XmlNode rowNode)
        {
            AuditLogItem logItem = new AuditLogItem();

            foreach (XmlNode itemNode in rowNode.ChildNodes)
            {
                switch (itemNode.Name)
                {
                case "SnapshotID":
                    logItem.snapshotId = itemNode.InnerText;
                    break;

                case "SeriesID":
                    logItem.seriesId = itemNode.InnerText;
                    break;

                case "Position":
                    logItem.position = readIntValue(itemNode.InnerText);
                    break;

                case "SnapshotName":
                    logItem.snapshotName = itemNode.InnerText;
                    break;

                case "Notes":
                    logItem.notes = itemNode.InnerText;
                    break;

                case "Style":
                    logItem.style = itemNode.InnerText;
                    break;

                case "ElementID":
                    logItem.elementId = readIntValue(itemNode.InnerText);
                    break;

                case "ElementType":
                    logItem.elementType = itemNode.InnerText;
                    break;

                case "StrContent":
                    logItem.strContent = itemNode.InnerText;
                    break;

                case "BinContent1":
//                        logItem.binContent1 = itemNode.InnerText;
                    break;

                case "BinContent2":
//                        logItem.binContent2 = itemNode.InnerText;
                    break;
                }
            }

            return(logItem);
        }
        //
        private bool isTransferable(AuditLogItem aItem)
        {
            // t_snapshotの snapshotName は更新されたテーブルを示すため、 この値が "t_snapshot" なら転送不要
            if (aItem.snapshotName == "t_snapshot")
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// パラメータのタグ付き値をDBから読み込み、Mapに格納する
        /// </summary>
        private List <AuditLogItem> readSnapShotTable()
        {
            Console.WriteLine("readSnapShotTable()");

            List <AuditLogItem> retList = new List <AuditLogItem>();
            string strSQL, strFields;

            // 読み込む項目リスト
            strFields =
                " SnapshotID, SeriesID, [Position], SnapshotName, Notes, " +
                " [Style], ElementID, ElementType, StrContent, BinContent1, BinContent2 ";

            // SQL文 を作成
            strSQL = "select " + strFields +
                     " from t_snapshot " +
                     " order by SnapshotID ";

            OleDbCommand dbCom = new OleDbCommand();

            // SQLを実行する
            dbCom.CommandText = strSQL;
            dbCom.Connection  = objConn;

            // DB読み込み
            OleDbDataReader reader = dbCom.ExecuteReader();

            while (reader.Read())
            {
                AuditLogItem logItem = new AuditLogItem();

                logItem.snapshotId   = DbUtil.readStringField(reader, 0);
                logItem.seriesId     = DbUtil.readStringField(reader, 1);
                logItem.position     = DbUtil.readIntField(reader, 2);
                logItem.snapshotName = DbUtil.readStringField(reader, 3);
                logItem.notes        = DbUtil.readStringField(reader, 4);

                logItem.style       = DbUtil.readStringField(reader, 5);
                logItem.elementId   = Int32.Parse(DbUtil.readStringField(reader, 6));
                logItem.elementType = DbUtil.readStringField(reader, 7);
                logItem.strContent  = DbUtil.readStringField(reader, 8);

                logItem.binContent1 = readBinaryField(reader, 9);
                logItem.binContent2 = rtrimNull(readBinaryField(reader, 10));

                retList.Add(logItem);
            }

            //reader.Close();

            Console.WriteLine("readSnapShotTable() 終了");


            return(retList);
        }
        private List <AuditLogItem> readDataRowsNode(XmlNode dataNode)
        {
            List <AuditLogItem> retLogItems = new List <AuditLogItem>();

            foreach (XmlNode rowNode in dataNode.ChildNodes)
            {
                if (rowNode.Name == "Row")
                {
                    AuditLogItem item = readRowNode(rowNode);
                    retLogItems.Add(item);
                }
            }

            return(retLogItems);
        }
 /// <summary>
 /// t_snapshotのnotes項目がカンマ区切り形式で {GUID},{name},{type}と記録されるのを利用し、
 /// GUIDの値を取得する。
 /// 対象テーブルが t_object の場合は 1番目(添字0)、t_attribute や t_method の場合は
 /// 4番目(添え字3)となるようだが、他のテーブルでのnotes項目の出力内容の詳細は不明。
 /// </summary>
 /// <param name="aItem">t_snapshot テーブルから読み込まれたAuditLogItem項目</param>
 /// <returns></returns>
 private string getElementGuidFromNotes(AuditLogItem aItem)
 {
     // elementGuid項目のセット
     if (aItem.snapshotName == "t_object")
     {
         // t_objectテーブルの場合、
         return(getColumnDataFromCsv(aItem.notes, 0));
     }
     else if (aItem.snapshotName == "t_attribute" || aItem.snapshotName == "t_operation")
     {
         return(getColumnDataFromCsv(aItem.notes, 3));
     }
     else
     {
         return("");
     }
 }
        public List <ChangeLogItem> transAuditLogToChangeLog(string outputDir)
        {
            List <ChangeLogItem> changeLogs = new List <ChangeLogItem>();

            Console.WriteLine("{0} start read SnapShot data", DateTime.Now.ToString());

            // t_snapshot テーブルを読んでその中身をAuditLogItemリストに格納
            SnapShotDataReader  reader   = new SnapShotDataReader(this.fromConnStr);
            List <AuditLogItem> logItems = reader.readSnapshotData();

            // logItemsが空ならコンソールに出力して終了
            if (logItems == null)
            {
                Console.WriteLine("対象のSnapShotデータがありませんでした");
                return(changeLogs);
            }

            Console.WriteLine("{0} SnapShot data record count: {1}", DateTime.Now.ToString(), logItems.Count);

            // reader.openConnection();

            StreamWriter sw = null;

            try
            {
                //BOM無しのUTF8でテキストファイルを作成する
                sw = new StreamWriter(outputDir + "\\changeLogs.txt");
                sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");
                sw.WriteLine("");

                for (int i = 0; i < logItems.Count; i++)
                {
                    AuditLogItem aItem = logItems[i];

                    // このレコードが転送対象かを判断
                    if (isTransferable(aItem))
                    {
                        Console.WriteLine("row: [ SnapshotID={0}, SeriesID={1}, SnapshotName={2}, Position={3} ]", aItem.snapshotId, aItem.seriesId, aItem.snapshotName, aItem.position);

                        ChangeLogItem chItem = transToChangeLog(aItem);

                        sw.WriteLine("--------------------------------------------------------------------------------");
                        sw.WriteLine("SnapshotId:" + chItem.snapshotId);
                        sw.WriteLine("seriesId:" + chItem.seriesId);
                        sw.WriteLine("notes:" + chItem.notes);
                        sw.WriteLine("changeType:" + chItem.changeType);
                        sw.WriteLine("changeItemName:" + chItem.changeItemName);
                        sw.WriteLine("elementGuid:" + chItem.elementGuid);
                        sw.WriteLine("metadata:" + chItem.metadata);
                        sw.WriteLine("logItem:" + chItem.logItem);
                        sw.WriteLine("changeUser:"******"changeDateTime:" + chItem.changeDateTime);

                        // 作成したChangeLogの情報をリストに保管
                        changeLogs.Add(chItem);
                    }
                    else
                    {
                        Console.WriteLine("row: [SnapshotID={0}] can not acceptable for ChangeLog", aItem.snapshotId);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("----------------------------------------------");
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
                reader.closeConnection();
            }

            return(changeLogs);
        }