Esempio n. 1
0
        private async Task <bool> MessageExists(FoundMessage message, IDbConnection conn)
        {
            var sql    = @"SELECT * FROM foundMessage WHERE externalId=@ExternalId";
            var result = await conn.QueryAsync <FoundMessage>(sql, message);

            return(result.Count() != 0);
        }
Esempio n. 2
0
    // void spawnRandomClue(){
    //  int clueNr = rand.Next (messages.Count);
    //  receiveMessage (clueNr);
    // }

    public void receiveMessage(int messageId, bool showNotification = true)
    {
        GameObject clueObject = (GameObject)Resources.Load("Clue");
        GameObject clue       = Instantiate(clueObject);

        receivedClues.Add(clue);
        clue.transform.SetParent(clueParent, false);

        // Message message = messages.Find(x => x.messageId == messageId);
        Message message = database.localMessages.Find(x => x.messageId == messageId);
        Sprite  image   = null;

        if (message.spritePath != "")
        {
            image = Resources.Load <Sprite>(message.spritePath);
        }
        FoundMessage foundMessage = new FoundMessage(message.messageId, false, System.DateTime.Now);

        playerController.player.foundMessages.Add(foundMessage);

        clue.GetComponent <messageScript>().init(message, foundMessage, image, showNotification);
        sortMessages();

        if (showNotification)
        {
            playerScript.addXpValue(350);
        }
        if (!foundMessage.opened)
        {
            updateNotification();
        }
        updateTotal();
        playerController.savePlayer();
    }
Esempio n. 3
0
    public void init(Message message, FoundMessage foundMessage, Sprite image, bool notification = true)
    {
        if (notification)
        {
            UIManager.ShowNotification("MessageNotification", -1, true, "Ný Vísbending!", message.title, closedScroll);
        }
        this.message      = message;
        this.foundMessage = foundMessage;
        sTitle            = message.title;
        receivedTime      = foundMessage.time;
        string minute = this.receivedTime.Minute < 10 ? "0" + this.receivedTime.Minute.ToString() : this.receivedTime.Minute.ToString();

        sDate       = receivedTime.Hour.ToString() + ":" + minute + ", " + this.receivedTime.Day.ToString() + "/" + this.receivedTime.Month.ToString();
        sLocation   = message.location;
        sContent    = message.content;
        sSprite     = image;
        this.opened = foundMessage.opened;
        if (this.opened)
        {
            scrollImage.GetComponent <Image> ().overrideSprite = openScroll;
        }
        this.title.text   = sTitle;
        this.content.text = sContent;
        this.date.text    = sDate;
    }
Esempio n. 4
0
 public async Task InsertRedditTickerMessage(FoundMessage message, int id, IDbConnection conn)
 {
     foreach (var ticker in message.Tickers)
     {
         var sql = @"INSERT INTO stocktickersfoundmessage(
             foundmessageid,
             stocktickerid
         )
             VALUES(
                 @id,
                 @ticker)";
         await conn.ExecuteAsync(sql, new { id = id, ticker = ticker.ToUpper() });
     }
 }
Esempio n. 5
0
        private async Task <bool> CallApi(FoundMessage message)
        {
            var content = ConvertToJson(message);

            using (var httpClientHandler = new HttpClientHandler())
                using (var httpClient = new HttpClient(httpClientHandler))
                {
                    httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => {
                        return(true);
                    };
                    var result = await httpClient.PostAsync($"{_serviceConfigurations.ApiUrl}/Message", content);

                    return(result.StatusCode == HttpStatusCode.Created);
                }
        }
        public async Task <IActionResult> CreateRedditMessage(FoundMessage message)
        {
            try
            {
                var createdMessageId = await _messageService.InsertMessage(message);

                if (createdMessageId == -1)
                {
                    return(StatusCode(409, "Resource Already Exists"));
                }
                else
                {
                    return(StatusCode(201, createdMessageId));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Esempio n. 7
0
        public async Task <int> InsertMessage(FoundMessage message)
        {
            try
            {
                message.TimePosted = message.TimePosted.ToUniversalTime();
                await _connection.OpenAsync();

                using (var transaction = await _connection.BeginTransactionAsync())
                {
                    var inserted = await _commentsRepo.InsertRedditMessage(message, _connection);

                    if (inserted != -1)
                    {
                        try
                        {
                            await _commentsRepo.InsertRedditTickerMessage(message, inserted, _connection);

                            await transaction.CommitAsync();

                            return(inserted);
                        }
                        catch (Exception ex)
                        {
                            await transaction.RollbackAsync();

                            throw ex;
                        }
                    }
                    else
                    {
                        return(-1);
                    }
                }
            }
            finally
            {
                await _connection.CloseAsync();
            }
        }
Esempio n. 8
0
        public async Task <int> InsertRedditMessage(FoundMessage message, IDbConnection conn)
        {
            var sql = @"INSERT INTO foundMessage(
                source,
                subreddit,
                externalid,
                timeposted,
                message,
                sentiment
            )
                VALUES (
                    @Source,
                    @SubReddit,
                    @ExternalId,
                    @TimePosted,
                    @Message,
                    @Sentiment) RETURNING id";

            if (await MessageExists(message, conn))
            {
                return(-1);
            }
            else
            {
                var result = await conn.QueryAsync <int>(sql, new {
                    Source     = message.Source.ToLower(),
                    SubReddit  = message.SubReddit,
                    ExternalId = message.ExternalId,
                    TimePosted = message.TimePosted,
                    Message    = message.Message,
                    Sentiment  = message.Sentiment,
                });

                return(result.Single());
            }
        }
Esempio n. 9
0
 private StringContent ConvertToJson(FoundMessage message) =>
 new StringContent(JsonConvert.SerializeObject(message), Encoding.UTF8, "application/json");