private void FillHistoryForSingleReview(IDbTransaction transaction, int projectId, int reviewId, Guid[] revisions)
        {
            var fileToId = new Dictionary <string, Guid>();

            var insertCmd = transaction.CreateCommand("insert into dbo.FileHistory(Id, ProjectId, ReviewId, FileId, RevisionId, FileName, IsNew, IsRenamed, IsDeleted, IsModified) values(NEWID(), @ProjectId, @ReviewId, @FileId, @RevisionId, @FileName, @N, @R, @D, @M)");

            insertCmd.CreateParameter("@ProjectId", DbType.Int32, projectId);
            insertCmd.CreateParameter("@ReviewId", DbType.Int32, reviewId);

            insertCmd.CreateParameter("@FileId", DbType.Guid);
            insertCmd.CreateParameter("@RevisionId", DbType.Guid);
            insertCmd.CreateParameter("@FileName", DbType.String);
            insertCmd.CreateParameter("@N", DbType.Boolean);
            insertCmd.CreateParameter("@R", DbType.Boolean);
            insertCmd.CreateParameter("@D", DbType.Boolean);
            insertCmd.CreateParameter("@M", DbType.Boolean);

            void InsertOne(Guid?revision, Guid id, string fileName, bool isNew, bool isRenamed, bool isDeleted, bool isModified)
            {
                ((DbParameter)insertCmd.Parameters["@FileId"]).Value     = id;
                ((DbParameter)insertCmd.Parameters["@FileName"]).Value   = fileName;
                ((DbParameter)insertCmd.Parameters["@RevisionId"]).Value = (object)revision ?? DBNull.Value;
                ((DbParameter)insertCmd.Parameters["@N"]).Value          = isNew;
                ((DbParameter)insertCmd.Parameters["@R"]).Value          = isRenamed;
                ((DbParameter)insertCmd.Parameters["@D"]).Value          = isDeleted;
                ((DbParameter)insertCmd.Parameters["@M"]).Value          = isModified;


                insertCmd.ExecuteNonQuery();
            }

            Guid?previousRevision = null;

            foreach (var revision in revisions)
            {
                var filesChangedInRevision = FilesChangedInRevision(transaction, revision);
                var entries = new Dictionary <Guid, FileEntry>();

                foreach (var entry in filesChangedInRevision)
                {
                    Guid fileId;
                    if (!fileToId.TryGetValue(entry.OldPath, out fileId))
                    {
                        // new file
                        fileId = Guid.NewGuid();
                    }

                    if (entry.OldPath != entry.NewPath && !fileToId.ContainsKey(entry.OldPath))
                    {
                        InsertOne(previousRevision, fileId, entry.OldPath, false, false, false, false);
                    }

                    fileToId.Remove(entry.OldPath);
                    fileToId[entry.NewPath] = fileId;
                    entries[fileId]         = entry;
                }

                foreach (var(fileName, id) in fileToId)
                {
                    var entry = entries.GetValueOrDefault(id);
                    InsertOne(revision, id, fileName, entry?.IsNew ?? false, entry?.IsRenamed ?? false, entry?.IsDeleted ?? false, entry != null);
                }

                previousRevision = revision;
            }
        }
Ejemplo n.º 2
0
 public static T ExecuteScalar <T>(this IDbTransaction transaction, string commandText, IDbDataParameter[]?parameters       = null, CommandType commandType = CommandType.Text) => (T)transaction.CreateCommand(commandText, parameters, commandType).ExecuteScalar();
Ejemplo n.º 3
0
 public static IDataReader ExecuteReader(this IDbTransaction transaction, string commandText, IDbDataParameter[]?parameters = null, CommandType commandType = CommandType.Text) => transaction.CreateCommand(commandText, parameters, commandType).ExecuteReader();
Ejemplo n.º 4
0
 public static int ExecuteNonQuery(this IDbTransaction transaction, string commandText, IDbDataParameter[]?parameters       = null, CommandType commandType = CommandType.Text) => transaction.CreateCommand(commandText, parameters, commandType).ExecuteNonQuery();
Ejemplo n.º 5
0
 /// <summary>
 /// Shortcut for creating a stored procedure IDbCommand from any IDbTransaction.
 /// </summary>
 /// <param name="transaction">The transaction to create a command from.</param>
 /// <param name="procedureName">The command text or stored procedure name to use.</param>
 /// <param name="secondsTimeout">The number of seconds to wait before the command times out.</param>
 /// <returns>The created SqlCommand.</returns>
 public static IDbCommand CreateStoredProcedureCommand(this IDbTransaction transaction,
                                                       string procedureName, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS)
 => transaction.CreateCommand(CommandType.StoredProcedure, procedureName, secondsTimeout);
Ejemplo n.º 6
0
 /// <summary>
 /// Shortcut for creating a text IDbCommand from any IDbTransaction.
 /// </summary>
 /// <param name="transaction">The transaction to create a command from.</param>
 /// <param name="commandText">The command text or stored procedure name to use.</param>
 /// <param name="secondsTimeout">The number of seconds to wait before the command times out.</param>
 /// <returns>The created SqlCommand.</returns>
 public static IDbCommand CreateTextCommand(this IDbTransaction transaction,
                                            string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS)
 => transaction.CreateCommand(CommandType.Text, commandText, secondsTimeout);