private static string ToJSON(this BCPlaylist playlist, JSONType t) { //--Build Playlist in JSON -------------------------------------// Builder jsonPlaylist = new Builder(",", "{", "}"); //id if (t.Equals(JSONType.Update)) { jsonPlaylist.AppendObject("id", playlist.id.ToString()); } //name if (!string.IsNullOrEmpty(playlist.name)) { jsonPlaylist.AppendField("name", playlist.name); } //referenceId if (!string.IsNullOrEmpty(playlist.referenceId)) { jsonPlaylist.AppendField("referenceId", playlist.referenceId); } //playlist type jsonPlaylist.AppendField("playlistType", playlist.playlistType.ToString()); if (t.Equals(JSONType.Create)) { //Video Ids should be a list of strings if (playlist.videoIds != null && playlist.videoIds.Count > 0) { IEnumerable <string> values = from val in playlist.videoIds select val.ToString(); jsonPlaylist.AppendObjectArray("videoIds", values); } } //filter tags should be a list of strings if (playlist.filterTags != null && playlist.filterTags.Count > 0) { jsonPlaylist.AppendStringArray("filterTags", playlist.filterTags); } //shortDescription if (!string.IsNullOrEmpty(playlist.shortDescription)) { jsonPlaylist.AppendField("shortDescription", playlist.shortDescription); } //tagInclusionRule if (!string.IsNullOrEmpty(playlist.tagInclusionRule)) { jsonPlaylist.AppendField("tagInclusionRule", playlist.tagInclusionRule); } return(jsonPlaylist.ToString()); }
private static string ToJSON(this BCPlaylist playlist, JSONType t) { //--Build Playlist in JSON -------------------------------------// StringBuilder jsonPlaylist = new StringBuilder(); //id if (t.Equals(JSONType.Update)) { jsonPlaylist.Append("\"id\": " + playlist.id.ToString()); } //name if (!string.IsNullOrEmpty(playlist.name)) { if (jsonPlaylist.Length > 0) { jsonPlaylist.Append(","); } jsonPlaylist.Append("\"name\": \"" + playlist.name + "\""); } //referenceId if (!string.IsNullOrEmpty(playlist.referenceId)) { if (jsonPlaylist.Length > 0) { jsonPlaylist.Append(","); } jsonPlaylist.Append("\"referenceId\": \"" + playlist.referenceId + "\""); } //thumbnailURL if (!string.IsNullOrEmpty(playlist.thumbnailURL)) { if (jsonPlaylist.Length > 0) { jsonPlaylist.Append(","); } jsonPlaylist.Append("\"thumbnailURL\": \"" + playlist.thumbnailURL + "\""); } //playlist type if (jsonPlaylist.Length > 0) { jsonPlaylist.Append(","); } jsonPlaylist.Append("\"playlistType\": \"" + playlist.playlistType.ToString() + "\""); if (t.Equals(JSONType.Create) || t.Equals(JSONType.Update)) { //Video Ids should be a list of strings if (playlist.videoIds != null && playlist.videoIds.Count > 0) { if (jsonPlaylist.Length > 0) { jsonPlaylist.Append(","); } jsonPlaylist.Append("\"videoIds\": ["); string append = ""; foreach (long id in playlist.videoIds) { jsonPlaylist.Append(append + "" + id.ToString() + ""); append = ","; } jsonPlaylist.Append("]"); } } //filter tags should be a list of strings if (playlist.filterTags != null && playlist.filterTags.Count > 0) { if (jsonPlaylist.Length > 0) { jsonPlaylist.Append(","); } jsonPlaylist.Append("\"filterTags\": ["); string append = ""; foreach (string tag in playlist.filterTags) { jsonPlaylist.Append(append + "\"" + tag + "\""); append = ","; } jsonPlaylist.Append("]"); } //shortDescription if (!string.IsNullOrEmpty(playlist.shortDescription)) { if (jsonPlaylist.Length > 0) { jsonPlaylist.Append(","); } jsonPlaylist.Append("\"shortDescription\": \"" + playlist.shortDescription + "\""); } return("{" + jsonPlaylist.ToString() + "}"); }
private static string ToJSON(this BCVideo video, JSONType type) { //--Build Video in JSON -------------------------------------// StringBuilder jsonVideo = new StringBuilder(); jsonVideo.Append("{"); if (type.Equals(JSONType.Update)) { //id jsonVideo.Append("\"id\": " + video.id.ToString() + ","); } //name if (!string.IsNullOrEmpty(video.name)) { jsonVideo.Append("\"name\": \"" + video.name + "\""); } //shortDescription if (!string.IsNullOrEmpty(video.shortDescription)) { jsonVideo.Append(",\"shortDescription\": \"" + video.shortDescription + "\""); } //Tags should be a list of strings if (video.tags.Count > 0) { jsonVideo.Append(",\"tags\": ["); string append = ""; foreach (string tag in video.tags) { jsonVideo.Append(append + "\"" + tag + "\""); append = ","; } jsonVideo.Append("]"); } // Custom Fields should be a list of strings if (video.customFields.Values.Count > 0) { jsonVideo.Append(",\"customFields\": {"); string append = ""; foreach (string key in video.customFields.Values.Keys) { jsonVideo.Append(append + "\"" + key + "\": \"" + video.customFields.Values[key] + "\""); append = ","; } jsonVideo.Append("}"); } //referenceId if (!string.IsNullOrEmpty(video.referenceId)) { jsonVideo.Append(",\"referenceId\": \"" + video.referenceId + "\""); } //longDescription if (!string.IsNullOrEmpty(video.longDescription)) { jsonVideo.Append(",\"longDescription\": \"" + video.longDescription + "\""); } if (!string.IsNullOrEmpty(video.linkText)) { jsonVideo.Append(",\"linkText\": \"" + video.linkText + "\""); } if (!string.IsNullOrEmpty(video.linkURL)) { jsonVideo.Append(",\"linkURL\": \"" + video.linkURL + "\""); } if (!string.IsNullOrEmpty(video.thumbnailURL)) { jsonVideo.Append(",\"thumbnailURL\": \"" + video.thumbnailURL + "\""); } if (!string.IsNullOrEmpty(video.videoStillURL)) { jsonVideo.Append(",\"videoStillURL\": \"" + video.videoStillURL + "\""); } if (video.cuePoints.Count > 0) { jsonVideo.Append(",\"cuePoints\": " + video.cuePoints.ToJSON()); } //economics jsonVideo.Append(",\"economics\": \"" + video.economics.ToString() + "\""); // Start Date jsonVideo.Append(",\"startDate\": "); if (string.IsNullOrEmpty(video.startDate)) { jsonVideo.Append("null"); } else { jsonVideo.Append("\"" + video.startDate + "\""); } // End Date jsonVideo.Append(",\"endDate\": "); if (string.IsNullOrEmpty(video.endDate)) { jsonVideo.Append("null"); } else { jsonVideo.Append("\"" + video.endDate + "\""); } jsonVideo.Append("}"); return(jsonVideo.ToString()); }
private static string ToJSON(this BCVideo video, JSONType type) { //--Build Video in JSON -------------------------------------// Builder jsonVideo = new Builder(",", "{", "}"); //id if (type.Equals(JSONType.Update)) { jsonVideo.AppendObject("id", video.id); } //referenceId if (!string.IsNullOrEmpty(video.referenceId)) { jsonVideo.AppendField("referenceId", video.referenceId); } //name if (!string.IsNullOrEmpty(video.name)) { jsonVideo.AppendField("name", video.name); } //shortDescription if (!string.IsNullOrEmpty(video.shortDescription)) { jsonVideo.AppendField("shortDescription", video.shortDescription); } //longDescription if (!string.IsNullOrEmpty(video.longDescription)) { jsonVideo.AppendField("longDescription", video.longDescription); } //Tags should be a list of strings if (video.tags.Count > 0) { jsonVideo.AppendStringArray("tags", video.tags); } //videoStillURL if (!string.IsNullOrEmpty(video.videoStillURL)) { jsonVideo.AppendField("videoStillURL", HttpUtility.UrlEncode(video.videoStillURL)); } //thumbnailURL if (!string.IsNullOrEmpty(video.thumbnailURL)) { jsonVideo.AppendField("thumbnailURL", HttpUtility.UrlEncode(video.thumbnailURL)); } if (video.cuePoints.Count > 0) { jsonVideo.AppendObject("cuePoints", video.cuePoints.ToJSON()); } if (video.renditions.Count > 0) { jsonVideo.AppendObject("renditions", video.renditions.ToJSON()); } if (!string.IsNullOrEmpty(video.videoFullLength.url) || !string.IsNullOrEmpty(video.videoFullLength.remoteUrl)) { jsonVideo.AppendObject("videoFullLength", video.videoFullLength.ToJSON()); } if (video.customFields.Values.Count > 0) { jsonVideo.AppendDictionaryArray("customFields", video.customFields.Values); } //startdate if (video.startDate != null) { jsonVideo.AppendField("startDate", BCObject.DateToUnix(video.startDate.Value)); } //enddate if (video.endDate != null) { jsonVideo.AppendField("endDate", BCObject.DateToUnix(video.endDate.Value)); } //economics jsonVideo.AppendObject("economics", video.economics.ToString()); if (video.iosRenditions.Count > 0) { jsonVideo.AppendObject("iosRenditions", video.iosRenditions.ToJSON()); } //remoteURL if (!string.IsNullOrEmpty(video.HLSURL)) { jsonVideo.AppendField("HLSURL", HttpUtility.UrlEncode(video.HLSURL)); } //adKeys if (!string.IsNullOrEmpty(video.adKeys)) { jsonVideo.AppendField("adKeys", HttpUtility.UrlEncode(video.adKeys)); } return(jsonVideo.ToString()); }