Exemplo n.º 1
0
    protected void specs_page()
    {
        Utility utility = new Utility();

        try
        {
            Image_Physical_Specs ips = new Image_Physical_Specs();
            if (!string.IsNullOrEmpty(image.ClientSizeCustom))
                ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSizeCustom);
            else
                ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);

            List<HD_Physical_Specs> specslist = new List<HD_Physical_Specs>();

            foreach (var hd in ips.hd)
            {
                long logical_block_size = Convert.ToInt64(hd.lbs);
                hd.size = (Convert.ToInt64(hd.size) * logical_block_size / 1000f / 1000f / 1000f).ToString("#.##") + " GB" + " / " + (Convert.ToInt64(hd.size) * logical_block_size / 1024f / 1024f / 1024f).ToString("#.##") + " GB";
                specslist.Add(hd);
            }

            gvHDs.DataSource = specslist;
            gvHDs.DataBind();

            foreach (GridViewRow row in gvHDs.Rows)
            {
                string isActive = ((HiddenField)row.FindControl("HiddenActive")).Value;
                if (isActive == "1")
                {
                    CheckBox box = row.FindControl("chkHDActive") as CheckBox;
                    box.Checked = true;
                }
            }

        }
        catch
        {
            lblSpecsUnavailable.Text = "Image Specifications Will Be Available After The Image Is Uploaded";
            lblSpecsUnavailable.Visible = true;
        }

        if(utility.GetSettings("Image Checksum") == "On" && lblSpecsUnavailable.Visible != true)
        {
            try
            {
                List<HD_Checksum> listPhysicalImageChecksums = new List<HD_Checksum>();
                string path = utility.GetSettings("Image Store Path") + image.Name;
                HD_Checksum imageChecksum = new HD_Checksum();
                imageChecksum.hdNumber = "hd1";
                imageChecksum.path = path;
                listPhysicalImageChecksums.Add(imageChecksum);
                for (int x = 2; true; x++)
                {
                    imageChecksum = new HD_Checksum();
                    string subdir = path + Path.DirectorySeparatorChar + "hd" + x;
                    if (Directory.Exists(subdir))
                    {
                        imageChecksum.hdNumber = "hd" + x;
                        imageChecksum.path = subdir;
                        listPhysicalImageChecksums.Add(imageChecksum);
                    }
                    else
                        break;
                }

                foreach (HD_Checksum hd in listPhysicalImageChecksums)
                {
                    List<File_Checksum> listChecksums = new List<File_Checksum>();

                    var files = Directory.GetFiles(hd.path, "*.*");
                    foreach (var file in files)
                    {
                        File_Checksum fc = new File_Checksum();
                        fc.fileName = Path.GetFileName(file);
                        fc.checksum = image.Calculate_Hash(file);
                        listChecksums.Add(fc);

                    }
                    hd.path = string.Empty;
                    hd.fc = listChecksums.ToArray();
                }

                string physicalImageJson = JsonConvert.SerializeObject(listPhysicalImageChecksums);
                if (physicalImageJson != image.Checksum)
                {

                    incorrectChecksum.Visible = true;
                    ViewState["checkSum"] = physicalImageJson;
                }
            }
            catch(Exception ex)
            {
                Logger.Log(ex.Message + " This can be safely ignored if the image has not been uploaded yet");
                incorrectChecksum.Visible = false;
            }
        }
    }
Exemplo n.º 2
0
    protected void btnUpdateImageSpecs_Click(object sender, EventArgs e)
    {
        Image_Physical_Specs ips = new Image_Physical_Specs();

        try
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSize);
        }
        catch
        { return; }

        int rowCounter = 0;

        foreach (GridViewRow row in gvHDs.Rows)
        {
            CheckBox box = row.FindControl("chkHDActive") as CheckBox;
            if (box.Checked)
            {
                ips.hd[rowCounter].active = "1";
            }
            else
            {
                ips.hd[rowCounter].active = "0";
            }

            GridView gvParts = (GridView)row.FindControl("gvParts");

            int partCounter = 0;
            foreach (GridViewRow partRow in gvParts.Rows)
            {
                CheckBox boxPart = partRow.FindControl("chkPartActive") as CheckBox;
                if (boxPart.Checked)
                {
                    ips.hd[rowCounter].partition[partCounter].active = "1";
                }
                else
                {
                    ips.hd[rowCounter].partition[partCounter].active = "0";
                }

                TextBox txtCustomSize = partRow.FindControl("txtCustomSize") as TextBox;
                if (!string.IsNullOrEmpty(txtCustomSize.Text))
                {
                    string customSize_BLK = (Convert.ToInt64(txtCustomSize.Text) * 1024 * 1024 / Convert.ToInt32(ips.hd[rowCounter].lbs)).ToString();
                    ips.hd[rowCounter].partition[partCounter].size_override = customSize_BLK;
                }


                GridView gvVG = (GridView)partRow.FindControl("gvVG");
                foreach (GridViewRow vg in gvVG.Rows)
                {
                    GridView gvLVS     = (GridView)vg.FindControl("gvLVS");
                    int      lvCounter = 0;
                    foreach (GridViewRow LV in gvLVS.Rows)
                    {
                        CheckBox boxLv = LV.FindControl("chkPartActive") as CheckBox;
                        if (boxLv.Checked)
                        {
                            ips.hd[rowCounter].partition[partCounter].vg.lv[lvCounter].active = "1";
                        }
                        else
                        {
                            ips.hd[rowCounter].partition[partCounter].vg.lv[lvCounter].active = "0";
                        }

                        TextBox txtCustomSizeLv = LV.FindControl("txtCustomSize") as TextBox;
                        if (!string.IsNullOrEmpty(txtCustomSizeLv.Text))
                        {
                            string customSize_BLK = (Convert.ToInt64(txtCustomSizeLv.Text) * 1024 * 1024 / Convert.ToInt32(ips.hd[rowCounter].lbs)).ToString();
                            ips.hd[rowCounter].partition[partCounter].vg.lv[lvCounter].size_override = customSize_BLK;
                        }
                        lvCounter++;
                    }
                }
                partCounter++;
            }
            rowCounter++;
        }

        if (image.UpdateSpecs(image.Name, JsonConvert.SerializeObject(ips)))
        {
            Master.Msgbox("Successfully Updated Image Specs");
        }
        else
        {
            Master.Msgbox("Could Not Update Image Specs");
        }
    }
Exemplo n.º 3
0
    protected void btnUpdateImageSpecs_Click(object sender, EventArgs e)
    {
        Image_Physical_Specs ips = new Image_Physical_Specs();
        try
        {
            ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);
        }
        catch
        { return; }

        int rowCounter = 0;
        foreach (GridViewRow row in gvHDs.Rows)
        {
            CheckBox box = row.FindControl("chkHDActive") as CheckBox;
            if (box.Checked)
                ips.hd[rowCounter].active = "1";
            else
                ips.hd[rowCounter].active = "0";

            GridView gvParts = (GridView)row.FindControl("gvParts");

            int partCounter = 0;
            foreach (GridViewRow partRow in gvParts.Rows)
            {
                CheckBox boxPart = partRow.FindControl("chkPartActive") as CheckBox;
                if (boxPart.Checked)
                    ips.hd[rowCounter].partition[partCounter].active = "1";
                else
                    ips.hd[rowCounter].partition[partCounter].active = "0";

                TextBox txtCustomSize = partRow.FindControl("txtCustomSize") as TextBox;
                if (!string.IsNullOrEmpty(txtCustomSize.Text))
                {
                    string customSize_BLK = (Convert.ToInt64(txtCustomSize.Text) * 1024 * 1024 / Convert.ToInt32(ips.hd[rowCounter].lbs)).ToString();
                    ips.hd[rowCounter].partition[partCounter].size_override = customSize_BLK;
                }

                GridView gvVG = (GridView)partRow.FindControl("gvVG");
                foreach(GridViewRow vg in gvVG.Rows)
                {
                    GridView gvLVS = (GridView)vg.FindControl("gvLVS");
                    int lvCounter = 0;
                    foreach (GridViewRow LV in gvLVS.Rows)
                    {
                        CheckBox boxLv = LV.FindControl("chkPartActive") as CheckBox;
                        if (boxLv.Checked)
                            ips.hd[rowCounter].partition[partCounter].vg.lv[lvCounter].active = "1";
                        else
                            ips.hd[rowCounter].partition[partCounter].vg.lv[lvCounter].active = "0";

                        TextBox txtCustomSizeLv = LV.FindControl("txtCustomSize") as TextBox;
                        if (!string.IsNullOrEmpty(txtCustomSizeLv.Text))
                        {
                            string customSize_BLK = (Convert.ToInt64(txtCustomSizeLv.Text) * 1024 * 1024 / Convert.ToInt32(ips.hd[rowCounter].lbs)).ToString();
                            ips.hd[rowCounter].partition[partCounter].vg.lv[lvCounter].size_override = customSize_BLK;
                        }
                        lvCounter++;
                    }
                }
                partCounter++;
            }
            rowCounter++;
        }

        if (image.UpdateSpecs(image.Name, JsonConvert.SerializeObject(ips)))
            Master.Msgbox("Successfully Updated Image Specs");
        else
            Master.Msgbox("Could Not Update Image Specs");
    }
Exemplo n.º 4
0
    protected void btnVG_Click(object sender, EventArgs e)
    {
        GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
        GridView gv = (GridView)gvRow.FindControl("gvLVS");

        string selectedHD = (string)(ViewState["selectedHD"]);

        Image_Physical_Specs ips = new Image_Physical_Specs();
        if (!string.IsNullOrEmpty(image.ClientSizeCustom))
            ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSizeCustom);
        else
            ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);

        List<LV_Physical_Specs> lvList = new List<LV_Physical_Specs>();

        foreach(var partition in ips.hd[Convert.ToInt32(selectedHD)].partition)
        {
            if (partition.vg.lv != null)
            {
                if (partition.vg.name != null)
                {
                    foreach (var lv in partition.vg.lv)
                    {
                        if (gvRow.Cells[1].Text == lv.vg)
                        {
                            long logical_block_size = Convert.ToInt64(ips.hd[Convert.ToInt32(selectedHD)].lbs);
                            if ((Convert.ToInt64(lv.size) * logical_block_size) < 1048576000)
                                lv.size = (Convert.ToInt64(lv.size) * logical_block_size / 1024f / 1024f).ToString("#.##") + " MB";
                            else
                                lv.size = (Convert.ToInt64(lv.size) * logical_block_size / 1024f / 1024f / 1024f).ToString("#.##") + " GB";
                            lv.used_mb = lv.used_mb + " MB";
                            if (!string.IsNullOrEmpty(lv.size_override))
                                lv.size_override = (Convert.ToInt64(lv.size_override) * logical_block_size / 1024f / 1024f).ToString();
                            if (!string.IsNullOrEmpty(lv.resize))
                                lv.resize = lv.resize + " MB";

                            lvList.Add(lv);
                        }
                    }
                }
            }

        }

        LinkButton btn = (LinkButton)gvRow.FindControl("vgClick");
        if (gv.Visible == false)
        {
            gv.Visible = true;

            var td = gvRow.FindControl("tdLVS");
            td.Visible = true;
            gv.DataSource = lvList;
            gv.DataBind();
            btn.Text = "-";
        }

        else
        {
            gv.Visible = false;
            var td = gvRow.FindControl("tdLVS");
            td.Visible = false;
            btn.Text = "+";
        }

        foreach (GridViewRow row in gv.Rows)
        {

            string isActive = ((HiddenField)row.FindControl("HiddenActivePart")).Value;
            if (isActive == "1")
            {
                CheckBox box = row.FindControl("chkPartActive") as CheckBox;
                box.Checked = true;
            }
        }
    }
