Beispiel #1
0
        protected override void BeginProcessing()
        {
            if (_path == null)
            {
                _path = new string[] { @".\" };
            }
            if (force)
            {
                priv = new Alphaleonis.Win32.Security.PrivilegeEnabler(Alphaleonis.Win32.Security.Privilege.Backup);
            }

            dopt = DirectoryEnumerationOptions.BasicSearch | DirectoryEnumerationOptions.ContinueOnException | DirectoryEnumerationOptions.LargeCache;
            if (recurse)
            {
                dopt |= DirectoryEnumerationOptions.Recursive;
            }
            if (directory && !file)
            {
                dopt |= DirectoryEnumerationOptions.Folders;
            }
            else if (file && !directory)
            {
                dopt |= DirectoryEnumerationOptions.Files;
            }
            else
            {
                dopt |= DirectoryEnumerationOptions.FilesAndFolders;
            }
        }
        public static IEnumerable <string> EnumerateDirectories(string path, DirectoryEnumerationOptions options)
        {
            // Adhere to the method name.
            options &= ~DirectoryEnumerationOptions.Files;  // Remove enumeration of files.
            options |= DirectoryEnumerationOptions.Folders; // Add enumeration of directories.

            return(EnumerateFileSystemEntryInfosCore <string>(null, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath));
        }
Beispiel #3
0
        public IEnumerable <FileInfo> EnumerateFiles(DirectoryEnumerationOptions options)
        {
            // Adhere to the method name.
            options &= ~DirectoryEnumerationOptions.Folders;
            options |= DirectoryEnumerationOptions.Files;

            return(Directory.EnumerateFileSystemEntryInfosCore <FileInfo>(Transaction, LongFullName, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath));
        }
Beispiel #4
0
        public IEnumerable <FileInfo> EnumerateFiles(string searchPattern, DirectoryEnumerationOptions options)
        {
            // Adhere to the method name.
            options &= ~DirectoryEnumerationOptions.Folders;
            options |= DirectoryEnumerationOptions.Files;

            return(Directory.EnumerateFileSystemEntryInfosCore <FileInfo>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath));
        }
        public static IEnumerable <string> EnumerateDirectories(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
        {
            // Adhere to the method name.
            options &= ~DirectoryEnumerationOptions.Files;
            options |= DirectoryEnumerationOptions.Folders;

            return(EnumerateFileSystemEntryInfosCore <string>(null, path, Path.WildcardStarMatchAll, options, pathFormat));
        }
        private static IEnumerable <string> GetPathsUsingAlphaFs(PathSearchOptions searchOptions)
        {
            DirectoryEnumerationOptions options = (DirectoryEnumerationOptions)searchOptions.TypesToGet |
                                                  DirectoryEnumerationOptions.ContinueOnException | DirectoryEnumerationOptions.SkipReparsePoints;

            if (searchOptions.SearchOption == SearchOption.AllDirectories)
            {
                options |= DirectoryEnumerationOptions.Recursive;
            }

            var paths = Directory.EnumerateFileSystemEntries(searchOptions.RootDirectory, searchOptions.SearchPattern, options);

            return(paths);
        }
Beispiel #7
0
 public static void Compress(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
 {
     CompressDecompressCore(null, path, Path.WildcardStarMatchAll, options, null, true, pathFormat);
 }
Beispiel #8
0
 public long CountFileSystemObjects(string searchPattern, DirectoryEnumerationOptions options)
 {
     return(Directory.EnumerateFileSystemEntryInfosCore <string>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath).Count());
 }
Beispiel #9
0
 public static Dictionary <string, long> GetProperties(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
 {
     return(GetPropertiesInternal(null, path, options, pathFormat));
 }
Beispiel #10
0
 public static void CompressTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
 {
     CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, options, null, true, PathFormat.RelativePath);
 }
 public long CountFileSystemObjects(string searchPattern, DirectoryEnumerationOptions options)
 {
    return Directory.EnumerateFileSystemEntryInfosInternal<string>(Transaction, LongFullName, searchPattern, options, PathFormat.LongFullPath).Count();
 }
 public static Dictionary<string, long> GetProperties(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
 {
    return GetPropertiesInternal(null, path, options, pathFormat);
 }
Beispiel #13
0
 public static IEnumerable <T> EnumerateFileSystemEntryInfosTransacted <T>(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
 {
     return(EnumerateFileSystemEntryInfosCore <T>(transaction, path, Path.WildcardStarMatchAll, options, pathFormat));
 }
 public static long CountFileSystemObjects(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
 {
    return EnumerateFileSystemEntryInfosInternal<string>(transaction, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath).Count();
 }
      internal static void CompressDecompressInternal(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, bool compress, PathFormat pathFormat)
      {
         string pathLp = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);

         // Process directories and files.
         foreach (var fso in EnumerateFileSystemEntryInfosInternal<string>(transaction, pathLp, searchPattern, options | DirectoryEnumerationOptions.AsLongPath, PathFormat.LongFullPath))
            Device.ToggleCompressionInternal(true, transaction, fso, compress, PathFormat.LongFullPath);

         // Compress the root directory, the given path.
         Device.ToggleCompressionInternal(true, transaction, pathLp, compress, PathFormat.LongFullPath);
      }
 public static void Compress(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
 {
    CompressDecompressInternal(null, path, Path.WildcardStarMatchAll, options, true, pathFormat);
 }
 public static void Decompress(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
 {
    CompressDecompressInternal(transaction, path, Path.WildcardStarMatchAll, options, false, pathFormat);
 }
 public static void Decompress(string path, DirectoryEnumerationOptions options)
 {
    CompressDecompressInternal(null, path, Path.WildcardStarMatchAll, options, false, PathFormat.RelativePath);
 }
 public static void Compress(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
 {
    CompressDecompressInternal(transaction, path, Path.WildcardStarMatchAll, options, true, PathFormat.RelativePath);
 }
 public void Decompress(DirectoryEnumerationOptions options)
 {
    Directory.CompressDecompressInternal(Transaction, LongFullName, Path.WildcardStarMatchAll, options, false, PathFormat.LongFullPath);
 }
 public static long CountFileSystemObjects(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
 {
    return EnumerateFileSystemEntryInfosInternal<string>(null, path, Path.WildcardStarMatchAll, options, pathFormat).Count();
 }
      internal static Dictionary<string, long> GetPropertiesInternal(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
      {
         const string propFile = "File";
         const string propTotal = "Total";
         const string propSize = "Size";
         long total = 0;
         long size = 0;
         Type typeOfAttrs = typeof(FileAttributes);
         Array attributes = Enum.GetValues(typeOfAttrs);
         Dictionary<string, long> props = Enum.GetNames(typeOfAttrs).OrderBy(attrs => attrs).ToDictionary<string, string, long>(name => name, name => 0);

         string pathLp = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);

         foreach (FileSystemEntryInfo fsei in EnumerateFileSystemEntryInfosInternal<FileSystemEntryInfo>(transaction, pathLp, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath))
         {
            total++;

            if (!fsei.IsDirectory)
               size += fsei.FileSize;

            foreach (FileAttributes attributeMarker in attributes)
            {
               // Marker exists in flags.
               if ((fsei.Attributes & attributeMarker) == attributeMarker)

                  // Regular directory that will go to stack, adding directory flag ++
                  props[(((attributeMarker & FileAttributes.Directory) == FileAttributes.Directory) ? FileAttributes.Directory : attributeMarker).ToString()]++;
            }
         }

         // Adjust regular files count.
         props.Add(propFile, total - props[FileAttributes.Directory.ToString()] - props[FileAttributes.ReparsePoint.ToString()]);
         props.Add(propTotal, total);
         props.Add(propSize, size);

         return props;
      }
Beispiel #23
0
    private static void DoWork(string f, string r, string d, string csv, string dt, bool debug, bool trace)
    {
        var levelSwitch = new LoggingLevelSwitch();

        var template = "{Message:lj}{NewLine}{Exception}";

        if (debug)
        {
            levelSwitch.MinimumLevel = LogEventLevel.Debug;
            template = "[{Timestamp:HH:mm:ss.fff} {Level:u3}] {Message:lj}{NewLine}{Exception}";
        }

        if (trace)
        {
            levelSwitch.MinimumLevel = LogEventLevel.Verbose;
            template = "[{Timestamp:HH:mm:ss.fff} {Level:u3}] {Message:lj}{NewLine}{Exception}";
        }

        var conf = new LoggerConfiguration()
                   .WriteTo.Console(outputTemplate: template)
                   .MinimumLevel.ControlledBy(levelSwitch);

        Log.Logger = conf.CreateLogger();

        if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            Console.WriteLine();
            Log.Fatal("Non-Windows platforms not supported due to the need to load ESI specific Windows libraries! Exiting...");
            Console.WriteLine();
            Environment.Exit(0);
            return;
        }

        if (f.IsNullOrEmpty() && d.IsNullOrEmpty())
        {
            var helpBld = new HelpBuilder(LocalizationResources.Instance, Console.WindowWidth);

            var hc = new HelpContext(helpBld, _rootCommand, Console.Out);

            helpBld.Write(hc);

            Log.Warning("Either -f or -d is required. Exiting\r\n");
            return;
        }


        if (f.IsNullOrEmpty() == false && !File.Exists(f))
        {
            Log.Warning("File '{File}' not found. Exiting", f);
            return;
        }

        if (d.IsNullOrEmpty() == false && !Directory.Exists(d))
        {
            Log.Warning("Directory '{D}' not found. Exiting", d);
            return;
        }

        if (csv.IsNullOrEmpty())
        {
            var helpBld = new HelpBuilder(LocalizationResources.Instance, Console.WindowWidth);

            var hc = new HelpContext(helpBld, _rootCommand, Console.Out);

            helpBld.Write(hc);

            Log.Warning("--csv is required. Exiting\r\n");
            return;
        }

        Log.Information("{Header}", Header);
        Console.WriteLine();
        Log.Information("Command line: {Args}\r\n", string.Join(" ", _args));

        if (IsAdministrator() == false)
        {
            Log.Warning("Warning: Administrator privileges not found!\r\n");
        }

        var sw = new Stopwatch();

        sw.Start();

        var ts = DateTimeOffset.UtcNow;

        Srum sr = null;

        if (d.IsNullOrEmpty() == false)
        {
            IEnumerable <string> files2;

#if NET6_0
            var enumerationOptions = new EnumerationOptions
            {
                IgnoreInaccessible    = true,
                MatchCasing           = MatchCasing.CaseInsensitive,
                RecurseSubdirectories = true,
                AttributesToSkip      = 0
            };

            files2 =
                Directory.EnumerateFileSystemEntries(d, "SRUDB.DAT", enumerationOptions);

            f = files2.FirstOrDefault();

            if (f.IsNullOrEmpty())
            {
                Log.Warning("Did not locate any files named 'SRUDB.dat'! Exiting");
                return;
            }

            Log.Information("Found SRUM database file '{F}'!", f);

            files2 =
                Directory.EnumerateFileSystemEntries(d, "SOFTWARE", enumerationOptions);

            r = files2.FirstOrDefault();

            if (r.IsNullOrEmpty())
            {
                Log.Warning("Did not locate any files named 'SOFTWARE'! Registry data will not be extracted");
            }
            else
            {
                Log.Information("Found SOFTWARE hive '{R}'!", r);
            }
            #elif NET462
            //kape mode, so find the files
            var ilter = new DirectoryEnumerationFilters();
            ilter.InclusionFilter = fsei =>
            {
                if (fsei.FileSize == 0)
                {
                    return(false);
                }

                if (fsei.FileName.ToUpperInvariant() == "SRUDB.DAT")
                {
                    return(true);
                }

                return(false);
            };

            ilter.RecursionFilter = entryInfo => !entryInfo.IsMountPoint && !entryInfo.IsSymbolicLink;

            ilter.ErrorFilter = (errorCode, errorMessage, pathProcessed) => true;

            const DirectoryEnumerationOptions dirEnumOptions =
                DirectoryEnumerationOptions.Files | DirectoryEnumerationOptions.Recursive |
                DirectoryEnumerationOptions.SkipReparsePoints | DirectoryEnumerationOptions.ContinueOnException |
                DirectoryEnumerationOptions.BasicSearch;

            files2 =
                Directory.EnumerateFileSystemEntries(d, dirEnumOptions, ilter);

            f = files2.FirstOrDefault();

            if (f.IsNullOrEmpty())
            {
                Log.Warning("Did not locate any files named 'SRUDB.dat'! Exiting");
                return;
            }

            Log.Information("Found SRUM database file '{F}'!", f);

            ilter = new DirectoryEnumerationFilters();
            ilter.InclusionFilter = fsei =>
            {
                if (fsei.FileSize == 0)
                {
                    return(false);
                }

                if (fsei.FileName.ToUpperInvariant() == "SOFTWARE")
                {
                    return(true);
                }

                return(false);
            };

            ilter.RecursionFilter = entryInfo => !entryInfo.IsMountPoint && !entryInfo.IsSymbolicLink;

            ilter.ErrorFilter = (errorCode, errorMessage, pathProcessed) => true;

            files2 =
                Directory.EnumerateFileSystemEntries(d, dirEnumOptions, ilter);


            r = files2.FirstOrDefault();

            if (r.IsNullOrEmpty())
            {
                Log.Warning("Did not locate any files named 'SOFTWARE'! Registry data will not be extracted");
            }
            else
            {
                Log.Information("Found SOFTWARE hive '{R}'!", r);
            }
#endif



            Console.WriteLine();
        }

        try
        {
            Log.Information("Processing '{F}'...", f);
            sr = new Srum(f, r);

            Console.WriteLine();
            Log.Information("Processing complete!");
            Console.WriteLine();

            Log.Information("{EnergyUse} {EnergyUsagesCount:N0}", "Energy Usage count:".PadRight(30),
                            sr.EnergyUsages.Count);
            Log.Information("{Unknown312s} {Unknown312sCount:N0}", "Unknown 312 count:".PadRight(30),
                            sr.TimelineProviders.Count);
            Log.Information("{UnknownD8Fs} {UnknownD8FsCount:N0}", "Unknown D8F count:".PadRight(30),
                            sr.Vfuprovs.Count);
            Log.Information("{AppResourceUseInfos} {AppResourceUseInfosCount:N0}",
                            "App Resource Usage count:".PadRight(30), sr.AppResourceUseInfos.Count);
            Log.Information("{NetworkConnections} {NetworkConnectionsCount:N0}",
                            "Network Connection count:".PadRight(30), sr.NetworkConnections.Count);
            Log.Information("{NetworkUsages} {NetworkUsagesCount}", "Network Usage count:".PadRight(30),
                            sr.NetworkUsages.Count);
            Log.Information("{PushNotifications} {PushNotificationsCount:N0}", "Push Notification count:".PadRight(30),
                            sr.PushNotifications.Count);
            Console.WriteLine();
        }
        catch (Exception e)
        {
            Log.Error(e,
                      "Error processing file! Message: {Message}.\r\n\r\nThis almost always means the database is dirty and must be repaired. This can be verified by running 'esentutl.exe /mh SRUDB.dat' and examining the 'State' property",
                      e.Message);
            Console.WriteLine();
            Log.Information(
                "If the database is dirty, **make a copy of your files**, ensure all files in the directory are not Read-only, open a PowerShell session as an admin, and repair by using the following commands (change directories to the location of SRUDB.dat first):\r\n\r\n'esentutl.exe /r sru /i'\r\n'esentutl.exe /p SRUDB.dat'\r\n\r\n");
            Environment.Exit(0);
        }

        if (csv.IsNullOrEmpty() == false)
        {
            if (Directory.Exists(csv) == false)
            {
                Log.Information(
                    "Path to '{Csv}' doesn't exist. Creating...", csv);

                try
                {
                    Directory.CreateDirectory(csv);
                }
                catch (Exception)
                {
                    Log.Fatal(
                        "Unable to create directory '{Csv}'. Does a file with the same name exist? Exiting", csv);
                    return;
                }
            }


            string outName;

            string outFile;

            Log.Information("CSV output will be saved to '{Csv}'\r\n", csv);

            StreamWriter swCsv;
            CsvWriter    csvWriter;
            try
            {
                Log.Debug("Dumping Energy Usage tables '{TableName}'", EnergyUsage.TableName);

                outName = $"{ts:yyyyMMddHHmmss}_SrumECmd_EnergyUsage_Output.csv";

                outFile = Path.Combine(csv, outName);

                swCsv = new StreamWriter(outFile, false, Encoding.UTF8);

                csvWriter = new CsvWriter(swCsv, CultureInfo.InvariantCulture);

                var foo = csvWriter.Context.AutoMap <EnergyUsage>();
                foo.Map(t => t.Timestamp).Convert(t =>
                                                  $"{t.Value.Timestamp:yyyy-MM-dd HH:mm:ss}");
                foo.Map(t => t.EventTimestamp).Convert(t =>
                                                       $"{t.Value.EventTimestamp?.ToString(dt)}");

                csvWriter.Context.RegisterClassMap(foo);
                csvWriter.WriteHeader <EnergyUsage>();
                csvWriter.NextRecord();

                csvWriter.WriteRecords(sr.EnergyUsages.Values);

                csvWriter.Flush();
                swCsv.Flush();
            }
            catch (Exception e)
            {
                Log.Error(e, "Error exporting 'EnergyUsage' data! Error: {Message}", e.Message);
            }


            try
            {
                Log.Debug("Dumping Unknown 312 table '{TableName}'", TimelineProvider.TableName);

                outName = $"{ts:yyyyMMddHHmmss}_SrumECmd_Unknown312_Output.csv";

                outFile = Path.Combine(csv, outName);

                swCsv = new StreamWriter(outFile, false, Encoding.UTF8);

                csvWriter = new CsvWriter(swCsv, CultureInfo.InvariantCulture);

                var foo = csvWriter.Context.AutoMap <TimelineProvider>();
                foo.Map(t => t.Timestamp).Convert(t =>
                                                  $"{t.Value.Timestamp:yyyy-MM-dd HH:mm:ss}");
                foo.Map(t => t.EndTime).Convert(t =>
                                                $"{t.Value.EndTime.ToString(dt)}");

                csvWriter.Context.RegisterClassMap(foo);
                csvWriter.WriteHeader <TimelineProvider>();
                csvWriter.NextRecord();

                csvWriter.WriteRecords(sr.TimelineProviders.Values);

                csvWriter.Flush();
                swCsv.Flush();
            }
            catch (Exception e)
            {
                Log.Error(e, "Error exporting 'Unknown312' data! Error: {Message}", e.Message);
            }

            try
            {
                Log.Debug("Dumping Unknown D8F table '{TableName}'", Vfuprov.TableName);

                outName = $"{ts:yyyyMMddHHmmss}_SrumECmd_UnknownD8F_Output.csv";

                outFile = Path.Combine(csv, outName);

                swCsv = new StreamWriter(outFile, false, Encoding.UTF8);

                csvWriter = new CsvWriter(swCsv, CultureInfo.InvariantCulture);

                var foo = csvWriter.Context.AutoMap <Vfuprov>();
                foo.Map(t => t.Timestamp).Convert(t =>
                                                  $"{t.Value.Timestamp:yyyy-MM-dd HH:mm:ss}");
                foo.Map(t => t.EndTime).Convert(t =>
                                                $"{t.Value.EndTime.ToString(dt)}");
                foo.Map(t => t.StartTime).Convert(t =>
                                                  $"{t.Value.StartTime.ToString(dt)}");

                csvWriter.Context.RegisterClassMap(foo);
                csvWriter.WriteHeader <Vfuprov>();
                csvWriter.NextRecord();

                csvWriter.WriteRecords(sr.Vfuprovs.Values);

                csvWriter.Flush();
                swCsv.Flush();
            }
            catch (Exception e)
            {
                Log.Error(e, "Error exporting 'UnknownD8F' data! Error: {Message}", e.Message);
            }

            try
            {
                Log.Debug("Dumping App Resource Use Info table '{TableName}'", AppResourceUseInfo.TableName);

                outName = $"{ts:yyyyMMddHHmmss}_SrumECmd_AppResourceUseInfo_Output.csv";

                outFile = Path.Combine(csv, outName);

                swCsv = new StreamWriter(outFile, false, Encoding.UTF8);

                csvWriter = new CsvWriter(swCsv, CultureInfo.InvariantCulture);

                var foo = csvWriter.Context.AutoMap <AppResourceUseInfo>();
                foo.Map(t => t.Timestamp).Convert(t =>
                                                  $"{t.Value.Timestamp:yyyy-MM-dd HH:mm:ss}");

                csvWriter.Context.RegisterClassMap(foo);
                csvWriter.WriteHeader <AppResourceUseInfo>();
                csvWriter.NextRecord();

                csvWriter.WriteRecords(sr.AppResourceUseInfos.Values);

                csvWriter.Flush();
                swCsv.Flush();
            }
            catch (Exception e)
            {
                Log.Error(e, "Error exporting 'AppResourceUseInfo' data! Error: {Message}", e.Message);
            }

            try
            {
                Log.Debug("Dumping Network Connection table '{TableName}'", NetworkConnection.TableName);

                outName = $"{ts:yyyyMMddHHmmss}_SrumECmd_NetworkConnections_Output.csv";

                outFile = Path.Combine(csv, outName);

                swCsv = new StreamWriter(outFile, false, Encoding.UTF8);

                csvWriter = new CsvWriter(swCsv, CultureInfo.InvariantCulture);

                var foo = csvWriter.Context.AutoMap <NetworkConnection>();
                foo.Map(t => t.Timestamp).Convert(t =>
                                                  $"{t.Value.Timestamp:yyyy-MM-dd HH:mm:ss}");
                foo.Map(t => t.ConnectStartTime).Convert(t =>
                                                         $"{t.Value.ConnectStartTime.ToString(dt)}");

                csvWriter.Context.RegisterClassMap(foo);
                csvWriter.WriteHeader <NetworkConnection>();
                csvWriter.NextRecord();

                csvWriter.WriteRecords(sr.NetworkConnections.Values);

                csvWriter.Flush();
                swCsv.Flush();
            }
            catch (Exception e)
            {
                Log.Error(e, "Error exporting 'NetworkConnection' data! Error: {Message}", e.Message);
            }

            try
            {
                Log.Debug("Dumping Network Usage table '{TableName}'", NetworkUsage.TableName);

                outName = $"{ts:yyyyMMddHHmmss}_SrumECmd_NetworkUsages_Output.csv";

                outFile = Path.Combine(csv, outName);

                swCsv = new StreamWriter(outFile, false, Encoding.UTF8);

                csvWriter = new CsvWriter(swCsv, CultureInfo.InvariantCulture);

                var foo = csvWriter.Context.AutoMap <NetworkUsage>();
                foo.Map(t => t.Timestamp).Convert(t =>
                                                  $"{t.Value.Timestamp:yyyy-MM-dd HH:mm:ss}");

                csvWriter.Context.RegisterClassMap(foo);
                csvWriter.WriteHeader <NetworkUsage>();
                csvWriter.NextRecord();

                csvWriter.WriteRecords(sr.NetworkUsages.Values);

                csvWriter.Flush();
                swCsv.Flush();
            }
            catch (Exception e)
            {
                Log.Error(e, "Error exporting 'NetworkUsage' data! Error: {Message}", e.Message);
            }

            try
            {
                Log.Debug("Dumping Push Notification table '{TableName}'", PushNotification.TableName);

                outName = $"{ts:yyyyMMddHHmmss}_SrumECmd_PushNotifications_Output.csv";

                outFile = Path.Combine(csv, outName);

                swCsv = new StreamWriter(outFile, false, Encoding.UTF8);

                csvWriter = new CsvWriter(swCsv, CultureInfo.InvariantCulture);

                var foo = csvWriter.Context.AutoMap <PushNotification>();
                foo.Map(t => t.Timestamp).Convert(t =>
                                                  $"{t.Value.Timestamp:yyyy-MM-dd HH:mm:ss}");

                csvWriter.Context.RegisterClassMap(foo);
                csvWriter.WriteHeader <PushNotification>();
                csvWriter.NextRecord();

                csvWriter.WriteRecords(sr.PushNotifications.Values);

                csvWriter.Flush();
                swCsv.Flush();
            }
            catch (Exception e)
            {
                Log.Error(e, "Error exporting 'PushNotification' data! Error: {Message}", e.Message);
            }

            sw.Stop();

            Log.Information("Processing completed in {TotalSeconds:N4} seconds\r\n", sw.Elapsed.TotalSeconds);
        }
    }
 public static long CountFileSystemObjects(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options)
 {
    return EnumerateFileSystemEntryInfosInternal<string>(transaction, path, searchPattern, options, PathFormat.RelativePath).Count();
 }
 public long CountFileSystemObjects(DirectoryEnumerationOptions options)
 {
    return Directory.EnumerateFileSystemEntryInfosInternal<string>(Transaction, LongFullName, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath).Count();
 }
 public static long CountFileSystemObjects(string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
 {
    return EnumerateFileSystemEntryInfosInternal<string>(null, path, searchPattern, options, pathFormat).Count();
 }
        public static IEnumerable <string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
        {
            // Adhere to the method name.
            options &= ~DirectoryEnumerationOptions.Files;
            options |= DirectoryEnumerationOptions.Folders;

            return(EnumerateFileSystemEntryInfosCore <string>(transaction, path, Path.WildcardStarMatchAll, options, PathFormat.RelativePath));
        }
Beispiel #28
0
 public static IEnumerable <T> EnumerateFileSystemEntryInfosTransacted <T>(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
 {
     return(EnumerateFileSystemEntryInfosCore <T>(transaction, path, searchPattern, options, pathFormat));
 }
Beispiel #29
0
 public static Dictionary <string, long> GetProperties(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
 {
     return(GetPropertiesInternal(transaction, path, options, PathFormat.RelativePath));
 }
        public static IEnumerable <string> EnumerateDirectories(string path, string searchPattern, DirectoryEnumerationOptions options)
        {
            // Adhere to the method name.
            options &= ~DirectoryEnumerationOptions.Files;
            options |= DirectoryEnumerationOptions.Folders;

            return(EnumerateFileSystemEntryInfosCore <string>(null, path, searchPattern, options, PathFormat.RelativePath));
        }
Beispiel #31
0
        internal static IEnumerable <T> EnumerateFileSystemEntryInfosCore <T>(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
        {
            // Enable BasicSearch and LargeCache by default.
            options |= DirectoryEnumerationOptions.BasicSearch | DirectoryEnumerationOptions.LargeCache;

            return(new FindFileSystemEntryInfo(true, transaction, path, searchPattern, options, typeof(T), pathFormat).Enumerate <T>());
        }
        public static IEnumerable <string> EnumerateDirectoriesTransacted(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
        {
            // Adhere to the method name.
            options &= ~DirectoryEnumerationOptions.Files;
            options |= DirectoryEnumerationOptions.Folders;

            return(EnumerateFileSystemEntryInfosCore <string>(transaction, path, searchPattern, options, pathFormat));
        }
        internal static Dictionary <string, long> GetPropertiesCore(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
        {
            long total = 0;
            long size  = 0;

            const string propFile  = "File";
            const string propTotal = "Total";
            const string propSize  = "Size";

            var typeOfAttrs = typeof(FileAttributes);
            var attributes  = Enum.GetValues(typeOfAttrs);
            var props       = Enum.GetNames(typeOfAttrs).OrderBy(attrs => attrs).ToDictionary <string, string, long>(name => name, name => 0);
            var pathLp      = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);

            foreach (var fsei in EnumerateFileSystemEntryInfosCore <FileSystemEntryInfo>(transaction, pathLp, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath))
            {
                total++;

                if (!fsei.IsDirectory)
                {
                    size += fsei.FileSize;
                }

                var fsei1 = fsei;

                foreach (var attributeMarker in attributes.Cast <FileAttributes>().Where(attributeMarker => (fsei1.Attributes & attributeMarker) != 0))
                {
                    props[((attributeMarker & FileAttributes.Directory) != 0 ? FileAttributes.Directory : attributeMarker).ToString()]++;
                }
            }

            // Adjust regular files count.
            props.Add(propFile, total - props[FileAttributes.Directory.ToString()] - props[FileAttributes.ReparsePoint.ToString()]);
            props.Add(propTotal, total);
            props.Add(propSize, size);

            return(props);
        }
Beispiel #34
0
        internal static Dictionary <string, long> GetPropertiesInternal(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
        {
            const string propFile           = "File";
            const string propTotal          = "Total";
            const string propSize           = "Size";
            long         total              = 0;
            long         size               = 0;
            Type         typeOfAttrs        = typeof(FileAttributes);
            Array        attributes         = Enum.GetValues(typeOfAttrs);
            Dictionary <string, long> props = Enum.GetNames(typeOfAttrs).OrderBy(attrs => attrs).ToDictionary <string, string, long>(name => name, name => 0);

            string pathLp = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);

            foreach (FileSystemEntryInfo fsei in EnumerateFileSystemEntryInfosInternal <FileSystemEntryInfo>(transaction, pathLp, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath))
            {
                total++;

                if (!fsei.IsDirectory)
                {
                    size += fsei.FileSize;
                }

                foreach (FileAttributes attributeMarker in attributes)
                {
                    // Marker exists in flags.
                    if ((fsei.Attributes & attributeMarker) == attributeMarker)
                    {
                        // Regular directory that will go to stack, adding directory flag ++
                        props[(((attributeMarker & FileAttributes.Directory) == FileAttributes.Directory) ? FileAttributes.Directory : attributeMarker).ToString()]++;
                    }
                }
            }

            // Adjust regular files count.
            props.Add(propFile, total - props[FileAttributes.Directory.ToString()] - props[FileAttributes.ReparsePoint.ToString()]);
            props.Add(propTotal, total);
            props.Add(propSize, size);

            return(props);
        }
Beispiel #35
0
 public void Compress(DirectoryEnumerationOptions options)
 {
     Directory.CompressDecompressInternal(Transaction, LongFullName, Path.WildcardStarMatchAll, options, true, PathFormat.LongFullPath);
 }
Beispiel #36
0
 public static void Compress(string path, DirectoryEnumerationOptions options, DirectoryEnumerationFilters filters)
 {
     CompressDecompressCore(null, path, Path.WildcardStarMatchAll, options, filters, true, PathFormat.RelativePath);
 }
 public static Dictionary <string, long> GetProperties(string path, DirectoryEnumerationOptions options)
 {
     return(GetPropertiesCore(null, path, options, PathFormat.RelativePath));
 }
Beispiel #38
0
 public static void CompressTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, DirectoryEnumerationFilters filters, PathFormat pathFormat)
 {
     CompressDecompressCore(transaction, path, Path.WildcardStarMatchAll, options, filters, true, pathFormat);
 }
 public static Dictionary <string, long> GetPropertiesTransacted(KernelTransaction transaction, string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
 {
     return(GetPropertiesCore(transaction, path, options, pathFormat));
 }
Beispiel #40
0
 public long CountFileSystemObjects(DirectoryEnumerationOptions options)
 {
     return(Directory.EnumerateFileSystemEntryInfosCore <string>(Transaction, LongFullName, Path.WildcardStarMatchAll, options, PathFormat.LongFullPath).Count());
 }
 public IEnumerable <FileInfo> EnumerateFiles(DirectoryEnumerationOptions options)
 {
     return(Directory.EnumerateFileSystemEntryInfosCore <FileInfo>(false, Transaction, LongFullName, Path.WildcardStarMatchAll, null, options, null, PathFormat.LongFullPath));
 }
 public IEnumerable <FileInfo> EnumerateFiles(string searchPattern, DirectoryEnumerationOptions options)
 {
     return(Directory.EnumerateFileSystemEntryInfosCore <FileInfo>(false, Transaction, LongFullName, searchPattern, null, options, null, PathFormat.LongFullPath));
 }
 public void Decompress(DirectoryEnumerationOptions options)
 {
     Directory.CompressDecompressCore(Transaction, LongFullName, Path.WildcardStarMatchAll, options, false, PathFormat.LongFullPath);
 }
        public FindFileSystemEntryInfo(bool isFolder, KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, Type typeOfT, PathFormat pathFormat)
        {
            Transaction = transaction;

            OriginalInputPath = path;
            InputPath         = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);
            IsRelativePath    = !Path.IsPathRooted(OriginalInputPath, false);

            // .NET behaviour.
            SearchPattern = searchPattern.TrimEnd(Path.TrimEndChars);

            FileSystemObjectType = null;

            ContinueOnException = (options & DirectoryEnumerationOptions.ContinueOnException) != 0;

            AsLongPath = (options & DirectoryEnumerationOptions.AsLongPath) != 0;

            AsString         = typeOfT == typeof(string);
            AsFileSystemInfo = !AsString && (typeOfT == typeof(FileSystemInfo) || typeOfT.BaseType == typeof(FileSystemInfo));

            FindExInfoLevel = NativeMethods.IsAtLeastWindows7 && (options & DirectoryEnumerationOptions.BasicSearch) != 0
            ? NativeMethods.FINDEX_INFO_LEVELS.Basic
            : NativeMethods.FINDEX_INFO_LEVELS.Standard;

            LargeCache = NativeMethods.IsAtLeastWindows7 && (options & DirectoryEnumerationOptions.LargeCache) != 0
            ? NativeMethods.FindExAdditionalFlags.LargeFetch
            : NativeMethods.FindExAdditionalFlags.None;

            IsDirectory = isFolder;

            if (IsDirectory)
            {
                // Need files or folders to enumerate.
                if ((options & DirectoryEnumerationOptions.FilesAndFolders) == DirectoryEnumerationOptions.None)
                {
                    options |= DirectoryEnumerationOptions.FilesAndFolders;
                }

                FileSystemObjectType = (options & DirectoryEnumerationOptions.FilesAndFolders) == DirectoryEnumerationOptions.FilesAndFolders
               ? (bool?)null
               : (options & DirectoryEnumerationOptions.Folders) != 0;

                Recursive = (options & DirectoryEnumerationOptions.Recursive) != 0;

                SkipReparsePoints = (options & DirectoryEnumerationOptions.SkipReparsePoints) != 0;
            }
        }
 public static Dictionary<string, long> GetProperties(KernelTransaction transaction, string path, DirectoryEnumerationOptions options)
 {
    return GetPropertiesInternal(transaction, path, options, PathFormat.RelativePath);
 }