コード例 #1
0
 public void Test_Topic()
 {
     using (DdeClient client = new DdeClient(ServiceName, TopicName)) 
     {
         Assert.AreEqual(TopicName, client.Topic);
     }
 }
コード例 #2
0
 public void Test_Ctor_Overload_2()
 {
     using (DdeContext context = new DdeContext())
     {
         DdeClient client = new DdeClient(ServiceName, TopicName, context);
     }
 }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
 public void Test_Register()
 {
     using (DdeServer server = new TestServer(ServiceName))
     {
         server.Register();
         using (DdeClient client = new DdeClient(ServiceName, TopicName))
         {
             client.Connect();
         }
     }
 }
コード例 #5
0
 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();
         }
     }
 }
コード例 #6
0
        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();
            }
        }
コード例 #7
0
 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);
             }
         }
     }
 }
コード例 #8
0
 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);
         }
     }
 }
コード例 #9
0
 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);
         }
     }
 }
コード例 #10
0
 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);
         }
     }
 }
コード例 #11
0
 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);
         }
     }
 }
コード例 #12
0
 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);
         }
     }
 }
コード例 #13
0
 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);
         }
     }
 }
コード例 #14
0
 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);
         }
     }
 }
コード例 #15
0
 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);
         }
     }
 }
コード例 #16
0
 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)));
         }
     }
 }
コード例 #17
0
 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);
         }
     }
 }
コード例 #18
0
 public void Test_Dispose()
 {
     using (DdeClient client = new DdeClient(ServiceName, TopicName))
     {
     }
 }
コード例 #19
0
 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);
         }
     }
 }
コード例 #20
0
 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);
         }
     }
 }
コード例 #21
0
 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);
             }
         }
     }
 }
コード例 #22
0
 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));
         }
     }
 }
コード例 #23
0
 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);
         }
     }
 }
コード例 #24
0
 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);
         }
     }
 }
コード例 #25
0
 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)));
         }
     }
 }
コード例 #26
0
 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);
         }
     }
 }
コード例 #27
0
 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();
         }
     }
 }
コード例 #28
0
 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);
         }
     }
 }
コード例 #29
0
 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);
         }
     }
 }
コード例 #30
0
 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));
         }
     }
 }