Beispiel #1
0
        private void BuilderFileContentItem(textfilecontent_item item, FileContentItemSystemData itemSystemData, textfilecontent_item fileContentItem)
        {
            item.line = new EntityItemStringType()
            {
                Value = itemSystemData.Line.ToString(), datatype = Modulo.Collect.OVAL.Common.SimpleDatatypeEnumeration.@string, status = StatusEnumeration.exists
            };
            List <EntityItemAnySimpleType> destSubs = new List <EntityItemAnySimpleType>();

            item.filename = new EntityItemStringType()
            {
                Value = itemSystemData.FileName.ToString(), datatype = Modulo.Collect.OVAL.Common.SimpleDatatypeEnumeration.@string, status = StatusEnumeration.exists
            };
            foreach (string thisSub in itemSystemData.SubExpressions)
            {
                destSubs.Add(new EntityItemAnySimpleType()
                {
                    Value = thisSub, datatype = Modulo.Collect.OVAL.Common.SimpleDatatypeEnumeration.@string, status = StatusEnumeration.exists
                });
            }
            item.subexpression = destSubs.ToArray();

            item.filepath = fileContentItem.filepath;
            item.path     = fileContentItem.path;
            item.pattern  = fileContentItem.pattern;
            item.status   = StatusEnumeration.exists;
        }
Beispiel #2
0
        protected override IEnumerable <CollectedItem> collectDataForSystemItem(ItemType systemItem)
        {
            var filePath = string.Empty;

            try
            {
                var fileContentItem = (textfilecontent_item)systemItem;
                filePath = Path.Combine(fileContentItem.path.Value, fileContentItem.filename.Value);
                var interimList = WinNetUtils.getWinTextFileContent(hostUNC, filePath, fileContentItem.line.Value);

                var collectedItems = new List <CollectedItem>();
                foreach (FileContentItemSystemData srcItem in interimList)
                {
                    var destItem = new textfilecontent_item();
                    this.BuilderFileContentItem(destItem, srcItem, fileContentItem);
                    var newCollectedItem = new CollectedItem()
                    {
                        ItemType = destItem, ExecutionLog = BuildExecutionLog()
                    };
                    collectedItems.Add(newCollectedItem);
                }

                return(collectedItems);
            }
            catch (FileNotFoundException)
            {
                base.SetDoesNotExistStatusForItemType(systemItem, filePath);
            }

            return(new ItemTypeHelper().CreateCollectedItemsWithOneItem(systemItem, BuildExecutionLog()));
        }
Beispiel #3
0
        public void Should_be_possible_to_create_itemTypes_by_combination_of_entities()
        {
            IEnumerable <string> paths = new List <string>()
            {
                @"c:\temp"
            };
            IEnumerable <string> fileNames = new List <string>()
            {
                "teste.txt"
            };
            IEnumerable <string> lines = new List <string>()
            {
                "teste"
            };

            FileContentItemTypeFactory factory   = new FileContentItemTypeFactory();
            IEnumerable <ItemType>     itemTypes = factory.CreateFileItemTypesByCombinationOfEntitiesFrom(paths, fileNames, lines);

            Assert.AreEqual(1, itemTypes.Count(), "The number of created File Items is not expected.");

            textfilecontent_item fileContentItem = (textfilecontent_item)itemTypes.ElementAt(0);

            Assert.AreEqual(@"c:\temp", fileContentItem.path.Value, "A invalid attribute value was found.");
            Assert.AreEqual("teste.txt", fileContentItem.filename.Value, "A invalid attribute value was found.");
            Assert.AreEqual("teste", fileContentItem.line.Value, "A invalid attribute value was found.");
        }
 private void CleanTextFileContentItem(textfilecontent_item itemToClean)
 {
     itemToClean.pattern         = null;
     itemToClean.instance        = null;
     itemToClean.filename.status = StatusEnumeration.doesnotexist;
     itemToClean.filepath.status = StatusEnumeration.doesnotexist;
     itemToClean.path.status     = StatusEnumeration.doesnotexist;
 }
