protected override void OnDisconnect(DdeConversation conversation) { Console.WriteLine("OnDisconnect:".PadRight(16) + " Service='" + conversation.Service + "'" + " Topic='" + conversation.Topic + "'" + " Handle=" + conversation.Handle.ToString()); }
// ********************************************************************** public void AddConversation(DdeConversation dc) { lock(conversations) conversations.Add(dc); if(ConversationAdded != null) ConversationAdded(); }
// ********************************************************************** public override void Disconnect(DdeConversation dc) { XlDdeChannel channel; if(channels.TryGetValue(dc.Topic, out channel)) channel.RemoveConversation(dc); base.Disconnect(dc); }
protected override ExecuteResult OnExecute(DdeConversation conversation, string command) { Console.WriteLine("OnExecute:".PadRight(16) + " Service='" + conversation.Service + "'" + " Topic='" + conversation.Topic + "'" + " Handle=" + conversation.Handle.ToString() + " Command='" + command + "'"); return base.OnExecute(conversation, command); }
// ********************************************************************** public void RemoveConversation(DdeConversation dc) { bool removed; lock(conversations) removed = conversations.Remove(dc); if(removed && ConversationRemoved != null) ConversationRemoved(); }
protected override PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format) { Console.WriteLine("OnPoke:".PadRight(16) + " Service='" + conversation.Service + "'" + " Topic='" + conversation.Topic + "'" + " Handle=" + conversation.Handle.ToString() + " Item='" + item + "'" + " Data=" + data.Length.ToString() + " Format=" + format.ToString()); return base.OnPoke(conversation, item, data, format); }
protected override PokeResult OnPoke(NDde.Server.DdeConversation conversation, string item, byte[] data, int format) { l.Debug("OnPoke " + conversation.Topic); switch (conversation.Topic) { case "[ALL_DEAL]ALL_DEAL": AllDealQueue.Add(data); break; } return(PokeResult.Processed); }
/// <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; }
/// <overloads> /// <summary> /// </summary> /// </overloads> /// <summary> /// This terminates the specified conversation. /// </summary> /// <param name="conversation"> /// The conversation to terminate. /// </param> /// <exception cref="ArgumentNullException"> /// This is thrown when conversation is a null reference. /// </exception> /// <exception cref="InvalidOperationException"> /// This is thrown when the server is not registered. /// </exception> /// <exception cref="DdeException"> /// This is thrown when the conversation could not be terminated. /// </exception> public virtual void Disconnect(DdeConversation conversation) { ThreadStart method = delegate { DdemlObject.Disconnect(conversation.DdemlObject); }; try { Context.Invoke(method); } catch (DdemlException e) { throw new DdeException(e); } catch (ObjectDisposedException e) { throw new ObjectDisposedException(GetType().ToString(), e); } }
/// <overloads> /// <summary> /// </summary> /// </overloads> /// <summary> /// This resumes the specified conversation. /// </summary> /// <param name="conversation"> /// The conversation to resume. /// </param> /// <exception cref="ArgumentNullException"> /// This is thrown when conversation is a null reference. /// </exception> /// <exception cref="InvalidOperationException"> /// This is thrown when the conversation is not paused or when the server is not registered. /// </exception> /// <exception cref="DdeException"> /// This is thrown when the conversation could not be resumed. /// </exception> public virtual void Resume(DdeConversation conversation) { ThreadStart method = delegate() { DdemlObject.Resume(conversation.DdemlObject); }; try { Context.Invoke(method); } catch (DdemlException e) { throw new DdeException(e); } catch (ArgumentException e) { throw e; } catch (ObjectDisposedException e) { throw new ObjectDisposedException(this.GetType().ToString(), e); } }
/// <summary> /// This is invoked when a client terminates a conversation. /// </summary> /// <param name="conversation"> /// The conversation associated with this event. /// </param> protected virtual void OnDisconnect(DdeConversation conversation) { }
protected override PokeResult OnPoke(DdeConversation c, string item, byte[] data, int format) { ((DataChannel)c.Tag).PutDdeData(data); return PokeResult.Processed; }
protected override void OnAfterConnect(DdeConversation c) { DataChannel channel = Channels[c.Topic]; c.Tag = channel; channel.IsConnected = true; }
protected override PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format) { var obj = new Dictionary<string, object>(); obj["service"] = conversation.Service; obj["topic"] = conversation.Topic; obj["handle"] = conversation.Handle; obj["item"] = item; obj["data"] = Encoding.Default.GetString(data); obj["format"] = format; var tcs = new TaskCompletionSource<string>(); Task.Run(async () => { var result = await _OnPoke(obj); tcs.SetResult((string)result); }); switch (tcs.Task.Result) { case "NotProcessed": return PokeResult.NotProcessed; case "PauseConversation": return PokeResult.PauseConversation; case "TooBusy": return PokeResult.TooBusy; default: return PokeResult.Processed; } }
protected override void OnAfterConnect(DdeConversation conversation) { var obj = new Dictionary<string, object>(); obj["service"] = conversation.Service; obj["topic"] = conversation.Topic; obj["handle"] = conversation.Handle; Task.Run(() => _OnAfterConnect(obj)); }
/// <overloads> /// <summary> /// </summary> /// </overloads> /// <summary> /// This is invoked when a client attempts to request data. /// </summary> /// <param name="conversation"> /// The conversation associated with this event. /// </param> /// <param name="item"> /// The item name associated with this event. /// </param> /// <param name="format"> /// The format of the data. /// </param> /// <returns> /// A <c>RequestResult</c> indicating the result. /// </returns> /// <remarks> /// The default implementation returns <c>RequestResult.NotProcessed</c> to the client. /// </remarks> protected virtual RequestResult OnRequest(DdeConversation conversation, string item, int format) { return RequestResult.NotProcessed; }
protected override void OnStopAdvise(DdeConversation conversation, string item) { var obj = new Dictionary<string, object>(); obj["service"] = conversation.Service; obj["topic"] = conversation.Topic; obj["handle"] = conversation.Handle; obj["item"] = item; Task.Run(() => _OnStopAdvise(obj)); }
protected override bool OnStartAdvise(DdeConversation conversation, string item, int format) { base.OnStartAdvise(conversation, item, format); return true; }
protected override void OnStopAdvise(DdeConversation conversation, string item) { base.OnStopAdvise(conversation, item); }
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; }
protected override RequestResult OnRequest(DdeConversation conversation, string item, int format) { base.OnRequest(conversation, item, format); string key = conversation.Topic + ":" + item + ":" + format.ToString(); if (_Data.Contains(key)) { return new RequestResult((byte[])_Data[key]); } return RequestResult.NotProcessed; }
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 void OnDisconnect(DdeConversation conversation) { base.OnDisconnect(conversation); _Conversation.Remove(conversation.Handle); }
protected override DdeServer.PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format) { StreamWriter streamWriter = new StreamWriter("ddedatalength.txt", true); streamWriter.WriteLine(string.Concat("Data length: ", data.Length.ToString())); streamWriter.Close(); FileStream fileStream = new FileStream("ddedata.txt", FileMode.Append); fileStream.Write(data, 0, data.Length); fileStream.Dispose(); Data(new DdeData(data, conversation.Topic, item)); return DdeServer.PokeResult.Processed; }
/// <summary> /// This is invoked when a client sends a command. /// </summary> /// <param name="conversation"> /// The conversation associated with this event. /// </param> /// <param name="command"> /// The command to be executed. /// </param> /// <returns> /// An <c>ExecuteResult</c> indicating the result. /// </returns> /// <remarks> /// The default implementation returns <c>ExecuteResult.NotProcessed</c> to the client. /// </remarks> protected virtual ExecuteResult OnExecute(DdeConversation conversation, string command) { return ExecuteResult.NotProcessed; }
protected override void OnAfterConnect(DdeConversation conversation) { base.OnAfterConnect(conversation); _Conversation.Add(conversation.Handle, conversation); }
/// <summary> /// This is invoked when a client sends data. /// </summary> /// <param name="conversation"> /// The conversation associated with this event. /// </param> /// <param name="item"> /// The item name associated with this event. /// </param> /// <param name="data"> /// The data associated with this event. /// </param> /// <param name="format"> /// The format of the data. /// </param> /// <returns> /// A <c>PokeResult</c> indicating the result. /// </returns> /// <remarks> /// The default implementation returns <c>PokeResult.NotProcessed</c> to the client. /// </remarks> protected virtual PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format) { return PokeResult.NotProcessed; }
protected override void OnAfterConnect(DdemlConversation conversation) { DdeConversation c = new DdeConversation(conversation); conversation.Tag = c; _Parent.OnAfterConnect(c); }
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 PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format) { Console.WriteLine("OnPoke:".PadRight(16) + " Service='" + conversation.Service + "'" + " Topic='" + conversation.Topic + "'" + " Handle=" + conversation.Handle.ToString() + " Item='" + item + "'" + " Data=" + data.Length.ToString() + " Format=" + format.ToString()); // Tell the client that the data was processed. return PokeResult.Processed; }
protected override ExecuteResult OnExecute(DdeConversation conversation, string command) { var obj = new Dictionary<string, object>(); obj["service"] = conversation.Service; obj["topic"] = conversation.Topic; obj["handle"] = conversation.Handle; obj["command"] = command; var tcs = new TaskCompletionSource<string>(); Task.Run(async () => { var result = await _OnExecute(obj); tcs.SetResult((string)result); }); switch (tcs.Task.Result) { case "NotProcessed": return ExecuteResult.NotProcessed; case "PauseConversation": return ExecuteResult.PauseConversation; case "TooBusy": return ExecuteResult.TooBusy; default: return ExecuteResult.Processed; } }
protected override bool OnStartAdvise(DdeConversation conversation, string item, int format) { Console.WriteLine("OnStartAdvise:".PadRight(16) + " Service='" + conversation.Service + "'" + " Topic='" + conversation.Topic + "'" + " Handle=" + conversation.Handle.ToString() + " Item='" + item + "'" + " Format=" + format.ToString()); // Initiate the advisory loop only if the format is CF_TEXT. return format == 1; }
protected override RequestResult OnRequest(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<string>(); Task.Run(async () => { var result = await _OnRequest(obj); tcs.SetResult((string)result); }); var text = tcs.Task.Result; // Return data to the client only if the format is CF_TEXT. if (format == 1) { return new RequestResult(System.Text.Encoding.Default.GetBytes(text + "\0")); } return RequestResult.NotProcessed; }
protected override void OnDisconnect(NDde.Server.DdeConversation conversation) { base.OnDisconnect(conversation); l.Debug(String.Format("Topic : {0} has been disconnected!", conversation.Topic)); }
protected override ExecuteResult OnExecute(DdeConversation conversation, string command) { Console.WriteLine("OnExecute:".PadRight(16) + " Service='" + conversation.Service + "'" + " Topic='" + conversation.Topic + "'" + " Handle=" + conversation.Handle.ToString() + " Command='" + command + "'"); // Tell the client that the command was processed. return ExecuteResult.Processed; }
protected override void OnDisconnect(DdeConversation c) { ((DataChannel)c.Tag).IsConnected = false; }
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 RequestResult.NotProcessed; }
/// <summary> /// This is invoked when a client attempts to initiate an advise loop. /// </summary> /// <param name="conversation"> /// The conversation associated with this event. /// </param> /// <param name="item"> /// The item name associated with this event. /// </param> /// <param name="format"> /// The format of the data. /// </param> /// <returns> /// True to allow the advise loop, false otherwise. /// </returns> /// <remarks> /// The default implementation accepts all advise loops. /// </remarks> protected virtual bool OnStartAdvise(DdeConversation conversation, string item, int format) { return true; }
protected override void OnStopAdvise(DdeConversation conversation, string item) { Console.WriteLine("OnStopAdvise:".PadRight(16) + " Service='" + conversation.Service + "'" + " Topic='" + conversation.Topic + "'" + " Handle=" + conversation.Handle.ToString() + " Item='" + item + "'"); }
/// <summary> /// This is invoked when a client terminates an advise loop. /// </summary> /// <param name="conversation"> /// The conversation associated with this event. /// </param> /// <param name="item"> /// The item name associated with this event. /// </param> protected virtual void OnStopAdvise(DdeConversation conversation, string item) { }
/// <summary> /// This is invoked when a client has successfully established a conversation. /// </summary> /// <param name="conversation"> /// The conversation associated with this event. /// </param> protected virtual void OnAfterConnect(DdeConversation conversation) { }
protected override bool OnStartAdvise(DdeConversation conversation, string item, int format) { Console.WriteLine("OnStartAdvise:".PadRight(16) + " Service='" + conversation.Service + "'" + " Topic='" + conversation.Topic + "'" + " Handle=" + conversation.Handle.ToString() + " Item='" + item + "'" + " Format=" + format.ToString()); return base.OnStartAdvise(conversation, item, format); }