예제 #1
0
        private void LoadImage(VM_EventLogRecord eventLogRecord, String dir)
        {
            String snapshotFile = System.IO.Path.Combine(dir, $"{eventLogRecord.EventId}.json");

            if (File.Exists(snapshotFile))
            {
                using (StreamReader file = File.OpenText(snapshotFile))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    Snapshot       eventImg   = (Snapshot)serializer.Deserialize(file, typeof(Snapshot));
                    eventLogRecord.EventSnapshotId = eventImg.Id;
                }
                return;
            }
            ;
            Snapshot snapshot = null;
            var      response = Client.GetSnapshot(logId: eventLogRecord.EventId)?.Items;

            if (response == null || response.Count == 0)
            {
                snapshot = new Snapshot
                {
                    Date             = eventLogRecord.EventTime,
                    EventLogRecordId = eventLogRecord.EventId,
                    File             = null,
                    Id       = 0,
                    MimeType = null,
                    Name     = null
                };
                eventLogRecord.EventSnapshotId = snapshot.Id;
            }
            else
            {
                eventLogRecord.EventSnapshotId = -1;
                snapshot = response.First();
                snapshot.EventLogRecordId = eventLogRecord.EventId;
            }

            using (StreamWriter stream = File.CreateText(snapshotFile))
            {
                JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()
                {
                    Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore
                });
                serializer.Serialize(stream, snapshot);
            }
        }
예제 #2
0
        private void Part_DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Part_EventSnapshotImg.Source        = null;
            Part_EventSnapshotImg.Visibility    = Visibility.Collapsed;
            Part_ImagePlaceholderLbl.Visibility = Visibility.Visible;

            VM_EventLogRecord selectedRecord = Part_DataGrid.SelectedItem as VM_EventLogRecord;

            if (selectedRecord == null)
            {
                return;
            }
            String pathToImageFile = System.IO.Path.Combine(AppConfig.FolderPathOf.RootStorageFolder, AppConfig.FolderPathOf.SnapshotsFolder, $"{selectedRecord.EventId}.json");

            if (File.Exists(pathToImageFile))
            {
                Snapshot eventSnapshot = null;
                using (StreamReader file = File.OpenText(pathToImageFile))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    eventSnapshot = (Snapshot)serializer.Deserialize(file, typeof(Snapshot));
                }
                String imageInBase64 = eventSnapshot.File;
                if (String.IsNullOrEmpty(imageInBase64))
                {
                    return;
                }
                using (MemoryStream stream = FromBase64(imageInBase64))
                {
                    BitmapImage img = ToBitmapImage(stream);
                    Part_EventSnapshotImg.Source = img;
                    if (LargeSnapshotWindow != null)
                    {
                        LargeSnapshotWindow.Part_SnapshotImg.Source = img;
                    }
                }
            }
            Part_EventSnapshotImg.Visibility    = Visibility.Visible;
            Part_ImagePlaceholderLbl.Visibility = Visibility.Collapsed;
        }