Exemple #1
2
        /// <summary>
        /// 开始监控火狐浏览器
        /// </summary>
        public List<WebSiteModel> MnitorFireFox()
        {
            try
            {
                string sUrl = string.Empty;
                DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo");
                dde.Connect();
                // 取得 URL 資訊
                string sUrlInfo = dde.Request("URL", int.MaxValue);
                // DDE Client 進行連結 
                dde.Disconnect();

                List<WebSiteModel> urls = new List<WebSiteModel>();

                // 取得的 sUrlInfo 內容為 "網址","標題",""
                // 取出網址部分
                if (sUrlInfo.Length > 0)
                {
                    //sUrlInfo.Split(',').ToList<>();
                    sUrl = sUrlInfo.Split(',')[0].Trim(new char[] { '"' });
                }
                return urls;
            }
            catch
            {
                return null;
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("DDE Console");
            String _myapp = "TOS";
            String _topic = "LAST";
            String _item = "SPY";

            try
            {
                // Create a client that connects to 'myapp|topic'.
                using (DdeClient client = new DdeClient(_myapp, _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
                    client.StartAdvise(_item, 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();
            }
        }
Exemple #3
0
        public MainForm()
        {
            InitializeComponent();

            client = new DdeClient("myapp", "myservice", this);
            client.Advise += client_Advise;
            client.Disconnected += client_Disconnected;
        }
 public void Test_BeginExecute()
 {
     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));
         }
     }
 }
 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);
         }
     }
 }
Exemple #6
0
        public 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();
            }
        }
Exemple #7
0
        public PluginResult OnTriggered(PluginTriggerEventArgs e)
        {
            DdeClient dde = new DdeClient("IExplore", "WWW_GetWindowInfo");
            dde.Connect();
            string result = dde.Request("0xFFFFFFFF,sURL,sTitle", 1000);
            dde.Disconnect();

            // Result string is in the format "uri", "title"\0
            var parts = result.Trim('\0').Trim('"').Split(new string[] { "\",\"" }, StringSplitOptions.None);
            string url = parts[0].Replace("\\\"", "\"");
            string name = parts[1].Replace("\\\"", "\"");

            return PluginResult.FromUrl(url, name);
        }
Exemple #8
0
        static void Main(string[] args)
        {
            var client = new DdeClient("MT4", "QUOTE");
            beat = new QuoteBeat();

            writer = new LogDataWriter("EURUSD");

            client.Advise += client_Advise;
            client.Connect();
            client.StartAdvise("EURUSD", 1, true, 60000);

            Console.ReadLine();
            writer.Close();
        }
Exemple #9
0
        public PluginResult OnTriggered(PluginTriggerEventArgs e)
        {
            DdeClient dde = new DdeClient("Opera", "WWW_GetWindowInfo");
            dde.Connect();
            string result = dde.Request("URL", 1000);
            dde.Disconnect();

            // Result string is in the format "url", "Opera - [title]", ...
            var parts = result.Trim('"').Split(new string[] { "\",\"" }, StringSplitOptions.None);
            string url = parts[0].Replace("\\\"", "\"");
            string name = Regex.Match(parts[1], @"Opera - \[(.*?)\]").Groups[1].Value.Replace("\\\"", "\"");

            return PluginResult.FromUrl(url, name);
        }
 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);
         }
     }
 }
 //
 // usage: GetBrowserURL("opera") or GetBrowserURL("firefox")
 //
 public static string GetBrowserURL(string browser)
 {
     try
     {
         DdeClient dde = new DdeClient(browser, "WWW_GetWindowInfo");
         dde.Connect();
         string url = dde.Request("URL", int.MaxValue);
         string[] text = url.Split(new string[] { "\",\"" }, StringSplitOptions.RemoveEmptyEntries);
         dde.Disconnect();
         return text[0].Substring(1);
     }
     catch
     {
         return null;
     }
 }
 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));
         }
     }
 }
 public static string GetUrl(string browser)
 {
     try
     {
         DdeClient dde = new DdeClient(browser, "WWW_GetWindowInfo"); // Using DDE-lib to connect and get information from the firefox browser
         dde.Connect();
         string url = dde.Request("URL", int.MaxValue);
         string[] text = url.Split(new string[] { "\",\"" }, StringSplitOptions.RemoveEmptyEntries);
         dde.Disconnect();
         return text[0].Substring(1);
     }
     catch
     {
         MessageBox.Show("Is your firefox open?", "Error"); // If firefox isnt open
         return null;
     }
 }
