using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using NLog;
using ZeroMQ;
using ZeroMQ.Monitoring;
using System.Threading;
using System.IO;                // StreamReader

namespace SendData
{
    public class Send
    {
        static Logger log = LogManager.GetLogger("agent_logger");

        // CSProject send trc file content to RecvProject
        public void SendTrc(String ip, String port, String trc_name, String home_path)
        {
            // zeromq socket send
            using (var socket = new ZSocket(ZSocketType.DEALER))
            {
                log.Debug("zeromq socket send start");

                // socket connect
                String conn = String.Format("tcp://{0}:{1}", ip, port);
                socket.Connect(conn);

                try
                {
                    ProcessFile.Files process_file = new ProcessFile.Files();

                    // trc 파일 읽어오기
                    String path = home_path + "dat\\" + trc_name + ".trc";

                    byte[] data_buffer = process_file.OpenTrcFile(path);

                    // trc 파일 내용 전송
                    socket.Send(new ZFrame(data_buffer), ZSocketFlags.DontWait);
                    log.Debug("send don't wait flag.");
                } catch(Exception e)
                {
                    log.Error(e.ToString());
                    Console.WriteLine("send error");
                }
                socket.Close();
            }
        }
    }
}
