Пример #1
0
        private IEnumerable <ItemType> ProcessOperationFilePath(OVAL.Definitions.ObjectType objectType)
        {
            var itemTypes = new List <ItemType>();

            EntityObjectStringType filePath = null;
            String path     = null;
            String fileName = null;

            if (objectType is OVAL.Definitions.Windows.file_object)
            {
                filePath = (EntityObjectStringType)((OVAL.Definitions.Windows.file_object)objectType).GetItemValue(file_object_ItemsChoices.filepath);
                path     = Path.GetDirectoryName(filePath.Value);
                fileName = Path.GetFileName(filePath.Value);
            }
            else if (objectType is OVAL.Definitions.Unix.file_object)
            {
                filePath = (EntityObjectStringType)((OVAL.Definitions.Unix.file_object)objectType).GetItemValue(OVAL.Definitions.Unix.ItemsChoiceType3.filepath);
                path     = GetUnixPath(filePath.Value);
                fileName = GetUnixFilename(filePath.Value);
            }

            if (filePath == null || filePath.Value == null)
            {
                return(itemTypes);
            }

            var filePathInformation = new FilePathRegexInformation(path);
            var operationForPath    = filePath.operation;

            if (this.operatorHelper.IsRegularExpression(operationForPath))
            {
                if (filePathInformation.GetPathWithFirstRegex() == null)
                {
                    operationForPath = OperationEnumeration.equals;
                }
            }
            else if (this.operatorHelper.IsNotEqualsOperation(operationForPath))
            {
                operationForPath = OperationEnumeration.equals;
            }

            var pathEntity = new EntityObjectStringType()
            {
                Value = path, operation = operationForPath
            };
            var fileNameEntity = new EntityObjectStringType()
            {
                Value = fileName, operation = filePath.operation
            };
            var fileEntities = new Dictionary <string, EntityObjectStringType>();

            fileEntities.Add("path", pathEntity);
            fileEntities.Add("filename", fileNameEntity);
            var paths     = this.ProcessOperationsPaths(fileEntities);
            var fileNames = this.ProcessOperationFileName(fileEntities, paths, true);

            var family = GetFamilyEnumerationForObjectType(objectType);

            return(new FileItemTypeFactory(family).CreateFileItemTypesWithFilePathsByCombinationFrom(paths, fileNames));
        }
Пример #2
0
 private bool IsFilePathSet(OVAL.Definitions.ObjectType objectType)
 {
     if (objectType is OVAL.Definitions.Windows.file_object)
     {
         return(((OVAL.Definitions.Windows.file_object)objectType).IsFilePathSet());
     }
     else if (objectType is OVAL.Definitions.Unix.file_object)
     {
         return(((OVAL.Definitions.Unix.file_object)objectType).IsFilePathSet());
     }
     else
     {
         throw new ArgumentException(String.Format("The object type '{0}' is not supported.", objectType.GetType().ToString()));
     }
 }
Пример #3
0
        public IEnumerable <ItemType> ProcessOperation(OVAL.Definitions.ObjectType objectType)
        {
            var itemTypes    = new List <ItemType>();
            var fileEntities = OvalHelper.GetFileEntitiesFromObjectType(objectType);

            if (IsFilePathSet(objectType))
            {
                itemTypes.AddRange(this.ProcessOperationFilePath(objectType));
                return(itemTypes);
            }
            else
            {
                var paths     = this.ProcessOperationsPaths(fileEntities);
                var fileNames = this.ProcessOperationFileName(fileEntities, paths, false);
                var family    = GetFamilyEnumerationForObjectType(objectType);
                return(new FileItemTypeFactory(family)
                       .CreateFileItemTypesByCombinationOfEntitiesFrom(new List <string>(), paths, fileNames));
            }
        }
Пример #4
0
 protected override set GetSetElement(OVAL.Definitions.ObjectType objectType)
 {
     return(null);
 }
Пример #5
0
 private FamilyEnumeration GetFamilyEnumerationForObjectType(OVAL.Definitions.ObjectType objectType)
 {
     return(objectType is OVAL.Definitions.Windows.file_object ? FamilyEnumeration.windows : FamilyEnumeration.unix);
 }