Code Examples
  Home arrow Code Examples arrow Page 3 - Implementing the CompressedFolder Class
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Implementing the CompressedFolder Class
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-03-19

    Table of Contents:
  • Implementing the CompressedFolder Class
  • More internal methods
  • Examining the Support Methods
  • Wrapping up

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Implementing the CompressedFolder Class - Examining the Support Methods


    (Page 3 of 4 )

    The support methods I’ve created simply add functionality to my class.  They are the various functions and routines that are used in conjunction with the ones you saw on the last page.  I’ll go through each of them and explain their purpose.  You should get a clearer picture that way.

    Private Function GetItemCount(strZipFile)

       GetItemCount = objShell.NameSpace(strZipFile).Items.Count

    End Function

    The GetItemCount function is used to populate the class object’s Count property.  Since the Count property provides a real-time count of the files in the compressed folder, I needed to create a function that would calculate that value whenever the property was referenced.  I’m simply returning to the Shell Object to get an item count on the folder. (This is a prime example of keeping my code inside of a function rather than processing it inside of the property block itself.)

    Private Function ShellBusy()

       intStartSize = objFso.GetFile(FullName).Size

       Sleep 500

       ShellBusy = objFso.GetFile(FullName).Size > intStartSize

    End Function

    As I mentioned briefly earlier, the Shell object’s move and copy procedures are performed synchronously.  This means that the script will continue to execute while the process completes in the background.  Since there are no easily available events, it becomes difficult to monitor the completion status and success of these actions.

    To circumvent these shortcomings, I’ve created a bit of code that works to pause script execution until these actions complete—essentially, turning this into an asynchronous process.  You can see this code in action in the AddFile Method.  I’m basically monitoring the starting folder count and waiting until the count changes, indicating that the file has been successfully added. 

    This poses a slight problem.  In the event of a copy error, the folder count would never change, thus the script would suspend indefinitely.  So I needed a better solution.

    The Shell object does not provide any means of monitoring its busy status.  It also does not provide any events to indicate when a move or copy process completes.  You could create a viable solution using WMI events (and possibly its move and copy methods, which I have not tested with compressed folders), but that would be a lot of very advanced code.

    I decided to set a timeout limit on my loop so that it couldn’t cause the entire script to hang.  In the meantime, I created the ShellBusy routine that attempts to determine whether the Shell object is still busy moving files around.  It works in much the same way as my previous loop, only it uses the Shell object to monitor disk size for changes.  Since the disk size value changes more frequently than the file count (during time-consuming processes, such as when moving large files), it provided a more accurate means of watching the processes.  This method is slightly better than the first, but since neither of them is foolproof, I elected to use them together.

    Private Sub Sleep(intDuration)

       'You must provide an applicable sleep routine for use in ASP.

       WScript.Sleep intDuration

    End Sub

    This simple Sleep routine is just a wrapper for a call to the WScript object’s own Sleep method.  Since the WScript object is only available in WSH (and I wanted my class to be compatible with ASP, WSC, HTA, etc.), I used a wrapper function to allow developers to drop in a compatible sleep function without having to edit any of the previous methods.

    More Code Examples Articles
    More By Nilpo


     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek