Ejemplo n.º 1
0
    public IEnumerator tryPost()
    {
        UnityWebRequest httpClient = new UnityWebRequest(player.HttpServerAddress + "api/Message/RegisterMessage", "POST");

        MessageSerializable newMessage = new MessageSerializable();

        newMessage.Id      = player.Id;
        newMessage.Message = messageInput.text;

        string jsonData = JsonUtility.ToJson(newMessage);

        byte[] dataToSend = Encoding.UTF8.GetBytes(jsonData);
        httpClient.uploadHandler      = new UploadHandlerRaw(dataToSend);
        httpClient.certificateHandler = new ByPassCertificate();
        httpClient.SetRequestHeader("Content-Type", "application/json");
        httpClient.SetRequestHeader("Authorization", "bearer " + player.Token);
        yield return(httpClient.SendWebRequest());

        if (httpClient.isNetworkError || httpClient.isHttpError)
        {
            throw new Exception("OnPostButtonClick: Error > " + httpClient.error);
        }

        httpClient.Dispose();
    }
Ejemplo n.º 2
0
    private IEnumerator InsertMessage()
    {
        MessageSerializable messageSerializable = new MessageSerializable();

        messageSerializable.IdPlayer = player.Id;
        messageSerializable.Content  = messageContent.text;

        using (UnityWebRequest httpClient = new UnityWebRequest(player.HttpServerAddress + "/api/Message/InsertNewMessage", "POST"))
        {
            string playerData = JsonUtility.ToJson(messageSerializable);
            byte[] bodyRaw    = Encoding.UTF8.GetBytes(playerData);
            httpClient.uploadHandler   = new UploadHandlerRaw(bodyRaw);
            httpClient.downloadHandler = new DownloadHandlerBuffer();

            httpClient.SetRequestHeader("Content-type", "application/json");
            httpClient.SetRequestHeader("Authorization", "bearer " + player.Token);

            yield return(httpClient.SendWebRequest());

            if (httpClient.isNetworkError || httpClient.isHttpError)
            {
                throw new System.Exception("InsertMessage > Error: " + httpClient.responseCode + ", Info: " + httpClient.error);
            }
            else
            {
                Debug.Log("InsertMessage > Info: " + httpClient.responseCode);
            }
        }
        messageContent.text = "";
    }
Ejemplo n.º 3
0
        public MessageSerializable.Message Execute_StockedProcedure(MessageSerializable.Message msg)
        {
            if(msg.Data[0].GetType() != typeof(TSQLProcedure))
                return msg;
            TSQLProcedure procedure = (TSQLProcedure)msg.Data[0];

            Program.Debug("Execution de la procedure: *"+procedure.Name+"*");

            this.oCNX.Open();

            // Creation de l'objet de commande en précisant le nom de la procédure
            OleDbCommand cmd = new OleDbCommand(procedure.Name, this.oCNX);

            // Dire à l'objet de commande qu'il est de type procédure stockée
            cmd.CommandType = CommandType.StoredProcedure;

            OleDbDataAdapter adp = new OleDbDataAdapter();

            // Ajouter les paramètres de la procédure
            if (procedure.Parameters != null)
            {
                foreach (ProcedureParameter param in procedure.Parameters)
                {
                    cmd.Parameters.Add(new OleDbParameter(param.Name, param.Type)).Value = param.Value;
                }
            }

            // Executer la commande
            DataSet ds = new DataSet();
            adp.SelectCommand = cmd;
            adp.Fill(ds);

            if (procedure.Name.Contains("Display") || procedure.Name.Contains("Select"))
            {
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                    Program.Debug("Le dataset retourné est null");
                else
                {
                    Program.Debug("Le dataset retourné contient des résultats\n");
                    Program.DebugPrintDataSet(ds);
                }
            }

            this.oCNX.Close();

            MessageSerializable.Message reponse = msg;
            reponse.Data[0] = ds;
            reponse.Statut = true;
            return reponse;
        }
Ejemplo n.º 4
0
    // ------------------------------------------------------------------------
    // Methods
    // ------------------------------------------------------------------------
    public Message(MessageSerializable serializedMessage)
    {
        node        = serializedMessage.node;
        player      = serializedMessage.player;
        clueGiven   = serializedMessage.clueGiven;
        Messages    = serializedMessage.messages;
        options     = serializedMessage.options;
        clueNeeded  = serializedMessage.clueNeeded;
        branch      = serializedMessage.branch;
        image       = serializedMessage.image;
        imageHeight = serializedMessage.imageHeight;
        imageWidth  = serializedMessage.imageWidth;

        OptionSelection = -1;
    }
Ejemplo n.º 5
0
        public static MessageSerializable.Message ModifierNode(MessageSerializable.Message msg)
        {
            string[] nodes = new string[2];
            string[] mails = new string[2];

            nodes = (string[])msg.Data[0];
            mails = (string[])msg.Data[1];

            //on crée un objet XmlDocument
            XmlDocument doc = new XmlDocument();

            //on charge le fichier XML
            doc.Load(SMTP_CONFIG_PATH);

            for (int i = 0; i < nodes.Length; i++)
            {
                doc.DocumentElement.SelectSingleNode("/Config/" + nodes[i]).InnerText = mails[i];
            }

            doc.Save(SMTP_CONFIG_PATH);

            return msg;
        }
Ejemplo n.º 6
0
        public MessageSerializable.Message SendMail(MessageSerializable.Message msg)
        {
            if (msg.Data[0].GetType() == typeof(string))
            {
                try
                {
                    message.To.Add((string)msg.Data[0]);
                    message.Subject = "JPO Exia Cesi";
                    message.From = new System.Net.Mail.MailAddress(config.Address, "Exia Cesi");
                    if ((string)msg.Data[1] == null)
                    {
                        msg.Statut = false;
                        return msg;
                    }
                    else
                    {
                        message.Body = (string)msg.Data[1];
                    }

                    smtp.Host = config.Host;
                    smtp.Port = config.Port;
                    smtp.EnableSsl = config.EnableSSL;
                    smtp.Send(message);

                    msg.Statut = true;
                    return msg;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERREUR :" + ex.Message);
                    msg.Statut = false;
                    return msg;
                }
            }
            msg.Statut = false;
            return msg;
        }
Ejemplo n.º 7
0
    public IEnumerator tryGet()
    {
        UnityWebRequest httpClient = new UnityWebRequest(player.HttpServerAddress + "api/Message/GetMessage", "GET");

        httpClient.SetRequestHeader("Authorization", "bearer " + player.Token);
        httpClient.SetRequestHeader("Accept", "application/json");
        httpClient.certificateHandler = new ByPassCertificate();
        httpClient.downloadHandler    = new DownloadHandlerBuffer();

        yield return(httpClient.SendWebRequest());

        if (httpClient.isNetworkError || httpClient.isHttpError)
        {
            throw new Exception("Chat > GetMessage: " + httpClient.error);
        }
        else
        {
            string jsonResponse             = httpClient.downloadHandler.text;
            MessageSerializable messageJson = JsonUtility.FromJson <MessageSerializable>(jsonResponse);
            messageOnChat.text = messageOnChat.text + "\n" + messageJson.Id.Substring(0, 3) + ">" + messageJson.Message;
        }

        httpClient.Dispose();
    }