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(); } }
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_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_StopAdvise() { 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(); client.StartAdvise(ItemName, 1, true, Timeout); client.StopAdvise(ItemName, Timeout); } } }