예제 #1
0
        [Produces("text/poop")] //text/plain doesn't work :(
        public async Task <object> Nzb(int id)
        {
            var nzbs = db.spotNzbs.Where(e => e.article == id).ToList();

            using (Spotnet spotnet = new Spotnet(config.host, config.port, config.user, config.pass))
            {
                await spotnet.Connect();

                var data = await spotnet.Nzb(nzbs[0].segment);

                return(data);
            }
        }
예제 #2
0
파일: Service.cs 프로젝트: Borf/sensorcloud
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            try
            {
                while (true)
                {
                    Spotnet spotnet = new Spotnet(config.host, config.port, config.user, config.pass);
                    await spotnet.Connect();

                    spotnet.OnSpot += async(s, spot) =>
                    {
                        using (SensorCloudContext db = new SensorCloudContext(configuration))
                        {
                            Log($"Saving {spot.article}");
                            datamodel.Spot dbSpot = new datamodel.Spot()
                            {
                                article   = spot.article,
                                articleid = spot.articleid,
                                cat       = spot.cat,
                                desc      = spot.desc,
                                posted    = spot.posted,
                                size      = spot.size,
                                subcat    = spot.subcat,
                                title     = spot.title,
                                nzbs      = spot.segments.Select(seg => new datamodel.SpotNzb()
                                {
                                    article   = spot.article,
                                    articleid = spot.articleid,
                                    segment   = seg
                                }).ToList()
                            };
                            db.spots.Add(dbSpot);
                            db.spotNzbs.AddRange(dbSpot.nzbs);
                            await db.SaveChangesAsync();

                            if (mqtt != null)
                            {
                                await mqtt.Publish("spotnet", JObject.FromObject(new { id = spot.articleid, title = spot.title }).ToString());
                            }
                        }
                    };
                    long min = spotnet.GroupInfo.low;
                    using (SensorCloudContext db = new SensorCloudContext(configuration))
                    {
                        try
                        {
                            min = db.spots.Max(e => e.article) + 1;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                    await spotnet.Update(min);

                    spotnet.Disconnect();
                    await Task.Delay(60000 * 5);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception thrown in spotnet");
                Console.WriteLine(e);
            }
        }