Beispiel #1
0
        private void Backup_Action(object sender, BackupActionEventArgs e)
        {
            if (!CanLog(e))
            {
                return;
            }

            if (e.Method != FileInfoEqualityMethods.None)
            {
                System.Console.WriteLine($"[{Thread.CurrentThread.ManagedThreadId:#00}] {e.Action} ({e.Method}): {GetDisplayName(e, e.SourceItem)}");
            }
            else
            {
                System.Console.WriteLine($"[{Thread.CurrentThread.ManagedThreadId:#00}] {e.Action}: {GetDisplayName(e, e.SourceItem)}");
            }
        }
        private void Backup_Action(object sender, BackupActionEventArgs e)
        {
            switch (e.Action)
            {
            case BackupAction.Created:
                if (e.SourceItem.IsDirectory())
                {
                    Interlocked.Increment(ref _directoryCreatedCount);
                }
                else
                {
                    Interlocked.Increment(ref _fileCreatedCount);
                }
                break;

            case BackupAction.Updated:
                if (e.SourceItem.IsFile())
                {
                    Interlocked.Increment(ref _fileUpdatedCount);
                }
                break;

            case BackupAction.Deleted:
                if (e.SourceItem.IsDirectory())
                {
                    Interlocked.Increment(ref _directoryDeletedCount);
                }
                else
                {
                    Interlocked.Increment(ref _fileDeletedCount);
                }
                break;

            case BackupAction.Synchronized:
                if (e.SourceItem.IsDirectory())
                {
                    Interlocked.Increment(ref _directoryCount);
                }
                else
                {
                    Interlocked.Increment(ref _fileCount);
                }

                break;
            }
        }
Beispiel #3
0
        private bool CanLog(BackupActionEventArgs e)
        {
            if (e.Action == BackupAction.Synchronized ||
                e.Action == BackupAction.Created ||
                e.Action == BackupAction.Updated ||
                e.Action == BackupAction.Deleted)
            {
                return(false);
            }

            if (e.Action == BackupAction.Creating && Level.HasFlag(ConsoleLoggerLevel.FileCreating) && e.SourceItem.IsFile())
            {
                return(true);
            }

            if (e.Action == BackupAction.Updating && Level.HasFlag(ConsoleLoggerLevel.FileUpdating) && e.SourceItem.IsFile())
            {
                return(true);
            }

            if (e.Action == BackupAction.Deleting && Level.HasFlag(ConsoleLoggerLevel.FileDeleting) && e.SourceItem.IsFile())
            {
                return(true);
            }

            if (e.Action == BackupAction.Synchronizing && Level.HasFlag(ConsoleLoggerLevel.DirectorySynchronizing) && e.SourceItem.IsDirectory())
            {
                return(true);
            }

            if (e.Action == BackupAction.Creating && Level.HasFlag(ConsoleLoggerLevel.DirectoryCreating) && e.SourceItem.IsDirectory())
            {
                return(true);
            }

            if (e.Action == BackupAction.Deleting && Level.HasFlag(ConsoleLoggerLevel.DirectoryDeleting) && e.SourceItem.IsDirectory())
            {
                return(true);
            }

            return(false);
        }
Beispiel #4
0
 private string GetDisplayName(BackupActionEventArgs e, IFileSystemInfo main)
 {
     return(GetDisplayName(e.Path, e.SourceItem, e.TargetItem, main));
 }