예제 #1
0
    public static void ParseAll()
    {
        string path = Application.dataPath;

        path += "/../";

        Debug.Log("Exe path: " + path);

        string[] files = System.IO.Directory.GetFiles(path, "*.txt");

        openChannelLogs = new Dictionary <int, LogMotionEntry>();
        channelLogs     = new Dictionary <int, List <LogMotionEntry> >();
        dailyLogs       = new Dictionary <DateTime, List <LogMotionEntry> >();
        combinedLogs    = new List <LogMotionEntry>();

        foreach (string fileName in files)
        {
            StreamReader reader = File.OpenText(fileName);
            string       line;
            while ((line = reader.ReadLine()) != null)
            {
                List <string> splitStrings = line.Split(new[] { "  " }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList();

                if (splitStrings[2] == "Alarm Start")
                {
                    int            channel = int.Parse((splitStrings[3])[splitStrings[3].Length - 1].ToString());
                    LogMotionEntry lme;

                    if (!openChannelLogs.TryGetValue(channel, out lme))
                    {
                        DateTime startTime = DateTime.ParseExact(splitStrings[1], "dd-MM-yyyy HH:mm:ss", null);

                        if (!EntryExists(channel, startTime, true))
                        {
                            lme         = new LogMotionEntry();
                            lme.start   = startTime;
                            lme.channel = channel;
                            openChannelLogs.Add(channel, lme);
                        }
                    }
                }
                else if (splitStrings[2] == "Alarm Stop")
                {
                    int            channel = int.Parse((splitStrings[3])[splitStrings[3].Length - 1].ToString());
                    LogMotionEntry lme;

                    DateTime endTime = DateTime.ParseExact(splitStrings[1], "dd-MM-yyyy HH:mm:ss", null);

                    if (!EntryExists(channel, endTime, false))
                    {
                        if (openChannelLogs.TryGetValue(channel, out lme))
                        {
                            lme.end      = endTime;
                            lme.duration = (lme.end - lme.start).Seconds;
                            openChannelLogs.Remove(channel);
                        }

                        if (lme != null)
                        {
                            List <LogMotionEntry> channelEntries;

                            if (!channelLogs.TryGetValue(channel, out channelEntries))
                            {
                                channelEntries = new List <LogMotionEntry>();
                                channelLogs.Add(channel, channelEntries);
                            }

                            channelEntries.Add(lme);
                            combinedLogs.Add(lme);

                            List <LogMotionEntry> dailyList;

                            if (!dailyLogs.TryGetValue(lme.start.Date, out dailyList))
                            {
                                dailyList = new List <LogMotionEntry>();
                                dailyLogs.Add(lme.start.Date, dailyList);
                            }

                            dailyList.Add(lme);
                        }
                    }
                }
            }
        }

        foreach (KeyValuePair <int, List <LogMotionEntry> > channelLog in channelLogs)
        {
            Debug.Log(channelNames[channelLog.Key - 1] + " (" + channelLog.Key + "): " + channelLog.Value.Count + " log entries");
        }

        if (combinedLogs.Count > 0)
        {
            Debug.Log("First entry: " + combinedLogs[0].start);
            Debug.Log("Last entry: " + combinedLogs[combinedLogs.Count - 1].start);
        }
    }
예제 #2
0
    public void AddAlert(LogMotionEntry entry)
    {
        ImageAlert.enabled = true;

        AlertEntries.Add(entry);
    }