Exemplo n.º 1
0
        protected override void ProcessRecord()
        {
            var connection = DatabaseConnection.Current;

            using (var command = new SqlCommand("Select [Id],[Path],[Name],[CompareImageWith],[IsSealed] from [Folder]"))
            {
                command.Connection = connection;
                WhereCauseBuilder whereCauseBuilder = new WhereCauseBuilder(command.Parameters);

                whereCauseBuilder.AddStringComparingCause("Name", Name, NamePropertyComparingModes);
                whereCauseBuilder.AddStringComparingCause("Path", Path, PathPropertyComparingModes);
                whereCauseBuilder.AddIntComparingCause("CompareImageWith", (int?)CompareImageWith);
                whereCauseBuilder.AddBitComparingCause("IsSealed", IsSealed);

                command.CommandText += whereCauseBuilder.ToFullWhereCommand();

                List <ImageStoreFolder> result = new List <ImageStoreFolder>();

                using (var reader = command.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                {
                    while (reader.Read())
                    {
                        ImageStoreFolder line = new ImageStoreFolder((Guid)reader[0], (string)reader[1])
                        {
                            Name = (string)reader[2],
                            CompareImageWithCode = (int)reader[3],
                            IsSealed             = (bool)reader[4]
                        };
                        result.Add(line);
                    }
                    reader.Close();
                }

                WriteObject(result);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }