本文整理汇总了C#中Task.GetPort方法的典型用法代码示例。如果您正苦于以下问题:C# Task.GetPort方法的具体用法?C# Task.GetPort怎么用?C# Task.GetPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Task
的用法示例。
在下文中一共展示了Task.GetPort方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartCustomMC
public bool StartCustomMC(string imageName)
{
string appPath = null;
string logPath = null;
string shell = null;
if (Environment.OSVersion.ToString().Contains("Unix"))
{
string dist = null;
ProcessStartInfo distInfo = new ProcessStartInfo();
distInfo.UseShellExecute = false;
distInfo.FileName = "uname";
distInfo.RedirectStandardOutput = true;
distInfo.RedirectStandardError = true;
using (Process process = Process.Start(distInfo))
{
dist = process.StandardOutput.ReadToEnd();
}
Logger.Log("Distro is " + dist);
if(dist.ToLower().Contains("bsd"))
shell = "/bin/csh";
else
shell = "/bin/bash";
logPath = HttpContext.Current.Server.MapPath("~") + @"/data/logs" + @"/";
}
else
{
appPath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "apps" + Path.DirectorySeparatorChar;
logPath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar;
shell = "cmd.exe";
}
Multicast multicast = new Multicast();
Utility settings = new Utility();
string fullImagePath = null;
Task task = new Task();
int portBase = task.GetPort();
string senderArgs = settings.GetSettings("Sender Args");
Process multiSender = null;
ProcessStartInfo senderInfo = new ProcessStartInfo();
senderInfo.FileName = (shell);
string udpFile = null;
String[] partFiles = null;
string compExt = null;
string compAlg = null;
string stdout = null;
//Multicasting currently only supports the first active hd
//Find First Active HD
Image image = new Image();
image.ID = image.GetImageID(imageName);
image.Read(image);
Image_Physical_Specs ips = new Image_Physical_Specs();
if (!string.IsNullOrEmpty(image.ClientSizeCustom))
{
ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSizeCustom);
try
{
ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSizeCustom);
}
catch { }
}
else
{
ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);
try
{
ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);
}
catch { }
}
string activeHD = null;
int activeCounter = 0;
foreach (var hd in ips.hd)
{
if (hd.active == "1")
{
activeHD = activeCounter.ToString();
break;
}
activeCounter++;
}
if (activeCounter == 0)
{
fullImagePath = settings.GetSettings("Image Store Path") + imageName;
}
else
{
fullImagePath = settings.GetSettings("Image Store Path") + imageName + Path.DirectorySeparatorChar + "hd" + (activeCounter + 1).ToString();
}
try
{
//.........这里部分代码省略.........
示例2: CreatePxeBoot
//.........这里部分代码省略.........
Utility.Message = "Could Not Create PXE File";
return false;
}
}
else
{
if (mode == "pxelinux" || mode == "syslinux_32_efi" || mode == "syslinux_64_efi")
{
path = settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeHostMac;
string[] tmplines = { @"DEFAULT cruciblewds",
@"LABEL cruciblewds", @"KERNEL " + "kernels" + Path.DirectorySeparatorChar + unicast.HostKernel ,
@"APPEND initrd=" + "images" + Path.DirectorySeparatorChar + unicast.HostBootImage + " root=/dev/ram0 rw ramdisk_size=127000 ip=dhcp imgDirection=" + direction + " consoleblank=0" + " web=" + settings.GetSettings("Web Path") + " WDS_KEY=" + wds_key + " " + settings.GetSettings("Global Host Args") + " " + unicast.HostArguments};
lines = tmplines;
}
else if (mode.Contains("ipxe"))
{
path = settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeHostMac + ".ipxe";
string[] tmplines = {@"#!ipxe",
@"kernel " + "http://"+ settings.GetServerIP() +"/cruciblewds/data/boot/kernels/" + unicast.HostKernel + ".krn" + " initrd=" + unicast.HostBootImage + " root=/dev/ram0 rw ramdisk_size=127000 ip=dhcp imgDirection=" + direction + " consoleblank=0" + " web=" + settings.GetSettings("Web Path") + " WDS_KEY=" + wds_key + " " + settings.GetSettings("Global Host Args") + " " + unicast.HostArguments,
@"imgfetch " + "http://"+ settings.GetServerIP() +"/cruciblewds/data/boot/images/" + unicast.HostBootImage ,
@"boot"};
lines = tmplines;
}
else
{
Utility.Message = "PXE Mode Is Not Set Correctly";
return false;
}
if (File.Exists(path))
{
Host hostFunction = new Host();
if (hostFunction.IsCustomBootEnabled(Task.PXEMacToMac(pxeHostMac)))
{
if (mode.Contains("ipxe"))
Utility.MoveFile(settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeHostMac + ".ipxe", settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeHostMac + ".ipxe.custom");
else
Utility.MoveFile(settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeHostMac, settings.GetSettings("Tftp Path") + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeHostMac + ".custom");
}
else
{
Utility.Message = "The PXE File Already Exists";
return false;
}
}
try
{
System.IO.File.WriteAllLines(path, lines);
if (Environment.OSVersion.ToString().Contains("Unix"))
{
Syscall.chmod(path, (FilePermissions.S_IWUSR | FilePermissions.S_IRGRP | FilePermissions.S_IROTH | FilePermissions.S_IRUSR));
}
}
catch (Exception ex)
{
Logger.Log(ex.ToString());
Utility.Message = "Could Not Create PXE File";
return false;
}
}
try
{
string storagePath = null;
string xferMode = settings.GetSettings("Image Transfer Mode");
if (xferMode == "smb" || xferMode == "smb+http")
storagePath = "SMB Path";
else
{
if (direction == "pull")
storagePath = "Nfs Upload Path";
else
storagePath = "Nfs Deploy Path";
}
string hostArgs = "imgName=" + unicast.ImageName + " storage=" + settings.GetSettings(storagePath) + " hostID=" + hostID +
" imgOS=" + unicast.ImageOS + " multicast=" + isMulticast + " hostScripts=" + unicast.HostScripts + " xferMode=" + xferMode + " serverIP=" + settings.GetSettings("Server IP") +
" hostName=" + unicast.HostName + " compAlg=" + settings.GetSettings("Compression Algorithm") + " compLevel=-" + settings.GetSettings("Compression Level");
if(direction == "pull" && xferMode == "udp+http")
{
int portBase = task.GetPort();
hostArgs = hostArgs + " portBase=" + portBase;
}
if (task.CreateTaskArgs(hostArgs,taskID))
return true;
else
return false;
}
catch (Exception ex)
{
Logger.Log(ex.ToString());
Utility.Message = "Could Not Create PXE File";
return false;
}
}
示例3: CreateMulticast
public void CreateMulticast(int groupID)
{
Multicast multicast = new Multicast();
Utility settings = new Utility();
Task task = new Task();
int portBase = task.GetPort();
if (portBase != 0)
{
multicast = multicast.Read(groupID);
if (multicast != null)
{
if (String.IsNullOrEmpty(multicast.GroupSenderArgs))
multicast.GroupSenderArgs = settings.GetSettings("Sender Args");
if (multicast.HostNames.Count > 0)
{
if (CheckAllHostsEqual(multicast))
{
if (CreateMulticastTask(multicast, "push", "true", portBase))
{
if (StartMulticastSender(multicast, portBase))
{
History history = new History();
history.Event = "Multicast";
history.Type = "Group";
history.TypeID = groupID.ToString();
history.CreateEvent(history);
Host host = new Host();
foreach (string mac in HostMacs)
{
history.Event = "Deploy";
history.Type = "Host";
history.Notes = "Via Group Multicast: " + multicast.GroupName;
history.TypeID = host.GetHostID(mac);
history.CreateEvent(history);
}
foreach (string name in HostNames)
{
Image image = new Image();
history.Event = "Deploy";
history.Type = "Image";
history.Notes = name;
history.TypeID = image.GetImageID(multicast.GroupImage);
history.CreateEvent(history);
}
}
else
RollBack(multicast, true, true, true);
}
}
}
else
Utility.Message = "The Group Does Not Have Any Hosts";
}
}
}