private void getReplyName() { try { if (ListSendServer != null) { if (ListSendServer.Count > 0) { List <String> ListClientsInfo = new List <string>(); ListClientsInfo = ServerObj.GetClientsInfo(); foreach (String s1 in ListSendServer) { foreach (String s2 in ListClientsInfo) { if (s1.Trim() == s2.Trim()) { String strInfo = s2.Split(')')[1].ToString().Trim(); String userReply = ""; if ((strInfo == null) || (strInfo == "")) { userReply = s2.Split('(')[0].ToString().Trim(); } else { userReply = strInfo.Split(';')[0].ToString().Trim(); } listViewTo.Items.Clear(); ListViewToItem = new ListViewItem[1]; ListSendServerListView.Add(userReply + ";" + ListReplyName[0].ToString().Trim()); ListViewToItem[0] = new ListViewItem(userReply); listViewTo.Items.AddRange(ListViewToItem); } } } btnClear.Enabled = true; txtMsg.Select(); txtMsg.Focus(); } } if (listViewTo.Items.Count == 0) { MessageBox.Show(SettingList["MsgBoxNoReplyMsg"], SettingList["MsgBoxCaptionWarning"], MessageBoxButtons.OK); this.Opacity = 0; this.Close(); } Visible = true; } catch (Exception ex) { MessageBox.Show(SettingList["MsgBoxErrListSendTo"] + ex.Message, SettingList["MsgBoxCaptionError"], MessageBoxButtons.OK); } }
public SelectForm(Dictionary <String, String> SettingList, IServerObject ServerObj, String userName) { InitializeComponent(); try { this.SettingList = SettingList; this.ServerObj = ServerObj; this.ListClientsInfo = ServerObj.GetClientsInfo(); this.ListADGroups = ServerObj.GetADGroups(); userNameCurrent = userName.Split('(')[0].Trim(); this.ListPrivateGroup = ServerObj.GetPrivateGroups(userNameCurrent); } catch { } }
private void SendMessage() { try { List <String> ListClientsInfo = new List <string>(); List <String> ListSend = new List <string>(); List <String> ListSendServer = new List <string>(); String ipAddressServer = ConfigurationSettings.AppSettings["ipAddressServer"].Trim(); int portServer = Convert.ToInt32(ConfigurationSettings.AppSettings["portServer"].Trim()); String to = ConfigurationSettings.AppSettings["to"].Trim(); String text = ConfigurationSettings.AppSettings["Text"].Trim(); if (ipAddressServer == "") { Console.Write("Parameter 'ipAddressServer' cannot be empty! Please check configuration file!"); return; } if (to == "") { Console.Write("Parameter 'to' cannot be empty! Please check configuration file!"); return; } if (text == "") { Console.Write("Parameter 'text' cannot be empty! Please check configuration file!"); return; } String hostName = Dns.GetHostName().ToLower(); if (hostName != "") { if (hostName.Length > 1) { hostName = hostName.ToLower(); hostName = hostName.Remove(1).ToUpper() + hostName.Substring(1); } else { hostName = hostName.ToUpper(); } } String userName = "******" + hostName + ")"; String serverURL = "tcp://" + ipAddressServer + ":" + portServer.ToString() + "/ServerObject.rem"; IServerObject ServerObj = (IServerObject)Activator.GetObject(typeof(IServerObject), serverURL); ListClientsInfo = ServerObj.GetClientsInfo(); if (to == "*") { ListSendServer = ListClientsInfo; if (ListSendServer.Count == 0) { Console.Write("Sorry. There is nobody to send this message."); return; } } else { String[] arrayTo = to.Split(';'); foreach (String arr in arrayTo) { String tmp = arr.Trim(); if (tmp == "") { continue; } ListSend.Add(tmp); } for (int i = 0; i < ListSend.Count; i++) { for (int j = 0; j < ListClientsInfo.Count; j++) { if (Regex.IsMatch(ListClientsInfo[j].ToString(), ListSend[i].ToString(), RegexOptions.IgnoreCase)) { ListSendServer.Add(ListClientsInfo[j].ToString().Split(')')[0].Trim() + ")"); } } } if (ListSendServer.Count > 0) { ListSendServer.Sort(); int index = 0; while (index < ListSendServer.Count - 1) { if (ListSendServer[index] == ListSendServer[index + 1]) { ListSendServer.RemoveAt(index); } else { index++; } } } else { Console.Write("Sorry. There is nobody to send this message."); return; } } AsyncCallback SendMessageCallBack = new AsyncCallback(SendMessageReturned); SendMessageDelegate SMDel = new SendMessageDelegate(ServerObj.SendMessageToServer); IAsyncResult SendMessageAsyncResult = SMDel.BeginInvoke(userName, ListSendServer, text, false, SendMessageCallBack, SMDel); Console.Write("The message has been sent."); } catch (Exception ex) { Console.Write("Cannot send this message. Either RSend server is offline or incorrect parameters in configuration file."); // + ex.ToString()); } }