Author Topic: Storing Resource drawings on Server vs. Local  (Read 1802 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Storing Resource drawings on Server vs. Local
« on: May 14, 2012, 06:28:37 PM »
Anyone who has worked off a server knows how a server can lag sometimes.
 
Do any of you copy resource drawings during startup or when app loaded, or during idle event?
 
So you do not have to go out to server for simple WblockClones, etc.....
 
If you do copy them local has it worked for you and would you suggest it?
 
Just a simple example
 
Code - C#: [Select]
  1.  
  2.     static void Main(string[] args)
  3.         {
  4.          
  5.             var t = new Task(() =>
  6.                 {
  7.                     CopyDirectory(@"J:\CadMgd\HGCE\Imperial", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)  
  8.  @"\Hpad");
  9.                    
  10.                 }
  11.                     );
  12.             t.Start();
  13.             Console.ReadLine();
  14.         }
  15.  
  16.         private static void CopyDirectory(string sourcePath, string destPath)
  17.         {
  18.             if (!Directory.Exists(destPath))
  19.             {
  20.                 Directory.CreateDirectory(destPath);
  21.             }
  22.             foreach (string file in Directory.GetFiles(sourcePath))
  23.             {
  24.                 string dest = Path.Combine(destPath, Path.GetFileName(file));
  25.                 File.Copy(file, dest);
  26.             }
  27.             foreach (string folder in Directory.GetDirectories(sourcePath))
  28.             {
  29.                 string dest = Path.Combine(destPath, Path.GetFileName(folder));
  30.                 CopyDirectory(folder, dest);
  31.             }
  32.         }
  33.  

Have not done much with lambdas in VB and wonder what they looked like
Code - Visual Basic: [Select]
  1.  
  2.      Public Sub Main()
  3.         Dim t = New Task(Sub()
  4.                              CopyDirectory("J:\CadMgd\HGCE\Imperial", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\Hpad")
  5.                          End Sub)
  6.         t.Start()
  7.         Console.ReadLine()
  8.     End Sub
  9.  
  10.     Private Sub CopyDirectory(sourcePath As String, destPath As String)
  11.         If Not Directory.Exists(destPath) Then
  12.             Directory.CreateDirectory(destPath)
  13.         End If
  14.         For Each file__1 As String In Directory.GetFiles(sourcePath)
  15.             Dim dest As String = Path.Combine(destPath, Path.GetFileName(file__1))
  16.             File.Copy(file__1, dest)
  17.         Next
  18.         For Each folder As String In Directory.GetDirectories(sourcePath)
  19.             Dim dest As String = Path.Combine(destPath, Path.GetFileName(folder))
  20.             CopyDirectory(folder, dest)
  21.         Next
  22.     End Sub
  23.  

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Storing Resource drawings on Server vs. Local
« Reply #1 on: May 15, 2012, 10:00:47 AM »
I forgot to add and would it cause a problem if I copied over at startup, pc3, plot style tables, etc... which I thought one or some the files for plotting if changed AutoCAD had to be restarted.

TheMaster

  • Guest
Re: Storing Resource drawings on Server vs. Local
« Reply #2 on: May 15, 2012, 10:29:50 PM »
I forgot to add and would it cause a problem if I copied over at startup, pc3, plot style tables, etc... which I thought one or some the files for plotting if changed AutoCAD had to be restarted.

I've used simple login scripts that compare file timestamps or crc's and avoid redundant or needless file copying.

You can also do the same on a demand-driven basis, at the point when you need a file, you can check to see if a local copy doesn't exist or is older than the remote copy, and copy the file from the remote location only if either of those conditions are true.

If you are copying on another thread, you need to be sure that none of those files will be accessed by a process on the local system before the copying is done.

[edit]  I found this in one of my helper libraries.

Code - C#: [Select]
  1.  
  2. public static class FileUtils
  3. {
  4.   public static bool CopyEx( string source, string destination )
  5.   {
  6.     if( string.IsNullOrEmpty( source ) )
  7.       throw new ArgumentException( "source cannot be null or empty" );
  8.     if( string.IsNullOrEmpty( destination ) )
  9.       throw new ArgumentException( "destination cannot be null or empty" );
  10.     if( string.Equals( source, destination, StringComparison.OrdinalIgnoreCase ) )
  11.       throw new InvalidOperationException("source and destination cannot be the same" );
  12.     if( ! File.Exists( source ) )
  13.       throw new FileNotFoundException( source );
  14.     if( ! File.Exists( destination ) )
  15.     {
  16.       File.Copy( source, destination );
  17.       return true;
  18.     }
  19.     DateTime destTime = File.GetLastWriteTimeUtc( destination );
  20.     DateTime sourceTime = File.GetLastWriteTimeUtc( source );
  21.     if( sourceTime > destTime )
  22.     {
  23.       File.Copy( source, destination, true );
  24.       return true;
  25.     }
  26.     return false;
  27.   }
  28. }
  29.  
« Last Edit: May 16, 2012, 05:23:39 PM by TheMaster »