Exemplo n.º 5
0
    protected void btnHds_Click(object sender, EventArgs e)
    {
        Utility     utility = new Utility();
        GridViewRow row     = (GridViewRow)(sender as Control).Parent.Parent;
        Image       image   = new Image();

        image.ID = image.GetImageID(row.Cells[4].Text);
        image.Read(image);

        GridView gvHDs = (GridView)row.FindControl("gvHDs");
        List <HD_Physical_Specs> specslist = new List <HD_Physical_Specs>();
        Image_Physical_Specs     ips       = new Image_Physical_Specs();

        try
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSize);
        }
        catch
        { return; }
        if (ips == null)
        {
            return;
        }
        foreach (var hd in ips.hd)
        {
            specslist.Add(hd);
        }


        LinkButton btn = (LinkButton)row.FindControl("btnHDs");

        if (gvHDs.Visible == false)
        {
            var td = row.FindControl("tdHds");
            td.Visible    = true;
            gvHDs.Visible = true;

            gvHDs.DataSource = specslist;
            gvHDs.DataBind();
            btn.Text = "-";
        }
        else
        {
            var td = row.FindControl("tdHds");
            td.Visible    = false;
            gvHDs.Visible = false;

            btn.Text = "+";
        }

        foreach (GridViewRow hdrow in gvHDs.Rows)
        {
            string imagePath = null;

            try
            {
                Label lbl = hdrow.FindControl("lblHDSize") as Label;
                try
                {
                    if (hdrow.RowIndex.ToString() == "0")
                    {
                        imagePath = utility.GetSettings("Image Store Path") + row.Cells[4].Text;
                    }
                    else
                    {
                        string selectedHD = (hdrow.RowIndex + 1).ToString();
                        imagePath = utility.GetSettings("Image Store Path") + row.Cells[4].Text + Path.DirectorySeparatorChar + "hd" + selectedHD;
                    }
                }
                catch
                {
                    return;
                }


                float size = GetDirectorySize(new DirectoryInfo(imagePath)) / 1024f / 1024f / 1024f;
                if (size == 0.0f)
                {
                    lbl.Text = "N/A";
                }
                else
                {
                    lbl.Text = size.ToString("#.##") + " GB";
                    if (lbl.Text == " GB")
                    {
                        lbl.Text = "< .01 GB";
                    }
                }
            }
            catch
            {
                Label lbl = hdrow.FindControl("lblHDSize") as Label;
                lbl.Text        = "N/A";
                Utility.Message = "";
            }

            try
            {
                Label lblClient = hdrow.FindControl("lblHDSizeClient") as Label;


                float fltClientSize = image.CalculateMinSizeHD(image.Name, hdrow.RowIndex, "1") / 1024f / 1024f / 1024f;

                if (fltClientSize == 0.0f)
                {
                    lblClient.Text = "N/A";
                }
                else
                {
                    lblClient.Text = fltClientSize.ToString("#.##") + " GB";
                    if (lblClient.Text == " GB")
                    {
                        lblClient.Text = "< .01 GB";
                    }
                }
            }
            catch (Exception)
            {
                Label lblClient = hdrow.FindControl("lblHDSizeClient") as Label;
                lblClient.Text  = "N/A";
                Utility.Message = "";
            }
        }
    }
Exemplo n.º 6
0
    protected void btnParts_Click(object sender, EventArgs e)
    {
        GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
        GridView gv = (GridView)gvRow.FindControl("gvParts");

        string selectedHD = gvRow.Cells[3].Text;
        ViewState["selectedHD"] = gvRow.RowIndex.ToString();
        ViewState["selectedHDName"] = selectedHD;
        Image_Physical_Specs ips = new Image_Physical_Specs();
        if (!string.IsNullOrEmpty(image.ClientSizeCustom))
            ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSizeCustom);
        else
            ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);

        List<Partition_Physical_Specs> specslist = new List<Partition_Physical_Specs>();
        List<VG_Physical_Specs> vgList = new List<VG_Physical_Specs>();
        foreach (var hd in ips.hd)
        {
            if (hd.name == selectedHD)
            {
                foreach (var part in hd.partition)
                {
                    long logical_block_size = Convert.ToInt64(hd.lbs);
                    if ((Convert.ToInt64(part.size) * logical_block_size) < 1048576000)
                        part.size = (Convert.ToInt64(part.size) * logical_block_size / 1024f / 1024f ).ToString("#.##") + " MB";
                    else
                        part.size = (Convert.ToInt64(part.size) * logical_block_size / 1024f / 1024f / 1024f).ToString("#.##") + " GB";
                    part.used_mb = part.used_mb + " MB";
                    if (!string.IsNullOrEmpty(part.size_override))
                        part.size_override = (Convert.ToInt64(part.size_override) * logical_block_size / 1024f / 1024f).ToString();
                    if(!string.IsNullOrEmpty(part.resize))
                        part.resize = part.resize + " MB";
                    specslist.Add(part);

                    if(part.vg != null)
                        if(part.vg.name != null)

                        vgList.Add(part.vg);

                }
            }
        }

        LinkButton btn = (LinkButton)gvRow.FindControl("btnParts");
        if (gv.Visible == false)
        {
            gv.Visible = true;

            var td = gvRow.FindControl("tdParts");
            td.Visible = true;
            gv.DataSource = specslist;
            gv.DataBind();

            btn.Text = "-";
        }
        else
        {
            gv.Visible = false;

            var td = gvRow.FindControl("tdParts");
            td.Visible = false;
            btn.Text = "+";
        }

        foreach (GridViewRow row in gv.Rows)
        {
            GridView gvVG = (GridView)row.FindControl("gvVG");
            foreach(var vg in vgList)
            {
                if(vg.pv == selectedHD + row.Cells[3].Text)
                {
                    List<VG_Physical_Specs> vgListBind = new List<VG_Physical_Specs>();
                    vgListBind.Add(vg);
                    gvVG.DataSource = vgListBind;
                    gvVG.DataBind();
                    gvVG.Visible = true;
                    var td = row.FindControl("tdVG");
                    td.Visible = true;
                }

            }
            string isActive = ((HiddenField)row.FindControl("HiddenActivePart")).Value;
            if (isActive == "1")
            {
                CheckBox box = row.FindControl("chkPartActive") as CheckBox;
                box.Checked = true;
            }
        }
    }
Exemplo n.º 7
0
    public ExtendedPartition CalculateMinSizeExtended(string imgName, int hdNumberToGet)
    {
        Image image = new Image();

        image.ID = image.GetImageID(imgName);
        image.Read(image);
        Image_Physical_Specs ips = new Image_Physical_Specs();

        if (!string.IsNullOrEmpty(image.ClientSizeCustom))
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSizeCustom);
        }
        else
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSize);
        }

        int lbs_BYTE         = Convert.ToInt32(ips.hd[hdNumberToGet].lbs);
        ExtendedPartition EP = new ExtendedPartition();

        EP.minSize_BLK = 0;
        EP.isOnlySwap  = false;

        bool hasExtendedPartition = false;
        bool hasLogicalPartition  = false;

        //Determine if any Extended or Logical Partitions are present.  Needed ahead of time correctly calculate sizes.
        //And calculate minimum needed extended partition size

        string logicalFSType = null;

        foreach (var part in ips.hd[hdNumberToGet].partition)
        {
            if (part.active != "1")
            {
                continue;
            }
            if (part.type.ToLower() == "extended")
            {
                hasExtendedPartition = true;
            }
            if (part.type.ToLower() == "logical")
            {
                EP.logicalCount++;
                logicalFSType       = part.fstype;
                hasLogicalPartition = true;
                EP.hasLogical       = true;
            }
        }

        if (EP.logicalCount == 1 && logicalFSType.ToLower() == "swap")
        {
            EP.isOnlySwap = true;
        }

        if (hasExtendedPartition)
        {
            foreach (var partition in ips.hd[hdNumberToGet].partition)
            {
                if (partition.active != "1")
                {
                    continue;
                }
                if (hasExtendedPartition && hasLogicalPartition)
                {
                    if (partition.type.ToLower() == "logical")
                    {
                        if (partition.fsid.ToLower() == "8e")
                        {
                            List <VolumeGroup> listVGS = image.CalculateMinSizeVG(imgName, hdNumberToGet);
                            foreach (var VG in listVGS)
                            {
                                if (VG.pv == ips.hd[hdNumberToGet].name + partition.number)
                                {
                                    EP.minSize_BLK = VG.minSize_BLK;
                                }
                            }
                            if (EP.minSize_BLK == 0)
                            {
                                EP.minSize_BLK = Convert.ToInt64(partition.size);
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(partition.size_override))
                            {
                                EP.minSize_BLK += Convert.ToInt64(partition.size_override);
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(partition.resize))
                                {
                                    EP.minSize_BLK += Convert.ToInt64(partition.size);
                                }
                                else
                                {
                                    if (Convert.ToInt64(partition.resize) > Convert.ToInt64(partition.used_mb))
                                    {
                                        EP.minSize_BLK += (Convert.ToInt64(partition.resize) * 1024 * 1024) / lbs_BYTE;
                                    }
                                    else
                                    {
                                        EP.minSize_BLK += (Convert.ToInt64(partition.used_mb) * 1024 * 1024) / lbs_BYTE;
                                    }
                                }
                            }
                        }
                    }
                }
                //If Hd has extended but no logical, use the extended to calc size
                else if (hasExtendedPartition && !hasLogicalPartition)
                {
                    //In this case someone has defined an extended partition but has not created any logical
                    //This could just be for preperation of leaving room for more logical partition later
                    //This should be highly unlikely but should account for it anyway.  There is no way of knowing a minimum size required
                    //while still having the partition be resizable.  So will set minimum sized required to unless user overrides
                    if (partition.type.ToLower() == "extended")
                    {
                        if (!string.IsNullOrEmpty(partition.size_override))
                        {
                            EP.minSize_BLK = Convert.ToInt64(partition.size_override);
                        }
                        else
                        {
                            //set arbitary minimum to 100MB
                            EP.minSize_BLK = (Convert.ToInt64("100") * 1024 * 1024) / lbs_BYTE;
                        }
                    }
                }
            }
        }
        //Logical paritions default to 1MB more than the previous block using fdisk. This needs to be added to extended size so logical parts will fit inside
        long epPadding = (((1048576 / lbs_BYTE) * EP.logicalCount) + (1048576 / lbs_BYTE));

        EP.minSize_BLK += epPadding;
        return(EP);
    }
