我有一个MVC应用程序,其中集成了一个.net控制台应用程序。现在我想传递一个从MVC模型中的方法返回的值,并将其作为控制台应用程序MAIN方法中的参数传递。
我希望从“PinBlock”函数返回的“hexString”作为参数传递到控制台应用程序的Main Method中。
**MVC Model Function**
public string PinBlock()
{
// PAN Code without first 3 characters and last character
string str1 = Convert.ToString(PAN).Remove(0, 3);
string str2 = str1.Remove(str1.Length - 1, 1);
// Adding 4 0s at the start of the remaining PAN Number
int count = 4;
char someChar = '0';
string AlgoA = str2.PadLeft(count + str2.Length, someChar);
Console.WriteLine("ALgoA: " + AlgoA);
//Finding the length of the pin code and adding it to the pin code wth 10 'F's
string PinLength = Convert.ToString(APIN);
PinLength = PinLength.ToString();
string result = String.Format("{0,2:X2}", PinLength.Length);
string AlgoB = result + APIN + "FFFFFFFFFF";
Console.WriteLine("ALgoB: " + AlgoB);
long dec1 = Convert.ToInt64(AlgoA, 16);
long dec2 = Convert.ToInt64(AlgoB, 16);
long res = dec1 ^ dec2;
string hexResult = res.ToString("X");
PIN = hexResult;
return hexResult;
}
**MVC Function that attaches Console app with the MVC app**
public string Onclick(string hexResult)
{
using (var process = new Process())
{
process.StartInfo.FileName = @"..\ABL-ESB-DCA\bin\Debug\net6.0\encrypt\ConsoleApp1.exe"; // relative path. absolute path works too.
process.StartInfo.Arguments = hexResult;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.OutputDataReceived += (sender, data) =>
{
Console.WriteLine(data.Data);
};
process.ErrorDataReceived += (sender, data) => Console.WriteLine(data.Data);
Console.WriteLine("starting");
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
var exited = process.WaitForExit(1000 * 10); // (optional) wait up to 10 seconds
Console.WriteLine($"exit {exited}");
}
// ProcessInfo.Start(@"C:\Users\Talha\Desktop\New folder\linkedin\server.exe");
return "BUTTON ONCLICK";
}
**Console app**
internal class Program
{
static void Main(string[] args)
{
ClassLibrary1.Class1 class1 = new ClassLibrary1.Class1(); ;
class1.Perform();
}