public string Create() { _imageProfile = ImageProfile.ReadProfile(_group.ImageProfileId); if (_imageProfile == null) { return("The Image Profile Does Not Exist"); } if (_imageProfile.Image == null) { return("The Image Does Not Exist"); } var validation = Image.CheckApprovalAndChecksum(_imageProfile.Image, _userId); if (!validation.IsValid) { return(validation.Message); } _multicastSession.Port = Port.GetNextPort(); if (_multicastSession.Port == 0) { return("Could Not Determine Current Port Base"); } var dp = BLL.DistributionPoint.GetPrimaryDistributionPoint(); if (dp == null) { return("Could Not Find A Primary Distribution Point"); } _multicastSession.UserId = _userId; //End of the road for starting an on demand multicast if (_isOnDemand) { _multicastSession.Name = _group.Name; _group.Name = _multicastSession.Port.ToString(); if (!StartMulticastSender()) { return("Could Not Start The Multicast Application"); } else { return("Successfully Started Multicast " + _group.Name); } } //Continue On If multicast is for a group _multicastSession.Name = _group.Name; _computers = Group.GetGroupMembers(_group.Id); if (_computers.Count < 1) { return("The group Does Not Have Any Members"); } if (!ActiveMulticastSession.AddActiveMulticastSession(_multicastSession)) { return("Could Not Create Multicast Database Task. An Existing Task May Be Running."); } if (!CreateComputerTasks()) { ActiveMulticastSession.Delete(_multicastSession.Id); return("Could Not Create Computer Database Tasks. A Computer May Have An Existing Task."); } if (!CreatePxeFiles()) { ActiveMulticastSession.Delete(_multicastSession.Id); return("Could Not Create Computer Boot Files"); } if (!CreateTaskArguments()) { ActiveMulticastSession.Delete(_multicastSession.Id); return("Could Not Create Computer Task Arguments"); } if (!StartMulticastSender()) { ActiveMulticastSession.Delete(_multicastSession.Id); return("Could Not Start The Multicast Application"); } foreach (var computer in _computers) { Utility.WakeUp(computer.Mac); } return("Successfully Started Multicast " + _group.Name); }
private bool StartMulticastSender() { var isUnix = Environment.OSVersion.ToString().Contains("Unix"); string shell; if (isUnix) { string dist = null; var distInfo = new ProcessStartInfo { UseShellExecute = false, FileName = "uname", RedirectStandardOutput = true, RedirectStandardError = true }; using (var process = Process.Start(distInfo)) if (process != null) { dist = process.StandardOutput.ReadToEnd(); } shell = dist != null && dist.ToLower().Contains("bsd") ? "/bin/csh" : "/bin/bash"; } else { shell = "cmd.exe"; } var processArguments = GenerateProcessArguments(); if (processArguments == null) { return(false); } var senderInfo = new ProcessStartInfo { FileName = shell, Arguments = processArguments }; var logPath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "private" + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar + "multicast.log"; var logText = (Environment.NewLine + DateTime.Now.ToString("MM-dd-yy hh:mm") + " Starting Multicast Session " + _group.Name + " With The Following Command:" + Environment.NewLine + senderInfo.FileName + senderInfo.Arguments + Environment.NewLine); File.AppendAllText(logPath, logText); Process sender; try { sender = Process.Start(senderInfo); } catch (Exception ex) { Logger.Log(ex.ToString()); File.AppendAllText(logPath, "Could Not Start Session " + _group.Name + " Try Pasting The Command Into A Command Prompt"); return(false); } Thread.Sleep(2000); if (sender == null) { return(false); } if (sender.HasExited) { File.AppendAllText(logPath, "Session " + _group.Name + " Started And Was Forced To Quit, Try Running The Command Manually"); return(false); } if (_isOnDemand) { _multicastSession.Pid = sender.Id; _multicastSession.Name = _group.Name; ActiveMulticastSession.AddActiveMulticastSession(_multicastSession); } else { _multicastSession.Pid = sender.Id; ActiveMulticastSession.UpdateActiveMulticastSession(_multicastSession); } return(true); }