コード例 #1
0
 protected object Convert2Date(RecWrapper rec, string field, string[] fieldvalues, object data)
 {
     DateTime dt;
     return DateTime.TryParseExact(fieldvalues[0], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt) ? dt.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture) : string.Empty;
 }
コード例 #2
0
 private bool ProcessLine(DataMappingInfo headerInfo, string line, RecWrapper rec)
 {
     try
     {
         string[] fields;
         Exception error = null;
         if (MappedDataHelper.ProcessLine(headerInfo, line, rec, this, out fields, ref error, new[] { ',' }))
         {
             if (string.IsNullOrEmpty(rec.Datetime))
                 rec.Datetime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
             return true;
         }
         throw error ?? new Exception("Unknown error in data helper process line");
     }
     catch (Exception e)
     {
         L.Log(LogType.FILE, LogLevel.ERROR, "Error while processing line:[" + line + "]:" + e);
     }
     return false;
 }
コード例 #3
0
        private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                L.Log(LogType.FILE, LogLevel.INFORM, "Begin Processing LastFile(" + lastFile + ") LastRecord(" + lastPosition + ")");
                if (!InitializeInstance())
                    return;

                if (!GetLastFile(false))
                    return;

                PrepareEncoding(ref encoding);

                var recordSent = 0;
                Dictionary<string, int> header = null;
                var svc = GetInstanceService(usingRegistry ? "Security Manager Sender" : "Security Manager Remote Recorder");
                while (recordSent < max_record_send)
                {
                    var fInfo = new FileInfo(Path.Combine(Location, lastFile));
                    if (fInfo.Exists)
                    {
                        using (
                            var inp = new FileStream(fInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
                            )
                        {
                            long position = 0;

                            var headerInfo = GetHeaderInfo(inp, ref header, ref position);
                            if (headerInfo == null)
                            {
                                L.Log(LogType.FILE, LogLevel.WARN, fInfo.FullName + " has no header");
                            }
                            else
                            {
                                WarnForMissingHeaders(fInfo, headerInfo, header);
                                if (position > lastPosition)
                                {
                                    SetReg(Id, position.ToString(CultureInfo.InvariantCulture), string.Empty, fInfo.Name,
                                           string.Empty);
                                    lastPosition = position;
                                }
                                inp.Seek(lastPosition, SeekOrigin.Begin);
                                var line = string.Empty;
                                var reader = new BufferedLineReader(inp);
                                var nl = 0;
                                var rec = new RecWrapper();
                                while (recordSent < max_record_send &&
                                       (line = reader.ReadLine(encoding, ref nl)) != null)
                                {
                                    if (ProcessLine(headerInfo, line, rec))
                                    {
                                        rec.LogName = "DHCPRecorder";
                                        rec.CustomStr9 = headerInfo.Name;
                                        svc.SetData(_dal, _virtualHost, rec.rec);
                                        recordSent++;
                                    }
                                    svc.SetReg(Id, reader.Position.ToString(CultureInfo.InvariantCulture), string.Empty,
                                               fInfo.Name, string.Empty, rec.Datetime);
                                    lastPosition = reader.Position;
                                }
                                if (recordSent == max_record_send)
                                    return;
                            }
                        }
                    }
                    if (isLastFileInLocation)
                        return;
                    if (!GetLastFile(true))
                        return;
                }
            }
            catch (Exception ex)
            {
                L.Log(LogType.FILE, LogLevel.ERROR, "Error in timer handler:" + ex);
            }
            finally
            {
                timer1.Enabled = true;
            }
        }
コード例 #4
0
 protected static object Convert2Int64(RecWrapper record, string field, string[] values, object data)
 {
     var l = 0L;
     return Int64.TryParse(values[0], out l) ? l : 0L;
 }
コード例 #5
0
 private void ClearRecord(RecWrapper rec)
 {
     foreach (var pInfo in typeof(RecWrapper).GetProperties())
     {
         pInfo.SetValue(rec, pInfo.PropertyType.IsValueType ? Activator.CreateInstance(pInfo.PropertyType) : null, null);
     }
 }
コード例 #6
0
 protected static object Convert2Date(RecWrapper record, string field, string[] values, object data)
 {
     DateTime dt;
     var recorder = data as DHCPRecorder;
     if (DateTime.TryParseExact(values[0] + " " + values[1], "M/d/y H:m:s", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)
         || DateTime.TryParseExact(values[0] + " " + values[1], "M/d/yyyy H:m:s", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
         return dt.AddSeconds(recorder == null ? 0 : recorder.zone).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
     return string.Empty;
 }
コード例 #7
0
 protected static object Convert2Int32(RecWrapper record, string field, string[] values, object data)
 {
     var i = 0;
     return Int32.TryParse(values[0], out i) ? i : 0;
 }
コード例 #8
0
 protected static object VersionConcat(RecWrapper record, string field, string[] values, object data)
 {
     if (string.IsNullOrEmpty(values[0]))
         return UrlDecode(values[1]);
     if (string.IsNullOrEmpty(values[1]))
         return UrlDecode(values[0]);
     return UrlDecode(values[0] + " " + values[1]);
 }
コード例 #9
0
        protected static object DescriptionSplitter(RecWrapper record, string field, string[] values, object data)
        {
            if (string.IsNullOrEmpty(values[0]))
            {
                record.CustomStr1 = string.Empty;
                return string.Empty;
            }

            var uriStr = UrlDecode(values[0]);
            var parts = uriStr.Split(new[] { ';' }, 2);
            if (parts.Length == 2)
                record.CustomStr1 = StringHelper.MakeSureLength(parts[1], 900);

            return StringHelper.MakeSureLength(parts[0], 900);
        }
コード例 #10
0
 protected static object CustomStr5Splitter(RecWrapper record, string field, string[] values, object data)
 {
     return StringHelper.MakeSureLength(values[0], 900);
 }
コード例 #11
0
        protected static object CustomStr1Splitter(RecWrapper record, string field, string[] values, object data)
        {
            if (string.IsNullOrEmpty(values[0]))
                return values[0];

            var uriStr = UrlDecode(values[0]);
            if (uriStr.Length > 1800)
                record.CustomStr10 = uriStr.Substring(900, 900);
            else if (uriStr.Length > 900)
                record.CustomStr10 = uriStr.Substring(900, uriStr.Length - 900);
            return StringHelper.MakeSureLength(uriStr, 900);
        }
コード例 #12
0
 protected virtual NextInstruction ApplyConstraints(RecWrapper recWrapper)
 {
     if (ConstrainedDataLookup == null)
         return NextInstruction.Do;
     foreach (var constraintCollection in ConstrainedDataLookup)
     {
         var consApplied = constraintCollection.Value.Apply(recWrapper, null);
         if ((consApplied & NextInstruction.Continue) != NextInstruction.Continue)
             return consApplied;
     }
     return NextInstruction.Do;
 }