Exemple #1
0
 private void SelectCurrentVersion()
 {
     try
     {
         var           currentVersion = Toolbox.settings.CurrentVersion.ToString();
         ChangeLogItem curVerItem     = null;
         foreach (var item in lbVersions.Items)
         {
             if (((ChangeLogItem)item).Version == $"v{currentVersion}")
             {
                 Toolbox.uAddDebugLog($"Found current version changelog item | [v]{currentVersion} [iv]{((ChangeLogItem)item).Version}");
                 curVerItem = ((ChangeLogItem)item);
                 break;
             }
         }
         if (curVerItem != null)
         {
             Toolbox.uAddDebugLog("We found the changelog item for the current version, changing current selected item");
             curVerItem.VersionColor = new SolidColorBrush(Toolbox.ColorFromHex("#FF13D6C5"));
             lbVersions.SelectedItem = curVerItem;
             Toolbox.uAddDebugLog($"Changed selected item to: {curVerItem.Version}");
         }
         else
         {
             Toolbox.uAddDebugLog("Couldn't find a matching changelog item for the current running version, didn't auto select");
         }
     }
     catch (Exception ex)
     {
         LogException(ex);
     }
 }
        /// <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);
        }
        /// <summary>
        /// ふるまい情報のインデックステーブルの行追加
        /// </summary>
        private void insertChangeLogTable(ChangeLogItem changelog)
        {
            string sql = @"insert into t_change_log (
                           SnapshotID, SeriesID, Notes,
                           ElementGuid, ChangeUser, ChangeDateTime,
                           ChangeType, ChangeItemName, Metadata, LogItem
                          ) values (
                           @snapshotId, @seriesId, @notes,
                           @elementGuid, @changeUser, @changeDateTime,
                           @changeType, @changeItemName, @metadata, @logItem
                          ) ";

            using (SQLiteCommand command2 = conn.CreateCommand())
            {
                SQLiteParameter[] parameters = new SQLiteParameter[] {
                    new SQLiteParameter("@snapshotId", changelog.snapshotId)
                    , new SQLiteParameter("@seriesId", changelog.seriesId)
                    , new SQLiteParameter("@notes", changelog.notes)
                    , new SQLiteParameter("@elementGuid", changelog.elementGuid)
                    , new SQLiteParameter("@changeUser", changelog.changeUser)
                    , new SQLiteParameter("@changeDateTime", changelog.changeDateTime)
                    , new SQLiteParameter("@changeType", changelog.changeType)
                    , new SQLiteParameter("@changeItemName", changelog.changeItemName)
                    , new SQLiteParameter("@metadata", changelog.metadata)
                    , new SQLiteParameter("@logItem", changelog.logItem)
                };

                command2.CommandText = sql;
                command2.Parameters.AddRange(parameters);
                command2.ExecuteNonQuery();

                // Console.WriteLine("insert t_change_log ( SnapShotID = {0} )", changelog.snapshotId);
            }
        }
Exemple #4
0
        public async Task <int> InsertAsync(ChangeLogItem item)
        {
            int newId;

            using (var connection = new SqlConnection(_connectionString.Path))
            {
                SqlTransaction transaction = null;
                try
                {
                    connection.Open();
                    transaction = connection.BeginTransaction();
                    newId       = await connection.InsertAsync <ChangeLogItem>(item, transaction);

                    transaction.Commit();
                }
                catch
                {
                    newId = -1;
                    transaction?.Rollback();
                }
                finally
                {
                    connection?.Close();
                }
            }
            return(newId);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="chItem"></param>
        public void writeOneChangeLog(ChangeLogItem chItem)
        {
            try
            {
                //conn.Open();
                //sqlt = conn.BeginTransaction();

                insertChangeLogTable(chItem);

                //sqlt.Commit();
                //conn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        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);
        }