using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
namespace WindowsFormsApp1
{
public partial class BlackDuckTool : Form
{
public BlackDuckTool()
{
InitializeComponent(); ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Use SecurityProtocolType.Ssl3 if needed for compatibility reasons
}
string baseProjectUrl = "https://xxx.app.blackduck.com/api/projects/17d8b108-4e2d-4321-95ff-a967da407efd/versions/1c04aecf-ba41-41c4-8048-2b4fcf2d98a1/components?offset={0}&limit=100&sort=projectName%20ASC";
string linksPath = "C:\\BlackDuck_MatckLinks.txt"; private void btnDone_Click(object sender, EventArgs e)
{
getLinks();
ParseAllSourcePaths();
} void ParseAllSourcePaths()
{
string allPath = "";
List<string> listPath = new List<string>();
string links = File.ReadAllText(linksPath);
var oklinks = links.Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (string l in oklinks)
{
if (string.IsNullOrEmpty(l)) { continue; }; var json = Httpget(l);
Matck.MatchObject mc = JsonConvert.DeserializeObject<Matck.MatchObject>(json);
if (mc != null && mc.items.Length > 0) {
mc.items.ToList().ForEach(
n => {
allPath+= n.filePath.path+"\r\n";
listPath.Add(n.filePath.path);
} ); }
} listPath.Sort();
allPath = "";
foreach (var s in listPath) {
allPath += s+"\r\n";
} File.WriteAllText("C:\\BlackDuckAllFilePath.txt",allPath); } private void getLinks()
{
string err = "";
int pageIndex = 0;
List<string> urlList = new List<string>();
for (int i = 0; i < 5; i++)
{
string url = string.Format(baseProjectUrl, pageIndex * 100);
string json = Httpget(url); if (json != "")
{ ResponseData data = JsonConvert.DeserializeObject<ResponseData>(json);
foreach (var d in data.items)
{
foreach (var o in d.origins)
{
o._meta.links.ToList().ForEach(n =>
{
if (n.rel == "matched-files")
{
if (!urlList.Contains(n.href))
{
urlList.Add(n.href);
}
};
});
} } }
else
{
err += (pageIndex + 1) + " failed\r\n"; }
pageIndex++; } string links = "";
foreach (var s in urlList)
{
links += s + "\r\n";
}
File.WriteAllText("C:\\BlackDuck_MatckLinks.txt", links); if (err != "")
{
MessageBox.Show(err); }
else
{
MessageBox.Show("get URLS OK");
} }
string Httpget(string url)
{ try
{
WebClient wc = new WebClient();
wc.Headers.Add("cookie", Properties.Resources.cookie); string s = wc.DownloadString(url);
wc.Dispose();
wc = null;
return s;
}
catch (Exception ex)
{ return ""; } }
} public class ResponseData
{
public int totalCount { get; set; }
public Item[] items { get; set; }
public object[] appliedFilters { get; set; }
public _Meta _meta { get; set; }
} public class _Meta
{
public string[] allow { get; set; }
public string href { get; set; }
public Link[] links { get; set; }
} public class Link
{
public string rel { get; set; }
public string href { get; set; }
public string name { get; set; }
public string label { get; set; }
} public class Item
{
public string componentName { get; set; }
public string componentVersionName { get; set; }
public string component { get; set; }
public string componentVersion { get; set; }
public int totalFileMatchCount { get; set; }
public License[] licenses { get; set; }
public Origin[] origins { get; set; }
public string[] usages { get; set; }
public string[] matchTypes { get; set; }
public DateTime releasedOn { get; set; }
public Licenseriskprofile licenseRiskProfile { get; set; }
public Securityriskprofile securityRiskProfile { get; set; }
public Versionriskprofile versionRiskProfile { get; set; }
public Activityriskprofile activityRiskProfile { get; set; }
public Operationalriskprofile operationalRiskProfile { get; set; }
public Activitydata activityData { get; set; }
public string reviewStatus { get; set; }
public string approvalStatus { get; set; }
public string policyStatus { get; set; }
public bool componentModified { get; set; }
public _Meta1 _meta { get; set; }
} public class Licenseriskprofile
{
public Count[] counts { get; set; }
} public class Count
{
public string countType { get; set; }
public int count { get; set; }
} public class Securityriskprofile
{
public Count1[] counts { get; set; }
} public class Count1
{
public string countType { get; set; }
public int count { get; set; }
} public class Versionriskprofile
{
public Count2[] counts { get; set; }
} public class Count2
{
public string countType { get; set; }
public int count { get; set; }
} public class Activityriskprofile
{
public Count3[] counts { get; set; }
} public class Count3
{
public string countType { get; set; }
public int count { get; set; }
} public class Operationalriskprofile
{
public Count4[] counts { get; set; }
} public class Count4
{
public string countType { get; set; }
public int count { get; set; }
} public class Activitydata
{
public DateTime lastCommitDate { get; set; }
public int newerReleases { get; set; }
public int contributorCount12Month { get; set; }
public int commitCount12Month { get; set; }
public string trending { get; set; }
} public class _Meta1
{
public string[] allow { get; set; }
public string href { get; set; }
public Link1[] links { get; set; }
} public class Link1
{
public string rel { get; set; }
public string href { get; set; }
} public class License
{
public string licenseDisplay { get; set; }
public string license { get; set; }
public string spdxId { get; set; }
public License1[] licenses { get; set; }
public string licenseType { get; set; }
} public class License1
{
public string licenseDisplay { get; set; }
public string license { get; set; }
public string spdxId { get; set; }
public object[] licenses { get; set; }
} public class Origin
{
public string name { get; set; }
public string origin { get; set; }
public string externalNamespace { get; set; }
public string externalId { get; set; }
public bool externalNamespaceDistribution { get; set; }
public _Meta2 _meta { get; set; }
} public class _Meta2
{
public object[] allow { get; set; }
public Link2[] links { get; set; }
} public class Link2
{
public string rel { get; set; }
public string href { get; set; }
} //--------------------- } namespace WindowsFormsApp1.Matck
{ public class MatchObject
{
public int totalCount { get; set; }
public Item[] items { get; set; }
public object[] appliedFilters { get; set; }
public _Meta _meta { get; set; }
} public class _Meta
{
public string[] allow { get; set; }
public string href { get; set; }
public object[] links { get; set; }
} public class Item
{
public Filepath filePath { get; set; }
public string[] usages { get; set; }
public _Meta1 _meta { get; set; }
} public class Filepath
{
public string path { get; set; }
public string archiveContext { get; set; }
public string compositePathContext { get; set; }
public string fileName { get; set; }
} public class _Meta1
{
public Link[] links { get; set; }
} public class Link
{
public string rel { get; set; }
public string href { get; set; }
} }

  

c# get all Blackfish match source file path list use API的更多相关文章

