Пример #1
0
        /// <summary>
        /// Create a unique DateTimeStamp to identify each log
        /// </summary>
        /// <returns></returns>
        private DateTimeStamp CreateIndexDts()
        {
            var indexTs = new DateTimeStamp(_lastDateTimeStamp, DateTime.UtcNow);

            _lastDateTimeStamp = indexTs;
            return(indexTs);
        }
Пример #2
0
 /// <summary>
 /// forceBuggyRemove is not used here since this client is not lockable.
 /// </summary>
 void IActivityMonitorBoundClient.SetMonitor(IActivityMonitorImpl source, bool forceBuggyRemove)
 {
     if (source != null && _monitorSource != null)
     {
         throw ActivityMonitorClient.CreateMultipleRegisterOnBoundClientException(this);
     }
     // Silently ignore null => null or monitor => same monitor.
     if (source != _monitorSource)
     {
         _currentMinimalFilter = LogFilter.Undefined;
         _prevLogType          = LogEntryType.None;
         _prevlogTime          = DateTimeStamp.Unknown;
         Debug.Assert((source == null) != (_monitorSource == null));
         if ((_monitorSource = source) == null)
         {
             // Releases the channel if any.
             _channel = null;
         }
         else
         {
             var g = _monitorSource.CurrentGroup;
             _currentGroupDepth = g != null ? g.Depth : 0;
             Interlocked.Increment(ref _version);
         }
     }
 }
Пример #3
0
 void IActivityMonitorBoundClient.SetMonitor(IActivityMonitorImpl?source, bool forceBuggyRemove)
 {
     if (source != null && _source != null)
     {
         throw ActivityMonitorClient.CreateMultipleRegisterOnBoundClientException(this);
     }
     // Silently ignore null => null or monitor => same monitor.
     if (source != _source)
     {
         _prevLogType = LogEntryType.None;
         _prevlogTime = DateTimeStamp.Unknown;
         Debug.Assert((source == null) != (_source == null));
         if ((_source = source) == null)
         {
             if (_file != null)
             {
                 _file.Close();
             }
             _file = null;
         }
         else
         {
             // If initialization failed, we let the file null: this monitor will not
             // work (the error will appear in the Critical errors) but this avoids
             // an exception to be thrown here.
             var f = new MonitorBinaryFileOutput(_path, _source.UniqueId, _maxCountPerFile, _useGzipCompression);
             if (f.Initialize(_source.InternalMonitor))
             {
                 var g = _source.CurrentGroup;
                 _currentGroupDepth = g != null ? g.Depth : 0;
                 _file = f;
             }
         }
     }
 }
Пример #4
0
        static ILogEntry ReadGroupClosed(int streamVersion, CKBinaryReader r, StreamLogType t, LogLevel logLevel)
        {
            DateTimeStamp time = new DateTimeStamp(DateTime.FromBinary(r.ReadInt64()), (t & StreamLogType.HasUniquifier) != 0 ? r.ReadByte() : (Byte)0);

            ActivityLogGroupConclusion[] conclusions = Util.Array.Empty <ActivityLogGroupConclusion>();
            if ((t & StreamLogType.HasConclusions) != 0)
            {
                int conclusionsCount = streamVersion < 6 ? r.ReadInt32() : r.ReadNonNegativeSmallInt32();
                conclusions = new ActivityLogGroupConclusion[conclusionsCount];
                for (int i = 0; i < conclusionsCount; i++)
                {
                    CKTrait cTags = ActivityMonitor.Tags.Register(r.ReadString());
                    string  cText = r.ReadString();
                    conclusions[i] = new ActivityLogGroupConclusion(cText, cTags);
                }
            }
            if ((t & StreamLogType.IsMultiCast) == 0)
            {
                return(new LECloseGroup(time, logLevel, conclusions));
            }
            Guid          mId;
            int           depth;
            LogEntryType  prevType;
            DateTimeStamp prevTime;

            ReadMulticastFooter(streamVersion, r, t, out mId, out depth, out prevType, out prevTime);

            return(new LEMCCloseGroup(mId, depth, prevTime, prevType, time, logLevel, conclusions));
        }
Пример #5
0
 /// <summary>
 /// Opens this writer if it is not already opened.
 /// </summary>
 /// <returns>True on success, false otherwise.</returns>
 public bool Open()
 {
     if (_source == null)
     {
         throw new InvalidOperationException("CKMonWriterClient must be registered in an ActivityMonitor.");
     }
     using (_source.ReentrancyAndConcurrencyLock())
     {
         if (_file != null)
         {
             return(true);
         }
         _file        = new MonitorBinaryFileOutput(_path, _source.UniqueId, _maxCountPerFile, _useGzipCompression);
         _prevLogType = LogEntryType.None;
         _prevlogTime = DateTimeStamp.Unknown;
         if (_file.Initialize(_source.InternalMonitor))
         {
             var g = _source.CurrentGroup;
             _currentGroupDepth = g != null ? g.Depth : 0;
         }
         else
         {
             _file = null;
         }
     }
     return(_file != null);
 }
