//-------------------------------------------------------------------------
 public StatisticsController(
     StatisticsDialog parentForm,
     BusinessLogic businessLogic)
 {
     _parentForm    = parentForm;
     _businessLogic = businessLogic;
 }
        //--------------------------------------------------------------------------
        public void MoreStats()
        {
            StatisticsDialog stats = new StatisticsDialog(_businessLogic);

            stats.ShowDialog();
        }
Exemple #3
0
        public StatisticsViewModel(StatisticsDialog view)
        {
            _view         = view;
            Filters       = new ObservableCollection <NameCountModel>();
            Formats       = new ObservableCollection <NameCountModel>();
            Partitions    = new ObservableCollection <NameCountModel>();
            Filesystems   = new ObservableCollection <NameCountModel>();
            Devices       = new ObservableCollection <DeviceStatsModel>();
            Medias        = new ObservableCollection <MediaStatsModel>();
            CloseCommand  = ReactiveCommand.Create(ExecuteCloseCommand);
            using var ctx = AaruContext.Create(Settings.Settings.LocalDbPath);

            if (ctx.Commands.Any())
            {
                if (ctx.Commands.Any(c => c.Name == "analyze"))
                {
                    foreach (Command oldAnalyze in ctx.Commands.Where(c => c.Name == "analyze"))
                    {
                        oldAnalyze.Name = "fs-info";
                        ctx.Commands.Update(oldAnalyze);
                    }

                    ulong count = 0;

                    foreach (Command fsInfo in ctx.Commands.Where(c => c.Name == "fs-info" && c.Synchronized))
                    {
                        count += fsInfo.Count;
                        ctx.Remove(fsInfo);
                    }

                    if (count > 0)
                    {
                        ctx.Commands.Add(new Command
                        {
                            Count        = count,
                            Name         = "fs-info",
                            Synchronized = true
                        });
                    }

                    ctx.SaveChanges();
                }

                if (ctx.Commands.Any(c => c.Name == "fs-info"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "fs-info" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "fs-info" && !c.Synchronized);

                    FsInfoVisible = true;
                    FsInfoText    = $"You have called the Filesystem Info command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "checksum"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "checksum" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "checksum" && !c.Synchronized);

                    ChecksumVisible = true;
                    ChecksumText    = $"You have called the Checksum command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "compare"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "compare" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "compare" && !c.Synchronized);

                    CompareVisible = true;
                    CompareText    = $"You have called the Compare command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "convert-image"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "convert-image" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "convert-image" && !c.Synchronized);

                    ConvertImageVisible = true;
                    ConvertImageText    = $"You have called the Convert-Image command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "create-sidecar"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "create-sidecar" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "create-sidecar" && !c.Synchronized);

                    CreateSidecarVisible = true;
                    CreateSidecarText    = $"You have called the Create-Sidecar command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "decode"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "decode" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "decode" && !c.Synchronized);

                    DecodeVisible = true;
                    DecodeText    = $"You have called the Decode command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "device-info"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "device-info" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "device-info" && !c.Synchronized);

                    DeviceInfoVisible = true;
                    DeviceInfoText    = $"You have called the Device-Info command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "device-report"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "device-report" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "device-report" && !c.Synchronized);

                    DeviceReportVisible = true;
                    DeviceReportText    = $"You have called the Device-Report command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "dump-media"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "dump-media" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "dump-media" && !c.Synchronized);

                    DumpMediaVisible = true;
                    DumpMediaText    = $"You have called the Dump-Media command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "entropy"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "entropy" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "entropy" && !c.Synchronized);

                    EntropyVisible = true;
                    EntropyText    = $"You have called the Entropy command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "formats"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "formats" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "formats" && !c.Synchronized);

                    FormatsCommandVisible = true;
                    FormatsCommandText    = $"You have called the Formats command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "image-info"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "image-info" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "image-info" && !c.Synchronized);

                    ImageInfoVisible = true;
                    ImageInfoText    = $"You have called the Image-Info command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "media-info"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "media-info" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "media-info" && !c.Synchronized);

                    MediaInfoVisible = true;
                    MediaInfoText    = $"You have called the Media-Info command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "media-scan"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "media-scan" && c.Synchronized).
                                  Select(c => c.Count).FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "media-scan" && !c.Synchronized);

                    MediaScanVisible = true;
                    MediaScanText    = $"You have called the Media-Scan command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "printhex"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "printhex" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "printhex" && !c.Synchronized);

                    PrintHexVisible = true;
                    PrintHexText    = $"You have called the Print-Hex command {count} times";
                }

                if (ctx.Commands.Any(c => c.Name == "verify"))
                {
                    ulong count = ctx.Commands.Where(c => c.Name == "verify" && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Commands.LongCount(c => c.Name == "verify" && !c.Synchronized);

                    VerifyVisible = true;
                    VerifyText    = $"You have called the Verify command {count} times";
                }

                CommandsVisible = FsInfoVisible || ChecksumVisible || CompareVisible || ConvertImageVisible ||
                                  CreateSidecarVisible || DecodeVisible || DeviceInfoVisible || DeviceReportVisible ||
                                  DumpMediaVisible || EntropyVisible || FormatsCommandVisible || ImageInfoVisible ||
                                  MediaInfoVisible || MediaScanVisible || PrintHexVisible || VerifyVisible;
            }

            if (ctx.Filters.Any())
            {
                FiltersVisible = true;

                foreach (string nvs in ctx.Filters.Select(n => n.Name).Distinct())
                {
                    ulong count = ctx.Filters.Where(c => c.Name == nvs && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Filters.LongCount(c => c.Name == nvs && !c.Synchronized);

                    Filters.Add(new NameCountModel
                    {
                        Name  = nvs,
                        Count = count
                    });
                }
            }

            if (ctx.MediaFormats.Any())
            {
                FormatsVisible = true;

                foreach (string nvs in ctx.MediaFormats.Select(n => n.Name).Distinct())
                {
                    ulong count = ctx.MediaFormats.Where(c => c.Name == nvs && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.MediaFormats.LongCount(c => c.Name == nvs && !c.Synchronized);

                    Formats.Add(new NameCountModel
                    {
                        Name  = nvs,
                        Count = count
                    });
                }
            }

            if (ctx.Partitions.Any())
            {
                PartitionsVisible = true;

                foreach (string nvs in ctx.Partitions.Select(n => n.Name).Distinct())
                {
                    ulong count = ctx.Partitions.Where(c => c.Name == nvs && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Partitions.LongCount(c => c.Name == nvs && !c.Synchronized);

                    Partitions.Add(new NameCountModel
                    {
                        Name  = nvs,
                        Count = count
                    });
                }
            }

            if (ctx.Filesystems.Any())
            {
                FilesystemsVisible = true;

                foreach (string nvs in ctx.Filesystems.Select(n => n.Name).Distinct())
                {
                    ulong count = ctx.Filesystems.Where(c => c.Name == nvs && c.Synchronized).Select(c => c.Count).
                                  FirstOrDefault();

                    count += (ulong)ctx.Filesystems.LongCount(c => c.Name == nvs && !c.Synchronized);

                    Filesystems.Add(new NameCountModel
                    {
                        Name  = nvs,
                        Count = count
                    });
                }
            }

            if (ctx.SeenDevices.Any())
            {
                DevicesVisible = true;

                foreach (DeviceStat ds in ctx.SeenDevices.OrderBy(n => n.Manufacturer).ThenBy(n => n.Manufacturer).
                         ThenBy(n => n.Revision).ThenBy(n => n.Bus))
                {
                    Devices.Add(new DeviceStatsModel
                    {
                        Model        = ds.Model,
                        Manufacturer = ds.Manufacturer,
                        Revision     = ds.Revision,
                        Bus          = ds.Bus
                    });
                }
            }

            if (!ctx.Medias.Any())
            {
                return;
            }

            MediasVisible = true;

            foreach (string media in ctx.Medias.OrderBy(ms => ms.Type).Select(ms => ms.Type).Distinct())
            {
                ulong count = ctx.Medias.Where(c => c.Type == media && c.Synchronized && c.Real).Select(c => c.Count).
                              FirstOrDefault();

                count += (ulong)ctx.Medias.LongCount(c => c.Type == media && !c.Synchronized && c.Real);

                if (count > 0)
                {
                    Medias.Add(new MediaStatsModel
                    {
                        Name  = media,
                        Count = count,
                        Type  = "real"
                    });
                }

                count = ctx.Medias.Where(c => c.Type == media && c.Synchronized && !c.Real).Select(c => c.Count).
                        FirstOrDefault();

                count += (ulong)ctx.Medias.LongCount(c => c.Type == media && !c.Synchronized && !c.Real);

                if (count == 0)
                {
                    continue;
                }

                Medias.Add(new MediaStatsModel
                {
                    Name  = media,
                    Count = count,
                    Type  = "image"
                });
            }
        }
Exemple #4
0
        private void Statistics_Click(object sender, EventArgs e)
        {
            StatisticsDialog statistics = new StatisticsDialog();

            statistics.ShowDialog();
        }