예제 #1
0
        protected override void ProcessRecord()
        {
            var connection = DatabaseConnection.Current;

            using (var command = new SqlCommand("Select [File1Id],[File2Id],[DifferenceDegree],[IgnoredMode] from [SimilarFile] 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())
                    {
                        ImageStoreSimilarFile line = new ImageStoreSimilarFile(Id, (Guid)reader[0], (Guid)reader[1], (float)reader[2])
                        {
                            IgnoredModeCode = (int)reader[3]
                        };
                        WriteObject(line);
                    }
                    else
                    {
                        WriteObject(null);
                    }
                    reader.Close();
                }
            }
        }
        private void listView3_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listView3.Items)
            {
                if (!item.Selected)
                {
                    continue;
                }

                Tuple <Guid, Guid, bool> tag = (Tuple <Guid, Guid, bool>)item.Tag;
                selectedFileModeSimilarFileRecord = allRecords[tag.Item1];
                selectedFileModeFile2RowIndex     = item.Index;
                fileModeSimilarFile1IsFile1       = tag.Item3;

                if (fileModeSimilarFile1IsFile1)
                {
                    doublePictureBox1.LoadPictures(allFileInfo[selectedFileModeSimilarFileRecord.File1Id], allFileInfo[selectedFileModeSimilarFileRecord.File2Id]);
                }
                else
                {
                    doublePictureBox1.LoadPictures(allFileInfo[selectedFileModeSimilarFileRecord.File2Id], allFileInfo[selectedFileModeSimilarFileRecord.File1Id]);
                }

                button16.Enabled = true;
                button15.Enabled = true;
                button14.Enabled = true;
                button13.Enabled = true;
                button12.Enabled = true;
                button11.Enabled = true;
                button10.Enabled = true;

                return;
            }

            button16.Enabled = false;
            button15.Enabled = false;
            button14.Enabled = false;
            button13.Enabled = false;
            button12.Enabled = false;
            button11.Enabled = false;
            button10.Enabled = false;

            //fileModeFile2SelectedFileId = Guid.Empty;
            selectedFileModeSimilarFileRecord = null;
            selectedFileModeFile2RowIndex     = -1;
            doublePictureBox1.ClearPictures();
        }
        private void dataGridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //selectedRalationModeRowIndex = -1;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (!row.Selected)
                {
                    continue;
                }
                selectedRalationModeRowIndex = row.Index;
                var similarFileId = (Guid)row.Tag;
                selectedRelationModeSimilarFileRecord = allRecords[similarFileId];

                doublePictureBox1.LoadPictures(allFileInfo[selectedRelationModeSimilarFileRecord.File1Id], allFileInfo[selectedRelationModeSimilarFileRecord.File2Id]);

                button1.Enabled = true;
                button2.Enabled = true;
                button3.Enabled = true;
                button6.Enabled = true;
                button7.Enabled = true;
                button8.Enabled = true;
                button9.Enabled = true;
                return;
            }

            button1.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            button6.Enabled = false;
            button7.Enabled = false;
            button8.Enabled = false;
            button9.Enabled = false;
            selectedRalationModeRowIndex          = -1;
            selectedRelationModeSimilarFileRecord = null;
            doublePictureBox1.ClearPictures();
        }
