List the nuget package from nexus server - c#

I want to get the nuget package list from some source
(https://nexus.sample.com) like that.When I try a below code
string void main(string args[])
{
Process commandProcess = new Process();
commandProcess.StartInfo.UseShellExecute = false;
commandProcess.StartInfo.FileName = #"C:\Nuget\nuget.exe"; // this is the path of curl where it is installed;
commandProcess.StartInfo.Arguments ="list -Verbose -AllVersions -Source http://nexus.sample.com/repository/nuget-hosted/";
commandProcess.StartInfo.CreateNoWindow = true;
commandProcess.StartInfo.RedirectStandardInput = true;
commandProcess.StartInfo.RedirectStandardOutput = true;
commandProcess.StartInfo.RedirectStandardError = true;
commandProcess.Start();
commandProcess.WaitForExit();
string output = commandProcess.StandardOutput.ReadToEnd();
}
the command console was not run.If I set StartInfo.RedirectStandardOutput= false.the command console was run.but I can't read the output value.Plese give any suggestion.

Instead of running the executable, why don't you just use NuGet.Core to list all packages ?
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("http://nexus.sample.com/repository/nuget-hosted");
foreach (IPackage p in repo.GetPackages())
{
Console.WriteLine(p.GetFullName());
}
For more infos : Play with Packages, programmatically!

Related

Puppeteer not working anymore in Azure Function

I have an Azure Function where I convert an HTML to PDF and then download the result.
Yesterday I updated the function to version 4 and .NET 6 and I also saw that the BrowserFetcher.DefaultRevision is obsoleted and I replaced it with recommended BrowserFetcher.DefaultChromiumRevision and the function is not working anymore after publish.
I also tried locally but there is all good. The error I received is Invalid URI: The hostname could not be parsed. and I suspect the Puppeteer.
This is my Startup function code:
public override void Configure(IFunctionsHostBuilder builder)
{
var bfOptions = new BrowserFetcherOptions();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
bfOptions.Path = Path.GetFullPath("mounted");
}
var bf = new BrowserFetcher(bfOptions);
try
{
bf.DownloadAsync(BrowserFetcher.DefaultChromiumRevision).Wait();
}
catch (Exception)
{
string zipPath = Path.Combine(bf.DownloadsFolder, $"download-{bf.Platform}-{BrowserFetcher.DefaultChromiumRevision}.zip");
string folderPath = Path.Combine(bf.DownloadsFolder, $"{bf.Platform}-{BrowserFetcher.DefaultChromiumRevision}");
using (var process = new Process())
{
process.StartInfo.FileName = "unzip";
process.StartInfo.Arguments = $"\"{zipPath}\" -d \"{folderPath}\"";
process.Start();
process.WaitForExit();
}
new FileInfo(zipPath).Delete();
}
builder.Services.AddHttpClient();
builder.Services.AddSingleton<IPdfPrinterService>((s) =>
{
return new ChromiumPdfPrinterService(bf.GetExecutablePath(BrowserFetcher.DefaultChromiumRevision));
});
}
Has anyone else faced this problem?
I found the issue. That was caused by RazorLight upgrade to stable version 2.0.0.
Rollback to version 2.0.0-rc.3 works fine.
Here is the GitHub issue: https://github.com/toddams/RazorLight/issues/481

How to get cross-platform system model name with .NET 5?

