Ejemplo n.º 1
0
        private void Entry()
        {
            listBox.DisplayMemberPath = "Name";

            var filesFromDatabase = _conn.FetchAll("select path, hash from files;");

            _filesFromDir = _overwatch.Files;

            filesFromDatabase.ForEach(row => {
                if (_filesFromDir.Count(x => x.FullName == (string)row[0]) == 0)
                {
                    listBoxForLostFiles.Items.Add((string)row[0]);
                }
                else
                {
                    var file = _filesFromDir.Where(x => x.FullName == (string)row[0]).ElementAt(0);
                    listBox.Items.Add(file);
                    _filesFromDir.Remove(file);
                }
            });

            _filesFromDir.ForEach(file => {
                var md5 = file.Md5;
                if (            // if row with same hash already exists in database
                    (int)_conn.FetchAll($"select count(*) from files where hash = '{md5}';")[0][0] == 0
                    )
                {
                    _conn.ExecuteUpdate($"execute procedure addFile('{file.Name}','{file.FullName}','{file.Md5}');");
                    _conn.ExecuteUpdate($"execute procedure bindTagToFile('new', '{file.FullName}');");
                }
                else
                {
                    _conn.ExecuteUpdate($"update files set filename = '{file.Name}'," +
                                        $"path = '{file.FullName}' where hash = '{md5}';");
                }
                listBox.Items.Add(file);
            });

            listBox.SelectionChanged += (sender, e) => {
                RenderOutputForFile();
            };

            _watcher.RenderRequested += (s, e) => {
                this.Dispatcher.Invoke(() => {
                    listBox.Items.Clear();
                    _overwatch.Files.ForEach(file => listBox.Items.Add(file));
                });
            };
        }
Ejemplo n.º 2
0
        private void OnFileChanged(object sender, FileSystemEventArgs e)
        {
            try {
                EnableRaisingEvents = false;

                var changedFile = new MediaFileInfo(e.FullPath);

                _conn.ExecuteUpdate(
                    $"update files set hash = '{changedFile.Md5}' where path = '{changedFile.FullName}';"
                    );

                OnRenderRequested(EventArgs.Empty);
            } finally {
                EnableRaisingEvents = true;
            }
        }