Beispiel #5
0
        private void AssertTextFileContentItem(textfilecontent_item textFileContentItem, string expectedValueForLineEntity, StatusEnumeration expectedCollectedObjectStatus)
        {
            var assertStatusFailedMessage = string.Format("The status must be '{0}'", expectedCollectedObjectStatus.ToString());

            Assert.AreEqual(expectedCollectedObjectStatus, textFileContentItem.status, assertStatusFailedMessage);

            if (!string.IsNullOrEmpty(expectedValueForLineEntity))
            {
                Assert.IsNotNull(textFileContentItem.line, "The line entity cannot be null.");
                Assert.AreEqual(expectedValueForLineEntity, textFileContentItem.line.Value, "Unexpected value for line entity was found.");
            }
        }
 private void AssertTextFileContentItem(textfilecontent_item itemToAssert, bool assertPathAndFilename = false)
 {
     ItemTypeEntityChecker.AssertItemTypeEntity(itemToAssert.filepath, "/usr/tmp/autorun.sh");
     if (assertPathAndFilename)
     {
         ItemTypeEntityChecker.AssertItemTypeEntity(itemToAssert.path, "/usr/tmp/");
         ItemTypeEntityChecker.AssertItemTypeEntity(itemToAssert.filename, "autorun.sh");
     }
     ItemTypeEntityChecker.AssertItemTypeEntity(itemToAssert.pattern, "if");
     ItemTypeEntityChecker.AssertItemTypeEntity(itemToAssert.instance, "1");
     ItemTypeEntityChecker.AssertItemTypeEntity(itemToAssert.text, "xxx if yyy");
 }
Beispiel #7
0
        private void ConfigureFilepathEnities(textfilecontent_item textFileContentItem)
        {
            var completeFilepath = textFileContentItem.GetCompleteFilepath();

            textFileContentItem.filepath = OvalHelper.CreateItemEntityWithStringValue(completeFilepath);
            if (String.IsNullOrWhiteSpace(completeFilepath))
            {
                return;
            }

            var directory = Path.GetDirectoryName(completeFilepath);

            textFileContentItem.path = OvalHelper.CreateItemEntityWithStringValue(directory);

            var filename = Path.GetFileName(completeFilepath);

            textFileContentItem.filename = OvalHelper.CreateItemEntityWithStringValue(filename);
        }
        private ItemType CreateItemType(string path, string fileName, string line)
        {
            textfilecontent_item fileContentItem = new textfilecontent_item();

            fileContentItem.filename = new EntityItemStringType()
            {
                Value = fileName
            };
            fileContentItem.path = new EntityItemStringType()
            {
                Value = path
            };
            fileContentItem.line = new EntityItemStringType()
            {
                Value = line
            };

            return(fileContentItem);
        }
Beispiel #9
0
        public void Should_be_possible_to_get_complete_filepath_from_textfilecontent_item()
        {
            var expectedFilepath = @"c:\windows\win.ini";

            var textFileContentItem1 =
                new textfilecontent_item()
            {
                filepath = OvalHelper.CreateItemEntityWithStringValue(expectedFilepath)
            };

            var textFileContentItem2 =
                new textfilecontent_item()
            {
                path     = OvalHelper.CreateItemEntityWithStringValue(Path.GetDirectoryName(expectedFilepath)),
                filename = OvalHelper.CreateItemEntityWithStringValue(Path.GetFileName(expectedFilepath))
            };


            Assert.AreEqual(expectedFilepath, textFileContentItem1.GetCompleteFilepath());
            Assert.AreEqual(expectedFilepath, textFileContentItem2.GetCompleteFilepath());
            Assert.AreEqual(String.Empty, new textfilecontent_item().GetCompleteFilepath());

            Assert.AreEqual(String.Empty,
                            new textfilecontent_item()
            {
                path = OvalHelper.CreateItemEntityWithStringValue("a")
            }
                            .GetCompleteFilepath());

            Assert.AreEqual(String.Empty,
                            new textfilecontent_item()
            {
                filename = OvalHelper.CreateItemEntityWithStringValue("a")
            }
                            .GetCompleteFilepath());
        }