  1. Maven group, artifact or version defined in the pom file do not match the file ...

    在把library上传到bintray空间的时候报以下错误 Could not upload to 'https://api.bintray.com/content/ping/maven/comm-a ...

  2. 报错:Can't find a source file at "xxxxx“Locate the file or edit the source lookup path to include its location.

    调试问题: Can't find a source file at "/tmp/TI_MKLIB6sLCzz/SRC/exit.c" Locate the file or edit ...

  3. Solved Unable to copy the source file ./installer/services.sh to the destination file /etc/vmware-t

    Sometimes when you intall vmwaretools there will be some problems such as "Unable to copy the s ...

  4. (转)Eclipse - CDT使用GDB调试C++的问题-无源文件命名(No source file named)

    http://tech.ddvip.com/2014-09/1411618782213496.html Eclipse CDT调试C++, 使用的Unix的调试器GDB; 由于在Unix下, 文件的目 ...

  5. eclipse调试(debug)的时候,出现Source not found,Edit Source Lookup Path,一闪而过

    问题描述 使用Eclipse调试代码的时候,打了断点,经常出现Source not found,网上找了半天,大部分提示点击Edit Source Lookup Path,添加被调试的工程,然而往往没 ...

  6. [LeetCode] Longest Absolute File Path 最长的绝对文件路径

    Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...

