public void Test_Topic() { using (DdeClient client = new DdeClient(ServiceName, TopicName)) { Assert.AreEqual(TopicName, client.Topic); } }
public void Test_Ctor_Overload_2() { using (DdeContext context = new DdeContext()) { DdeClient client = new DdeClient(ServiceName, TopicName, context); } }
static void Main(string[] args) { try { // Read all the lines from a .set file string[] lines = System.IO.File.ReadAllLines(@"symbols.set"); foreach (string line in lines) { // Construct the item list with the symbols not commented out with # if(!line.StartsWith("#")) { Item item = new Item(); item.Name = line; item.Filename = "logs\\" + item.Name + "_" + DateTime.Now.ToFileTime() + ".txt"; items.Add(item); } } // Wait for the user to press ENTER before proceding. Console.WriteLine("Meta Trader DDE Server must be running before the client can connect."); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); // Create a client that connects to 'MT4|QUOTE'. DdeClient client = new DdeClient(application, topic); // Subscribe to the Disconnected event. This event will notify the application when a conversation has been terminated. client.Disconnected += OnDisconnected; // Connect to the server. It must be running or an exception will be thrown. client.Connect(); // Advise Loop foreach (Item item in items) { client.StartAdvise(item.Name, 1, true, 60000); } client.Advise += OnAdvise; Console.WriteLine("Press ENTER to quit..."); Console.ReadLine(); } catch (DdeNet.DdeException e) { Console.WriteLine(e.ToString()); Console.WriteLine("DDE Server Not Found..."); Console.WriteLine("Press ENTER to quit..."); Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e.ToString()); Console.WriteLine("Press ENTER to quit..."); Console.ReadLine(); } }
public void Test_Register() { using (DdeServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); } } }
public void Test_Connect_After_Dispose() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Dispose(); client.Connect(); } } }
static void Main(string[] args) { // Wait for the user to press ENTER before proceding. Console.WriteLine("The Server sample must be running before the client can connect."); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); try { // Create a client that connects to 'myapp|mytopic'. using (DdeClient client = new DdeClient("myapp", "mytopic")) { // Subscribe to the Disconnected event. This event will notify the application when a conversation has been terminated. client.Disconnected += OnDisconnected; // Connect to the server. It must be running or an exception will be thrown. client.Connect(); // Synchronous Execute Operation client.Execute("mycommand", 60000); // Synchronous Poke Operation client.Poke("myitem", DateTime.Now.ToString(), 60000); // Syncronous Request Operation Console.WriteLine("Request: " + client.Request("myitem", 60000)); // Asynchronous Execute Operation client.BeginExecute("mycommand", OnExecuteComplete, client); // Asynchronous Poke Operation client.BeginPoke("myitem", Encoding.ASCII.GetBytes(DateTime.Now.ToString() + "\0"), 1, OnPokeComplete, client); // Asynchronous Request Operation client.BeginRequest("myitem", 1, OnRequestComplete, client); // Advise Loop client.StartAdvise("myitem", 1, true, 60000); client.Advise += OnAdvise; // Wait for the user to press ENTER before proceding. Console.WriteLine("Press ENTER to quit..."); Console.ReadLine(); } } catch (Exception e) { Console.WriteLine(e.ToString()); Console.WriteLine("Press ENTER to quit..."); Console.ReadLine(); } }
public void Test_Unregister() { using (DdeServer server = new TestServer(ServiceName)) { server.Register(); server.Unregister(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { try { client.Connect(); Assert.Fail(); } catch (DdeException e) { Assert.AreEqual(0x400A, e.Code); } } } }
public void Test_Disconnected_Variation_3() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { EventListener listener = new EventListener(); client.Disconnected += listener.OnEvent; client.Connect(); client.Dispose(); Assert.IsTrue(listener.Received.WaitOne(Timeout, false)); DdeDisconnectedEventArgs args = (DdeDisconnectedEventArgs)listener.Events[0]; Assert.IsFalse(args.IsServerInitiated); Assert.IsTrue(args.IsDisposed); } } }
public void Test_EndExecute_After_Dispose() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); IAsyncResult ar = client.BeginExecute(TestData, null, null); Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(Timeout, false)); client.Dispose(); client.EndExecute(ar); } } }
public void Test_BeginExecute_Before_Connect() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { IAsyncResult ar = client.BeginExecute(TestData, null, null); } } }
public void Test_Abandon_After_Dispose() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Pause(); IAsyncResult ar = client.BeginExecute(CommandText, null, null); client.Dispose(); client.Abandon(ar); } } }
public void Test_TryPoke_Variation_1() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { int result = client.TryPoke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, Timeout); Assert.AreNotEqual(0, result); } } }
public void Test_Execute() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Execute(CommandText, Timeout); Assert.AreEqual(CommandText, server.Command); } } }
public void Test_BeginRequest_Before_Connect() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData)); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { IAsyncResult ar = client.BeginRequest(ItemName, 1, null, null); } } }
public void Test_TryRequest_Variation_1() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData)); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { byte[] data; int result = client.TryRequest(ItemName, 1, Timeout, out data); Assert.AreNotEqual(0, result); } } }
public void Test_EndPoke() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); IAsyncResult ar = client.BeginPoke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, null, null); Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(Timeout, false)); client.EndPoke(ar); Assert.AreEqual(TestData, Encoding.ASCII.GetString(server.GetData(TopicName, ItemName, 1))); } } }
public void Test_BeginPoke_After_Dispose() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Dispose(); IAsyncResult ar = client.BeginPoke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, null, null); } } }
public void Test_Dispose() { using (DdeClient client = new DdeClient(ServiceName, TopicName)) { } }
public void Test_Poke_Before_Connect() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Poke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, Timeout); } } }
public void Test_StartAdvise_Variation_1() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData)); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { EventListener listener = new EventListener(); client.Advise += listener.OnEvent; client.Connect(); client.StartAdvise(ItemName, 1, true, Timeout); server.Advise(TopicName, ItemName); Assert.IsTrue(listener.Received.WaitOne(Timeout, false)); DdeAdviseEventArgs args = (DdeAdviseEventArgs)listener.Events[0]; Assert.AreEqual(ItemName, args.Item); Assert.AreEqual(1, args.Format); Assert.AreEqual(TestData, Encoding.ASCII.GetString(args.Data)); Assert.AreEqual(TestData, args.Text); } } }
public void Test_Execute_TooBusy() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); try { client.Execute("#TooBusy", Timeout); } catch (DdeException e) { Assert.AreEqual(0x4001, e.Code); } } } }
public void Test_Request() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData)); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); byte[] data = client.Request(ItemName, 1, Timeout); Assert.AreEqual(TestData, Encoding.ASCII.GetString(data)); } } }
public void Test_Execute_PauseConversation() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Execute("#PauseConversation", (int)server.Interval * 2); } } }
public void Test_IsPaused_Variation_3() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Pause(); client.Resume(); Assert.IsFalse(client.IsPaused); } } }
public void Test_Poke() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Poke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, Timeout); Assert.AreEqual(TestData, Encoding.ASCII.GetString(server.GetData(TopicName, ItemName, 1))); } } }
public void Test_EndRequest_After_Dispose() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData)); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); IAsyncResult ar = client.BeginRequest(ItemName, 1, null, null); Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(Timeout, false)); client.Dispose(); byte[] data = client.EndRequest(ar); } } }
public void Test_Resume_Before_Pause() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Resume(); } } }
public void Test_Execute_Before_Connect() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Execute(TestData, Timeout); } } }
public void Test_TryExecute_Variation_2() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); int result = client.TryExecute(TestData, Timeout); Assert.AreEqual(0, result); Assert.AreEqual(TestData, server.Command); } } }
public void Test_Abandon() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Pause(); IAsyncResult ar = client.BeginExecute(CommandText, null, null); Assert.IsFalse(ar.AsyncWaitHandle.WaitOne(Timeout, false)); client.Abandon(ar); client.Resume(); Assert.IsFalse(ar.AsyncWaitHandle.WaitOne(Timeout, false)); } } }