public async Task UpdateOneEmbed(SaasafrasGoogleDriveService saasyDrive, Embed embed, List <Embed> embeds, string subfolderId, Podio podio, RoutedPodioEvent e) { try { var id = saasyDrive.GetFileId(embed.OriginalUrl); var original = await saasyDrive.GetFileMicro(id, "name, parents"); if (original.Parents == null) { original.Parents = new List <string>(); } Console.WriteLine($"{e.podioEvent.item_id} - Old File ID: {original.Id}, Name: {original.Name}"); original.Parents.Clear(); original.Parents.Add(subfolderId); original.Name = e.environmentId + " " + original.Name; var clone = await saasyDrive.CopyFile(id); var permissionsAdded = await saasyDrive.SetPermissions(id, "writer", "anyone"); await Task.Run(() => { var embedServ = new EmbedService(podio);; Console.WriteLine($"{e.podioEvent.item_id} - CloneID: {clone.Id}"); //runs 130x approx var waitSeconds = 5; CallPodio: Embed em; try { em = embedServ.AddAnEmbed(clone.WebViewLink).Result; } catch (PodioUnavailableException ex) { Console.WriteLine($"{ex.Message}"); Console.WriteLine($"Trying again in {waitSeconds} seconds."); for (var i = 0; i < waitSeconds; i++) { System.Threading.Thread.Sleep(1000); Console.WriteLine("."); } waitSeconds *= 2; goto CallPodio; } //Console.WriteLine($"{e.podioEvent.item_id} - WebViewLink: {clone.WebViewLink}"); embeds.Add(em); }); } catch (Exception ex) { Console.WriteLine($"{e.podioEvent.item_id} - {ex.Message} - {ex.StackTrace} - {ex.InnerException}"); } }
public async System.Threading.Tasks.Task UpdateOneEmbed(DriveService ds, Embed embed, List <Embed> embeds, string subfolderId, Podio podio, RoutedPodioEvent e) { try { //Console.WriteLine($"{e.podioEvent.item_id} - Old Embed Link (resolved): {embed.ResolvedUrl}"); var id = GetDriveId(embed.OriginalUrl, e); var original = GetFileByTitle(ds, id, e); if (original.Parents == null) { original.Parents = new List <string>(); } Console.WriteLine($"{e.podioEvent.item_id} -Old File ID: {original.Id}, Name: {original.Name}"); original.Parents.Clear(); original.Parents.Add(subfolderId); original.Name = e.environmentId + " " + original.Name; var clone = ds.Files.Copy(original, id).Execute(); await Task.Run(() => { var p = new Permission { Role = "writer", Type = "anyone" }; new PermissionsResource.CreateRequest(ds, p, clone.Id).Execute(); }); await Task.Run(() => { var embedServ = new EmbedService(podio);; Console.WriteLine($"{e.podioEvent.item_id} - CloneID: {clone.Id}"); var req = ds.Files.Get(clone.Id); req.Fields = "webViewLink"; clone = req.Execute(); //runs 130x approx var waitSeconds = 5; CallPodio: Embed em; try { em = embedServ.AddAnEmbed(clone.WebViewLink).Result; } catch (PodioUnavailableException ex) { Console.WriteLine($"{ex.Message}"); Console.WriteLine($"Trying again in {waitSeconds} seconds."); for (var i = 0; i < waitSeconds; i++) { System.Threading.Thread.Sleep(1000); Console.WriteLine("."); } waitSeconds = waitSeconds * 2; goto CallPodio; } //Console.WriteLine($"{e.podioEvent.item_id} - WebViewLink: {clone.WebViewLink}"); embeds.Add(em); }); } catch (Exception ex) { Console.WriteLine($"{e.podioEvent.item_id} - {ex.Message} - {ex.StackTrace} - {ex.InnerException}"); } }