예제 #4
0
        protected override void ProcessRecord()
        {
            if (AnotherFileId.HasValue && !FileId.HasValue)
            {
                FileId        = AnotherFileId.Value;
                AnotherFileId = null;
            }

            var    connection  = DatabaseConnection.Current;
            string commandPart = " [Id],[File1Id],[File2Id],[DifferenceDegree],[IgnoredMode] from [SimilarFile]";

            using (var command = new SqlCommand()
            {
                CommandTimeout = 0
            })
            {
                command.Connection = connection;
                if (Top.HasValue)
                {
                    command.CommandText = "SELECT TOP " + Top.Value.ToString() + commandPart;
                }
                else
                {
                    command.CommandText = "SELECT" + commandPart;
                }


                WhereCauseBuilder whereCauseBuilder = new WhereCauseBuilder(command.Parameters);

                if (FileId.HasValue)
                {
                    if (AnotherFileId.HasValue)
                    {
                        whereCauseBuilder.AddPlainCause("(([File1Id] = @File1Id and [File2Id] = @File2Id) or ([File2Id] = @File1Id and [File1Id] = @File2Id))");
                        command.Parameters.Add(new SqlParameter("@File1Id", System.Data.SqlDbType.UniqueIdentifier)
                        {
                            Value = FileId.Value
                        });
                        command.Parameters.Add(new SqlParameter("@File2Id", System.Data.SqlDbType.UniqueIdentifier)
                        {
                            Value = AnotherFileId.Value
                        });
                    }
                    else
                    {
                        whereCauseBuilder.AddPlainCause("([File1Id] = @FileId or [File2Id] = @FileId)");
                        command.Parameters.Add(new SqlParameter("@FileId", System.Data.SqlDbType.UniqueIdentifier)
                        {
                            Value = FileId.Value
                        });
                    }
                }

                whereCauseBuilder.AddRealComparingCause("DifferenceDegree", DifferenceDegree, DifferenceDegreeGreaterOrEqual, DifferenceDegreeLessOrEqual);

                List <int> ignoredModes = new List <int>();
                if (IncludesEffective.IsPresent)
                {
                    ignoredModes.Add(0);
                }
                if (IncludesHiddenButConnected.IsPresent)
                {
                    ignoredModes.Add(1);
                }
                if (IncludesHiddenAndDisconnected.IsPresent)
                {
                    ignoredModes.Add(2);
                }
                if (ignoredModes.Count != 3)
                {
                    if (ignoredModes.Count == 0)
                    {
                        ignoredModes.Add(0);
                    }
                    whereCauseBuilder.AddIntInRangeCause("IgnoredMode", ignoredModes);
                }

                command.CommandText += whereCauseBuilder.ToFullWhereCommand();

                if (OrdersByDifferenceDegree.IsPresent)
                {
                    command.CommandText += " order by [DifferenceDegree]";
                }

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

                using (var reader = command.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                {
                    while (reader.Read())
                    {
                        ImageStoreSimilarFile line = new ImageStoreSimilarFile((Guid)reader[0], (Guid)reader[1], (Guid)reader[2], (float)reader[3])
                        {
                            IgnoredModeCode = (int)reader[4]
                        };
                        result.Add(line);
                    }
                    reader.Close();
                }

                WriteObject(result);
            }
        }
예제 #5
0
        void LoadToMemory(Guid fileIdSpecified)
        {
            var connection = DatabaseConnection.Current;

            using (var command = new SqlCommand("Create table #tempSimilarFile ([Id] uniqueidentifier, [File1Id] uniqueidentifier, [File2Id] uniqueidentifier, [DifferenceDegree] real, [IgnoredMode] int)", connection))
            {
                command.ExecuteNonQuery();
            }

            var insertCommand = "insert into #tempSimilarFile Select [Id],[File1Id],[File2Id],[DifferenceDegree],[IgnoredMode] from [SimilarFile] where [DifferenceDegree]<=@DifferenceDegree";

            if (!IncludesDisconnected.IsPresent) //skip while loading to memory
            {
                insertCommand += " and [IgnoredMode]<>2";
            }
            using (var command = new SqlCommand(insertCommand, connection)
            {
                CommandTimeout = 180
            })
            {
                command.Parameters.Add(new SqlParameter("@DifferenceDegree", System.Data.SqlDbType.Real)
                {
                    Value = DifferenceDegree
                });
                if (fileIdSpecified != Guid.Empty)
                {
                    command.CommandText += " and ([File1Id] = @FileId or [File2Id] = @FileId)";
                    command.Parameters.Add(new SqlParameter("@FileId", System.Data.SqlDbType.UniqueIdentifier)
                    {
                        Value = fileIdSpecified
                    });
                }
                command.ExecuteNonQuery();
            }

            using (var command = new SqlCommand("Select [Id],[File1Id],[File2Id],[DifferenceDegree],[IgnoredMode] from #tempSimilarFile", connection)
            {
                CommandTimeout = 180
            })
            {
                using (var reader = command.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                {
                    while (reader.Read())
                    {
                        ImageStoreSimilarFile line = new ImageStoreSimilarFile((Guid)reader[0], (Guid)reader[1], (Guid)reader[2], (float)reader[3])
                        {
                            IgnoredModeCode = (int)reader[4]
                        };
                        allRecords.Add(line.Id, line);

                        if (!fileToRecords.TryGetValue(line.File1Id, out var records))
                        {
                            records = new List <Guid>();
                            fileToRecords.Add(line.File1Id, records);
                        }
                        records.Add(line.Id);
                        if (!fileToRecords.TryGetValue(line.File2Id, out records))
                        {
                            records = new List <Guid>();
                            fileToRecords.Add(line.File2Id, records);
                        }
                        records.Add(line.Id);
                    }
                }
            }

            using (var command = new SqlCommand("Create table #tempSimilarFileId ([Id] uniqueidentifier)", connection))
            {
                command.ExecuteNonQuery();
            }

            using (var command = new SqlCommand("insert into #tempSimilarFileId select distinct * from (select [File1Id] from #tempSimilarFile union select [File2Id] from #tempSimilarFile) IdTable", connection)
            {
                CommandTimeout = 180
            })
            {
                command.ExecuteNonQuery();
            }

            using (var command = new SqlCommand("drop table #tempSimilarFile", connection))
            {
                command.ExecuteNonQuery();
            }

            using (var command = new SqlCommand("Select [Id],[FolderId],[Path],[FileName],[ExtensionId],[ImageHash],[Sha1Hash],[FileSize],[FileState],[ImageComparedThreshold] from [File] Where [Id] in (select [id] from #tempSimilarFileId)", connection)
            {
                CommandTimeout = 180
            })
            {
                using (var reader = command.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                {
                    ImageStoreFile result;
                    while (reader.Read())
                    {
                        result = 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]
                        };
                        allFiles.Add(result.Id, result);
                        allFileInfo.Add(result.Id, new FileInfo());
                    }
                    reader.Close();
                }
            }


            using (var command = new SqlCommand("drop table #tempSimilarFileId", connection))
            {
                command.ExecuteNonQuery();
            }

            if (allFiles.Count > 0)
            {
                allFolders        = new Dictionary <Guid, ImageStoreFolder>();
                allExtensionNames = new Dictionary <Guid, string>();

                foreach (var folder in FolderHelper.GetAllFolders())
                {
                    allFolders.Add(folder.Id, folder);
                }

                foreach (var extension in ExtensionHelper.GetAllExtensions())
                {
                    allExtensionNames.Add(extension.Id, extension.Extension);
                }

                Parallel.ForEach(allFiles.Values, i => allFileInfo[i.Id].SetData(i, allFolders[i.FolderId], allExtensionNames[i.ExtensionId]));
            }
        }