protected override void ProcessRecord() { var connection = DatabaseConnection.Current; using (var command = new SqlCommand("Select [Id],[FolderId],[Directory],[IsSubDirectoryIncluded] from [IgnoredDirectory]")) { command.Connection = connection; WhereCauseBuilder whereCauseBuilder = new WhereCauseBuilder(command.Parameters); whereCauseBuilder.AddUniqueIdentifierComparingCause("FolderId", FolderId); whereCauseBuilder.AddStringComparingCause("Directory", Directory, DirectoryPropertyComparingModes); whereCauseBuilder.AddBitComparingCause("IsSubDirectoryIncluded", IsSubDirectoryIncluded); command.CommandText += whereCauseBuilder.ToFullWhereCommand(); List <ImageStoreIgnoredDirectory> result = new List <ImageStoreIgnoredDirectory>(); using (var reader = command.ExecuteReader(System.Data.CommandBehavior.SequentialAccess)) { while (reader.Read()) { ImageStoreIgnoredDirectory line = new ImageStoreIgnoredDirectory((Guid)reader[0]) { FolderId = (Guid)reader[1], Directory = (string)reader[2], IsSubDirectoryIncluded = (bool)reader[3] }; result.Add(line); } reader.Close(); } WriteObject(result); } }
protected override void ProcessRecord() { var connection = DatabaseConnection.Current; using (var command = new SqlCommand(" [Id],[FolderId],[Path],[FileName],[ExtensionId],[ImageHash],[Sha1Hash],[FileSize],[FileState],[ImageComparedThreshold] from [File]")) { command.Connection = connection; command.CommandTimeout = 0; if (Top.HasValue) { command.CommandText = "SELECT TOP " + Top.Value.ToString() + command.CommandText; } else { command.CommandText = "SELECT" + command.CommandText; } WhereCauseBuilder whereCauseBuilder = new WhereCauseBuilder(command.Parameters); whereCauseBuilder.AddUniqueIdentifierComparingCause("FolderId", FolderId); whereCauseBuilder.AddStringComparingCause("Path", Path, PathPropertyComparingModes); whereCauseBuilder.AddStringComparingCause("FileName", FileName, FileNamePropertyComparingModes); whereCauseBuilder.AddUniqueIdentifierComparingCause("ExtensionId", ExtensionId); whereCauseBuilder.AddBinaryComparingCause("ImageHash", ImageHash, ImageHashIsNull.IsPresent, 40); whereCauseBuilder.AddBinaryComparingCause("Sha1Hash", Sha1Hash, Sha1HashIsNull.IsPresent, 20); whereCauseBuilder.AddIntComparingCause("FileSize", FileSize, FileSizeGreaterOrEqual, FileSizeLessOrEqual); List <int> fileStates = new List <int>(); if (IncludesNewFile.IsPresent) { fileStates.Add(0); } if (IncludesNotImage.IsPresent) { fileStates.Add(1); } if (IncludesNotReadable.IsPresent) { fileStates.Add(2); } if (IncludesSizeZero.IsPresent) { fileStates.Add(254); } if (IncludesComputed.IsPresent) { fileStates.Add(255); } if (fileStates.Count != 5) { whereCauseBuilder.AddIntInRangeCause("FileState", fileStates); } whereCauseBuilder.AddRealComparingCause("ImageComparedThreshold", ImageComparedThreshold, ImageComparedThresholdGreaterOrEqual, ImageComparedThresholdLessOrEqual); command.CommandText += whereCauseBuilder.ToFullWhereCommand(); command.CommandText += " order by [FolderId], [Path], [FileName], [ExtensionId], [FileState]"; List <ImageStoreFile> result = new List <ImageStoreFile>(); using (var reader = command.ExecuteReader(System.Data.CommandBehavior.SequentialAccess)) { while (reader.Read()) { ImageStoreFile line = new ImageStoreFile((Guid)reader[0], (Guid)reader[1], (string)reader[2], (string)reader[3], (Guid)reader[4]) { ImageHash = DBNullableReader.ConvertFromReferenceType <byte[]>(reader[5]), Sha1Hash = DBNullableReader.ConvertFromReferenceType <byte[]>(reader[6]), FileSize = (int)reader[7], FileStateCode = (int)reader[8], ImageComparedThreshold = (float)reader[9] }; result.Add(line); } reader.Close(); } WriteObject(result); } }