I'm developing a cross-platform application in C# / NET 5, it will run on both Windows and MacOS. I need to print the "manufacturer model name" of the running system. On Windows, this is more or less what is returned by querying the WMI class Win32_ComputerSystem. For example the "Name" field:
Caption: Computer System Product
Description: Computer System Product
IdentifyingNumber: <hidden>
Name: Inspiron 7370 **<--- I need to print this kind of info!**
UUID: <hidden>
Vendor: Dell Inc.
Version:
The software will run also on MacOS, so I need a common way to retrieve, example, "Apple Mac Mini" or similar string. I assume it won't be possible to get it via WMI.
Is there a cross-platform solution? Thanks
I've "solved" by branching between the different OS and without needing to use System.Management package:
public static string GetSystemModelName()
{
var cmd = new ProcessStartInfo();
cmd.RedirectStandardError = true;
cmd.CreateNoWindow = true;
cmd.UseShellExecute = false;
cmd.RedirectStandardOutput = true;
if (System.OperatingSystem.IsWindows())
{
cmd.FileName = "CMD.exe";
cmd.Arguments = "/C wmic csproduct get name | find /v \"Name\"";
}
else if (System.OperatingSystem.IsMacOS())
{
cmd.FileName = "sh";
cmd.Arguments = "-c \"sysctl -n hw.model\"";
}
else return null;
try
{
var builder = new StringBuilder();
using (Process process = Process.Start(cmd))
{
process.WaitForExit();
builder.Append(process.StandardOutput.ReadToEnd());
}
return builder.ToString().Trim();
}
catch (Exception)
{
return null;
}
}

The file being use by another process when i add it programatically by SharpSvn

We are using SharpSvn to add SolidWorks files programatically to SVN tortoise.
When file is open in SolidWorks, i want to add it to SVN by code without closing file.
I used code below
var SvnResult = new SvnResult();
var FullPath = SvnHelper.FileCombine(FileName);
try
{
var SvnArg = new SvnAddArgs();
SvnArg.Force = true;
SvnArg.Depth = SvnDepth.Infinity;
//
SvnClient.Add(FullPath, SvnArg);
SvnResult.Message = "Success.";
SvnResult.Status = true;
//
return SvnResult;
}
catch (SvnException exc)
{
SvnResult.Message = exc.Message;
SvnResult.Status = false;
return SvnResult;
}
and i get error like this :
The process cannot access the file because it is being used by another process.
How can i add it to SVN without closing file?
Regards,
We solved the problem. At first we used TortoiseSvn.exe command lines to add and commit the file but when we used to send commit command, svn Dialog form was raised. For solving this problem I install “Command Line Client Tools” from the svn setup. By installing this option you can find svn.exe under svn path “C:\Program Files\TortoiseSVN\bin”.
I add this path to Environment Variables and then use svn command lines to add and commit while file is open.
public SvnResult CommitFiles_BySVNCmd(string filePath)
{
var fullPath = SvnHelper.FileCombine(filePath);
var svnResult = new SvnResult();
try
{
// svn add command
var status = GetStatus(fullPath);
//
if (status.LocalContentStatus == SvnStatus.NotVersioned)
{
var argumentsAdd = $#"add {fullPath}";
ProcessStart(argumentsAdd);
}
// svn commit command
var argumentsCommit = $#"commit -m Commited_Automatically {fullPath}";
ProcessStart(argumentsCommit);
svnResult.Message = "Success
svnResult.Status = true;
return svnResult;
}
catch (SvnException se)
{
svnResult.Message = se.Message;
svnResult.Status = false;
return svnResult;
}
}
private void ProcessStart(string arguments)
{
var processInfo = new ProcessStartInfo("svn", arguments);
processInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
Process.Start(processInfo);
}
Best Regards,

Scan uploaded files C# ASP.net

