示例#1
0
        public static Grabber[] GrabbersFromJson(string json)
        {
            const string EXPECTED_VERSION = "1.0";

            using JsonDocument document = JsonDocument.Parse(json);

            string version = document.RootElement.GetProperty("version").GetString();

            if (version != EXPECTED_VERSION)
            {
                throw new InvalidOperationException("invalid JSON version");
            }

            List <Grabber> grabbers = new List <Grabber>();

            foreach (var grabber in document.RootElement.GetProperty("grabbers").EnumerateObject())
            {
                GrabberInfo info = new GrabberInfo()
                {
                    ID       = grabber.Value.GetProperty("id").GetString(),
                    Name     = grabber.Value.GetProperty("name").GetString(),
                    Callsign = grabber.Value.GetProperty("callsign").GetString(),
                    Location = grabber.Value.GetProperty("location").GetString(),
                    ImageUrl = grabber.Value.GetProperty("imageUrl").GetString(),
                    SiteUrl  = grabber.Value.GetProperty("siteUrl").GetString(),
                };

                GrabberHistory history = new GrabberHistory()
                {
                    LastUniqueHash       = grabber.Value.GetProperty("lastUniqueHash").GetString(),
                    LastUniqueDateTime   = grabber.Value.GetProperty("lastUniqueDateTime").GetDateTime(),
                    LastUniqueAgeMinutes = grabber.Value.GetProperty("lastUniqueAgeMinutes").GetInt32(),
                    URLs = grabber.Value.GetProperty("urls").EnumerateArray().Select(x => x.GetString()).ToArray()
                };

                grabbers.Add(new Grabber(info, history));
            }

            return(grabbers.ToArray());
        }
示例#2
0
 public void Update(GrabberHistory oldHistory)
 {
     LastUniqueHash       = oldHistory.LastUniqueHash;
     LastUniqueDateTime   = oldHistory.LastUniqueDateTime;
     LastUniqueAgeMinutes = oldHistory.LastUniqueAgeMinutes;
 }
示例#3
0
 public Grabber(GrabberInfo info = null, GrabberHistory history = null)
 {
     Info    = info ?? new GrabberInfo();
     History = history ?? new GrabberHistory();
     Data    = new GrabberData();
 }