  7. Longest Absolute File Path

    Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...

  8. Error: pathspec '*' did not match any file(s) known to git.

    git切换分支报错 error: pathspec 'develop' did not match any file(s) known to git. 解决办法如下: plumm@MACY-PC MI ...

  9. Leetcode: Longest Absolute File Path

    Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsub ...

  10. eclipse debug时老提示edit source lookup path解决方案

    用myeclipse debug web应用的时候,总提示edit source lookup path,每次都得手动选择项目,费时费力.在网上终于找到了方法. 搬运:http://www.educi ...

随机推荐

  1. PME算法简单Python实现

    技术背景 在前面的两篇博客中,我们分别介绍了Ewald算法求解静电势能和基于格点拉格朗日插值法的PME算法.在多种计算优化算法(Ewald求和.快速傅里叶变换.格点拉格朗日插值.截断近似)的加持下,使 ...

  2. 使用 vscode 编译+运行 typescropt Mac win同理

    一..d.ts文件最好在src/typings 目录下,可在tsconfig.json 文件配置 二.vs 监听文件变化,自动编译ts文件 tsconfig.json { "compiler ...

  3. 为什么在http协议中使用base64编码方式传输二进制文件

    相关: 图解 Base64 实现原理并使用 js 实现一个简单的 Base64 编码器 常用加密方法之Base64编解码及代码实现 一直都知道在http协议中使用base64的方式传递二进制文件,虽然 ...

  4. 量子线路设计:减少CNOT和T门的意义。

    在量子线路的设计中,我们往往希望减少线路中的CNOT门和T门的数目,原因如下: 一般文献宣称减少T门的数量是为了更高效地执行容错量子计算(fault-tolerant quantum computat ...

  5. 关于MySQL表设计,测试人员可以关注哪些点

    测试人员关注数据库表设计是"测试左移"的一种手段,可以把有关数据库的潜在bug消灭在系统测试之前,从而提高交付效率. 以MySQL为例,QA可从以下方面对数据库表设计做测试的左移: ...

  6. 太强了!14.7K star!Windows系统居然还有开源替代版了?!

    在操作系统的世界里,Windows 系统一直占据着重要的地位.然而,你可能不知道的是,还有一个拥有 14.7K star 的开源替代版 --ReactOS. 1.ReactOS 介绍 ReactOS ...

  7. Go语言net/http包源码学习

    0.前言 该笔记为笔者第一次学习go的net/http包源码的时候所记,也许写的并不是很精确,希望大家多多包涵,一起讨论学习. 该笔记很大程度的参考了网名为"小徐先生"的前辈所分享 ...

  8. ARC143D Bridges

    ARC143D Bridges 巧妙的图论题. 思路 分析题目,发现很像拆点. 由于拆点要设置出入点,这里我们也把 \(a_i\) 设成入点,把 \(a_i+n\) 设成出点,再次分析问题. 考虑我们 ...

  9. HarmonyOS-Chat聊天室|纯血鸿蒙Next5 api12聊天app|ArkUI仿微信

    自研原生鸿蒙NEXT5.0 API12 ArkTS仿微信app聊天模板HarmonyOSChat. harmony-wechat原创重磅实战纯血鸿蒙OS ArkUI+ArkTs仿微信App聊天实例.包 ...

  10. linux找到目录下的大文件

    用这个命令找一下大于800M的文件 find . -type f -size +800M -print0 | xargs -0 ls -lh 非常方便 能看的到哪些文件有多大