/// <summary> /// Получение списка проектов и файлов сохраненные на серевер у данного пользователя /// </summary> /// <param name="client">Сокет клиента</param> /// <param name="login">Логин</param> /// <param name="isThisUser"></param> public static void GetListProject(Socket client, string login, bool isThisUser) { try { string quary = "select Project.*, ViewApplication.Name from Project " + "inner join HistoryDownload on HistoryDownload.idProject = Project.idProject " + "inner join Person on Person.idPerson = HistoryDownload.idPerson " + "inner join `User` on `User`.idUser = Person.idUser " + "inner join ViewApplication on ViewApplication.idViewApplication = Project.idViewApplication " + $"where `User`.Login = '******'"; MySqlClass.mySQLConn.Open(); MySql.Data.MySqlClient.MySqlDataReader reader = (new MySql.Data.MySqlClient.MySqlCommand(quary, MySqlClass.mySQLConn)).ExecuteReader(); while (reader.Read()) { int idProject = reader.GetInt32(0); string name = reader.GetString(2); int countVote = reader.GetInt32(3); double rating = reader.GetDouble(4); string date = reader.GetDateTime(5).ToString("dd-MM-yyyy"); string note = (reader.IsDBNull(7) == true) ? string.Empty : reader.GetString(7); string image = (reader.IsDBNull(8) == true) ? string.Empty : reader.GetString(8); string viewApplication = reader.GetString(9); ServerClass.SendMsgClient(client, 2048, 1002, isThisUser, idProject, name, countVote, rating, date, note, image, viewApplication); } } catch (Exception ex) { ServerClass.WriteConsoleMsg("GetListProject : " + ex.Message); } finally { MySqlClass.mySQLConn.Close(); } }
/// <summary> /// Получение списка категорий проекта разделеными символом '#' /// </summary> /// <returns>Строка с списком</returns> public static string GetListViewApplication() { string listData = string.Empty; try { string quary = "select Name from ViewApplication " + "where idViewApplication != -1"; MySqlClass.mySQLConn.Open(); MySql.Data.MySqlClient.MySqlDataReader reader = (new MySql.Data.MySqlClient.MySqlCommand(quary, MySqlClass.mySQLConn)).ExecuteReader(); while (reader.Read()) { listData += reader.GetString(0) + " #"; } } catch (Exception ex) { ServerClass.WriteConsoleMsg("GetListViewApplication : " + ex.Message); } finally { MySqlClass.mySQLConn.Close(); } return(listData); }
/// <summary> /// Создание пакетов файла и отправка пакета на сервер /// </summary> /// <param name="client">Socket клиента</param> public static void ContinueSendFile(Socket client) { foreach (var fileSend in listFileSend) { if (fileSend.user.socket == client) { if (fileSend != null && fileSend.progressSend.Length != 0) { uint lengthFile = (uint)fileSend.progressSend.Length; int nextPacketSize = (int)((lengthFile - fileSend.progress > FileSett.bufferSize) ? FileSett.bufferSize : lengthFile - fileSend.progress); if (fileSend.progress < lengthFile) { MemoryStream packet = new MemoryStream(new byte[nextPacketSize + 8], 0, nextPacketSize + 8, true, true); ServerClass.SendFileClient(fileSend.user.socket, 520, 1004, fileSend.progress, packet, nextPacketSize, fileSend.progressSend); } else { ServerClass.SendMsgClient(client, 16, 1005); listFileSend.Remove(fileSend); } fileSend.progress += nextPacketSize; break; } } } }
public ChatClient(Socket socket, ServerClass server) { //id = Guid.NewGuid(); client = socket; this.server = server; info = null; }
public ClientClass(TcpClient tcpClient, ServerClass server1) { Id = Guid.NewGuid().ToString(); client = tcpClient; server = server1; server1.AddConnection(this); }
/// <summary> /// Добавление свойства проекта в базу /// </summary> /// <param name="client">Сокет клиента</param> /// <param name="login">Логин пользователя</param> /// <param name="nameProject">Имя проекта</param> public static void AddNewProject(Socket client, string login, string nameProject) { string[] arrParm = { "@nameUserIn", "@nameProjectIn", "@datePublication", "@idProjectOut" }; string[] arrParmData = { login, nameProject, DateTime.Now.ToString("yyyy-MM-dd") }; string[] arrParmOut = MySqlClass.MySQLInOut("AddProject", arrParm, arrParmData); ServerClass.SendMsgClient(client, 64, 1006, arrParmOut[0]); }
/// <summary> /// Проверяет логин\email на уникальность /// </summary> /// <param name="client">Сокет клиента</param> /// <param name="login">Логин</param> /// <param name="email">Почта</param> /// <param name="idOperation">Номер операции которая выполнется в клиенте</param> public static void CheckUnique(Socket client, string login, string email, int idOperation = 2) { string[] arrParm = { "@loginIn", "@emailIn", "@loginOutBool" }; string[] arrParmData = { login, email }; string[] arrParmOut = MySqlClass.MySQLInOut("CheckUnique", arrParm, arrParmData); ServerClass.SendMsgClient(client, 64, idOperation, Int32.Parse(arrParmOut[0])); }
/// <summary> /// Получение всей информации о проекте из базы /// </summary> /// <param name="client">Клиент</param> /// <param name="loginUser">Логин</param> /// <param name="nameProject">Имя проекта</param> public static void GetFullInfoForProject(Socket client, string loginUser, string nameProject) { string[] arrParm = { "@loginUserIn", "@nameProjectIn", "@datePub", "@rating", "@countVote", "@note", "@image", "@viewApp" }; string[] arrParmData = { loginUser, nameProject }; string[] arrParmOut = MySqlClass.MySQLInOut("GetInfoProject", arrParm, arrParmData); ServerClass.SendMsgClient(client, 512, 8, nameProject, arrParmOut[0], arrParmOut[1], arrParmOut[2], arrParmOut[3], arrParmOut[4], arrParmOut[5]); }
/// <summary> /// Получаем всю информацию о пользователе из базы /// </summary> /// <param name="client">Сокет клиента</param> /// <param name="login">Логин</param> /// <param name="isThisUser"></param> public static void CheckFullInfoOfPerson(Socket client, string login, bool isThisUser) { string[] arrParm = { "@loginUser", "@nameOut", "@lastnameOut", "@levelOut", "@likeOut", "@imageOut", "@emailOut", "@countProjectOut", "@noteOut", "@countSubOut" }; string[] arrParmData = { login }; string[] arrParmOut = MySqlClass.MySQLInOut("CheckFullInfoPerson", arrParm, arrParmData); ServerClass.SendMsgClient(client, 1024, 3, isThisUser, arrParmOut[0], arrParmOut[1], Int32.Parse(arrParmOut[2]), Int32.Parse(arrParmOut[3]), arrParmOut[4], arrParmOut[5], arrParmOut[6], arrParmOut[7], arrParmOut[8]); }
internal static List <FileSett> listFileSend = new List <FileSett>(); // Список файлов который в данный момент скачиваются из сервера #region База - Сервер /// <summary> /// Читает данные о пользователе и отправляет ответ клиенту /// </summary> /// <param name="client">Сокет клиента</param> /// <param name="login">Логин</param> /// <param name="password">Пароль</param> public static void CheckLoginAndPasswordUser(Socket client, string login, string password) { string[] arrParm = { "@loginIn", "@passIn", "@loginOut" }; string[] arrParmData = { login, password }; string[] arrParmOut = MySqlClass.MySQLInOut("CheckLoginAndPassUser", arrParm, arrParmData); Connect(ServerClass.nextID++, login, client); ServerClass.SendMsgClient(client, 64, 1, Int32.Parse(arrParmOut[0])); }
public User Constructor( string username, int id, decimal funds, List<InvestmentData> investments, byte[] keyFile, ServerClass server ) { User target = new User(username, id, funds, investments, keyFile, server); return target; // TODO: add assertions to method UserTest.Constructor(String, Int32, Decimal, List`1<InvestmentData>, Byte[], ServerClass) }
/// <summary> /// Изменяет данные у проекта в базе /// </summary> /// <param name="client">Клиент</param> /// <param name="id">id проекта</param> /// <param name="name">Имя</param> /// <param name="viewApp">Категория</param> /// <param name="note">Описание</param> /// <param name="hrefImage">Ссылка на изображение</param> public static void UpdateInfoForProject(Socket client, int id, string name, int viewApp, string note, string hrefImage) { string[] arrParm = { "@idProj", "@nameProj", "@viewApp", "@note", "@hrefImage", "@isRenameProj", "@oldNameProj" }; string[] arrParmData = { id.ToString(), name, viewApp.ToString(), note, hrefImage }; string[] arrParmOut = MySqlClass.MySQLInOut("UpdateInfoForProject", arrParm, arrParmData); if (arrParmOut[0].Equals("1")) { ServerClass.SendMsgClient(client, 512, 1007, name); string nameUser = ServerClass.clients.FirstOrDefault(f => f.socket == client).name; File.Move(ServerClass.pathProjectFile + "\\" + nameUser + "\\" + arrParmOut[1], ServerClass.pathProjectFile + "\\" + nameUser + "\\" + name); } }
static void Main(string[] args) { try { server = new ServerClass(); listenThread = new Thread(new ThreadStart(server.Listen)); listenThread.Start(); } catch (Exception ex) { server.Disconnect(); Console.WriteLine(ex.Message); } }
/// <summary> /// Получение файлов от клиента (по пакетам) /// </summary> /// <param name="fileSize">Записываемый буффер</param> /// <param name="infoFile">Количество байт полученных от клиента</param> /// <param name="countRecByte">Размер пакета</param> internal static void ReceivedFile(FileSett file, byte[] infoFile, int countRecByte) { /* * if (file.progressSend == null) * file.progressSend = infoFile; * * else * { * byte[] buf = file.progressSend; * Array.Resize(ref file.progressSend, countRecByte + file.progressSend.Length); * Buffer.BlockCopy(buf, 0, file.progressSend, 0, buf.Length); * Buffer.BlockCopy(infoFile, 0, file.progressSend, file.progress, countRecByte); * } */ Buffer.BlockCopy(infoFile, 0, file.progressSend, file.progress - countRecByte, countRecByte); ServerClass.SendMsgClient(file.user.socket, 256, 1001); }
public RequestManager(ServerClass serverClass) { this.serverClass = serverClass; utf8 = new UTF8Encoding(); Log.Write("Starting to generate public/private key pair."); waitForKeyGeneration = new EventWaitHandle(false, EventResetMode.ManualReset); rsa = new RSACrypto(); rsa.OnKeysGenerated += new RSACrypto.KeysGenerated(KeyGenerated); rsa.GenerateKeys(2048); aes = new AesManaged(); listener = new HttpListener(); listener.Prefixes.Add("http://*:80/"); alive = false; Log.Write("Request manager created, and ready to start server."); }
/// <summary> /// Main method /// </summary> static void Main() { mServer = new ServerClass(); OutputProjects(mServer.GetProjectList()); ThreadPool.QueueUserWorkItem(new WaitCallback(SocketThread)); ThreadPool.QueueUserWorkItem(new WaitCallback(WCFThread)); ThreadPool.QueueUserWorkItem(new WaitCallback(CheckClients)); ThreadPool.QueueUserWorkItem(new WaitCallback(SaveFile)); DisplayCommands(); while (Run) { string cmd = Console.ReadLine(); //string cmd = "l"; switch (cmd) { case "l": mServer.LoadFile(); break; case "s": mServer.SaveFile(); break; case "se": mServer.SaveFile(); Run = false; break; case "e": Run = false; break; default: Console.WriteLine("Wrong command!"); DisplayCommands(); break; } } }
/// <summary> /// Отправка клиенту топ лучших проектов /// </summary> /// <param name="client">Клиент</param> /// <param name="login">Имя клиента</param> public async void RandomPeople(Socket client, string login) { List <List <dynamic> > infoUser; string quary = "SELECT `User`.Login, Person.`Level`,Person.image FROM Person inner join `User` on `User`.idUser = Person.idUser " + " JOIN(SELECT RAND() * (SELECT MAX(idPerson) FROM Person) AS max_id ) AS m " + $" WHERE Person.idPerson >= m.max_id and `User`.Login != '{login}' " + " ORDER BY Person.idPerson ASC " + " LIMIT 10; "; await Task.Run(() => { infoUser = MySqlClass.MySqlQuaryOut(quary, 0, 1, 2); for (int i = 0; i < infoUser[0].Count; i++) { ServerClass.SendMsgClient(client, 2048, 2002, infoUser[0][i], infoUser[1][i], infoUser[2][i]); } ServerClass.SendMsgClient(client, 2048, 2002, "###ThisNull###"); }); }
/// <summary> /// Поиск людей по введенной строке /// </summary> /// <param name="stringFind">Подстрока</param> public async void SearchPeople(Socket client, string stringFind) { List <List <dynamic> > peopleInfo; string quary = "select `User`.Login, Person.image, Person.Level, Count(*) from Person " + " inner join `User` on `User`.idUser = Person.idUser " + " inner join HistoryDownload on HistoryDownload.idPerson = Person.idPerson " + $" where `User`.Login like('%{stringFind}%') " + " group by Person.idPerson "; await Task.Run(() => { peopleInfo = MySqlClass.MySqlQuaryOut(quary, 0, 1, 2, 3); for (int i = 0; i < peopleInfo[0].Count; i++) { ServerClass.SendMsgClient(client, 2048, 2000, peopleInfo[0][i], peopleInfo[1][i], peopleInfo[2][i], peopleInfo[3][i]); } ServerClass.SendMsgClient(client, 2048, 2000, "###ThisNull###"); }); }
static void Main(string[] args) { ServerClass sc = new ServerClass(15321); sc.ClientAntwort += ClientAntwort; sc.Start(); while (sc.Running == true) { Console.WriteLine("To stop the Server press ESC"); ConsoleKeyInfo cki = Console.ReadKey(); if (cki.Key == ConsoleKey.Escape) { sc.Stop(); } } Console.WriteLine("Press any Key to close the Program. . ."); Console.ReadKey(); }
/// <summary> /// Отправка клиенту топ лучших проектов /// </summary> /// <param name="client">Клиент</param> public async void SendTopProject(Socket client) { List <List <dynamic> > projectInfo; string quary = "SELECT `User`.Login, Project.`Name`, Project.image, Project.Rating, Project.Note FROM Person " + " inner join `HistoryDownload` on HistoryDownload.idPerson = Person.idPerson " + " inner join `User` on `User`.idUser = Person.idUser " + " inner join Project on Project.idProject = HistoryDownload.idProject " + " order by(Project.Rating) desc " + " Limit 10; "; await Task.Run(() => { projectInfo = MySqlClass.MySqlQuaryOut(quary, 0, 1, 2, 3, 4); for (int i = 0; i < projectInfo[0].Count; i++) { ServerClass.SendMsgClient(client, 2048, 2001, projectInfo[0][i], projectInfo[1][i], projectInfo[2][i], projectInfo[3][i], projectInfo[4][i]); } ServerClass.SendMsgClient(client, 2048, 2001, "###ThisNull###"); }); }
public Updater(ServerClass server) { mServer = server; }
public Updater() { mServer = new ServerClass(); }
public ServerClass Constructor(string predictorName, string pathToFixml) { ServerClass target = new ServerClass(predictorName, pathToFixml); return target; // TODO: add assertions to method ServerClassTest.Constructor(String, String) }
static void Main(string[] args) { ServerClass server = new ServerClass("127.0.0.1", 11000); server.Listen(10); }
public void SetServer(ServerClass server) { mServer = server; }
public static void Main(String[] args) { Contract.Requires(!ReferenceEquals(args, null)); Contract.Requires(args.All(s => !String.IsNullOrWhiteSpace(s))); Contract.Requires(args.Length >= 2); Contract.Requires(File.Exists(args[1])); if (args.Length < 2) { Console.WriteLine("To start the PocketInvester Server use:"); Console.WriteLine("./Server.exe <predictor name> <path to FIXML>"); return; } Log.Write("PocketInvestor starting."); ServerClass server = new ServerClass(args[0], args[1]); if (args.Any(a => a.Equals("-genkeys"))) server.GenerateKeyFiles(); server.requestManager.StartServer(); }
private void StartButton_Click(object sender, EventArgs e) { ServerClass server = new ServerClass(StatusTextBox); server.StartServer(); }