Exemple #14
0
 public UrlUpload()
 {
     InitializeComponent ();
     //initialize
     close_mode=true;
     Is_firefox_alive=Is_opera_alive=false;
     Firefox_=new DdeClient ("Firefox", "WWW_GetWindowInfo");
     Opera_=new DdeClient ("Opera", "WWW_GetWindowInfo");
     var t=new System.Windows.Forms.Timer ();
     t.Interval=500;
     GetInfo ();
     t.Tick+=delegate
     {
         //check if a url is in Firefox, Opera or clipboard
         GetInfo ();
         if (radioButton1.Checked) this.button1.Enabled=true;
         if (radioButton3.Checked)
         {
             //in Firefox
             if (Firefox.StartsWith ("{error")) this.button1.Enabled=false;
             else this.button1.Enabled=true;
         }
         if (radioButton4.Checked)
         {
             //in Opera
             if (Opera.StartsWith ("{error")) this.button1.Enabled=false;
             else this.button1.Enabled=true;
         }
         if (radioButton2.Checked)
         {
             //on clipboard
             if (Clipboardz.StartsWith ("{error")) this.button1.Enabled=false;
             else this.button1.Enabled=true;
         }
     };
     t.Start ();
     this.FormClosing+=delegate
     {
         //@ existing, disconnect the DDe from the web browsers
         DisconnectDde ();
         if (close_mode) this.DialogResult=DialogResult.Cancel;
         else this.DialogResult=DialogResult.OK;
     };
 }
 public void Test_Execute_NotProcessed()
 {
     using (TestServer server = new TestServer(ServiceName))
     {
         server.Register();
         using (DdeClient client = new DdeClient(ServiceName, TopicName))
         {
             client.Connect();
             try
             {
                 client.Execute("#NotProcessed", Timeout);
             }
             catch (DdeException e)
             {
                 Assert.AreEqual(0x4009, e.Code);
             }
         }
     }
 }
