Пример #1
0
        protected override ItemType CreateFileItem(string fullFilePath, bool containsFilePathEntity)
        {
            var newFileItem = new file_item() { filepath = new EntityItemStringType() { Value = fullFilePath } };
            if (! containsFilePathEntity)
            {
                ((file_item)newFileItem).filepath = null;
                ((file_item)newFileItem).path = base.CreateEntityItemWithValue(Path.GetDirectoryName(fullFilePath));
                ((file_item)newFileItem).filename = this.CreateEntityItemWithValue(Path.GetFileName(fullFilePath));
            }

            return newFileItem;
        }
Пример #2
0
        public void Should_be_possible_to_collect_a_fileItem_without_filename_information()
        {
            var fileItem =
                new file_item()
                {
                    path = OvalHelper.CreateItemEntityWithStringValue("c:\\windows"),
                    filename = OvalHelper.CreateItemEntityWithStringValue(string.Empty)
                };
            var fileObjectCollector =
                new FileObjectCollector()
                {
                    WmiDataProvider = GetMockedWmiDataProvider()
                };

            var collectedObjects = fileObjectCollector.CollectDataForSystemItem(fileItem);
        }
Пример #3
0
        public void FillItemTypeWithData(file_item newFileItem, object collectedData)
        {
            FileItemSystemData fileSystemData = (FileItemSystemData)collectedData;

            newFileItem.owner = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.Owner);
            newFileItem.size = OvalHelper.CreateItemEntityWithIntegerValue(fileSystemData.Size.ToString());
            newFileItem.a_time = OvalHelper.CreateItemEntityWithIntegerValue(fileSystemData.ATime.ToString());
            newFileItem.c_time = OvalHelper.CreateItemEntityWithIntegerValue(fileSystemData.CTime.ToString());
            newFileItem.m_time = OvalHelper.CreateItemEntityWithIntegerValue(fileSystemData.MTime.ToString());
            newFileItem.ms_checksum = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.MS_Checksum);
            newFileItem.version = OvalHelper.CreateVersionItemTypeWithValue(fileSystemData.Version);
            newFileItem.type = new EntityItemFileTypeType() { Value = fileSystemData.Type };
            newFileItem.development_class = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.DevelopmentClass);
            newFileItem.company = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.Company);
            newFileItem.internal_name = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.InternalName);
            newFileItem.language = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.Language);
            newFileItem.original_filename = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.OriginalFilename);
            newFileItem.product_name = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.ProductName);
            newFileItem.product_version = OvalHelper.CreateVersionItemTypeWithValue(fileSystemData.ProductVersion);
        }
Пример #4
0
        private FileProber GetMockedFileProber(file_item fakeItem)
        {
            IList<String> fakeValues = new List<String>(new string[] { "FakeValue" });
            CollectedItem fakeCollectedItem = ProbeHelper.CreateFakeCollectedItem(fakeItem);

            MockRepository mocks = new MockRepository();
            IConnectionManager fakeConnection = mocks.DynamicMock<IConnectionManager>();
            ISystemInformationService fakeSystemInformation = mocks.DynamicMock<ISystemInformationService>();
            FileConnectionProvider fakeProvider = mocks.DynamicMock<FileConnectionProvider>();
            WmiDataProvider fakeWmiProvider = mocks.DynamicMock<WmiDataProvider>();
            FileObjectCollector fakeDataCollector = mocks.DynamicMock<FileObjectCollector>();
            fakeDataCollector.WmiDataProvider = fakeWmiProvider;

            //Expect.Call(fakeConnection.Connect<FileConnectionProvider>(null, null)).IgnoreArguments().Repeat.Any().Return(fakeProvider);
            Expect.Call(fakeDataCollector.CollectDataForSystemItem(fakeItem)).IgnoreArguments().Repeat.Any().Return(new List<CollectedItem>() {fakeCollectedItem});
            Expect.Call(fakeDataCollector.GetValues(null)).IgnoreArguments().Repeat.Any().Return(fakeValues);
            Expect.Call(fakeSystemInformation.GetSystemInformationFrom(null)).IgnoreArguments().Return(SystemInformationFactory.GetExpectedSystemInformation());
            mocks.ReplayAll();

            return new FileProber() { ConnectionManager = fakeConnection, ObjectCollector = fakeDataCollector };
        }
