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());
        }
        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;
        }
        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;
        }
 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");
 }
 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;
 }
        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);
        }
        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());
        }
示例#8
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.");
            }
        }