Exemplo n.º 1
0
    private IEnumerator SendSavedMail(IEnumerable <string> FilePaths)
    {
        int retry = 0;

        do
        {
            try
            {
                foreach (string filePath in FilePaths)
                {
                    NetHelper.EmailPrototype prototype = JsonUtility.FromJson <NetHelper.EmailPrototype>(
                        json: File.ReadAllText(filePath));

                    bool isMailSend = NetHelper.SendMail(
                        subject: prototype.subject,
                        body: prototype.body,
                        HTMLBody: prototype.isHTML);

                    if (isMailSend)
                    {
                        File.Delete(filePath);
                        List <string> _FilePaths = FilePaths.ToList();
                        _FilePaths.Remove(filePath);

                        FilePaths = _FilePaths.AsEnumerable();
                        Debug.Log(
                            message: name + " saved form sended \'" + Path.GetFileName(filePath) + "\'");
                    }
                }
                if (FilePaths.Count() > 0)
                {
                    retry++;
                }

                Debug.Log(
                    message: name + "Retry number: " + retry.ToString());
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            yield return(new WaitForSecondsRealtime(30));
        }while (retry < 3 && FilePaths.Count() > 0);
    }
Exemplo n.º 2
0
    private IEnumerator SendFormAsync()
    {
        yield return(null);

        string subject = "Opinion form " +
                         DateTime.Now.ToString("g");
        string body = "<html><head><title>Opinion form</title></head>" +
                      "<body><p>";

        if (!string.IsNullOrWhiteSpace(Email.text))
        {
            body += "<h3> Contact info:</h3><li style =\"margin - left: 1em; \">" +
                    "<b>E-Mail: </b><i>" + Email.text + "</i>" +
                    "</li><hr>";
        }


        body += "<main>";

        if (!string.IsNullOrWhiteSpace(GeneralOpinion.text))
        {
            body += "<article><h3>General Opinion:</h3><br><div><pre>" +
                    GeneralOpinion.text +
                    "</pre></div></article>";
        }

        if (!string.IsNullOrWhiteSpace(Errors.text))
        {
            body += "<article><h3>Problems found:</h3><br><div><pre>" +
                    Errors.text +
                    "</pre></div></article>";
        }

        if (!string.IsNullOrWhiteSpace(Suggestions.text))
        {
            body += "<article><h3>Suggestions:</h3><br><div><pre>" +
                    Suggestions.text +
                    "</pre></div></article>";
        }

        body += "<hr></main>" +
                "<b>Opinion form send: </b>" + DateTime.Now.ToString("dd-MM-yyyy") + "<br>" +
                "<hr></p></body></html>";

        Debug.Log(
            message: name + " Opinion form ready to send.");

        bool isMailSend = NetHelper.SendMail(
            subject: subject,
            body: body,
            HTMLBody: true);

        if (!isMailSend)
        {
            Debug.Log(
                message: name + " E-Mail couldn't be send, saving for future re-try.");

            string savePath = this.savePath +
                              SystemInfo.deviceUniqueIdentifier + "_" +
                              DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") +
                              ".json";

            NetHelper.EmailPrototype prototype = new NetHelper.EmailPrototype(
                subject: subject,
                body: body,
                isHTML: true);

            AppHelper.SaveToFile(
                filePath: savePath,
                content: JsonUtility.ToJson(prototype));
        }
        else
        {
            Debug.Log(
                message: name + "Form sended.");
        }
        GameObject.Find("GameManager")
        .GetComponent <GameManager>()
        .LoadSceneAsync("MainMenu", true);
    }