Exemplo n.º 8
0
    protected void btnVG_Click(object sender, EventArgs e)
    {
        GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
        GridView    gv    = (GridView)gvRow.FindControl("gvLVS");

        string selectedHD = (string)(ViewState["selectedHD"]);

        Image_Physical_Specs ips = new Image_Physical_Specs();

        if (!string.IsNullOrEmpty(image.ClientSizeCustom))
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSizeCustom);
        }
        else
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSize);
        }


        List <LV_Physical_Specs> lvList = new List <LV_Physical_Specs>();

        foreach (var partition in ips.hd[Convert.ToInt32(selectedHD)].partition)
        {
            if (partition.vg.lv != null)
            {
                if (partition.vg.name != null)
                {
                    foreach (var lv in partition.vg.lv)
                    {
                        if (gvRow.Cells[1].Text == lv.vg)
                        {
                            long logical_block_size = Convert.ToInt64(ips.hd[Convert.ToInt32(selectedHD)].lbs);
                            if ((Convert.ToInt64(lv.size) * logical_block_size) < 1048576000)
                            {
                                lv.size = (Convert.ToInt64(lv.size) * logical_block_size / 1024f / 1024f).ToString("#.##") + " MB";
                            }
                            else
                            {
                                lv.size = (Convert.ToInt64(lv.size) * logical_block_size / 1024f / 1024f / 1024f).ToString("#.##") + " GB";
                            }
                            lv.used_mb = lv.used_mb + " MB";
                            if (!string.IsNullOrEmpty(lv.size_override))
                            {
                                lv.size_override = (Convert.ToInt64(lv.size_override) * logical_block_size / 1024f / 1024f).ToString();
                            }
                            if (!string.IsNullOrEmpty(lv.resize))
                            {
                                lv.resize = lv.resize + " MB";
                            }


                            lvList.Add(lv);
                        }
                    }
                }
            }
        }

        LinkButton btn = (LinkButton)gvRow.FindControl("vgClick");

        if (gv.Visible == false)
        {
            gv.Visible = true;

            var td = gvRow.FindControl("tdLVS");
            td.Visible    = true;
            gv.DataSource = lvList;
            gv.DataBind();
            btn.Text = "-";
        }

        else
        {
            gv.Visible = false;
            var td = gvRow.FindControl("tdLVS");
            td.Visible = false;
            btn.Text   = "+";
        }

        foreach (GridViewRow row in gv.Rows)
        {
            string isActive = ((HiddenField)row.FindControl("HiddenActivePart")).Value;
            if (isActive == "1")
            {
                CheckBox box = row.FindControl("chkPartActive") as CheckBox;
                box.Checked = true;
            }
        }
    }
Exemplo n.º 9
0
        public void getOriginalLVM(string imgName, string hdToGet, string clienthd)
        {
            Image image = new Image();
            image.ID = image.GetImageID(imgName);
            image.Read(image);
            Image_Physical_Specs ips = new Image_Physical_Specs();
            if (!string.IsNullOrEmpty(image.ClientSizeCustom))
                ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSizeCustom);
            else
                ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);
            int hdNumberToGet = Convert.ToInt32(hdToGet) - 1;

            foreach (var part in ips.hd[hdNumberToGet].partition)
            {
                if (part.active != "1")
                    continue;
                if (part.vg != null)
                {
                    if (part.vg.lv != null)
                    {
                        HttpContext.Current.Response.Write("pvcreate -u " + part.uuid + " --norestorefile -yf " + clienthd+part.vg.pv[part.vg.pv.Length - 1] + "\r\n");
                        HttpContext.Current.Response.Write("vgcreate " + part.vg.name + " " + clienthd + part.vg.pv[part.vg.pv.Length - 1] + " -yf" + "\r\n");
                        HttpContext.Current.Response.Write("echo \"" + part.vg.uuid + "\" >>/tmp/vg-" +part.vg.name + "\r\n");
                        foreach (var lv in part.vg.lv)
                        {
                            if (lv.active == "1")
                            {
                                HttpContext.Current.Response.Write("lvcreate -L " + lv.size + "s -n " + lv.name + " " + lv.vg + "\r\n");
                                HttpContext.Current.Response.Write("echo \"" + lv.uuid + "\" >>/tmp/" + lv.vg + "-" + lv.name + "\r\n");
                            }
                        }
                        HttpContext.Current.Response.Write("vgcfgbackup -f /tmp/lvm-" + part.vg.name + "\r\n");

                    }
                }
            }
        }
