Ejemplo n.º 1
0
        public async Task <JsonResult> GetQuotes()
        {
            QuotesData quotesData = new QuotesData();

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync("https://opinionated-quotes-api.gigalixirapp.com/v1/quotes"))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    quotesData = JsonConvert.DeserializeObject <QuotesData>(apiResponse);

                    //foreach (var quote in quotesData.Quotes)
                    //{
                    //    QuoteMap newQuote = new QuoteMap()
                    //    {
                    //        Author = quote.Author,
                    //        Lang = quote.Lang,
                    //        Quote = quote.quote,
                    //        Tags = string.Join(",",quote.Tags.ToArray())
                    //    };
                    //    _bookService.AddQuote(newQuote);
                    //}
                }
            }

            //TODO: Save to our db// saved with the foreach loop

            return(Json(quotesData));
        }
Ejemplo n.º 2
0
        public override async Task GetQuotesStream(Stock request, IServerStreamWriter <QuotesData> responseStream, ServerCallContext context)
        {
            Random random = new Random();
            double previousValue = 0, variationValue = 0, percentageChange = 0, currentValue = 0;
            string bearOrBull = string.Empty;

            while (!context.CancellationToken.IsCancellationRequested)
            {
                currentValue     = random.NextDouble(1276.00, 1285.50);
                bearOrBull       = (previousValue > currentValue ? "🐻" : "🐂");
                variationValue   = currentValue - (previousValue == 0 ? currentValue : previousValue);
                percentageChange = (previousValue > 0 ? ((currentValue / previousValue) * 100) - 100 : 0);
                var quotes = new QuotesData
                {
                    Datetime         = DateTime.UtcNow.ToString(),
                    Ticker           = request.Ticker,
                    Quote            = currentValue.ToString("f2"),
                    Priorquote       = previousValue.ToString("f2"),
                    Variationvalue   = variationValue.ToString("f2"),
                    Percentagechange = $"{percentageChange.ToString("f2")}%",
                    Details          = $"{bearOrBull}"
                };

                previousValue = currentValue;
                _logger.LogInformation($"Sending {request} quotes");
                await responseStream.WriteAsync(quotes);

                await Task.Delay(1200);
            }

            if (context.CancellationToken.IsCancellationRequested)
            {
                _logger.LogInformation("The client cancelled their request");
            }
        }
Ejemplo n.º 3
0
        private ExchangeRateResponse ToResponse(YahooManaged.Base.Response <HistQuotesResult> resp, YCurrencyID[] currencies)
        {
            List <ExchangeRateData> lst = new List <ExchangeRateData>();

            if (resp.Result != null)
            {
                foreach (HistQuotesDataChain hqc in resp.Result.Chains)
                {
                    if (hqc.Count > 0)
                    {
                        YCurrencyID cur = FinanceHelper.YCurrencyIDFromString(hqc.ID);
                        if (cur != null)
                        {
                            QuotesData q = new QuotesData();
                            q.SetID(hqc.ID);
                            HistQuotesData hqd = (HistQuotesData)hqc[0];
                            q.Change             = hqd.Close - hqd.PreviousClose;
                            q.LastTradePriceOnly = hqd.Close;
                            q.LastTradeDate      = hqd.TradingDate;
                            q.Volume             = hqd.Volume;
                            lst.Add(new ExchangeRateData(cur.BaseCurrency, cur.DepCurrency, q));
                        }
                    }
                }
            }
            return(new ExchangeRateResponse(resp.Connection, new ExchangeRateResult(lst.ToArray(), currencies)));
        }
