Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        public static int DownloadImagesAtInterval(Evercam evercam, string user, Camera camera, DateTime fromDay, DateTime toDay, int fromHour, int toHour, int interval, int startIndex, string timestamp, string path)
        {
            int index = startIndex;
            DateTime from = new DateTime(fromDay.Year, fromDay.Month, fromDay.Day, fromHour, 0, 0);
            DateTime to = new DateTime(toDay.Year, toDay.Month, toDay.Day, toHour, 59, 59);
            while (from <= to)
            {
                byte[] data = null;
                long time = Utility.ToUnixTimestamp(Utils.ConvertToUtc(from, camera.Timezone));
                for (int i = 1; i <= 1; i++)
                {
                    try
                    {
                        int sec = interval * 60;
                        int range = Convert.ToInt32(sec / 2);
                        Snapshot snap = evercam.GetSnapshot(camera.ID, time.ToString(), "Evercam Proxy", true, range);
                        if (snap != null)
                        {
                            data = snap.ToBytes();

                            DateTime datetime = Utility.ToWindowsDateTime(snap.CreatedAt);
                            DateTime stamp = Utils.ConvertFromUtc(datetime, camera.Timezone);
                            //if (timestamp == "true")
                            //    Utils.TimestampImage(data, stamp.ToString(), 2);

                            Console.WriteLine(index + " : " + snap.CreatedAt + " = " + stamp);
                            break;
                        }
                    }
                    catch (Exception x)
                    {
                        //if (i < 2) Thread.Sleep(10 * 1000);
                        Console.WriteLine(" - ERR " + time + " :" + x.Message);
                    }
                }

                try
                {
                    if (SaveFile(path + index + ".jpg", data))
                        index++;
                }
                catch (Exception x)
                {
                    Console.WriteLine(" - ERR2 :" + x.Message);
                }

                from = from.AddMinutes(interval);
            }
            return index;
        }