Exemplo n.º 10
0
        public void getPartLayout(string imgName, string hdToGet, string newHDSize, string clientHD, string taskType)
        {
            Image image = new Image();
            image.ID = image.GetImageID(imgName);
            image.Read(image);
            Image_Physical_Specs ips = new Image_Physical_Specs();
            if (!string.IsNullOrEmpty(image.ClientSizeCustom))
                ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSizeCustom);
            else
                ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);

            int activeCounter = Convert.ToInt32(hdToGet);
            int hdNumberToGet = Convert.ToInt32(hdToGet) - 1;
            //Look for first active hd
            if (ips.hd[hdNumberToGet].active != "1")
            {
                while (activeCounter <= ips.hd.Count())
                {
                    if (ips.hd[activeCounter - 1].active == "1")
                    {
                        hdNumberToGet = activeCounter - 1;
                    }
                    activeCounter++;
                }
            }

            newHDSize = (Convert.ToInt64(newHDSize) * .99).ToString("#");

            int lbs_BYTE = Convert.ToInt32(ips.hd[hdNumberToGet].lbs);
            long newHD_BYTES = Convert.ToInt64(newHDSize);
            long newHD_BLK = Convert.ToInt64(newHDSize) / lbs_BYTE;

            List<Partition_Resized_Client> listPhysicalAndExtended = new List<Partition_Resized_Client>();
            List<Partition_Resized_Client> listLogical = new List<Partition_Resized_Client>();
            List<Partition_Resized_Client_LVM> listLVM = new List<Partition_Resized_Client_LVM>();

            string bootPart = null;
            if(ips.hd[hdNumberToGet].boot.Length > 0)
                bootPart = ips.hd[hdNumberToGet].boot.Substring(ips.hd[hdNumberToGet].boot.Length - 1, 1);

            ExtendedPartition EP = image.CalculateMinSizeExtended(imgName,hdNumberToGet);
            List<VolumeGroup> listVGS = new List<VolumeGroup>();

            long agreedExtendedSize_BLK = 0;
            double percentCounter = 0;
            bool partLayoutVerified = false;
            bool hasResizableVG = false;
            int startPart = 0;
            while (!partLayoutVerified)
            {
                double totalPercentage = 0;
                listPhysicalAndExtended.Clear();
                listLogical.Clear();
                listVGS.Clear();
                startPart = Convert.ToInt32(ips.hd[hdNumberToGet].partition[0].start);
                int partCounter = 0;
                hasResizableVG = false;
                foreach (var part in ips.hd[hdNumberToGet].partition)
                {
                    if (Convert.ToInt32(part.start) < startPart)
                        startPart = Convert.ToInt32(part.start);
                    if (part.active != "1")
                        continue;
                    if (part.type.ToLower() == "logical")
                        continue;

                    VolumeGroup VG = image.SinglePartMinSizeVG(imgName, hdNumberToGet, partCounter);
                    if (VG.pv != null)
                    {
                        part.resize = (VG.minSize_BLK * lbs_BYTE / 1024 / 1024).ToString();
                        hasResizableVG = true;
                    }

                    Partition_Resized_Client resizedPart = new Partition_Resized_Client();
                    if (bootPart == part.number)
                        resizedPart.isBoot = true;
                    else
                        resizedPart.isBoot = false;

                    resizedPart.number = part.number;
                    resizedPart.start = part.start;
                    resizedPart.type = part.type;
                    resizedPart.fsid = part.fsid;
                    resizedPart.uuid = part.uuid;
                    resizedPart.guid = part.guid;
                    resizedPart.fstype = part.fstype;

                    //If not resizable set aside a minimum size based off original partition length
                    long newPartSize_BLK = 0;
                    double tmpTotalPercentage = 0;

                    if (!string.IsNullOrEmpty(part.size_override))
                    {
                        newPartSize_BLK = Convert.ToInt64(part.size_override);
                        resizedPart.size = newPartSize_BLK.ToString();
                        tmpTotalPercentage = (double)newPartSize_BLK / newHD_BLK;
                        resizedPart.partResized = false;
                        if (resizedPart.type.ToLower() == "extended")
                        {
                            resizedPart.size = EP.minSize_BLK.ToString();
                            agreedExtendedSize_BLK = EP.minSize_BLK;
                        }

                    }

                    else if ((string.IsNullOrEmpty(part.resize) && part.type.ToLower() != "extended") || (part.type.ToLower() == "extended" && EP.isOnlySwap) || Convert.ToInt64(part.size) * lbs_BYTE <= 2097152000)
                    {
                        newPartSize_BLK = Convert.ToInt64(part.size);
                        resizedPart.size = newPartSize_BLK.ToString();
                        tmpTotalPercentage = (double)newPartSize_BLK / newHD_BLK;
                        resizedPart.partResized = false;
                        if (resizedPart.type.ToLower() == "extended")
                        {
                            resizedPart.size = EP.minSize_BLK.ToString();
                            agreedExtendedSize_BLK = EP.minSize_BLK;
                        }

                    }
                    //If resizable determine what percent of drive partition was originally and match that to the new drive
                    //while making sure the min size is still greater than the resized size.
                    else
                    {
                        resizedPart.partResized = true;
                        if (part.type.ToLower() == "extended")
                            newPartSize_BLK = EP.minSize_BLK;
                        else
                        {
                            if (VG.pv != null)
                            {
                                newPartSize_BLK = (Convert.ToInt64(part.resize) * 1024 * 1024) / lbs_BYTE;
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(part.used_mb))
                                    part.used_mb = "0";
                                if (Convert.ToInt64(part.resize) > Convert.ToInt64(part.used_mb))
                                    newPartSize_BLK = (Convert.ToInt64(part.resize) * 1024 * 1024) / lbs_BYTE;
                                else
                                    newPartSize_BLK = (Convert.ToInt64(part.used_mb) * 1024 * 1024) / lbs_BYTE;
                            }
                        }

                        double percentOfOrigDrive = (double)(Convert.ToInt64(part.size) / (double)(Convert.ToInt64(ips.hd[hdNumberToGet].size)));
                        if (percentOfOrigDrive - (percentCounter / 100) <= 0)
                            resizedPart.size = (newHD_BLK * (percentOfOrigDrive)).ToString("#");
                        else
                            resizedPart.size = (newHD_BLK * (percentOfOrigDrive - (percentCounter / 100))).ToString("#");

                        if (resizedPart.type.ToLower() == "extended")
                            tmpTotalPercentage = ((double)(Convert.ToInt64(resizedPart.size)) + (((1048576 / lbs_BYTE) * EP.logicalCount) + (1048576 / lbs_BYTE))) / newHD_BLK;
                        else
                            tmpTotalPercentage = (double)(Convert.ToInt64(resizedPart.size)) / newHD_BLK;

                        if (Convert.ToInt64(resizedPart.size) < newPartSize_BLK)
                        {
                            if (resizedPart.type.ToLower() == "extended")
                            {
                                resizedPart.size = (newPartSize_BLK + (((1048576 / lbs_BYTE) * EP.logicalCount) + (1048576 / lbs_BYTE))).ToString();
                                tmpTotalPercentage = (double)(Convert.ToInt64(resizedPart.size)) / newHD_BLK;
                            }
                            else
                            {
                                resizedPart.size = newPartSize_BLK.ToString();
                                tmpTotalPercentage = (double)(Convert.ToInt64(resizedPart.size)) / newHD_BLK;
                            }
                        }

                        if (resizedPart.type.ToLower() == "extended")
                            agreedExtendedSize_BLK = Convert.ToInt64(resizedPart.size);

                    }

                    if (hasResizableVG)
                    {
                        VG.agreedPVSize_BLK = Convert.ToInt64(resizedPart.size);
                        listVGS.Add(VG);
                    }

                    totalPercentage += tmpTotalPercentage;
                    listPhysicalAndExtended.Add(resizedPart);

                    partCounter++;
                }

                percentCounter++;
                if (totalPercentage <= 1)
                {
                    long totalAllocated_BLK = 0;
                    long totalUnallocated = 0;
                    int resizablePartsCount = 0;
                    //If totalPercentage is too far below 1 try to increase size of available resizable partitions
                    if (totalPercentage < .95)
                    {
                        foreach (var partition in listPhysicalAndExtended)
                        {
                            totalAllocated_BLK += Convert.ToInt64(partition.size);
                            if (partition.partResized)
                                resizablePartsCount++;
                        }
                        totalUnallocated = newHD_BLK - totalAllocated_BLK;
                        if (resizablePartsCount > 0)
                        {
                            foreach (var partition in listPhysicalAndExtended)
                            {
                                if (partition.partResized)
                                {
                                    partition.size = (Convert.ToInt64(partition.size) + (totalUnallocated / resizablePartsCount)).ToString();
                                    if (partition.type.ToLower() == "extended")
                                        agreedExtendedSize_BLK = Convert.ToInt64(partition.size);
                                    for (int i = 0; i < listVGS.Count(); i++)
                                        if (ips.hd[hdNumberToGet].name + partition.number == listVGS[i].pv)
                                            listVGS[i].agreedPVSize_BLK = Convert.ToInt64(partition.size);
                                }
                            }
                        }

                    }
                    partLayoutVerified = true;
                }

                //Theoretically should never hit this, but added to prevent infinite loop
                if (percentCounter == 99)
                {
                    HttpContext.Current.Response.Write("false");
                    Logger.Log("Error.  Could Not Determine A Partition Layout That Fits This HD");
                    return;

                }

            }

            //Try to resize lv to fit inside newly created lvm
            if (partLayoutVerified && hasResizableVG)
            {
                foreach (var volumeGroup in listVGS)
                {
                    volumeGroup.agreedPVSize_BLK = Convert.ToInt64(volumeGroup.agreedPVSize_BLK * .99);
                    foreach (var partition in ips.hd[hdNumberToGet].partition)
                    {
                        if (ips.hd[hdNumberToGet].name + partition.number == volumeGroup.pv)
                        {
                            bool singleLvVerified = false;

                            percentCounter = 0;

                            while (!singleLvVerified)
                            {
                                double totalPercentage = 0;
                                listLVM.Clear();
                                if (partition.active != "1")
                                    continue;

                                foreach (var lv in partition.vg.lv)
                                {
                                    if (lv.active != "1")
                                        continue;
                                    Partition_Resized_Client_LVM resizedLV = new Partition_Resized_Client_LVM();

                                    resizedLV.name = lv.name;
                                    resizedLV.vg = lv.vg;
                                    resizedLV.uuid = lv.uuid;
                                    resizedLV.fstype = lv.fstype;

                                    //If not resizable set aside a minimum size based off original partition length
                                    long newPartSize_BLK = 0;
                                    double tmpTotalPercentage = 0;

                                    if (!string.IsNullOrEmpty(lv.size_override))
                                    {
                                        newPartSize_BLK = Convert.ToInt64(lv.size_override);
                                        resizedLV.size = newPartSize_BLK.ToString();
                                        tmpTotalPercentage = (double)newPartSize_BLK / volumeGroup.agreedPVSize_BLK;
                                        resizedLV.partResized = false;
                                    }

                                    else if (string.IsNullOrEmpty(lv.resize))
                                    {
                                        newPartSize_BLK = (Convert.ToInt64(lv.size));
                                        resizedLV.size = newPartSize_BLK.ToString();
                                        tmpTotalPercentage = (double)newPartSize_BLK / volumeGroup.agreedPVSize_BLK;
                                        resizedLV.partResized = false;
                                    }
                                    //If resizable determine what percent of drive partition was originally and match that to the new drive
                                    //while making sure the min size is still greater than the resized size.
                                    else
                                    {
                                        resizedLV.partResized = true;

                                        if (Convert.ToInt64(lv.resize) > Convert.ToInt64(lv.used_mb))
                                            newPartSize_BLK = (Convert.ToInt64(lv.resize) * 1024 * 1024) / lbs_BYTE;
                                        else
                                            newPartSize_BLK = (Convert.ToInt64(lv.used_mb) * 1024 * 1024) / lbs_BYTE;

                                        double percentOfOrigDrive = (double)(Convert.ToInt64(lv.size) / (double)(Convert.ToInt64(ips.hd[hdNumberToGet].size)));
                                        if (percentOfOrigDrive - (percentCounter / 100) <= 0)
                                            resizedLV.size = (volumeGroup.agreedPVSize_BLK * (percentOfOrigDrive)).ToString("#");
                                        else
                                            resizedLV.size = (volumeGroup.agreedPVSize_BLK * (percentOfOrigDrive - (percentCounter / 100))).ToString("#");
                                        tmpTotalPercentage = (double)(Convert.ToInt64(resizedLV.size)) / volumeGroup.agreedPVSize_BLK;
                                        if (Convert.ToInt64(resizedLV.size) < newPartSize_BLK)
                                        {
                                            resizedLV.size = newPartSize_BLK.ToString();
                                            tmpTotalPercentage = (double)(Convert.ToInt64(resizedLV.size)) / volumeGroup.agreedPVSize_BLK;

                                        }

                                    }

                                    totalPercentage += tmpTotalPercentage;
                                    listLVM.Add(resizedLV);

                                }
                                percentCounter++;
                                if (totalPercentage <= 1)
                                {
                                    long totalAllocated_BLK = 0;
                                    long totalUnallocated = 0;
                                    int resizablePartsCount = 0;
                                    //If totalPercentage is too far below 1 try to increase size of available resizable partitions
                                    if (totalPercentage < .95)
                                    {
                                        foreach (var lv in listLVM)
                                        {
                                            totalAllocated_BLK += Convert.ToInt64(lv.size);
                                            if (lv.partResized)
                                                resizablePartsCount++;
                                        }
                                        totalUnallocated = volumeGroup.agreedPVSize_BLK - totalAllocated_BLK;
                                        if (resizablePartsCount > 0)
                                        {
                                            foreach (var lv in listLVM)
                                            {
                                                if (lv.partResized)
                                                    lv.size = (Convert.ToInt64(lv.size) + (totalUnallocated / resizablePartsCount)).ToString();
                                            }
                                        }

                                    }
                                    singleLvVerified = true;
                                }

                                //Theoretically should never hit this, but added to prevent infinite loop
                                if (percentCounter == 99)
                                {
                                    HttpContext.Current.Response.Write("Error");
                                    break;
                                }
                            }
                        }

                    }

                }
            }

            // Try to resize logical to fit inside newly created extended
            if (partLayoutVerified && EP.hasLogical)
            {
                percentCounter = 0;
                bool logicalPartLayoutVerified = false;

                while (!logicalPartLayoutVerified)
                {
                    listLogical.Clear();
                    double totalPercentage = 0;

                    foreach (var part in ips.hd[hdNumberToGet].partition)
                    {
                        if (part.type.ToLower() != "logical")
                            continue;
                        Partition_Resized_Client resizedPart = new Partition_Resized_Client();
                        if (bootPart == part.number)
                            resizedPart.isBoot = true;
                        else
                            resizedPart.isBoot = false;

                        resizedPart.number = part.number;
                        resizedPart.start = part.start;
                        resizedPart.type = part.type;
                        resizedPart.fsid = part.fsid;
                        resizedPart.uuid = part.uuid;
                        resizedPart.guid = part.guid;
                        resizedPart.fstype = part.fstype;

                        //If not resizable set aside a minimum size based off original partition length
                        long newPartSize_BLK = 0;
                        double tmpTotalPercentage = 0;

                        //If partition is logical and lvm
                        if (part.fsid.ToLower() == "8e")
                        {
                            //List<VolumeGroup> listVGS_lv = new List<VolumeGroup>();
                            listVGS = image.CalculateMinSizeVG(imgName, hdNumberToGet);
                            foreach (var VG in listVGS)
                            {
                                if (VG.pv == ips.hd[hdNumberToGet].name + part.number)
                                    newPartSize_BLK = VG.minSize_BLK;
                            }
                            if (newPartSize_BLK == 0)
                                newPartSize_BLK = Convert.ToInt64(part.size);
                            part.resize = ((newPartSize_BLK * lbs_BYTE) / 1024 / 1024).ToString();
                        }

                        if (!string.IsNullOrEmpty(part.size_override))
                        {
                            newPartSize_BLK = Convert.ToInt64(part.size_override);
                            resizedPart.size = newPartSize_BLK.ToString();
                            tmpTotalPercentage = (double)newPartSize_BLK / agreedExtendedSize_BLK;
                            resizedPart.partResized = false;
                        }

                        if (string.IsNullOrEmpty(part.resize))
                        {

                            newPartSize_BLK = (Convert.ToInt64(part.size));
                            resizedPart.size = newPartSize_BLK.ToString();
                            tmpTotalPercentage = (double)newPartSize_BLK / agreedExtendedSize_BLK;
                            resizedPart.partResized = false;

                        }
                        //If resizable determine what percent of drive partition was originally and match that to the new drive
                        //while making sure the min size is still greater than the resized size.
                        else
                        {
                            resizedPart.partResized = true;

                            if (part.fsid.ToLower() == "8e")
                            {
                                newPartSize_BLK = (Convert.ToInt64(part.resize) * 1024 * 1024) / lbs_BYTE;
                            }
                            else
                            {
                                if (Convert.ToInt64(part.resize) > Convert.ToInt64(part.used_mb))
                                    newPartSize_BLK = (Convert.ToInt64(part.resize) * 1024 * 1024) / lbs_BYTE;
                                else
                                    newPartSize_BLK = (Convert.ToInt64(part.used_mb) * 1024 * 1024) / lbs_BYTE;
                            }

                            if (taskType == "upload")
                                resizedPart.size = newPartSize_BLK.ToString();
                            else
                            {
                                double percentOfOrigDrive = (double)(Convert.ToInt64(part.size) / (double)(Convert.ToInt64(ips.hd[hdNumberToGet].size)));
                                if (percentOfOrigDrive - (percentCounter / 100) <= 0)
                                    resizedPart.size = (agreedExtendedSize_BLK * (percentOfOrigDrive)).ToString("#");
                                else
                                    resizedPart.size = (agreedExtendedSize_BLK * (percentOfOrigDrive - (percentCounter / 100))).ToString("#");
                                tmpTotalPercentage = (double)(Convert.ToInt64(resizedPart.size)) / agreedExtendedSize_BLK;
                                if (Convert.ToInt64(resizedPart.size) < newPartSize_BLK)
                                {
                                    resizedPart.size = newPartSize_BLK.ToString();
                                    tmpTotalPercentage = (double)(Convert.ToInt64(resizedPart.size)) / agreedExtendedSize_BLK;

                                }
                            }
                        }

                        totalPercentage += tmpTotalPercentage;
                        listLogical.Add(resizedPart);

                    }

                    percentCounter++;
                    if (totalPercentage <= 1)
                    {
                        long totalAllocated_BLK = 0;
                        long totalUnallocated = 0;
                        int resizablePartsCount = 0;
                        //If totalPercentage is too far below 1 try to increase size of available resizable partitions
                        if (totalPercentage < .95)
                        {
                            foreach (var partition in listLogical)
                            {
                                totalAllocated_BLK += Convert.ToInt64(partition.size);
                                if (partition.partResized)
                                    resizablePartsCount++;
                            }
                            totalUnallocated = agreedExtendedSize_BLK - totalAllocated_BLK;
                            if (resizablePartsCount > 0)
                            {
                                foreach (var partition in listLogical)
                                {
                                    if (partition.partResized)
                                        partition.size = (Convert.ToInt64(partition.size) + (totalUnallocated / resizablePartsCount)).ToString();
                                }
                            }

                        }
                        logicalPartLayoutVerified = true;

                        //testing if logical is also lvm
                        foreach (var part in listLogical)
                        {
                            if (part.fsid.ToLower() == "8e")
                            {
                                foreach (var VG in listVGS)
                                {
                                    if (VG.pv == ips.hd[hdNumberToGet].name + part.number)
                                    {
                                        VG.agreedPVSize_BLK = Convert.ToInt64(part.size);
                                    }
                                }

                                foreach (var volumeGroup in listVGS)
                                {
                                    volumeGroup.agreedPVSize_BLK = Convert.ToInt64(volumeGroup.agreedPVSize_BLK * .99);
                                    foreach (var partition in ips.hd[hdNumberToGet].partition)
                                    {
                                        if (ips.hd[hdNumberToGet].name + partition.number == volumeGroup.pv)
                                        {
                                            bool singleLvVerified = false;

                                            percentCounter = 0;

                                            while (!singleLvVerified)
                                            {
                                                totalPercentage = 0;
                                                listLVM.Clear();
                                                if (partition.active != "1")
                                                    continue;

                                                foreach (var lv in partition.vg.lv)
                                                {
                                                    if (lv.active != "1")
                                                        continue;
                                                    Partition_Resized_Client_LVM resizedLV = new Partition_Resized_Client_LVM();

                                                    resizedLV.name = lv.name;
                                                    resizedLV.vg = lv.vg;
                                                    resizedLV.uuid = lv.uuid;
                                                    resizedLV.fstype = lv.fstype;

                                                    //If not resizable set aside a minimum size based off original partition length
                                                    long newPartSize_BLK = 0;
                                                    double tmpTotalPercentage = 0;

                                                    if (!string.IsNullOrEmpty(lv.size_override))
                                                    {
                                                        newPartSize_BLK = Convert.ToInt64(lv.size_override);
                                                        resizedLV.size = newPartSize_BLK.ToString();
                                                        tmpTotalPercentage = (double)newPartSize_BLK / volumeGroup.agreedPVSize_BLK;
                                                        resizedLV.partResized = false;
                                                    }

                                                    else if (string.IsNullOrEmpty(lv.resize))
                                                    {
                                                        newPartSize_BLK = (Convert.ToInt64(lv.size));
                                                        resizedLV.size = newPartSize_BLK.ToString();
                                                        tmpTotalPercentage = (double)newPartSize_BLK / volumeGroup.agreedPVSize_BLK;
                                                        resizedLV.partResized = false;
                                                    }
                                                    //If resizable determine what percent of drive partition was originally and match that to the new drive
                                                    //while making sure the min size is still greater than the resized size.
                                                    else
                                                    {
                                                        resizedLV.partResized = true;

                                                        if (Convert.ToInt64(lv.resize) > Convert.ToInt64(lv.used_mb))
                                                            newPartSize_BLK = (Convert.ToInt64(lv.resize) * 1024 * 1024) / lbs_BYTE;
                                                        else
                                                            newPartSize_BLK = (Convert.ToInt64(lv.used_mb) * 1024 * 1024) / lbs_BYTE;

                                                        double percentOfOrigDrive = (double)(Convert.ToInt64(lv.size) / (double)(Convert.ToInt64(ips.hd[hdNumberToGet].size)));
                                                        if (percentOfOrigDrive - (percentCounter / 100) <= 0)
                                                            resizedLV.size = (volumeGroup.agreedPVSize_BLK * (percentOfOrigDrive)).ToString("#");
                                                        else
                                                            resizedLV.size = (volumeGroup.agreedPVSize_BLK * (percentOfOrigDrive - (percentCounter / 100))).ToString("#");
                                                        tmpTotalPercentage = (double)(Convert.ToInt64(resizedLV.size)) / volumeGroup.agreedPVSize_BLK;
                                                        if (Convert.ToInt64(resizedLV.size) < newPartSize_BLK)
                                                        {
                                                            resizedLV.size = newPartSize_BLK.ToString();
                                                            tmpTotalPercentage = (double)(Convert.ToInt64(resizedLV.size)) / volumeGroup.agreedPVSize_BLK;

                                                        }

                                                    }

                                                    totalPercentage += tmpTotalPercentage;
                                                    listLVM.Add(resizedLV);

                                                }
                                                percentCounter++;
                                                if (totalPercentage <= 1)
                                                {
                                                    totalAllocated_BLK = 0;
                                                    totalUnallocated = 0;
                                                    resizablePartsCount = 0;
                                                    //If totalPercentage is too far below 1 try to increase size of available resizable partitions
                                                    if (totalPercentage < .95)
                                                    {
                                                        foreach (var lv in listLVM)
                                                        {
                                                            totalAllocated_BLK += Convert.ToInt64(lv.size);
                                                            if (lv.partResized)
                                                                resizablePartsCount++;
                                                        }
                                                        totalUnallocated = volumeGroup.agreedPVSize_BLK - totalAllocated_BLK;
                                                        if (resizablePartsCount > 0)
                                                        {
                                                            foreach (var lv in listLVM)
                                                            {
                                                                if (lv.partResized)
                                                                    lv.size = (Convert.ToInt64(lv.size) + (totalUnallocated / resizablePartsCount)).ToString();
                                                            }
                                                        }

                                                    }
                                                    singleLvVerified = true;
                                                }

                                                //Theoretically should never hit this, but added to prevent infinite loop
                                                if (percentCounter == 99)
                                                {
                                                    HttpContext.Current.Response.Write("Error");
                                                    break;
                                                }
                                            }
                                        }

                                    }

                                }
                            }
                        }
                    }

                    //Theoretically should never hit this, but added to prevent infinite loop
                    if (percentCounter == 99)
                    {
                        HttpContext.Current.Response.Write("Error");
                        break;
                    }
                }
            }

            //Order partitions based of block start
            listPhysicalAndExtended = listPhysicalAndExtended.OrderBy(Part => Part.start, new Image.CustomComparer()).ToList();
            listLogical = listLogical.OrderBy(Part => Part.start, new Image.CustomComparer()).ToList();

            if(taskType == "debug")
            {
                try
                {
                    agreedExtendedSize_BLK = agreedExtendedSize_BLK * 512 / 1024 / 1024;
                }
                catch { }
                foreach(var p in listPhysicalAndExtended)
                    p.size = (Convert.ToInt64(p.size) * 512 / 1024 /1024).ToString();
                foreach (var p in listLogical)
                    p.size = (Convert.ToInt64(p.size) * 512 / 1024 / 1024).ToString();
                foreach (var p in listLVM)
                    p.size = (Convert.ToInt64(p.size) * 512 / 1024 / 1024).ToString();

            }

            //Create Menu
            if (ips.hd[hdNumberToGet].table.ToLower() == "mbr")
            {
                int counter = 0;
                int partCount = listPhysicalAndExtended.Count;

                string partitionCommands = null;
                if(Convert.ToInt32(listPhysicalAndExtended[0].start) < 2048)
                    partitionCommands = "fdisk -c=dos " + clientHD + " &>>/tmp/clientlog.log <<FDISK\r\n";
                else
                    partitionCommands = "fdisk " + clientHD + " &>>/tmp/clientlog.log <<FDISK\r\n";

                foreach (var part in listPhysicalAndExtended)
                {
                    counter++;
                    partitionCommands += "n\r\n";
                    if (part.type == "primary")
                        partitionCommands += "p\r\n";
                    else if (part.type == "extended")
                    {
                        partitionCommands += "e\r\n";
                    }
                    partitionCommands += part.number + "\r\n";
                    if (counter == 1 || taskType == "upload")
                        partitionCommands += startPart.ToString() + "\r\n";
                    else
                        partitionCommands += "\r\n";
                    if(part.type == "extended")
                         partitionCommands += "+" + (Convert.ToInt64(agreedExtendedSize_BLK) - 1).ToString() + "\r\n";
                    else //FDISK seems to include the starting sector in size so we need to subtract 1
                        partitionCommands += "+" + (Convert.ToInt64(part.size) -1).ToString() + "\r\n";

                    partitionCommands += "t\r\n";
                    if (counter == 1)
                        partitionCommands += part.fsid + "\r\n";
                    else
                    {
                        partitionCommands += part.number + "\r\n";
                        partitionCommands += part.fsid + "\r\n";
                    }
                    if (counter == 1 && part.isBoot)
                        partitionCommands += "a\r\n";
                    if (counter != 1 && part.isBoot)
                    {
                        partitionCommands += "a\r\n";
                        partitionCommands += part.number + "\r\n";
                    }
                    if ((counter == partCount && listLogical.Count == 0))
                    {
                        partitionCommands += "w\r\n";
                        partitionCommands += "FDISK\r\n";
                    }

                }

                int logicalCounter = 0;
                foreach (var logicalPart in listLogical)
                {
                    logicalCounter++;
                    partitionCommands += "n\r\n";

                    if (listPhysicalAndExtended.Count < 4)
                        partitionCommands += "l\r\n";

                    partitionCommands += "\r\n";

                    if (taskType == "debug")
                        partitionCommands += "+" + (Convert.ToInt64(logicalPart.size) - (logicalCounter * 1)).ToString() + "\r\n";
                    else
                        partitionCommands += "+" + (Convert.ToInt64(logicalPart.size) - (logicalCounter * 2049)).ToString() + "\r\n";

                    partitionCommands += "t\r\n";

                    partitionCommands += logicalPart.number + "\r\n";
                    partitionCommands += logicalPart.fsid + "\r\n";

                    if (logicalPart.isBoot)
                    {
                        partitionCommands += "a\r\n";
                        partitionCommands += logicalPart.number + "\r\n";
                    }
                    if (logicalCounter == listLogical.Count)
                    {
                        partitionCommands += "w\r\n";
                        partitionCommands += "FDISK\r\n";
                    }
                }
                HttpContext.Current.Response.Write(partitionCommands);
            }
            else
            {
                int counter = 0;
                int partCount = listPhysicalAndExtended.Count;

                string partitionCommands = "gdisk " + clientHD + " &>>/tmp/clientlog.log <<GDISK\r\n";
                foreach (var part in listPhysicalAndExtended)
                {
                    counter++;

                    partitionCommands += "n\r\n";

                    partitionCommands += part.number + "\r\n";
                    if (counter == 1 || taskType == "upload")
                        partitionCommands += startPart.ToString() + "\r\n";
                    else
                        partitionCommands += "\r\n";
                    //GDISK seems to NOT include the starting sector in size so don't subtract 1 like in FDISK
                    partitionCommands += "+" + Convert.ToInt64(part.size).ToString() + "\r\n";

                    partitionCommands += part.fsid + "\r\n";

                    if ((counter == partCount))
                    {
                        partitionCommands += "w\r\n";
                        partitionCommands += "y\r\n";
                        partitionCommands += "GDISK\r\n";
                    }

                }
                HttpContext.Current.Response.Write(partitionCommands);

            }

            foreach (var part in ips.hd[hdNumberToGet].partition)
            {
                if (part.active != "1")
                    continue;
                if (part.vg != null)
                {
                    if (part.vg.lv != null)
                    {
                         HttpContext.Current.Response.Write("echo \"pvcreate -u " + part.uuid + " --norestorefile -yf " + clientHD + part.vg.pv[part.vg.pv.Length - 1] + "\" >>/tmp/lvmcommands \r\n");
                         HttpContext.Current.Response.Write("echo \"vgcreate " + part.vg.name + " " + clientHD + part.vg.pv[part.vg.pv.Length - 1] + " -yf" + "\" >>/tmp/lvmcommands \r\n");
                        HttpContext.Current.Response.Write("echo \"" + part.vg.uuid + "\" >>/tmp/vg-" + part.vg.name + " \r\n");
                        foreach (var lv in part.vg.lv)
                        {
                            foreach(var rlv in listLVM)
                            {
                                if (lv.name == rlv.name && lv.vg == rlv.vg)
                                {
                                    HttpContext.Current.Response.Write("echo \"lvcreate -L " + ((Convert.ToInt64(rlv.size) - 8192).ToString()) + "s -n " + rlv.name + " " + rlv.vg + "\" >>/tmp/lvmcommands \r\n");
                                    HttpContext.Current.Response.Write("echo \"" + rlv.uuid + "\" >>/tmp/" + rlv.vg + "-" + rlv.name + "\r\n");
                                }
                            }
                        }
                        HttpContext.Current.Response.Write("echo \"vgcfgbackup -f /tmp/lvm-" + part.vg.name + "\" >>/tmp/lvmcommands\r\n");

                    }
                }
            }
        }
