Beispiel #1
0
        public async Task <IHttpActionResult> getCar(idClass id)
        {
            HttpResponseMessage response;
            string content = "";
            var    Car     = db.Cars.Find(id.id);
            var    Image   = "";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.nhtsa.gov/");
                try
                {
                    response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + Car.model_year +
                                                     "/make/" + Car.make +
                                                     "/model/" + Car.model_name + "?format=json");

                    content = await response.Content.ReadAsStringAsync();
                }
                catch (Exception e)
                {
                    return(InternalServerError(e));
                }
            }

            dynamic Recalls = JsonConvert.DeserializeObject(content);

            // Bing Search API
            var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/v1/Image"));

            image.Credentials = new NetworkCredential("accountKey", "s8cUIpKPWJ609E7VqtBbx9HNdRp9Z2NbUne/HyPgxbQ");

            var marketData = image.Composite(
                "image",
                Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim + " " + "NOT ebay",
                null, null, null, null, null, null, null, null, null, null, null, null, null).Execute();

            var Images = marketData.FirstOrDefault().Image;

            foreach (var Img in Images)
            {
                if (UrlCtrl.isUrl(Img.MediaUrl))
                {
                    Image = Img.MediaUrl;
                    break;
                }
                else
                {
                    continue;
                }
            }

            if (string.IsNullOrWhiteSpace(Image))
            {
                Image = "/images/no-image.png";
            }

            return(Ok(new { car = Car, recalls = Recalls, image = Image }));
        }
Beispiel #2
0
            /// <summary>
            /// Loads a font file into memory, disposing of any previously loaded font first
            /// </summary>
            /// <param name="filename">The filename of the font to load</param>
            private void readFont(string filename)
            {
                try
                {
                    // Load the entrie file into a memory stream for quick access
                    FileStream   fs = new FileStream(filename, FileMode.Open);
                    BinaryReader br = new BinaryReader(fs);
                    this.ms = new MemoryStream(br.ReadBytes((int)br.BaseStream.Length));
                    fs.Close();
                    br = new BinaryReader(ms);
                    br.BaseStream.Position = 0x020c;
                    int indexCount = br.ReadInt32();

                    #region Load UTF Table Entries
                    // Read individual character info for each Index entry
                    // Share any common UTF entries
                    for (int i = 0; i < indexCount; i++)
                    {
                        br.BaseStream.Position = 0x40400 + i * 0x10;
                        CharInfo cInfo = new CharInfo(i);
                        cInfo.Read(br);
                        charInfos.Add(cInfo);
                        br.BaseStream.Position    = cInfo.Offset;
                        cInfo.CompressedImageData = br.ReadBytes(cInfo.Size);
                    }
                    #endregion

                    #region Load Index Table entries
                    // Read index table (4 bytes per entry)
                    for (int i = 0; i < ids.Length; i++)
                    {
                        br.BaseStream.Position = 0x400 + i * 4;
                        ids[i]       = new idClass(br.ReadInt32());
                        ids[i].cInfo = charInfos[ids[i].index];
                        charInfoPos[ids[i].index] = charInfos[ids[i].index];
                        charInfos[ids[i].index].IdClasses.Add(ids[i]);
                    }
                    #endregion
                    _isLoaded = true;
                }
                catch
                {
                    _isLoaded = false;
                }
            }
        public async Task<IHttpActionResult> getCar(idClass id)
        {
            HttpResponseMessage response;
            string content = "";
            var Car = db.Cars.Find(id.id);

            var Image = "";
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.nhtsa.gov/");
                try
                {
                    response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + Car.model_year +
                                                                                    "/make/" + Car.make +
                                                                                    "/model/" + Car.model_name + "?format=json");
                    content = await response.Content.ReadAsStringAsync();
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }

            dynamic Recalls = JsonConvert.DeserializeObject(content);


            var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/v1/Image"));

            image.Credentials = new NetworkCredential("accountKey", "9DVmvKlSSAnTU1On117Lu4rMsXdLgjDI+sUWSdxdzIc");   //"dwmFt1J2rM45AQXkGTk4ebfcVLNcytTxGMHK6dgMreg"
            var marketData = image.Composite(
                "image",
                Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim + " " + "NOT ebay",
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
                ).Execute();

            //Image = marketData.First().Image.First().MediaUrl;
            //return Ok(new { car = Car, recalls = Recalls, image = Image });
            //return JSON.parse(new { car = Car, recalls = Recalls, image = Image });
            // return Ok(Recalls);
            var Images = marketData.FirstOrDefault()?.Image;
            //int imgCnt = Images.Count();
            foreach (var Img in Images)
            {

                if (UrlCtrl.IsUrl(Img.MediaUrl))
                {
                    Image = Img.MediaUrl;
                    break;
                }
                else
                {
                    continue;
                }


            }
            if (string.IsNullOrWhiteSpace(Image))
            {
                Image = "images/carnotfound.jpg";
            }
            return Ok(new { car = Car, recalls = Recalls, image = Image });
        }
