public static void SendPublishToRemoteComputer(Publish pub, RemotePublishLocation publoc, string pubRoot, EventHandler <SendPublishEventArgs> completed, bool dobackup) { Object[] objects = new object[5]; objects[0] = pub; objects[1] = publoc; objects[2] = pubRoot; objects[3] = completed; objects[4] = dobackup; Thread publishThread = new Thread(new ParameterizedThreadStart(SendPublish)); publishThread.Start(objects); }
private void btnOK_Click(object sender, EventArgs e) { newPublishLocation = new RemotePublishLocation(); newPublishLocation.localDrive = cmbLocalDrive.Text; newPublishLocation.name = txtPublishLocationName.Text; newPublishLocation.password = txtPassword.Text; newPublishLocation.remoteShare = txtRemoteShare.Text; newPublishLocation.username = txtUsername.Text; newPublishLocation.removeShare = chkRemoveShare.Checked; this.DialogResult = DialogResult.OK; }
private void btnDeleteRemoteLocation_Click(object sender, EventArgs e) { if (cmbRemoteLocations.SelectedItem is RemotePublishLocation == false) { return; } RemotePublishLocation rpl = cmbRemoteLocations.SelectedItem as RemotePublishLocation; PublishManager.settings.RemoteLocations.Remove(rpl); PublishManager.settings.Save(pubRoot); UpdateLocalPublishLocations(); }
public static bool GetRemotePublishLocationByComputerName(string name, out RemotePublishLocation rpl) { foreach (RemotePublishLocation r in PublishManager.settings.RemoteLocations) { if (r.remoteShare.ToLower().Contains("\\\\" + name.ToLower() + "\\")) { rpl = r; return(true); } } Trace.WriteLine("Could not find rpl named: " + name); rpl = null; return(false); }
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 btnPublish_Click(object sender, EventArgs e) { if ((cmbPublishes.SelectedItem == null) || (cmbRemoteLocations.SelectedItem == null)) { return; } RemotePublishLocation rpl = (RemotePublishLocation)cmbRemoteLocations.SelectedItem; Trace.WriteLine("Starting to publish : " + (string)cmbPublishes.SelectedItem); bool dobackup = false; if (Properties.Settings.Default.autoBackupPublishes) { dobackup = true; } else { DialogResult r = MessageBox.Show(this, "Create backup of publish " + cmbPublishes.SelectedItem + " on computer " + rpl.ToString() + "?", "Backup Exiting Publish", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); dobackup = (r == DialogResult.Yes); if (r == DialogResult.Cancel) { return; } } PublishManager.SendPublishToRemoteComputer(Publish.Load((string)cmbPublishes.SelectedItem, pubRoot), rpl, pubRoot, new EventHandler <Publisher.PublishManager.SendPublishEventArgs>(delegate(object o, Publisher.PublishManager.SendPublishEventArgs args) { this.BeginInvoke(new MethodInvoker(delegate() { Publish p = o as Publish; if (args.ok) { MessageBox.Show(this, "The Publish " + p.name + " Succeeded.", "Publisher", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(this, "The Publish Failed. Check Trace for more info.", "Publisher", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); }), dobackup); // MessageBox.Show(this, "The Publish Failed. Check Trace for more info.", "Publisher", MessageBoxButtons.OK, MessageBoxIcon.Error); }
private void btnCreateNewRemoteLocation_Click(object sender, EventArgs e) { frmNewPublishLocation newPubLoc = new frmNewPublishLocation(); newPubLoc.ShowDialog(); if (newPubLoc.DialogResult == DialogResult.OK) { RemotePublishLocation rpl = newPubLoc.newPublishLocation; if (PublishManager.settings == null) { PublishManager.settings = new PublishSettings(); } if (PublishManager.settings.RemoteLocations == null) { PublishManager.settings.RemoteLocations = new List <RemotePublishLocation>(); } PublishManager.settings.RemoteLocations.Add(rpl); PublishManager.settings.Save(pubRoot); UpdateLocalPublishLocations(); cmbRemoteLocations.SelectedItem = rpl; } }
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; }
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; }
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; }
public static void SendPublishToRemoteComputer(Publish pub, RemotePublishLocation publoc, string pubRoot, EventHandler<SendPublishEventArgs> completed, bool dobackup ) { Object[] objects = new object[5]; objects[0] = pub; objects[1] = publoc; objects[2] = pubRoot; objects[3] = completed; objects[4] = dobackup; Thread publishThread = new Thread(new ParameterizedThreadStart(SendPublish)); publishThread.Start(objects); }
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; }
public static bool GetRemotePublishLocationByComputerName(string name, out RemotePublishLocation rpl) { foreach (RemotePublishLocation r in PublishManager.settings.RemoteLocations) { if (r.remoteShare.ToLower().Contains("\\\\" + name.ToLower() + "\\")) { rpl = r; return true; } } Trace.WriteLine("Could not find rpl named: " + name); rpl = null; return false; }