public static bool MapAllDrives() { Trace.WriteLine("Mapping all network drives-----------------------"); if (mountedDrives != null) { return(false); } mountedDrives = new List <string>(); foreach (RemotePublishLocation rpl in PublishManager.settings.RemoteLocations) { try { string drv = NetworkDrive.GetNextAvailableDrive(); NetworkDrive.zMapDrive(rpl.username, rpl.password, drv, rpl.remoteShare); mountedDrives.Add(drv); Debug.Write("."); } catch { Trace.WriteLine("Could not map network drive to " + rpl.remoteShare); } } Trace.WriteLine("Done Mapping Drives."); return(true); }
public static void SendPublishDefinitionOnly(Publish pub, RemotePublishLocation publoc, string pubRoot) { Trace.WriteLine("------------Attempting to send publish definition " + pub.name + " to " + publoc.name + ".---------------"); string netDrive = NetworkDrive.GetNextAvailableDrive(); if (publoc.remoteShare.EndsWith("\\")) { publoc.remoteShare = publoc.remoteShare.Remove(publoc.remoteShare.Length - 1); } Trace.WriteLine("Mounting Drive " + netDrive + " to " + publoc.remoteShare + "..."); try { NetworkDrive.zMapDrive(publoc.username, publoc.password, netDrive, publoc.remoteShare); } catch (Exception ex) { Trace.WriteLine("Failed to map network drive! " + ex.Message); return; } Trace.WriteLine("Copying files..."); try { File.Copy(Publish.FilenameFromPublishname(pub.name, pubRoot), netDrive + "\\" + pub.name + Publish.pubExt, true); } catch (IOException ex) { Trace.WriteLine("Error copying file " + Publish.FilenameFromPublishname(pub.name, pubRoot) + "."); Trace.WriteLine("Check the publish is stopped and that your definition of the publish is recent. Detail:" + ex.Message); NetworkDrive.zUnMapDrive(true, netDrive); Trace.WriteLine("Published Defition Failed!----------------------------------------"); return; } pub.lastPublish = DateTime.Now; pub.Save(pubRoot); if (publoc.removeShare) { NetworkDrive.zUnMapDrive(true, netDrive); } Trace.WriteLine("Published Defition Sent OK!----------------------------------------------"); return; }
private void PopulateCmbNetworkDrives() { cmbLocalDrive.Items.Clear(); for (int i = 0; i < 26; i++) { byte[] tmp = new byte[1]; tmp[0] = (byte)(i + 65); string drv = Encoding.ASCII.GetString(tmp) + ":\\"; cmbLocalDrive.Items.Add(drv); } string next = NetworkDrive.GetNextAvailableDrive(); foreach (string s in cmbLocalDrive.Items) { if (s.Equals(next)) { cmbLocalDrive.SelectedItem = s; } } }
public static bool UnmapAllDrives() { if (mountedDrives == null) { return(false); } foreach (string s in mountedDrives) { try { NetworkDrive.zUnMapDrive(true, s); Debug.Write("."); } catch { Trace.WriteLine("Could not unmap network drive to " + s); } } mountedDrives = null; Trace.WriteLine("Done Unmapping Drives."); return(true); }
public static void SyncPublishWithRemotePublishDefinition(string pubname, string pubRoot, RemotePublishLocation publoc) { Trace.WriteLine("Attempting to sync publish " + pubname + " with " + publoc.name + "."); string netDrive = NetworkDrive.GetNextAvailableDrive(); if (publoc.remoteShare.EndsWith("\\")) { publoc.remoteShare = publoc.remoteShare.Remove(publoc.remoteShare.Length - 1); } Trace.WriteLine("Mounting Drive " + netDrive + " to " + publoc.remoteShare + "..."); try { NetworkDrive.zMapDrive(publoc.username, publoc.password, netDrive, publoc.remoteShare); } catch (Exception ex) { Trace.WriteLine("Failed to map network drive! " + ex.Message); return; } Trace.WriteLine("Copying files..."); //the file SHOULD be located now on the drive with the pub name....so load it.... try { File.Copy(Publish.FilenameFromPublishname(pubname, netDrive), Publish.FilenameFromPublishname(pubname, pubRoot), true); } catch (IOException) { Trace.WriteLine("Could not sync the file. It may not exist on the remote machine or is locked for some other reason."); NetworkDrive.zUnMapDrive(true, netDrive); return; } Trace.WriteLine("Synced Published OK!"); return; }
private static void SendPublish(Object o) { Object[] objects = (Object[])o; Publish pub = (Publish)objects[0]; RemotePublishLocation publoc = (RemotePublishLocation)objects[1]; string pubRoot = (string)objects[2]; EventHandler <SendPublishEventArgs> completed = (EventHandler <SendPublishEventArgs>)objects[3]; bool dobackup = (bool)objects[4]; Trace.WriteLine("------------Attempting to publish " + pub.name + " to " + publoc.name + ".---------------"); string netDrive = NetworkDrive.GetNextAvailableDrive(); if (publoc.remoteShare.EndsWith("\\")) { publoc.remoteShare = publoc.remoteShare.Remove(publoc.remoteShare.Length - 1); } Trace.WriteLine("Mounting Drive " + netDrive + " to " + publoc.remoteShare + "..."); try { NetworkDrive.zMapDrive(publoc.username, publoc.password, netDrive, publoc.remoteShare); } catch (Exception ex) { Trace.WriteLine("Failed to map network drive! " + ex.Message); completed(pub, new SendPublishEventArgs(false)); return; } if (dobackup) { string backupDir = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "." + DateTime.Now.Minute + "." + DateTime.Now.Second; Trace.WriteLine("Backing up existing copy files to \\" + backupDir + "\\..."); if (Directory.Exists(netDrive + pub.relativeLocation)) { Directory.CreateDirectory(netDrive + pub.relativeLocation + "\\" + backupDir); string[] files = Directory.GetFiles(netDrive + pub.relativeLocation, "*.*", SearchOption.TopDirectoryOnly); foreach (string file in files) { if (file.ToLower().Contains("log")) { continue; } try { File.Copy(file, netDrive + pub.relativeLocation + "\\" + backupDir + "\\" + Path.GetFileName(file)); } catch (Exception ex) { Trace.WriteLine("Warning: Could not backup file " + Path.GetFileName(file) + "." + ex.Message); } } } else { Trace.WriteLine("Warning: No files found to backup!"); } } Trace.WriteLine("Copying files..."); if (pub.files != null) { foreach (string pubFile in pub.files) { string lpath = settings.RepoRoot + pubFile; string filename = Path.GetFileName(pubFile); string rpath = netDrive + pub.relativeLocation + "\\" + filename; Directory.CreateDirectory(netDrive + pub.relativeLocation); Trace.WriteLine("copying " + filename); try { File.Copy(lpath, rpath, true); } catch (IOException ex) { Trace.WriteLine("Error Copying file: " + lpath + ". Detail: " + ex.Message); NetworkDrive.zUnMapDrive(true, netDrive); Trace.WriteLine("Published Failed!----------------------------------------"); completed(pub, new SendPublishEventArgs(false)); return; } catch (NotSupportedException ex) { Trace.WriteLine("Error Copying file: " + lpath + ". The file does not appear to be in the repository. Detail: " + ex.Message); NetworkDrive.zUnMapDrive(true, netDrive); Trace.WriteLine("Published Failed!----------------------------------------"); completed(pub, new SendPublishEventArgs(false)); return; } } } try { File.Copy(Publish.FilenameFromPublishname(pub.name, pubRoot), netDrive + "\\" + pub.name + Publish.pubExt, true); } catch (IOException ex) { Trace.WriteLine("Error copying file " + Publish.FilenameFromPublishname(pub.name, pubRoot) + "."); Trace.WriteLine("Check the publish is stopped and that your definition of the publish is recent. Detail:" + ex.Message); NetworkDrive.zUnMapDrive(true, netDrive); completed(pub, new SendPublishEventArgs(false)); Trace.WriteLine("Published Failed!----------------------------------------"); return; } pub.lastPublish = DateTime.Now; pub.Save(pubRoot); if (publoc.removeShare) { NetworkDrive.zUnMapDrive(true, netDrive); } Trace.WriteLine("Published OK!----------------------------------------------"); completed(pub, new SendPublishEventArgs(true)); return; }