/// <summary> /// Get Symbol and data type (quotes or dom) from dde conversation object /// </summary> /// <returns></returns> protected void GetDataType(DdeConversation conversation, out string symbol, out string dataType) { // Check format like "[SBER03]Quotes" Regex regex = new Regex(@"\[(?<Symbol>.*)\](?<DataType>.*)"); Match match = regex.Match(conversation.Topic); symbol = match.Groups["Symbol"].Value; dataType = match.Groups["DataType"].Value; // If no symbol, format like "SBER03" if (string.IsNullOrEmpty(symbol)) { symbol = conversation.Topic; } }
protected override RequestResult OnRequest(DdeConversation conversation, string item, int format) { Console.WriteLine("OnRequest:".PadRight(16) + " Service='" + conversation.Service + "'" + " Topic='" + conversation.Topic + "'" + " Handle=" + conversation.Handle.ToString() + " Item='" + item + "'" + " Format=" + format.ToString()); // Return data to the client only if the format is CF_TEXT. if (format == 1) { return(new RequestResult(System.Text.Encoding.ASCII.GetBytes("Time=" + DateTime.Now.ToString() + "\0"))); } return(DdeServer.RequestResult.NotProcessed); }
/// <summary> /// /// </summary> /// <param name="conversation"></param> /// <param name="item"></param> /// <param name="data"></param> /// <param name="format"></param> /// <returns></returns> protected override PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format) { if (this.pokeCallback != null) { this.pokeCallback.Invoke( conversation.Handle, conversation.IsPaused, conversation.Service, conversation.Topic, conversation.Tag, item, data); } return(PokeResult.Processed); }
protected override PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format) { var newCandles = new DdeCandlesParser().Parse(data); if (newCandles.SequenceEqual(_candles) == false) { _candles = newCandles; if (DataChanged != null) { DataChanged(this, EventArgs.Empty); } } return(PokeResult.Processed); }
protected override bool OnStartAdvise(DdeConversation conversation, string item, int format) { var obj = new Dictionary <string, object>(); obj["service"] = conversation.Service; obj["topic"] = conversation.Topic; obj["handle"] = conversation.Handle; obj["item"] = item; obj["format"] = format; var tcs = new TaskCompletionSource <bool>(); Task.Run(async() => { var result = await _OnStartAdvise(obj); tcs.SetResult((bool)result); }); return(tcs.Task.Result); }
protected override RequestResult OnRequest(DdeConversation conversation, string item, int format) { if (format == 1) { string key = item; try { QuoteItem tmpddeItem = sendData[key]; return(new RequestResult(sendData[key].value)); //return new RequestResult(dic_clients[tmpddeItem.collectServer + "|"+ tmpddeItem.collectTopic].Request(tmpddeItem.collectItem,1,1000)); } catch { //return new RequestResult(sendData[key].value); } } return(RequestResult.NotProcessed); }
protected override PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format) { base.OnPoke(conversation, item, data, format); string key = conversation.Topic + ":" + item + ":" + format.ToString(); _Data[key] = data; switch (item) { case "#NotProcessed": { return(PokeResult.NotProcessed); } case "#PauseConversation": { if ((string)conversation.Tag == item) { conversation.Tag = null; return(PokeResult.Processed); } conversation.Tag = item; if (!_Timer.Enabled) { _Timer.Start(); } return(PokeResult.PauseConversation); } case "#Processed": { return(PokeResult.Processed); } case "#TooBusy": { return(PokeResult.TooBusy); } } return(PokeResult.Processed); }
/// <summary> /// Catch DDE Data /// </summary> /// <param name="conversation"></param> /// <param name="item"></param> /// <param name="data"></param> /// <param name="format"></param> /// <returns></returns> protected override PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format) { //QuikLoader.StaticDataLoadedSync.WaitOne(); object[][] table = XLTable.Cells(data); string symbol = null; string dataType = null; GetDataType(conversation, out symbol, out dataType); switch (dataType.ToLower()) { case "dom": // Dom data load Dom.DomLoader.AddSnapShotFromDde(symbol, table); break; case "quotes": default: // Load quotes data QuikQuotesLoader.AddQuotesFromDde(table); break; } Trace.WriteLine("OnPoke:".PadRight(16) + " Service='" + conversation.Service + "'" + " Topic='" + conversation.Topic + "'" + " Handle=" + conversation.Handle.ToString() + " Item='" + item + "'" + " Data=" + data.Length.ToString() + " Format=" + format.ToString()); // Static data is loaded sygnal // QuikLoader.StaticDataLoadedSync.Set(); // Tell the client that the data was processed. return(PokeResult.Processed); }
protected override ExecuteResult OnExecute(DdeConversation conversation, string command) { base.OnExecute(conversation, command); _Command = command; switch (command) { case "#NotProcessed": { return(ExecuteResult.NotProcessed); } case "#PauseConversation": { if ((string)conversation.Tag == command) { conversation.Tag = null; return(ExecuteResult.Processed); } conversation.Tag = command; if (!_Timer.Enabled) { _Timer.Start(); } return(ExecuteResult.PauseConversation); } case "#Processed": { return(ExecuteResult.Processed); } case "#TooBusy": { return(ExecuteResult.TooBusy); } } return(ExecuteResult.Processed); }
protected override bool OnStartAdvise(DdeConversation conversation, string item, int format) { base.OnStartAdvise(conversation, item, format); return true; }
protected override ExecuteResult OnExecute(DdeConversation conversation, string command) { Console.WriteLine("OnExecute"); return(ExecuteResult.Processed); }
protected override void OnDisconnect(DdeConversation conversation) { base.OnDisconnect(conversation); _Conversation.Remove(conversation.Handle); }
protected override RequestResult OnRequest(DdeConversation conversation, string item, int format) { return(base.OnRequest(conversation, item, format)); }
protected override PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format) { //IRC에서 폰으로 int getValueLength = byteArrayDefrag(data); //string AndroData = item + " " + Encoding.UTF8.GetString(data, 0, getValueLength + 1); // 저장 string AndroData = item + " " + Encoding.GetEncoding("utf-8").GetString(data, 0, getValueLength + 1); // 저장 string[] tmp = AndroData.Split(' ', ''); // DDE를 통해 받은 데이터를 분할 string[] tmp2 = new string[1024]; if (item == "[인증]") { client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); client.Connect("210.118.69.193", 5001); //인증 서버 주소 string authkey = tmp[1] + "+" + Dns.GetHostAddresses(Dns.GetHostName())[3] + "\r\n"; byte[] key = Encoding.Default.GetBytes(authkey); client.Send(key); Console.WriteLine("인증 시도 중"); byte[] resp = new byte[1024]; try { client.Receive(resp); } catch { } string auth_check = Encoding.UTF8.GetString(resp).Replace("\0", "").Replace("\r", "\r\n"); if (auth_check.Contains("success")) { string[] reg = auth_check.Split('&'); Properties.Settings.Default.gcm_id = reg[1]; Properties.Settings.Default.gcm_msg = "auth_success"; Console.WriteLine("인증 완료 : " + reg[1]); } else if (auth_check.Contains("fail")) { Properties.Settings.Default.gcm_msg = "auth_fail"; } Properties.Settings.Default.Save(); client.Shutdown(SocketShutdown.Both); client.Close(); } else if (item == "[인증해제]") { //client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //client.Connect("210.118.69.193", 5001); //인증 서버 주소 //string authkey = Dns.GetHostAddresses(Dns.GetHostName())[3] + "\r\n"; //byte[] key = Encoding.Default.GetBytes(authkey); //client.Send(key); //Console.WriteLine("인증해제 시도 중"); //byte[] resp = new byte[10]; //try { client.Receive(resp); } //catch { } //string auth_check = Encoding.UTF8.GetString(resp); //if (auth_check.Contains("deleted")) //{ GCM.request(item, null, null, null, null, Properties.Settings.Default.gcm_id); Properties.Settings.Default.gcm_msg = "auth_cancel"; Properties.Settings.Default.gcm_id = null; Console.WriteLine("인증해제 완료"); //} //else if (auth_check.Contains("fail")) Properties.Settings.Default.gcm_msg = "auth_fail"; //Properties.Settings.Default.Save(); //client.Shutdown(SocketShutdown.Both); //client.Close(); } else if (item == "[폰인증해제]") { Properties.Settings.Default.gcm_msg = "auth_cancel"; Properties.Settings.Default.gcm_id = null; Console.WriteLine("인증해제 완료"); } else if (item == "[정보]") { string[] Adata = AndroData.Split('㎯'); // DDE를 통해 받은 데이터를 분할 int cnt = Adata.Count(); //주소(공통) string[] address = Adata[0].Split(':'); whois.address = address[1]; //사용자명(공통) string[] name = Adata[1].Split(':'); whois.name = name[1]; //채널 string[] chan = Adata[2].Split(':'); if (chan[0].Contains("채널")) { whois.chanlist = chan[1]; } else { whois.chanlist = "없음"; } //서버 string[] server = Adata[3].Split(':'); if (server[0].Contains("서버")) { whois.server = server[1]; } // 상태 string[] state = Adata[4].Split(':'); if (state[0].Contains("상태")) { whois.state = state[1]; } else { whois.state = "없음"; } //유휴시간 string[] idle = Adata[5].Split(':'); if (idle[0].Contains("유휴시간")) { whois.idle = idle[1]; } //접속일시 string[] time = Adata[6].Split(':'); if (time[0].Contains("접속일시")) { whois.time = time[1]; } //인증 string[] auth = Adata[7].Split(':'); if (auth[0].Contains("인증")) { whois.auth = auth[1]; } else { whois.auth = "없음"; } } else if (tmp[0] == "[채널모드]" || tmp[0] == "[입장]" || tmp[0] == "[퇴장]" || tmp[0] == "[대화]" || tmp[0] == "[호출]" || tmp[0] == "[옵]" || tmp[0] == "[디옵]" || tmp[0] == "[보이스]" || tmp[0] == "[디보이스]" || tmp[0] == "[토픽변경]" || tmp[0] == "[킥]" || tmp[0] == "[밴]" || tmp[0] == "[언밴]" || tmp[0] == "[강조]") { Array.Copy(tmp, tmp2, tmp.Length); // tmp를 tmp2로 복사 Array.Clear(tmp2, 0, 4); // tmp2에서 메세지를 제외하고 삭제 string msg = string.Join(" ", tmp2, 4, tmp.Length - 4); // 문자열 배열을 문자열로 변경 i_list.type = tmp[0]; i_list.timestamp = tmp[1]; i_list.chan = tmp[2]; i_list.nick = tmp[3]; i_list.msg = msg; if (tmp[0] == "[호출]" || tmp[0] == "[강조]") // 대화도 추가해야함 { GCM.request(i_list.type, i_list.timestamp, i_list.chan, i_list.nick, i_list.msg, Properties.Settings.Default.gcm_id); } } else if (tmp[0] == "[내대화]") { Array.Copy(tmp, tmp2, tmp.Length); // tmp를 tmp2로 복사 Array.Clear(tmp2, 0, 3); // tmp2에서 메세지를 제외하고 삭제 string msg = string.Join(" ", tmp2, 3, tmp.Length - 3); // 문자열 배열을 문자열로 변경 i_list.type = tmp[0]; i_list.timestamp = tmp[1]; i_list.chan = tmp[2]; i_list.nick = null; i_list.msg = msg; } else if (tmp[0] == "[에러]" || tmp[0] == "[알림]") { Array.Copy(tmp, tmp2, tmp.Length); // tmp를 tmp2로 복사 Array.Clear(tmp2, 0, 1); // tmp2에서 메세지를 제외하고 삭제 string msg = string.Join(" ", tmp2, 2, tmp.Length - 2); // 문자열 배열을 문자열로 변경 i_list.type = tmp[0]; i_list.timestamp = tmp[1]; i_list.chan = null; i_list.nick = null; i_list.msg = msg; } else if (tmp[0] == "[초대]") { i_list.type = tmp[0]; i_list.timestamp = tmp[1]; i_list.chan = tmp[2]; i_list.nick = tmp[3]; i_list.msg = null; GCM.request(i_list.type, i_list.timestamp, i_list.chan, i_list.nick, i_list.msg, Properties.Settings.Default.gcm_id); } else if (tmp[0] == "[내입장]" || tmp[0] == "[내퇴장]") { i_list.type = tmp[0]; i_list.timestamp = tmp[1]; i_list.chan = tmp[2]; i_list.nick = null; if (tmp.Length > 3) { i_list.msg = tmp[3]; } else { i_list.msg = null; } } else if (tmp[0] == "[내대화명변경]") { i_list.type = tmp[0]; i_list.timestamp = tmp[1]; i_list.chan = null; i_list.nick = null; i_list.msg = tmp[2]; } else if (tmp[0] == "[귓말대화]" || tmp[0] == "[대화명변경]" || tmp[0] == "[귓말호출]" || tmp[0] == "[종료]" || tmp[0] == "[노티스]") { Array.Copy(tmp, tmp2, tmp.Length); // tmp를 tmp2로 복사 Array.Clear(tmp2, 0, 3); // tmp2에서 메세지를 제외하고 삭제 string msg = string.Join(" ", tmp2, 3, tmp.Length - 3); // 문자열 배열을 문자열로 변경 i_list.type = tmp[0]; i_list.timestamp = tmp[1]; i_list.chan = null; i_list.nick = tmp[2]; i_list.msg = msg; if (tmp[0] == "[귓말호출]" || tmp[0] == "[귓말대화]") { GCM.request(i_list.type, i_list.timestamp, i_list.chan, i_list.nick, i_list.msg, Properties.Settings.Default.gcm_id); } } else if (tmp[0] == "[닉목록]" || tmp[0] == "[닉목록1]" || tmp[0] == "[닉목록2]" || tmp[0] == "[닉목록3]" || tmp[0] == "[닉목록4]" || tmp[0] == "[닉목록5]") { Array.Copy(tmp, tmp2, tmp.Length); // tmp를 tmp2로 복사 if (tmp.Length > 3) { Array.Clear(tmp2, 0, 4); // tmp2에서 메세지를 제외하고 삭제 string msg = string.Join(" ", tmp2, 4, tmp.Length - 4); // 문자열 배열을 문자열로 변경 i_list.type = tmp[0]; i_list.timestamp = tmp[1]; i_list.chan = tmp[2]; i_list.nick = tmp[3]; i_list.msg = msg; } } else if (tmp[0] == "[채널목록]" || tmp[0] == "[대화목록]" || tmp[0] == "[내닉네임]") { i_list.type = tmp[0]; i_list.timestamp = null; i_list.chan = null; i_list.nick = null; i_list.msg = tmp[1]; if (tmp[1] == "n#ull") { i_list.msg = null; } } else if (item == "[현재토픽]" || tmp[0] == "[강조추가]" || tmp[0] == "[강조삭제]") { Array.Copy(tmp, tmp2, tmp.Length); // tmp를 tmp2로 복사 Array.Clear(tmp2, 0, 1); // tmp2에서 메세지를 제외하고 삭제 string msg = string.Join(" ", tmp2, 1, tmp.Length - 1); // 문자열 배열을 문자열로 변경 i_list.type = tmp[0]; i_list.timestamp = null; i_list.chan = null; i_list.nick = null; i_list.msg = msg; } else if (item == "[shutdown]") { Environment.Exit(0); } else if (tmp[0] == "[GCM]") { Array.Copy(tmp, tmp2, tmp.Length); // tmp를 tmp2로 복사 Array.Clear(tmp2, 0, 5); // tmp2에서 메세지를 제외하고 삭제 string msg = string.Join(" ", tmp2, 5, tmp.Length - 5); // 문자열 배열을 문자열로 변경 i_list.type = tmp[1]; i_list.timestamp = tmp[2]; i_list.chan = tmp[3]; i_list.nick = tmp[4]; i_list.msg = msg; GCM.request(i_list.type, i_list.timestamp, i_list.chan, i_list.nick, i_list.msg, Properties.Settings.Default.gcm_id); } else if (tmp[0] == "[DDE]") { Properties.Settings.Default.gcm_msg = "dde_state"; Properties.Settings.Default.Save(); } else { Console.WriteLine("알 수 없는 데이터 : " + AndroData); } try { if (clientSocket.Connected && (i_list.type != null || whois.server != null)) { send_data = JsonConvert.SerializeObject(i_list); if (whois.server != null) { send_data = JsonConvert.SerializeObject(whois); } Data = Encoding.UTF8.GetBytes(send_data); byte[] sData = new byte[Data.Length + 2]; sData[0] = 0x02; Data.CopyTo(sData, 1); Array.Copy(Data, 0, sData, 1, Data.Length); sData[Data.Length + 1] = 0x03; // 전송 clientSocket.Send(sData); Console.WriteLine("[송신] " + send_data); // MONITOR i_list.type = i_list.timestamp = i_list.chan = i_list.nick = i_list.msg = null; whois.address = whois.name = whois.server = whois.chanlist = whois.state = whois.idle = whois.time = whois.idle = null; } else { // 저장 send_data = JsonConvert.SerializeObject(i_list); if (i_list.type != "[내입장]" && i_list.type != null) { File.AppendAllText("DDE_Logger.txt", send_data + "\r\n", Encoding.Default); Console.WriteLine("[기록] " + send_data); } } } catch (Exception) { // 저장 send_data = JsonConvert.SerializeObject(i_list); if (i_list.type != "[내입장]" && i_list.type != null) { File.AppendAllText("DDE_Logger.txt", send_data + "\r\n", Encoding.Default); Console.WriteLine("[기록] " + send_data); } } return(PokeResult.Processed); }
protected override RequestResult OnRequest(DdeConversation conversation, string item, int format) { return(RequestResult.NotProcessed); }
protected override void OnStopAdvise(DdeConversation conversation, string item) { Console.WriteLine("OnStopAdvise"); }
// -------------------------------------------------------------- protected override void OnDisconnect(DdeConversation c) { ((XlDdeChannel)c.Tag).IsConnected = false; }
protected override bool OnStartAdvise(DdeConversation conversation, string item, int format) { Console.WriteLine("OnStartAdvise"); return(format == 1); }
protected override void OnDisconnect(DdeConversation conversation) { Console.WriteLine("OnDisconnect"); }
protected override PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format) { Console.WriteLine("OnPoke"); return(PokeResult.Processed); }
protected override void OnStopAdvise(DdeConversation conversation, string item) { base.OnStopAdvise(conversation, item); }
public override void Pause(DdeConversation conversation) { base.Pause(conversation); }
protected override void OnAfterConnect(DdeConversation conversation) { base.OnAfterConnect(conversation); _Conversation.Add(conversation.Handle, conversation); }
protected override void OnDisconnect(DdeConversation conversation) { LOGGER.Info("QuikServerDde disconnected."); }
public override void Disconnect(DdeConversation conversation) { base.Disconnect(conversation); }
protected override bool OnStartAdvise(DdeConversation conversation, string item, int format) { return(format == 1); }
// -------------------------------------------------------------- protected override void OnDisconnect(DdeConversation dc) { ((XlDdeChannel)dc.Tag).RemoveConversation(dc); }
protected override ExecuteResult OnExecute(DdeConversation conversation, string command) { return(ExecuteResult.Processed); }
protected override void OnAfterConnect(DdeConversation conversation) { }
protected override void OnAfterConnect(DdemlConversation conversation) { var c = new DdeConversation(conversation); conversation.Tag = c; _Parent.OnAfterConnect(c); }