Пример #1
0
        public static DriveItem ToDriveItem(this string relativePath, DriveItemType driveItemType)
        {
            var itemName   = Path.GetFileName(relativePath);
            var folderPath = Path.GetDirectoryName(relativePath).NormalizeSlashes();

            if (driveItemType == DriveItemType.RemoteItem)
            {
                throw new NotSupportedException();
            }

            var driveItem = new DriveItem()
            {
                File            = driveItemType == DriveItemType.File ? new Microsoft.Graph.File() : null,
                Folder          = driveItemType == DriveItemType.Folder ? new Folder() : null,
                Name            = itemName,
                ParentReference = new ItemReference()
                {
                    Path = $"{CryptoDriveConstants.PathPrefix}{folderPath}"
                }
            };

            driveItem.Id = driveItem.GetItemPath();

            return(driveItem);
        }
Пример #2
0
        // from x to drive item
        public static DriveItem ToDriveItem(this FileSystemEventArgs fileSystemEventArgs, string basePath)
        {
            var fileInfo = new FileInfo(fileSystemEventArgs.FullPath);

            if (fileSystemEventArgs.ChangeType == WatcherChangeTypes.Deleted)
            {
                var relativePath = fileSystemEventArgs.FullPath.Substring(basePath.Length);
                var fileName     = Path.GetFileName(relativePath);
                var folderPath   = Path.GetDirectoryName(relativePath).NormalizeSlashes();

                var driveItem = new DriveItem()
                {
                    Deleted        = new Deleted(),
                    File           = new Microsoft.Graph.File(),
                    FileSystemInfo = new Microsoft.Graph.FileSystemInfo()
                    {
                        LastModifiedDateTime = DateTime.UtcNow
                    },
                    Name            = fileName,
                    ParentReference = new ItemReference()
                    {
                        Path = $"{CryptoDriveConstants.PathPrefix}{folderPath}",
                    },
                    Size = 0
                };

                driveItem.Id = driveItem.GetItemPath();

                return(driveItem);
            }
            else
            {
                return(fileInfo.ToDriveItem(basePath));
            }
        }
Пример #3
0
        // properties
        public static WatcherChangeTypes GetChangeType(this DriveItem newDriveItem, DriveItem oldDriveItem = null)
        {
            if (oldDriveItem == null)
            {
                return(WatcherChangeTypes.Created);
            }

            if (newDriveItem.Deleted != null)
            {
                return(WatcherChangeTypes.Deleted);
            }

            else if (oldDriveItem.Id != newDriveItem.Id)
            {
                throw new ArgumentException();
            }

            else if (oldDriveItem.GetItemPath() != newDriveItem.GetItemPath())
            {
                return(WatcherChangeTypes.Renamed);
            }

            else if (newDriveItem.Type() == DriveItemType.File &&
                     (oldDriveItem.LastModified() != newDriveItem.LastModified() ||
                      oldDriveItem.Size != newDriveItem.Size))
            {
                return(WatcherChangeTypes.Changed);
            }

            // no change
            else
            {
                return(0);
            }
        }
Пример #4
0
        public static DriveItem ToDriveItem(this FileInfo fileInfo, string basePath)
        {
            var fileName   = fileInfo.Name;
            var folderPath = fileInfo.DirectoryName.Substring(basePath.Length).NormalizeSlashes();

            var driveItem = new DriveItem()
            {
                AdditionalData = new Dictionary <string, object>()
                {
                    [CryptoDriveConstants.DownloadUrl] = new Uri(fileInfo.FullName),
                },
                File           = new Microsoft.Graph.File(),
                FileSystemInfo = new Microsoft.Graph.FileSystemInfo()
                {
                    LastModifiedDateTime = fileInfo.LastWriteTimeUtc
                },
                Name            = fileName,
                ParentReference = new ItemReference()
                {
                    Path = $"{CryptoDriveConstants.PathPrefix}{folderPath}"
                },
                Size = fileInfo.Length
            };

            driveItem.Id = driveItem.GetItemPath();

            return(driveItem);
        }
Пример #5
0
        public static DriveItem ToDriveItem(this DirectoryInfo folderInfo, string basePath)
        {
            var folderName = folderInfo.Name;
            var folderPath = folderInfo.Parent.FullName.Substring(basePath.Length).NormalizeSlashes();

            var driveItem = new DriveItem()
            {
                FileSystemInfo = new Microsoft.Graph.FileSystemInfo()
                {
                    LastModifiedDateTime = folderInfo.LastWriteTimeUtc
                },
                Folder          = new Folder(),
                Id              = folderInfo.Name,
                Name            = folderName,
                ParentReference = new ItemReference()
                {
                    Path = $"{CryptoDriveConstants.PathPrefix}{folderPath}"
                }
            };

            driveItem.Id = driveItem.GetItemPath();

            return(driveItem);
        }
Пример #6
0
 public static string GetAbsolutePath(this DriveItem driveItem, string basePath)
 {
     return(driveItem.GetItemPath().ToAbsolutePath(basePath));
 }