public ReadDataSourceResult <FileInfoDataSource> Read(ReadDataSourceInput <FileInfoDataSource> input) { var result = new ReadDataSourceResult <FileInfoDataSource>(); var fi = new FileInfo(input.Config.Path); var attrs = new Dictionary <string, bool>(); foreach (var fa in Enum.GetValues(typeof(FileAttributes))) { attrs[Enum.GetName(typeof(FileAttributes), fa)] = (fi.Attributes & ((FileAttributes)fa)) != 0; } result.State = new FileInfoDataSource { Path = input.Config.Path, Exists = fi.Exists, FullPath = fi.FullName, Attributes = attrs, Name = fi.Name, Extension = fi.Extension, CreationTime = fi.Exists ? fi.CreationTime.ToString("r") : "", LastAccessTime = fi.Exists ? fi.LastAccessTime.ToString("r") : "", LastWriteTime = fi.Exists ? fi.LastWriteTime.ToString("r") : "", Length = fi.Exists ? fi.Length : -1, }; return(result); }
public ReadDataSourceResult <SystemInfoDataSource> Read(ReadDataSourceInput <SystemInfoDataSource> input) { var result = new ReadDataSourceResult <SystemInfoDataSource>(); var osPlatform = SystemInfoDataSource.OtherOSPlatform; foreach (var osp in SystemInfoDataSource.OSPlatforms) { if (RuntimeInformation.IsOSPlatform(osp)) { osPlatform = osp.ToString(); } } result.State = new SystemInfoDataSource { ProcessArchitecture = RuntimeInformation.ProcessArchitecture.ToString(), OSArchitecture = RuntimeInformation.OSArchitecture.ToString(), OSPlatform = osPlatform, OSDescription = RuntimeInformation.OSDescription, OSVersionString = System.Environment.OSVersion.VersionString, FrameworkDescription = RuntimeInformation.FrameworkDescription, }; return(result); }
public ReadDataSourceResult <RegistryKeyDataSource> Read( ReadDataSourceInput <RegistryKeyDataSource> input) { var result = new ReadDataSourceResult <RegistryKeyDataSource>(); var root = RegUtil.ParseRootKey(input.Config.Root); if (root == null) { result.Error("invalid root, must be one of: " + string.Join(" | ", RegUtil.AllRootAliases)); } else { using (var regKey = root.OpenSubKey(input.Config.Path)) { result.State = new RegistryKeyDataSource { Root = input.Config.Root, Path = input.Config.Path, KeyNames = regKey.GetSubKeyNames(), ValueNames = regKey.GetValueNames(), Entries = new Dictionary <string, Registry.ComputedRegValue>(), }; foreach (var n in result.State.ValueNames) { var val = regKey.GetValue(n); var typ = regKey.GetValueKind(n); var regVal = new ComputedRegValue { Type = RegUtil.ToString(typ) }; switch (typ) { case RegistryValueKind.MultiString: regVal.Values = (string[])regKey.GetValue(n); break; case RegistryValueKind.Binary: regVal.ValueBase64 = Convert.ToBase64String((byte[])regKey.GetValue(n) ?? new byte[0]); break; default: regVal.Value = regKey.GetValue(n)?.ToString(); break; } result.State.Entries.Add(n, regVal); } } } return(result); }