///<summary>Sends data for pat to the Dexis Integrator program using a DDE Execute command. Shows a message box if pat is null instructing user ///to first select a pat. Sends SET command with the following format: SET 17 LN="LName" FN="FName" MI="MiddleI" BD=19760205. The first ///parameter of the command is the patient ID defined by the program property as either PatNum or ChartNumber. The BD portion will only be added ///if the pat has a valid bday and adding it to the commmand won't increase the length of the command to >255 characters.</summary> public static void SendData(Program progCur, Patient pat) { if (pat == null) { MsgBox.Show("DexisIntegrator", "Please select a patient first."); return; } try { if (_client == null || _client.Context == null) { DdeContext context = new DdeContext(Application.OpenForms.OfType <FormOpenDental>().FirstOrDefault() ?? Application.OpenForms[0]); _client = new DdeClient("Dexis", "Patient", context); } if (!_client.IsConnected) { _client.Connect(); } string patId = pat.PatNum.ToString(); if (ProgramProperties.GetPropVal(progCur.ProgramNum, "Enter 0 to use PatientNum, or 1 to use ChartNum") == "1") { patId = pat.ChartNumber; } string ddeCommand = "SET " + patId + " LN=\"" + pat.LName + "\" FN=\"" + pat.FName + "\" MI=\"" + pat.MiddleI + "\""; if (pat.Birthdate.Year > 1880 && ddeCommand.Length < 244) //add optional bday only if valid and it won't increase the length to >255 characters { ddeCommand += " BD=" + pat.Birthdate.ToString("yyyyMMdd"); } _client.Execute(ddeCommand, 30000); //timeout 30 seconds //if execute was successfully sent, subscribe the PatientChangedEvent_Fired handler to the PatientChangedEvent.Fired event PatientChangedEvent.Fired -= PatientChangedEvent_Fired; PatientChangedEvent.Fired += PatientChangedEvent_Fired; UserodChangedEvent.Fired -= UserodChangedEvent_Fired; UserodChangedEvent.Fired += UserodChangedEvent_Fired; } catch (ObjectDisposedException ode) { if (_isRetry) { FriendlyException.Show(Lans.g("DexisIntegrator", "There was an error trying to launch Dexis with the selected patient."), ode); return; } _isRetry = true; if (_client != null && _client.IsConnected) { ODException.SwallowAnyException(new Action(() => _client.Disconnect())); //disconnect if necessary } ODException.SwallowAnyException(new Action(() => _client.Dispose())); _client = null; //will cause a new _client to be made with a new context SendData(progCur, pat); } catch (Exception ex) { FriendlyException.Show(Lans.g("DexisIntegrator", "There was an error trying to launch Dexis with the selected patient."), ex); return; } finally { _isRetry = false; } }
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 StopQuotes() { if (client.IsConnected == true) { client.Disconnect(); client.Dispose(); } }
public void Test_Poke_After_Dispose() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); client.Connect(); client.Dispose(); Assert.Throws<ObjectDisposedException>(() => client.Poke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, Timeout)); }
public void Test_BeginStartAdvise_After_Dispose() { using var server = new TestServer(ServiceName); server.Register(); server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData)); using var client = new DdeClient(ServiceName, TopicName); client.Connect(); client.Dispose(); Assert.Throws<ObjectDisposedException>(() => client.BeginStartAdvise(ItemName, 1, false, null, null)); }
public void Test_Abandon_After_Dispose() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); client.Connect(); client.Pause(); var ar = client.BeginExecute(CommandText, null, null); client.Dispose(); Assert.Throws<ObjectDisposedException>(() => client.Abandon(ar)); }
public void Test_EndExecute_After_Dispose() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); client.Connect(); var ar = client.BeginExecute(TestData, null, null); Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(Timeout, false)); client.Dispose(); Assert.Throws<ObjectDisposedException>(() => client.EndExecute(ar)); }
private void Dispose() { if (_ddeclient != null) { _ddeclient.Dispose(); } NotifyDDE("OFF Conexão ao DDE server parada"); this.Stop(); _omsclient = null; _ddeclient = null; }
public void Test_EndStartAdvise_After_Dispose() { using var server = new TestServer(ServiceName); server.Register(); server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData)); using var client = new DdeClient(ServiceName, TopicName); client.Connect(); var ar = client.BeginStartAdvise(ItemName, 1, true, null, null); Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(Timeout, false)); client.Dispose(); Assert.Throws<ObjectDisposedException>(() => client.EndStartAdvise(ar)); }
void c_Disconnected(object sender, DdeDisconnectedEventArgs e) { lock (_syncLock) { foreach (TOSDataPoint p in _dataPoints.Values) { p.OnDisconnected(); } OnDisconnection(this); c.Dispose(); } }
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(); } } }
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_Poke_After_Dispose() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Dispose(); client.Poke(ItemName, Encoding.ASCII.GetBytes(TestData), 1, Timeout); } } }
public void Test_BeginExecute_After_Dispose() { using (var server = new TestServer(ServiceName)) { server.Register(); using (var client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Dispose(); Assert.Throws<ObjectDisposedException>(() => client.BeginExecute(TestData, null, null)); } } }
public void Test_Execute_After_Dispose() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Dispose(); client.Execute(TestData, Timeout); } } }
public void Test_BeginExecute_After_Dispose() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { client.Connect(); client.Dispose(); IAsyncResult ar = client.BeginExecute(TestData, null, null); } } }
void IDisposable.Dispose() { if (disposed) { return; } if (client != null) { client.Dispose(); } client = null; disposed = true; }
public void Test_Request_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(); client.Dispose(); byte[] data = client.Request(ItemName, 1, Timeout); } } }
public void Test_Disconnected_Variation_3() { using var server = new TestServer(ServiceName); server.Register(); using var client = new DdeClient(ServiceName, TopicName); var listener = new EventListener(); client.Disconnected += listener.OnEvent; client.Connect(); client.Dispose(); Assert.IsTrue(listener.Received.WaitOne(Timeout, false)); var args = (DdeDisconnectedEventArgs) listener.Events[0]; Assert.IsFalse(args.IsServerInitiated); Assert.IsTrue(args.IsDisposed); }
public void Test_EndPoke_After_Dispose() { 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.Dispose(); client.EndPoke(ar); } } }
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_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); } } }
/** 移除所在連線資訊列(row)相關連線資訊與所關聯的項目(item)資訊 * <param = row_idx> dgView1 移除按鈕事件所在列的位置 */ private void Remove_Connect_and_Item_Row(int row_idx) { /** 確定為 "移除按鈕" 後的處理 * 1. 刪除 HashTable 內的 key/value, 以及 DdeClient instance * 2. 將該列(row)從 dgConnection(DataGridView) 移除。 */ //取得移除按鈕按下時所在的列(row) DataGridViewRow del_row = dgConnection.Rows[row_idx]; //取得刪除列的欄位(col_service, col_topic)值當成 key, 以取出所對應的 DdeClient 連線 instance. string key = del_row.Cells["col_service"].Value.ToString() + "|" + del_row.Cells["col_topic"].Value.ToString(); DdeClient client_conn = (DdeClient)ht_conn[key]; //利用 連線字串(service+topic) 為 key, 刪除相關聯(1到多) dgItemInfo 所在的 Item 列 ArrayList list = new ArrayList(); //暫存欲刪除的 Item Key. foreach (DictionaryEntry de1 in ht_gdv) { //取出 "!" 前面的字串 (service|topic) string item_key = de1.Key.ToString(); string item_key_substr = item_key.Substring(0, item_key.IndexOf("!")); //每一個欲刪除的 Item, 需先呼叫 DdeClient.StopAdvise if (key.Equals(item_key_substr)) { DataGridViewRow del_item_row = (DataGridViewRow)de1.Value; string item = del_item_row.Cells["col_iteminfo_Item"].Value.ToString(); this.Stop_advise(client_conn, item); list.Add(item_key); } } //實際刪除 Item 所在的 DataGridView Row, 以及移除儲存在 HashTable 的 key/value foreach (string str_key in list) { DataGridViewRow del_item_row = (DataGridViewRow)ht_gdv[str_key]; ht_gdv.Remove(str_key); dgItemInfo.Rows.Remove(del_item_row); } //刪除所儲存連線資訊的 key/value, 以及將該 DdeClient 連線移除。 ht_conn.Remove(key); client_conn.Dispose(); //將所在的連線資料列刪除掉 dgConnection.Rows.RemoveAt(row_idx); }
public void Dispose() { NotifyDDE("OFF Conexão ao DDE server parada"); _keealiveoms = false; _keealivecma = false; _keealivenpc = false; if (_cmaClient != null) { _cmaClient.Dispose(); } if (_npcClient != null) { _npcClient.Dispose(); } _omsclient = null; _cmaClient = null; _npcClient = null; }
public void Dispose() { client.Dispose(); }
static void Main(string[] args) { XDocument doc = XDocument.Load(".\\Plant.xml"); var pumps = doc.Root .Elements("drives") .Elements("pump") .Select(x => x) .ToList(); var pumpInputs = doc.Root .Elements("drives") .Elements("pump") .Elements("input") .Attributes("address") .Select(x => x.Value) .ToList(); var flowMeters = doc.Root .Elements("sensors") .Elements("flowMeter") .Select(x => x) .ToList(); foreach (var pump in pumps) { Hashtable DigitalInputs = new Hashtable(StringComparer.InvariantCultureIgnoreCase); var digitalInputs = pump.Elements("digitalInput").Select(x => x).ToList(); foreach (var i in digitalInputs) { var input = new DigitalInput(i.Attribute("name").Value.ToString(), i.Attribute("address").Value.ToString()); DigitalInputs.Add(i.Attribute("name").Value, (object)input); } Hashtable DigitalOutputs = new Hashtable(StringComparer.InvariantCultureIgnoreCase); var digitalOutputs = pump.Elements("digitalOutput").Select(x => x).ToList(); foreach (var i in digitalOutputs) { var output = new DigitalOutput(i.Attribute("name").Value.ToString(), i.Attribute("address").Value.ToString()); DigitalOutputs.Add(i.Attribute("name").Value, (object)output); } Hashtable AnalogInputs = new Hashtable(StringComparer.InvariantCultureIgnoreCase); var analogInputs = pump.Elements("analogInput").Select(x => x).ToList(); foreach (var i in analogInputs) { var input = new AnalogInput(i.Attribute("name").Value.ToString(), i.Attribute("address").Value.ToString(), i.Attribute("scaleLow").Value.ToString(), i.Attribute("scaleHigh").Value.ToString()); AnalogInputs.Add(i.Attribute("name").Value, (object)input); } Hashtable AnalogOutputs = new Hashtable(StringComparer.InvariantCultureIgnoreCase); var analogOutputs = pump.Elements("analogOutput").Select(x => x).ToList(); foreach (var i in analogOutputs) { var output = new AnalogOutput(i.Attribute("name").Value.ToString(), i.Attribute("address").Value.ToString(), i.Attribute("scaleLow").Value.ToString(), i.Attribute("scaleHigh").Value.ToString()); AnalogOutputs.Add(i.Attribute("name").Value, (object)output); } Pump p = new Pump(pump.Attribute("name").Value, DigitalInputs, DigitalOutputs, AnalogInputs, AnalogOutputs); double maxFlowRate; double.TryParse(pump.Attribute("maxFlowRate").Value, out maxFlowRate); p.MaxFlowRate = maxFlowRate; double rampUpTime; double.TryParse(pump.Attribute("rampUpTime").Value, out rampUpTime); p.rampUpTime = rampUpTime; double rampDownTime; double.TryParse(pump.Attribute("rampDownTime").Value, out rampDownTime); p.rampDownTime = rampDownTime; Pumps.Add(p); } foreach (var flowMeter in flowMeters) { var sources = flowMeter.Elements("source").Attributes("name").Select(x => x.Value).ToList(); FlowMeter f = new FlowMeter(sources, new Hashtable()); FlowMeters.Add(f); } lock (FieldInputsLock) { foreach (var i in pumpInputs) { _FieldInputs.Add(i, null); } } /* try * { * c = new DdeClient("RSLinx", "PlantSim"); * * c.Disconnected += C_Disconnected; * * Console.Write("Connecting..."); * c.Connect(); * Console.WriteLine(" OK"); * * Console.Write("Starting advisor..."); * c.Advise += C_Advise; * Console.WriteLine(" OK"); * * Console.Write("Adding vars..."); * * // RSLinx seems to reject the first register request. Try it 3 times, if it still doesn't work then an issue. * lock (FieldInputsLock) * { * foreach (var item in _FieldInputs.Keys) * { * if (item != null) * { * try * { * c.StartAdvise(item.ToString(), 1, true, 1000); * } * catch * { * try * { * c.StartAdvise(item.ToString(), 1, true, 1000); * } * catch * { * //If this doesn't work, fall through to exception handler * c.StartAdvise(item.ToString(), 1, true, 1000); * } * } * } * } * } * * Console.WriteLine(" OK"); * } * catch (Exception e) * { * Console.WriteLine(e.ToString()); * Console.ReadKey(); * } */ Timer t = new Timer(); t.Elapsed += T_Elapsed; t.Interval = 100; t.AutoReset = true; t.Start(); Console.WriteLine("Press any key to close application"); Console.ReadKey(); Console.Write("Stopping Timer..."); t.Stop(); t.Elapsed -= T_Elapsed; Console.WriteLine(" OK"); Console.Write("Closing DDE Link..."); c.Dispose(); // c.Disconnect(); Console.WriteLine(" OK"); }