Ejemplo n.º 1
0
        public ClientPartitionHelper(Models.ImageProfile imageProfile)
        {
            string schema = null;
     
            if (imageProfile != null)
            {
                _imageProfile = imageProfile;
                if (imageProfile.PartitionMethod == "Dynamic" && !string.IsNullOrEmpty(imageProfile.CustomSchema))
                {
                    schema = imageProfile.CustomSchema;
                }
                else
                {
                    var path = Settings.PrimaryStoragePath + "images" + Path.DirectorySeparatorChar + imageProfile.Image.Name + Path.DirectorySeparatorChar +
                               "schema";
                    if (File.Exists(path))
                    {
                        using (var reader = new StreamReader(path))
                        {
                            schema = reader.ReadLine() ?? "";
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(schema))
            {
                _imageSchema = JsonConvert.DeserializeObject<Models.ImageSchema.ImageSchema>(schema);
            }
        }
Ejemplo n.º 2
0
        public ClientPartitionHelper(Models.ImageProfile imageProfile)
        {
            string schema = null;

            if (imageProfile != null)
            {
                _imageProfile = imageProfile;
                if ((imageProfile.PartitionMethod == "Dynamic" || imageProfile.PartitionMethod == "Standard" || imageProfile.PartitionMethod == "Standard Core Storage") && !string.IsNullOrEmpty(imageProfile.CustomSchema))
                {
                    schema = imageProfile.CustomSchema;
                }
                else
                {
                    var path = Settings.PrimaryStoragePath + "images" + Path.DirectorySeparatorChar + imageProfile.Image.Name + Path.DirectorySeparatorChar +
                               "schema";
                    if (File.Exists(path))
                    {
                        using (var reader = new StreamReader(path))
                        {
                            schema = reader.ReadLine() ?? "";
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(schema))
            {
                _imageSchema = JsonConvert.DeserializeObject <Models.ImageSchema.ImageSchema>(schema);
            }
        }
Ejemplo n.º 3
0
 protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);
     Image = !string.IsNullOrEmpty(Request["imageid"]) ? BLL.Image.GetImage(Convert.ToInt32(Request.QueryString["imageid"])) : null;
     ImageProfile = !string.IsNullOrEmpty(Request["profileid"]) ? BLL.ImageProfile.ReadProfile(Convert.ToInt32(Request.QueryString["profileid"])) : null;
     if (Image == null)
         RequiresAuthorization(Authorizations.SearchImage);
     else
         RequiresAuthorizationOrManagedImage(Authorizations.ReadImage, Image.Id);
 }
Ejemplo n.º 4
0
 public ClientPartition(int hdToGet, string newHdSize, Models.ImageProfile imageProfile, string partitionPrefix)
 {
     _hdToGet      = hdToGet;
     _newHdSize    = (long)(Convert.ToInt64(newHdSize) * .99);
     _imageProfile = imageProfile;
     PrimaryAndExtendedPartitions = new List <Models.ClientPartition>();
     LogicalPartitions            = new List <Models.ClientPartition>();
     LogicalVolumes     = new List <ClientLogicalVolume>();
     VolumeGroupHelpers = new List <ClientVolumeGroupHelper>();
     _imageSchema       = new ClientPartitionHelper(_imageProfile).GetImageSchema();
 }
Ejemplo n.º 5
0
        public List <Services.Client.PhysicalPartition> GetActivePartitions(int schemaHdNumber, Models.ImageProfile imageProfile)
        {
            var listPhysicalPartition = new List <Services.Client.PhysicalPartition>();
            var imagePath             = Settings.PrimaryStoragePath + Path.DirectorySeparatorChar + "images" + Path.DirectorySeparatorChar + imageProfile.Image.Name + Path.DirectorySeparatorChar + "hd" +
                                        schemaHdNumber;

            foreach (var partition in _imageSchema.HardDrives[schemaHdNumber].Partitions.Where(partition => partition.Active))
            {
                var physicalPartition = new Services.Client.PhysicalPartition();
                physicalPartition.Number        = partition.Number;
                physicalPartition.Guid          = partition.Guid;
                physicalPartition.Uuid          = partition.Uuid;
                physicalPartition.FileSystem    = partition.FsType;
                physicalPartition.Type          = partition.Type;
                physicalPartition.EfiBootLoader = partition.EfiBootLoader;
                string imageFile = null;
                foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "xfs" })
                {
                    try
                    {
                        imageFile =
                            Directory.GetFiles(
                                imagePath + Path.DirectorySeparatorChar, "part" + partition.Number + "." + ext + ".*")
                            .FirstOrDefault();
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(ex.Message);
                    }
                    if (imageFile != null)
                    {
                        physicalPartition.PartcloneFileSystem = ext;
                        break;
                    }
                }
                switch (Path.GetExtension(imageFile))
                {
                case ".lz4":
                    physicalPartition.Compression = "lz4";
                    physicalPartition.ImageType   = "Block";
                    break;

                case ".gz":
                    physicalPartition.Compression = "gz";
                    physicalPartition.ImageType   = "Block";
                    break;

                case ".uncp":
                    physicalPartition.Compression = "uncp";
                    physicalPartition.ImageType   = "Block";
                    break;

                case ".wim":
                    physicalPartition.ImageType = "File";
                    break;
                }

                if (partition.VolumeGroup.Name != null)
                {
                    physicalPartition.VolumeGroup      = new Services.Client.VolumeGroup();
                    physicalPartition.VolumeGroup.Name = partition.VolumeGroup.Name;
                    var listLogicalVolumes   = new List <Services.Client.LogicalVolume>();
                    var logicalVolumeCounter = 0;
                    foreach (var logicalVolume in partition.VolumeGroup.LogicalVolumes.Where(x => x.Active))
                    {
                        logicalVolumeCounter++;
                        var clientLogicalVolume = new Services.Client.LogicalVolume();
                        clientLogicalVolume.Name       = logicalVolume.Name;
                        clientLogicalVolume.FileSystem = logicalVolume.FsType;
                        clientLogicalVolume.Uuid       = logicalVolume.Uuid;


                        foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "xfs" })
                        {
                            try
                            {
                                imageFile =
                                    Directory.GetFiles(
                                        imagePath + Path.DirectorySeparatorChar,
                                        partition.VolumeGroup.Name + "-" + logicalVolume.Name + "." + ext + ".*")
                                    .FirstOrDefault();
                            }
                            catch (Exception ex)
                            {
                                Logger.Log(ex.Message);
                            }
                            if (imageFile != null)
                            {
                                clientLogicalVolume.PartcloneFileSystem = ext;
                                break;
                            }
                        }
                        switch (Path.GetExtension(imageFile))
                        {
                        case ".lz4":
                            clientLogicalVolume.Compression = "lz4";
                            clientLogicalVolume.ImageType   = "Block";
                            break;

                        case ".gz":
                            clientLogicalVolume.Compression = "gz";
                            clientLogicalVolume.ImageType   = "Block";
                            break;

                        case ".uncp":
                            clientLogicalVolume.Compression = "uncp";
                            clientLogicalVolume.ImageType   = "Block";
                            break;

                        case ".wim":
                            clientLogicalVolume.ImageType = "File";
                            break;
                        }

                        listLogicalVolumes.Add(clientLogicalVolume);
                    }
                    physicalPartition.VolumeGroup.LogicalVolumeCount = logicalVolumeCounter;
                    physicalPartition.VolumeGroup.LogicalVolumes     = listLogicalVolumes;
                }
                listPhysicalPartition.Add(physicalPartition);
            }

            return(listPhysicalPartition);
        }