Exemplo n.º 11
0
        public void getMinHDSize(string imgName, string hdToGet, string newHDSize)
        {
            Image image = new Image();
            image.ID = image.GetImageID(imgName);
            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 { }
            }

            if(ips.hd == null)
            {
                HttpContext.Current.Response.Write("compatibility,0");
                return;
            }

            if (ips.hd.Count() < Convert.ToInt32(hdToGet))
            {
                HttpContext.Current.Response.Write("notexist,0");
                return;
            }

            int activeCounter = Convert.ToInt32(hdToGet);
            bool foundActive = false;
            int hdNumberToGet = Convert.ToInt32(hdToGet) - 1;

            //Look for first active hd
            if (ips.hd[hdNumberToGet].active == "1")
            {
                foundActive = true;
            }
            else
            {
                while(activeCounter <= ips.hd.Count())
                {
                    if(ips.hd[activeCounter -1 ].active == "1")
                    {
                        hdNumberToGet = activeCounter - 1;
                        foundActive = true;
                        break;
                    }
                    activeCounter++;
                }
            }

            if(!foundActive)
            {
                HttpContext.Current.Response.Write("notactive,0");
                return;
            }

            long minHDSizeRequired_BYTE = image.CalculateMinSizeHD(imgName, hdNumberToGet, newHDSize);
            long newHD_BYTES = Convert.ToInt64(newHDSize);

            if (minHDSizeRequired_BYTE > newHD_BYTES)
            {
                HttpContext.Current.Response.Write("false," + (hdNumberToGet + 1));
                Logger.Log("Error:  " + newHD_BYTES / 1024 / 1024 + " MB Is Less Than The Minimum Required HD Size For This Image(" + minHDSizeRequired_BYTE / 1024 / 1024 + " MB)");
            }
            else if(minHDSizeRequired_BYTE == newHD_BYTES)
            {
                HttpContext.Current.Response.Write("original,"+ (hdNumberToGet + 1));
            }
            else
                HttpContext.Current.Response.Write("true," + (hdNumberToGet + 1));
        }
