protected override void ProcessRecord() { var connection = DatabaseConnection.Current; using (var command = new SqlCommand("Select [Sha1Hash],[FileId],[IsIgnored] from [SameFile] Where [Id]=@Id")) { command.Connection = connection; command.Parameters.Add(new SqlParameter("@Id", System.Data.SqlDbType.UniqueIdentifier) { Value = Id }); using (var reader = command.ExecuteReader(System.Data.CommandBehavior.SequentialAccess)) { if (reader.Read()) { ImageStoreSameFile line = new ImageStoreSameFile(Id, (byte[])reader[0], (Guid)reader[1]) { IsIgnored = (bool)reader[2] }; WriteObject(line); } else { WriteObject(null); } reader.Close(); } } }
protected override void ProcessRecord() { base.ProcessRecord(); var connection = DatabaseConnection.Current; using (var command = new SqlCommand()) { string text = " [Id],[Sha1Hash],[FileId],[IsIgnored] from [SameFile] "; if (Top.HasValue) { text = "SELECT TOP " + Top.Value.ToString() + text; } else { text = "SELECT" + text; } if (Sha1Hash != null) { text += "Where [Sha1Hash]=@Sha1Hash"; command.Parameters.Add(new SqlParameter("@Sha1Hash", System.Data.SqlDbType.Binary, 20) { Value = Sha1Hash }); if (OnlyIgnored.IsPresent) { text += " and [IsIgnored]=1"; } else if (!IncludesIgnored.IsPresent) { text += " and [IsIgnored]=0"; } } else if (IncludesObsoleted.IsPresent) { if (OnlyIgnored.IsPresent) { text += "where [IsIgnored]=1"; } else if (!IncludesIgnored.IsPresent) { text += "where [IsIgnored]=0"; } } else { text += "Where [Sha1Hash] in (Select [Sha1Hash] From [SameFile] "; if (OnlyIgnored.IsPresent) { text += "where [IsIgnored]=1 "; } else if (!IncludesIgnored.IsPresent) { text += "where [IsIgnored]=0 "; } text += "Group by [Sha1Hash] Having Count([Id]) > 1)"; } command.CommandText = text + " order by [Sha1Hash]"; command.Connection = connection; command.CommandTimeout = 0; List <ImageStoreSameFile> result = new List <ImageStoreSameFile>(); using (var reader = command.ExecuteReader(System.Data.CommandBehavior.SequentialAccess)) { while (reader.Read()) { ImageStoreSameFile line = new ImageStoreSameFile((Guid)reader[0], (byte[])reader[1], (Guid)reader[2]) { IsIgnored = (bool)reader[3] }; result.Add(line); } reader.Close(); } if (Sha1Hash != null && IncludesObsoleted.IsPresent && result.Count == 1) { WriteObject(new List <ImageStoreSameFile>()); } else { WriteObject(result); } } }