public static SrcFileInfo ShouldBeFilled(this SrcFileInfo srcFileInfo) { srcFileInfo.ShouldNotBeNull(); srcFileInfo.path.ShouldNotBeNull(); srcFileInfo.links.ShouldBeFilled(); return(srcFileInfo); }
private void IndexProject( SrcFileInfo searchFile, ConcurrentDictionary <PackageReference, HashSet <RepoInfo> > graph, IScanProgress scanProgress) { var fileName = Path.GetFileName(searchFile.path); if (!fileName.EndsWith(".csproj")) { return; } var repoSlug = ExtractSlugFromUrl(searchFile.links.self.href); if (_skipRepos.Contains(repoSlug)) { Console.WriteLine($"Skipped {repoSlug}"); return; } var repoResource = _client.RepositoriesEndPoint().RepositoryResource(_bbAccount, repoSlug); if (!_reposCache.TryGetValue(repoSlug, out var repo)) { var repoInfo = repoResource.GetRepository(); var fileLink = $"{repoInfo.links.html.href}/src/master/{searchFile.path}"; repo = RepoInfo.Parse(repoInfo.slug, fileLink); _reposCache.Add(repoSlug, repo); scanProgress.UpdateRepoProgress(); } var projectContent = repoResource.SrcResource().GetFileContent(searchFile.path); var nugetRefs = ProjectFileParser.Parse(projectContent); foreach (var nugetRef in nugetRefs) { if (!graph.TryGetValue(nugetRef, out var repoInfos)) { repoInfos = new HashSet <RepoInfo>(); } repoInfos.Add(repo); graph[nugetRef] = repoInfos; } scanProgress.UpdateProjectProgress(); Console.WriteLine($"Processed {fileName} from {repo.Name}"); }
private void IndexProject(SrcFileInfo searchFile, ConcurrentDictionary <PackageReference, HashSet <RepoInfo> > graph) { var fileName = Path.GetFileName(searchFile.path); if (!fileName.EndsWith(".csproj")) { return; } var repoSlug = ExtractSlugFromUrl(searchFile.links.self.href); var repoResource = _client.RepositoriesEndPoint().RepositoryResource(_bbAccount, repoSlug); if (!_reposCache.TryGetValue(repoSlug, out var repo)) { var repoInfo = repoResource.GetRepository(); repo = RepoInfo.Parse(repoInfo.slug, repoInfo.links.html.href); _reposCache.Add(repoSlug, repo); ++_foundReposCount; } var projectContent = repoResource.SrcResource().GetFileContent(searchFile.path); var nugetRefs = ProjectFileParser.Parse(projectContent); foreach (var nugetRef in nugetRefs) { if (!graph.TryGetValue(nugetRef, out var repoInfos)) { repoInfos = new HashSet <RepoInfo>(); } repoInfos.Add(repo); graph[nugetRef] = repoInfos; } ++_scannedProjectFilesCount; Console.WriteLine($"Processed {fileName} from {repo.Name}"); }
private void buttonSend_Click(object sender, EventArgs e) { if (checkBox.Checked) { //Thread thread = new Thread(new ThreadStart(ShowMB)); //thread.IsBackground = true; //thread.Start(); using (FileStream srcFileStream = File.Open(SrcFileInfo.FullName, FileMode.Open, FileAccess.Read), resFileStream = File.Create(SrcFileInfo.DirectoryName + "\\" + Path.GetFileNameWithoutExtension(SrcFileInfo.FullName) + ".encryp"), keyFileStream = File.Create(SrcFileInfo.DirectoryName + "\\" + Path.GetFileNameWithoutExtension(SrcFileInfo.FullName) + ".key")) { //вызовы функций шифрования IDEAEncryption encryption = new IDEAEncryption(srcFileStream, resFileStream, keyFileStream, SrcFileInfo.Extension); encryption.Encrypt(); SrcFileInfo = new FileInfo(SrcFileInfo.DirectoryName + "\\" + Path.GetFileNameWithoutExtension(SrcFileInfo.FullName) + ".encryp"); KeyFileInfo = new FileInfo(SrcFileInfo.DirectoryName + "\\" + Path.GetFileNameWithoutExtension(SrcFileInfo.FullName) + ".key"); } //thread.Abort(); } try { int port = 4000; IPAddress iPAddress = new IPAddress(Convert.ToInt64(textBoxID.Text)); IPEndPoint endPoint = new IPEndPoint(iPAddress, port); TcpClient tcpClient = new TcpClient(endPoint); using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider()) using (NetworkStream networkStream = tcpClient.GetStream()) using (CryptoStream cryptoNetStream = new CryptoStream(networkStream, aes.CreateEncryptor(), CryptoStreamMode.Write)) { //отправка открытого ключа RSAParameters rSAParameters = rsa.ExportParameters(false); networkStream.Write(rSAParameters.Modulus, 0, 128); networkStream.Write(rSAParameters.Exponent, 0, 3); //получение и дешифровка сеансового ключа byte[] encrData = new byte[128], sessionKey; networkStream.Read(encrData, 0, encrData.Length); sessionKey = rsa.Decrypt(encrData, false); //инициализация сеансовго ключа for (int i = 0; i < 32; i++) { aes.Key[i] = sessionKey[i]; } for (int i = 32; i < 48; i++) { aes.IV[i - 32] = sessionKey[i]; } progressBar1.Visible = true; progressBar1.Maximum = (int)(SrcFileInfo.Length / 2); byte[] buffer = new byte[16]; byte[] name; int bytesCount = 0; if (KeyFileInfo != null) { progressBar1.Maximum += (int)(KeyFileInfo.Length / 2); networkStream.WriteByte(255); name = Encoding.ASCII.GetBytes(KeyFileInfo.Name); networkStream.WriteByte((byte)name.Length); networkStream.Write(name, 0, name.Length); networkStream.Write(BitConverter.GetBytes(KeyFileInfo.Length), 0, 8); name = Encoding.ASCII.GetBytes(SrcFileInfo.Name); networkStream.WriteByte((byte)name.Length); networkStream.Write(name, 0, name.Length); networkStream.Write(BitConverter.GetBytes(SrcFileInfo.Length), 0, 8); using (Stream keyFile = KeyFileInfo.OpenRead()) { for (long i = 0; i < KeyFileInfo.Length; i += buffer.Length) { //добавить шифрование bytesCount = keyFile.Read(buffer, 0, buffer.Length); cryptoNetStream.Write(buffer, 0, bytesCount); progressBar1.Value += buffer.Length / 2; } } } else { networkStream.WriteByte(0); name = Encoding.ASCII.GetBytes(SrcFileInfo.Name); networkStream.WriteByte((byte)name.Length); networkStream.Write(name, 0, name.Length); networkStream.Write(BitConverter.GetBytes(SrcFileInfo.Length), 0, 8); } using (FileStream srcFile = SrcFileInfo.OpenRead()) { for (long i = 0; i < SrcFileInfo.Length; i += buffer.Length) { //добавить шифрование bytesCount = srcFile.Read(buffer, 0, buffer.Length); cryptoNetStream.Write(buffer, 0, bytesCount); progressBar1.Value += buffer.Length / 2; } } } tcpClient.Close(); KeyFileInfo.Delete(); SrcFileInfo.Delete(); MessageBox.Show("File succsessfully sended", "Succsess", MessageBoxButtons.OK, MessageBoxIcon.None); } catch (Exception exp) { MessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.DialogResult = DialogResult.OK; }