public Stage(string name, UInt32 score, StateLock _lock, StateSelect select) { Name = name; Score = score; Lock = _lock; Select = select; }
public Ship(string name, StateLock _lock, StateSelect select, int cost) { Name = name; Lock = _lock; Select = select; Cost = cost; }
private void ValidateStateLocks() { IEnumerable <Tuple <StateLock, bool> > stateLocks = this.ReplicableMethodInfo.TestStateLocks; int numberOfReadLocks = 0; int numberOfWriteLocks = 0; if (stateLocks != null) { foreach (Tuple <StateLock, bool> lockTuple in stateLocks) { StateLock stateLock = lockTuple.Item1; bool isWriteLock = lockTuple.Item2; if (isWriteLock == false) { Assert.IsTrue(stateLock.TestNumberOfReaders >= 1, "No readers found"); Assert.AreEqual(0, stateLock.TestNumberOfWaitingReaders, "Unexpected number of waiting readers"); numberOfReadLocks++; } else { Assert.IsTrue(stateLock.TestIsWriterLockHeld, "Writer lock not held"); Assert.AreEqual(0, stateLock.TestNumberOfWaitingWriters, "Unexpected number of waiting writers"); numberOfWriteLocks++; } } } Assert.AreEqual(this.NumberOfExpectedReadLocks, numberOfReadLocks, "Unexpected number of read locks"); Assert.AreEqual(this.NumberOfExpectedWriteLocks, numberOfWriteLocks, "Unexpected number of write locks"); }
/// <summary> /// Flush the cache. /// </summary> public void Flush() { using (StateLock.Lock()) { Assemblies.Clear(); IsDirty = true; } }
/// <summary> /// Load cache state from the specified file. /// </summary> /// <param name="cacheFile"> /// The file containing persisted cache state. /// </param> public void Load(string cacheFile) { if (String.IsNullOrWhiteSpace(cacheFile)) { throw new ArgumentException("Argument cannot be null, empty, or entirely composed of whitespace: 'cacheFile'.", nameof(cacheFile)); } using (StateLock.Lock()) { Assemblies.Clear(); using (StreamReader input = File.OpenText(cacheFile)) using (JsonTextReader json = new JsonTextReader(input)) { JsonSerializer.Create(SerializerSettings).Populate(json, this); } IsDirty = false; } }
/// <summary> /// Write cache state to the specified file. /// </summary> /// <param name="cacheFile"> /// The file that will contain cache state. /// </param> public void Save(string cacheFile) { if (String.IsNullOrWhiteSpace(cacheFile)) { throw new ArgumentException("Argument cannot be null, empty, or entirely composed of whitespace: 'cacheFile'.", nameof(cacheFile)); } using (StateLock.Lock()) { if (File.Exists(cacheFile)) { File.Delete(cacheFile); } using (StreamWriter output = File.CreateText(cacheFile)) using (JsonTextWriter json = new JsonTextWriter(output)) { JsonSerializer.Create(SerializerSettings).Serialize(json, this); } IsDirty = false; } }
/// <summary> /// Get metadata for the specified task assembly, updating the cache if required. /// </summary> /// <param name="assemblyPath"> /// The full path to the assembly. /// </param> /// <returns> /// The assembly metadata. /// </returns> public async Task <MSBuildTaskAssemblyMetadata> GetAssemblyMetadata(string assemblyPath) { if (String.IsNullOrWhiteSpace(assemblyPath)) { throw new ArgumentException("Argument cannot be null, empty, or entirely composed of whitespace: 'assemblyPath'.", nameof(assemblyPath)); } MSBuildTaskAssemblyMetadata metadata; using (await StateLock.LockAsync()) { FileInfo assemblyFile = new FileInfo(assemblyPath); if (!Assemblies.TryGetValue(assemblyPath, out metadata) || metadata.TimestampUtc < assemblyFile.LastWriteTimeUtc) { metadata = await MSBuildTaskScanner.GetAssemblyTaskMetadata(assemblyPath); Assemblies[metadata.AssemblyPath] = metadata; IsDirty = true; } } return(metadata); }
public void RecordTaskActionHandler(RecordTaskAction message) { var workflowId = message.WorkflowInstanceId; var tenantId = message.TenantId; var auditContext = message.AuditContext; var objId = message.TargetObjectId; var objType = message.TargetObjectType; var taskEvent = message.Event; var task = message.State + "|" + message.Task; var state = message.State; var workflowName = message.WorkflowTemplateName; var stateNameForLock = (string.IsNullOrEmpty(state) ? message.StateId.ToString() : state); var stateLock = new StateLock() { WorkflowInstanceId = workflowId, WorkflowInstanceTenantId = tenantId, StateName = stateNameForLock, }; while (lockedStates.Exists(x => x.WorkflowInstanceId == workflowId && x.StateName == stateNameForLock && x.WorkflowInstanceTenantId == tenantId)) { System.Threading.Thread.Sleep(100); } lockedStates.Add(stateLock); try { //System.Console.WriteLine("Event Received : " + taskEvent); WorkflowInstance data = null; using (var dataContext = new DataContext(message.TenantId, auditContext)) { try { data = Utils.GetWorkflowInstance(dataContext, workflowId, objId, objType); if (data == null) { return; } var stateData = data.States.Where(x => (x.Id == message.StateId)).FirstOrDefault(); if (stateData == null) { stateData = data.States.Where(x => (x.StateTemplate.StateName == message.State)).OrderByDescending(x => x.Id).FirstOrDefault(); if (stateData == null) { return; } } var taskData = stateData.Tasks.Where(x => (x.Id == message.TaskId)).FirstOrDefault(); if (taskData == null) { taskData = stateData.Tasks.Where(x => (x.TaskTemplate.TaskName == task)).OrderByDescending(x => x.Id).FirstOrDefault(); if (taskData == null) { return; } } var eventData = data.WorkflowTemplate.EventsTypes.FirstOrDefault(x => x.ParentName == taskData.TaskTemplate.TaskName && x.Event == taskEvent && x.Type == EventType.EventLevel.TASK); if (eventData == null) { return; } var workflowEvent = new WorkflowEvent() { EventDate = DateTime.UtcNow, EventMetaData = null, EventType = eventData, ExecutedBy = auditContext, TaskParent = taskData, WorkflowInstance = data, }; data.Events.Add(workflowEvent); if (data.CurrentState.Id == stateData.Id && taskData.IsCurrentTask == true) { TaskTemplate nextTaskTemplate = stateData.StateTemplate.Tasks.FirstOrDefault(x => x.TaskName == eventData.MoveTo); if (nextTaskTemplate == null) { return; } taskData.IsCurrentTask = false; PocketBoss.Models.Task newTask = new Models.Task() { TaskTemplate = nextTaskTemplate, IsCurrentTask = true, LastTask = nextTaskTemplate.LastTask, State = stateData, WorkflowInstance = data, TransitionDate = DateTime.UtcNow, TransitionedBy = auditContext, TransitionEvent = workflowEvent, }; stateData.Tasks.Add(newTask); dataContext.SaveChanges(); publishNewTasks(data, newTask, message.AuditContext, message.TenantId, _bus); } } catch (Exception exc) { } } using (var dataContext = new DataContext(message.TenantId, auditContext)) { if (dataContext.Tasks.Count(x => x.LastTask == false && x.IsCurrentTask == true && x.State.IsCurrent == true && x.WorkflowInstanceId == data.Id) == 0) { updateStateAsComplete(data, message.AuditContext, message.TenantId, _bus); } } } catch (Exception exc) { } finally { lockedStates.Remove(stateLock); } }