Exemple #16
0
        private void CollectPrice()
        {
            string _topic = "LAST";
            string _myapp = Properties.Settings.Default.AppDDE;
            string expiration = "110416";
            string item = "'.SPY" + expiration;  //'.SPY110416C132'
            DdeClient client;

            try
            {
                // Create a client that connects to 'myapp|topic'.
                using (client = new DdeClient(_myapp, _topic))
                {
                    // Subscribe to the Disconnected event.  This event will notify the application when a conversation has been terminated.
                    client.Disconnected += OnDisconnectedPrice;

                    // Connect to the server.  It must be running or an exception will be thrown.
                    client.Connect();

                    client.StartAdvise("SPY", 1, true, 60000);
                    // Advise Loop
                    for (int j = 0; j < 2; j++)
                    {
                        string cp = (j == 0) ? "C" : "P";
                        int strike = 127;
                        for (int i = 0; i < 10; i++)
                        {
                            ++strike;
                            string _item = item + cp + strike.ToString();
                            client.StartAdvise(_item, 1, true, 60000);
                        }
                    }
                    client.Advise += OnAdvisePrice;
                }
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.ToString());
                log.WriteLine(getTimeStamp() + " Price " + e.ToString());
            }
        }
        /// <summary>
        /// Gets the current status of the ChemStation app via DDE and maps it to our model object.
        /// </summary>
        /// <returns>The ORMed ChemStation Status.</returns>
        public ChemStationStatus GetCurrentStatus()
        {
            var status = new ChemStationStatus();
            status.Time = DateTime.Now;
            var appName = string.Empty;
            try
            {
                appName = GetChemStationAppName();
            }
            catch (ApplicationException e)
            {
                status.Status = e.Message;
                status.MethodName = string.Empty;
                status.SequenceName = string.Empty;
                return status;
            }

            using (DdeClient client = new DdeClient(appName, _DDETopicName))
            {
                client.Connect();
                foreach (var variable in _chemStationVariableNameToPropertyMap)
                {
                    var rawVariable = client.Request(variable.Key, 60000);

                    // Use reflection to map the raw variable just extracted from ChemStation to the model object.
                    if (variable.Value.PropertyType == typeof(bool))
                    {
                        var val = rawVariable[0] == '1' ? true : false;
                        _chemStationVariableNameToPropertyMap[variable.Key].SetValue(status, val, null);
                    }
                    else
                    {
                        // String variables tend to come out of ChemStation with a bizarre amount of control characters followed by jibberish at the end.
                        var val = rawVariable.Remove(rawVariable.IndexOf(rawVariable.Where(c => char.IsControl(c)).First()));
                        _chemStationVariableNameToPropertyMap[variable.Key].SetValue(status, val, null);
                    }
                }
            }
            return status;
        }
        /** 新增項目(Item), 並取得該項目的值(Value)
         *   1. 呼叫 DdeClient 的 "Request()" & "StartAdvise" 取得該 Item 的值
         *   2. 利用 service|topic!item 字串為 key
         *   2.1 ht_gdv(HashTable) -> (key, DataGridViewRow)
         *   3. 在 dgItemInfo(DataGridView)新增一列, 顯示項目相關資訊
         *
         *   <param name="dc">     "新增項目" 按鈕事件所在列對應的 DdeClient
         *   <param name="item"> "新增項目" 名稱(Name)
         */
        private void AddItem(DdeClient dc, string item)
        {
            try
            {
                string key = dc.Service + "|" + dc.Topic + "!" + item;

                Item it = new Item();
                it.item = item; it.value = "";

                try
                {
                    //Synchronous Request Operation, 用以取得第一次呼叫的值
                    //eLeader, 康和 並未支援同步呼叫; yeswin/hts 則有支援
                    byte[] data = dc.Request(item, 1, 60000);
                    int codepage = Encoding.Default.CodePage;   //取得編碼的 codpage. 中文 Default: 950
                    string value = Encoding.GetEncoding(codepage).GetString(data, 0, data.Length);
                    //it.value = Encoding.ASCII.GetString(data);
                    it.value = value;
                }
                catch (Exception )
                {
                    ;  //忽略該錯誤
                }

                // Advise Loop
                dc.StartAdvise(item, 1, true, 60000);

                //Add a Row
                int idx = dgItemInfo.Rows.Add(dc.Service, dc.Topic, item, it.value);
                //保存 key 與 所在新增 Row
                ht_gdv.Add(key, dgItemInfo.Rows[idx]);
            }
            catch (Exception thrown)
            {
                MessageBox.Show("無法新增項目: \n" + thrown.Message);
            }
        }
 public void Test_IsConnected_Variation_4()
 {
     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();
             server.Disconnect();
             Assert.IsTrue(listener.Received.WaitOne(Timeout, false));
             Assert.IsFalse(client.IsConnected);
         }
     }
 }
