BLL.Workflows.DefaultBootMenu.CreateIpxeMenu C# (CSharp) Method

CreateIpxeMenu() private method

private CreateIpxeMenu ( ) : void
return void
        private void CreateIpxeMenu()
        {
            var customMenuEntries = BLL.BootEntry.SearchBootEntrys().Where(x => x.Type == "ipxe" && x.Active == 1).OrderBy(x => x.Order).ThenBy(x => x.Name);
            var defaultCustomEntry = customMenuEntries.FirstOrDefault(x => x.Default == 1);

            var ipxeMenu = new StringBuilder();

            ipxeMenu.Append("#!ipxe" + NewLineChar);
            ipxeMenu.Append("chain 01-${net0/mac:hexhyp}.ipxe || chain 01-${net1/mac:hexhyp}.ipxe || goto Menu" + NewLineChar);
            ipxeMenu.Append("" + NewLineChar);
            ipxeMenu.Append(":Menu" + NewLineChar);
            ipxeMenu.Append("menu Boot Menu" + NewLineChar);
            ipxeMenu.Append("item bootLocal Boot To Local Machine" + NewLineChar);
            ipxeMenu.Append("item console Client Console" + NewLineChar);
            ipxeMenu.Append("item register Add Computer" + NewLineChar);
            ipxeMenu.Append("item ond On Demand" + NewLineChar);
            ipxeMenu.Append("item diag Diagnostics" + NewLineChar);
            foreach (var customEntry in customMenuEntries)
            {
                ipxeMenu.Append("item " + _alphaNumericNoSpace.Replace(customEntry.Name, "") + " " +
                                _alphaNumericSpace.Replace(customEntry.Name, "") + NewLineChar);
            }
            if(defaultCustomEntry == null)
                ipxeMenu.Append("choose --default bootLocal --timeout 5000 target && goto ${target}" + NewLineChar);
            else
            {
                ipxeMenu.Append("choose --default " + _alphaNumericNoSpace.Replace(defaultCustomEntry.Name,"") + " --timeout 5000 target && goto ${target}" + NewLineChar);
            }
            ipxeMenu.Append("" + NewLineChar);

            if (Settings.IpxeRequiresLogin == "True")
            {
                ipxeMenu.Append(":bootLocal" + NewLineChar);
                ipxeMenu.Append("exit" + NewLineChar);
                ipxeMenu.Append("" + NewLineChar);

                ipxeMenu.Append(":console" + NewLineChar);
                ipxeMenu.Append("set task debug" + NewLineChar);
                ipxeMenu.Append("goto login" + NewLineChar);
                ipxeMenu.Append("" + NewLineChar);

                ipxeMenu.Append(":register" + NewLineChar);
                ipxeMenu.Append("set task register" + NewLineChar);
                ipxeMenu.Append("goto login" + NewLineChar);
                ipxeMenu.Append("" + NewLineChar);

                ipxeMenu.Append(":ond" + NewLineChar);
                ipxeMenu.Append("set task ond" + NewLineChar);
                ipxeMenu.Append("goto login" + NewLineChar);

                ipxeMenu.Append("" + NewLineChar);
                ipxeMenu.Append(":diag" + NewLineChar);
                ipxeMenu.Append("set task diag" + NewLineChar);
                ipxeMenu.Append("goto login" + NewLineChar);
                ipxeMenu.Append("" + NewLineChar);

                ipxeMenu.Append(":login" + NewLineChar);
                ipxeMenu.Append("login" + NewLineChar);
                ipxeMenu.Append("params" + NewLineChar);
                ipxeMenu.Append("param uname ${username:uristring}" + NewLineChar);
                ipxeMenu.Append("param pwd ${password:uristring}" + NewLineChar);
                ipxeMenu.Append("param kernel " + Kernel + "" + NewLineChar);
                ipxeMenu.Append("param bootImage " + BootImage + "" + NewLineChar);
                ipxeMenu.Append("param task " + "${task}" + "" + NewLineChar);
                ipxeMenu.Append("echo Authenticating" + NewLineChar);
                ipxeMenu.Append("chain --timeout 15000 " + Settings.WebPath + "IpxeLogin##params || goto Menu" +
                                NewLineChar);
            }
            else
            {
                ipxeMenu.Append(":bootLocal" + NewLineChar);
                ipxeMenu.Append("exit" + NewLineChar);
                ipxeMenu.Append("" + NewLineChar);

                ipxeMenu.Append(":console" + NewLineChar);
                ipxeMenu.Append("kernel " + Settings.WebPath + "IpxeBoot?filename=" + Kernel + "&type=kernel" +
                                " initrd=" + BootImage + " root=/dev/ram0 rw ramdisk_size=156000 " + " web=" +
                                Settings.WebPath + " USER_TOKEN=" + _userToken + " task=debug" + " consoleblank=0 " +
                                _globalComputerArgs + NewLineChar);
                ipxeMenu.Append("imgfetch --name " + BootImage + " " + Settings.WebPath + "IpxeBoot?filename=" +
                                BootImage + "&type=bootimage" + NewLineChar);
                ipxeMenu.Append("boot" + NewLineChar);
                ipxeMenu.Append("" + NewLineChar);

                ipxeMenu.Append(":register" + NewLineChar);
                ipxeMenu.Append("kernel " + Settings.WebPath + "IpxeBoot?filename=" + Kernel + "&type=kernel" +
                                " initrd=" + BootImage + " root=/dev/ram0 rw ramdisk_size=156000 " + " web=" +
                                Settings.WebPath + " USER_TOKEN=" + _userToken + " task=register" + " consoleblank=0 " +
                                _globalComputerArgs + NewLineChar);
                ipxeMenu.Append("imgfetch --name " + BootImage + " " + Settings.WebPath + "IpxeBoot?filename=" +
                                BootImage + "&type=bootimage" + NewLineChar);
                ipxeMenu.Append("boot" + NewLineChar);
                ipxeMenu.Append("" + NewLineChar);

                ipxeMenu.Append(":ond" + NewLineChar);
                ipxeMenu.Append("kernel " + Settings.WebPath + "IpxeBoot?filename=" + Kernel + "&type=kernel" +
                                " initrd=" + BootImage + " root=/dev/ram0 rw ramdisk_size=156000 " + " web=" +
                                Settings.WebPath + " USER_TOKEN=" + _userToken + " task=ond" + " consoleblank=0 " +
                                _globalComputerArgs + NewLineChar);
                ipxeMenu.Append("imgfetch --name " + BootImage + " " + Settings.WebPath + "IpxeBoot?filename=" +
                                BootImage + "&type=bootimage" + NewLineChar);
                ipxeMenu.Append("boot" + NewLineChar);
                ipxeMenu.Append("" + NewLineChar);

                ipxeMenu.Append(":diag" + NewLineChar);
                ipxeMenu.Append("kernel " + Settings.WebPath + "IpxeBoot?filename=" + Kernel + "&type=kernel" +
                                " initrd=" + BootImage + " root=/dev/ram0 rw ramdisk_size=156000 " + " web=" +
                                Settings.WebPath + " USER_TOKEN=" + _userToken + " task=diag" + " consoleblank=0 " +
                                _globalComputerArgs + NewLineChar);
                ipxeMenu.Append("imgfetch --name " + BootImage + " " + Settings.WebPath + "IpxeBoot?filename=" +
                                BootImage + "&type=bootimage" + NewLineChar);
                ipxeMenu.Append("boot" + NewLineChar);
                ipxeMenu.Append("" + NewLineChar);

            }

            //Set Custom Menu Entries
            foreach (var customEntry in customMenuEntries)
            {
                ipxeMenu.Append(":" + _alphaNumericNoSpace.Replace(customEntry.Name, "") + NewLineChar);
                ipxeMenu.Append(customEntry.Content + NewLineChar);
            }

            string path;
            if (Type == "standard")
                path = Settings.TftpPath + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default.ipxe";
            else
                path = Settings.TftpPath + "proxy" + Path.DirectorySeparatorChar + Type +
                       Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + "default.ipxe";

            new FileOps().WritePath(path, ipxeMenu.ToString());
        }