public static int DownloadAllImages(Evercam evercam, string user, string camera, string timezone, DateTime userFromDate, DateTime userToDate, int startIndex, string timestamp, string path) { byte[] data = null; int index = startIndex; long fromTimestamp = Utility.ToUnixTimestamp(userFromDate); long toTimestamp = Utility.ToUnixTimestamp(userToDate); List<Snapshot> snaps = evercam.GetSnapshots(camera, fromTimestamp, toTimestamp, 10000, null); foreach (Snapshot s in snaps) { try { Snapshot snap = evercam.GetSnapshot(camera, s.CreatedAt.ToString(), "Evercam Proxy", true, 0); DateTime datetime = Utility.ToWindowsDateTime(snap.CreatedAt); DateTime snaptime = Utils.ConvertFromUtc(datetime, timezone); if (snap != null && snaptime >= userFromDate) { data = snap.ToBytes(); //if (timestamp == "true") // data = Utils.TimestampImage(data, snaptime.ToString(), Settings.WatermarkPostion); Console.WriteLine(index + " : " + snap.CreatedAt + " = " + snaptime); try { if (SaveFile(path + index + ".jpg", data)) index++; } catch (Exception x) { Console.WriteLine(" - ERR1 :" + x.Message); } } } catch (Exception x) { Console.WriteLine(" - ERR2 :" + x.Message); } } return index; }
public static int DownloadAllImages(Evercam evercam, Camera camera, DateTime userFromDate, DateTime userToDate, string path) { byte[] data = null; int index = 0; while (userFromDate < userToDate) { var diff_date = userToDate - userFromDate; DateTime newToDate = DateTime.Now; if (diff_date.Hours >= 1) { newToDate = userFromDate.AddHours(1); } else { newToDate = userToDate; } long fromTimestamp = Utility.ToUnixTimestamp(userFromDate); long toTimestamp = Utility.ToUnixTimestamp(newToDate); List<Snapshot> snaps = evercam.GetSnapshots(camera.ID, fromTimestamp, toTimestamp, 3600, 1); foreach (Snapshot s in snaps) { try { Snapshot snap = evercam.GetSnapshot(camera.ID, s.CreatedAt.ToString(), "Evercam Proxy", true, 0); DateTime datetime = Utility.ToWindowsDateTime(snap.CreatedAt); DateTime snaptime = ConvertFromUtc(datetime, Utility.ToWindowsTimezone(camera.Timezone)); if (snap != null && snaptime >= userFromDate && snaptime <= newToDate) { data = snap.ToBytes(); //if (timestamp == "true") // data = Utils.TimestampImage(data, snaptime.ToString(), Settings.WatermarkPostion); Console.WriteLine("Camera: " + camera.ID + ", " + index + " : " + snap.CreatedAt + " = " + snaptime); try { if (SaveFile(Path.Combine(path, index + ".jpg"), data)) index++; } catch (Exception x) { Console.WriteLine(" - ERR1 :" + x.Message); } } } catch (Exception x) { Console.WriteLine(" - ERR2 :" + x.Message); } } userFromDate = newToDate; } return index; }
public static int DownloadTimelapseImages(Evercam evercam, string user, string camera, string timezone, DateTime userFromDate, DateTime userToDate, int startIndex, string path, int minutes) { List<Snapshot> snaps = new List<Snapshot>(); byte[] data = null; int index = startIndex; DateTime newFromDate = userFromDate; DateTime newToDate = userToDate; while (newFromDate <= userToDate) { newToDate = newFromDate.AddMinutes(minutes); long fromTimestamp = Utility.ToUnixTimestamp(newFromDate); long toTimestamp = Utility.ToUnixTimestamp(newToDate); try { snaps = evercam.GetSnapshots(camera, fromTimestamp, toTimestamp, 1, null); if (snaps.Count > 0) { Snapshot snap = evercam.GetSnapshot(camera, snaps[0].CreatedAt.ToString(), "Evercam Proxy", true, 0); if (snap != null) { data = snap.ToBytes(); DateTime datetime = Utility.ToWindowsDateTime(snap.CreatedAt); DateTime snaptime = Utils.ConvertFromUtc(datetime, timezone); Console.WriteLine(index + " : " + snap.CreatedAt + " = " + snaptime); try { if (SaveFile(path + index + ".jpg", data)) index++; } catch (Exception x) { Console.WriteLine(" - ERR1 :" + x.Message); } } } } catch (Exception x) { } newFromDate = newToDate; } return index; }