예제 #1
0
        public static DriveItem MemberwiseClone(this DriveItem driveItem)
        {
            Dictionary <string, object> additionalData = null;
            ItemReference parentReference = null;

            Microsoft.Graph.FileSystemInfo fileSystemInfo = null;
            Hashes hashes = null;

            if (driveItem.AdditionalData != null)
            {
                additionalData = new Dictionary <string, object>()
                {
                    [CryptoDriveConstants.DownloadUrl] = driveItem.AdditionalData[CryptoDriveConstants.DownloadUrl]
                }
            }
            ;

            if (driveItem.ParentReference != null)
            {
                parentReference = new ItemReference()
                {
                    Path = driveItem.ParentReference.Path
                }
            }
            ;

            if (driveItem.FileSystemInfo != null)
            {
                fileSystemInfo = new Microsoft.Graph.FileSystemInfo()
                {
                    CreatedDateTime      = driveItem.FileSystemInfo.CreatedDateTime,
                    LastAccessedDateTime = driveItem.FileSystemInfo.LastAccessedDateTime,
                    LastModifiedDateTime = driveItem.FileSystemInfo.LastModifiedDateTime
                };
            }

            if (driveItem.File?.Hashes != null)
            {
                hashes = new Hashes()
                {
                    QuickXorHash = driveItem.QuickXorHash()
                };
            }

            return(new DriveItem()
            {
                AdditionalData = additionalData,
                Content = driveItem.Content,
                Deleted = driveItem.Deleted == null ? null : new Deleted(),
                File = driveItem.File == null ? null : new Microsoft.Graph.File()
                {
                    Hashes = hashes
                },
                Folder = driveItem.Folder == null ? null : new Folder(),
                Id = driveItem.Id,
                Name = driveItem.Name,
                ParentReference = parentReference,
                RemoteItem = driveItem.RemoteItem == null ? null : new RemoteItem(),
                Size = driveItem.Size,
                FileSystemInfo = fileSystemInfo,
            });
        }
예제 #2
0
        // from remote state to drive item and vice versa
        public static RemoteState ToRemoteState(this DriveItem driveItem)
        {
            var type = driveItem.Type();

            return(new RemoteState()
            {
                Path = driveItem.ParentReference.Path.Substring(CryptoDriveConstants.PathPrefix.Length),
                Id = driveItem.Id,
                Name = driveItem.Name,
                LastModified = driveItem.FileSystemInfo.LastModifiedDateTime.Value.UtcDateTime,
                QuickXorHash = type == DriveItemType.File && driveItem.File.Hashes != null?driveItem.QuickXorHash() : null,
                                   Size = type == DriveItemType.File ? driveItem.Size.Value : 0,
                                   Type = type
            });
        }