private void CreateChat() { using (Stream stream = request.InputStream) { using (StreamReader reader = new StreamReader(stream)) { string test = reader.ReadToEnd(); //JsonConverter<Chat> jsonConverter = new JsonConverter(); Chat mychat = JsonConvert.DeserializeObject <Chat>(reader.ReadToEnd()); Console.WriteLine($"{mychat.Title}\n" + $"{mychat.IsPrivate}\n" + $"{mychat.ChatMembers.Count}"); Wheel_Context wheel_Context = new Wheel_Context(); ChatService chatService = new ChatService(wheel_Context); chatService.CreateChat(mychat); using (Stream outstream = response.OutputStream) { //Bitmap bitmap = new Bitmap(@"C:\Users\qwert\Desktop\1.jpg"); //ImageConverter converter = new ImageConverter(); //string jsonObj = JsonConvert.SerializeObject(bitmap); //byte[] buffer = (byte[])converter.ConvertTo(bitmap, typeof(byte[])); //response.ContentLength64 = buffer.Length; //outstream.Write(buffer, 0, buffer.Length); outstream.Close(); } Wheel_Context dbcontext = new Wheel_Context(); IUserService userService = new UserService(dbcontext); } } }
public async void TryLogin() { try { using (Stream stream = request.InputStream) { using (StreamReader reader = new StreamReader(stream)) { string data = reader.ReadToEnd(); string login = data.Split('&')[1]; string password = data.Split('&')[2]; //string deviceIp = data.Split('&')[3]; Wheel_Context dbcontext = new Wheel_Context(); IUserService userService = new UserService(dbcontext); User exist = await userService.IsUserExist(login, password); if (exist != null) { //Device device = new Device() { User = exist, IpAdress = deviceIp }; //await userService.AddDevice(device); User user = await userService.TryLogin(login, password); userService.SetOnline(user.Id); using (Stream outstream = response.OutputStream) { string jsonObj = JsonConvert.SerializeObject(user); byte[] buffer = Encoding.UTF8.GetBytes(jsonObj); response.ContentLength64 = buffer.Length; outstream.Write(buffer, 0, buffer.Length); outstream.Close(); } } else { using (Stream outstream = response.OutputStream) { string jsonObj = JsonConvert.SerializeObject(null); byte[] buffer = Encoding.UTF8.GetBytes(jsonObj); response.ContentLength64 = buffer.Length; outstream.Write(buffer, 0, buffer.Length); outstream.Close(); } } } } } catch (Exception ex) { } }
public Server(string ip, string port) { Wheel_Context dbcontext = new Wheel_Context(); this.ip = ip; this.port = port; Console.OutputEncoding = Encoding.UTF8; server = new HttpListener(); ServerConfiguration(); server.Start(); start(); }
public void Registration() { Wheel_Context dbcontext = new Wheel_Context(); IUserManipulationService userManipulationService = new UserManipulationService(dbcontext); using (Stream stream = request.InputStream) { using (StreamReader reader = new StreamReader(stream)) { dynamic json = reader.ReadToEnd(); User user = JsonConvert.DeserializeObject <User>(json); user = userManipulationService.Registration(user); Console.WriteLine("reged: " + user.Id.ToString() + ' ' + user.Login); } } }
//private bool Numcheck(string str) //{ // return int.TryParse(str, out int id); //} private async void GetProfile(int id) { Wheel_Context dbcontext = new Wheel_Context(); IUserManipulationService userManipulationService = new UserManipulationService(dbcontext); using (Stream stream = request.InputStream) { using (Stream outstream = response.OutputStream) { User user = await userManipulationService.GetUserByID(id); if (user != null) { Console.WriteLine(user.Id.ToString() + ' ' + user.Login); string jsonObj = JsonConvert.SerializeObject(user); byte[] buffer = Encoding.UTF8.GetBytes(jsonObj); response.ContentLength64 = buffer.Length; outstream.Write(buffer, 0, buffer.Length); outstream.Close(); } } } }
public UserService(Wheel_Context context) { this.context = context; }
public CommunicationService(Wheel_Context context) { this.context = context; }
public UserManipulationService(Wheel_Context context) { this.context = context; }
public ChatService(Wheel_Context context) { this.context = context; }