Пример #1
0
        public void SyncFolder(SourceFolder sourceFolder, GoogleFolder remoteFolder)
        {
            if (sourceFolder.Files != null)
            {
                foreach (var file in sourceFolder.Files)
                {
                    if (!_googleDriveService.DoesFileExistInFolder(remoteFolder, file.FileName))
                    {
                        try
                        {
                            var remoteFile = _googleDriveService.UploadFile(remoteFolder, file.FileName, file.FullLocation, file.MimeType);
                            _log.Info("File {0} uploaded, google id: {1}", file.FullLocation, remoteFile.Id);
                        }
                        catch (Exception ex)
                        {
                            _log.Error(ex);
                        }
                    }
                    else
                    {
                        _log.Info("File {0} already exists", file.FullLocation);
                    }
                }
            }
            if (sourceFolder.Folders != null)
            {
                foreach (var childFolder in sourceFolder.Folders)
                {
                    if (_googleDriveService.DoesFolderExistInFolder(remoteFolder, childFolder.FolderName))
                    {
                        try
                        {
                            var childRemoteFolder = _googleDriveService.CreateFolder(remoteFolder, childFolder.FolderName);
                            _log.Info("Folder {0} created, google id: {1}", childFolder.FullLocation, childRemoteFolder.Id);

                            SyncFolder(childFolder, childRemoteFolder);
                        }
                        catch (Exception ex)
                        {
                            _log.Error(ex);
                        }
                    }
                    else
                    {
                        _log.Info("Folder {0} already exists", childFolder.FullLocation);
                    }
                }
            }
        }