public static async Task GenerateCards(SkillResult result, dynamic boxBody) { var boxConfig = new BoxConfig(string.Empty, string.Empty, new Uri(config.BoxApiUrl)); var session = new OAuthSession(boxBody.token.write.access_token.Value, string.Empty, 3600, "bearer"); var client = new BoxClient(boxConfig, session); if (client == null) { throw new Exception("Unable to create box client"); } Console.WriteLine("======== BoxHelper Result ========="); Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.None)); var cards = new List <Dictionary <string, object> > { GenerateSupportHeaderCard(result, boxBody), GenerateScoreKeywordCard(result, boxBody), GenerateTopicsKeywordCard(result, boxBody), GenerateScriptAdherenceKeywordCard(result, boxBody), GenerateTranscriptCard(result, boxBody) }; cards.AddRange(GeneateSentimentTimelineCards(result, boxBody)); Console.WriteLine("======== Cards ========="); Console.WriteLine(JsonConvert.SerializeObject(cards, Formatting.None)); var skillsMetadata = new Dictionary <string, object>() { { "cards", cards } }; try { await client.MetadataManager.CreateFileMetadataAsync(boxBody.source.id.Value, skillsMetadata, "global", "boxSkillsCards"); Console.WriteLine("Created metadata"); } catch (Exception e) { Console.WriteLine("Exception creating metadata. Trying update"); Console.WriteLine(e); BoxMetadataUpdate updateObj = new BoxMetadataUpdate { Op = MetadataUpdateOp.replace, Path = "/cards", Value = cards }; try { await client.MetadataManager.UpdateFileMetadataAsync(boxBody.source.id.Value, new List <BoxMetadataUpdate>() { updateObj }, "global", "boxSkillsCards"); } catch (Exception e2) { Console.WriteLine("Exception updating metadata. giving up"); Console.WriteLine(e2); return; } Console.WriteLine("Successfully updated metadata"); } }
public async Task Metadata_File_CRUD_LiveSession() { const string FILE_ID = "16894937607"; //create metadata var md = new Dictionary <string, object>() { { "attr1", ATTR1 }, { "attr2", ATTR2 }, { "attr3", ATTR3 }, { "attr4", ATTR4 } }; var createdMD = await _client.MetadataManager.CreateFileMetadataAsync(FILE_ID, md, SCOPE, TEMPLATE_KEY); Assert.IsTrue(createdMD.Keys.Contains("attr1"), "Failed to correctly create file metadata"); //get metadata var fetchedMD = await _client.MetadataManager.GetFileMetadataAsync(FILE_ID, SCOPE, TEMPLATE_KEY); Assert.IsTrue(fetchedMD.Keys.Contains("attr1"), "Failed to correctly fetch file metadata"); //update metadata var update = new BoxMetadataUpdate() { Op = MetadataUpdateOp.copy, Path = "/attr1", From = "/attr4" }; var update2 = new BoxMetadataUpdate() { Op = MetadataUpdateOp.replace, Path = "/attr4", Value = "value2" }; var update3 = new BoxMetadataUpdate() { Op = MetadataUpdateOp.replace, Path = "/attr2", Value = 2 }; // Int update var updatedMD = await _client.MetadataManager.UpdateFileMetadataAsync(FILE_ID, new List <BoxMetadataUpdate>() { update, update2, update3 }, SCOPE, TEMPLATE_KEY); Assert.AreEqual(ATTR4, updatedMD["attr1"], "Failed to update metadata on file"); Assert.AreEqual("value2", updatedMD["attr4"], "Failed to update metadata on file"); Assert.AreEqual(Convert.ToInt64(2), updatedMD["attr2"], "Failed to update metadata on file"); //get all file metadata var allMD = await _client.MetadataManager.GetAllFileMetadataTemplatesAsync(FILE_ID); Assert.AreEqual(1, allMD.Entries.Count, "Failed to get all file metadata"); //delete metadata var result = await _client.MetadataManager.DeleteFileMetadataAsync(FILE_ID, SCOPE, TEMPLATE_KEY); Assert.IsTrue(result, "Failed to delete file metadata"); }
private List <BoxMetadataUpdate> ProcessMetadataUpdate() { var updates = new List <BoxMetadataUpdate>(); var update = new BoxMetadataUpdate(); if (this._add.HasValue()) { update.Op = MetadataUpdateOp.add; } else if (this._copy.HasValue()) { update.Op = MetadataUpdateOp.copy; } else if (this._move.HasValue()) { update.Op = MetadataUpdateOp.move; } else if (this._remove.HasValue()) { update.Op = MetadataUpdateOp.remove; } else if (this._replace.HasValue()) { update.Op = MetadataUpdateOp.replace; } else if (this._test.HasValue()) { update.Op = MetadataUpdateOp.test; } else { throw new Exception("You must select an op for this command"); } update.Path = this._path.Value(); update.From = this._from.Value(); if (this._isFloat.HasValue()) { update.Value = Decimal.Parse(this._value.Value()); } else { update.Value = this._value.Value(); } updates.Add(update); return(updates); }
// fileId comes from boxBody.source.id.Value // writeToken comes from boxBody.token.write.access_token.Value public static async Task UpdateSkillCards(List <Dictionary <string, object> > cards, string writeToken, string fileId) { var boxConfig = new BoxConfig(string.Empty, string.Empty, new Uri(config.BoxSdkUrl)); var session = new OAuthSession(writeToken, string.Empty, 3600, "bearer"); var client = new BoxClient(boxConfig, session); if (client == null) { throw new Exception("Unable to create box client"); } var skillsMetadata = new Dictionary <string, object>() { { "cards", cards } }; //TODO: first load then merge (so it's an update and not replacement off all that's there) try { Console.WriteLine("--------------------- Cards --------------"); Console.WriteLine(JsonConvert.SerializeObject(skillsMetadata, Formatting.None)); await client.MetadataManager.CreateFileMetadataAsync(fileId, skillsMetadata, "global", "boxSkillsCards"); Console.WriteLine("Created metadata"); } catch (Exception e) { Console.WriteLine("Exception creating metadata. Trying update"); Console.WriteLine(e); BoxMetadataUpdate updateObj = new BoxMetadataUpdate { Op = MetadataUpdateOp.replace, Path = "/cards", Value = cards }; try { await client.MetadataManager.UpdateFileMetadataAsync(fileId, new List <BoxMetadataUpdate>() { updateObj }, "global", "boxSkillsCards"); } catch (Exception e2) { Console.WriteLine("Exception updating metadata. giving up"); Console.WriteLine(e2); return; } Console.WriteLine("Successfully updated metadata"); } }