Exemplo n.º 12
0
        public void getHDParameter(string imgName, string paramName, string hdToGet, string partNumber)
        {
            Image image = new Image();
            image.ID = image.GetImageID(imgName);
            image.Read(image);
            Image_Physical_Specs ips = new Image_Physical_Specs();
            if (!string.IsNullOrEmpty(image.ClientSizeCustom))
                ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSizeCustom);
            else
                ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);

            int activeCounter = Convert.ToInt32(hdToGet);
            int hdNumberToGet = Convert.ToInt32(hdToGet) - 1;

            //Look for first active hd
            if (ips.hd[hdNumberToGet].active != "1")
            {
                while (activeCounter <= ips.hd.Count())
                {
                    if (ips.hd[activeCounter - 1].active == "1")
                    {
                        hdNumberToGet = activeCounter - 1;
                    }
                    activeCounter++;
                }
            }

            if (paramName == "uuid")
            {
                foreach (var partition in ips.hd[hdNumberToGet].partition)
                    if (partition.number == partNumber)
                    {
                        HttpContext.Current.Response.Write(partition.uuid);
                        break;
                    }
            }
            else if (paramName == "lvmswap")
            {
                foreach (var partition in ips.hd[hdNumberToGet].partition)
                {
                    if (partition.vg != null)
                    {
                        if (partition.vg.lv != null)
                        {
                            foreach (var lv in partition.vg.lv)
                            {
                                if (lv.fstype.ToLower() == "swap"  && lv.active == "1")
                                {
                                    HttpContext.Current.Response.Write(lv.vg.Replace("-","--") + "-" + lv.name.Replace("-","--") + "," + lv.uuid);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else if (paramName == "guid")
            {
                foreach (var partition in ips.hd[hdNumberToGet].partition)
                    if (partition.number == partNumber)
                    {
                        HttpContext.Current.Response.Write(partition.guid);
                        break;
                    }
            }
            else if (paramName == "table")
            {
                HttpContext.Current.Response.Write(ips.hd[hdNumberToGet].table);
            }
            else if (paramName == "partCount")
            {
                int activePartsCounter = 0;
                foreach(var part in ips.hd[hdNumberToGet].partition)
                {
                    if (part.active == "1")
                        activePartsCounter++;
                }
                HttpContext.Current.Response.Write(activePartsCounter.ToString());
            }
            else if (paramName == "activeParts")
            {
                Utility settings = new Utility();
                string parts = null;
                string imageFiles = null;
                String[] partFiles = null;
                string compExt = null;
                foreach (var part in ips.hd[hdNumberToGet].partition)
                {
                    if (part.active == "1")
                    {
                        if (hdNumberToGet == 0)
                            imageFiles = settings.GetSettings("Image Store Path") + imgName;
                        else
                            imageFiles = settings.GetSettings("Image Store Path") + imgName + Path.DirectorySeparatorChar + "hd" + (hdNumberToGet + 1).ToString();

                        try
                        {
                            // modified by cocoon^M
                            foreach (var ext in ImageExtensions)
                            {
                                partFiles = Directory.GetFiles(imageFiles + Path.DirectorySeparatorChar, "*" + ext);
                                if (partFiles != null && partFiles.Length > 0)
                                {
                                    compExt = ext;
                                    break;
                                }
                            }
                            if (partFiles.Length == 0)
                            {
                                Logger.Log("Image Files Could Not Be Located");
                            }
                        }
                        catch
                        {
                            Logger.Log("Image Files Could Not Be Located");
                        }

                        // modified by cocoon^M
                        foreach (var pType in ImagePartTypes)
                        {
                            if (File.Exists(imageFiles + Path.DirectorySeparatorChar + "part" + part.number + pType + compExt))
                            {
                                parts += part.number + " ";
                                break;
                            }
                        }
                    }
                }
                HttpContext.Current.Response.Write(parts);
            }
            else if (paramName == "lvmactiveParts")
            {
                Utility settings = new Utility();
                string parts = null;
                string imageFiles = null;
                String[] partFiles = null;
                string compExt = null;
                foreach (var part in ips.hd[hdNumberToGet].partition)
                {
                    if (part.active != "1")
                        continue;
                    if (hdNumberToGet == 0)
                        imageFiles = settings.GetSettings("Image Store Path") + imgName;
                    else
                        imageFiles = settings.GetSettings("Image Store Path") + imgName + Path.DirectorySeparatorChar + "hd" + (hdNumberToGet + 1).ToString();

                    try
                    {
                            // modified by cocoon
                            foreach (var ext in ImageExtensions)
                            {
                                partFiles = Directory.GetFiles(imageFiles + Path.DirectorySeparatorChar, "*" + ext);
                                if (partFiles != null && partFiles.Length > 0)
                                {
                                    compExt = ext;
                                    break;
                                }
                            }
                            if (partFiles.Length == 0)
                            {
                                Logger.Log("Image Files Could Not Be Located");
                            }
                    }
                    catch
                    {
                        Logger.Log("Image Files Could Not Be Located");
                    }
                    if (part.vg != null)
                    {
                        if (part.vg.lv != null)
                        {
                            foreach (var lv in part.vg.lv)
                            {
                                if (lv.active == "1")
                                {

                                    // modified by cocoon
                                    foreach (var pType in ImagePartTypes)
                                    {
                                        if (File.Exists(imageFiles + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + pType + compExt))
                                        {
                                            parts += lv.vg + "-" + lv.name + " ";
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                HttpContext.Current.Response.Write(parts);
            }
            else if (paramName == "HDguid")
            {
                HttpContext.Current.Response.Write(ips.hd[hdNumberToGet].guid);
            }
            else if (paramName == "originalHDSize")
            {
                string originalSize = (Convert.ToInt64(ips.hd[hdNumberToGet].size) * Convert.ToInt32(ips.hd[hdNumberToGet].lbs)).ToString();
                HttpContext.Current.Response.Write(originalSize);
            }
            else if (paramName == "isKnownLayout")
            {
                if(ips.hd[hdNumberToGet].table == "mbr")
                {
                    if(ips.hd[hdNumberToGet].partition.Count() == 1)
                        if(ips.hd[hdNumberToGet].partition[0].start == "63")
                            HttpContext.Current.Response.Write("winxp");
                        else if (ips.hd[hdNumberToGet].partition[0].start == "2048")
                            HttpContext.Current.Response.Write("winvista");
                        else
                            HttpContext.Current.Response.Write("false");
                    else if(ips.hd[hdNumberToGet].partition.Count() == 2)
                    {
                        string part1Size = ((Convert.ToInt64(ips.hd[hdNumberToGet].partition[0].size) * Convert.ToInt32(ips.hd[hdNumberToGet].lbs) / 1024 /1024)).ToString();
                        if(ips.hd[hdNumberToGet].partition[0].start == "2048" && part1Size == "100")
                            HttpContext.Current.Response.Write("win7");
                        else if(ips.hd[hdNumberToGet].partition[0].start == "2048" && part1Size == "350")
                            HttpContext.Current.Response.Write("win8");
                        else
                            HttpContext.Current.Response.Write("false");
                    }
                    else
                        HttpContext.Current.Response.Write("false");
                }
                else if (ips.hd[hdNumberToGet].table == "gpt")
                {
                    if (ips.hd[hdNumberToGet].partition.Count() == 3)
                        if (ips.hd[hdNumberToGet].partition[0].start == "2048" && ips.hd[hdNumberToGet].partition[1].start == "206848" && ips.hd[hdNumberToGet].partition[2].start == "468992")
                            HttpContext.Current.Response.Write("win7gpt");
                        else
                            HttpContext.Current.Response.Write("false");
                    else if (ips.hd[hdNumberToGet].partition.Count() == 4)
                    {
                        if (ips.hd[hdNumberToGet].partition[0].start == "2048" && ips.hd[hdNumberToGet].partition[1].start == "616448" && ips.hd[hdNumberToGet].partition[2].start == "821248" && ips.hd[hdNumberToGet].partition[3].start == "1083392")
                            HttpContext.Current.Response.Write("win8gpt");
                        else if (ips.hd[hdNumberToGet].partition[0].start == "2048" && ips.hd[hdNumberToGet].partition[1].start == "616448" && ips.hd[hdNumberToGet].partition[2].start == "819200" && ips.hd[hdNumberToGet].partition[3].start == "1081344")
                            HttpContext.Current.Response.Write("win8gpt");
                        else
                            HttpContext.Current.Response.Write("false");
                    }
                    else
                        HttpContext.Current.Response.Write("false");
                }
                else
                    HttpContext.Current.Response.Write("Error: Could Not Determine Partition Table Type");
            }
        }
Exemplo n.º 13
0
        public void imagesize()
        {
            Utility utility = new Utility();
             HttpContext postedContext = HttpContext.Current;
             HttpFileCollection Files = postedContext.Request.Files;
             string imagename = utility.Decode((string)postedContext.Request.Form["imgName"]);
             string imagesize = utility.Decode((string)postedContext.Request.Form["imageSize"]);
            try
            {
                using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString))
                {
                    NpgsqlCommand cmd = new NpgsqlCommand("images_updatesize", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new NpgsqlParameter("@imagename", imagename));
                    cmd.Parameters.Add(new NpgsqlParameter("@imagesize", imagesize));
                    conn.Open();
                    cmd.ExecuteNonQuery();

                }

            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
                HttpContext.Current.Response.Write("false");
                return;
            }

            //Validate image specifications were recorded successfully
            Image image = new Image();
            image.ID = image.GetImageID(imagename);
            image.Read(image);
            Image_Physical_Specs existingips = new Image_Physical_Specs();
            try
            {
                existingips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);
            }
            catch(Exception ex)
            {
                Logger.Log(ex.ToString());
                HttpContext.Current.Response.Write("false");
                return;
            }
            if (existingips.hd == null)
            {
                HttpContext.Current.Response.Write("false");
                return;
            }
            //Reset Custom Specs
            image.UpdateSpecs(image.Name, "");
            HttpContext.Current.Response.Write("true");
        }
Exemplo n.º 14
0
    protected void specs_page()
    {
        Utility utility = new Utility();

        try
        {
            Image_Physical_Specs ips = new Image_Physical_Specs();
            if (!string.IsNullOrEmpty(image.ClientSizeCustom))
            {
                ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSizeCustom);
            }
            else
            {
                ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSize);
            }


            List <HD_Physical_Specs> specslist = new List <HD_Physical_Specs>();

            foreach (var hd in ips.hd)
            {
                long logical_block_size = Convert.ToInt64(hd.lbs);
                hd.size = (Convert.ToInt64(hd.size) * logical_block_size / 1000f / 1000f / 1000f).ToString("#.##") + " GB" + " / " + (Convert.ToInt64(hd.size) * logical_block_size / 1024f / 1024f / 1024f).ToString("#.##") + " GB";
                specslist.Add(hd);
            }

            gvHDs.DataSource = specslist;
            gvHDs.DataBind();

            foreach (GridViewRow row in gvHDs.Rows)
            {
                string isActive = ((HiddenField)row.FindControl("HiddenActive")).Value;
                if (isActive == "1")
                {
                    CheckBox box = row.FindControl("chkHDActive") as CheckBox;
                    box.Checked = true;
                }
            }
        }
        catch
        {
            lblSpecsUnavailable.Text    = "Image Specifications Will Be Available After The Image Is Uploaded";
            lblSpecsUnavailable.Visible = true;
        }

        if (utility.GetSettings("Image Checksum") == "On" && lblSpecsUnavailable.Visible != true)
        {
            try
            {
                List <HD_Checksum> listPhysicalImageChecksums = new List <HD_Checksum>();
                string             path          = utility.GetSettings("Image Store Path") + image.Name;
                HD_Checksum        imageChecksum = new HD_Checksum();
                imageChecksum.hdNumber = "hd1";
                imageChecksum.path     = path;
                listPhysicalImageChecksums.Add(imageChecksum);
                for (int x = 2; true; x++)
                {
                    imageChecksum = new HD_Checksum();
                    string subdir = path + Path.DirectorySeparatorChar + "hd" + x;
                    if (Directory.Exists(subdir))
                    {
                        imageChecksum.hdNumber = "hd" + x;
                        imageChecksum.path     = subdir;
                        listPhysicalImageChecksums.Add(imageChecksum);
                    }
                    else
                    {
                        break;
                    }
                }

                foreach (HD_Checksum hd in listPhysicalImageChecksums)
                {
                    List <File_Checksum> listChecksums = new List <File_Checksum>();

                    var files = Directory.GetFiles(hd.path, "*.*");
                    foreach (var file in files)
                    {
                        File_Checksum fc = new File_Checksum();
                        fc.fileName = Path.GetFileName(file);
                        fc.checksum = image.Calculate_Hash(file);
                        listChecksums.Add(fc);
                    }
                    hd.path = string.Empty;
                    hd.fc   = listChecksums.ToArray();
                }


                string physicalImageJson = JsonConvert.SerializeObject(listPhysicalImageChecksums);
                if (physicalImageJson != image.Checksum)
                {
                    incorrectChecksum.Visible = true;
                    ViewState["checkSum"]     = physicalImageJson;
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message + " This can be safely ignored if the image has not been uploaded yet");
                incorrectChecksum.Visible = false;
            }
        }
    }
Exemplo n.º 15
0
    public long CalculateMinSizeHD(string imgName, int hdNumberToGet, string newHDSize)
    {
        Image image = new Image();

        image.ID = image.GetImageID(imgName);
        image.Read(image);

        Image_Physical_Specs ips = new Image_Physical_Specs();

        if (!string.IsNullOrEmpty(image.ClientSizeCustom))
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSizeCustom);
        }
        else
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSize);
        }
        ExtendedPartition  EP      = image.CalculateMinSizeExtended(imgName, hdNumberToGet);
        List <VolumeGroup> listVGS = image.CalculateMinSizeVG(imgName, hdNumberToGet);

        long minHDSizeRequired_BLK = 0;
        int  lbs_BYTE = Convert.ToInt32(ips.hd[hdNumberToGet].lbs);

        if (Convert.ToInt64(ips.hd[hdNumberToGet].size) * lbs_BYTE == Convert.ToInt64(newHDSize))
        {
            return(Convert.ToInt64(newHDSize));
        }
        foreach (var part in ips.hd[hdNumberToGet].partition)
        {
            if (part.active != "1")
            {
                continue;
            }
            long minPartSize_BLK = 0;

            if (!string.IsNullOrEmpty(part.size_override))
            {
                minPartSize_BLK = Convert.ToInt64(part.size_override);
            }
            else if (part.fsid.ToLower() == "8e" || part.fsid.ToLower() == "8e00")
            {
                foreach (var VG in listVGS)
                {
                    if (VG.pv == ips.hd[hdNumberToGet].name + part.number)
                    {
                        minPartSize_BLK = VG.minSize_BLK;
                    }
                }
                if (minPartSize_BLK == 0)
                {
                    minPartSize_BLK = Convert.ToInt64(part.size);
                }
            }
            else if ((string.IsNullOrEmpty(part.resize) && part.type.ToLower() != "extended") || (part.type.ToLower() == "extended" && EP.isOnlySwap))
            {
                minPartSize_BLK = Convert.ToInt64(part.size);
            }
            else
            {
                if (part.type.ToLower() == "extended")
                {
                    minPartSize_BLK = EP.minSize_BLK;
                }

                else
                {
                    if (string.IsNullOrEmpty(part.used_mb))
                    {
                        part.used_mb = "0";
                    }
                    if (Convert.ToInt64(part.resize) > Convert.ToInt64(part.used_mb))
                    {
                        minPartSize_BLK = (Convert.ToInt64(part.resize) * 1024 * 1024) / lbs_BYTE;
                    }
                    else
                    {
                        minPartSize_BLK = (Convert.ToInt64(part.used_mb) * 1024 * 1024) / lbs_BYTE;
                    }
                }
            }

            if (part.type.ToLower() != "logical")
            {
                minHDSizeRequired_BLK += minPartSize_BLK;
            }
        }
        return(minHDSizeRequired_BLK * lbs_BYTE);
    }
Exemplo n.º 16
0
    protected void btnParts_Click(object sender, EventArgs e)
    {
        GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
        GridView    gv    = (GridView)gvRow.FindControl("gvParts");

        string selectedHD = gvRow.Cells[3].Text;

        ViewState["selectedHD"]     = gvRow.RowIndex.ToString();
        ViewState["selectedHDName"] = selectedHD;
        Image_Physical_Specs ips = new Image_Physical_Specs();

        if (!string.IsNullOrEmpty(image.ClientSizeCustom))
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSizeCustom);
        }
        else
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSize);
        }

        List <Partition_Physical_Specs> specslist = new List <Partition_Physical_Specs>();
        List <VG_Physical_Specs>        vgList    = new List <VG_Physical_Specs>();

        foreach (var hd in ips.hd)
        {
            if (hd.name == selectedHD)
            {
                foreach (var part in hd.partition)
                {
                    long logical_block_size = Convert.ToInt64(hd.lbs);
                    if ((Convert.ToInt64(part.size) * logical_block_size) < 1048576000)
                    {
                        part.size = (Convert.ToInt64(part.size) * logical_block_size / 1024f / 1024f).ToString("#.##") + " MB";
                    }
                    else
                    {
                        part.size = (Convert.ToInt64(part.size) * logical_block_size / 1024f / 1024f / 1024f).ToString("#.##") + " GB";
                    }
                    part.used_mb = part.used_mb + " MB";
                    if (!string.IsNullOrEmpty(part.size_override))
                    {
                        part.size_override = (Convert.ToInt64(part.size_override) * logical_block_size / 1024f / 1024f).ToString();
                    }
                    if (!string.IsNullOrEmpty(part.resize))
                    {
                        part.resize = part.resize + " MB";
                    }
                    specslist.Add(part);

                    if (part.vg != null)
                    {
                        if (part.vg.name != null)
                        {
                            vgList.Add(part.vg);
                        }
                    }
                }
            }
        }



        LinkButton btn = (LinkButton)gvRow.FindControl("btnParts");

        if (gv.Visible == false)
        {
            gv.Visible = true;

            var td = gvRow.FindControl("tdParts");
            td.Visible    = true;
            gv.DataSource = specslist;
            gv.DataBind();

            btn.Text = "-";
        }
        else
        {
            gv.Visible = false;

            var td = gvRow.FindControl("tdParts");
            td.Visible = false;
            btn.Text   = "+";
        }

        foreach (GridViewRow row in gv.Rows)
        {
            GridView gvVG = (GridView)row.FindControl("gvVG");
            foreach (var vg in vgList)
            {
                if (vg.pv == selectedHD + row.Cells[3].Text)
                {
                    List <VG_Physical_Specs> vgListBind = new List <VG_Physical_Specs>();
                    vgListBind.Add(vg);
                    gvVG.DataSource = vgListBind;
                    gvVG.DataBind();
                    gvVG.Visible = true;
                    var td = row.FindControl("tdVG");
                    td.Visible = true;
                }
            }
            string isActive = ((HiddenField)row.FindControl("HiddenActivePart")).Value;
            if (isActive == "1")
            {
                CheckBox box = row.FindControl("chkPartActive") as CheckBox;
                box.Checked = true;
            }
        }
    }
