/// <summary> /// Sends the specified change to the remote database. /// </summary> /// <param name="change">The object containing the changed information.</param> public void SendChange(ShowInfoChange change) { new Thread(() => { var req = Remote.API.SendDatabaseChange(change, _user, _pass); if (!req.Success || !req.OK) { PendingChanges.Add(change); PendingChangesTimer.Start(); } }).Start(); }
/// <summary> /// Serializes the list of followed TV shows and their marked episodes. /// </summary> /// <returns>List of serialized TV show states.</returns> public static List <ShowInfoChange> SerializeDatabase() { var list = new List <ShowInfoChange>(); var shows = Database.Query("select showid, name, (select value from showdata where showdata.showid = tvshows.showid and key = 'grabber') as grabber from tvshows order by name asc"); foreach (var show in shows) { var showinf = "{0}\0{1}\0{2}\0{3}".FormatWith( show["name"], Engines[show["grabber"]], Languages[Database.ShowData(show["showid"], show["grabber"] + ".lang")], Database.ShowData(show["showid"], show["grabber"] + ".id") ); var addchg = new ShowInfoChange { Time = (long)DateTime.UtcNow.ToUnixTimestamp(), Change = ShowInfoChange.ChangeType.AddShow, Show = showinf }; list.Add(addchg); var markchg = new ShowInfoChange { Time = (long)DateTime.UtcNow.ToUnixTimestamp(), Change = ShowInfoChange.ChangeType.MarkEpisode, Show = showinf, Data = SerializeMarkedEpisodes(show["showid"]) }; list.Add(markchg); } var orderchg = new ShowInfoChange { Time = (long)DateTime.UtcNow.ToUnixTimestamp(), Change = ShowInfoChange.ChangeType.ReorderList, Data = Database.Query("select name from tvshows order by rowid asc").Select(dict => dict["name"]).ToArray() }; list.Add(orderchg); return(list); }
/// <summary> /// Serializes the list of followed TV shows and their marked episodes. /// </summary> /// <returns>List of serialized TV show states.</returns> public static List<ShowInfoChange> SerializeDatabase() { var list = new List<ShowInfoChange>(); var shows = Database.Query("select showid, name, (select value from showdata where showdata.showid = tvshows.showid and key = 'grabber') as grabber from tvshows order by name asc"); foreach (var show in shows) { var showinf = "{0}\0{1}\0{2}\0{3}".FormatWith( show["name"], Engines[show["grabber"]], Languages[Database.ShowData(show["showid"], show["grabber"] + ".lang")], Database.ShowData(show["showid"], show["grabber"] + ".id") ); var addchg = new ShowInfoChange { Time = (long)DateTime.UtcNow.ToUnixTimestamp(), Change = ShowInfoChange.ChangeType.AddShow, Show = showinf }; list.Add(addchg); var markchg = new ShowInfoChange { Time = (long)DateTime.UtcNow.ToUnixTimestamp(), Change = ShowInfoChange.ChangeType.MarkEpisode, Show = showinf, Data = SerializeMarkedEpisodes(show["showid"]) }; list.Add(markchg); } var orderchg = new ShowInfoChange { Time = (long)DateTime.UtcNow.ToUnixTimestamp(), Change = ShowInfoChange.ChangeType.ReorderList, Data = Database.Query("select name from tvshows order by rowid asc").Select(dict => dict["name"]).ToArray() }; list.Add(orderchg); return list; }
/// <summary> /// Creates a new object which will be sent to the remote server. /// </summary> /// <param name="showid">The ID of the TV show in the database.</param> /// <param name="type">The type of the change.</param> /// <param name="data">The data of the change.</param> /// <returns>Simple JSON object.</returns> public static ShowInfoChange InitChange(string showid, ShowInfoChange.ChangeType type, object data = null) { return new ShowInfoChange { Time = (DateTime.UtcNow.Ticks - 621355968000000000) / 10000000d, Change = type, Data = data, Show = type != ShowInfoChange.ChangeType.ReorderList ? GetShowData(showid) : null }; }