protected override void OnMessage(MessageEventArgs e)
            {
                MsgType msgType = (MsgType)JsonDocument.Parse(e.Data).RootElement.GetProperty("type").GetInt32();

                if (msgType == MsgType.GetKey)
                {
                    Console.WriteLine("Client asks for public key");
                    SendKeyMsg sendKeyMsg    = new SendKeyMsg(Decryptor.RSACreateKeys());
                    string     serializedMsg = JsonSerializer.Serialize <SendKeyMsg>(sendKeyMsg);
                    Send(serializedMsg);
                }

                if (msgType == MsgType.DES)
                {
                    DESDbStringMes ecnryptedDbString = JsonSerializer.Deserialize <DESDbStringMes>(e.Data);
                    DESDbStringMes testEncDbString   = JsonSerializer.Deserialize <DESDbStringMes>(e.Data);
                    ecnryptedDbString.Key = Decryptor.RSAdecrypt(ecnryptedDbString.Key);
                    string      serializedDbString = Decryptor.DESdecrypt(ecnryptedDbString);
                    DbStringMsg dbString           = JsonSerializer.Deserialize <DbStringMsg>(serializedDbString);

                    Console.WriteLine(dbString.surname + ' ' + dbString.name + ' ' + dbString.second_name + ' ' +
                                      dbString.country + ' ' + dbString.picture + ' ' + dbString.exposition);

                    Artist artist = new Artist(
                        dbString.name, dbString.surname, dbString.second_name,
                        new Country(dbString.country), new Movement(dbString.movement), new Picture(dbString.picture),
                        new Exposition(dbString.exposition)
                        );

                    PgConnector.InsertData(artist);

                    //Send("You just have sent \"" + e.Data + "\" to me.");
                }
            }
Beispiel #2
0
        static public List <DbStringMsg> createDbStringMsgList(DataTable table)
        {
            List <DbStringMsg> dbStringMsgs = new List <DbStringMsg>();

            foreach (DataRow row in table.Rows)
            {
                string surname     = row["surname"].ToString();
                string name        = row["name"].ToString();
                string second_name = row["second_name"].ToString();
                string country     = row["country"].ToString();
                string picture     = row["picture"].ToString();
                string movement    = row["movement"].ToString();
                string exposition  = row["exposition"].ToString();

                DbStringMsg dbStrMsg = new DbStringMsg(surname, name, second_name, country, picture, movement, exposition);
                dbStringMsgs.Add(dbStrMsg);
            }

            return(dbStringMsgs);
        }