Пример #6
0
 public void MergeFrom(WeatherData other)
 {
     if (other == null)
     {
         return;
     }
     if (other.dateTimeStamp_ != null)
     {
         if (dateTimeStamp_ == null)
         {
             DateTimeStamp = new global::Google.Protobuf.WellKnownTypes.Timestamp();
         }
         DateTimeStamp.MergeFrom(other.DateTimeStamp);
     }
     if (other.TemperatureC != 0)
     {
         TemperatureC = other.TemperatureC;
     }
     if (other.TemperatureF != 0)
     {
         TemperatureF = other.TemperatureF;
     }
     if (other.Summary.Length != 0)
     {
         Summary = other.Summary;
     }
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
Пример #7
0
        public void matching_DateTimeStamp()
        {
            DateTimeStamp t = DateTimeStamp.UtcNow;

            CheckDateTimeStamp(t);
            CheckDateTimeStamp(new DateTimeStamp(t.TimeUtc, 67));
        }
Пример #8
0
 static void ReadMulticastFooter(int streamVersion, CKBinaryReader r, StreamLogType t, out string gId, out string mId, out int depth, out LogEntryType prevType, out DateTimeStamp prevTime)
 {
     if (streamVersion == 9)
     {
         gId   = r.ReadString();
         mId   = r.ReadString();
         depth = r.ReadNonNegativeSmallInt32();
         Throw.CheckData(mId == GrandOutput.ExternalLogMonitorUniqueId || Base64UrlHelper.IsBase64UrlCharacters(mId));
     }
     else
     {
         gId = GrandOutput.UnknownGrandOutputId;
         Debug.Assert(Guid.Empty.ToByteArray().Length == 16);
         mId   = streamVersion < 8 ? new Guid(r.ReadBytes(16)).ToString() : r.ReadString();
         depth = streamVersion < 6 ? r.ReadInt32() : r.ReadNonNegativeSmallInt32();
         if (streamVersion >= 8)
         {
             Throw.CheckData(mId == GrandOutput.ExternalLogMonitorUniqueId || Base64UrlHelper.IsBase64UrlCharacters(mId));
         }
     }
     Throw.CheckData(gId == GrandOutput.UnknownGrandOutputId || Base64UrlHelper.IsBase64UrlCharacters(gId));
     Throw.CheckData(depth >= 0);
     prevType = LogEntryType.None;
     prevTime = DateTimeStamp.Unknown;
     if ((t & StreamLogType.IsPreviousKnown) != 0)
     {
         prevTime = new DateTimeStamp(DateTime.FromBinary(r.ReadInt64()), (t & StreamLogType.IsPreviousKnownHasUniquifier) != 0 ? r.ReadByte() : (Byte)0);
         prevType = (LogEntryType)r.ReadByte();
     }
 }
Пример #9
0
        /// <summary>
        /// Updates or creates a shoplist owner record in the ShopListOwner table.
        /// </summary>
        /// <param name="shopList"></param>
        /// <param name="user"></param>
        /// <returns>
        /// Returns a Tuple<bool, string> with a processing message.
        /// </returns>
        public static Tuple <bool, string> UpdateShopListOwner(ShopList shopList, AppUser user)
        {
            Tuple <bool, string> result = new Tuple <bool, string>(false, "");

            using (SQLiteConnection connection = new SQLiteConnection(LoadConnectionString(), SQLiteOpenFlags.ReadWrite))
            {
                try
                {
                    if (SADatabaseReader.DoesShopListExist(shopList))
                    {
                        connection.Execute(
                            "INSERT OR REPLACE INTO ShopListOwner (AppUser_ID, ShopList_ID, DateTimeModified) " +
                            $"VALUES ({user.ID}, {shopList.SHOPLISTID}, '{DateTimeStamp.Stamp()}')"
                            );

                        result = new Tuple <bool, string>(false, $"De owner van shoplist {shopList.Name}({shopList.SHOPLISTID}) is bijgewerkt.");
                    }
                    else
                    {
                        result = new Tuple <bool, string>(false, $"ShopList {shopList.Name}({shopList.SHOPLISTID}) bestaat niet.");
                    }
                }
                catch (SQLiteException ex)
                {
                    // TODO : SADatabaseReader.UpdateShopListOwner: Error logging naar log.db
                    throw;
                }
            }

            return(result);
        }
Пример #10
0
        public DispatcherSink(Action <IActivityMonitor> initialRegister,
                              IdentityCard identityCard,
                              TimeSpan timerDuration,
                              TimeSpan externalTimerDuration,
                              Action externalTimer,
                              Action <LogFilter?, LogLevelFilter?> filterChange,
                              bool isDefaultGrandOutput)
        {
            _initialRegister = initialRegister;
            _identityCard    = identityCard;
            _queue           = Channel.CreateUnbounded <IMulticastLogEntry?>(new UnboundedChannelOptions()
            {
                SingleReader = true
            });
            _handlers             = new List <IGrandOutputHandler>();
            _confTrigger          = new object();
            _stopTokenSource      = new CancellationTokenSource();
            _timerDuration        = timerDuration;
            _deltaTicks           = timerDuration.Ticks;
            _deltaExternalTicks   = externalTimerDuration.Ticks;
            _externalOnTimer      = externalTimer;
            _filterChange         = filterChange;
            _externalLogLock      = new object();
            _externalLogLastTime  = DateTimeStamp.MinValue;
            _isDefaultGrandOutput = isDefaultGrandOutput;
            _newConf = Array.Empty <GrandOutputConfiguration>();
            var monitor = new ActivityMonitor(applyAutoConfigurations: false);

            // We emit the identity card changed from this monitor (so we need its id).
            // But more importantly, this monitor identifier is the one of the GrandOutput: each log entry
            // references this identifier.
            _sinkMonitorId = monitor.UniqueId;
            _task          = ProcessAsync(monitor);
        }
Пример #11
0
 internal RawLogFile(string fileName)
 {
     _fileName       = fileName;
     InitializerLock = new object();
     _firstEntryTime = DateTimeStamp.MaxValue;
     _lastEntryTime  = DateTimeStamp.MinValue;
 }
Пример #12
0
 internal void Register( RawLogFileMonitorOccurence fileOccurrence, bool newOccurrence, long streamOffset, IMulticastLogEntry log )
 {
     lock( _files )
     {
         Debug.Assert( newOccurrence == !_files.Contains( fileOccurrence ) ); 
         if( newOccurrence ) _files.Add( fileOccurrence );
         if( _firstEntryTime > log.LogTime )
         {
             _firstEntryTime = log.LogTime;
             _firstDepth = log.GroupDepth;
         }
         if( _lastEntryTime < log.LogTime )
         {
             _lastEntryTime = log.LogTime;
             _lastDepth = log.GroupDepth;
         }
         if( !log.Tags.IsEmpty )
         {
             if( _tags == null )
             {
                 _tags = new Dictionary<CKTrait, int>();
                 foreach( var t in log.Tags.AtomicTraits ) _tags.Add( t, 1 );
             }
             else
             {
                 foreach( var t in log.Tags.AtomicTraits )
                 {
                     int count;
                     _tags.TryGetValue( t, out count );
                     _tags[t] = count + 1;
                 }
             }
         }
     }
 }
Пример #13
0
 void IActivityMonitorBoundClient.SetMonitor( IActivityMonitorImpl source, bool forceBuggyRemove )
 {
     if( source != null && _source != null ) throw ActivityMonitorClient.CreateMultipleRegisterOnBoundClientException( this );
     // Silently ignore null => null or monitor => same monitor.
     if( source != _source )
     {
         _prevLogType = LogEntryType.None;
         _prevlogTime = DateTimeStamp.Unknown;
         Debug.Assert( (source == null) != (_source == null) );
         if( (_source = source) == null )
         {
             if( _file != null ) _file.Close();
             _file = null;
         }
         else
         {
             // If initialization failed, we let the file null: this monitor will not
             // work (the error will appear in the Critical errors) but this avoids
             // an exception to be thrown here.
             var f = new MonitorBinaryFileOutput( _path, ((IUniqueId)_source).UniqueId, _maxCountPerFile, _useGzipCompression );
             if( f.Initialize( new SystemActivityMonitor( false, null ) ) )
             {
                 var g = _source.CurrentGroup;
                 _currentGroupDepth = g != null ? g.Depth : 0;
                 _file = f;
             }
         }
     }
 }
Пример #14
0
        private bool ParseJsonInner(string json, float offsetX, float offsetY)
        {
            PositionJson p = JsonConvert.DeserializeObject <PositionJson>(json);

            Code = p.tag_id;
            X    = p.x.ToFloat() * AppSetting.PositionPower;
            Y    = p.z.ToFloat() * AppSetting.PositionPower;
            Z    = p.y.ToFloat() * AppSetting.PositionPower;

            //Y = p.y.ToFloat() * 10;
            //Z = p.z.ToFloat() * 10;
            X += offsetX;
            Z += offsetY;

            DateTimeStamp = p.timestamp.ToLong();
            DateTime      = DateTimeStamp.ToDateTime();
            Number        = p.sn.ToInt();
            Power         = (int)(p.bettery.ToFloat() * 100);
            EventType     = 0;
            if (p.events != null && p.events.Count() > 0)
            {
                for (int i = 0; i < p.events.Count(); i++)
                {
                    string strEventType = p.events[i].event_type;
                    if (strEventType == "SOS")
                    {
                        EventType = 1;
                    }
                }
            }
            return(true);
        }
 public OneLogReader(RawLogFileMonitorOccurence file, DateTimeStamp firstLogTime)
 {
     File            = file;
     _reader         = file.CreateFilteredReaderAndMoveTo(firstLogTime);
     FirstGroupDepth = _reader.CurrentMulticast.GroupDepth;
     Head            = _reader.CurrentMulticastWithOffset;
 }
Пример #16
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (dateTimeStamp_ != null)
            {
                hash ^= DateTimeStamp.GetHashCode();
            }
            if (TemperatureC != 0)
            {
                hash ^= TemperatureC.GetHashCode();
            }
            if (TemperatureF != 0)
            {
                hash ^= TemperatureF.GetHashCode();
            }
            if (Summary.Length != 0)
            {
                hash ^= Summary.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Пример #17
0
 public LEMCOpenGroup(Guid monitorId, int depth, DateTimeStamp previousLogTime, LogEntryType previousEntryType, string text, DateTimeStamp t, string fileName, int lineNumber, LogLevel l, CKTrait tags, CKExceptionData ex)
     : base(text, t, fileName, lineNumber, l, tags, ex)
 {
     _monitorId         = monitorId;
     _depth             = depth;
     _previousEntryType = previousEntryType;
     _previousLogTime   = previousLogTime;
 }
Пример #18
0
 public LEMCCloseGroup(Guid monitorId, int depth, DateTimeStamp previousLogTime, LogEntryType previousEntryType, DateTimeStamp t, LogLevel level, IReadOnlyList <ActivityLogGroupConclusion> c)
     : base(t, level, c)
 {
     _monitorId         = monitorId;
     _depth             = depth;
     _previousEntryType = previousEntryType;
     _previousLogTime   = previousLogTime;
 }
Пример #19
0
 internal LiveIndexedMonitor(Guid monitorId, MultiLogReader reader)
 {
     MonitorId       = monitorId;
     _reader         = reader;
     _files          = new List <RawLogFileMonitorOccurence>();
     _firstEntryTime = DateTimeStamp.MaxValue;
     _lastEntryTime  = DateTimeStamp.MinValue;
 }
Пример #20
0
 public void OnGroupClosed(IActivityLogGroup group, IReadOnlyList <ActivityLogGroupConclusion> conclusions)
 {
     if (group.CloseLogTime <= _lastOne)
     {
         ++NbClash;
     }
     _lastOne = group.CloseLogTime;
 }
Пример #21
0
 public void OnOpenGroup(IActivityLogGroup group)
 {
     if (group.LogTime <= _lastOne)
     {
         ++NbClash;
     }
     _lastOne = group.LogTime;
 }
Пример #22
0
 public void OnUnfilteredLog(ActivityMonitorLogData data)
 {
     if (data.LogTime <= _lastOne)
     {
         ++NbClash;
     }
     _lastOne = data.LogTime;
 }
Пример #23
0
 public LEMCCloseGroup( Guid monitorId, int depth, DateTimeStamp previousLogTime, LogEntryType previousEntryType, DateTimeStamp t, LogLevel level, IReadOnlyList<ActivityLogGroupConclusion> c )
     : base( t, level, c )
 {
     _monitorId = monitorId;
     _depth = depth;
     _previousEntryType = previousEntryType;
     _previousLogTime = previousLogTime;
 }
Пример #24
0
 public Entry(ActivityMonitorLogData d)
 {
     Level     = d.Level;
     Tags      = d.Tags;
     Text      = d.Text;
     Exception = d.Exception;
     LogTime   = d.LogTime;
 }
Пример #25
0
 public Entry( ActivityMonitorLogData d )
 {
     Level = d.Level;
     Tags = d.Tags;
     Text = d.Text;
     Exception = d.Exception;
     LogTime = d.LogTime;
 }
Пример #26
0
 public Entry(IActivityLogGroup d)
 {
     Level     = d.GroupLevel;
     Tags      = d.GroupTags;
     Text      = d.GroupText;
     Exception = d.Exception;
     LogTime   = d.LogTime;
 }
Пример #27
0
 /// <summary>
 /// Binary writes a closing entry.
 /// </summary>
 /// <param name="w">Binary writer to use.</param>
 /// <param name="level">Log level of the log entry.</param>
 /// <param name="closeTime">Time stamp of the group closing.</param>
 /// <param name="conclusions">Group conclusions.</param>
 static public void WriteCloseGroup(CKBinaryWriter w, LogLevel level, DateTimeStamp closeTime, IReadOnlyList <ActivityLogGroupConclusion> conclusions)
 {
     if (w == null)
     {
         throw new ArgumentNullException("w");
     }
     DoWriteCloseGroup(w, StreamLogType.TypeGroupClosed, level, closeTime, conclusions);
 }
Пример #28
0
 public Entry( IActivityLogGroup d )
 {
     Level = d.GroupLevel;
     Tags = d.GroupTags;
     Text = d.GroupText;
     Exception = d.Exception;
     LogTime = d.LogTime;
 }
Пример #29
0
 internal RawLogFileMonitorOccurence(RawLogFile f, string monitorId, long streamOffset)
 {
     LogFile        = f;
     MonitorId      = monitorId;
     FirstOffset    = streamOffset;
     FirstEntryTime = DateTimeStamp.MaxValue;
     LastEntryTime  = DateTimeStamp.MinValue;
 }
Пример #30
0
 internal LiveIndexedMonitor(string monitorId)
 {
     MonitorId            = monitorId;
     _files               = new List <RawLogFileMonitorOccurence>();
     _firstEntryTime      = DateTimeStamp.MaxValue;
     _lastEntryTime       = DateTimeStamp.MinValue;
     _identityCardCreated = new CancellationTokenSource();
 }
Пример #31
0
 public LEMCLog( Guid monitorId, int depth, DateTimeStamp previousLogTime, LogEntryType previousEntryType, string text, DateTimeStamp t, string fileName, int lineNumber, LogLevel l, CKTrait tags, CKExceptionData ex )
     : base( text, t, fileName, lineNumber, l, tags, ex )
 {
     _monitorId = monitorId;
     _depth = depth;
     _previousEntryType = previousEntryType;
     _previousLogTime = previousLogTime;
 }
Пример #32
0
 internal LiveIndexedMonitor( Guid monitorId, MultiLogReader reader )
 {
     MonitorId = monitorId;
     _reader = reader;
     _files = new List<RawLogFileMonitorOccurence>();
     _firstEntryTime = DateTimeStamp.MaxValue;
     _lastEntryTime = DateTimeStamp.MinValue;
 }
 internal Entry( CKTrait tags, LogLevel level, string text, DateTimeStamp logTime, Exception ex )
 {
     Debug.Assert( (level & LogLevel.IsFiltered) == 0 );
     Tags = tags;
     MaskedLevel = level;
     LogTime = logTime;
     Text = text;
     Exception = ex;
 }
Пример #34
0
 void IActivityMonitorClient.OnUnfilteredLog(ref ActivityMonitorLogData data)
 {
     if (_file != null)
     {
         _file.UnicastWrite(data, this);
         _prevlogTime = data.LogTime;
         _prevLogType = LogEntryType.Line;
     }
 }
Пример #35
0
        private void LoadFeedbackMessage()
        {
            Message = Template;

            Message = Message.Replace("$object", Object);
            Message = Message.Replace("$block", Block);
            Message = Message.Replace("$item", Item);
            Message = Message.Replace("$time", DateTimeStamp.ToString("HH:mm"));
        }
Пример #36
0
 void IActivityMonitorClient.OnGroupClosed(IActivityLogGroup group, IReadOnlyList <ActivityLogGroupConclusion>?conclusions)
 {
     if (_file != null)
     {
         _file.UnicastWriteCloseGroup(group, conclusions, this);
         --_currentGroupDepth;
         _prevlogTime = group.CloseLogTime;
         _prevLogType = LogEntryType.CloseGroup;
     }
 }
Пример #37
0
 public LEOpenGroup( string text, DateTimeStamp t, string fileName, int lineNumber, LogLevel l, CKTrait tags, CKExceptionData ex )
 {
     _text = text;
     _time = t;
     _fileName = fileName;
     _lineNumber = lineNumber;
     _level = l;
     _tags = tags;
     _ex = ex;
 }
 internal Monitor(LiveIndexedMonitor m)
 {
     _monitorId      = m.MonitorId;
     _files          = m._files.OrderBy(f => f.FirstEntryTime).ToArray();
     _firstEntryTime = m._firstEntryTime;
     _firstDepth     = m._firstDepth;
     _lastEntryTime  = m._lastEntryTime;
     _lastDepth      = m._lastDepth;
     _tags           = m._tags != null?m._tags.OrderByDescending(k => k.Key).ToArray() : Util.Array.Empty <KeyValuePair <CKTrait, int> >();
 }
Пример #39
0
 void IActivityMonitorClient.OnOpenGroup(IActivityLogGroup group)
 {
     if (_file != null)
     {
         _file.UnicastWriteOpenGroup(group, this);
         ++_currentGroupDepth;
         _prevlogTime = group.Data.LogTime;
         _prevLogType = LogEntryType.OpenGroup;
     }
 }
Пример #40
0
 public LEOpenGroup( LEMCOpenGroup e )
 {
     _text = e.Text;
     _time = e.LogTime;
     _fileName = e.FileName;
     _lineNumber = e.LineNumber;
     _level = e.LogLevel;
     _tags = e.Tags;
     _ex = e.Exception;
 }
Пример #41
0
 /// <summary>
 /// Initializes or reinitializes this group (if it has been disposed). 
 /// </summary>
 internal void Initialize( ActivityMonitorGroupData data )
 {
     SavedMonitorFilter = Monitor._configuredFilter;
     SavedMonitorTags = Monitor._currentTag;
     if( (_unfilteredParent = Monitor._currentUnfiltered) != null ) _depth = _unfilteredParent._depth + 1;
     else _depth = 1;
     // Logs everything when a Group is an error: we then have full details available without
     // logging all with Error or Fatal.
     if( data.MaskedLevel >= LogLevel.Error && Monitor._configuredFilter != LogFilter.Debug ) Monitor.DoSetConfiguredFilter( LogFilter.Debug );
     _closeLogTime = DateTimeStamp.MinValue;
     _data = data;
 }
Пример #42
0
        private static void CheckDateTimeStamp( DateTimeStamp t )
        {
            string s = t.ToString();
            var m = new StringMatcher( "X" + s + "Y" );
            Assert.That( m.MatchChar( 'X' ) );
            DateTimeStamp parsed;
            Assert.That( m.MatchDateTimeStamp( out parsed ) && parsed == t );
            Assert.That( m.MatchChar( 'Y' ) );

            m = new StringMatcher( s.Insert( 2, "X" ) );
            Assert.That( m.MatchDateTimeStamp( out parsed ), Is.False );
            Assert.That( m.ErrorMessage, Is.Not.Null );
            int i;
            Assert.That( m.MatchInt32( out i ) && i == 20 );
        }
Пример #43
0
 /// <summary>
 /// Matches a <see cref="DateTimeStamp"/>.
 /// </summary>
 /// <param name="this">This <see cref="StringMatcher"/>.</param>
 /// <param name="time">Resulting time stamp on successful match; <see cref="DateTimeStamp.Unknown"/> otherwise.</param>
 /// <returns>True if the time stamp has been matched.</returns>
 static public bool MatchDateTimeStamp( this StringMatcher @this, out DateTimeStamp time )
 {
     time = DateTimeStamp.Unknown;
     int savedIndex = @this.StartIndex;
     DateTime t;
     if( [email protected]( out t ) ) return @this.SetError();
     byte uniquifier = 0;
     if( @this.MatchChar( '(' ) )
     {
         int unique;
         if( [email protected]( out unique, 0, 255 ) || [email protected]( ')' ) ) return @this.BackwardAddError( savedIndex );
         uniquifier = (byte)unique;
     }
     time = new DateTimeStamp( t, uniquifier );
     return @this.Forward( 0 );
 }
Пример #44
0
 /// <summary>
 /// forceBuggyRemove is not used here since this client is not lockable.
 /// </summary>
 void IActivityMonitorBoundClient.SetMonitor( IActivityMonitorImpl source, bool forceBuggyRemove )
 {
     if( source != null && _monitorSource != null ) throw ActivityMonitorClient.CreateMultipleRegisterOnBoundClientException( this );
     // Silently ignore null => null or monitor => same monitor.
     if( source != _monitorSource )
     {
         _currentMinimalFilter = LogFilter.Undefined;
         _prevLogType = LogEntryType.None;
         _prevlogTime = DateTimeStamp.Unknown;
         Debug.Assert( (source == null) != (_monitorSource == null) );
         if( (_monitorSource = source) == null )
         {
             // Releases the channel if any.
             _channel = null;
         }
         else
         {
             var g = _monitorSource.CurrentGroup;
             _currentGroupDepth = g != null ? g.Depth : 0;
             Interlocked.Increment( ref _version );
         }
     }
 }
Пример #45
0
        static string FindUniqueTimedFile( string pathPrefix, string fileSuffix, DateTime time, int maxTryBeforeGuid, Func<string, bool> tester )
        {
            if( pathPrefix == null ) throw new ArgumentNullException( "pathPrefix" );
            if( fileSuffix == null ) throw new ArgumentNullException( "fileSuffix" );
            if( maxTryBeforeGuid < 0 ) throw new ArgumentOutOfRangeException( "maxTryBeforeGuid" );

            DateTimeStamp timeStamp = new DateTimeStamp( time );
            int counter = 0;
            string result = pathPrefix + timeStamp.ToString() + fileSuffix;
            for( ; ; )
            {
                if( tester( result ) ) break;
                if( counter < maxTryBeforeGuid )
                {
                    timeStamp = new DateTimeStamp( timeStamp, timeStamp );
                    result = pathPrefix + timeStamp.ToString() + fileSuffix;
                }
                else
                {
                    if( counter == maxTryBeforeGuid + 1 ) throw new CKException( Impl.CoreResources.FileUtilUnableToCreateUniqueTimedFile );
                    if( counter == maxTryBeforeGuid )
                    {
                        result = pathPrefix + FormatTimedUniqueFilePart( time ) + fileSuffix;
                    }
                }
                ++counter;
            }
            return result;
        }
Пример #46
0
 /// <summary>
 /// Opens a <see cref="LogReader"/> that reads unicast entries only from this monitor and positions it on the first entry
 /// with the given time (i.e. <see cref="LogReader.MoveNext"/> has been called).
 /// </summary>
 /// <param name="logTime">Log time. Must exist in the stream otherwise an exception is thrown.</param>
 /// <returns>A log reader that will read only entries from this monitor.</returns>
 public LogReader CreateFilteredReaderAndMoveTo( DateTimeStamp logTime )
 {
     var r = LogReader.Open( LogFile.FileName, FirstOffset, new LogReader.MulticastFilter( MonitorId, LastOffset ) );
     while( r.MoveNext() && r.Current.LogTime < logTime ) ;
     return r;
 }
Пример #47
0
 internal RawLogFileMonitorOccurence( RawLogFile f, Guid monitorId, long streamOffset )
 {
     LogFile = f;
     MonitorId = monitorId;
     FirstOffset = streamOffset;
     FirstEntryTime = DateTimeStamp.MaxValue;
     LastEntryTime = DateTimeStamp.MinValue;
 }
Пример #48
0
 /// <summary>
 /// Opens this writer if it is not already opened.
 /// </summary>
 /// <returns>True on success, false otherwise.</returns>
 public bool Open()
 {
     using( _source.ReentrancyAndConcurrencyLock() )
     {
         if( _source == null ) throw new InvalidOperationException( "CKMonWriterClient must be registered in an ActivityMonitor." );
         if( _file != null ) return true;
         _file = new MonitorBinaryFileOutput( _path, _source.UniqueId, _maxCountPerFile, _useGzipCompression );
         _prevLogType = LogEntryType.None;
         _prevlogTime = DateTimeStamp.Unknown;
     }
     using( SystemActivityMonitor.EnsureSystemClient( _source ) )
     {
         using( _source.ReentrancyAndConcurrencyLock() )
         {
             if( _file.Initialize( _source ) )
             {
                 var g = _source.CurrentGroup;
                 _currentGroupDepth = g != null ? g.Depth : 0;
             }
             else _file = null;
         }
     }
     return _file != null;
 }
Пример #49
0
 internal DateTimeStamp CombineTagsAndAdjustLogTime( CKTrait tags, DateTimeStamp lastLogTime )
 {
     if( _tags.IsEmpty ) _tags = tags;
     else _tags = _tags.Union( tags );
     return _logTime = new DateTimeStamp( lastLogTime, _logTime.IsKnown ? _logTime : DateTimeStamp.UtcNow );
 }
Пример #50
0
 void IActivityMonitorClient.OnOpenGroup( IActivityLogGroup group )
 {
     var h = EnsureChannel();
     if( h != null )
     {
         IMulticastLogEntry e = LogEntry.CreateMulticastOpenGroup( _monitorSource.UniqueId, _prevLogType, _prevlogTime, _currentGroupDepth, group.GroupText, group.LogTime, group.GroupLevel, group.FileName, group.LineNumber, group.GroupTags, group.EnsureExceptionData() );
         h.Handle( new GrandOutputEventInfo( e, _monitorSource.Topic ) );
         ++_currentGroupDepth;
         _prevlogTime = group.LogTime;
         _prevLogType = LogEntryType.OpenGroup;
     }
 }
Пример #51
0
 void IActivityMonitorClient.OnOpenGroup( IActivityLogGroup group )
 {
     if( _file != null )
     {
         _file.UnicastWriteOpenGroup( group, this );
         ++_currentGroupDepth;
         _prevlogTime = group.LogTime;
         _prevLogType = LogEntryType.OpenGroup;
     }
 }
Пример #52
0
 /// <summary>
 /// Initializes a new <see cref="ActivityMonitorLogData"/>.
 /// </summary>
 /// <param name="level">Log level. Can not be <see cref="LogLevel.None"/>.</param>
 /// <param name="exception">Exception of the log. Can be null.</param>
 /// <param name="tags">Tags (from <see cref="ActivityMonitor.Tags"/>) to associate to the log. It will be union-ed with the current <see cref="IActivityMonitor.AutoTags"/>.</param>
 /// <param name="text">Text of the log. Can be null or empty only if <paramref name="exception"/> is not null: the <see cref="T:Exception.Message"/> is the text.</param>
 /// <param name="logTime">
 /// Time of the log. 
 /// You can use <see cref="DateTimeStamp.UtcNow"/> or <see cref="ActivityMonitorExtension.NextLogTime">IActivityMonitor.NextLogTime()</see> extension method.
 /// </param>
 /// <param name="fileName">Name of the source file that emitted the log. Can be null.</param>
 /// <param name="lineNumber">Line number in the source file that emitted the log. Can be null.</param>
 public ActivityMonitorLogData( LogLevel level, Exception exception, CKTrait tags, string text, DateTimeStamp logTime, string fileName, int lineNumber )
     : this( level, fileName, lineNumber )
 {
     if( MaskedLevel == LogLevel.None || MaskedLevel == LogLevel.Mask ) throw new ArgumentException( Impl.ActivityMonitorResources.ActivityMonitorInvalidLogLevel, "level" );
     Initialize( text, exception, tags, logTime );
 }
Пример #53
0
 internal RawLogFile( string fileName )
 {
     _fileName = fileName;
     InitializerLock = new object();
     _firstEntryTime = DateTimeStamp.MaxValue;
     _lastEntryTime = DateTimeStamp.MinValue;
 }
Пример #54
0
 internal void Initialize( MultiLogReader reader )
 {
     try
     {
         var monitorOccurrences = new Dictionary<Guid, RawLogFileMonitorOccurence>();
         var monitorOccurrenceList = new List<RawLogFileMonitorOccurence>();
         using( var r = LogReader.Open( _fileName ) )
         {
             if( r.MoveNext() )
             {
                 _fileVersion = r.StreamVersion;
                 do
                 {
                     var log = r.Current as IMulticastLogEntry;
                     if( log != null )
                     {
                         ++_totalEntryCount;
                         if( _firstEntryTime > log.LogTime ) _firstEntryTime = log.LogTime;
                         if( _lastEntryTime < log.LogTime ) _lastEntryTime = log.LogTime;
                         UpdateMonitor( reader, r.StreamOffset, monitorOccurrences, monitorOccurrenceList, log );
                     }
                 }
                 while( r.MoveNext() );
             }
             _badEndOfFile = r.BadEndOfFileMarker;
             _error = r.ReadException;
         }
         _monitors = monitorOccurrenceList.ToArray();
     }
     catch( Exception ex )
     {
         _error = ex;
     }
 }
Пример #55
0
 void IActivityMonitorClient.OnGroupClosed( IActivityLogGroup group, IReadOnlyList<ActivityLogGroupConclusion> conclusions )
 {
     var h = EnsureChannel();
     if( h != null )
     {
         IMulticastLogEntry e = LogEntry.CreateMulticastCloseGroup( _monitorSource.UniqueId, _prevLogType, _prevlogTime, _currentGroupDepth, group.CloseLogTime, group.GroupLevel, conclusions );
         h.Handle( new GrandOutputEventInfo( e, _monitorSource.Topic ) );
         --_currentGroupDepth;
         _prevlogTime = group.CloseLogTime;
         _prevLogType = LogEntryType.CloseGroup;
     }
 }
Пример #56
0
        /// <summary>
        /// Initializes this data.
        /// </summary>
        /// <param name="text">
        /// Text of the log. Can be null or empty: if <paramref name="exception"/> is not null, 
        /// the <see cref="Exception.Message"/> becomes the text otherwise <see cref="ActivityMonitor.NoLogText"/> is used.
        /// </param>
        /// <param name="exception">Exception of the log. Can be null.</param>
        /// <param name="tags">
        /// Tags (from <see cref="ActivityMonitor.Tags"/>) to associate to the log. 
        /// It will be union-ed with the current <see cref="IActivityMonitor.AutoTags"/>.</param>
        /// <param name="logTime">
        /// Time of the log. 
        /// You can use <see cref="DateTimeStamp.UtcNow"/> or <see cref="ActivityMonitorExtension.NextLogTime">IActivityMonitor.NextLogTime()</see> extension method.
        /// </param>
        public void Initialize( string text, Exception exception, CKTrait tags, DateTimeStamp logTime )
        {
            if( string.IsNullOrEmpty( (_text = text) ) )
            {
                _text = exception == null ? ActivityMonitor.NoLogText : exception.Message;
            }

            _exception = exception;
            _tags = tags ?? ActivityMonitor.Tags.Empty;
            _logTime = logTime;
        }
Пример #57
0
 void IActivityMonitorClient.OnUnfilteredLog( ActivityMonitorLogData data )
 {
     if( _file != null )
     {
         _file.UnicastWrite( data, this );
         _prevlogTime = data.LogTime;
         _prevLogType = LogEntryType.Line;
     }
 }
Пример #58
0
 void IActivityMonitorClient.OnGroupClosed( IActivityLogGroup group, IReadOnlyList<ActivityLogGroupConclusion> conclusions )
 {
     if( _file != null )
     {
         _file.UnicastWriteCloseGroup( group, conclusions, this );
         --_currentGroupDepth;
         _prevlogTime = group.CloseLogTime;
         _prevLogType = LogEntryType.CloseGroup;
     }
 }
Пример #59
0
 void IActivityMonitorClient.OnUnfilteredLog( ActivityMonitorLogData data )
 {
     var h = EnsureChannel();
     if( h != null )
     {
         IMulticastLogEntry e = LogEntry.CreateMulticastLog( _monitorSource.UniqueId, _prevLogType, _prevlogTime, _currentGroupDepth, data.Text, data.LogTime, data.Level, data.FileName, data.LineNumber, data.Tags, data.EnsureExceptionData() );
         h.Handle( new GrandOutputEventInfo( e, _monitorSource.Topic ) );
         _prevlogTime = data.LogTime;
         _prevLogType = LogEntryType.Line;
     }
 }
 internal DependentToken( Guid monitorId, DateTimeStamp logTime, string topic )
 {
     _originatorId = monitorId;
     _creationDate = logTime;
     _topic = topic;
 }