Initial commit
v1.0
This commit is contained in:
146
HSUCO_CCTV_GetData/Program.cs
Normal file
146
HSUCO_CCTV_GetData/Program.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace HSUCO_CCTV_GetData
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
const string _commandErrorMessge = "input command [data, xml]";
|
||||
const string _filePath = "config.xml";
|
||||
if (args.Length == 0 )
|
||||
{
|
||||
|
||||
Console.WriteLine( _commandErrorMessge );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(!System.IO.File.Exists(_filePath))
|
||||
{
|
||||
Console.WriteLine("not Found config.xml");
|
||||
return;
|
||||
}
|
||||
|
||||
Config config = XmlSystem.LoadFromPath<Config>(_filePath);
|
||||
|
||||
|
||||
switch (args[0].ToUpper())
|
||||
{
|
||||
case "DATA":
|
||||
GetData(config);
|
||||
break;
|
||||
case "XML":
|
||||
List<Config.Information> cctvInformations = GetInformation(config);
|
||||
if(cctvInformations != null)
|
||||
{
|
||||
config.CCTV = cctvInformations;
|
||||
XmlSystem.Save<Config>("result.xml", config);
|
||||
Console.Write("Save Complete");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine(_commandErrorMessge);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
static void GetData(Config config)
|
||||
{
|
||||
List<DetailData> detailDatas = new List<DetailData>();
|
||||
foreach (var nvr in config.NVR)
|
||||
{
|
||||
try
|
||||
{
|
||||
string connectionString = String.Format("server={0};port=3306;database={1};user={2};password={3}", nvr.IpAddress, "leopard", "root", "ehtlrhdtk1!");
|
||||
MySqlConnection mySqlConnection = new MySqlConnection(connectionString);
|
||||
mySqlConnection.Open();
|
||||
MySqlCommand sqlCommand = new MySqlCommand("Select name, addr,id,password From tbl_camera where IsDeleted='0'", mySqlConnection);
|
||||
using (MySqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
|
||||
{
|
||||
while (sqlDataReader.Read())
|
||||
{
|
||||
DetailData detailData = new DetailData();
|
||||
detailData.ServerName = nvr.Name;
|
||||
detailData.ServerIP = nvr.IpAddress;
|
||||
detailData.Name = sqlDataReader["name"].ToString();
|
||||
detailData.IP = sqlDataReader["addr"].ToString();
|
||||
detailData.ID = sqlDataReader["id"].ToString();
|
||||
detailData.Password = sqlDataReader["password"].ToString();
|
||||
detailDatas.Add(detailData);
|
||||
|
||||
}
|
||||
}
|
||||
mySqlConnection.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(nvr.Name + " : " + ex.Message + Environment.NewLine);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
StringBuilder writeData = new StringBuilder();
|
||||
writeData.AppendLine("ServerName, ServerIP, Name, IP, ID, Password");
|
||||
foreach (var item in detailDatas)
|
||||
{
|
||||
writeData.AppendLine(item.ServerName + "," + item.ServerIP + "," + item.Name + "," + item.IP + "," + item.ID + "," + item.Password);
|
||||
}
|
||||
|
||||
System.IO.File.WriteAllText("reulst.csv", writeData.ToString());
|
||||
Console.WriteLine("write result.csv, count : " + detailDatas.Count);
|
||||
}
|
||||
static List<Config.Information> GetInformation(Config config)
|
||||
{
|
||||
List<Config.Information> informations = new List<Config.Information>();
|
||||
foreach (var nvr in config.NVR)
|
||||
{
|
||||
try
|
||||
{
|
||||
string connectionString = String.Format("server={0};port=3306;database={1};user={2};password={3}", nvr.IpAddress, "leopard", "root", "ehtlrhdtk1!");
|
||||
MySqlConnection mySqlConnection = new MySqlConnection(connectionString);
|
||||
mySqlConnection.Open();
|
||||
MySqlCommand sqlCommand = new MySqlCommand("Select name, addr,id,password From tbl_camera where IsDeleted='0'", mySqlConnection);
|
||||
using (MySqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
|
||||
{
|
||||
while (sqlDataReader.Read())
|
||||
{
|
||||
Config.Information information = new Config.Information();
|
||||
|
||||
information.Name = sqlDataReader["name"].ToString();
|
||||
information.IpAddress = sqlDataReader["addr"].ToString();
|
||||
|
||||
informations.Add(information);
|
||||
;
|
||||
}
|
||||
}
|
||||
mySqlConnection.Close();
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Console.WriteLine(nvr.Name + " : " + ex.Message + Environment.NewLine);
|
||||
}
|
||||
|
||||
}
|
||||
if(informations.Count < 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return informations;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user