Exemplo n.º 17
0
    public VolumeGroup SinglePartMinSizeVG(string imgName, int hdNumberToGet, int partToGet)
    {
        Image image = new Image();

        image.ID = image.GetImageID(imgName);
        image.Read(image);
        Image_Physical_Specs ips = new Image_Physical_Specs();

        if (!string.IsNullOrEmpty(image.ClientSizeCustom))
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSizeCustom);
        }
        else
        {
            ips = JsonConvert.DeserializeObject <Image_Physical_Specs>(image.ClientSize);
        }

        int lbs_BYTE = Convert.ToInt32(ips.hd[hdNumberToGet].lbs);

        //Determine if any Volume Groups Are present.  Needed ahead of time correctly calculate sizes.
        //And calculate minimum needed lvm partition size

        VolumeGroup VG = new VolumeGroup();

        VG.minSize_BLK = 0;
        VG.hasLv       = false;

        if (ips.hd[hdNumberToGet].partition[partToGet].fsid.ToLower() == "8e" || ips.hd[hdNumberToGet].partition[partToGet].fsid.ToLower() == "8e00")
        {
            if (ips.hd[hdNumberToGet].partition[partToGet].active != "1")
            {
                return(VG);
            }

            //if part.vg is null, most likely version 2.3.0 beta1 before lvm was added.
            if (ips.hd[hdNumberToGet].partition[partToGet].vg != null)
            {
                //if vg.name is null partition was uploaded at physical partion level, not using the resize flag
                if (ips.hd[hdNumberToGet].partition[partToGet].vg.name != null)
                {
                    VG.name = ips.hd[hdNumberToGet].partition[partToGet].vg.name;
                    foreach (var lv in ips.hd[hdNumberToGet].partition[partToGet].vg.lv)
                    {
                        if (lv.active != "1")
                        {
                            continue;
                        }
                        VG.hasLv = true;
                        VG.pv    = ips.hd[hdNumberToGet].partition[partToGet].vg.pv;
                        if (!string.IsNullOrEmpty(lv.size_override))
                        {
                            VG.minSize_BLK += Convert.ToInt64(lv.size_override);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(lv.resize))
                            {
                                VG.minSize_BLK += Convert.ToInt64(lv.size);
                            }
                            else
                            {
                                if (Convert.ToInt64(lv.resize) > Convert.ToInt64(lv.used_mb))
                                {
                                    VG.minSize_BLK += (Convert.ToInt64(lv.resize) * 1024 * 1024) / lbs_BYTE;
                                }
                                else
                                {
                                    VG.minSize_BLK += (Convert.ToInt64(lv.used_mb) * 1024 * 1024) / lbs_BYTE;
                                }
                            }
                        }
                    }
                    //Could Have VG Without LVs
                    //Set arbitary minimum size to 100mb
                    if (!VG.hasLv)
                    {
                        VG.pv          = ips.hd[hdNumberToGet].partition[partToGet].vg.pv;
                        VG.minSize_BLK = (Convert.ToInt64("100") * 1024 * 1024) / lbs_BYTE;
                    }
                }
            }
        }
        return(VG);
    }
