コード例 #1
0
        public static Snapshot ToSnapshot(this JSnapshot jSnapshot)
        {
            if (jSnapshot == null)
            {
                throw new ArgumentNullException(nameof(jSnapshot));
            }

            Snapshot snapshot = new()
            {
                Id           = jSnapshot.Id,
                OriginalPath = jSnapshot.OriginalPath,
                CreationTime = jSnapshot.CreationTime
            };

            IEnumerable <HDirectory> directories = jSnapshot.GetHDirectories();

            if (directories != null)
            {
                snapshot.Directories.AddRange(directories);
            }

            IEnumerable <HFile> files = jSnapshot.GetHFiles();

            if (files != null)
            {
                snapshot.Files.AddRange(files);
            }

            return(snapshot);
        }
コード例 #2
0
        public Snapshot ReadSnapshot(string filePath)
        {
            using StreamReader streamReader     = File.OpenText(filePath);
            using JsonTextReader jsonTextReader = new(streamReader);

            JsonSerializer serializer = new();
            JSnapshot      jSnapshot  = (JSnapshot)serializer.Deserialize(jsonTextReader, typeof(JSnapshot));

            return(jSnapshot.ToSnapshot());
        }
コード例 #3
0
        public void Open()
        {
            if (!File.Exists(filePath))
            {
                return;
            }

            using StreamReader streamReader     = File.OpenText(filePath);
            using JsonTextReader jsonTextReader = new(streamReader);

            JsonSerializer serializer = new();

            Snapshot = (JSnapshot)serializer.Deserialize(jsonTextReader, typeof(JSnapshot));
        }
コード例 #4
0
 private static IEnumerable <HFile> GetHFiles(this JSnapshot jSnapshot)
 {
     return(jSnapshot.Files?
            .Select(x => x.ToHFile())
            .ToList());
 }
コード例 #5
0
 private static IEnumerable <HDirectory> GetHDirectories(this JSnapshot jSnapshot)
 {
     return(jSnapshot.Directories?
            .Select(x => x.ToHDirectory())
            .ToList());
 }