Beispiel #1
0
 public AirSyncLogParser()
 {
     this.startTime   = DateTime.MinValue;
     this.endTime     = DateTime.MaxValue;
     this.hourlyTable = new ExportMobileSyncLog.HourlyRow[168];
     for (uint num = 0U; num < 7U; num += 1U)
     {
         for (uint num2 = 0U; num2 < 24U; num2 += 1U)
         {
             ExportMobileSyncLog.HourlyRow hourlyRow = new ExportMobileSyncLog.HourlyRow();
             hourlyRow.Devices = new Dictionary <string, bool>();
             hourlyRow.Day     = (DayOfWeek)num;
             hourlyRow.Hour    = num2;
             this.hourlyTable[(int)((UIntPtr)(num * 24U + num2))] = hourlyRow;
         }
     }
     this.fieldsPattern  = new Regex("^#\\s*Fields\\s*:\\s*(.*?)\\s*$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.CultureInvariant);
     this.valuesPattern  = new Regex("(\\S+)(?:\\s+|$)", RegexOptions.Compiled | RegexOptions.CultureInvariant);
     this.queryPattern   = new Regex("^(?:(?:^|&)(?:(?i:Cmd)=(?<Cmd>[^&]*)|(?i:DeviceId)=(?<DeviceId>[^&]*)|(?i:DeviceType)=(?<DeviceType>[^&]*)|(?i:Log)=(?:(?:Ty:(?<Ty>[^_]+)|Cli:(?<CliA>[0-9]+)a(?<CliC>[0-9]+)c(?<CliD>[0-9]+)d(?<CliF>[0-9]+)f(?<CliE>[0-9]+)e|Srv:(?<SrvA>[0-9]+)a(?<SrvC>[0-9]+)c(?<SrvD>[0-9]+)d(?<SrvS>[0-9]+)s(?<SrvE>[0-9]+)e(?<SrvR>[0-9]+)r(?<SrvAA>[0-9]+)A(?<SrvSD>[0-9]+)sd|Oof:(?<Oof>[^_]*)|Ssp(?<Ssp>[0-9]+)|Unc(?<Unc>[0-9]+)|Att(?<Att>[0-9]+)|Attb(?<Attb>[0-9]+)|Pa(?<Pa>[0-9]+)|[a-zA-Z]+(?:[0-9]+|:[^_]*))(?:_|$|(?=&)))*|[^=]+=[^&]*))*$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
     this.columnNameToID = new Dictionary <string, ExportMobileSyncLog.ColumnID>();
     this.columnNameToID.Add("date", ExportMobileSyncLog.ColumnID.dateColumn);
     this.columnNameToID.Add("time", ExportMobileSyncLog.ColumnID.timeColumn);
     this.columnNameToID.Add("cs-username", ExportMobileSyncLog.ColumnID.userNameColumn);
     this.columnNameToID.Add("cs-uri-query", ExportMobileSyncLog.ColumnID.uriQueryColumn);
     this.columnNameToID.Add("sc-bytes", ExportMobileSyncLog.ColumnID.bytesSentColumn);
     this.columnNameToID.Add("cs-bytes", ExportMobileSyncLog.ColumnID.bytesReceivedColumn);
     this.columnNameToID.Add("s-computername", ExportMobileSyncLog.ColumnID.computerNameColumn);
     this.columnNameToID.Add("cs-uri-stem", ExportMobileSyncLog.ColumnID.uriStemColumn);
     this.columnNameToID.Add("cs-host", ExportMobileSyncLog.ColumnID.hostColumn);
     this.columnNameToID.Add("s-ip", ExportMobileSyncLog.ColumnID.ipAddressColumn);
     this.columnNameToID.Add("cs(user-agent)", ExportMobileSyncLog.ColumnID.userAgentColumn);
     this.columnNameToID.Add("sc-status", ExportMobileSyncLog.ColumnID.statusColumn);
     this.columnNameToID.Add("sc-substatus", ExportMobileSyncLog.ColumnID.subStatusColumn);
 }
Beispiel #2
0
            public void ParseLine(string line)
            {
                Match match = null;

                if (line.Length == 0)
                {
                    return;
                }
                if (line[0] == '#')
                {
                    match = this.fieldsPattern.Match(line);
                    if (match.Success)
                    {
                        string          value           = match.Groups[1].Value;
                        MatchCollection matchCollection = this.valuesPattern.Matches(value);
                        this.columnCount     = matchCollection.Count;
                        this.columnIndexToID = new ExportMobileSyncLog.ColumnID[this.columnCount];
                        for (int i = 0; i < this.columnCount; i++)
                        {
                            string key = matchCollection[i].Groups[1].Value.ToLower(CultureInfo.InvariantCulture);
                            ExportMobileSyncLog.ColumnID columnID;
                            if (this.columnNameToID.TryGetValue(key, out columnID))
                            {
                                this.columnIndexToID[i] = columnID;
                            }
                            else
                            {
                                this.columnIndexToID[i] = ExportMobileSyncLog.ColumnID.maxColumn;
                            }
                        }
                    }
                    return;
                }
                if (this.columnCount == 0)
                {
                    return;
                }
                this.columnValues = new string[13];
                int num  = 0;
                int num2 = 0;
                int j    = 0;

                while (j < line.Length)
                {
                    while (num2 < line.Length && line[num2] == ' ')
                    {
                        num2++;
                    }
                    j = num2;
                    while (j < line.Length && line[j] != ' ')
                    {
                        j++;
                    }
                    if (j == num2)
                    {
                        break;
                    }
                    if (num >= this.columnCount)
                    {
                        return;
                    }
                    ExportMobileSyncLog.ColumnID columnID2 = this.columnIndexToID[num];
                    if (columnID2 != ExportMobileSyncLog.ColumnID.maxColumn)
                    {
                        string text = line.Substring(num2, j - num2);
                        if (text.Length == 1 && text[0] == '-')
                        {
                            text = null;
                        }
                        this.columnValues[(int)columnID2] = text;
                    }
                    num++;
                    num2 = j;
                }
                if (num != this.columnCount)
                {
                    return;
                }
                string strA = this.columnValues[7];

                if (string.Compare(strA, "/Microsoft-Server-ActiveSync", true, CultureInfo.InvariantCulture) != 0 && string.Compare(strA, "/Microsoft-Server-ActiveSync/default.eas", true, CultureInfo.InvariantCulture) != 0)
                {
                    return;
                }
                string text2 = this.columnValues[0];
                string text3 = this.columnValues[1];

                if (text2 == null || text3 == null)
                {
                    return;
                }
                DateTime dateTime;

                if (!DateTime.TryParse(text2 + " " + text3, out dateTime))
                {
                    return;
                }
                if (dateTime < this.startTime || dateTime > this.endTime)
                {
                    return;
                }
                string text4  = this.columnValues[3];
                string text5  = this.columnValues[2];
                string text6  = this.columnValues[6];
                string text7  = this.columnValues[8];
                string text8  = this.columnValues[9];
                string text9  = this.columnValues[11];
                string text10 = this.columnValues[12];
                string text11 = this.columnValues[10];
                ulong  num3   = 0UL;
                ulong  num4   = 0UL;

                ulong.TryParse(this.columnValues[4], out num3);
                ulong.TryParse(this.columnValues[5], out num4);
                string strA2      = null;
                string text12     = null;
                string deviceType = null;
                uint   num5       = 0U;
                uint   num6       = 0U;
                uint   num7       = 0U;
                uint   num8       = 0U;
                string strA3      = null;
                uint   num9       = 0U;
                uint   num10      = 0U;
                uint   num11      = 0U;
                uint   num12      = 0U;
                uint   num13      = 0U;
                uint   num14      = 0U;

                if (text4 != null)
                {
                    match = this.queryPattern.Match(text4);
                    if (!match.Success)
                    {
                        return;
                    }
                    strA2      = match.Groups[1].Value;
                    text12     = match.Groups[2].Value;
                    deviceType = match.Groups[3].Value;
                    strA3      = match.Groups[18].Value;
                    uint.TryParse(match.Groups[19].Value, out num9);
                    uint.TryParse(match.Groups[20].Value, out num10);
                    uint.TryParse(match.Groups[21].Value, out num11);
                    uint.TryParse(match.Groups[22].Value, out num12);
                    uint.TryParse(match.Groups[23].Value, out num13);
                }
                string text13 = "";

                if (!string.IsNullOrEmpty(text5))
                {
                    text13 += text5.ToLower(CultureInfo.InvariantCulture);
                }
                text13 += "_";
                if (!string.IsNullOrEmpty(text12))
                {
                    text13 += text12.ToLower(CultureInfo.InvariantCulture);
                }
                if (text13.Length > 1)
                {
                    ExportMobileSyncLog.UserRow userRow;
                    if (!this.userTable.TryGetValue(text13, out userRow))
                    {
                        userRow            = new ExportMobileSyncLog.UserRow();
                        userRow.Alias      = text5;
                        userRow.DeviceID   = text12;
                        userRow.DeviceType = deviceType;
                        this.userTable.Add(text13, userRow);
                    }
                    if (text4 != null)
                    {
                        int count = match.Groups[4].Captures.Count;
                        if (count > 0)
                        {
                            int num15 = match.Groups[10].Captures.Count - 1;
                            int num16 = match.Groups[5].Captures.Count - 1;
                            for (int k = count - 1; k >= 0; k--)
                            {
                                num6 = (num5 = (num7 = (num8 = (num14 = 0U))));
                                int    index  = match.Groups[4].Captures[k].Index;
                                string value2 = match.Groups[4].Captures[k].Value;
                                if (num16 >= 0 && match.Groups[5].Captures.Count > num16 && index < match.Groups[5].Captures[num16].Index)
                                {
                                    uint.TryParse(match.Groups[5].Captures[num16].Value, out num5);
                                    uint.TryParse(match.Groups[6].Captures[num16].Value, out num6);
                                    num16--;
                                }
                                if (num15 >= 0 && match.Groups[10].Captures.Count > num15 && index < match.Groups[10].Captures[num15].Index)
                                {
                                    uint.TryParse(match.Groups[10].Captures[num15].Value, out num7);
                                    uint.TryParse(match.Groups[11].Captures[num15].Value, out num8);
                                    uint.TryParse(match.Groups[16].Captures[num15].Value, out num14);
                                    num15--;
                                }
                                userRow.ItemsSent     += (ulong)(num7 + num8 + num14);
                                userRow.ItemsReceived += (ulong)(num5 + num6);
                                if (string.Compare(value2, "Em", false, CultureInfo.InvariantCulture) == 0)
                                {
                                    userRow.EmailsSent += (ulong)(num7 + num14 + num8);
                                }
                                if (string.Compare(value2, "Ca", false, CultureInfo.InvariantCulture) == 0)
                                {
                                    userRow.CalendarsSent     += (ulong)(num7 + num8);
                                    userRow.CalendarsReceived += (ulong)(num5 + num6);
                                }
                                if (string.Compare(value2, "Co", false, CultureInfo.InvariantCulture) == 0)
                                {
                                    userRow.ContactsSent     += (ulong)(num7 + num8);
                                    userRow.ContactsReceived += (ulong)(num5 + num6);
                                }
                                if (string.Compare(value2, "Ta", false, CultureInfo.InvariantCulture) == 0)
                                {
                                    userRow.TasksSent     += (ulong)(num7 + num8);
                                    userRow.TasksReceived += (ulong)(num5 + num6);
                                }
                                if (string.Compare(value2, "Nt", false, CultureInfo.InvariantCulture) == 0)
                                {
                                    userRow.NotesSent     += (ulong)(num7 + num8);
                                    userRow.NotesReceived += (ulong)(num5 + num6);
                                }
                            }
                        }
                        else
                        {
                            uint.TryParse(match.Groups[5].Value, out num5);
                            uint.TryParse(match.Groups[6].Value, out num6);
                            uint.TryParse(match.Groups[10].Value, out num7);
                            uint.TryParse(match.Groups[11].Value, out num8);
                            userRow.ItemsSent     += (ulong)(num7 + num8);
                            userRow.ItemsReceived += (ulong)(num5 + num6);
                        }
                    }
                    if (string.Compare(strA2, "SendMail", true, CultureInfo.InvariantCulture) == 0 || string.Compare(strA2, "SmartReply", true, CultureInfo.InvariantCulture) == 0 || string.Compare(strA2, "SmartForward", true, CultureInfo.InvariantCulture) == 0)
                    {
                        userRow.EmailsReceived += 1UL;
                    }
                    if (string.Compare(strA2, "Settings", true, CultureInfo.InvariantCulture) == 0)
                    {
                        if (string.Compare(strA3, "Set", true, CultureInfo.InvariantCulture) == 0)
                        {
                            userRow.NumberOfOOFSet += 1UL;
                        }
                        if (string.Compare(strA3, "Get", true, CultureInfo.InvariantCulture) == 0)
                        {
                            userRow.NumberOfOOFGet += 1UL;
                        }
                    }
                    if (string.Compare(strA2, "Search", true, CultureInfo.InvariantCulture) == 0)
                    {
                        userRow.SearchRequests += 1UL;
                    }
                    userRow.Hits            += 1UL;
                    userRow.BytesSent       += num3;
                    userRow.BytesReceived   += num4;
                    userRow.SharePointHits  += (ulong)num9;
                    userRow.UncHits         += (ulong)num10;
                    userRow.AttachmentHits  += (ulong)num11;
                    userRow.AttachmentBytes += (ulong)num12;
                    if (num13 > 0U && dateTime > userRow.LastPolicyTime)
                    {
                        userRow.LastPolicyTime   = dateTime;
                        userRow.PolicyCompliance = (ExportMobileSyncLog.PolicyCompliance)num13;
                    }
                }
                StringBuilder stringBuilder = new StringBuilder();

                if (text6 != null)
                {
                    stringBuilder.Append(text6.ToLower(CultureInfo.InvariantCulture));
                }
                stringBuilder.Append('_');
                if (text7 != null)
                {
                    stringBuilder.Append(text7.ToLower(CultureInfo.InvariantCulture));
                }
                stringBuilder.Append('_');
                if (text8 != null)
                {
                    stringBuilder.Append(text8.ToLower(CultureInfo.InvariantCulture));
                }
                if (stringBuilder.Length > 2)
                {
                    string key2 = stringBuilder.ToString();
                    ExportMobileSyncLog.ServerRow serverRow;
                    if (!this.serverTable.TryGetValue(key2, out serverRow))
                    {
                        serverRow = new ExportMobileSyncLog.ServerRow();
                        serverRow.DevicesPerDay = new Dictionary <string, Dictionary <string, bool> >();
                        serverRow.ComputerName  = text6;
                        serverRow.HostName      = text7;
                        serverRow.IPAddress     = text8;
                        this.serverTable.Add(key2, serverRow);
                    }
                    if (text12 != null)
                    {
                        Dictionary <string, bool> dictionary;
                        if (!serverRow.DevicesPerDay.TryGetValue(text2, out dictionary))
                        {
                            dictionary = new Dictionary <string, bool>();
                            serverRow.DevicesPerDay.Add(text2, dictionary);
                        }
                        dictionary[text12] = true;
                    }
                    serverRow.Hits          += 1UL;
                    serverRow.BytesSent     += num3;
                    serverRow.BytesReceived += num4;
                }
                ExportMobileSyncLog.HourlyRow hourlyRow = this.hourlyTable[(int)(dateTime.DayOfWeek * (DayOfWeek)24 + dateTime.Hour)];
                if (text12 != null)
                {
                    hourlyRow.Devices[text12] = true;
                }
                if (string.Compare(strA2, "Sync", true, CultureInfo.InvariantCulture) == 0 || string.Compare(strA2, "GetItemEstimate", true, CultureInfo.InvariantCulture) == 0)
                {
                    hourlyRow.SyncCount += 1UL;
                }
                string text14 = "";

                if (text9 != null)
                {
                    text14 = text9.PadLeft(3, '0');
                }
                text14 += "_";
                if (text10 != null)
                {
                    text14 += text10.PadLeft(11, '0');
                }
                if (text14.Length > 1)
                {
                    ExportMobileSyncLog.StatusRow statusRow;
                    if (!this.statusTable.TryGetValue(text14, out statusRow))
                    {
                        statusRow           = new ExportMobileSyncLog.StatusRow();
                        statusRow.Status    = text9;
                        statusRow.SubStatus = text10;
                        this.statusTable.Add(text14, statusRow);
                    }
                    statusRow.Hits += 1UL;
                }
                if (text11 != null)
                {
                    ExportMobileSyncLog.UserAgentRow userAgentRow;
                    if (!this.userAgentTable.TryGetValue(text11, out userAgentRow))
                    {
                        userAgentRow           = new ExportMobileSyncLog.UserAgentRow();
                        userAgentRow.Devices   = new Dictionary <string, bool>();
                        userAgentRow.UserAgent = text11;
                        this.userAgentTable.Add(text11, userAgentRow);
                    }
                    userAgentRow.Hits += 1UL;
                    if (text12 != null)
                    {
                        userAgentRow.Devices[text12] = true;
                    }
                }
            }