Ejemplo n.º 4
0
        public async Task <JsonResult> GetQuotes()
        {
            QuotesData quotesData = new QuotesData();

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync("https://opinionated-quotes-api.gigalixirapp.com/v1/quotes"))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    quotesData = JsonConvert.DeserializeObject <QuotesData>(apiResponse);

                    foreach (var quote in quotesData.Quotes)
                    {
                        QuoteMap newQuote = new QuoteMap()
                        {
                            Author   = quote.Author,
                            Language = quote.Language,
                            Quote    = quote.quote,
                            Tags     = string.Join(",", quote.Tags.ToArray())
                        };
                        _quoteService.Add(newQuote);
                    }
                }
            }
            //TODO: Save to our DB

            return(Json(quotesData));
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string myQuote = QuotesData.GetQuoteOfTheDay();

            Quote.Text       = "Your quote of the day is " + myQuote + "\n";
            myRandomQuote    = QuotesData.GetRandomQuote();
            RandomQuote.Text = "Your random quote is: " + myRandomQuote;
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Index(string guildId)
        {
            Guild g = _db.GetGuildFor(guildId);

            if (g is null)
            {
                return(new NotFoundResult());
            }

            var dGuildAsync = _bot.Client.GetGuildAsync(g.GuildID);

            var quotes = from q in _db.Quotes.Include(q => q.Source)
                         where q.GuildID == g !.ID
                         select q;

            List <QuoteData> quotesList             = new();
            Dictionary <string, UserData> userList  = new();
            Dictionary <string, RoleData> rolesList = new();

            foreach (var quote in quotes)
            {
                quotesList.Add(new QuoteData(quote.Text, quote.SourceName));
                if (quote.Source is not null)
                {
                    var user = quote.Source !;
                    if (!userList.ContainsKey(quote.SourceName))
                    {
                        var dGuild = await dGuildAsync;
                        var dUser  = await dGuild.GetMemberAsync(new Snowflake(user.UserID));

                        var roles = (from r in dUser.Roles
                                     select r.Name.Replace(' ', '_')).ToList();

                        userList.Add(quote.SourceName, new UserData(user.UserID, user.Name, dUser.AvatarUrl, Int32.Parse(dUser.Discriminator), roles));

                        foreach (var role in dUser.Roles)
                        {
                            if (!rolesList.ContainsKey(role.Name.Replace(' ', '_')))
                            {
                                rolesList.Add(role.Name.Replace(' ', '_'), new RoleData(role.Color.ToString(), role.Name));
                            }
                        }
                    }
                }
            }

            var res = new QuotesData()
            {
                Quotes = quotesList.ToList(),
                Users  = userList,
                Roles  = rolesList
            };

            return(new JsonResult(res));
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Randomize)
     {
         Quote.Text = QuotesData.GetRandomQuote();
     }
     else
     {
         Quote.Text = QuotesData.GetQuoteOfTheDay();
     }
 }
Ejemplo n.º 8
0
        public IActionResult Index(string guildId)
        {
            Guild g = _db.GetGuildFor(guildId);

            if (g is null)
            {
                return(new NotFoundResult());
            }


            var quotes = from q in _db.Quotes.Include(q => q.Source)
                         where q.GuildID == g !.ID
                         select q;

            List <Quote> quotesList            = new();
            Dictionary <string, User> userList = new();

            foreach (var quote in quotes)
            {
                quotesList.Add(new Quote(quote.Text, quote.SourceName));
                if (quote.Source is not null)
                {
                    var user = quote.Source !;

                    userList.TryAdd(quote.SourceName, new User(user.UserID, user.Name, ""));
                }
            }

            var res = new QuotesData()
            {
                Quotes = quotesList.ToList(),
                Users  = userList
            };

            return(new JsonResult(res));
        }
Ejemplo n.º 9
0
        protected void QuoteButton_Click(object sender, EventArgs e)
        {
            string myRandomQuote = QuotesData.GetRandomQuote();

            RandomQuote.Text = "Your random quote is: " + myRandomQuote;
        }
