public void UpdateEverythingAsync() { // Arrange Folder actual = null; const string newDescription = "new description"; var folder = Client.CreateFolder(RootId, TestItemName(), null); var newParent = Client.CreateFolder(RootId, TestItemName(), null); var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions { CanDownload = true, CanPreview = true }); var newName = TestItemName(); // Act folder.Name = newName; folder.Description = newDescription; folder.Parent.Id = newParent.Id; folder.SharedLink = sharedLink; Client.Update(updatedFolder => actual = updatedFolder, AbortOnFailure, folder, null); AssertActionComplete(ref actual); Client.Delete(folder, true); Client.Delete(newParent, true); AssertFolderConstraints(actual, newName, newParent.Id, folder.Id); AssertSharedLink(sharedLink, actual.SharedLink); Assert.That(actual.Description, Is.EqualTo(newDescription)); }
public void UpdateEverything() { string fileName = TestItemName(); File file = Client.CreateFile(RootId, fileName); string newDescription = "new description"; string newFolder = TestItemName(); Folder folder = Client.CreateFolder(RootId, newFolder, null); var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions { CanDownload = true, CanPreview = true }); string newName = TestItemName(); // Act try { file.Parent.Id = folder.Id; file.Description = newDescription; file.Name = newName; file.SharedLink = sharedLink; File updatedFile = Client.Update(file); // Assert AssertFileConstraints(updatedFile, newName, folder.Id, file.Id); AssertSharedLink(sharedLink, file.SharedLink); Assert.That(updatedFile.Description, Is.EqualTo(newDescription)); } finally { Client.Delete(folder, true); } }
public void UpdateAsync() { // Arrange File actual = null; File file = Client.CreateFile(RootId, TestItemName()); const string newDescription = "new description"; Folder folder = Client.CreateFolder(RootId, TestItemName(), null); var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions { CanDownload = true, CanPreview = true }); string newName = TestItemName(); // Act file.Name = newName; file.Description = newDescription; file.Parent.Id = folder.Id; file.SharedLink = sharedLink; Client.Update(updatedFile => { actual = updatedFile; }, AbortOnFailure, file, null); AssertActionComplete(ref actual); Client.Delete(folder, recursive: true); AssertFileConstraints(actual, newName, folder.Id, file.Id); AssertSharedLink(sharedLink, actual.SharedLink); Assert.That(actual.Description, Is.EqualTo(newDescription)); }
public void UpdateEverything() { var folder = Client.CreateFolder(RootId, TestItemName(), null); var newDescription = "new description"; var newParent = Client.CreateFolder(RootId, TestItemName(), null); var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions { CanDownload = true, CanPreview = true }); var newName = TestItemName(); // Act try { folder.Parent.Id = newParent.Id; folder.Description = newDescription; folder.Name = newName; folder.SharedLink = sharedLink; var updatedFolder = Client.Update(folder); // Assert AssertFolderConstraints(updatedFolder, newName, newParent.Id, folder.Id); AssertSharedLink(sharedLink, folder.SharedLink); Assert.That(updatedFolder.Description, Is.EqualTo(newDescription)); } finally { Client.Delete(newParent, true); } }
public async Task <int> IterateReviewsCount() { pgsbar.Visible = true; Core it = new Core(); using (var dbx = new DropboxClient(it._key)) { var sharedLink = new SharedLink("derm"); var sharedFiles = await dbx.Files.ListFolderAsync("", true); foreach (var file in sharedFiles.Entries) { ListBoxItem st = new ListBoxItem(); if (file.PathDisplay.EndsWith(".rev") && file.Name != "derm" && file.Name.StartsWith(Path.GetFileName(GrabRECNAME).Replace(".derm", ""))) { Regex word = new Regex(@"(.*)-(\d+?).rev"); Match m = word.Match(file.Name); if (!lstrev.Contains(int.Parse(m.Groups[2].Value))) { lstrev.Add(int.Parse(m.Groups[2].Value)); } } } pgsbar.Visible = false; return(lstrev.Count != 0 ? lstrev.LastOrDefault() : 0); } }
public async Task <bool> Insert(SharedLink sharedLink) { await _context.ShareResourceLinks.AddAsync(sharedLink.ToModel()).ConfigureAwait(false); await _context.SaveChangesAsync().ConfigureAwait(false); return(true); }
public Task <bool> Insert(SharedLink sharedLink) { _sharedLinks.Add(new SharedLink { ConfirmationCode = sharedLink.ConfirmationCode, ResourceId = sharedLink.ResourceId, Scopes = sharedLink.Scopes }); return(Task.FromResult(true)); }
public void CreateSharedLink() { var folderName = TestItemName(); var folder = Client.CreateFolder(RootId, folderName, null); var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions { CanPreview = true, CanDownload = true }); var update = Client.ShareLink(folder, sharedLink); AssertFolderConstraints(update, folderName, RootId, folder.Id); AssertSharedLink(update.SharedLink, sharedLink); Client.Delete(update, true); }
public void ShareLinkAccessOnly() { string fileName = TestItemName(); File file = Client.CreateFile(RootId, fileName); // Act var expectedLink = new SharedLink(Access.Open); File linkedFile = Client.ShareLink(file, expectedLink); Client.Delete(linkedFile); // Assert AssertFileConstraints(linkedFile, file.Name, RootId, file.Id); AssertSharedLink(linkedFile.SharedLink, expectedLink); }
public void ShareLink() { string fileName = TestItemName(); File file = Client.CreateFile(RootId, fileName); // Act var expectedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions { CanDownload = true, CanPreview = true }); File linkedFile = Client.ShareLink(file, expectedLink); Client.Delete(linkedFile); // Assert AssertFileConstraints(linkedFile, file.Name, RootId, file.Id); AssertSharedLink(linkedFile.SharedLink, expectedLink); }
public async Task <string> Execute(ShareResourceParameter shareResourceParameter) { if (shareResourceParameter == null) { throw new ArgumentNullException(nameof(shareResourceParameter)); } if (string.IsNullOrWhiteSpace(shareResourceParameter.ResourceId)) { throw new BaseUmaException(Errors.ErrorCodes.InvalidRequestCode, Errors.ErrorDescriptions.TheResourceIdMustBeSpecified); } if (shareResourceParameter.Scopes == null) { throw new BaseUmaException(Errors.ErrorCodes.InvalidRequestCode, Errors.ErrorDescriptions.TheScopesMustBeSpecified); } var resource = await _resourceSetRepository.Get(shareResourceParameter.ResourceId).ConfigureAwait(false); if (resource == null) { throw new UmaResourceNotFoundException(); } if (!shareResourceParameter.Scopes.All(s => resource.Scopes.Contains(s))) { throw new BaseUmaException(Errors.ErrorCodes.InvalidRequestCode, Errors.ErrorDescriptions.TheScopeAreNotValid); } if (resource.Owner != shareResourceParameter.Owner) { throw new UmaNotAuthorizedException(); } var sharedLink = new SharedLink { ConfirmationCode = Guid.NewGuid().ToString(), ResourceId = resource.Id, Scopes = shareResourceParameter.Scopes }; if (!await _sharedLinkRepository.Insert(sharedLink)) { throw new BaseUmaException(Errors.ErrorCodes.InternalError, Errors.ErrorDescriptions.TheSharedLinkCannotBeInserted); } return(sharedLink.ConfirmationCode); }
public void ShareFolderLinkAsync() { Folder actual = null; var folderName = TestItemName(); var folder = Client.CreateFolder(RootId, folderName, null); var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions { CanPreview = true, CanDownload = true }); Client.ShareFolderLink(copiedFolder => actual = copiedFolder, AbortOnFailure, folder.Id, sharedLink, null); AssertActionComplete(ref actual); Client.Delete(folder, true); AssertFolderConstraints(actual, folderName, RootId); AssertSharedLink(actual.SharedLink, sharedLink); }
public void ShareLinkMustHaveSomePermissions() { string fileName = TestItemName(); File file = Client.CreateFile(RootId, fileName); // Act var expectedLink = new SharedLink(Access.Open, permissions: new Permissions() { CanDownload = false, CanPreview = false }); File linkedFile = Client.ShareLink(file, expectedLink); Client.Delete(linkedFile); // Assert AssertFileConstraints(linkedFile, file.Name, RootId, file.Id); AssertSharedLink(linkedFile.SharedLink, expectedLink); }
public void ShareFileLinkAsync() { // Arrange File actual = null; File file = Client.CreateFile(RootId, TestItemName()); var expectedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions { CanDownload = true, CanPreview = true }); // Act Client.ShareLink(sharedFile => { actual = sharedFile; }, AbortOnFailure, file, expectedLink, null); AssertActionComplete(ref actual); Client.Delete(actual); AssertFileConstraints(actual, file.Name, RootId, file.Id); AssertSharedLink(actual.SharedLink, expectedLink); }
protected static void AssertSharedLink(SharedLink actual, SharedLink sharedLink) { if (sharedLink == null) { Assert.That(actual, Is.Null); return; } Assert.That(actual, Is.Not.Null); Assert.That(actual.Access, Is.EqualTo(sharedLink.Access)); Assert.That(actual.UnsharedAt.HasValue, Is.EqualTo(sharedLink.UnsharedAt.HasValue)); if (actual.UnsharedAt.HasValue) { Assert.That(actual.UnsharedAt, Is.GreaterThan(DateTime.MinValue)); Assert.That(actual.UnsharedAt, Is.LessThan(DateTime.MaxValue)); } Assert.That(actual.Permissions.CanDownload, Is.EqualTo(sharedLink.Permissions.CanDownload)); Assert.That(actual.Permissions.CanPreview, Is.EqualTo(sharedLink.Permissions.CanPreview)); }
/// <summary> /// Adds a new shared link. /// </summary> public async Task <SharedLink> AddSharedLink(Folder folder = null, int[] tagIds = null, SearchScope?mode = null, string dateFrom = null, string dateTo = null, string key = null) { var link = new SharedLink { Key = key ?? UniqueKey.Get(), CreationDate = DateTime.Now, Folder = folder, DateFrom = dateFrom, DateTo = dateTo, Scope = mode ?? SearchScope.CurrentFolder, Tags = tagIds?.JoinString(",") }; _db.SharedLinks.Add(link); await _db.SaveChangesAsync(); return(link); }
public async Task <bool> IsRecExists(string recname) { using (var dbx = new DropboxClient(_key)) { var sharedLink = new SharedLink("/derm"); var sharedFiles = await dbx.Files.ListFolderAsync(sharedLink.Url); foreach (var file in sharedFiles.Entries) { if (file.Name == recname) { _RepExists = true; MessageBox.Show("Replay already exists! Please rename your replay."); break; } } } return(_RepExists ? true : false); }
public async Task <int> CheckRevs(string recname) { Core it = new Core(); using (var dbx = new DropboxClient(it._key)) { var sharedLink = new SharedLink("derm"); var sharedFiles = await dbx.Files.ListFolderAsync("", true); foreach (var file in sharedFiles.Entries) { if (file.Name.StartsWith(recname) && file.PathDisplay.EndsWith(".rev") && file.Name != "derm") { } } } return(0); }
/// <summary> /// Creates a new shared link. /// </summary> public async Task <KeyResultVM> CreateAsync(SharedLinkVM vm) { await ValidateAsync(vm); var folderPath = PathHelper.Normalize(vm.Folder); var folder = await _db.Folders.GetAsync(x => x.Path == folderPath, $"Folder '{vm.Folder}' does not exist."); var link = new SharedLink { Key = UniqueKey.Get(), CreationDate = DateTime.Now, Folder = folder, }; _mapper.Map(vm, link); _db.SharedLinks.Add(link); await _db.SaveChangesAsync(); return(new KeyResultVM { Key = link.Key }); }
public void DisableSharedLink() { var folderName = TestItemName(); var folder = Client.CreateFolder(RootId, folderName, null); Folder actual = null; try { var sharedLink = new SharedLink(Access.Open, DateTime.UtcNow.AddDays(3), new Permissions { CanPreview = true, CanDownload = true }); var update = Client.ShareLink(folder, sharedLink); AssertSharedLink(update.SharedLink, sharedLink); actual = Client.DisableSharedLink(update); AssertSharedLink(actual.SharedLink, null); } finally { if (actual != null) { Client.Delete(actual, true); } } }
public JsonNetResult UpdateEvaluationSharedLink(string period, string username, SharedLink sharedLink) { ExecuteCommand(new UpdateEvaluationSharedLink(period, username, sharedLink)); return(Json(null)); }
public UpdateEvaluationSharedLink(string period, string userName, SharedLink sharedLink) { _period = period; _userName = userName; _sharedLink = sharedLink; }
public IRestRequest Update <TField>(ResourceType resourceResourceType, string id, string etag, IEnumerable <TField> fields, string parentId = null, string name = null, string description = null, SharedLink sharedLink = null, string message = null) where TField : IField { IRestRequest request = JsonRequest(resourceResourceType, "{id}", Method.PUT, fields); request.AddUrlSegment("id", id.Trim()); TryAddIfMatchHeader(request, etag); var body = new Dictionary <string, object>(); TryAddToBody(body, "parent", Massage(parentId), new { id = Massage(parentId) }); TryAddToBody(body, "name", Massage(name)); TryAddToBody(body, "description", Massage(description)); TryAddToBody(body, "shared_link", sharedLink); TryAddToBody(body, "message", Massage(message)); request.AddBody(body); return(request); }
private async Task <int> Run() { DropboxCertHelper.InitializeCertPinning(); string[] scopeList = new string[] { "files.metadata.read", "files.content.read", "account_info.read", "sharing.read" }; var uid = await AcquireAccessToken(scopeList, IncludeGrantedScopes.None); if (string.IsNullOrEmpty(uid)) { return(1); } // Specify socket level timeout which decides maximum waiting time when no bytes are received by the socket. var httpClient = new HttpClient(new WebRequestHandler { ReadWriteTimeout = 10 * 1000 }) { // Specify request level timeout which decides maximum time that can be spent on download/upload files. Timeout = TimeSpan.FromMinutes(20) }; try { var config = new DropboxClientConfig("SimpleOAuthApp") { HttpClient = httpClient }; var client = new DropboxClient(Settings.Default.AccessToken, Settings.Default.RefreshToken, Settings.Default.ApiKey, Settings.Default.ApiSecret, config); var scopes = new string[] { "files.metadata.read", "files.content.read", "sharing.read" }; await client.RefreshAccessToken(scopes); if (Settings.Default.SharedLinks == null || Settings.Default.SharedLinks.Count == 0) { Settings.Default.SharedLinks = new System.Collections.Specialized.StringCollection(); Console.Write("Shared link URL: "); var line = Console.ReadLine(); while (line.Length > 0) { Settings.Default.SharedLinks.Add(line); Console.Write("Additional shared link URL (leave blank to finish): "); line = Console.ReadLine(); } Settings.Default.Save(); } var sharedLinks = Settings.Default.SharedLinks; foreach (var sharedLinkUrl in sharedLinks) { GetSharedLinkMetadataArg arg = new GetSharedLinkMetadataArg(sharedLinkUrl); var sharedLinkMetaData = await client.Sharing.GetSharedLinkMetadataAsync(arg); var localDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), sharedLinkMetaData.Name); Directory.CreateDirectory(localDir); Console.WriteLine($"Processing shared link name: {sharedLinkMetaData.Name}"); if (Verbose) { Console.WriteLine($"Shared link local folder: {localDir}"); } SharedLink sharedLink = new SharedLink(sharedLinkUrl); ListFolderArg listFolderArg = new ListFolderArg(path: "", sharedLink: sharedLink); var listFiles = await client.Files.ListFolderAsync(listFolderArg); foreach (var listFile in listFiles.Entries) { try { if (Verbose) { Console.WriteLine($"Processing: {listFile.Name}"); } // Get the remote object details var remoteFile = listFile.AsFile; // Construct a reference to the local equivalent var localFile = Path.Combine(localDir, listFile.Name); if (Verbose) { Console.WriteLine($" Local filename: {localFile}"); } // Do we have a file already if (File.Exists(localFile)) { if (Verbose) { Console.WriteLine($" Local file exists. Comparing timestamp"); } var localTimestamp = File.GetLastWriteTimeUtc(localFile); if (Verbose) { Console.WriteLine($" Checking {remoteFile.ServerModified} with {localTimestamp}"); } if (DateTime.Compare(remoteFile.ServerModified, localTimestamp) == 0) { if (Verbose) { Console.WriteLine($" Skipping unchanged file: {listFile.Name}"); } continue; } } GetSharedLinkMetadataArg downloadArg = new GetSharedLinkMetadataArg(sharedLinkUrl, $"/{listFile.Name}"); if (Verbose) { Console.WriteLine($"SharedLinkUrl: {sharedLinkUrl}"); Console.WriteLine($" File Name: {listFile.Name}"); } var download = await client.Sharing.GetSharedLinkFileAsync(downloadArg); Console.WriteLine($" Downloading: {remoteFile.Name}"); using (var ms = new MemoryStream()) { var bytes = await download.GetContentAsByteArrayAsync(); if (bytes.Length > 0) { File.WriteAllBytes(localFile, bytes.ToArray()); File.SetCreationTimeUtc(localFile, remoteFile.ServerModified); File.SetLastWriteTimeUtc(localFile, remoteFile.ServerModified); } else { Console.Error.WriteLine($"No bytes downloaded"); } } } catch (Exception ex) { Console.Error.WriteLine($"Failed during download: ${ex.Message}"); } } if (Verbose) { Console.WriteLine("Download complete!"); } } if (Verbose) { Console.WriteLine("All downloads complete!"); } if (PromptToExit) { Console.WriteLine("Exit with any key"); Console.ReadKey(); } } catch (HttpException e) { Console.WriteLine("Exception reported from RPC layer"); Console.WriteLine(" Status code: {0}", e.StatusCode); Console.WriteLine(" Message : {0}", e.Message); if (e.RequestUri != null) { Console.WriteLine(" Request uri: {0}", e.RequestUri); } } return(0); }
public JsonNetResult DeleteEvaluationSharedLink(string period, string username, SharedLink sharedLink) { ExecuteCommand(new DeleteEvaluationSharedLink(period, username, sharedLink)); return(Json("OK")); }