Beispiel #4
0
        public async Task<IHttpActionResult> getCar(idClass id)
        {
            HttpResponseMessage response;
            string content = "";
            var Car = db.Cars.Find(id.id);
            var Image = "";
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.nhtsa.gov/");
                try
                {
                    response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + Car.model_year +
                                                                                    "/make/" + Car.make +
                                                                                    "/model/" + Car.model_name + "?format=json");
                    content = await response.Content.ReadAsStringAsync();
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }

            dynamic Recalls = JsonConvert.DeserializeObject(content);

            // Bing Search API
            var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/v1/Image"));

            image.Credentials = new NetworkCredential("accountKey", "s8cUIpKPWJ609E7VqtBbx9HNdRp9Z2NbUne/HyPgxbQ");

            var marketData = image.Composite(
               "image",
               Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim + " " + "NOT ebay",
               null, null, null, null, null, null, null, null, null, null, null, null, null).Execute();

              var Images = marketData.FirstOrDefault().Image;

            foreach(var Img in Images)
            {
                if(UrlCtrl.isUrl(Img.MediaUrl))
                {
                    Image = Img.MediaUrl;
                    break;
                }
                else
                {
                    continue;
                }
            }

            if(string.IsNullOrWhiteSpace (Image))
            {
                Image = "/images/no-image.png";
            }

            return Ok(new { car = Car, recalls = Recalls, image = Image });
        }
Beispiel #5
0
            /// <summary>
            /// Loads a font file into memory, disposing of any previously loaded font first
            /// </summary>
            /// <param name="filename">The filename of the font to load</param>
            private void readFont(string filename)
            {
                try
                {
                    // Load the entrie file into a memory stream for quick access
                    FileStream fs = new FileStream(filename, FileMode.Open);
                    BinaryReader br = new BinaryReader(fs);
                    this.ms = new MemoryStream(br.ReadBytes((int)br.BaseStream.Length));
                    fs.Close();
                    br = new BinaryReader(ms);
                    br.BaseStream.Position = 0x020c;
                    int indexCount = br.ReadInt32();

                    #region Load UTF Table Entries
                    // Read individual character info for each Index entry
                    // Share any common UTF entries
                    for (int i = 0; i < indexCount; i++)
                    {
                        br.BaseStream.Position = 0x40400 + i * 0x10;
                        CharInfo cInfo = new CharInfo(i);
                        cInfo.Read(br);
                        charInfos.Add(cInfo);
                        br.BaseStream.Position = cInfo.Offset;
                        cInfo.CompressedImageData = br.ReadBytes(cInfo.Size);
                    }
                    #endregion

                    #region Load Index Table entries
                    // Read index table (4 bytes per entry)
                    for (int i = 0; i < ids.Length; i++)
                    {
                        br.BaseStream.Position = 0x400 + i * 4;
                        ids[i] = new idClass(br.ReadInt32());
                        ids[i].cInfo = charInfos[ids[i].index];
                        charInfoPos[ids[i].index] = charInfos[ids[i].index];
                        charInfos[ids[i].index].IdClasses.Add(ids[i]);
                    }
                    #endregion
                    _isLoaded = true;
                }
                catch
                {
                    _isLoaded = false;
                }
            }