Exemplo n.º 1
0
 public Temprature(Newtonsoft.Json.Linq.JObject json)
 {
     this.Type  = json.Children().Where(p => p.Path.Equals("type")).FirstOrDefault().First().ToString();
     this.Name  = json.Children().Where(p => p.Path.Equals("name")).FirstOrDefault().First().ToString();
     this.IP    = json.Children().Where(p => p.Path.Equals("ip")).FirstOrDefault().First().ToString();
     this.Time  = int.Parse(json.Children().Where(p => p.Path.Equals("time")).FirstOrDefault().First().ToString());
     this.Value = json.Children().Where(p => p.Path.Equals("value")).FirstOrDefault().First().ToString();
 }
Exemplo n.º 2
0
        public static string GetMarketData(PTMagicConfiguration systemConfiguration, LogHelper log)
        {
            string result = "";

            try {
                string baseUrl = "https://api.coinmarketcap.com/v2/ticker/";

                log.DoLogInfo("CoinMarketCap - Getting market data...");

                Dictionary <string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log);
                if (jsonObject.Count > 0)
                {
                    if (jsonObject["data"] != null)
                    {
                        Newtonsoft.Json.Linq.JObject jsonDataObject = (Newtonsoft.Json.Linq.JObject)jsonObject["data"];
                        log.DoLogInfo("CoinMarketCap - Market data received for " + jsonDataObject.Count.ToString() + " currencies");

                        Dictionary <string, Market> markets = new Dictionary <string, Market>();
                        foreach (Newtonsoft.Json.Linq.JToken currencyTicker in jsonDataObject.Children())
                        {
                            if (currencyTicker.First["quotes"] != null)
                            {
                                if (currencyTicker.First["quotes"]["USD"] != null)
                                {
                                    Market market = new Market();
                                    market.Position  = markets.Count + 1;
                                    market.Name      = currencyTicker.First["name"].ToString();
                                    market.Symbol    = currencyTicker.First["symbol"].ToString();
                                    market.Price     = (double)currencyTicker.First["quotes"]["USD"]["price"];
                                    market.Volume24h = (double)currencyTicker.First["quotes"]["USD"]["volume_24h"];
                                    if (!String.IsNullOrEmpty(currencyTicker.First["quotes"]["USD"]["percent_change_24h"].ToString()))
                                    {
                                        market.TrendChange24h = (double)currencyTicker.First["quotes"]["USD"]["percent_change_24h"];
                                    }

                                    markets.Add(market.Name, market);
                                }
                            }
                        }

                        CoinMarketCap.CheckForMarketDataRecreation(markets, systemConfiguration, log);

                        DateTime fileDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0).ToUniversalTime();

                        FileHelper.WriteTextToFile(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + Constants.PTMagicPathData + Path.DirectorySeparatorChar + Constants.PTMagicPathCoinMarketCap + Path.DirectorySeparatorChar, "MarketData_" + fileDateTime.ToString("yyyy-MM-dd_HH.mm") + ".json", JsonConvert.SerializeObject(markets), fileDateTime, fileDateTime);


                        log.DoLogInfo("CoinMarketCap - Market data saved.");

                        FileHelper.CleanupFiles(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + Constants.PTMagicPathData + Path.DirectorySeparatorChar + Constants.PTMagicPathCoinMarketCap + Path.DirectorySeparatorChar, systemConfiguration.AnalyzerSettings.MarketAnalyzer.StoreDataMaxHours);
                        log.DoLogInfo("CoinMarketCap - Market data cleaned.");
                    }
                }
            } catch (Exception ex) {
                log.DoLogCritical(ex.Message, ex);
                result = ex.Message;
            }

            return(result);
        }
Exemplo n.º 3
0
        protected void Begin_Request()
        {
            #region Input Validation against XSS attacks
            //Validate only post methods with no form data. Because if form data available MVC validate it by itself. We exclude file uploads and validate only some specific controllers.
            if (Request.HttpMethod == "POST" && Request.Form.Count == 0 && Request.InputStream != null && Request.InputStream.Length > 0 && Request.Files != null && Request.Files.Count == 0 && !string.IsNullOrEmpty(Request.RawUrl))
            {
                string controller = string.Empty;
                var    urlParts   = Request.RawUrl.Split('/');
                if (urlParts.Length > 1)
                {
                    controller = urlParts[1];
                }
                Stream req = Request.InputStream;
                req.Seek(0, SeekOrigin.Begin);
                string json = new StreamReader(req).ReadToEnd();
                req.Position = 0;
                Newtonsoft.Json.Linq.JObject input = JsonConvert.DeserializeObject <dynamic>(json);
                if (input != null && input.HasValues)
                {
                    foreach (var item in input.Children())
                    {
                        var value = ((Newtonsoft.Json.Linq.JProperty)item).Value?.ToString() ?? string.Empty;
                        if (!string.IsNullOrEmpty(value) && !value.IsInputClear())
                        {
                            string message = @"{
                                                       ""status"":
                                                           {
                                                               ""code"": 500,
                                                               ""errorMessage"": ""A potentially dangerous value was detected from the client.""
                                                           },
                                                       ""body"": """"
                                                       }";

                            Context.Response.StatusCode = 500;
                            Context.Response.Write(message);
                            Context.Response.End();
                        }
                    }
                }
            }
            #endregion
        }
Exemplo n.º 4
0
        public static List <UserDataItem> FromJObject(object obj)
        {
            var uds = new List <UserDataItem>();

            Newtonsoft.Json.Linq.JObject jObj = null;
            if (obj is string)
            {
                jObj = Newtonsoft.Json.Linq.JObject.Parse(obj?.ToString());
            }
            else if (obj is Newtonsoft.Json.Linq.JObject j)
            {
                jObj = j;
            }

            if (jObj != null)
            {
                uds = jObj.Children()
                      .OfType <Newtonsoft.Json.Linq.JProperty>()
                      .Where(_ => !_.Name.StartsWith("__")) // hide reserved items, such as "__layer__"
                      .Select(_ => new UserDataItem(_.Name, _.Value.ToString()))
                      .ToList();
            }
            return(uds);
        }