/// <summary> /// Deletes the saved server options. /// </summary> /// <param name="serverOptions">The GhostCast Server options to delete.</param> /// <returns>A message about success or failure.</returns> public string DeleteSavedSession(GhostCastServerOptions serverOptions) { return DeleteSavedSessionByName(serverOptions.Name); }
/// <summary> /// Validates the settings on the GhostCast Server options object. /// </summary> /// <param name="serverOptions">The options object to validate.</param> /// <returns>An empty string if the options are valid. If they are invalid then an error message is returned.</returns> public string ValidateServerOptions(GhostCastServerOptions serverOptions) { string message = String.Empty; if (serverOptions == null) { message = "Error: GhostCast server options object is null. This should never occure!"; return message; } if (!String.IsNullOrWhiteSpace(serverOptions.GhostImageFilePrimary)) { if (!serverOptions.GhostImageFilePrimary.Contains(AgentSettings.Load().GhostImageFileRootPathPrimary)) { serverOptions.GhostImageFilePrimary = Path.Combine(AgentSettings.Load().GhostImageFileRootPathPrimary, serverOptions.GhostImageFilePrimary.TrimStart('\\')); } } if (!String.IsNullOrWhiteSpace(serverOptions.GhostImageFileSecondary)) { if (!serverOptions.GhostImageFileSecondary.Contains(AgentSettings.Load().GhostImageFileRootPathSecondary)) { serverOptions.GhostImageFileSecondary = Path.Combine(AgentSettings.Load().GhostImageFileRootPathSecondary, serverOptions.GhostImageFileSecondary.TrimStart('\\')); } } if (!File.Exists(serverOptions.GhostImageFilePrimary)) { message = "Error: Ghost file (gho) does not exist: " + serverOptions.GhostImageFilePrimary; } if (serverOptions.DualDrop && !File.Exists(serverOptions.GhostImageFileSecondary)) { message = "Error: Ghost file (gho) does not exist: " + serverOptions.GhostImageFilePrimary; } List<GhostCastSession> allSessions = GetGhostCastSessions(); GhostCastSession foundSession = allSessions.Find(n => n.SessionName == serverOptions.SessionNamePrimary); if (foundSession != null && foundSession.Status.ToUpper().Contains("WAITING")) { message = "Error: Session already running and waiting to send: " + serverOptions.GhostImageFilePrimary; } foundSession = allSessions.Find(n => n.SessionName == serverOptions.SessionNameSecondary); if (foundSession != null && serverOptions.DualDrop && foundSession.Status.ToUpper().Contains("WAITING")) { message = "Error: Session already running and waiting to send: " + serverOptions.GhostImageFilePrimary; } return message; }
/// <summary> /// Returns the command line arguments for the Ghostsrv.exe launch for the secondary session. /// </summary> /// <param name="serverOptions">All required ghostcast server options as an object.</param> /// <returns>The command line arguments as a single string.</returns> private string GetGhostServerCommandlineArgsSecondary(GhostCastServerOptions serverOptions, bool ignoreCloseOnCompletion) { StringBuilder sb = new StringBuilder(); // Ghost image file. if (serverOptions.GhostImageFileSecondary == null) { throw new Exception("Error: GhostCast Server image file is not set and equal to null."); } else if (!File.Exists(serverOptions.GhostImageFileSecondary)) { throw new Exception("Error: GhostCast Server image file does not exist.\nPath: " + serverOptions.GhostImageFilePrimary); } else { sb.Append(" \"" + serverOptions.GhostImageFileSecondary.Trim('"') + "\""); } // Session name. if (serverOptions.SessionNameSecondary == null || String.IsNullOrEmpty(serverOptions.SessionNameSecondary)) { throw new Exception("Error: GhostCast Server Session Name is not set."); } else { sb.Append(" " + serverOptions.SessionNameSecondary); } // Partition options. if (serverOptions.PartitionNoSecondary > 0) { sb.Append(" -P" + serverOptions.PartitionNoSecondary); } // Auto start options. if (serverOptions.AutoStartClientCount > 0) { sb.Append(" -N" + serverOptions.AutoStartClientCount); } else if (serverOptions.AutoStartTimeout > 0) { sb.Append(" -O" + serverOptions.AutoStartTimeout); } else if (!String.IsNullOrWhiteSpace(serverOptions.AutoStartTime) && Regex.IsMatch(serverOptions.AutoStartTime, @"\d\d:\d\d")) { sb.Append(" -T" + serverOptions.AutoStartTime); } // Mode switch. switch (serverOptions.ForceMode) { case GhostCastServerOptions.Mode.Multicast: { sb.Append(" -UM"); break; } case GhostCastServerOptions.Mode.DirectedBroadcast: { sb.Append(" -UD"); break; } case GhostCastServerOptions.Mode.Unicast: { sb.Append(" -UU"); break; } } // Restart options. if (serverOptions.OnCompletion == GhostCastServerOptions.CompletionAction.Close && !ignoreCloseOnCompletion) { sb.Append(" -C"); } else if (serverOptions.OnCompletion == GhostCastServerOptions.CompletionAction.Restart) { sb.Append(" -R"); } // Logging options. string logFilePath = Path.Combine(AgentSettings.SessionLogPath, serverOptions.SessionNameSecondary + AgentSettings.ConsoleLogFileSuffix); sb.Append(" -LI -F\"" + logFilePath + "\""); return sb.ToString(); }
/// <summary> /// If the passed server options already exists, updates the saved settings. /// If it does not exist a new server option is saved. /// </summary> /// <param name="serverOptions">GhostCast Server options to be saved.</param> /// <returns>A message about success or failure.</returns> public string SaveSession(GhostCastServerOptions serverOptions) { serverOptions.GhostImageFilePrimary = serverOptions.GhostImageFilePrimary.Trim('"'); serverOptions.GhostImageFileSecondary = serverOptions.GhostImageFileSecondary.Trim('"'); List<GhostCastServerOptions> sessions = GetAllSavedSessions(); GhostCastServerOptions foundOptions = sessions.Find(n => n.Name == serverOptions.Name); if (foundOptions == null) { sessions.Add(serverOptions); } else { sessions.Remove(foundOptions); sessions.Add(serverOptions); } sessions.Sort(); SaveSessions(sessions); return Log.Write(String.Format("GhostCast Server options saved for {0}.", serverOptions.Name)); }