Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Combining progress counters when copying several folders.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #19423 |

    Is there any way to combine the progress counters for two separate folders being copied into one single counter. I’m using the following code currently:

    static bool CopyFiles(string strSrc1, string strSrc2, string strDstDirectory)
    {
    DiskFolder folderSrc1 = new DiskFolder(strSrc1);
    DiskFolder folderSrc2 = new DiskFolder(strSrc2);
    DiskFolder folderDst = new DiskFolder(strDstDirectory);

    folderCopyEvents.ItemProgression +=new ItemProgressionEventHandler(OnItemProgression);
    folderCopyEvents.ItemException +=new ItemExceptionEventHandler(OnItemException);

    folderSrc1.CopyFilesTo(folderCopyEvents, “Copying”, folderDst, true, true, “”);

    return true;
    }

    private static void OnItemProgression( object sender, ItemProgressionEventArgs e )
    {

    Console.WriteLine(“{0}% finished.”, e.AllItems.Percent);

    }

    This is good, but get’s each folder’s copy progress separately. I’d like to combine the two progress counters of these two folders into one counter when calling up OnItemProgression. Is that possible with the Xceed library?

    Imported from legacy forums. Posted by rahsas (had 5114 views)

    User (Old forums)
    Member
    Post count: 23064

    Oops, I left out one line, the code is actually like this:

    static bool CopyFiles(string strSrc1, string strSrc2, string strDstDirectory)
    {
    DiskFolder folderSrc1 = new DiskFolder(strSrc1);
    DiskFolder folderSrc2 = new DiskFolder(strSrc2);
    DiskFolder folderDst = new DiskFolder(strDstDirectory);

    folderCopyEvents.ItemProgression +=new ItemProgressionEventHandler(OnItemProgression);
    folderCopyEvents.ItemException +=new ItemExceptionEventHandler(OnItemException);

    folderSrc1.CopyFilesTo(folderCopyEvents, “Copying”, folderDst, true, true, “”);
    folderSrc2.CopyFilesTo(folderCopyEvents, “Copying”, folderDst, true, true, “”);

    return true;
    }

    private static void OnItemProgression( object sender, ItemProgressionEventArgs e )
    {
    Console.WriteLine(“{0}% finished.”, e.AllItems.Percent);
    }

    Imported from legacy forums. Posted by rahsas (had 316 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi rahsas.

    There is no built-in solution, but instead of passing “Copying” as the user data, you could pass info about the starting offset and applicable range, somehow like this:

    folderSrc1.CopyFilesTo(folderCopyEvents, 50, folderDst, true, true, “”);
    folderSrc2.CopyFilesTo(folderCopyEvents, 5050, folderDst, true, true, “”);

    private static void OnItemProgression( object sender, ItemProgressionEventArgs e )
    {
    int userdata = ( int )e.UserData;
    int offset = ( int )( userdata / 100 );
    int range = userdata % 100;

    Console.WriteLine(“{0}% finished.”, offset + ( e.AllItems.Percent * range / 100 ) );
    }

    As you can see, I’m storing the offset in the “hundreds”, and the range in the modulus 100.

    Someone with a wicked mind could encapsulate event handling in a custom class which would perform those calculations automatically and raise its own events.

    But note that this is an approximation. If the first folder is much smaller (or greater) than the second, the progress bar will get to 50% faster (or slower) than it will get to 100%.

    Imported from legacy forums. Posted by Martin (had 3533 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.