Пример #5
0
        private file_item CreateFakeFileItem(string filepath, string path, string filename)
        {
            string fullFilePath = filepath;
            string collectSuccessfully = "The File, which fullPath is '{0}', was collected sucessfully.";

            file_item newFileItem = new file_item();
            newFileItem.status = StatusEnumeration.exists;
            newFileItem.message = MessageType.FromString(string.Format(collectSuccessfully, fullFilePath));

            return newFileItem;
        }
Пример #6
0
 private void AssertPathAndFileNameEntitiesExistence(file_item fileItem)
 {
     Assert.IsFalse(IsItemEntityDefined(fileItem.filepath), string.Format(INVALID_FILEITEM_FORMAT_ERROR_MSG, "<path> and <filename>", "<filepath>"));
     Assert.IsTrue(IsItemEntityDefined(fileItem.path), string.Format(FILEITEM_ENTITY_NOT_FOUND, "<filepath>"));
     Assert.IsTrue(IsItemEntityDefined(fileItem.filename), string.Format(FILEITEM_ENTITY_NOT_FOUND, "<filename>"));
 }
Пример #7
0
        private WmiObject OpenWmiLogicalFileClass(file_item fileItem)
        {
            var fullFilePath = this.GetCompleteFilePath(fileItem);
            var isDirectory =
                ((fileItem.path != null) &&
                    ((fileItem.filename == null) ||
                    (string.IsNullOrWhiteSpace(fileItem.filename.Value))));

            IEnumerable<WmiObject> result = null;
            if (isDirectory)
            {
                fullFilePath = fullFilePath.Replace("\\\\", "\\");
                var wql = GetWqlForSearchDirectory(fullFilePath);
                result = this.WmiDataProvider.ExecuteWQL(wql);
            }
            else
            {
                var wmiInParameters = this.CreateWmiParameters(fullFilePath);
                result = this.WmiDataProvider.SearchWmiObjects(WMI_FILE_CLASS, wmiInParameters);
            }

            return ExtractResultFromWmiReturn(result);
        }
Пример #8
0
        private string GetCompleteFilePath(file_item fileItem)
        {
            bool isFilePathDefined = ((fileItem.filepath != null) && (!string.IsNullOrEmpty(fileItem.filepath.Value)));
            string completeFilePath = isFilePathDefined ? fileItem.filepath.Value : ConcatFilePathAndFileName(fileItem);

            if (string.IsNullOrEmpty(Path.GetExtension(completeFilePath)) && (!completeFilePath[completeFilePath.Length - 1].Equals(@"\")))
                return string.Format(@"{0}\", completeFilePath);

            return completeFilePath;
        }
Пример #9
0
 private string ConcatFilePathAndFileName(file_item fileItem)
 {
     if (fileItem.path.Value.EndsWith("\\"))
     {
         return string.Format("{0}{1}", fileItem.path.Value, fileItem.filename.Value);
     }
     else
     {
         return string.Format("{0}\\{1}", fileItem.path.Value, fileItem.filename.Value);
     }
 }
Пример #10
0
        private FileItemSystemData CollectFileItemSystemData(file_item fileItem)
        {
            WmiObject wmiLogicalFile = this.OpenWmiLogicalFileClass(fileItem);
            string fullFilePath = this.GetCompleteFilePath(fileItem);

            var fileItemSystemData = new FileItemSystemData();
            this.FillFileItemSystemData(wmiLogicalFile.GetValues(), fileItemSystemData);
            return fileItemSystemData;
        }