private void CreateAssertData() { XmlSerializer ser = new XmlSerializer(typeof(List <MediaFile>)); DirectoryInfo di = new DirectoryInfo(path); FileInfo[] files = di.GetFiles(); TextWriter writer = new StreamWriter(xmlFileName); List <MediaFile> mediaFiles = new List <MediaFile>(); foreach (FileInfo f in files) { mediaFiles.Add(StorageMapper.Map(f)); } ser.Serialize(writer, mediaFiles); writer.Close(); }
public async Task SetAsync(WebProgressTask task, IO.ContentStream content, string options) { var match = boundaryRegex.Match(options); var boundary = match.Success ? match.Groups["name"].Value : ""; boundary = $"--{boundary}"; ReadOnlyMemory <byte> rawBoundary = Encoding.UTF8.GetBytes(boundary); Entries.Clear(); using var reader = new NetworkReader(content, null, true); // parse the content while (true) { // expect boundary if (reader.ReadLine() != boundary) { break; } // read headers until an empty line is found var dict = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase); string?line; while (!string.IsNullOrWhiteSpace(line = reader.ReadLine())) { var header = headerSplit.Match(line); if (!header.Success) { break; } dict.Add(header.Groups["name"].Value, header.Groups["value"].Value); } var entry = GetEntry(dict); var storeInTemp = (AlwaysStoreFiles && entry is FormDataFile) || (MaximumCacheSize >= 0 && content.FullLength > MaximumCacheSize); // read the content of these entries if (storeInTemp) { var name = Path.GetTempFileName(); using var file = new FileStream(name, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None ); using var stream = StorageMapper?.Invoke(task, file) ?? file; await reader.ReadUntilAsync(rawBoundary, stream).ConfigureAwait(false); entry.Set(new FileInfo(name)); } else { entry.Set(await reader.ReadUntilAsync(rawBoundary).ConfigureAwait(false)); } // add new entry Entries.Add(entry); } // there should nothing left but to be sure just discard the rest content.Discard(); }
public async Task <Result <IEnumerable <Storage> > > GetPhysicalStoragesAsync() { var output = new List <Storage>(); var win32DiskDrives = await GetPhysicalData(() => _componentRepo.Get <Win32_DiskDrive>()); if (!win32DiskDrives.IsSuccess) { return(Result <IEnumerable <Storage> > .Fail(win32DiskDrives.Exception)); } var win32DiskPartitions = await GetPhysicalData(() => _componentRepo.Get <Win32_DiskPartition>()); if (!win32DiskPartitions.IsSuccess) { return(Result <IEnumerable <Storage> > .Fail(win32DiskPartitions.Exception)); } var win32DiskDriveToDiskPartitions = await GetPhysicalData(() => _componentRepo.Get <Win32_DiskDriveToDiskPartition>()); if (!win32DiskDriveToDiskPartitions.IsSuccess) { return(Result <IEnumerable <Storage> > .Fail(win32DiskDriveToDiskPartitions.Exception)); } var win32LogicalDiscsToPartitions = await GetPhysicalData(() => _componentRepo.Get <Win32_LogicalDiskToPartition>()); if (!win32LogicalDiscsToPartitions.IsSuccess) { return(Result <IEnumerable <Storage> > .Fail(win32LogicalDiscsToPartitions.Exception)); } var win32LogicalDiscs = await GetPhysicalData(() => _componentRepo.Get <Win32_LogicalDisk>()); if (!win32LogicalDiscs.IsSuccess) { return(Result <IEnumerable <Storage> > .Fail(win32LogicalDiscs.Exception)); } var msftPhysicalDiscs = await GetPhysicalData(() => _componentRepo.Get <MSFT_PhysicalDisk>()); if (!msftPhysicalDiscs.IsSuccess) { return(Result <IEnumerable <Storage> > .Fail(msftPhysicalDiscs.Exception)); } var mappings = RelateObjects(win32DiskDriveToDiskPartitions.Output, win32LogicalDiscsToPartitions.Output); if (!mappings.IsSuccess) { return(Result <IEnumerable <Storage> > .Fail(mappings.Exception)); } try { foreach (var mapGroup in mappings.Output.GroupBy(x => x.DiskDrive).ToList()) { var diskDrive = win32DiskDrives.Output.First(x => x.DeviceID == mapGroup.Key); var msftPhysicalDisk = msftPhysicalDiscs.Output.First(x => x.Model == diskDrive.Model); var diskPartitions = new List <Partition>(); foreach (var mapping in mapGroup) { var diskPartition = win32DiskPartitions.Output.First(x => x.DeviceID == mapping.DiskPartition); var logicalDisk = win32LogicalDiscs.Output.FirstOrDefault(x => x.DeviceID == mapping.LogicalDisk); diskPartitions.Add(PartitionMapper.From(diskPartition, logicalDisk)); } output.Add(StorageMapper.From(diskDrive, msftPhysicalDisk, diskPartitions)); } return(Result <IEnumerable <Storage> > .Ok(output)); } catch (Exception e) { return(Result <IEnumerable <Storage> > .Fail(e)); } }