Exemplo n.º 18
0
    protected void btnHds_Click(object sender, EventArgs e)
    {
        Utility utility = new Utility();
        GridViewRow row = (GridViewRow)(sender as Control).Parent.Parent;
        Image image = new Image();
        image.ID = image.GetImageID(row.Cells[4].Text);
        image.Read(image);

        GridView gvHDs = (GridView)row.FindControl("gvHDs");
        List<HD_Physical_Specs> specslist = new List<HD_Physical_Specs>();
        Image_Physical_Specs ips = new Image_Physical_Specs();
        try
        {
            ips = JsonConvert.DeserializeObject<Image_Physical_Specs>(image.ClientSize);
        }
        catch
        { return; }
           if(ips == null)
            return;
        foreach (var hd in ips.hd)
        {
            specslist.Add(hd);
        }

        LinkButton btn = (LinkButton)row.FindControl("btnHDs");
        if (gvHDs.Visible == false)
        {
            var td = row.FindControl("tdHds");
            td.Visible = true;
            gvHDs.Visible = true;

            gvHDs.DataSource = specslist;
            gvHDs.DataBind();
            btn.Text = "-";
        }
        else
        {
            var td = row.FindControl("tdHds");
            td.Visible = false;
            gvHDs.Visible = false;

            btn.Text = "+";
        }

        foreach (GridViewRow hdrow in gvHDs.Rows)
        {
            string imagePath = null;

            try
            {
                Label lbl = hdrow.FindControl("lblHDSize") as Label;
                try
                {
                    if (hdrow.RowIndex.ToString() == "0")
                    {
                        imagePath = utility.GetSettings("Image Store Path") + row.Cells[4].Text;

                    }
                    else
                    {
                        string selectedHD = (hdrow.RowIndex + 1).ToString();
                        imagePath = utility.GetSettings("Image Store Path") + row.Cells[4].Text + Path.DirectorySeparatorChar + "hd" + selectedHD;

                    }
                }
                catch
                {
                    return;
                }

                float size = GetDirectorySize(new DirectoryInfo(imagePath)) / 1024f / 1024f / 1024f;
                if (size == 0.0f)
                    lbl.Text = "N/A";
                else
                {
                    lbl.Text = size.ToString("#.##") + " GB";
                    if (lbl.Text == " GB")
                        lbl.Text = "< .01 GB";
                }
            }
            catch
            {
                Label lbl = hdrow.FindControl("lblHDSize") as Label;
                lbl.Text = "N/A";
                Utility.Message = "";
            }

            try
            {

                Label lblClient = hdrow.FindControl("lblHDSizeClient") as Label;

                float fltClientSize = image.CalculateMinSizeHD(image.Name, hdrow.RowIndex, "1") / 1024f / 1024f / 1024f;

                if (fltClientSize == 0.0f)
                    lblClient.Text = "N/A";
                else
                {
                    lblClient.Text = fltClientSize.ToString("#.##") + " GB";
                    if (lblClient.Text == " GB")
                        lblClient.Text = "< .01 GB";
                }
            }
            catch (Exception)
            {
                Label lblClient = hdrow.FindControl("lblHDSizeClient") as Label;
                lblClient.Text = "N/A";
                Utility.Message = "";
            }
        }
    }
Exemplo n.º 19
0
    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
        {
            // modified by cocoon
            string[] ImageExtensions = new string[3] { ".gz", ".lz4", ".none" }; // modified by cocoon

            foreach (var ext in ImageExtensions)
            {
                partFiles = Directory.GetFiles(fullImagePath + Path.DirectorySeparatorChar, "*" + ext);
                if (partFiles != null && partFiles.Length > 0)
                {
                    compExt = ext;
                    if (compExt == ".lz4")
                    {
                        compAlg = Environment.OSVersion.ToString().Contains("Unix") ? "lz4 -d " : "lz4.exe -d ";
                        stdout = " - ";
                    }
                    else if (compExt == ".gz")
                    {
                        compAlg = Environment.OSVersion.ToString().Contains("Unix") ? "gzip -c -d " : "gzip.exe -c -d ";
                        stdout = "";
                    }
                    else
                    {
                        compAlg = Environment.OSVersion.ToString().Contains("Unix") ? "cat " : "type ";
            stdout = "";
                    }
                    break;
                }
            }
            if (partFiles.Length == 0)
            {
               	Utility.Message = "Image Files Could Not Be Located";
        return false;
            }
        }
        catch
        {
            Utility.Message = "Image Files Could Not Be Located";
            return false;
        }

        int x = 0;
        foreach (var part in ips.hd[activeCounter].partition)
        {
            udpFile = null;
            if (part.active == "1")
            {
                if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".ntfs" + compExt))
                    udpFile = fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".ntfs" + compExt;
                else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".fat" + compExt))
                    udpFile = fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".fat" + compExt;
                else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".extfs" + compExt))
                    udpFile = fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".extfs" + compExt;
                else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".hfsp" + compExt))
                    udpFile = fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".hfsp" + compExt;
                else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".imager" + compExt))
                    udpFile = fullImagePath + Path.DirectorySeparatorChar + "part" + part.number + ".imager" + compExt;
                else
                {
                    //Look for lvm
                    if (part.vg != null)
                    {
                        if (part.vg.lv != null)
                        {
                            foreach (var lv in part.vg.lv)
                            {
                                if (lv.active == "1")
                                {

                                    if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".ntfs" + compExt))
                                        udpFile = fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".ntfs" + compExt;
                                    else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".fat" + compExt))
                                        udpFile = fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".fat" + compExt;
                                    else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".extfs" + compExt))
                                        udpFile = fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".extfs" + compExt;
                                    else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".hfsp" + compExt))
                                        udpFile = fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".hfsp" + compExt;
                                    else if (File.Exists(fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".imager" + compExt))
                                        udpFile = fullImagePath + Path.DirectorySeparatorChar + lv.vg + "-" + lv.name + ".imager" + compExt;
                                }
                            }
                        }
                    }
                }

                if (udpFile == null)
                    continue;
                else
                    x++;

                if (Environment.OSVersion.ToString().Contains("Unix"))
                {
                    if (x == 1)
                        senderInfo.Arguments = (" -c \"" + compAlg + udpFile + stdout + " | udp-sender" +
                                           " --portbase " + portBase + " " + senderArgs + " --ttl 32");
                    else
                        senderInfo.Arguments += (" ; " + compAlg + udpFile + stdout + " | udp-sender" +
                                           " --portbase " + portBase + " " + senderArgs + " --ttl 32");
                }
                else
                {
                    if (x == 1)
                        senderInfo.Arguments = (" /c " + appPath + compAlg + udpFile + stdout + " | " + appPath + "udp-sender.exe" +
                                           " --portbase " + portBase + " " + senderArgs + " --ttl 32");
                    else
                        senderInfo.Arguments += (" & " + appPath + compAlg + udpFile + stdout + " | " + appPath + "udp-sender.exe" +
                                           " --portbase " + portBase + " " + senderArgs + " --ttl 32");
                }
            }
        }

        string log = ("\r\n" + DateTime.Now.ToString("MM.dd.yy hh:mm") + " Starting Multicast Session " + portBase +
                      " With The Following Command:\r\n\r\n" + senderInfo.FileName + senderInfo.Arguments + "\r\n\r\n");
        System.IO.File.AppendAllText(logPath + "multicast.log", log);

        if (Environment.OSVersion.ToString().Contains("Unix"))
        {
             senderInfo.Arguments += "\"";
        }

        try
        {
            multiSender = Process.Start(senderInfo);

        }
        catch (Exception ex)
        {
            Logger.Log(ex.ToString());
            Utility.Message = "Could Not Start Multicast Sender.  Check The Exception Log For More Info";
            System.IO.File.AppendAllText(logPath + "multicast.log", "Could Not Start Session " + portBase + " Try Pasting The Command Into A Command Prompt");
            return false;
        }

        Thread.Sleep(2000);

        if (multiSender.HasExited)
        {
            Utility.Message = "Could Not Start Multicast Sender";
            System.IO.File.AppendAllText(logPath + "multicast.log", "Session " + portBase + @" Started And Was Forced To Quit, Try Pasting The Command Into A Command Prompt");
            return false;
        }
        try
        {
            using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString))
            {
                NpgsqlCommand cmd = new NpgsqlCommand("multicast_createcustom", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new NpgsqlParameter("@mcTaskName", portBase.ToString()));
                cmd.Parameters.Add(new NpgsqlParameter("@mcPID", multiSender.Id));
                cmd.Parameters.Add(new NpgsqlParameter("@mcPortBase", portBase));
                cmd.Parameters.Add(new NpgsqlParameter("@mcImage", imageName));

                conn.Open();
                cmd.ExecuteNonQuery();
                Utility.Message = "Successfully Started Task " + portBase;
            }
        }
        catch (Exception ex)
        {
            Utility.Message = "Could Not Create Custom Multicast.  Check The Exception Log For More Info";
            Logger.Log(ex.ToString());
            return false;
        }
        return true;
    }