Ejemplo n.º 10
0
        private static QuotesData CsvArrayToQuoteData(string[] rowItems, QuoteProperty[] properties, System.Globalization.CultureInfo culture)
        {
            if (rowItems.Length > 0)
            {
                QuotesData quote = null;
                if (rowItems.Length == properties.Length)
                {
                    quote = new QuotesData();
                    for (int i = 0; i <= properties.Length - 1; i++)
                    {
                        quote[properties[i]] = QuoteStringToObject(rowItems[i], properties[i], culture);
                    }
                }
                else
                {

                    if (rowItems.Length > 1)
                    {
                        List<QuoteProperty> alternateProperties = new List<QuoteProperty>();
                        foreach (QuoteProperty qp in properties)
                        {
                            foreach (QuoteProperty q in mAlternateQuoteProperties)
                            {
                                if (qp == q)
                                {
                                    alternateProperties.Add(qp);
                                    break;
                                }
                            }
                        }

                        if (alternateProperties.Count > 0)
                        {
                            List<KeyValuePair<QuoteProperty, int>[]> lst = new List<KeyValuePair<QuoteProperty, int>[]>();
                            int[][] permutations = MaxThreePerm(alternateProperties.Count, Math.Min(rowItems.Length - properties.Length + 1, 3));
                            foreach (int[] perm in permutations)
                            {
                                List<KeyValuePair<QuoteProperty, int>> lst2 = new List<KeyValuePair<QuoteProperty, int>>();
                                for (int i = 0; i <= alternateProperties.Count - 1; i++)
                                {
                                    lst2.Add(new KeyValuePair<QuoteProperty, int>(alternateProperties[i], perm[i]));
                                }
                                lst.Add(lst2.ToArray());
                            }

                            foreach (KeyValuePair<QuoteProperty, int>[] combination in lst)
                            {
                                String[] newRowItems = CsvNewRowItems(rowItems, properties, combination);

                                try
                                {
                                    if (newRowItems.Length > 0)
                                    {
                                        quote = new QuotesData();
                                        for (int i = 0; i <= properties.Length - 1; i++)
                                        {
                                            quote[properties[i]] = QuoteStringToObject(rowItems[i], properties[i], culture);
                                        }
                                        break;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    System.Diagnostics.Debug.WriteLine(ex.Message);
                                }
                            }

                        }
                    }
                }
                return quote;
            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Tries to read a QuoteData from XML
 /// </summary>
 /// <param name="node">The XML node of a QuoteData</param>
 /// <param name="culture">The used culture for formating dates and numbers. If parameter value is null/Nothing, default Culture will be used.</param>
 /// <returns>The converted quote data or Nothing</returns>
 /// <remarks></remarks>
 public static QuotesData ToQuoteData(XElement node, System.Globalization.CultureInfo culture = null)
 {
     if (node != null && node.Name.LocalName.ToLower() == "quote")
     {
         System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
         if (culture != null)
             ci = culture;
         QuotesData quote = new QuotesData();
         foreach (XElement propertyNode in node.Elements())
         {
             foreach (QuoteProperty qp in Enum.GetValues(typeof(QuoteProperty)))
             {
                 if (propertyNode.Name.LocalName == qp.ToString())
                 {
                     quote[qp] = MyHelper.StringToObject(propertyNode.Value, ci);
                     break; // TODO: might not be correct. Was : Exit For
                 }
             }
         }
         return quote;
     }
     else
     {
         return null;
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Writes a QuoteData to XML format
 /// </summary>
 /// <param name="writer">The used XML writer</param>
 /// <param name="quote">The used QuoteData</param>
 /// <param name="properties">The used properties of the quotes</param>
 /// <param name="culture">The used culture for formating dates and numbers. If parameter value is null/Nothing, default Culture will be used.</param>
 /// <remarks></remarks>
 public static void FromQuoteData(System.Xml.XmlWriter writer, QuotesData quote, IEnumerable<QuoteProperty> properties, System.Globalization.CultureInfo culture = null)
 {
     System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
     if (culture != null)
         ci = culture;
     writer.WriteStartElement("Quote");
     if (quote[QuoteProperty.Symbol] != null)
         writer.WriteAttributeString("ID", quote[QuoteProperty.Symbol].ToString());
     QuoteProperty[] prps = FinanceHelper.CheckPropertiesOfQuotesData(new QuotesData[] { quote }, properties);
     foreach (QuoteProperty qp in prps)
     {
         writer.WriteStartElement(qp.ToString());
         writer.WriteValue(MyHelper.ObjectToString(quote[qp], ci));
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Writes a QuoteData to XML format
 /// </summary>
 /// <param name="writer">The used XML writer</param>
 /// <param name="quote">The used QuoteData</param>
 /// <param name="culture">The used culture for formating dates and numbers. If parameter value is null/Nothing, default Culture will be used.</param>
 /// <remarks></remarks>
 public static void FromQuoteData(System.Xml.XmlWriter writer, QuotesData quote, System.Globalization.CultureInfo culture = null)
 {
     FromQuoteData(writer, quote, null, culture);
 }
Ejemplo n.º 14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string quoteOfTheDay = Randomize ? QuotesData.GetRandomQuote() : QuotesData.GetQuoteOfTheDay();

            QuoteLabel.Text = quoteOfTheDay;
        }