public void Test_Handle_Variation_1() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); Assert.AreEqual(IntPtr.Zero, client.Handle); }
public IOServerDDEFluidSim(DdeClient plc, String outm, String inm) { ps = plc; inMarke = inm; outMarke = outm; ps.Disconnected += OnDisconnected; }
// 按下 dgConnection(DataGridView) Cell 後的事件處理 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { // Ignore clicks that are not on button cells. if (e.RowIndex < 0 || (e.ColumnIndex != dgConnection.Columns["col_remove_conn"].Index && e.ColumnIndex != dgConnection.Columns["col_btn_add_item"].Index)) { return; } //判斷 dgv 內的按鈕名稱 if (dgConnection.Columns[e.ColumnIndex].Name.Equals("col_remove_conn")) { this.Remove_Connect_and_Item_Row(e.RowIndex); } else if (dgConnection.Columns[e.ColumnIndex].Name.Equals("col_btn_add_item")) { if (txt_item.Text == "") { MessageBox.Show("項目(Item)不能為空!"); } else { //新增 gdItemInfo Row //取得新增按鈕按下時所在的列(row) DataGridViewRow curr_row = dgConnection.Rows[e.RowIndex]; //取得該列的連線字串, 並以該字串為 key, 找出對應的 DdeClient instance. string key = curr_row.Cells["col_service"].Value.ToString() + "|" + curr_row.Cells["col_topic"].Value.ToString(); DdeClient dc = (DdeClient)ht_conn[key]; string item = txt_item.Text; this.AddItem(dc, item); //新增 Item } } }
/** 新增 DDE連線 的事件處理 * */ private void btnAddConnect_Click(object sender, EventArgs e) { if (ht_conn.ContainsKey(txtService.Text + "|" + txtTopic.Text)) { MessageBox.Show("連線字串不能重覆!"); return; } DdeClient dc = new DdeClient(txtService.Text, txtTopic.Text); //register the event handler dc.Disconnected += client_Disconnected; dc.Advise += client_Advise; try { // Connect to the server. It must be running or an exception will be thrown. dc.Connect(); dgConnection.Rows.Add(txtService.Text, txtTopic.Text, "已連線"); //利用 "service|topic" 為 HashTable 的 Key; DdeClient 為 Object. string key = txtService.Text + "|" + txtTopic.Text; ht_conn.Add(key, dc); } catch (Exception thrown) { MessageBox.Show("無法連結 DDE Server:" + thrown.Message); } }
// 按下 dgItemInfo(DataGridView) Cell 後的事件處理 private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e) { // Ignore clicks that are not on button cells. if (e.RowIndex < 0 || e.ColumnIndex != dgItemInfo.Columns["col_iteminfo_btn_delete"].Index) { return; } //取得移除按鈕按下時所在的列(row) DataGridViewRow del_row = dgItemInfo.Rows[e.RowIndex]; //取得該列欄位的 service, topic, item 字串值 string service_topic = del_row.Cells["col_iteminfo_service"].Value.ToString() + "|" + del_row.Cells["col_iteminfo_topic"].Value.ToString(); string item = del_row.Cells["col_iteminfo_Item"].Value.ToString(); //Get DdeClient connection. DdeClient dc = (DdeClient)ht_conn[service_topic]; //Stop Advise. this.Stop_advise(dc, item); //移除該列並從 HashTable 也一併移除所對應的 key/value. string service_topic_item = service_topic + "!" + item; DataGridViewRow del_item_row = (DataGridViewRow)ht_gdv[service_topic_item]; ht_gdv.Remove(service_topic_item); dgItemInfo.Rows.Remove(del_item_row); }
public void D_client() { try { using (DdeClient client = new DdeClient("asirc", "command")) { client.Disconnected += OnDisconnected; client.Connect(); while (true) { //send_cmd = Console.ReadLine(); //send_cmd = "/msg #openssm 잘되네유"; if (!send_cmd.Equals(null)) { bytecode = Encoding.GetEncoding("utf-8").GetBytes(send_cmd + "\0"); } client.BeginPoke("command", bytecode, 1, OnPokeComplete, client); send_cmd = null; bytecode = null; } } } catch (Exception) { Environment.Exit(0); } }
private void AddConnection(String a_service, String a_topic) { if (ht_conn.ContainsKey(a_service + "|" + a_topic)) { MessageBox.Show("連線字串不能重覆!"); return; } DdeClient dc = new DdeClient(a_service, a_topic); //register the event handler dc.Disconnected += client_Disconnected; dc.Advise += client_Advise; try { // Connect to the server. It must be running or an exception will be thrown. dc.Connect(); dgConnection.Rows.Add(a_service, a_topic, "已連線"); //利用 "service|topic" 為 HashTable 的 Key; DdeClient 為 Object. string key = a_service + "|" + a_topic; ht_conn.Add(key, dc); } catch (Exception thrown) { MessageBox.Show("無法連結 DDE Server:" + thrown.Message); } }
public void Test_IsConnected_Variation_1() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); Assert.IsFalse(client.IsConnected); }
private void StartAssetDDE() { String _topic = "LAST"; try { // Create a client that connects to 'myapp|topic'. using (DdeClient client = new DdeClient(Properties.Settings.Default.APP, _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(Properties.Settings.Default.ITEM, 1, true, 60000); client.Advise += OnAdvise; } } catch (Exception e) { MessageBox.Show("Please run " + Properties.Settings.Default.APP + " and restart this application!"); } }
public static void Agent() { // Create a client that connects to 'myapp|machineswitch' string myApp = "ncdde"; string myTopic = "machineswitch"; DdeClient client = new DdeClient(myApp, myTopic); try { client.Disconnected += OnDisconnected; // Advise Loop client.Connect(); for (int i = 0; i < Events.list.Count; i++) { client.StartAdvise(Events.list[i].foreignEvent, 1, true, 60000); } client.Advise += OnAdvise; // Console.WriteLine("Press ENTER to quit..."); Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e.ToString()); // Console.WriteLine("Press ENTER to quit..."); Console.ReadLine(); } finally { } }
public void Test_Poke_Before_Connect() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); Assert.Throws<InvalidOperationException>(() => client.Poke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, Timeout)); }
public API_CMA() { this._batchOperation = new TableBatchOperation(); this._track = new ConcurrentDictionary <int, string>(); this._orders = new ConcurrentDictionary <string, NewOrderData>(); this._lasttime = new ConcurrentDictionary <string, DateTime>(); this._keealiveoms = true; this._omsclient = new RoboTrading(); this._omsclient.OnStatusChanged += _omsclient_OnStatusChanged; this._omsclient.OnNewOrderReply += _omsclient_OnNewOrderReply; this._omsclient.OnCancelOrderReply += _omsclient_OnCancelOrderReply; this._omsclient.OnOrderListReply += _omsclient_OnOrderListReply; this._omsclient.OnOrderListUpdate += _omsclient_OnOrderListUpdate; this._lasttime.TryAdd("NPC", BvspTime); this._keealivenpc = true; this._npcClient = new DdeClient("profitchart", "cot"); this._npcClient.Advise += OnTickArrived; this._npcClient.Disconnected += (s, e) => { IsDDEAvailable(_npcClient); }; this._npcSymbols = new ConcurrentDictionary <string, DateTime>(); this._lasttime.TryAdd("CMA", BvspTime); this._keealivecma = true; this._cmaClient = new DdeClient("TWSVR", "CMA"); this._cmaClient.Advise += OnTickArrived; this._cmaClient.Disconnected += (s, e) => { IsDDEAvailable(_cmaClient); }; this._cmaSymbols = new ConcurrentDictionary <string, DateTime>(); }
public void BeginStartQuotes(IEnumerable <Symbol> symbols) { try { if (client.IsConnected == true) { client.Disconnect(); client = new DdeClient("MTX", "DATA"); } client.Advise += OnAdvise; client.Disconnected += new EventHandler <DdeDisconnectedEventArgs>(client_Disconnected); client.Connect(); foreach (var item in symbols) { for (int j = 0; j < UpdateFields.Length; ++j) { client.BeginStartAdvise(item.Value.ToUpper() + "." + UpdateFields[j], 1, true, null, null); } } } catch { } }
public void Test_Ctor_Overload_2() { using (DdeContext context = new DdeContext()) { DdeClient client = new DdeClient(ServiceName, TopicName, context); } }
public void Test_BeginExecute_Before_Connect() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); Assert.Throws<InvalidOperationException>(() => client.BeginExecute(TestData, null, null)); }
/// <summary> /// Check if external programs are available /// </summary> private bool ChooseServers() { this._ddeserver = Process.GetProcessesByName("TCA_DDESVR").Length > 0; this._ddeserveralt = !this._ddeserver && Process.GetProcessesByName("ProfitChart").Length > 0; if ((this._ddeclient == null || this._ddeclient.Service == "profitchart") && this._ddeserver) { this._ddeclient = new DdeClient("TWSVR", "CMA"); } if ((this._ddeclient == null || this._ddeclient.Service == "TWSVR") && this._ddeserveralt) { this._ddeclient = new DdeClient("profitchart", "cot"); } if (this._ddeserver || this._ddeserveralt) { _ddeclient.Advise += OnTickArrived; } else { this._ddeclient = null; // No DDE server is available } var status = this._ddeserver ? "servidor DDE do CMA" : this._ddeserveralt ? "servidor DDE do ProfitChart" : "OFF Link DDE do CMA indisponível"; NotifyDDE(status); return(this._ddeclient == null); }
/// <summary> /// 开始监控火狐浏览器 /// </summary> public List <WebSiteModel> MnitorFireFox() { try { string sUrl = string.Empty; string sTitle = 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[] { '"' }); sTitle = sUrlInfo.Split(',')[1].ToString(); urls.Add(new WebSiteModel() { url = sUrl, title = sTitle }); } return(urls); } catch { return(null); } }
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(); } }
public void Test_Service() { using (var client = new DdeClient(ServiceName, TopicName)) { Assert.AreEqual(ServiceName, client.Service); } }
public WebLiveMonitorViewModel(params object[] args) { HidePleaseWait = false; //LineSr.DataSqlUpdateSucceeded += DataCopy_DataSqlUpdateSucceeded; if (args.Length > 0) { int.TryParse(args[0].ToString(), out _screen); } Mediator.Register <string>(this, SetUpBrowser, MsgTag.SetUpBrowser); Mediator.Register <string>(this, ChangeVisibility, MsgTag.ChangeVisibility); _client = new DdeClient("terminal", MsgTag.SetUpBrowser); while (!_client.IsConnected) { try { _client.Connect(); _client.Disconnected += client_Disconnected; _client.StartAdvise("test" + _screen, 1, true, 6000); _client.Advise += client_Advise; } catch (Exception e) { Log.Error(e.Message, e); } } }
public void Test_Disconnect_Before_Connect() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); Assert.Throws<InvalidOperationException>(() => client.Disconnect()); }
public void Test_Topic() { using (DdeClient client = new DdeClient(ServiceName, TopicName)) { Assert.AreEqual(TopicName, client.Topic); } }
public void Test_Connect() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); client.Connect(); }
public void Test_BeginStartAdvise_Before_Connect() { using var server = new TestServer(ServiceName); server.Register(); server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData)); using var client = new DdeClient(ServiceName, TopicName); Assert.Throws<InvalidOperationException>(() => client.BeginStartAdvise(ItemName, 1, false, null, null)); }
public void Test_Connect_After_Dispose() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); client.Dispose(); Assert.Throws<ObjectDisposedException>(() => client.Connect()); }
public void Test_TryPoke_Variation_1() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); var result = client.TryPoke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, Timeout); Assert.AreNotEqual(0, result); }
private TOSTopicConnection(TOSTopic topic) { Topic = topic; c = new DdeClient("TOS", topic.Name); c.Advise += new EventHandler <DdeAdviseEventArgs>(c_Advise); c.Disconnected += new EventHandler <DdeDisconnectedEventArgs>(c_Disconnected); c.Connect(); }
public void Test_TryExecute_Variation_1() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); var result = client.TryExecute(TestData, Timeout); Assert.AreNotEqual(0, result); }
public void Test_Execute_PauseConversation() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); client.Connect(); client.Execute("#PauseConversation", (int) server.Interval * 2); }
public MainForm() { InitializeComponent(); client = new DdeClient("myapp", "myservice", this); client.Advise += client_Advise; client.Disconnected += client_Disconnected; }
///<summary>Launches the program using the patient.Cur data.</summary> public static void SendData(Program ProgramCur, Patient pat){ ArrayList ForProgram=ProgramProperties.GetForProgram(ProgramCur.ProgramNum);; if(pat==null){ MessageBox.Show("Please select a patient first"); return; } //Get the program path from the ini file string windir=Environment.GetEnvironmentVariable("windir");// C:\WINDOWS string iniFile=windir+"\\dentx.ini"; if(!File.Exists(iniFile)){ MessageBox.Show("Could not find "+iniFile); return; } //Make sure the program is running string proimagePath=ReadValue(iniFile,"imagemgt","MainFile"); Process[] proImageInstances=Process.GetProcessesByName("ProImage"); if(proImageInstances.Length==0){ Process.Start(proimagePath); Thread.Sleep(TimeSpan.FromSeconds(10)); } //command="Xray,PatientNo,FirstName,LastName,Birth Date,Sex,Address,City,State,Code"(zip) string command="Xray,"; //PatientNo can be any string format up to 9 char ProgramProperty PPCur=ProgramProperties.GetCur(ForProgram, "Enter 0 to use PatientNum, or 1 to use ChartNum");; if(PPCur.PropertyValue=="0"){ command+=pat.PatNum.ToString()+","; } else{ if(pat.ChartNumber==""){ MessageBox.Show("ChartNumber for this patient is blank."); return; } command+=pat.ChartNumber.Replace(",","")+","; } command+=pat.FName.Replace(",","")+"," +pat.LName.Replace(",","")+"," +pat.Birthdate.ToShortDateString()+","; if(pat.Gender==PatientGender.Female) command+="F,"; else command+="M,"; command+=pat.Address.Replace(",","")+"," +pat.City.Replace(",","")+"," +pat.State.Replace(",","")+"," +pat.Zip.Replace(",",""); //MessageBox.Show(command); try { //Create a context that uses a dedicated thread for DDE message pumping. using(DdeContext context=new DdeContext()){ //Create a client. using(DdeClient client=new DdeClient("ProImage","Image",context)){ //Establish the conversation. client.Connect(); //Start ProImage and open to the Xray Chart screen client.Execute(command,2000);//timeout 2 secs } } } catch{ //MessageBox.Show(e.Message); } }
///<summary>Launches the program if necessary. Then passes patient.Cur data using DDE.</summary> public static void SendData(Program ProgramCur, Patient pat){ string path=Programs.GetProgramPath(ProgramCur); ArrayList ForProgram=ProgramProperties.GetForProgram(ProgramCur.ProgramNum);; if(pat==null){ MessageBox.Show("Please select a patient first"); return; } //The path is available in the registry, but we'll just make the user enter it. if(!File.Exists(path)){ MessageBox.Show("Could not find "+path); return; } //Make sure the program is running if(Process.GetProcessesByName("DentalEye").Length==0){ Process.Start(path); Thread.Sleep(TimeSpan.FromSeconds(4)); } //command="[Add][PatNum][Fname][Lname][Address|Address2|City, ST Zip][phone1][phone2][mobile phone][email][sex(M/F)][birthdate (YYYY-MM-DD)]" ProgramProperty PPCur=ProgramProperties.GetCur(ForProgram, "Enter 0 to use PatientNum, or 1 to use ChartNum");; string patID; if(PPCur.PropertyValue=="0"){ patID=pat.PatNum.ToString(); } else{ if(pat.ChartNumber==""){ MessageBox.Show("ChartNumber for this patient is blank."); return; } patID=pat.ChartNumber; } string command="[Add]["+patID+"]" +"["+pat.FName+"]" +"["+pat.LName+"]" +"["+pat.Address+"|"; if(pat.Address2!=""){ command+=pat.Address2+"|"; } command+=pat.City+", "+pat.State+" "+pat.Zip+"]" +"["+pat.HmPhone+"]" +"["+pat.WkPhone+"]" +"["+pat.WirelessPhone+"]" +"["+pat.Email+"]"; if(pat.Gender==PatientGender.Female) command+="[F]"; else command+="[M]"; command+="["+pat.Birthdate.ToString("yyyy-MM-dd")+"]"; //MessageBox.Show(command); try { //Create a context that uses a dedicated thread for DDE message pumping. using(DdeContext context=new DdeContext()){ //Create a client. using(DdeClient client=new DdeClient("DENTEYE","Patient",context)){ //Establish the conversation. client.Connect(); //Add patient or modify if already exists client.Execute(command,2000);//timeout 2 secs //Then, select patient command="[Search]["+patID+"]"; client.Execute(command,2000); } } } catch{ //MessageBox.Show(e.Message); } }
///<summary>Launches the program if necessary. Then passes patient.Cur data using DDE.</summary> public static void SendData(Program ProgramCur, Patient pat) { ArrayList ForProgram=ProgramProperties.GetForProgram(ProgramCur.ProgramNum);; if(pat==null){ MessageBox.Show("Please select a patient first"); return; } if(!File.Exists(ProgramCur.Path)){ MessageBox.Show("Could not find "+ProgramCur.Path); return; } //Make sure the program is running //Documentation says to include the -nostartup command line switch (to avoid optional program preference startup command). if(Process.GetProcessesByName("Vipersoft").Length==0){ Process.Start(ProgramCur.Path,"-nostartup"); Thread.Sleep(TimeSpan.FromSeconds(4)); } //Data is sent to the Vipersoft DDE Server by use of the XTYP_EXECUTE DDE message only. //The format ot the XTYP_EXECUTE DDE message is" //command="\004hwnd|name|ID|Lastname|Firstname|MI|Comments|Provider|Provider Phone|Addrs1|Addrs2|City|State|Zip|Patient Phone|Practice Name|Patient SSN|restore server|" //\004 is one byte code for version 4. 0x04 or Char(4) //hwnd is calling software's windows handle. //name is for name of calling software (Open Dental) //ID is patient ID. Required and must be unique. //Provider field is for provider name. //hwnd, ID, Lastname, Firstname, and Provider fields are required. All other fields are optional. //All vertical bars (|) are required, including the ending bar. //The restore server flag is for a future release's support of the specialized capture/view commands (default is '1') //Visual Basic pseudo code: //Chan = DDEInitiate("Vipersoft", "Advanced IntraOral") //DDE_String$ = "" //etc //DDEExecute Chan, DDE_String$ //send XTYP_EXECUTE DDE command: //DDETerminate Chan Char char4=Convert.ToChar(4); string command=char4.ToString();//tested to make sure this is just one non-printable byte. IntPtr hwnd=Application.OpenForms[0].Handle; command+=hwnd.ToString()+"|"//hwnd +"OpenDental|";//name ProgramProperty PPCur=ProgramProperties.GetCur(ForProgram, "Enter 0 to use PatientNum, or 1 to use ChartNum");; string patID; if(PPCur.PropertyValue=="0"){ patID=pat.PatNum.ToString(); } else{ if(pat.ChartNumber==""){ MessageBox.Show("ChartNumber for this patient is blank."); return; } patID=pat.ChartNumber; } command+=patID+"|";//ID command+=pat.LName+"|";//Lastname command+=pat.FName+"|";//Firstname command+=pat.MiddleI+"|";// command+="|";//Comments: blank Provider prov=Providers.GetProv(Patients.GetProvNum(pat)); command+=prov.LName+", "+prov.FName+"|";//Provider command+="|";//Provider phone command+="|";//Addr command+="|";//Addr2 command+="|";//City command+="|";//State command+="|";//Zip command+="|";//Phone command+="|";//Practice command+=pat.SSN+"|";//SSN command+="1|";//Restore Server //MessageBox.Show(command); try { //Create a context that uses a dedicated thread for DDE message pumping. using(DdeContext context=new DdeContext()){ //Create a client. using(DdeClient client=new DdeClient("Vipersoft","Advanced IntraOral",context)){ //Establish the conversation. client.Connect(); //Select patient client.Execute(command,2000);//timeout 2 secs client.Disconnect(); } } } catch{ //MessageBox.Show(e.Message); } }