public List <Project> GetProjects() { var issueTypes = new List <Type>(); var projects = new List <Project>(); try { "Getting a list of issue types from JIRA".Debug(); //https://yoursite.atlassian.net/rest/api/2/issuetype var issueTypeRequest = CreateRequest("rest/api/2/issuetype", Method.GET); var issueTypeResponse = ExecuteRequest(issueTypeRequest); if (issueTypeResponse.StatusCode == HttpStatusCode.OK) { "JIRA issue types retrieved. Deserializing results.".Debug(); var jiraIssueTypes = new JsonSerializer <List <IssueType> >().DeserializeFromString(issueTypeResponse.Content); if (jiraIssueTypes != null && jiraIssueTypes.Any()) { issueTypes.AddRange(jiraIssueTypes.Select(jiraIssueType => new Type(jiraIssueType.Name))); } } "Getting projects from JIRA".Debug(); //https://yoursite.atlassian.net/rest/api/2/project var request = CreateRequest("rest/api/2/project", Method.GET); var jiraResp = ExecuteRequest(request); if (jiraResp.StatusCode != HttpStatusCode.OK) { string.Format("Failed to get projects from JIRA. {0}: {1}", jiraResp.StatusCode, jiraResp.ErrorMessage ?? string.Empty).Warn(); //var serializer = new JsonSerializer<ErrorMessage>(); //var errorMessage = serializer.DeserializeFromString(jiraResp.Content); return(projects); } "JIRA projects retrieved. Deserializing results.".Debug(); var resp = new JsonSerializer <List <JiraProject> >().DeserializeFromString(jiraResp.Content); if (resp != null && resp.Any()) { projects.AddRange( resp.Select( jiraProject => new Project(jiraProject.Key, jiraProject.Name, issueTypes, GetProjectStates(jiraProject.Key)))); } else { "No JIRA projects were retrieved. Please check account access to projects.".Error(); } } catch (Exception ex) { "Error getting JIRA projects.".Error(ex); } return(projects); }
private static GridVideoRenderer[] FindVideos(string rawHtml) { if (VideoJsonRegex.Match(rawHtml).Success) { var jsonBody = VideoJsonRegex.Match(rawHtml).Groups[1].Value; var gridVideoTabs = new JsonSerializer().Deserialize <YoutubeVideoBlock[]>(new JsonTextReader(new StringReader($"[{jsonBody}]"))); return(gridVideoTabs.Select(i => i.GridVideoRenderer).ToArray()); } return(new GridVideoRenderer[0]); }
public List<Project> GetProjects() { var issueTypes = new List<Type>(); var projects = new List<Project>(); try { "Getting a list of issue types from JIRA".Debug(); //https://yoursite.atlassian.net/rest/api/2/issuetype var issueTypeRequest = new RestRequest("/rest/api/2/issuetype", Method.GET); var issueTypeResponse = _restClient.Execute(issueTypeRequest); if (issueTypeResponse.StatusCode == HttpStatusCode.OK) { "JIRA issue types retrieved. Deserializing results.".Debug(); var jiraIssueTypes = new JsonSerializer<List<IssueType>>().DeserializeFromString(issueTypeResponse.Content); if (jiraIssueTypes != null && jiraIssueTypes.Any()) { issueTypes.AddRange(jiraIssueTypes.Select(jiraIssueType => new Type(jiraIssueType.Name))); } } "Getting projects from JIRA".Debug(); //https://yoursite.atlassian.net/rest/api/2/project var request = new RestRequest("/rest/api/2/project", Method.GET); var jiraResp = _restClient.Execute(request); if (jiraResp.StatusCode != HttpStatusCode.OK) { string.Format("Failed to get projects from JIRA. {0}: {1}", jiraResp.StatusCode, jiraResp.ErrorMessage ?? string.Empty).Warn(); //var serializer = new JsonSerializer<ErrorMessage>(); //var errorMessage = serializer.DeserializeFromString(jiraResp.Content); return projects; } "JIRA projects retrieved. Deserializing results.".Debug(); var resp = new JsonSerializer<List<JiraProject>>().DeserializeFromString(jiraResp.Content); if (resp != null && resp.Any()) { projects.AddRange( resp.Select( jiraProject => new Project(jiraProject.Key, jiraProject.Name, issueTypes, GetProjectStates(jiraProject.Key)))); } } catch (Exception ex) { "Error getting JIRA projects.".Error(ex); } return projects; }
public override async Task Preprocess(Auth0ResourceTemplate template) { //Connection templates have a property enabled_clients_match_conditions that contains regexes or string //literals of client names that the connection should be associated with. //This preprocessing step looks up all the deployed clients and var matchConditions = new JsonSerializer().Deserialize <ConnectionClientMatchConditions>( new JTokenReader(template.Template)) ?.EnabledClientsMatchConditions?.ToList() ?? new List <string>(); if (matchConditions.Count == 0) { template.Preprocessed = true; return; } using var managementClient = await _managementApiClientFactory.CreateAsync(); var getClientsRequest = new GetClientsRequest() { IsGlobal = false, IncludeFields = true, Fields = "name,client_id" }; var clients = await managementClient.Clients.GetAllAsync(getClientsRequest, new PaginationInfo()); var matchConditionsRegexes = matchConditions.Select(x => new Regex(x)); var matchingClientIds = clients.Where(x => //check for exact string match OR regex match matchConditionsRegexes.Any(regex => string.Equals(regex.ToString(), x.Name) || regex.IsMatch(x.Name)) ).Select(x => (object)new JValue(x.ClientId)).ToList(); if (!(template.Template is JObject t)) { throw new InvalidOperationException( $"{Type.Name} template {template.Filename} processed type is not of type JObject." + $" Found {template.Template.GetType().Name}"); } //add the enabled_clients t.Add("enabled_clients", new JArray(matchingClientIds.ToArray())); //remove the enabled_clients_match_conditions t.Remove("enabled_clients_match_conditions"); if (_args.CurrentValue.DryRun) { Reporter.Warn( "Dry-run flag is set. Any clients that do not exist but that will be created by " + "these templates when run without the dry-run flag may not be found and included in this " + "connections\' enabled_clients list. The complete list of matching clients will be found when " + "run without the dry-run flag."); } template.Preprocessed = true; }
public virtual int SaveUser(int?userId, SysUser info, Func <string> pwdCreator) { if (context.SysUsers.Any(s => s.Account == info.Account && userId != s.UserID)) { throw new ClientNotificationException("帐号重复,不能重复添加。"); } if (context.SysUsers.Any(s => s.Mobile == info.Mobile && s.UserID != userId)) { throw new ClientNotificationException(string.Format("手机号为{0}的用户已经存在。", info.Mobile)); } var userRoles = new List <SysUserRole>(); IEnumerable <int> roleIds = null; var roleNames = string.Empty; if (!string.IsNullOrEmpty(info.Role)) { var posts = context.SysRoles.ToList(); var array = new JsonSerializer().Deserialize <string[]>(info.Role); roleIds = array.Select(s => Convert.ToInt32(s)); roleNames = string.Join("、", posts.Where(s => roleIds.Contains(s.RoleID)).Select(s => s.Name)); } info.RoleNames = roleNames; info.PyCode = info.Name.ToPinyin(); if (pwdCreator != null) { info.Password = pwdCreator(); } if (userId == null) { context.SysUsers.Insert(info); userId = info.UserID; } else { context.SysUsers.Update(info, s => s.UserID == userId); context.SysUserRoles.Delete(s => s.UserID == userId); } if (roleIds != null) { userRoles.AddRange(roleIds.Select(s => new SysUserRole { RoleID = s, UserID = (int)userId })); context.SysUserRoles.Batch(userRoles, (u, s) => u.Insert(s)); } return((int)userId); }
public async Task <HttpResponseMessage> Confirm() { var contentStream = await Request.Content.ReadAsStreamAsync(); var confirmingFiles = new JsonSerializer().Deserialize <IEnumerable <Tuple <string, Guid> > >( new JsonTextReader(new StreamReader(contentStream))); var result = confirmingFiles.Select(file => new SynchronizationConfirmation { FileName = file.Item1, Status = CheckSynchronizedFileStatus(file) }); return(this.GetMessageWithObject(result) .WithNoCache()); }
protected string[] GetExpandedItemsFromCookie() { var cookie = Request.Cookies[IndexModel.ExpandedItemsCookieName]; var value = cookie != null?HttpUtility.UrlDecode(cookie.Value) : null; if (string.IsNullOrEmpty(value)) { return(new string[0]); } try { var items = new JsonSerializer().GetObject <object[]>(value); var result = items.Select(t => (string)t).ToArray(); return(result); } catch { return(new string[0]); } }
public async Task<IEnumerable<SynchronizationConfirmation>> Confirm() { var contentStream = await Request.Content.ReadAsStreamAsync(); var confirmingFiles = new JsonSerializer().Deserialize<IEnumerable<Tuple<string, Guid>>>( new JsonTextReader(new StreamReader(contentStream))); return confirmingFiles.Select(file => new SynchronizationConfirmation { FileName = file.Item1, Status = CheckSynchronizedFileStatus(file) }); }
public async Task<HttpResponseMessage> Confirm() { var contentStream = await Request.Content.ReadAsStreamAsync(); var confirmingFiles = new JsonSerializer().Deserialize<IEnumerable<Tuple<string, Guid>>>( new JsonTextReader(new StreamReader(contentStream))); var result = confirmingFiles.Select(file => new SynchronizationConfirmation { FileName = file.Item1, Status = CheckSynchronizedFileStatus(file) }); return this.GetMessageWithObject(result) .WithNoCache(); }