Esempio n. 1
0
        private static void ValidateDisks(RASD_Type rasd, File_Type[] files, VirtualDiskDesc_Type[] disks,
                                          ref List <File_Type> linkedFiles, ref List <string> warnings)
        {
            log.Info("Validating disks");

            VirtualDiskDesc_Type disk;

            if (rasd.HostResource != null && rasd.HostResource.Length > 0)
            {
                disk = disks.FirstOrDefault(d => rasd.HostResource[0].Value.Contains(d.diskId));
            }
            else
            {
                disk = disks.FirstOrDefault(d => rasd.InstanceID.Value == d.diskId);
            }

            File_Type file = null;

            if (disk != null)
            {
                file = files.FirstOrDefault(f => f.id == disk.fileRef);
            }

            if (file != null && !linkedFiles.Contains(file))
            {
                linkedFiles.Add(file);
            }
        }
Esempio n. 2
0
        internal static void Decompress(string _SourcePath, string _OutputPath, File_Type _Type)
        {
            using (FileStream _InputStream = new FileStream(_SourcePath, FileMode.Open))
            {
                using (FileStream _OutputStream = new FileStream(_OutputPath, FileMode.Create))
                {
                    switch (_Type)
                    {
                    case File_Type.CSV:
                    {
                        byte[] _Properties = new byte[5];
                        _InputStream.Read(_Properties, 0, 5);

                        byte[] _Buffer = new byte[4];
                        _InputStream.Read(_Buffer, 0, 4);

                        _Decoder.SetDecoderProperties(_Properties);
                        _Decoder.Code(_InputStream, _OutputStream, _InputStream.Length, BitConverter.ToInt32(_Buffer, 0), null);

                        break;
                    }

                    case File_Type.SC:
                    {
                        _InputStream.Seek(26, SeekOrigin.Current);

                        byte[] _Properties = new byte[5];
                        _InputStream.Read(_Properties, 0, 5);

                        byte[] _Buffer = new byte[4];
                        _InputStream.Read(_Buffer, 0, 4);

                        _Decoder.SetDecoderProperties(_Properties);
                        _Decoder.Code(_InputStream, _OutputStream, _InputStream.Length, BitConverter.ToInt32(_Buffer, 0), null);

                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// An ovf can contain both encrypted and non-encrypted file mixed together.
        /// find if file name is encrypted.
        /// 1. check the References for the security ID
        /// 2. check the Security id section exists.
        /// </summary>
        /// <param name="ovfObj">OVF Envelope</param>
        /// <param name="filename">filename to check</param>
        /// <returns>true = encrypted; false = not encrypted</returns>
        public static bool IsThisEncrypted(EnvelopeType ovfObj, RASD_Type rasd)
        {
            bool _isEncrypted = false;

            // 15,16,17,19,20 are attached files.
            // rest is RASD specific

            switch (rasd.ResourceType.Value)
            {
            case 15:
            case 16:
            case 17:
            case 19:
            case 20:
            {
                File_Type file = FindFileReferenceByRASD(ovfObj, rasd);
                if (file != null)
                {
                    if (!string.IsNullOrEmpty(file.Id))
                    {
                        _isEncrypted = IsThisIdEncrypted(ovfObj, file.Id);
                    }
                }
                break;
            }

            default:
            {
                // currently encrypted RASD or Elements, isn't being done, but this can check it.
                if (rasd.AnyAttr != null && rasd.AnyAttr.Length > 0)
                {
                    foreach (XmlAttribute xa in rasd.AnyAttr)
                    {
                        if (xa.Name.ToLower().Equals("xenc:id"))
                        {
                            _isEncrypted = IsThisIdEncrypted(ovfObj, xa.Value);
                            break;
                        }
                    }
                }
                break;
            }
            }
            return(_isEncrypted);
        }
Esempio n. 4
0
        public DiskElements CreateDiskModels(IList <Disk> diskModels)
        {
            var diskFiles  = new List <File_Type>();
            var disks      = new List <VirtualDiskDesc_Type>();
            var diskDrives = new List <RASD_Type>();

            int ideDiskCount  = 0;
            int scsiDiskCount = 0;

            for (var i = 0; i < diskModels.Count; i++)
            {
                var diskModel = diskModels[i];
                var diskFile  = new File_Type {
                    href = diskModel.Path, id = "diskFile" + i, sizeSpecified = true, size = diskModel.FileSize
                };
                var disk = new VirtualDiskDesc_Type
                {
                    fileRef  = diskFile.id,
                    diskId   = "diskId" + i,
                    capacity = diskModels[i].CapacityMb.ToString(),
                    format   = formatStringLookup[diskModels[i].Format],
                    capacityAllocationUnits = "byte * 2^20"
                };

                string parent;
                int    addressOnParent;
                if (diskModel.ControllerType == ControllerType.IDE)
                {
                    parent          = "ide" + ideDiskCount / 2;
                    addressOnParent = ideDiskCount % 2;
                    ideDiskCount++;
                }
                else
                {
                    parent          = "scsi0";
                    addressOnParent = scsiDiskCount;
                    scsiDiskCount++;
                }

                var diskDrive = new RASD_Type
                {
                    AddressOnParent = new cimString {
                        Value = addressOnParent.ToString()
                    },
                    AutomaticAllocation = new cimBoolean {
                        Value = false
                    },
                    AutomaticDeallocation = new cimBoolean {
                        Value = false
                    },
                    InstanceID = new cimString {
                        Value = disk.diskId
                    },
                    ElementName = new cimString {
                        Value = "Disk " + disk.diskId
                    },
                    ResourceType = new ResourceType {
                        Value = "17"
                    },
                    HostResource = new[] { new cimString {
                                               Value = "ovf:/disk/" + disk.diskId
                                           } },
                    Parent = new cimString {
                        Value = parent
                    }
                };

                diskFiles.Add(diskFile);
                disks.Add(disk);
                diskDrives.Add(diskDrive);
            }

            return(new DiskElements(diskFiles, disks, diskDrives));
        }
Esempio n. 5
0
 public void getpath(string path1)
 {
     try
     {
         string realfile = "";
         string paths    = this.ctrlr.getserver();
         if (path1 != "")
         {
             realfile = paths + path1;
             if (File.Exists(realfile) == true)
             {
                 if (File_Type.ToLower() == ".jpeg" || File_Type.ToLower() == ".jpg" || File_Type.ToLower() == ".gif" || File_Type.ToLower() == ".png")
                 {
                     Image_Zoom frm = new Image_Zoom();
                     frm.attach_id = attach_id;
                     frm.ShowDialog(this);
                     frm.Dispose();
                 }
                 else if (File_Type.ToLower() == ".docx" || File_Type.ToLower() == ".doc")
                 {
                     SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                     saveFileDialog1.Filter = "Word Documents|*.doc | Word Documents 2010|*.docx";
                     saveFileDialog1.Title  = "Save an Image File";
                     saveFileDialog1.ShowDialog();
                     if (saveFileDialog1.FileName != "")
                     {
                         if (attach_id != 0)
                         {
                             if (File.Exists(realfile))
                             {
                                 System.IO.File.Copy(realfile, saveFileDialog1.FileName);
                                 MessageBox.Show("Successfully Saved !!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             }
                             else
                             {
                                 MessageBox.Show("File Not Found", "Not Exists", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             }
                         }
                     }
                 }
                 else if (File_Type.ToLower() == ".xls" || File_Type.ToLower() == ".xlsx")
                 {
                     SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                     saveFileDialog1.Filter = "Excel Worksheets|*.xls | Excel Worksheets 2010|*.xlsx";
                     saveFileDialog1.Title  = "Save an Image File";
                     saveFileDialog1.ShowDialog();
                     if (saveFileDialog1.FileName != "")
                     {
                         if (attach_id != 0)
                         {
                             if (File.Exists(realfile))
                             {
                                 System.IO.File.Copy(realfile, saveFileDialog1.FileName);
                                 MessageBox.Show("Successfully Saved !!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             }
                             else
                             {
                                 MessageBox.Show("File Not Found", "Not Exists", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             }
                         }
                     }
                 }
                 else if (File_Type.ToLower() == ".pdf")
                 {
                     SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                     saveFileDialog1.Filter = "Pdf Files|*.pdf";
                     saveFileDialog1.Title  = "Save an Image File";
                     saveFileDialog1.ShowDialog();
                     if (saveFileDialog1.FileName != "")
                     {
                         if (attach_id != 0)
                         {
                             if (File.Exists(realfile))
                             {
                                 System.IO.File.Copy(realfile, saveFileDialog1.FileName);
                                 MessageBox.Show("Successfully Saved !!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             }
                             else
                             {
                                 MessageBox.Show("File Not Found", "Not Exists", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             }
                         }
                     }
                 }
             }
             else
             {
                 MessageBox.Show("Image Not Found", "Not Exists", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 6
0
 public OvfStorageResource(RASD_Type type, EnvelopeType envelopeType)
 {
     rasd     = type;
     envelope = envelopeType;
     file     = OVF.FindFileReferenceByRASD(envelope, rasd);
 }
Esempio n. 7
0
        /// <summary>
        /// 递归拷贝文件,把源目录下所有文件和文件夹拷贝到目标目录
        /// </summary>
        /// <param name="sourceDirectory">源路径</param>
        /// <param name="aimDirectory">目标路径</param>
        private bool RecursionCopyFiles2(string sourceDirectory, string aimDirectory, File_Type fileType)
        {
            if (!System.IO.Directory.Exists(sourceDirectory) & !System.IO.Directory.Exists(aimDirectory))//
            {
                return(false);
            }
            try
            {
                if (fileType == File_Type.Png_Ico_Jpg)
                {
                    if (!System.IO.Directory.Exists(aimDirectory))
                    {
                        System.IO.Directory.CreateDirectory(aimDirectory);//if not exist the aimDirectory,create it
                    }

                    string[] files = System.IO.Directory.GetFiles(sourceDirectory);

                    if (files.Length > 0)
                    {
                        foreach (string file in files)
                        {
                            string extention = System.IO.Path.GetExtension(file);
                            if (extention.Equals(".png") || extention.Equals(".jpg") || extention.Equals(".ico"))
                            {
                                //不需要进度条效果,可以直接使用下一句来拷贝文件
                                // System.IO.File.Copy(file,aimDirectory+file.Substring(file.LastIndexOf(@"\")));//Copy The File To The Aim
                                string sourceFile = file;
                                string aimFile    = aimDirectory + file.Substring(file.LastIndexOf(@"\"));
                                CopyFile(sourceFile, aimFile);//调用文件拷贝函数
                            }
                        }
                    }
                    return(true);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 8
0
 private void AddFromRecordSet(SQLiteDataReader rs)
 {
     try
     {
         if (!rs.IsDBNull(0))
         {
             _backup_lsn = rs.GetDecimal(0);
         }
         if (!rs.IsDBNull(1))
         {
             _create_lsn = rs.GetDecimal(1);
         }
         if (!rs.IsDBNull(2))
         {
             _data_space_id = rs.GetInt32(2);
         }
         if (!rs.IsDBNull(3))
         {
             _database_id = rs.GetInt32(3);
         }
         if (!rs.IsDBNull(4))
         {
             _differential_base_guid = rs.GetGuid(4);
         }
         if (!rs.IsDBNull(5))
         {
             _differential_base_lsn = rs.GetDecimal(5);
         }
         if (!rs.IsDBNull(6))
         {
             _differential_base_time = rs.GetDateTime(6);
         }
         if (!rs.IsDBNull(7))
         {
             _drop_lsn = rs.GetDecimal(7);
         }
         if (!rs.IsDBNull(8))
         {
             _file_guid = rs.GetGuid(8);
         }
         if (!rs.IsDBNull(9))
         {
             _file_id = rs.GetInt32(9);
         }
         if (!rs.IsDBNull(10))
         {
             _growth = rs.GetInt32(10);
         }
         if (!rs.IsDBNull(11))
         {
             _is_media_read_only = rs.GetBoolean(11);
         }
         if (!rs.IsDBNull(12))
         {
             _is_name_reserved = rs.GetBoolean(12);
         }
         if (!rs.IsDBNull(13))
         {
             _is_percent_growth = rs.GetBoolean(13);
         }
         if (!rs.IsDBNull(14))
         {
             _is_read_only = rs.GetBoolean(14);
         }
         if (!rs.IsDBNull(15))
         {
             _is_sparse = rs.GetBoolean(15);
         }
         if (!rs.IsDBNull(16))
         {
             _max_size = rs.GetInt32(16);
         }
         if (!rs.IsDBNull(17))
         {
             _name = rs.GetString(17);
         }
         if (!rs.IsDBNull(18))
         {
             _physical_name = rs.GetString(18);
         }
         if (!rs.IsDBNull(19))
         {
             _read_only_lsn = rs.GetDecimal(19);
         }
         if (!rs.IsDBNull(20))
         {
             _read_write_lsn = rs.GetDecimal(20);
         }
         if (!rs.IsDBNull(21))
         {
             _redo_start_fork_guid = rs.GetGuid(21);
         }
         if (!rs.IsDBNull(22))
         {
             _redo_start_lsn = rs.GetDecimal(22);
         }
         if (!rs.IsDBNull(23))
         {
             _redo_target_fork_guid = rs.GetGuid(23);
         }
         if (!rs.IsDBNull(24))
         {
             _redo_target_lsn = rs.GetDecimal(24);
         }
         if (!rs.IsDBNull(25))
         {
             _size = rs.GetInt32(25);
         }
         if (!rs.IsDBNull(26))
         {
             _state = (FileState)rs.GetByte(26);
         }
         if (!rs.IsDBNull(27))
         {
             _state_desc = rs.GetString(27);
         }
         if (!rs.IsDBNull(28))
         {
             _type = (File_Type)rs.GetByte(28);
         }
         if (!rs.IsDBNull(29))
         {
             _type_desc = rs.GetString(29);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }