/// <summary> /// Executes this operation. /// </summary> /// <param name="cps">The points to save (none of these should correspond to previously created /// features in the map model, otherwise an exception will be raised).</param> /// <param name="ent">The entity type to assign to control points</param> internal void Execute(ControlPoint[] cps, IEntity ent) { CadastralMapModel mapModel = CadastralMapModel.Current; foreach (ControlPoint cp in cps) { // Add a new point to the map & define it's ID PointFeature p = mapModel.AddPoint(cp, ent, this); // Create the new ID (and point the ID and feature to each other). string keystr = cp.ControlId.ToString(); ForeignId fid = new ForeignId(keystr); fid.Add(p); m_Features.Add(p); } Complete(); }
public GroupDef EndGetGroupTrackerIds( IAsyncResult asyncResult ) { if ( asyncResult is AsyncResult<int> ) { // it's a test group with faked locations taken from files int group = ( asyncResult as AsyncResult<int> ).EndInvoke( ); if ( group != TestGroup ) throw new ApplicationException( string.Format( "Unknown test group {0}", group ) ); return GetTestGroup( ); } if ( asyncResult is AsyncResult<GroupDef> ) { // result was cached, so now it is just a technical call to retrieve it: return ( asyncResult as AsyncResult<GroupDef> ).EndInvoke( ); } GroupDef result; int prevOp = Interlocked.CompareExchange( ref this.operation, ( int ) ( Operation.None ), ( int ) ( Operation.GetGroupTrackerIds ) ); if ( prevOp != ( int ) Operation.GetGroupTrackerIds ) { throw new InvalidOperationException( "End* call doesn't have a corresponding Begin* call." ); } result.TrackerNames = new List<TrackerName>( ); try { using ( SqlDataReader sqlDataReader = this.sqlCmd.EndExecuteReader( asyncResult ) ) { while ( sqlDataReader.Read( ) ) { TrackerName trackerId; trackerId.Name = sqlDataReader["Name"].ToString( ); ForeignId foreignId = new ForeignId( "SPOT", sqlDataReader["TrackerForeignId"].ToString( ) ); trackerId.ForeignId = foreignId; result.TrackerNames.Add( trackerId ); } } object objValue = this.sqlCmd.Parameters["@Version"].Value; if ( objValue is DBNull ) result.VersionInDb = 0; else result.VersionInDb = Convert.ToInt32( objValue ); objValue = this.sqlCmd.Parameters["@DisplayUserMessages"].Value; if ( objValue is DBNull ) result.ShowUserMessages = false; else result.ShowUserMessages = Convert.ToBoolean( objValue ); try { object objStartTs = this.sqlCmd.Parameters["@StartTs"].Value; if ( objStartTs is DBNull ) result.StartTs = null; else { DateTime temp = Convert.ToDateTime( objStartTs ); if ( temp.Kind == DateTimeKind.Unspecified ) result.StartTs = DateTime.SpecifyKind( temp, DateTimeKind.Utc ); else result.StartTs = temp.ToUniversalTime( ); } } catch ( Exception exc ) { // It's a service feature, so mainly just ignore the error: Log.ErrorFormat( "Can't get StartTs: {0}", exc.Message ); result.StartTs = null; } } catch ( Exception exc ) { Log.ErrorFormat( "Can't end getting group IDs: {0}", exc.Message ); throw; } finally { this.sqlCmd.Connection.Close( ); } SetInCache( this.groupId, result ); return result; }
private static TrackerStateHolder GetHolder( ForeignId id, DateTime addedTime = default(DateTime) ) { var originalReplacement = TimeService.DebugReplacement; try { if ( addedTime != default( DateTime ) ) TimeService.DebugReplacement = ( ) => addedTime; return new TrackerStateHolder( id ); } finally { TimeService.DebugReplacement = originalReplacement; } }
internal void AddRequestStartEvent( ForeignId foreignId, DateTime requestStart ) { try { lock ( this.sync ) { { TimeSpan? spanFromPrevStart = this.callStartsByForeignTypeTimer.GetSpan( foreignId.Type, requestStart ); if ( spanFromPrevStart != null ) this.timeFromPrevStartEvents.AddEvent( foreignId.Type, spanFromPrevStart.Value, requestStart ); } { TimeSpan? callGap = this.callGapsByForeignTypeTimer.GetSpan( foreignId.Type, requestStart ); if ( callGap != null ) this.callGapEvents.AddEvent( foreignId.Type, callGap.Value, requestStart ); } { // for statistics, we don't care about specific tracker's hit interval, but rather interested in // hit intervals for a foreign type. // So despite sameFeedHitSpan is for foreignId, event is saved for foreignId.Type: TimeSpan? sameFeedHitSpan = this.sameFeedHitTimer.GetSpan( foreignId, requestStart ); if ( sameFeedHitSpan != null ) this.sameFeedHitEvents.AddEvent( foreignId.Type, sameFeedHitSpan.Value ); } this.callDurationTimer.Reset( foreignId, requestStart ); } } catch ( Exception exc ) { Log.Error( exc ); } }
internal void AddRequestEndEvent( ForeignId foreignId ) { try { lock ( this.sync ) { // recording just the fact if the event here, hence 0 as parameter: this.requestSuccessesEvents.AddEvent(foreignId.Type, 0); this.callGapsByForeignTypeTimer.Reset( foreignId.Type ); { TimeSpan? callDuration = this.callDurationTimer.GetSpan( foreignId ); // A span obtained for foreignId is being saved for foreignId.Type, // see adding event for sameFeedHitEvents for reasons why: if ( callDuration != null ) this.callDurationEvents.AddEvent( foreignId.Type, callDuration.Value ); } } } catch ( Exception exc ) { Log.Error( exc ); } }
public TrackerStateHolder( ForeignId foreignId ) { ForeignId = foreignId; }