I'm trying to do a virus scan on uploaded files.
I have no control over the installed virus scanner, the product hosted by multiple parties with different scanners.
I tried the following library but it always returns VirusNotFound on the eicar file.
https://antivirusscanner.codeplex.com/
Do you know any other solutions?
ClamAV has pretty bad detection scores.
VirusTotal is not on premises.
I decided to create CLI wrappers for multiple scanners, nuget packages can be found here: https://www.nuget.org/packages?q=avscan
And its documentation and source code available at https://github.com/yolofy/AvScan
I used this library for .net (It uses the VirusTotal public api):
https://github.com/Genbox/VirusTotal.NET
A little example from github :
static void Main(string[] args)
{
VirusTotal virusTotal = new VirusTotal("INSERT API KEY HERE");
//Use HTTPS instead of HTTP
virusTotal.UseTLS = true;
FileInfo fileInfo = new FileInfo("testfile.txt");
//Create a new file
File.WriteAllText(fileInfo.FullName, "This is a test file!");
//Check if the file has been scanned before.
Report fileReport = virusTotal.GetFileReport(fileInfo).First();
bool hasFileBeenScannedBefore = fileReport.ResponseCode == 1;
if (hasFileBeenScannedBefore)
{
Console.WriteLine(fileReport.ScanId);
}
else
{
ScanResult fileResults = virusTotal.ScanFile(fileInfo);
Console.WriteLine(fileResults.VerboseMsg);
}
}
A full example can be found here :
https://github.com/Genbox/VirusTotal.NET/blob/master/VirusTotal.NET%20Client/Program.cs
Clam AV is pretty good.
https://www.clamav.net/downloads
C# Api here:
https://github.com/michaelhans/Clamson/
I just tried various ways, But some didn't work.
Then I decided to use ESET NOD32 command line tools .
It works fine for me:
public bool Scan(string filename)
{
var result = false;
try
{
Process process = new Process();
var processStartInfo = new ProcessStartInfo(#"C:/Program Files/ESET/ESET Security/ecls.exe")
{
Arguments = $" \"{filename}\"",
CreateNoWindow = true,
ErrorDialog = false,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
};
process.StartInfo = processStartInfo;
process.Start();
process.WaitForExit();
if (process.ExitCode == 0) //if it doesn't exist virus ,it returns 0 ,if not ,it returns 1
{
result = true;
}
}
catch (Exception)
{ //nothing;
}
return result;
}

how to execute multiple ssis packages from c#

I have created 10 different packages and i want to execute them from c# coding. Can some one post some screen shots to achieve this.
I have tried this
Application app = new Application();
TraceService("loading system From File system");
//Create package Container to hold the package.
//And Load the Package Using the Application Object.
Package package = app.LoadPackage(#"C:\User\Kiran\Documents\Visual Studio 2012\Projects\WindowsServiceTest\WindowsServiceTest\Package1.dtsx", null);
TraceService("Execution Started");
DTSExecResult result = package.Execute();
// print the result
TraceService(result.ToString());
TraceService("Execution Completed");
Here i have to get the file name in run time not by hard coding
Following code will execute all packages from given folder.
var pkgLocation = #"C:\User\Kiran\Documents\Visual Studio 2012\Projects\WindowsServiceTest\WindowsServiceTest\";
foreach (var file in Directory.EnumerateFiles(pkgLocation, "*.dtsx"))
using (var pkg = new Application().LoadPackage(file, null))
{
var pkgResults = pkg.Execute();
Console.WriteLine("Package File Name:{0}, Result:{1}",file.ToString(), pkgResults.ToString());
}
The executing SSIS package from C# and VB is well documented in official site. This is my complete code in script task to execute multiple SSIS packages.
string packagesFolder = Dts.Variables["User::packagesFolder"].Value.ToString();
string rootFolder = Dts.Variables["User::rootFolder"].Value.ToString();
Package pkg;
Microsoft.SqlServer.Dts.Runtime.Application app;
DTSExecResult pkgResults;
foreach (var pkgLocation in Directory.EnumerateFiles(packagesFolder+"\\", "ValidateDataMigration-*.dtsx"))
{
try
{
app = new Microsoft.SqlServer.Dts.Runtime.Application();
pkg = app.LoadPackage(pkgLocation, null);
pkgResults = pkg.Execute();
File.AppendAllText(rootFolder + "\\DataValidationProgress.log", pkgLocation.ToString()+"=>"+ pkgResults.ToString()+ Environment.NewLine);
}
catch(Exception e)
{
File.AppendAllLines(rootFolder + "\\DataValidationErrors.log", new string[] { e.Message, e.StackTrace });
}
}

Categories