Exemple #20
0
        static void Main(string[] args)
        {
            XmlDocument xml = new XmlDocument();
            try
            {
                xml.Load(@"tase.xml");
            }
            catch (Exception )
            {
                Console.WriteLine("File dde.xml was not found in current folder!");
                Console.WriteLine("Press ENTER to quit...");
                Console.ReadLine();
                return;
            }

            Dictionary<string, string> myDict = new Dictionary<string, string>();
            XmlNodeList nodeList;
            XmlElement root = xml.DocumentElement;
            nodeList = root.SelectNodes("/tase/option");
            foreach (XmlNode option in nodeList)
            {
                XmlNodeList optionsData = option.ChildNodes;
                string opname = "";
                string id = "";
                string exp = "";
                foreach (XmlNode op in optionsData)
                {
                    if (op.Name == "name")
                    {
                        opname = op.InnerText.Substring(0, 6);
                    }
                    else if (op.Name == "id")
                    {
                        id = op.InnerText;
                    }
                    else if (op.Name == "expiration")
                    {
                        DateTime dt = DateTime.ParseExact(op.InnerText, "dd/MM/yyyy",
                                   CultureInfo.InvariantCulture);
                        exp = dt.Month.ToString();
                    }
                }
                //Console.Write("{0} {1}\n", opname+"_"+exp, id);
                myDict.Add(opname + "_" + exp, id);
            }

            // create a writer and open the file
            string filename = "data" + DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + ".txt";
            tw = new StreamWriter(filename);

            tw.WriteLine("DDE BIZPORTAL {0:MM/dd/yy}", DateTime.Now);
            string _myapp = "Star32";
            string _topic = "DDE";

            try
            {
                // Create a client that connects to 'myapp|topic'.
                using (DdeClient client = new DdeClient(_myapp, _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 (KeyValuePair<string, string> pair in myDict)
                    {
                        foreach(string name in Enum.GetNames(typeof(DDE_VALUES)))
                        {
                            string advice = name + pair.Value;
                            client.StartAdvise(advice, 1, true, 60000);
                        }
                    }

                    client.Advise += OnAdvise;

                    // Wait for the user to press ENTER before proceding.
                    Console.WriteLine("Press Ctrl X to quit...");
                    ConsoleKeyInfo info = Console.ReadKey(true);
                    while (info.Key != ConsoleKey.X && info.Modifiers != ConsoleModifiers.Control)
                    {
                        info = Console.ReadKey(true);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine("Press ENTER to quit...");
                Console.ReadLine();
            }

            // close the stream
            tw.Close();
        }
 public void Test_Handle_Variation_3()
 {
     using (TestServer server = new TestServer(ServiceName))
     {
         server.Register();
         using (DdeClient client = new DdeClient(ServiceName, TopicName))
         {
             client.Connect();
             client.Disconnect();
             Assert.AreEqual(IntPtr.Zero, client.Handle);
         }
     }
 }
 /// <summary>
 /// This method may potentially be refactored into its own interface/class to deal with other versions of ChemStation. The
 ///    version currently being used requires the DDE app name to be composed of 'hpcore' + the process number of the instance of
 ///    ChemStation that is currently online (connected to an instrument).
 /// </summary>
 /// <returns>The DDE App name used to connect to ChemStation via DDE as a string.</returns>
 private string GetChemStationAppName()
 {
     var potentialChemStations = Process.GetProcesses().Where(x => x.ProcessName.ToUpper().Contains(_windowsAppName));
     foreach (var chemStation in potentialChemStations)
     {
         using (DdeClient client = new DdeClient(_baseDDEAppName + chemStation.Id.ToString(), _DDETopicName))
         {
             client.Connect();
             var offline = client.Request("_OFFLINE", 60000)[0] == '1' ? true : false;
             if (!offline)   return (_baseDDEAppName + chemStation.Id.ToString());
         }
     }
     throw new ApplicationException("Unable to find an online ChemStation process.");
 }
 public void Test_IsConnected_Variation_2()
 {
     using (TestServer server = new TestServer(ServiceName))
     {
         server.Register();
         using (DdeClient client = new DdeClient(ServiceName, TopicName))
         {
             client.Connect();
             Assert.IsTrue(client.IsConnected);
         }
     }
 }
 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_Resume_After_Dispose()
 {
     using (TestServer server = new TestServer(ServiceName))
     {
         server.Register();
         using (DdeClient client = new DdeClient(ServiceName, TopicName))
         {
             client.Connect();
             client.Pause();
             client.Dispose();
             client.Resume();
         }
     }
 }
 public void Test_Request_Overload_2()
 {
     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();
             string data = client.Request(ItemName, Timeout);
             Assert.AreEqual(TestData, data);
         }
     }
 }
 public void Test_Request_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))
         {
             byte[] data = client.Request(ItemName, 1, Timeout);
         }
     }
 }
 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_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_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);
         }
     }
 }