This commit is contained in:
chi
2020-04-17 08:17:10 +09:00
parent 6565f2bacc
commit a98072ab75
12 changed files with 492 additions and 0 deletions

View File

@@ -0,0 +1,47 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.40629.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FTP_DB_Adapt", "FTP_DB_Adapt\FTP_DB_Adapt.csproj", "{BECE73DE-15C8-42B0-9F93-9484D745DF3A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FTPClass", "FTP_DB_Adapt\Sub\arftp\FTPClass.csproj", "{150859D3-1C5D-4E20-B324-F9EBE188D893}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArLog", "FTP_DB_Adapt\Sub\arLog_CSharp\ArLog.csproj", "{E9E16A98-8F8D-4848-A27E-4571C184FB1A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "arSetting", "FTP_DB_Adapt\Sub\arSetting\arSetting.csproj", "{8870CE55-DF29-4E05-92FA-6D251DE4EC6C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sub", "Sub", "{97A5415A-4C67-4C76-95E6-4AB406BF67CD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BECE73DE-15C8-42B0-9F93-9484D745DF3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BECE73DE-15C8-42B0-9F93-9484D745DF3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BECE73DE-15C8-42B0-9F93-9484D745DF3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BECE73DE-15C8-42B0-9F93-9484D745DF3A}.Release|Any CPU.Build.0 = Release|Any CPU
{150859D3-1C5D-4E20-B324-F9EBE188D893}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{150859D3-1C5D-4E20-B324-F9EBE188D893}.Debug|Any CPU.Build.0 = Debug|Any CPU
{150859D3-1C5D-4E20-B324-F9EBE188D893}.Release|Any CPU.ActiveCfg = Release|Any CPU
{150859D3-1C5D-4E20-B324-F9EBE188D893}.Release|Any CPU.Build.0 = Release|Any CPU
{E9E16A98-8F8D-4848-A27E-4571C184FB1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9E16A98-8F8D-4848-A27E-4571C184FB1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9E16A98-8F8D-4848-A27E-4571C184FB1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9E16A98-8F8D-4848-A27E-4571C184FB1A}.Release|Any CPU.Build.0 = Release|Any CPU
{8870CE55-DF29-4E05-92FA-6D251DE4EC6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8870CE55-DF29-4E05-92FA-6D251DE4EC6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8870CE55-DF29-4E05-92FA-6D251DE4EC6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8870CE55-DF29-4E05-92FA-6D251DE4EC6C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{150859D3-1C5D-4E20-B324-F9EBE188D893} = {97A5415A-4C67-4C76-95E6-4AB406BF67CD}
{E9E16A98-8F8D-4848-A27E-4571C184FB1A} = {97A5415A-4C67-4C76-95E6-4AB406BF67CD}
{8870CE55-DF29-4E05-92FA-6D251DE4EC6C} = {97A5415A-4C67-4C76-95E6-4AB406BF67CD}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FTP_DB_Adapt
{
public class CSetting : arUtil.Setting
{
public string connstr { get; set; }
public string ftphost { get; set; }
public string ftpid { get; set; }
public string ftppw { get; set; }
public override void AfterLoad()
{
if (connstr == "")
connstr = "Data Source=10.131.15.18;Initial Catalog=EE;Persist Security Info=True;User ID=eeuser;Password=Amkor123!";
}
public override void AfterSave()
{
//throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BECE73DE-15C8-42B0-9F93-9484D745DF3A}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FTP_DB_Adapt</RootNamespace>
<AssemblyName>FTP_DB_Adapt</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="ArLog.Net4">
<HintPath>..\..\DLL\ArLog.Net4.dll</HintPath>
</Reference>
<Reference Include="ArSetting.Net4">
<HintPath>..\..\DLL\ArSetting.Net4.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\DLL\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CSetting.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Sub\arftp\FTPClass.csproj">
<Project>{150859d3-1c5d-4e20-b324-f9ebe188d893}</Project>
<Name>FTPClass</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,236 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace FTP_DB_Adapt
{
class Program
{
static System.Data.SqlClient.SqlConnection cn;
static System.Data.SqlClient.SqlCommand cmd;
static System.Data.SqlClient.SqlDataAdapter da;
static arUtil.FTPClient.FTPClient ftp;
static CSetting setting;
static arUtil.Log log;
static string lastfile = "";
static DateTime lasttime = DateTime.Now;
class retdata
{
public int count { get; set; }
public System.Data.DataTable result { get; set; }
public string message { get; set; }
}
static void Main(string[] args)
{
//var jstest = JsonConvert.SerializeObject(retval);
// var jsontest = "{\"count\":1,\"result\":[{\"id\":\"395552\",\"password\":\"B6589FC6AB0DC82CF12099D1C2D40AB994E8410C\",\"nameE\":\"Chikyun.Kim\",\"name\":\"<22><>ġ<EFBFBD><C4A1>\",\"dept\":\"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> K4<4B><34><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>Ʈ\",\"grade\":\"å<><C3A5>\",\"email\":\"Chikyun.Kim@amkor.co.kr\",\"level\":1,\"indate\":\"2018-04-11\",\"outdate\":null";
/// var json = JObject.Parse(jsontest);
// // var cnt = json["count"];
cw("setting load");
setting = new CSetting();
setting.Load();
if (setting.Xml.Exist() == false)
{
setting.Xml.CreateFile();
cw("setting file created");
}
if (setting.ftphost == "")
{
setting.ftphost = "ftp.amkor.co.kr";
setting.ftpid = "k4pcbmgr";
setting.ftppw = "W2$fYiXp";
setting.Save();
cw("setting default");
}
cw(string.Format("ftp info - {0}", setting.ftphost));
Properties.Settings.Default["cs"] = setting.connstr; // "Data Source=10.131.15.18;Initial Catalog=EE;Persist Security Info=True;User ID=eeuser;Password=Amkor123!";
cw("program start v191212-0950" );
cn = new System.Data.SqlClient.SqlConnection(Properties.Settings.Default.cs);
DateTime conntime = DateTime.Now;
//ftp = new arUtil.FTPClient();
while(true)
{
if(cn.State == System.Data.ConnectionState.Open)
{
if(ftp == null)
{
ftp = new arUtil.FTPClient.FTPClient();
ftp.Host = setting.ftphost;
ftp.UserPassword = setting.ftppw;
ftp.UserID = setting.ftpid;
ftp.Port = 21;
cw(string.Format("ftp Initialize {0}",ftp.Host));
}
//monitor file list
string path = "/2D TEST/101369103/Log/QryResult";
var list = ftp.directoryListSimple(path);
var sqllist = list.Where(t => t.ToLower().EndsWith(".sql"));
DateTime findtime = DateTime.Parse("1982-11-23");
foreach(var sqlfile in sqllist)
{
string fn = sqlfile.Substring(0, sqlfile.Length - 3);
string resultfile = fn + "json";
if (list.Contains(resultfile)) continue;
if(lastfile == sqlfile)
{
var ts = DateTime.Now - lasttime;
if (ts.TotalSeconds < 3) continue; //3초이내 연속 실행 불가
}
//다운로드전에 무조건 대기해준다.
System.Threading.Thread.Sleep(200);
// //이파일명에 해당하는 json 파일을 찾는다.
// string rltfile =
var file_local = AppDomain.CurrentDomain.BaseDirectory + sqlfile;
var file_remote = path + "/" + sqlfile;
try
{
if (System.IO.File.Exists(file_local)) System.IO.File.Delete(file_local);
cw(string.Format("Down {0} to {1}",file_remote, file_local));
lastfile = sqlfile;
lasttime = DateTime.Now;
if(ftp.Download(file_remote,file_local))
{
retdata retval = new retdata();
retval.count = 0;
retval.result = null;
retval.message = "";
cw("download ok : " + file_remote);
var jsonStr = "";
var sql = System.IO.File.ReadAllText(file_local, System.Text.Encoding.Default);
if (cmd == null) cmd = new System.Data.SqlClient.SqlCommand(sql);
var downfi = new System.IO.FileInfo(file_local);
if (downfi.Length < 1)
{
retval.message = "0byte File Downaloaded : " + file_local;
}
else if(sql.Trim() == "")
{
retval.message = "No Sql data";
}
else
{
cmd.CommandText = sql;
cmd.Connection = cn;
if (cn.State == System.Data.ConnectionState.Closed) cn.Open();
if (sql.ToLower().StartsWith("select"))
{
cw("select query");
//data table
if (da == null) da = new System.Data.SqlClient.SqlDataAdapter(cmd);
using (var ds = new System.Data.DataSet())
{
try
{
da.Fill(ds);
if (ds != null && ds.Tables.Count > 0)
{
retval.result = ds.Tables[0];
retval.count = retval.result.Rows.Count;
}
}
catch (Exception ex)
{
retval.message = ex.Message + ",sql=" + sql;
}
}
}
else
{
cw("non query");
//insert /update/ delete
cmd.Connection = cn;
try
{
retval.count = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
retval.message = ex.Message + ",sql=" + sql;
}
}
jsonStr = JsonConvert.SerializeObject(retval);
if (jsonStr != "")
{
file_local = AppDomain.CurrentDomain.BaseDirectory + resultfile;
System.IO.File.WriteAllText(file_local, jsonStr, System.Text.Encoding.Default);
cw("result file save : " + file_local);
file_remote = path + "/" + resultfile;
if (!ftp.Upload(file_remote, file_local))
cw("ftp Upload error remote = " + file_remote + "," + file_local);
}
}
}
else
{
cw("ftp down error remote = " + file_remote);
}
}
catch (Exception ex)
{
cw("conn error:" + ex.Message);
}
}
}
else
{
var ts = DateTime.Now - conntime;
if(ts.TotalSeconds > 5)
{
try
{
cw("Try Database Connect ");
cn.Open();
cw("Database Connected\n\nFTP Monitor ON");
}
catch (Exception ex)
{
cw("conn error:" + ex.Message);
}
finally
{
conntime = DateTime.Now;
}
}
}
System.Threading.Thread.Sleep(1);
}
}
static void cw(string msg,Boolean logon=true)
{
if(log == null)
{
log = new arUtil.Log();
}
if (logon) log.Add(msg);
Console.WriteLine(msg);
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리의 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
[assembly: AssemblyTitle("FTP_DB_Adapt")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FTP_DB_Adapt")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하십시오.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("0d606978-0719-4d02-aea0-740db9f2a058")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 버전이 자동으로
// 지정되도록 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("19.12.12.0950")]
[assembly: AssemblyFileVersion("19.12.12.0950")]

View File

@@ -0,0 +1,37 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 이 코드는 도구를 사용하여 생성되었습니다.
// 런타임 버전:4.0.30319.42000
//
// 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면
// 이러한 변경 내용이 손실됩니다.
// </auto-generated>
//------------------------------------------------------------------------------
namespace FTP_DB_Adapt.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
[global::System.Configuration.DefaultSettingValueAttribute("Data Source=10.131.15.18;Initial Catalog=EE;Persist Security Info=True;User ID=ee" +
"user;Password=EEmicro123!")]
public string cs {
get {
return ((string)(this["cs"]));
}
}
}
}

View File

@@ -0,0 +1,14 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="FTP_DB_Adapt.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="cs" Type="(Connection string)" Scope="Application">
<DesignTimeValue Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;ConnectionString&gt;Data Source=10.131.15.18;Initial Catalog=EE;Persist Security Info=True;User ID=eeuser;Password=EEmicro123!&lt;/ConnectionString&gt;
&lt;ProviderName&gt;System.Data.SqlClient&lt;/ProviderName&gt;
&lt;/SerializableConnectionString&gt;</DesignTimeValue>
<Value Profile="(Default)">Data Source=10.131.15.18;Initial Catalog=EE;Persist Security Info=True;User ID=eeuser;Password=EEmicro123!</Value>
</Setting>
</Settings>
</SettingsFile>

Submodule FTP_DB_Adapt/FTP_DB_Adapt/Sub/arLog_CSharp added at 106f873d37

Submodule FTP_DB_Adapt/FTP_DB_Adapt/Sub/arSetting added at a09d4eb9f8

Submodule FTP_DB_Adapt/FTP_DB_Adapt/Sub/arftp added at 0826cbe09b

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="FTP_DB_Adapt.Properties.Settings.cs" connectionString="Data Source=10.131.15.18;Initial Catalog=EE;Persist Security Info=True;User ID=eeuser;Password=EEmicro123!" providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

Binary file not shown.