示例#1
0
        private static bool ValidateVHD(File_Type[] files)
        {
            // MUST BE Performed cannot skip.
            bool isValid = true;
            foreach (File_Type file in files)
            {
                string ext = Path.GetExtension(file.href).ToLower();
                if (ext == Properties.Settings.Default.manifestFileExtension || ext == Properties.Settings.Default.certificateFileExtension)
                    continue;

                if (File.Exists(file.href))
                {
                    if (!Properties.Settings.Default.knownFileExtensions.ToLower().Contains(ext))
                    {
                        log.WarnFormat(Messages.VALIDATION_INVALID_FILETYPE, file.href);
                    }
                }
                else
                {
                    var message = string.Format(Messages.VALIDATION_FILE_NOTFOUND, file.href);
                    log.Error(message);
                    throw new Exception(message);
                }
            }
            return isValid;
        }
示例#2
0
 public OvfStorageResource(RASD_Type type, EnvelopeType envelopeType)
 {
     rasd = type;
     envelope = envelopeType;
     file = OVF.FindFileReferenceByRASD(envelope, rasd);
 }
示例#3
0
        private static bool ValidateFiles(string ovfpath, File_Type[] files, VirtualDiskDesc_Type[] disks, RASD_Type[] rasds, ValidationFlags validationFlags, ref List<string> validationErrorMessages)
        {
            bool isValid = true;
            if ((validationFlags & ValidationFlags.Files) != 0)
            {
                if (files != null && files.Length > 0)
                {
                    foreach (File_Type file in files)
                    {
                        string ext = Path.GetExtension(file.href).ToLower();
                        if (ext == Properties.Settings.Default.manifestFileExtension || ext == Properties.Settings.Default.certificateFileExtension)
                            continue;

                        string filename = string.Format(@"{0}{1}{2}", string.IsNullOrEmpty(ovfpath) ? "" : ovfpath,
                                                                      string.IsNullOrEmpty(ovfpath) ? "" : @"\",
                                                                      file.href);
                        if (!File.Exists(filename))
                        {
                            var message = string.Format(Messages.VALIDATION_FILE_NOTFOUND, file.href);
                            validationErrorMessages.Add(message);
                            log.Error(message);
                            throw new Exception(message);
                        }
                    }
                }
                else
                {
                    log.Info("ValidateFiles: no attached files defined, continuing");
                    return isValid;
                }
                if (isValid)
                {
                    bool validlink = false;
                    foreach (File_Type file in files)
                    {
                        validlink = false;
                        foreach (VirtualDiskDesc_Type disk in disks)
                        {
                            if (file.id == disk.fileRef)
                            {
                                foreach (RASD_Type rasd in rasds)
                                {
                                    if (rasd.ResourceType.Value == 17 ||
                                        rasd.ResourceType.Value == 19 ||
                                        rasd.ResourceType.Value == 20 ||
                                        rasd.ResourceType.Value == 21)
                                    {
                                        if (rasd.HostResource != null && rasd.HostResource.Length > 0)
                                        {
                                            if (rasd.HostResource[0].Value.Contains(disk.diskId))
                                            {
                                                validlink = true;
                                                break;
                                            }
                                        }
                                        else if (disk.diskId == rasd.InstanceID.Value)
                                        {
                                            validlink = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (!validlink)
                        {
                            log.WarnFormat("Disk linkage [File to RASD] does not exist: {0}", file.href);
                            break;
                        }
                    }
                }
            }
            return isValid;
        }