public IEnumerable <ObjectRequest> InsertItem(IMachineInformation machineInfo, Object heldObject, IEnumerable <Item> inventory, Farmer source, out Action doInsert) { State state = machineInfo.GetState <State>(); // Check if already processing if (state.Processing) { doInsert = default; return(null); } // Check if enough stone is being held if (heldObject.ParentSheetIndex == Objects.Stone) { // If stone is actually inserted into the machine, make sure to update the state doInsert = () => { state.Processing = true; state.StartTime = SDateTime.Now; }; // Request 100 stone return(new ObjectRequest(heldObject, 100).Yield()); } // Don't request anything doInsert = default; return(null); }
/// <summary> /// Constructor /// </summary> /// <param name="request">request</param> /// <param name="machineInformation">machine information</param> /// <param name="experimentContext">experiment context</param> /// <param name="knownIpAddresses">known ip addresses</param> /// <param name="settings">GateSettings</param> public GateContext(IGatedRequest request, IMachineInformation machineInformation, IExperimentContext experimentContext, INamedIPAddresses knownIpAddresses = null, IGateSettings settings = null) { Request = request; MachineInformation = machineInformation; ExperimentContext = experimentContext; KnownIpAddresses = knownIpAddresses; m_settings = settings; }
/// <summary> /// Dispose of the timed scope /// </summary> /// <param name="disposing">Should dispose or not</param> /// <param name="machineInformation">Machine Information</param> protected virtual void Dispose(bool disposing, IMachineInformation machineInformation) { if (disposing && !IsDisposed) { IsDisposed = true; EndScope(machineInformation); } }
/// <summary> /// Constructor /// </summary> /// <param name="callContextManager">Call context manager</param> /// <param name="machineInformation">Machine information</param> public TimedScopeStackManager(ICallContextManager callContextManager, IMachineInformation machineInformation) { Code.ExpectsArgument(callContextManager, nameof(callContextManager), TaggingUtilities.ReserveTag(0x2381705f /* tag_96xb5 */)); Code.ExpectsArgument(machineInformation, nameof(machineInformation), TaggingUtilities.ReserveTag(0x23817060 /* tag_96xb6 */)); CallContextManager = callContextManager; MachineInformation = machineInformation; }
/// <summary> /// Creates a default timed scope provider. /// </summary> /// <param name="scopeLogger">Custom logger</param> /// <param name="replayEventConfigurator">Reply event configurator</param> /// <param name="machineInformation">Machine information</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> public static ITimedScopeProvider CreateTimedScopeProvider( IMachineInformation machineInformation, ITimedScopeLogger scopeLogger, IReplayEventConfigurator replayEventConfigurator, ITimedScopeStackManager timedScopeStackManager) { return(new TimedScopeProvider(new MockCorrelationDataProvider(), machineInformation, scopeLogger, replayEventConfigurator, timedScopeStackManager)); }
/// <summary> /// Constructor /// </summary> /// <param name="correlationHandler">correlation handler, used to store correlation data in underlying logging system</param> /// <param name="callContextManager">call context manager, to handle context operations</param> /// <param name="machineInformation">machine information</param> public Correlation(ICorrelationStorage correlationHandler, ICallContextManager callContextManager, IMachineInformation machineInformation) { Code.ExpectsArgument(correlationHandler, nameof(correlationHandler), TaggingUtilities.ReserveTag(0x2381771b /* tag_96x21 */)); Code.ExpectsArgument(callContextManager, nameof(callContextManager), TaggingUtilities.ReserveTag(0x2381771c /* tag_96x22 */)); Code.ExpectsArgument(machineInformation, nameof(machineInformation), TaggingUtilities.ReserveTag(0x2381771d /* tag_96x23 */)); CorrelationHandler = correlationHandler; CallContextManager = callContextManager; MachineInformation = machineInformation; }
/// <summary> /// Creates a default timed scope. /// </summary> /// <param name="scopeLogger">Custom logger</param> /// <param name="replayEventConfigurator">Reply event configurator</param> /// <param name="machineInformation">Machine information</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> /// <param name="initialResult">Initial scope result.</param> /// <param name="startScope">Start scope implicitly.</param> /// <returns>The created scope.</returns> public static TimedScope CreateDefaultTimedScope( ITimedScopeLogger scopeLogger = null, IReplayEventConfigurator replayEventConfigurator = null, IMachineInformation machineInformation = null, ITimedScopeStackManager timedScopeStackManager = null, bool?initialResult = null, bool startScope = true) { return(CreateTimedScopeProvider(machineInformation, scopeLogger, replayEventConfigurator, timedScopeStackManager) .Create(UnitTestTimedScopes.DefaultScope, TimedScope.ConvertBoolResultToTimedScopeResult(initialResult), startScope)); }
/// <summary> /// Creates a scope (and starts by default) /// </summary> /// <param name="correlationData">Correlation Data</param> /// <param name="machineInformation">Machine Information</param> /// <param name="initialResult">Initial result to use</param> /// <param name="startScope">Should the scope be automatically started (for use in e.g. 'using' statement)</param> /// <param name="customLogger">Optional custom timed scope logger</param> /// <param name="replayEventConfigurator">Optional replay event configurator</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> /// <returns>A timed scope</returns> public TimedScope Create(CorrelationData correlationData, IMachineInformation machineInformation, ITimedScopeLogger customLogger, IReplayEventConfigurator replayEventConfigurator, ITimedScopeStackManager timedScopeStackManager, TimedScopeResult initialResult = default(TimedScopeResult), bool startScope = true) { TimedScope scope = TimedScope.Create(this, correlationData, machineInformation, customLogger, replayEventConfigurator, timedScopeStackManager, initialResult); if (startScope) { scope.Start(); } return(scope); }
/// <summary> /// Creates an instance of the test counters timed scope. /// </summary> /// <param name="initialResult">Initial scope result.</param> /// <param name="startScope">Start scope implicitly</param> /// <param name="machineInformation">Machine information</param> /// <param name="scopeLogger">Custom logger</param> /// <param name="replayEventConfigurator">Replay event configurator</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> /// <returns>The created scope.</returns> public static TimedScope CreateTestCountersUnitTestTimedScope( bool?initialResult = null, bool startScope = true, IMachineInformation machineInformation = null, ITimedScopeLogger scopeLogger = null, IReplayEventConfigurator replayEventConfigurator = null, ITimedScopeStackManager timedScopeStackManager = null) { CorrelationData data = new CorrelationData(); return(UnitTestTimedScopes.TestCounters.UnitTest.Create(data, machineInformation, scopeLogger, replayEventConfigurator, timedScopeStackManager, initialResult, startScope)); }
/// <summary> /// End the timed scope explicitly /// </summary> private void EndScope(IMachineInformation machineInformation) { if (Interlocked.CompareExchange(ref m_isScopeEnded, 1, 0) == 0) { EndTick = Stopwatch.GetTimestamp(); PerfDiagnostics?.Stop(); LogEnd(machineInformation); IsScopeActive = false; } }
/// <summary> /// Create a timed scope /// </summary> /// <param name="correlation">Correlation data</param> /// <param name="machineInformation">Machine Information</param> /// <param name="customLogger">Use a custom logger for the timed scope</param> /// <param name="replayEventConfigurator">Replay event configurator</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> public TimedScopeProvider( ICorrelationDataProvider correlation, IMachineInformation machineInformation, ITimedScopeLogger customLogger, IReplayEventConfigurator replayEventConfigurator, ITimedScopeStackManager timedScopeStackManager) { m_correlation = Code.ExpectsArgument(correlation, nameof(correlation), TaggingUtilities.ReserveTag(0x2375d3d1 /* tag_933pr */)); m_machineInformation = Code.ExpectsArgument(machineInformation, nameof(machineInformation), TaggingUtilities.ReserveTag(0x2375d3d2 /* tag_933ps */)); m_scopeLogger = Code.ExpectsArgument(customLogger, nameof(customLogger), TaggingUtilities.ReserveTag(0x2375d3d3 /* tag_933pt */)); m_replayEventConfigurator = Code.ExpectsArgument(replayEventConfigurator, nameof(replayEventConfigurator), TaggingUtilities.ReserveTag(0x2375d3d4 /* tag_933pu */)); m_timedScopeStackManager = Code.ExpectsArgument(timedScopeStackManager, nameof(timedScopeStackManager), TaggingUtilities.ReserveTag(0x2375d3d5 /* tag_933pv */)); }
public IEnumerable <IEnumerable <ObjectRequest> > Accept(IMachineInformation machineInfo, IEnumerable <ObjectRequest> items, Vector2 inputTile, out MachineAction doAccept) { State state = machineInfo.GetState <State>(); // Check if already processing if (state.Processing) { doAccept = default; return(null); } // Get all available stone IEnumerable <ObjectRequest> stone = items.Where(i => i.Item.ParentSheetIndex == Objects.Stone); // Create requests for up to 100 stone List <ObjectRequest> requests = new List <ObjectRequest>(); int remaining = 100; foreach (ObjectRequest request in stone) { // Create a new request for stone if (request.Quantity <= remaining) { // Requests are structs, so it's fine to just pass it around like this requests.Add(request); remaining -= request.Quantity; } else { requests.Add(new ObjectRequest(request.Item, remaining)); remaining = 0; } // Check if reached 100 stone if (remaining == 0) { // If the machine actually accepts something, make sure to update the state of the machine doAccept = payload => { state.Processing = true; state.StartTime = SDateTime.Now; }; // Return the requested stone as a single payload return(requests.AsEnumerable().Yield()); } } // There isn't 100 stone available, so return null doAccept = default; return(null); }
/// <summary> /// Constructor /// </summary> /// <param name="scopeDefinition">Timed scope definition</param> /// <param name="scopeLogger">Scope metrics logger</param> /// <param name="replayEventConfigurator">Replay event configurator</param> /// <param name="machineInformation">Machine Information</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> /// <param name="correlationData">Correlation data</param> private TimedScope(TimedScopeDefinition scopeDefinition, CorrelationData correlationData, ITimedScopeLogger scopeLogger, IReplayEventConfigurator replayEventConfigurator, IMachineInformation machineInformation, ITimedScopeStackManager timedScopeStackManager) { Code.ExpectsArgument(scopeDefinition, nameof(scopeDefinition), TaggingUtilities.ReserveTag(0x238174da /* tag_96xt0 */)); Code.ExpectsArgument(scopeLogger, nameof(scopeLogger), TaggingUtilities.ReserveTag(0x238174db /* tag_96xt1 */)); Code.ExpectsArgument(replayEventConfigurator, nameof(replayEventConfigurator), TaggingUtilities.ReserveTag(0x238174dc /* tag_96xt2 */)); Code.ExpectsArgument(timedScopeStackManager, nameof(timedScopeStackManager), TaggingUtilities.ReserveTag(0x23817062 /* tag_96xb8 */)); ScopeDefinition = scopeDefinition; ScopeLogger = scopeLogger; ReplayEventConfigurator = replayEventConfigurator; CorrelationData = correlationData; MachineInformation = machineInformation; TimedScopeStackManager = timedScopeStackManager; }
public IEnumerable <IEnumerable <ObjectRequest> > Eject(IMachineInformation machineInfo, IEnumerable <ObjectRequest> items, Vector2 outputTile, out MachineAction doEject) { State state = machineInfo.GetState <State>(); // Check if not done if (!(state.Processing && (SDateTime.Now - state.StartTime).TotalMinutes >= 60)) { doEject = null; return(null); } // If the machine actually ejects something, make sure to update the state of the machine doEject = payload => state.Processing = false; // Return a new diamond payload return(new ObjectRequest(new Object(Vector2.Zero, Objects.Diamond, 1)).Yield().Yield()); }
/// <summary> /// Logs the scope end to ULS /// </summary> private void LogEnd(IMachineInformation machineInformation) { if (!IsSuccessful.HasValue) { ULSLogging.LogTraceTag(0x238174e3 /* tag_96xt9 */, Categories.TimingGeneral, Levels.Warning, "Result not set for scope {0}. Considered as SystemError", Name); Result = TimedScopeResult.SystemError; FailureDescription = InternalFailureDescription.UnknownResultAsSystemError; } CorrelationData scopeData = ConstructCorrelationDataEntries(machineInformation); ScopeLogger.LogScopeEnd(this, scopeData); ReplayEventConfigurator.ConfigureReplayEventsOnScopeEnd(this); }
public IEnumerable <ObjectRequest> RemoveItem(IMachineInformation machineInfo, Farmer source, out Action doRemove) { State state = machineInfo.GetState <State>(); // Check if done int elapsedMinutes = (SDateTime.Now - state.StartTime).TotalMinutes; if (state.Processing && elapsedMinutes >= 60) { // When the payload is removed from this machine, update the state doRemove = () => state.Processing = false; // Return a single diamond payload that this machine can provide return(new ObjectRequest(new Object(Vector2.Zero, Objects.Diamond, 1)).Yield()); } // If the machine actually ejects something, make sure to update the state of the machine doRemove = default; return(null); }
/// <summary> /// Current call context /// </summary> public ICallContext CallContextHandler(IMachineInformation machineInformation) { return(CallContextOverride ?? new HttpCallContext(useLogicalCallContext: false, machineInformation: machineInformation)); }
/// <summary> /// The call context /// Depending on the 'UseLogicalCallContext' app setting it will either use classic - OperationCallContext -> ThreadCallContext chain /// or the new LogicalCallContext as backup /// </summary> private Lazy <ICallContext> s_callContext(IMachineInformation machineInformation) { return(new Lazy <ICallContext>(() => new HttpCallContext(useLogicalCallContext: false, machineInformation: machineInformation), LazyThreadSafetyMode.PublicationOnly)); }
/// <summary> /// Create a timed scope /// </summary> /// <param name="scopeDefinition">Timed scope definition</param> /// <param name="initialResult">The default result for the scope</param> /// <param name="customLogger">Use a custom logger for the timed scope</param> /// <param name="replayEventConfigurator">Replay event configurator</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> /// <param name="correlationData">Correlation data</param> /// <param name="machineInformation">Machine Information</param> /// <returns>Newly created scope</returns> public static TimedScope Create(TimedScopeDefinition scopeDefinition, CorrelationData correlationData, IMachineInformation machineInformation, ITimedScopeLogger customLogger, IReplayEventConfigurator replayEventConfigurator, ITimedScopeStackManager timedScopeStackManager, TimedScopeResult initialResult = default(TimedScopeResult)) { return(new TimedScope(scopeDefinition, correlationData, customLogger, replayEventConfigurator, machineInformation, timedScopeStackManager) { TimedScopeData = correlationData, RunningTransaction = TransactionMonitor.RunningTransaction(correlationData), Result = initialResult, }); }
public void AfterDraw(IMachineInformation machineInformation, SpriteBatch spriteBatch, int x, int y) { }
/// <summary> Context data stored on LogicalCallContext </summary> public LogicalCallContext(IMachineInformation machineInformation) { MachineInformation = machineInformation; }
/// <summary> /// Constructor /// </summary> /// <param name="eventSource">The event source for timed scopes</param> /// <param name="machineInformation">Machine information</param> public CustomActivityTimedScopeLogger(TimedScopeEventSource eventSource, IMachineInformation machineInformation) { m_eventSource = Code.ExpectsArgument(eventSource, nameof(eventSource), TaggingUtilities.ReserveTag(0x2375d3d6 /* tag_933pw */)); m_machineInformation = Code.ExpectsArgument(machineInformation, nameof(machineInformation), TaggingUtilities.ReserveTag(0x2375d3d7 /* tag_933px */)); }
/// <summary> /// Deprecated - Start a timed scope /// </summary> /// <remarks>Please use TimedScopeDefinition for creating timed scopes</remarks> /// <param name="correlationData">Correlation data</param> /// <param name="machineInformation">Machine Information</param> /// <param name="scopeName">The name of the timed scope</param> /// <param name="customLogger">Use a custom logger for the timed scope</param> /// <param name="replayEventConfigurator">Replay event configurator</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> /// <param name="initialResult">The default result for the scope</param> /// <returns>Newly created scope</returns> public static TimedScope Start(CorrelationData correlationData, IMachineInformation machineInformation, string scopeName, ITimedScopeLogger customLogger, IReplayEventConfigurator replayEventConfigurator, ITimedScopeStackManager timedScopeStackManager, bool?initialResult) => new TimedScopeDefinition(scopeName).Start(correlationData, machineInformation, customLogger, replayEventConfigurator, timedScopeStackManager, ConvertBoolResultToTimedScopeResult(initialResult));
/// <summary> /// Constructs the timed scope correlation data /// </summary> /// <returns>Correlation data</returns> private CorrelationData ConstructCorrelationDataEntries(IMachineInformation machineInformation) { CorrelationData correlationData = TimedScopeData; CorrelationData scopeData = TimedScopeData.Clone(); scopeData.AddData(TimedScopeDataKeys.InternalOnly.ScopeName, Name); scopeData.AddData(TimedScopeDataKeys.InternalOnly.InstanceId, InstanceId.ToString()); scopeData.AddData(TimedScopeDataKeys.InternalOnly.IsSuccessful, IsSuccessful.HasValue ? IsSuccessful.Value.ToString() : bool.FalseString); scopeData.AddData(TimedScopeDataKeys.InternalOnly.IsRoot, IsRoot.ToString()); scopeData.AddData(TimedScopeDataKeys.InternalOnly.ScopeResult, Result.ToString()); bool isFailed = !IsSuccessful ?? false; if (isFailed && FailureDescription != null) { scopeData.AddData(TimedScopeDataKeys.InternalOnly.FailureDescription, FailureDescription.ToString()); } scopeData.AddData(TimedScopeDataKeys.InternalOnly.Duration, DurationInMilliseconds.ToString(CultureInfo.InvariantCulture)); long sequenceNumber = correlationData == null ? 0 : correlationData.NextEventSequenceNumber(); scopeData.AddData(TimedScopeDataKeys.InternalOnly.SequenceNumber, sequenceNumber.ToString(CultureInfo.InvariantCulture)); scopeData.AddData(TimedScopeDataKeys.InternalOnly.CallDepth, correlationData == null ? "0" : correlationData.CallDepth.ToString(CultureInfo.InvariantCulture)); IMachineInformation machineInfo = machineInformation; if (machineInfo != null) { scopeData.AddData(TimedScopeDataKeys.InternalOnly.MachineId, machineInfo.MachineId); scopeData.AddData(TimedScopeDataKeys.InternalOnly.MachineCluster, machineInfo.MachineCluster); scopeData.AddData(TimedScopeDataKeys.InternalOnly.MachineRole, machineInfo.MachineRole); scopeData.AddData(TimedScopeDataKeys.InternalOnly.AgentName, machineInfo.AgentName); } // if the user hash has been set, add it to the scope data if (!string.IsNullOrWhiteSpace(m_userHashOverride)) { ULSLogging.LogTraceTag(0x23817500 /* tag_96xua */, Categories.TimingGeneral, Levels.Verbose, "Overriding user hash metadata in the Timed Scope '{0}' with value '{1}'", Name, m_userHashOverride); scopeData.AddData(TimedScopeDataKeys.InternalOnly.UserHash, m_userHashOverride); } else if (correlationData != null && !string.IsNullOrWhiteSpace(correlationData.UserHash)) { scopeData.AddData(TimedScopeDataKeys.InternalOnly.UserHash, correlationData.UserHash); } // capture performance metrics if (PerfDiagnostics != null && PerfDiagnostics.LastStatus) { scopeData.AddData(TimedScopeDataKeys.InternalOnly.CpuCycles, PerfDiagnostics.CyclesUsed.ToString(CultureInfo.InvariantCulture)); scopeData.AddData(TimedScopeDataKeys.InternalOnly.UserModeDuration, PerfDiagnostics.UserModeMilliseconds.ToString(CultureInfo.InvariantCulture)); scopeData.AddData(TimedScopeDataKeys.InternalOnly.KernelModeDuration, PerfDiagnostics.KernelModeMilliseconds.ToString(CultureInfo.InvariantCulture)); scopeData.AddData(TimedScopeDataKeys.InternalOnly.HttpRequestCount, PerfDiagnostics.HttpRequestCount.ToString(CultureInfo.InvariantCulture)); scopeData.AddData(TimedScopeDataKeys.InternalOnly.ServiceCallCount, PerfDiagnostics.ServiceCallCount.ToString(CultureInfo.InvariantCulture)); } return(scopeData); }
/// <summary> /// Deprecated - Create a timed scope /// </summary> /// <remarks>Please use TimedScopeDefinition for creating timed scopes</remarks> /// <param name="correlationData">Correlation data</param> /// <param name="machineInformation">Machine Information</param> /// <param name="scopeName">The name of the timed scope</param> /// <param name="initialResult">The default result for the scope</param> /// <param name="customLogger">Use a custom logger for the timed scope</param> /// <param name="replayEventConfigurator">Replay event configurator</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> /// <returns>newly created scope</returns> public static TimedScope Create(CorrelationData correlationData, IMachineInformation machineInformation, string scopeName, ITimedScopeLogger customLogger, IReplayEventConfigurator replayEventConfigurator, ITimedScopeStackManager timedScopeStackManager, bool?initialResult = null) => new TimedScopeDefinition(scopeName).Create(correlationData, machineInformation, customLogger, replayEventConfigurator, timedScopeStackManager, initialResult: initialResult, startScope: false);
public void UpdateTick(IMachineInformation machineInfo) { }
/// <summary> /// Deprecated - Start a timed scope /// </summary> /// <remarks>Please use TimedScopeDefinition for creating timed scopes</remarks> /// <param name="correlationData">Correlation Data</param> /// <param name="machineInformation">Machine Information</param> /// <param name="scopeName">The name of the timed scope</param> /// <param name="description">The description of the timed scope</param> /// <param name="initialResult">The default result for the scope</param> /// <param name="customLogger">Use a custom logger for the timed scope</param> /// <param name="replayEventConfigurator">Replay event configurator</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> /// <returns>Newly created scope</returns> public static TimedScope Start(CorrelationData correlationData, IMachineInformation machineInformation, string scopeName, string description, ITimedScopeLogger customLogger, IReplayEventConfigurator replayEventConfigurator, ITimedScopeStackManager timedScopeStackManager, TimedScopeResult initialResult = default(TimedScopeResult)) => new TimedScopeDefinition(scopeName, description).Start(correlationData, machineInformation, customLogger, replayEventConfigurator, timedScopeStackManager, initialResult);
public void Placed(IMachineInformation machineInfo) { machineInfo.SetState(new State()); }
/// <summary> /// Deprecated - Create a timed scope /// </summary> /// <remarks>Please use TimedScopeDefinition for creating timed scopes</remarks> /// <param name="correlationData">Correlation data</param> /// <param name="machineInformation">Machine Information</param> /// <param name="scopeName">The name of the timed scope</param> /// <param name="description">The description of the timed scope</param> /// <param name="customLogger">Use a custom logger for the timed scope</param> /// <param name="replayEventConfigurator">Replay event configurator</param> /// <param name="timedScopeStackManager">Timed scope stack manager</param> /// <param name="initialResult">The default result for the scope</param> /// <returns>Newly created scope</returns> public static TimedScope Create(CorrelationData correlationData, IMachineInformation machineInformation, string scopeName, string description, ITimedScopeLogger customLogger, IReplayEventConfigurator replayEventConfigurator, ITimedScopeStackManager timedScopeStackManager, bool?initialResult) => new TimedScopeDefinition(scopeName, description).Create(correlationData, machineInformation, customLogger, replayEventConfigurator, timedScopeStackManager, initialResult: ConvertBoolResultToTimedScopeResult(initialResult), startScope: false);
public void Removed(IMachineInformation machineInfo) { }
internal Information(IApplicationInformation application, IMachineInformation machine, IUserInformation user) { Application = application; Machine = machine; User = user; }