Beispiel #1
0
        private void ProcessChangesIfAny()
        {
            lock (DedupLock)
            {
                if (NewFiles.Any() || DeletedFiles.Any())
                {
                    DedupTask = Task.Factory.StartNew(
                        ProcessChanges,
                        CancelSource.Token);
                    return;
                }

                if (!CurrentState.Settings.MonitorChanges)
                {
                    operationStartTime = DateTime.MinValue;
                    OnOperationUpdate(
                        OperationType.Completed,
                        ProgressStyle.NoProgress);
                    OnLogged("Finished comparison.");
                    return;
                }

                operationStartTime = DateTime.Now;
                OnOperationUpdate(
                    OperationType.Monitoring,
                    ProgressStyle.Marquee);
                OnLogged("Monitoring for file changes...");
                return;
            }
        }
Beispiel #2
0
        private void OK(object x)
        {
            var win = x as Window;

            if (System.Windows.MessageBox.Show($"Are you sure to apply change to [{ID}] ?",
                                               "Question", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                if (!NewFiles.Any(y => y[root] == this.Path))
                {
                    mDB.DeleteRecord(this.ID);
                }
                var tID = this.ID;
                foreach (var i in NewFiles)
                {
                    var t = new FileInfo(i).Name;
                    if (i[root] == this.Path)
                    {
                        mDB.UpDateFile(tID, i[root], t, this.Time);
                    }
                    else
                    {
                        mDB.AddDataItem(i[root], t, this.Time, tID, null);
                    }

                    mDB.SetUploadStatus(tID, this.Visable, this.IsUploaded);
                    tID = Database.GenerateID();
                }
                var s = "";
                System.Windows.MessageBox.Show("OK!");
                win.DialogResult = true;
            }
        }
Beispiel #3
0
        private void AddToList(object sender)
        {
            if (LSelectedItem < 0)
            {
                return;
            }
            var mItem = FolderItems[LSelectedItem];

            if (!mItem.FilePath.IsNullOrEmptyOrWhiltSpace())
            {
                FileAttributes attr = File.GetAttributes(mItem);
                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    return;
                }
                if (!NewFiles.Any(x => x == mItem))
                {
                    NewFiles.Add(mItem);
                }
            }
        }
Beispiel #4
0
 private void OpenFile(object sender)
 {
     using (var mdlg = new OpenFileDialog())
     {
         mdlg.CheckFileExists = true;
         mdlg.Filter          = "Transport Stream(*.ts;*.m2ts)|*.ts;*.m2ts|Meta Data(*.meta;*.xml)|*.meta;*.xml|All file(*.*)|*.*";
         mdlg.Multiselect     = true;
         if (mdlg.ShowDialog() == DialogResult.OK)
         {
             foreach (string i in mdlg.FileNames)
             {
                 if (!NewFiles.Any(x => x == i))
                 {
                     NewFiles.Add(i);
                 }
             }
         }
         else
         {
             return;
         }
     }
 }
Beispiel #5
0
        private void ProcessChanges()
        {
            var cancelToken = CancelSource.Token;

            while (DeletedFiles.Any())
            {
                var deletedFile = DeletedFiles.First().Key;
                _ = DeletedFiles.TryRemove(deletedFile, out var _);

                if (CurrentState.VideoFiles.Remove(deletedFile))
                {
                    CurrentState.SaveState();
                    OnLogged($"Removed file: {deletedFile.FilePath}");
                }
                else
                {
                    OnLogged($"Deleted file not in VideoFile-List: " +
                             $"{deletedFile.FilePath}");
                }
                cancelToken.ThrowIfCancellationRequested();
            }

            operationStartTime = DateTime.Now;
            OnOperationUpdate(OperationType.Comparing, 0, NewFiles.Count());
            // We need to count for the ProgressUpdate since we shrink
            // the Queue on every iteration.
            var filesProcessed = 1;

            while (NewFiles.Any())
            {
                var newFile = NewFiles.First().Key;
                _ = NewFiles.TryRemove(newFile, out var _);
                OnOperationUpdate(OperationType.Comparing, filesProcessed,
                                  filesProcessed + NewFiles.Count());
                filesProcessed++;

                if (!newFile.WaitForFileAccess(cancelToken))
                {
                    OnLogged($"Unable to access new file: {newFile.FileName}");
                    cancelToken.ThrowIfCancellationRequested();
                    continue;
                }
                cancelToken.ThrowIfCancellationRequested();

                if (newFile.Duration == TimeSpan.Zero)
                {
                    OnLogged($"New file has no duration: {newFile.FilePath}");
                    continue;
                }
                cancelToken.ThrowIfCancellationRequested();

                if (!CurrentState.VideoFiles.Contains(newFile))
                {
                    OnLogged($"New file added to VideoFile-List: {newFile.FilePath}");
                    CurrentState.VideoFiles.Add(newFile);
                }
                else
                {
                    OnLogged($"New file already in VideoFile-List: {newFile.FilePath}");
                    continue;
                }
                cancelToken.ThrowIfCancellationRequested();

                FindDuplicatesOf(CurrentState.VideoFiles, newFile, cancelToken);
                CurrentState.SaveState();
                // Cleanup in case of cancel
                foreach (var file in CurrentState.VideoFiles)
                {
                    file.DisposeImages();
                }
                cancelToken.ThrowIfCancellationRequested();
            }

            ProcessChangesIfAny();
        }