Пример #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;
            }
        }
    }
Пример #2
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;
            }
        }
    }
Пример #3
0
    public bool Check_Checksum(string imageID)
    {
        Utility utility = new Utility();

        if (utility.GetSettings("Image Checksum") == "On")
        {
            Image image = new Image();
            image.ID = imageID;
            image    = image.Read(image);

            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)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message);
                return(false);
            }
        }
        return(true);
    }