public static void ManipClientObject(ThisDevice thisObject) { if (thisObject.data == "REMOVE_THIS_DEVICE") { UpdateFlag = 1; ListClient.Remove(thisObject); } else { foreach (var item in ListClient) { if (item.address.Equals(thisObject.address)) { if (!item.data.Equals(thisObject.data)) { item.data = thisObject.data; } } } if (thisObject.flag == 1) { UpdateFlag = 1; ListClient.Add(thisObject); Cnt++; thisObject.flag = 1; } } }
// Accept 동작의 Default 대리자 Method private void Default_Accept_Work(Socket sock, Object obj) { ListClient.Add(sock.RemoteEndPoint.ToString(), sock); Console.WriteLine("Connected : {0}", sock.RemoteEndPoint.ToString()); }
private void syncServerCtl1_DataReceivedHandler(int ClientID, object Data) { #region PopupMessageSend if (Data is DtPopUpMessageSend) { DtPopUpMessageSend pms = (DtPopUpMessageSend)Data; if (pms.MessageType == enMessageType.InternalMessage && pms.Caption == "_Warning_") { string strQuery = CreateSqlWarning(pms.MessageData.ToString()); //using (StreamWriter sw = new StreamWriter("DataLog.txt", false)) //{ // sw.WriteLine("Events utk Tabel: " + pms.MessageData.ToString() + // ", NoDok: " + pms.Message); // sw.WriteLine(strQuery); //} IList <clsWarningSend> ListWarningSend = BaseFramework.DefaultDp .ListFastLoadEntitiesUsingSqlSelect <clsWarningSend>(null, strQuery, string.Empty, new FieldParam("NoDok", pms.Message)); DtPopUpMessageReceive pmr = new DtPopUpMessageReceive( FindSender(ClientID), pms.Caption, pms.Message, null, enMessageType.Information); foreach (clsWarningSend ws in ListWarningSend) { //using (StreamWriter sw = new StreamWriter("DataLog.txt", true)) //{ // sw.WriteLine(ws.NoDokumen + ":" + ws.NamaPeringatan); // sw.WriteLine("Penanggung Jawab: " + ws.PenanggungJawab); // sw.WriteLine("DictUserClient.Count=" + DictUserClient.Count); // foreach (string nm in DictUserClient.Keys) // sw.WriteLine(nm); //} pmr.Caption = ws.NamaPeringatan; pmr.Message = string.Concat("NoDok: ", ws.NoDokumen, "; Pembuat: ", ws.Pembuat, '\n', ws.Keterangan); pmr.MessageType = ws.JenisWarning ? enMessageType.Warning : enMessageType.Information; List <int> ListClient; if (DictUserClient.TryGetValue( ws.PenanggungJawab.ToLower(), out ListClient)) { foreach (int Id in ListClient) { syncServerCtl1.Send(Id, pmr); } } } } else { DtPopUpMessageReceive pmr = new DtPopUpMessageReceive( FindSender(ClientID), pms.Caption, pms.Message, pms.MessageData, pms.MessageType); foreach (string UserName in pms.UserName) { List <int> ListClient; if (DictUserClient.TryGetValue(UserName.Trim().ToLower(), out ListClient)) { foreach (int Id in ListClient) { syncServerCtl1.Send(Id, pmr); } } } } return; } #endregion #region RaiseEventData if (Data is DtRaiseEventData) { DtRaiseEventData red = (DtRaiseEventData)Data; int Id; if (DictActionListener.TryGetValue(red.EventName, out Id)) { syncServerCtl1.Send(Id, red); } List <int> ListClient; if (DictUserListener.TryGetValue(red.EventName, out ListClient)) { foreach (int ClId in ListClient) { syncServerCtl1.Send(ClId, red); } } return; } #endregion #region RegisterActionListener if (Data is DtRegisterActionListener) { DtRegisterActionListener ral = (DtRegisterActionListener)Data; foreach (string EventName in ral.EventName) { if (!DictActionListener.ContainsKey(EventName)) { DictActionListener.Add(EventName, ClientID); } else { syncServerCtl1.Send(ClientID, new DtPopUpMessageReceive("BxEventServer", "Error Registrasi Action Listener", string.Concat( "Event ", EventName, " sudah dihandle Action Listener lain !"), null, enMessageType.Error)); } } return; } #endregion #region RegisterUserListener if (Data is DtRegisterUserListener) { DtRegisterUserListener rul = (DtRegisterUserListener)Data; foreach (string EventName in rul.EventName) { List <int> ListClient; if (!DictUserListener.TryGetValue(EventName, out ListClient)) { ListClient = new List <int>(); DictUserListener.Add(EventName, ListClient); } else { bool ClientExist = false; foreach (int cl in ListClient) { if (cl == ClientID) { ClientExist = true; break; } } if (ClientExist) { continue; } } ListClient.Add(ClientID); } return; } #endregion #region DtLogin if (Data is DtLogin) { DtLogin lg = (DtLogin)Data; List <int> ListClient; if (!DictUserClient.TryGetValue(lg.UserName.ToLower(), out ListClient)) { ListClient = new List <int>(); DictUserClient.Add(lg.UserName.ToLower(), ListClient); } ListClient.Add(ClientID); syncServerCtl1.Send(ClientID, true); //using (StreamWriter sw = new StreamWriter("DataLog.txt", false)) //{ // sw.WriteLine(lg.UserName + " Logged; ClientId=" + ClientID); //} //string Message = BuildWelcomeMessage(); //if (Message.Length > 0) //{ // DateTime dt = DateTime.Now; // string Caption; // if (dt.Hour <= 10) // Caption = "Selamat Pagi !"; // else if (dt.Hour <= 15) // Caption = "Selamat Siang !"; // else if (dt.Hour <= 19) // Caption = "Selamat Sore !"; // else // Caption = "Selamat Malam !"; // syncServerCtl1.Send(ClientID, new DtPopUpMessageReceive( // string.Empty, Caption, // Message, null, enMessageType.Information)); //} } #endregion }