/// <summary> /// Initializes a new instance. /// </summary> /// <param name="model">The model the successors are computed for.</param> /// <param name="capacity">The maximum number of successors that can be cached.</param> /// <param name="formulas">The formulas that should be checked for all successor states.</param> public ActivationMinimalTransitionSetBuilder(RuntimeModel model, long capacity, params Func<bool>[] formulas) { Requires.NotNull(model, nameof(model)); Requires.NotNull(formulas, nameof(formulas)); Requires.That(formulas.Length < 32, "At most 32 formulas are supported."); Requires.That(capacity <= (1 << 30), nameof(capacity), $"Maximum supported capacity is {1 << 30}."); _stateVectorSize = model.StateVectorSize; _formulas = formulas; _transitionBuffer.Resize(capacity * sizeof(CandidateTransition), zeroMemory: false); _transitions = (CandidateTransition*)_transitionBuffer.Pointer; _targetStateBuffer.Resize(capacity * model.StateVectorSize, zeroMemory: true); _targetStateMemory = _targetStateBuffer.Pointer; _lookupBuffer.Resize(capacity * sizeof(int), zeroMemory: false); _faultsBuffer.Resize(capacity * sizeof(FaultSetInfo), zeroMemory: false); _hashedStateBuffer.Resize(capacity * _stateVectorSize, zeroMemory: false); _successors = new List<uint>(); _capacity = capacity; _lookup = (int*)_lookupBuffer.Pointer; _faults = (FaultSetInfo*)_faultsBuffer.Pointer; _hashedStateMemory = _hashedStateBuffer.Pointer; for (var i = 0; i < capacity; ++i) _lookup[i] = -1; }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="model">The model that should be simulated.</param> /// <param name="formulas">The formulas that can be evaluated on the model.</param> public Simulator(ModelBase model, params Formula[] formulas) { Requires.NotNull(model, nameof(model)); Requires.NotNull(formulas, nameof(formulas)); _runtimeModel = RuntimeModel.Create(model, formulas); Reset(); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="counterExample">The counter example that should be simulated.</param> public Simulator(CounterExample counterExample) { Requires.NotNull(counterExample, nameof(counterExample)); _counterExample = counterExample; _runtimeModel = counterExample.RuntimeModel; Reset(); }
/// <summary> /// Disposes the object, releasing all managed and unmanaged resources. /// </summary> /// <param name="disposing">If true, indicates that the object is disposed; otherwise, the object is finalized.</param> protected override void OnDisposing(bool disposing) { if (!disposing) { return; } ChoiceResolver.SafeDispose(); TemporaryStateStorage.SafeDispose(); RuntimeModel.SafeDispose(); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="runtimeModelCreator">A factory function that creates the model instance that should be executed.</param> /// <param name="formulas">The formulas that should be evaluated for each state.</param> /// <param name="successorStateCapacity">The maximum number of successor states supported per state.</param> /// <param name="stateHeaderBytes"> /// The number of bytes that should be reserved at the beginning of each state vector for the model checker tool. /// </param> internal ActivationMinimalExecutedModel(CoupledExecutableModelCreator <TExecutableModel> runtimeModelCreator, int stateHeaderBytes, Func <bool>[] formulas, long successorStateCapacity) : base(runtimeModelCreator, stateHeaderBytes) { formulas = formulas ?? RuntimeModel.Formulas.Select(formula => FormulaCompilationVisitor <TExecutableModel> .Compile(RuntimeModel, formula)).ToArray(); _transitions = new ActivationMinimalTransitionSetBuilder <TExecutableModel>(RuntimeModel, successorStateCapacity, formulas); _stateConstraints = RuntimeModel.StateConstraints; ChoiceResolver = new NondeterministicChoiceResolver(); RuntimeModel.SetChoiceResolver(ChoiceResolver); }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "Anf.ChannelModel.Entity.AnfRole", typeof(AnfRole), baseEntityType); var id = runtimeEntityType.AddProperty( "Id", typeof(long), propertyInfo: typeof(IdentityRole <long>).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityRole <long>).GetField("<Id>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var concurrencyStamp = runtimeEntityType.AddProperty( "ConcurrencyStamp", typeof(string), propertyInfo: typeof(IdentityRole <long>).GetProperty("ConcurrencyStamp", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityRole <long>).GetField("<ConcurrencyStamp>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true, concurrencyToken: true); var name = runtimeEntityType.AddProperty( "Name", typeof(string), propertyInfo: typeof(IdentityRole <long>).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityRole <long>).GetField("<Name>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true, maxLength: 256); var normalizedName = runtimeEntityType.AddProperty( "NormalizedName", typeof(string), propertyInfo: typeof(IdentityRole <long>).GetProperty("NormalizedName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityRole <long>).GetField("<NormalizedName>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true, maxLength: 256); var key = runtimeEntityType.AddKey( new[] { id }); runtimeEntityType.SetPrimaryKey(key); var index = runtimeEntityType.AddIndex( new[] { normalizedName }, unique: true); index.AddAnnotation("Relational:Name", "RoleNameIndex"); return(runtimeEntityType); }
/// <summary> /// Initializes a new instance. /// </summary> public Worker(int index, InvariantChecker context, StateStack stateStack, Func <RuntimeModel> createModel, int successorCapacity) { _index = index; _context = context; _createModel = createModel; _model = _createModel(); _stateStack = stateStack; var invariant = CompilationVisitor.Compile(_model.Formulas[0]); _transitions = new TransitionSet(_model, successorCapacity, invariant); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="runtimeModel">The runtime model the counter example was generated for.</param> /// <param name="states">The serialized counter example.</param> /// <param name="replayInfo">The replay information of the counter example.</param> /// <param name="endsWithException">Indicates whether the counter example ends with an exception.</param> internal CounterExample(RuntimeModel runtimeModel, byte[][] states, int[][] replayInfo, bool endsWithException) { Requires.NotNull(runtimeModel, nameof(runtimeModel)); Requires.NotNull(states, nameof(states)); Requires.NotNull(replayInfo, nameof(replayInfo)); Requires.That(replayInfo.Length == states.Length - 1, "Invalid replay info."); RuntimeModel = runtimeModel; EndsWithException = endsWithException; _states = states; _replayInfo = replayInfo; }
protected override void ProcessModelAnnotations( Dictionary <string, object?> annotations, IModel model, RuntimeModel runtimeModel, bool runtime) { base.ProcessModelAnnotations(annotations, model, runtimeModel, runtime); if (!runtime) { annotations.Remove(CosmosAnnotationNames.Throughput); } }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="runtimeModelCreator">A factory function that creates the model instance that should be executed.</param> /// <param name="successorStateCapacity">The maximum number of successor states supported per state.</param> /// <param name="stateHeaderBytes"> /// The number of bytes that should be reserved at the beginning of each state vector for the model checker tool. /// </param> internal LtmdpExecutedModel(CoupledExecutableModelCreator <TExecutableModel> runtimeModelCreator, int stateHeaderBytes, long successorStateCapacity) : base(runtimeModelCreator, stateHeaderBytes) { var formulas = RuntimeModel.Formulas.Select(formula => FormulaCompilationVisitor <TExecutableModel> .Compile(RuntimeModel, formula)).ToArray(); _stepGraph = new LtmdpStepGraph(); _cachedLabeledStates = new LtmdpCachedLabeledStates <TExecutableModel>(RuntimeModel, successorStateCapacity, _stepGraph, formulas); _ltmdpChoiceResolver = new LtmdpChoiceResolver(_stepGraph); ChoiceResolver = _ltmdpChoiceResolver; RuntimeModel.SetChoiceResolver(ChoiceResolver); }
public void WithDomainObjectResolverTest() { var resolver = new Mock <IDomainObjectResolver>(); var eventStore = new Mock <IEventStore>(); resolver.Setup(x => x.New <Location>()).Returns(new Location()).Verifiable(); var domainModel = new RuntimeModel(new BoundedContextModel().WithCommandHandler <MoveIn, Location, MovedIn>().WithDomainObjectResolver(resolver.Object), eventStore.Object); domainModel.Aggregates.RetrieveById <Location>(string.Empty); resolver.VerifyAll(); }
void FillRuntimesForProject(List<RuntimeModel> list, SolutionItem project, ref int runtimes) { ExecutionTarget previous = null; foreach (var target in configurationMergers [project].GetTargetsForConfiguration (IdeApp.Workspace.ActiveConfigurationId, configurationMergers.Count < 2)) { if (target is ExecutionTargetGroup) { var devices = (ExecutionTargetGroup)target; if (previous != null) list.Add (new RuntimeModel (this, displayText: null));//Seperator list.Add (new RuntimeModel (this, target, true, project)); foreach (var device in devices) { if (device is ExecutionTargetGroup) { var versions = (ExecutionTargetGroup)device; if (versions.Count > 1) { var parent = new RuntimeModel (this, device, true, project) { IsIndented = true, }; list.Add (parent); foreach (var version in versions) { parent.AddChild (new RuntimeModel (this, version, false, project)); runtimes++; } } else { list.Add (new RuntimeModel (this, versions [0], true, project) { IsIndented = true, }); runtimes++; } } else { list.Add (new RuntimeModel (this, device, true, project) { IsIndented = true, }); runtimes++; } } } else { if (previous is ExecutionTargetGroup) { list.Add (new RuntimeModel (this, displayText: null));//Seperator } list.Add (new RuntimeModel (this, target, true, project)); runtimes++; } previous = target; } }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "Anf.ChannelModel.Entity.AnfSearchStatistic", typeof(AnfSearchStatistic), baseEntityType); var id = runtimeEntityType.AddProperty( "Id", typeof(ulong), propertyInfo: typeof(AnfStatistic).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(AnfStatistic).GetField("<Id>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var content = runtimeEntityType.AddProperty( "Content", typeof(string), propertyInfo: typeof(AnfSearchStatistic).GetProperty("Content", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(AnfSearchStatistic).GetField("<Content>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), maxLength: 250); var count = runtimeEntityType.AddProperty( "Count", typeof(long), propertyInfo: typeof(AnfStatistic).GetProperty("Count", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(AnfStatistic).GetField("<Count>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var time = runtimeEntityType.AddProperty( "Time", typeof(DateTime), propertyInfo: typeof(AnfStatistic).GetProperty("Time", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(AnfStatistic).GetField("<Time>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var type = runtimeEntityType.AddProperty( "Type", typeof(StatisticLevels), propertyInfo: typeof(AnfStatistic).GetProperty("Type", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(AnfStatistic).GetField("<Type>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var key = runtimeEntityType.AddKey( new[] { id }); runtimeEntityType.SetPrimaryKey(key); var index = runtimeEntityType.AddIndex( new[] { content }); return(runtimeEntityType); }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "BlazingPizza.NotificationSubscription", typeof(NotificationSubscription), baseEntityType); var notificationSubscriptionId = runtimeEntityType.AddProperty( "NotificationSubscriptionId", typeof(int), propertyInfo: typeof(NotificationSubscription).GetProperty("NotificationSubscriptionId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(NotificationSubscription).GetField("<NotificationSubscriptionId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var auth = runtimeEntityType.AddProperty( "Auth", typeof(string), propertyInfo: typeof(NotificationSubscription).GetProperty("Auth", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(NotificationSubscription).GetField("<Auth>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var p256dh = runtimeEntityType.AddProperty( "P256dh", typeof(string), propertyInfo: typeof(NotificationSubscription).GetProperty("P256dh", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(NotificationSubscription).GetField("<P256dh>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var url = runtimeEntityType.AddProperty( "Url", typeof(string), propertyInfo: typeof(NotificationSubscription).GetProperty("Url", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(NotificationSubscription).GetField("<Url>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var userId = runtimeEntityType.AddProperty( "UserId", typeof(string), propertyInfo: typeof(NotificationSubscription).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(NotificationSubscription).GetField("<UserId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var key = runtimeEntityType.AddKey( new[] { notificationSubscriptionId }); runtimeEntityType.SetPrimaryKey(key); return(runtimeEntityType); }
/// <summary> /// Executes an initial transition of the model. /// </summary> protected override void ExecuteInitialTransition() { //TODO: _resetRewards(); foreach (var fault in RuntimeModel.NondeterministicFaults) { fault.Reset(); } var savedActivations = RuntimeModel.NondeterministicFaults.ToDictionary(fault => fault, fault => fault.Activation); if (!_allowFaultsOnInitialTransitions) { foreach (var fault in RuntimeModel.NondeterministicFaults) { fault.Activation = Activation.Suppressed; } } if (_activateIndependentFaultsAtStepBeginning) { // Note: Faults get activated and their effects occur, but they are not notified yet of their activation. foreach (var fault in RuntimeModel.NondeterministicFaults) { fault.TryActivate(); } } RuntimeModel.ExecuteInitialStep(); if (!_activateIndependentFaultsAtStepBeginning) { // force activation of non-transient faults foreach (var fault in RuntimeModel.NondeterministicFaults) { if (!(fault is Modeling.TransientFault)) { fault.TryActivate(); } } } if (!_allowFaultsOnInitialTransitions) { foreach (var fault in RuntimeModel.NondeterministicFaults) { fault.Activation = savedActivations[fault]; } } }
protected override void ProcessModelAnnotations( Dictionary <string, object?> annotations, IModel model, RuntimeModel runtimeModel, bool runtime) { base.ProcessModelAnnotations(annotations, model, runtimeModel, runtime); if (!runtime) { annotations.Remove(SqlServerAnnotationNames.IdentityIncrement); annotations.Remove(SqlServerAnnotationNames.IdentitySeed); annotations.Remove(SqlServerAnnotationNames.MaxDatabaseSize); annotations.Remove(SqlServerAnnotationNames.PerformanceLevelSql); annotations.Remove(SqlServerAnnotationNames.ServiceTierSql); } }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "OpenBudget.Model.Entities.PayeeSnapshot", typeof(PayeeSnapshot), baseEntityType); var entityID = runtimeEntityType.AddProperty( "EntityID", typeof(string), propertyInfo: typeof(EntitySnapshot).GetProperty("EntityID", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(EntitySnapshot).GetField("<EntityID>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), afterSaveBehavior: PropertySaveBehavior.Throw); var isDeleted = runtimeEntityType.AddProperty( "IsDeleted", typeof(bool), propertyInfo: typeof(EntitySnapshot).GetProperty("IsDeleted", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(EntitySnapshot).GetField("<IsDeleted>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var lastEventID = runtimeEntityType.AddProperty( "LastEventID", typeof(string), propertyInfo: typeof(EntitySnapshot).GetProperty("LastEventID", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(EntitySnapshot).GetField("<LastEventID>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var lastEventVector = runtimeEntityType.AddProperty( "LastEventVector", typeof(VectorClock), propertyInfo: typeof(EntitySnapshot).GetProperty("LastEventVector", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(EntitySnapshot).GetField("<LastEventVector>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true, valueConverter: new VectorClockConverter()); var name = runtimeEntityType.AddProperty( "Name", typeof(string), propertyInfo: typeof(PayeeSnapshot).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(PayeeSnapshot).GetField("<Name>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var key = runtimeEntityType.AddKey( new[] { entityID }); runtimeEntityType.SetPrimaryKey(key); return(runtimeEntityType); }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "BlazingPizza.PizzaSpecial", typeof(PizzaSpecial), baseEntityType); var id = runtimeEntityType.AddProperty( "Id", typeof(int), propertyInfo: typeof(PizzaSpecial).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(PizzaSpecial).GetField("<Id>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var basePrice = runtimeEntityType.AddProperty( "BasePrice", typeof(decimal), propertyInfo: typeof(PizzaSpecial).GetProperty("BasePrice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(PizzaSpecial).GetField("<BasePrice>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var description = runtimeEntityType.AddProperty( "Description", typeof(string), propertyInfo: typeof(PizzaSpecial).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(PizzaSpecial).GetField("<Description>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var imageUrl = runtimeEntityType.AddProperty( "ImageUrl", typeof(string), propertyInfo: typeof(PizzaSpecial).GetProperty("ImageUrl", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(PizzaSpecial).GetField("<ImageUrl>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var name = runtimeEntityType.AddProperty( "Name", typeof(string), propertyInfo: typeof(PizzaSpecial).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(PizzaSpecial).GetField("<Name>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var key = runtimeEntityType.AddKey( new[] { id }); runtimeEntityType.SetPrimaryKey(key); return(runtimeEntityType); }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "Anf.ChannelModel.Entity.AnfComicVisit", typeof(AnfVisitCount), baseEntityType); var id = runtimeEntityType.AddProperty( "Id", typeof(ulong), propertyInfo: typeof(AnfCount).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(AnfCount).GetField("<Id>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var address = runtimeEntityType.AddProperty( "Address", typeof(string), propertyInfo: typeof(AnfVisitCount).GetProperty("Address", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(AnfVisitCount).GetField("<Address>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), maxLength: 512); var iP = runtimeEntityType.AddProperty( "IP", typeof(string), propertyInfo: typeof(AnfCount).GetProperty("IP", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(AnfCount).GetField("<IP>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true, maxLength: 36); var time = runtimeEntityType.AddProperty( "Time", typeof(DateTime), propertyInfo: typeof(AnfCount).GetProperty("Time", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(AnfCount).GetField("<Time>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var key = runtimeEntityType.AddKey( new[] { id }); runtimeEntityType.SetPrimaryKey(key); var index = runtimeEntityType.AddIndex( new[] { address }); var index0 = runtimeEntityType.AddIndex( new[] { time }); return(runtimeEntityType); }
/// <summary> /// Gets all transitions towards successor states of <paramref name="state" />. /// </summary> /// <param name="state">The state the successors should be returned for.</param> public override TransitionCollection GetSuccessorTransitions(byte *state) { BeginExecution(); ChoiceResolver.PrepareNextState(); while (ChoiceResolver.PrepareNextPath()) { RuntimeModel.Deserialize(state); ExecuteTransition(); GenerateTransition(); } return(EndExecution()); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="runtimeModelCreator">A factory function that creates the model instance that should be executed.</param> /// <param name="configuration">The analysis configuration that should be used.</param> internal LtmcExecutedModel(CoupledExecutableModelCreator <TExecutableModel> runtimeModelCreator, AnalysisConfiguration configuration) : base(runtimeModelCreator, 0, configuration) { var formulas = RuntimeModel.Formulas.Select(formula => FormulaCompilationVisitor <TExecutableModel> .Compile(RuntimeModel, formula)).ToArray(); _transitions = new LtmcTransitionSetBuilder <TExecutableModel>(TemporaryStateStorage, configuration.SuccessorCapacity, formulas); var useForwardOptimization = configuration.EnableStaticPruningOptimization; _ltmcChoiceResolver = new LtmcChoiceResolver(useForwardOptimization); ChoiceResolver = _ltmcChoiceResolver; RuntimeModel.SetChoiceResolver(ChoiceResolver); _allowFaultsOnInitialTransitions = configuration.AllowFaultsOnInitialTransitions; }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", typeof(IdentityUserLogin <string>), baseEntityType); var loginProvider = runtimeEntityType.AddProperty( "LoginProvider", typeof(string), propertyInfo: typeof(IdentityUserLogin <string>).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserLogin <string>).GetField("<LoginProvider>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), afterSaveBehavior: PropertySaveBehavior.Throw, maxLength: 128); var providerKey = runtimeEntityType.AddProperty( "ProviderKey", typeof(string), propertyInfo: typeof(IdentityUserLogin <string>).GetProperty("ProviderKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserLogin <string>).GetField("<ProviderKey>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), afterSaveBehavior: PropertySaveBehavior.Throw, maxLength: 128); var providerDisplayName = runtimeEntityType.AddProperty( "ProviderDisplayName", typeof(string), propertyInfo: typeof(IdentityUserLogin <string>).GetProperty("ProviderDisplayName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserLogin <string>).GetField("<ProviderDisplayName>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var userId = runtimeEntityType.AddProperty( "UserId", typeof(string), propertyInfo: typeof(IdentityUserLogin <string>).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserLogin <string>).GetField("<UserId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var key = runtimeEntityType.AddKey( new[] { loginProvider, providerKey }); runtimeEntityType.SetPrimaryKey(key); var index = runtimeEntityType.AddIndex( new[] { userId }); return(runtimeEntityType); }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "BlazingPizza.Pizza", typeof(Pizza), baseEntityType); var id = runtimeEntityType.AddProperty( "Id", typeof(int), propertyInfo: typeof(Pizza).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(Pizza).GetField("<Id>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var orderId = runtimeEntityType.AddProperty( "OrderId", typeof(int), propertyInfo: typeof(Pizza).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(Pizza).GetField("<OrderId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var size = runtimeEntityType.AddProperty( "Size", typeof(int), propertyInfo: typeof(Pizza).GetProperty("Size", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(Pizza).GetField("<Size>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var specialId = runtimeEntityType.AddProperty( "SpecialId", typeof(int), propertyInfo: typeof(Pizza).GetProperty("SpecialId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(Pizza).GetField("<SpecialId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var key = runtimeEntityType.AddKey( new[] { id }); runtimeEntityType.SetPrimaryKey(key); var index = runtimeEntityType.AddIndex( new[] { orderId }); var index0 = runtimeEntityType.AddIndex( new[] { specialId }); return(runtimeEntityType); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="runtimeModelCreator">A factory function that creates the model instance that should be executed.</param> /// <param name="formulas">The formulas that should be evaluated for each state.</param> /// <param name="configuration">The analysis configuration that should be used.</param> /// <param name="stateHeaderBytes"> /// The number of bytes that should be reserved at the beginning of each state vector for the model checker tool. /// </param> internal ActivationMinimalExecutedModel(CoupledExecutableModelCreator <TExecutableModel> runtimeModelCreator, int stateHeaderBytes, Func <bool>[] formulas, AnalysisConfiguration configuration) : base(runtimeModelCreator, stateHeaderBytes, configuration) { formulas = formulas ?? RuntimeModel.Formulas.Select(formula => FormulaCompilationVisitor <TExecutableModel> .Compile(RuntimeModel, formula)).ToArray(); _transitions = new ActivationMinimalTransitionSetBuilder <TExecutableModel>(TemporaryStateStorage, configuration.SuccessorCapacity, formulas); _stateConstraints = RuntimeModel.StateConstraints; var useForwardOptimization = configuration.EnableStaticPruningOptimization; ChoiceResolver = new NondeterministicChoiceResolver(useForwardOptimization); FaultSet.CheckFaultCount(RuntimeModel.Faults.Length); RuntimeModel.SetChoiceResolver(ChoiceResolver); _allowFaultsOnInitialTransitions = configuration.AllowFaultsOnInitialTransitions; }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", typeof(IdentityUserClaim <string>), baseEntityType); var id = runtimeEntityType.AddProperty( "Id", typeof(int), propertyInfo: typeof(IdentityUserClaim <string>).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserClaim <string>).GetField("<Id>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var claimType = runtimeEntityType.AddProperty( "ClaimType", typeof(string), propertyInfo: typeof(IdentityUserClaim <string>).GetProperty("ClaimType", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserClaim <string>).GetField("<ClaimType>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var claimValue = runtimeEntityType.AddProperty( "ClaimValue", typeof(string), propertyInfo: typeof(IdentityUserClaim <string>).GetProperty("ClaimValue", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserClaim <string>).GetField("<ClaimValue>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var userId = runtimeEntityType.AddProperty( "UserId", typeof(string), propertyInfo: typeof(IdentityUserClaim <string>).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserClaim <string>).GetField("<UserId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var key = runtimeEntityType.AddKey( new[] { id }); runtimeEntityType.SetPrimaryKey(key); var index = runtimeEntityType.AddIndex( new[] { userId }); return(runtimeEntityType); }
/// <summary> /// Gets all initial transitions of the model. /// </summary> public override TransitionCollection GetInitialTransitions() { BeginExecution(); ChoiceResolver.PrepareNextState(); fixed(byte *state = RuntimeModel.ConstructionState) { while (ChoiceResolver.PrepareNextPath()) { RuntimeModel.Deserialize(state); ExecuteInitialTransition(); GenerateTransition(); } } return(EndExecution()); }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "BlazingPizza.Order", typeof(Order), baseEntityType); var orderId = runtimeEntityType.AddProperty( "OrderId", typeof(int), propertyInfo: typeof(Order).GetProperty("OrderId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(Order).GetField("<OrderId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var createdTime = runtimeEntityType.AddProperty( "CreatedTime", typeof(DateTime), propertyInfo: typeof(Order).GetProperty("CreatedTime", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(Order).GetField("<CreatedTime>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); var deliveryAddressId = runtimeEntityType.AddProperty( "DeliveryAddressId", typeof(int?), nullable: true); var userId = runtimeEntityType.AddProperty( "UserId", typeof(string), propertyInfo: typeof(Order).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(Order).GetField("<UserId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var key = runtimeEntityType.AddKey( new[] { orderId }); runtimeEntityType.SetPrimaryKey(key); var index = runtimeEntityType.AddIndex( new[] { deliveryAddressId }); return(runtimeEntityType); }
protected virtual RuntimeModel Create(IModel model) { var runtimeModel = new RuntimeModel(); runtimeModel.SetSkipDetectChanges(((IRuntimeModel)model).SkipDetectChanges); ((IModel)runtimeModel).ModelDependencies = model.ModelDependencies !; var entityTypes = model.GetEntityTypesInHierarchicalOrder(); var entityTypePairs = new List <(IEntityType Source, RuntimeEntityType Target)>(entityTypes.Count); foreach (var entityType in entityTypes) { var runtimeEntityType = Create(entityType, runtimeModel); entityTypePairs.Add((entityType, runtimeEntityType)); foreach (var property in entityType.GetDeclaredProperties()) { var runtimeProperty = Create(property, runtimeEntityType); CreateAnnotations(property, runtimeProperty, static (convention, annotations, source, target, runtime) =>
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="context">The context of the traversal process.</param> /// <param name="stateFormulas">The state formulas that can be evaluated over the generated state graph.</param> /// <param name="transitionSizeInBytes">The size of a transition in bytes.</param> /// <param name="model">The runtime model the state graph is generated for.</param> /// <param name="createModel"> /// The factory function that should be used to create instances of the <see cref="RuntimeModel" /> /// the state graph is generated for. /// </param> internal StateGraph(TraversalContext context, Formula[] stateFormulas, int transitionSizeInBytes, RuntimeModel model, Func<RuntimeModel> createModel) { Requires.NotNull(context, nameof(context)); StateFormulas = stateFormulas; TransitionSize = transitionSizeInBytes; RuntimeModel = model; RuntimeModelCreator = createModel; _stateStorage = context.States; _transitionCapacity = context.Configuration.TransitionCapacity; _transitionsBuffer.Resize(TransitionSize * _transitionCapacity, zeroMemory: false); _stateMapBuffer.Resize(context.Configuration.StateCapacity * sizeof(TransitionRange), zeroMemory: false); _transitions = _transitionsBuffer.Pointer; _stateMap = (TransitionRange*)_stateMapBuffer.Pointer; }
RuntimeModel SelectActiveRuntime(SolutionItem project, RuntimeModel preferedRuntimeModel) { var runtimes = AllRuntimes (ToolbarView.RuntimeModel).Cast<RuntimeModel> ().ToList (); string lastRuntimeForProject = project.UserProperties.GetValue<string> ("PreferredExecutionTarget", defaultValue: null); var activeTarget = preferedRuntimeModel?.Project == project ? preferedRuntimeModel.ExecutionTarget : null; var multiProjectExecutionTarget = activeTarget as MultiProjectExecutionTarget; if (multiProjectExecutionTarget != null) { activeTarget = multiProjectExecutionTarget.GetTarget (project); } var activeTargetId = activeTarget?.Id; RuntimeModel defaultRuntime = null; foreach (var item in runtimes) { using (var model = item.GetMutableModel ()) { if (!model.Enabled) continue; } var target = item.ExecutionTarget; if (target == null || item.Project != project) continue; if (target is ExecutionTargetGroup) if (item.HasChildren) continue; if (defaultRuntime == null || lastRuntimeForProject == target.Id) { defaultRuntime = item; } if (target.Id == activeTargetId) { project.UserProperties.SetValue ("PreferredExecutionTarget", target.Id); return item; } if (target.Equals (activeTarget)) { defaultRuntime = item; } } if (defaultRuntime?.ExecutionTarget?.Id != null) project.UserProperties.SetValue("PreferredExecutionTarget", defaultRuntime.ExecutionTarget.Id); return defaultRuntime; }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "Microsoft.AspNetCore.Identity.IdentityUserToken<long>", typeof(IdentityUserToken <long>), baseEntityType); var userId = runtimeEntityType.AddProperty( "UserId", typeof(long), propertyInfo: typeof(IdentityUserToken <long>).GetProperty("UserId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserToken <long>).GetField("<UserId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), afterSaveBehavior: PropertySaveBehavior.Throw); var loginProvider = runtimeEntityType.AddProperty( "LoginProvider", typeof(string), propertyInfo: typeof(IdentityUserToken <long>).GetProperty("LoginProvider", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserToken <long>).GetField("<LoginProvider>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), afterSaveBehavior: PropertySaveBehavior.Throw); var name = runtimeEntityType.AddProperty( "Name", typeof(string), propertyInfo: typeof(IdentityUserToken <long>).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserToken <long>).GetField("<Name>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), afterSaveBehavior: PropertySaveBehavior.Throw); var value = runtimeEntityType.AddProperty( "Value", typeof(string), propertyInfo: typeof(IdentityUserToken <long>).GetProperty("Value", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(IdentityUserToken <long>).GetField("<Value>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var key = runtimeEntityType.AddKey( new[] { userId, loginProvider, name }); runtimeEntityType.SetPrimaryKey(key); return(runtimeEntityType); }
/// <summary> /// Executes an initial transition of the model. /// </summary> protected override void ExecuteInitialTransition() { //TODO: _resetRewards(); foreach (var fault in RuntimeModel.NondeterministicFaults) { fault.Reset(); } if (!_allowFaultsOnInitialTransitions) { foreach (var fault in RuntimeModel.NondeterministicFaults) { fault.Activation = Activation.Suppressed; } } // Note: Faults get activated and their effects occur, but they are not notified yet of their activation. foreach (var fault in RuntimeModel.OnStartOfStepFaults) { fault.TryActivate(); } foreach (var fault in RuntimeModel.OnCustomFaults) { if (fault.HasCustomDemand()) { fault.TryActivate(); } else { fault.Activation = Activation.Suppressed; } } RuntimeModel.ExecuteInitialStep(); for (var i = 0; i < RuntimeModel.NondeterministicFaults.Length; i++) { RuntimeModel.NondeterministicFaults[i].RestoreActivation(SavedActivations[i]); } }
/// <summary> /// Initializes a new instance of the <see cref="RuntimeSequence" /> class. /// </summary> /// <param name="name">The sequence name.</param> /// <param name="model">The model.</param> /// <param name="type">The type of values generated.</param> /// <param name="schema">The schema.</param> /// <param name="startValue">The initial value.</param> /// <param name="incrementBy">The value increment.</param> /// <param name="cyclic">Whether the sequence is cyclic.</param> /// <param name="minValue">The minimum value.</param> /// <param name="maxValue">The maximum value.</param> public RuntimeSequence( string name, RuntimeModel model, Type type, string?schema = null, long startValue = Sequence.DefaultStartValue, int incrementBy = Sequence.DefaultIncrementBy, bool cyclic = false, long?minValue = null, long?maxValue = null) { Model = model; Name = name; _schema = schema; _type = type; _startValue = startValue; _incrementBy = incrementBy; _isCyclic = cyclic; _minValue = minValue; _maxValue = maxValue; }
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null) { var runtimeEntityType = model.AddEntityType( "OpenBudget.Model.SQLite.Tables.Info", typeof(Info), baseEntityType); var id = runtimeEntityType.AddProperty( "Id", typeof(int), propertyInfo: typeof(Info).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(Info).GetField("<Id>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), valueGenerated: ValueGenerated.OnAdd, afterSaveBehavior: PropertySaveBehavior.Throw); var data = runtimeEntityType.AddProperty( "Data", typeof(byte[]), propertyInfo: typeof(Info).GetProperty("Data", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(Info).GetField("<Data>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var key = runtimeEntityType.AddProperty( "Key", typeof(string), propertyInfo: typeof(Info).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), fieldInfo: typeof(Info).GetField("<Key>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), nullable: true); var key0 = runtimeEntityType.AddKey( new[] { id }); runtimeEntityType.SetPrimaryKey(key0); var index = runtimeEntityType.AddIndex( new[] { key }, unique: true); return(runtimeEntityType); }
/// <summary> /// Adds a transition to the <paramref name="model" />'s current state. /// </summary> /// <param name="model">The model the transition should be added for.</param> public void Add(RuntimeModel model) { if (_count >= _capacity) throw new OutOfMemoryException("Unable to store an additional transition. Try increasing the successor state capacity."); ++_computedCount; // 1. Serialize the model's computed state; that is the successor state of the transition's source state // modulo any changes resulting from notifications of fault activations var successorState = _targetStateMemory + _stateVectorSize * _count; var activatedFaults = FaultSet.FromActivatedFaults(model.NondeterministicFaults); model.Serialize(successorState); // 2. Make sure the transition we're about to add is activation-minimal if (!Add(successorState, activatedFaults)) return; // 3. Execute fault activation notifications and serialize the updated state if necessary if (model.NotifyFaultActivations()) model.Serialize(successorState); // 4. Store the transition _transitions[_count] = new CandidateTransition { TargetState = successorState, Formulas = new StateFormulaSet(_formulas), ActivatedFaults = activatedFaults, IsValid = true, }; ++_count; }
public RuntimeModel (MainToolbarController controller, ExecutionTarget target, RuntimeModel parent) : this (controller, target) { if (parent == null) HasParent = false; else { HasParent = true; parent.HasChildren = true; parent.AddChild (this); } }
void FillRuntimes () { ignoreRuntimeChangedCount++; try { ToolbarView.RuntimeModel = Enumerable.Empty<IRuntimeModel> (); if (!IdeApp.Workspace.IsOpen || currentSolution == null || !currentSolution.SingleStartup || currentSolution.StartupItem == null) return; // Check that the current startup project is enabled for the current configuration var solConf = currentSolution.GetConfiguration (IdeApp.Workspace.ActiveConfiguration); if (solConf == null || !solConf.BuildEnabledForItem (currentSolution.StartupItem)) return; ExecutionTarget previous = null; int runtimes = 0; var list = new List<RuntimeModel> (); foreach (var target in configurationMerger.GetTargetsForConfiguration (IdeApp.Workspace.ActiveConfigurationId, true)) { if (target is ExecutionTargetGroup) { var devices = (ExecutionTargetGroup) target; if (previous != null) list.Add (new RuntimeModel (this, target: null)); list.Add (new RuntimeModel (this, target)); foreach (var device in devices) { if (device is ExecutionTargetGroup) { var versions = (ExecutionTargetGroup) device; if (versions.Count > 1) { var parent = new RuntimeModel (this, device) { IsIndented = true, }; list.Add (parent); foreach (var version in versions) { list.Add (new RuntimeModel (this, version, parent)); runtimes++; } } else { list.Add (new RuntimeModel (this, versions[0]) { IsIndented = true, }); runtimes++; } } else { list.Add (new RuntimeModel (this, device) { IsIndented = true, }); runtimes++; } } } else { if (previous is ExecutionTargetGroup) { list.Add (new RuntimeModel (this, target: null)); } list.Add (new RuntimeModel (this, target)); runtimes++; } previous = target; } var cmds = IdeApp.CommandService.CreateCommandEntrySet (TargetsMenuPath); if (cmds.Count > 0) { bool needsSeparator = runtimes > 0; foreach (CommandEntry ce in cmds) { if (ce.CommandId == Command.Separator) { needsSeparator = true; continue; } var cmd = ce.GetCommand (IdeApp.CommandService) as ActionCommand; if (cmd != null) { var ci = IdeApp.CommandService.GetCommandInfo (cmd.Id, new CommandTargetRoute (lastCommandTarget)); if (ci.Visible) { if (needsSeparator) { list.Add (new RuntimeModel (this, target: null)); needsSeparator = false; } list.Add (new RuntimeModel (this, cmd)); runtimes++; } } } } ToolbarView.PlatformSensitivity = runtimes > 1; ToolbarView.RuntimeModel = list; } finally { ignoreRuntimeChangedCount--; } }
void SelectActiveRuntime (RuntimeModel preferedRuntimeModel) { ignoreRuntimeChangedCount++; try { if (ToolbarView.RuntimeModel.Any ()) { if (startupProjects.Length > 1) { var multiProjectTarget = new MultiProjectExecutionTarget (); var multipleRuntime = new RuntimeModel (this, multiProjectTarget, false, null); foreach (var startupProject in startupProjects) { var runtimeModel = SelectActiveRuntime (startupProject.Item1, preferedRuntimeModel); multiProjectTarget.SetExecutionTarget (startupProject.Item1, runtimeModel.ExecutionTarget); multipleRuntime.AddChild (runtimeModel); } ToolbarView.ActiveRuntime = multipleRuntime; IdeApp.Workspace.ActiveExecutionTarget = multipleRuntime.ExecutionTarget; } else if (startupProjects.Length == 1) { var runtimeModel = SelectActiveRuntime (startupProjects.First ().Item1, preferedRuntimeModel); ToolbarView.ActiveRuntime = runtimeModel; IdeApp.Workspace.ActiveExecutionTarget = runtimeModel?.ExecutionTarget; UpdateBuildConfiguration (); } else { ToolbarView.ActiveRuntime = null; IdeApp.Workspace.ActiveExecutionTarget = null; } } } finally { ignoreRuntimeChangedCount--; } }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="runtimeModel">The model instance that should be executed.</param> internal ExecutedModel(RuntimeModel runtimeModel) { Requires.NotNull(runtimeModel, nameof(runtimeModel)); RuntimeModel = runtimeModel; }
RuntimeModel SelectActiveRuntime (SolutionItem project, RuntimeModel preferedRuntimeModel) { var runtimes = AllRuntimes (ToolbarView.RuntimeModel).Cast<RuntimeModel> ().ToList (); string lastRuntimeForProject = project.UserProperties.GetValue<string> ("PreferredExecutionTarget", defaultValue: null); var activeTarget = preferedRuntimeModel?.Project == project ? preferedRuntimeModel.ExecutionTarget : null; var multiProjectExecutionTarget = activeTarget as MultiProjectExecutionTarget; if (multiProjectExecutionTarget != null) { activeTarget = multiProjectExecutionTarget.GetTarget (project); } var activeTargetId = activeTarget?.Id; RuntimeModel defaultRuntime = null; foreach (var item in runtimes) { using (var model = item.GetMutableModel ()) { if (!model.Enabled) continue; } var target = item.ExecutionTarget; if (target == null || !target.Enabled || item.Project != project) continue; if (target is ExecutionTargetGroup) if (item.HasChildren) continue; if (defaultRuntime == null || lastRuntimeForProject == target.Id) { defaultRuntime = item; } if (target.Id == activeTargetId) { project.UserProperties.SetValue ("PreferredExecutionTarget", target.Id); return item; } if (target.Equals (activeTarget)) { defaultRuntime = item; } } if (defaultRuntime?.ExecutionTarget?.Id != null) project.UserProperties.SetValue("PreferredExecutionTarget", defaultRuntime.ExecutionTarget.Id); return defaultRuntime; }
/// <summary> /// Loads a counter example from the <paramref name="file" />. /// </summary> /// <param name="file">The path to the file the counter example should be loaded from.</param> public static CounterExample Load(string file) { Requires.NotNullOrWhitespace(file, nameof(file)); using (var reader = new BinaryReader(File.OpenRead(file), Encoding.UTF8)) { if (reader.ReadInt32() != FileHeader) throw new InvalidOperationException("The file does not contain a counter example that is compatible with this version of S#."); var endsWithException = reader.ReadBoolean(); var serializedRuntimeModel = reader.ReadBytes(reader.ReadInt32()); var modelData = RuntimeModelSerializer.LoadSerializedData(serializedRuntimeModel); foreach (var fault in modelData.ObjectTable.OfType<Fault>()) fault.Activation = (Activation)reader.ReadInt32(); var runtimeModel = new RuntimeModel(modelData); runtimeModel.UpdateFaultSets(); var metadataStream = new MemoryStream(reader.ReadBytes(reader.ReadInt32())); var formatter = new BinaryFormatter(); var slotMetadata = new StateVectorLayout((StateSlotMetadata[])formatter.Deserialize(metadataStream)); var modelMetadata = runtimeModel.StateVectorLayout; var counterExample = new byte[reader.ReadInt32()][]; var slotCount = reader.ReadInt32(); if (slotCount != runtimeModel.StateVectorSize) { throw new InvalidOperationException( $"State slot count mismatch; the instantiated model requires {runtimeModel.StateVectorSize} state slots, " + $"whereas the counter example uses {slotCount} state slots."); } if (slotMetadata.SlotCount != modelMetadata.SlotCount) { throw new InvalidOperationException( $"State slot metadata count mismatch; the instantiated model has {modelMetadata.SlotCount} state slot metadata entries, " + $"whereas the counter example has {slotMetadata.SlotCount} state slot entries."); } for (var i = 0; i < slotMetadata.SlotCount; ++i) { if (modelMetadata[i] != slotMetadata[i]) throw new StateVectorMismatchException(slotMetadata, modelMetadata); } for (var i = 0; i < counterExample.Length; ++i) { counterExample[i] = new byte[runtimeModel.StateVectorSize]; for (var j = 0; j < runtimeModel.StateVectorSize; ++j) counterExample[i][j] = reader.ReadByte(); } var replayInfo = new int[reader.ReadInt32()][]; for (var i = 0; i < replayInfo.Length; ++i) { replayInfo[i] = new int[reader.ReadInt32()]; for (var j = 0; j < replayInfo[i].Length; ++j) replayInfo[i][j] = reader.ReadInt32(); } return new CounterExample(runtimeModel, counterExample, replayInfo, endsWithException); } }
void FillRuntimesForProject (List<RuntimeModel> list, SolutionItem project, ref int runtimes) { ExecutionTarget previous = null; foreach (var target in configurationMergers [project].GetTargetsForConfiguration (IdeApp.Workspace.ActiveConfigurationId, configurationMergers.Count < 2)) { if (target is ExecutionTargetGroup) { var devices = (ExecutionTargetGroup)target; if (previous != null) list.Add (new RuntimeModel (this, displayText: null));//Seperator foreach (var device in devices) { if (device is ExecutionTargetGroup) { var versions = (ExecutionTargetGroup)device; if (versions.Count > 1) { var parent = new RuntimeModel (this, device, true, project) { IsIndented = true, }; list.Add (parent); foreach (var version in versions) { parent.AddChild (new RuntimeModel (this, version, false, project)); runtimes++; } } else { list.Add (new RuntimeModel (this, versions [0], true, project) { IsIndented = true, }); runtimes++; } } else { list.Add (new RuntimeModel (this, device, true, project) { IsIndented = true, }); runtimes++; } } } else { if (previous is ExecutionTargetGroup) { list.Add (new RuntimeModel (this, displayText: null));//Seperator } list.Add (new RuntimeModel (this, target, true, project)); runtimes++; } previous = target; } }
void FillRuntimes () { ignoreRuntimeChangedCount++; try { ToolbarView.RuntimeModel = Enumerable.Empty<IRuntimeModel> (); if (!IdeApp.Workspace.IsOpen || currentSolution == null) return; var list = new List<RuntimeModel> (); int runtimes = 0; if (currentSolution.StartupConfiguration is MultiItemSolutionRunConfiguration) { bool anyValid = false; foreach (var startConf in ((MultiItemSolutionRunConfiguration)currentSolution.StartupConfiguration).Items) { if (startConf?.SolutionItem == null) continue; // Check that the current startup project is enabled for the current configuration var solConf = currentSolution.GetConfiguration (IdeApp.Workspace.ActiveConfiguration); if (solConf == null || !solConf.BuildEnabledForItem (startConf.SolutionItem)) continue; anyValid = true; var projectList = new List<RuntimeModel> (); FillRuntimesForProject (projectList, startConf.SolutionItem, ref runtimes); var parent = new RuntimeModel (this, startConf.SolutionItem.Name); parent.HasChildren = true; list.Add (parent); foreach (var p in projectList) { parent.AddChild (p); } } if (!anyValid) return; } else { var startConf = currentSolution.StartupConfiguration as SingleItemSolutionRunConfiguration; if (startConf == null || startConf.Item == null) return; // Check that the current startup project is enabled for the current configuration var solConf = currentSolution.GetConfiguration (IdeApp.Workspace.ActiveConfiguration); if (solConf == null || !solConf.BuildEnabledForItem (startConf.Item)) return; FillRuntimesForProject (list, startConf.Item, ref runtimes); } var cmds = IdeApp.CommandService.CreateCommandEntrySet (TargetsMenuPath); if (cmds.Count > 0) { bool needsSeparator = runtimes > 0; foreach (CommandEntry ce in cmds) { if (ce.CommandId == Command.Separator) { needsSeparator = true; continue; } var cmd = ce.GetCommand (IdeApp.CommandService) as ActionCommand; if (cmd != null) { var ci = IdeApp.CommandService.GetCommandInfo (cmd.Id, new CommandTargetRoute (lastCommandTarget)); if (ci.Visible) { if (needsSeparator) { list.Add (new RuntimeModel (this, displayText: null)); needsSeparator = false; } list.Add (new RuntimeModel (this, cmd)); runtimes++; } } } } ToolbarView.PlatformSensitivity = runtimes > 1; ToolbarView.RuntimeModel = list; } finally { ignoreRuntimeChangedCount--; } }