public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jo = JObject.Load(reader); var schema = JsonConvert.DeserializeObject<Schema>(jo.ToString(), GetSettings(serializer)); var requiredList = new List<string>(); //Per JSON schema 4.0, each node uses the "IsRequired" field (an array) to call out mandatory properties. var requiredProperties = new JArray(schema.Required); foreach (var requiredProperty in requiredProperties) { requiredList.Add((string) requiredProperty); } schema.Required = requiredList; if (schema.Properties != null) { foreach (var key in schema.Properties.Keys) { Schema value = schema.Properties[key]; bool inRequiredList = (requiredProperties.FirstOrDefault(p => (string) p == key) != null); value.IsRequired = inRequiredList; } } return schema; }
/// <summary> /// Is this a child build job. If so return the ID of the parent job and base url /// </summary> internal static bool IsChildJob(JArray actions, out string baseUrl, out int parentBuildId) { baseUrl = null; parentBuildId = 0; var obj = actions.FirstOrDefault(x => x["causes"] != null); if (obj == null) { return false; } var array = (JArray)obj["causes"]; if (array.Count == 0) { return false; } var data = array[0]; baseUrl = data.Value<string>("upstreamUrl"); parentBuildId = data.Value<int>("upstreamBuild"); return baseUrl != null && parentBuildId != 0; }
private void Merge(JArray result, JObject outputEntry) { var existing = result.FirstOrDefault(x => this.tableOps.IsPrimaryKeyEqual(outputEntry.AsDictionary(), ((JObject) x).AsDictionary())); if (existing != null) { existing.Replace(outputEntry); } else { result.Add(outputEntry); } }
internal static bool TryParsePullRequestInfo(JArray actions, out PullRequestInfo info) { var container = actions.FirstOrDefault(x => x["parameters"] != null); if (container == null) { info = null; return false; } string sha1 = null; string pullLink = null; int? pullId = null; string pullAuthor = null; string pullAuthorEmail = null; string commitAuthorEmail = null; var parameters = (JArray)container["parameters"]; foreach (var pair in parameters) { switch (pair.Value<string>("name")) { case "ghprbActualCommit": sha1 = pair.Value<string>("value") ?? sha1; break; case "ghprbPullId": pullId = pair.Value<int>("value"); break; case "ghprbPullAuthorLogin": pullAuthor = pair.Value<string>("value") ?? pullAuthor; break; case "ghprbPullAuthorEmail": pullAuthorEmail = pair.Value<string>("value") ?? pullAuthorEmail; break; case "ghprbActualCommitAuthorEmail": commitAuthorEmail = pair.Value<string>("value") ?? commitAuthorEmail; break; case "ghprbPullLink": pullLink = pair.Value<string>("value") ?? pullLink; break; default: break; } } // It's possible for the pull email to be blank if the Github settings for the user // account hides their public email address. In that case fall back to the commit // author. It's generally the same value and serves as a nice backup identifier. if (string.IsNullOrEmpty(pullAuthorEmail)) { pullAuthorEmail = commitAuthorEmail; } if (sha1 == null || pullLink == null || pullId == null || pullAuthorEmail == null) { info = null; return false; } info = new PullRequestInfo( author: pullAuthor, authorEmail: pullAuthorEmail, id: pullId.Value, pullUrl: pullLink, sha1: sha1); return true; }
private void LoadProfiles() { if (profiles == null || profiles.Count == 0) { string data = MyGetWebData(homeUrl, true); Regex rgx = new Regex(@"nf\.constants\.page\.contextData =(.*); }\(netflix\)\);"); Match m = rgx.Match(data); if (m.Success) { string jsonData = m.Groups[1].Value; JObject json = (JObject)JsonConvert.DeserializeObject(jsonData); profiles = json["profiles"]["data"]["allProfiles"].Value<JArray>(); if (string.IsNullOrEmpty(ProfileName) || !profiles.Any(p => p["profileName"].Value<string>() == ProfileName)) { if (!string.IsNullOrWhiteSpace(startupUserProfile) && profiles.Any(p => p["profileName"].Value<string>() == startupUserProfile)) { currentProfile = (JObject)profiles.FirstOrDefault(p => p["profileName"].Value<string>() == startupUserProfile); } else { currentProfile = (JObject)profiles.FirstOrDefault(p => p["isAccountOwner"].Value<bool>()); } } else { currentProfile = (JObject)profiles.FirstOrDefault(p => p["profileName"].Value<string>() == ProfileName); } MyGetWebData(string.Format(switchProfileUrl, apiRoot, ProfileToken), true); } else { cc = null; Settings.DynamicCategoriesDiscovered = false; Settings.Categories.Clear(); profiles = null; throw new OnlineVideosException("Error loading profiles. Please try again"); } } }