I have created 1 console Application and it is running perfectly. In my project I have to take input string and from telnet specific window named as "telnet 192.168.x.x" and run my project and give output related to that string (i.e barcode code is all I have to receive on telnet window and give output (details of barcode code) related to that code in same telnet window). I am able to run this console app in cmd.exe and ConsoleApplicat ion.exe but now I am passing barcode string manually then how to run this application on telnet window and receive barcode string automatically?
please help .
please help .
Code:
namespace ConsoleApplication2
{
class Program
{
string path = @"text file path";
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["constring"].ToString());
public void getConsoleInput()
{
try
{
FileInfo fi = new FileInfo(path);
for (int i = 0; i <= 0; i++)
{
Console.WriteLine("");
using (StreamWriter sw = new StreamWriter(path))
{
sw.WriteLine(Console.ReadLine());
sw.Close();
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public void ReadWriteIntoFile()
{
try
{
string filename = @"txt file path";
StringBuilder sb = new StringBuilder();
StreamReader sr = new StreamReader(path);
string s = sr.ReadLine();
sr.Close();
DataExport("Select * from PATIENT_TABLE where [BARCODE] = '" + s + "'", filename);
}
catch { }
}
public void DataExport(string SelectQuery, string filename)
{
try
{
using (var dt = new DataTable())
{
using (var da = new SqlDataAdapter(SelectQuery, con))
{
da.Fill(dt);
var rows =
from dr in dt.Rows.Cast<datarow>()
select String.Join(
",",
from dc in dt.Columns.Cast<datacolumn>()
let t1 = Convert.IsDBNull(dr[dc]) ? "" : dr[dc].ToString()
let t2 = t1.Contains(",") ? String.Format("\"{0}\"", t1) : t1
select t2);
using (var sw = new StreamWriter(filename))
{
// sw.WriteLine(header);
foreach (var row in rows)
{
sw.WriteLine(row);
}
sw.Close();
}
}
}
}
catch (Exception e) { Console.WriteLine(e.Message); }
}
public void WriteFileOutput()
{
string path = @"C:\Users\Priya\Desktop\Project\Data.txt";
if (File.Exists(path))
{
string[] lines = File.ReadAllLines(path);
foreach (string line in lines)
{
Console.WriteLine(line);
}
}
Console.ReadLine();
}
public static void Main(string[] args)
{
Program p = new Program();
p.getConsoleInput();
p.ReadWriteIntoFile();
p.WriteFileOutput();
}
public void timerfor()
{
Timer t;
t = new System.Timers.Timer(10000);
// Hook up the Elapsed event for the timer.
t.Elapsed += OnTimedEvent;
t.Enabled = true;
}
private static void OnTimedEvent(Object source, ElapsedEventArgs e)
{
Console.WriteLine(ConsoleKey.Enter);
}
}
}