1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- namespace CentralServer
- {
- class Program
- {
- public static gr672_pgvEntities db = new gr672_pgvEntities();
- static void Main(string[] args)
- {
- Listener();
- Console.Read();
- }
- public static async void Listener()
- {
- HttpListener listener = new HttpListener();
- listener.Prefixes.Add("http://127.0.0.1:8888/");
- listener.Start();
- Console.WriteLine("Start server...");
- while (true)
- {
- HttpListenerContext context = await listener.GetContextAsync();
- HttpListenerRequest request = context.Request;
- if (request.RawUrl.Contains("/getDataOfStore"))
- {
- string StoreID = request.RawUrl.Split('=')[1];
- int ID = Convert.ToInt32(StoreID);
- var Store = db.Stores.Find(ID);
- HttpListenerResponse response = context.Response;
- if (Store is null)
- {
- byte[] buffer = Encoding.UTF8.GetBytes("Магазин не найден");
- response.ContentLength64 = buffer.Length;
- Stream output = response.OutputStream;
- output.Write(buffer, 0, buffer.Length);
- output.Close();
- }
- else
- {
- List<RootDataOfCashier> dataOfCashier = new List<RootDataOfCashier>();
- foreach (var item in Store.Cashiers)
- {
- dataOfCashier.Add(new RootDataOfCashier { CashierID = item.CashierID });
- }
- RootDataOfStore rootDataOfStore = new RootDataOfStore();
- rootDataOfStore.Cashiers = dataOfCashier;
- rootDataOfStore.StoreID = Store.StoreID;
- rootDataOfStore.Address = Store.Address;
- string Json = JsonConvert.SerializeObject(rootDataOfStore);
- byte[] buffer = Encoding.UTF8.GetBytes(Json);
- response.ContentLength64 = buffer.Length;
- Stream output = response.OutputStream;
- output.Write(buffer, 0, buffer.Length);
- output.Close();
- }
- }
- }
- }
- }
- }
|