Exemplo n.º 1
0
        static void SelectData(DateTime start, DateTime end, int m)
        {
            TimeSpan ts        = new TimeSpan(-(start - end).Ticks / m);
            TimeSpan tsOneHalf = new TimeSpan(-(start - end).Ticks / m / 2);

            arrDT   = new DateTime[m];
            arrTraf = new double[m];
            RecordTableAdapter rta = new RecordTableAdapter();
            DateTime           dt  = start;

            for (int i = 0; i < m; i++)
            {
                arrDT[i] = dt + tsOneHalf;
                double?bytes = rta.BytesPerInterval(dt, dt + ts);
                if (bytes.HasValue)
                {
                    arrTraf[i] = (double)bytes;
                }
                else
                {
                    arrTraf[i] = 0;
                }
                dt += ts;
            }
        }
Exemplo n.º 2
0
        public static void ReadLogFile(FileInfo info, BackgroundWorker w, long sum, long total)
        {
            StreamReader sr = new StreamReader(info.FullName);

            sr.ReadLine(); sr.ReadLine(); sr.ReadLine(); sr.ReadLine();
            string              s;
            long                read = 0;
            int                 percent = 0;
            int                 uidMax = 0, hidMax = 0, sidMax = 0;
            long                ridMax = 0;
            UserTableAdapter    uta = new UserTableAdapter();
            HostTableAdapter    hta = new HostTableAdapter();
            SessionTableAdapter sta = new SessionTableAdapter();
            RecordTableAdapter  rta = new RecordTableAdapter();
            int?                quid = uta.MaxId(), qhid = hta.MaxId();
            long?               qsid = sta.MaxId(), qrid = rta.MaxId();

            if (quid.HasValue)
            {
                uidMax = (int)quid;
            }
            if (qhid.HasValue)
            {
                hidMax = (int)qhid;
            }
            if (qsid.HasValue)
            {
                sidMax = (int)qsid;
            }
            if (qrid.HasValue)
            {
                ridMax = (int)qrid;
            }
            LogsDBDataSet.UserDataTable    udt = new LogsDBDataSet.UserDataTable();
            LogsDBDataSet.HostDataTable    hdt = new LogsDBDataSet.HostDataTable();
            LogsDBDataSet.SessionDataTable sdt = new LogsDBDataSet.SessionDataTable();
            LogsDBDataSet.RecordDataTable  rdt = new LogsDBDataSet.RecordDataTable();
            if (uidMax == 0 && hidMax == 0 && sidMax == 0)
            {
                dict.Clear();
            }
            while ((s = sr.ReadLine()) != null)
            {
                read += s.Length;
                string[] arrS  = s.Split('\t');
                string[] arrHS = arrS[7].Split('.');
                string   h;
                if (arrHS.Length > 1 && !char.IsDigit(arrHS.Last()[0]))
                {
                    h = arrHS[arrHS.Length - 2] + "." + arrHS.Last();
                }
                else
                {
                    h = arrS[7];
                }
                string uip = arrS[0],
                       name = arrS[1].Substring(0, Math.Min(30, arrS[1].Length)),
                       agent = arrS[2].Substring(0, Math.Min(50, arrS[2].Length)),
                       datetime = arrS[3] + " " + arrS[4],
                       host = h.Substring(0, Math.Min(50, h.Length)),
                       hip = arrS[8],
                       port = arrS[9],
                       duration = arrS[10],
                       receive = arrS[11],
                       send = arrS[12],
                       protocol = arrS[13].Substring(0, Math.Min(10, arrS[13].Length)),
                       url = arrS[15].Substring(0, Math.Min(50, arrS[15].Length));
                DateTime dt = DateTime.Parse(datetime);
                int      dur, se, re, p;
                if (!int.TryParse(duration, out dur))
                {
                    dur = 0;
                }
                if (!int.TryParse(send, out se))
                {
                    se = 0;
                }
                if (!int.TryParse(receive, out re))
                {
                    re = 0;
                }
                if (!int.TryParse(port, out p))
                {
                    p = 0;
                }
                int    uid, hid, sid;
                string ukey = uip + name + agent, hkey = hip + port + host;
                if (!dict.TryGetValue(ukey, out uid))
                {
                    uid = ++uidMax;
                    dict.Add(ukey, uid);
                    udt.AddUserRow(uid, uip, name, agent);
                }
                if (!dict.TryGetValue(hkey, out hid))
                {
                    hid = ++hidMax;
                    dict.Add(hkey, hid);
                    hdt.AddHostRow(hid, hip, p, host);
                }
                string skey = string.Format("{0}{1}{2}", uid, hid, protocol + url);
                if (!dict.TryGetValue(skey, out sid))
                {
                    sid = ++sidMax;
                    dict.Add(skey, sid);
                    sdt.AddSessionRow(sid, uid, protocol, hid, url);
                }
                rdt.AddRecordRow(++ridMax, dt, sid, se / 1048576.0f, re / 1048576.0f, dur);
                int x = (int)((read + sum) * 100 / total);
                if (x > percent)
                {
                    percent = x;
                    w.ReportProgress(percent);
                }
                if (w.CancellationPending)
                {
                    uta.Update(udt);
                    hta.Update(hdt);
                    sta.Update(sdt);
                    rta.Update(rdt);
                    sr.Close();
                    return;
                }
            }
            uta.Update(udt);
            hta.Update(hdt);
            sta.Update(sdt);
            rta.Update(rdt);
            sr.Close();
        }