public void ConstructTest() { StateEntry stateEntry = new StateEntry(); Assert.AreEqual(stateEntry.Label, null); Assert.AreEqual(stateEntry.Url, null); stateEntry = new StateEntry("Url", "Label"); Assert.AreEqual(stateEntry.Label, "Label"); Assert.AreEqual(stateEntry.Url, "Url"); Assert.Catch<ArgumentNullException>(() => { new StateEntry(null as string, "Label"); }); Assert.Catch<ArgumentNullException>(() => { new StateEntry("Url", null); }); }
public void AddEntry(string Name, string Parent, ITreeStateEntry Target) { if (Root) { if (!Entries.ContainsKey(Name) && Entries.ContainsKey(Parent) && !Entries[Parent].Children.Contains(Name)) { StateEntry NewEntry = new StateEntry { Name = Name, ParentName = Parent, Children = new List <string>(), Target = Target }; Entries[Name] = NewEntry; Entries[Parent].Children.Add(Name); } } }
private void AddInsertEntryCommands(ITransaction transaction, StateEntry stateEntry) { var compositePrimaryKeyValues = ConstructKeyValue(stateEntry, (se, prop) => stateEntry[prop]); var redisDataKeyName = ConstructRedisDataKeyName(stateEntry.EntityType, compositePrimaryKeyValues); // Note: null entries are stored as the absence of the property_name-property_value pair in the hash var entries = stateEntry.EntityType.Properties .Where(p => stateEntry[p] != null) .Select(p => new HashEntry(p.Name, EncodeAsBytes(stateEntry[p]))).ToArray(); transaction.HashSetAsync(redisDataKeyName, entries); var redisPrimaryKeyIndexKeyName = ConstructRedisPrimaryKeyIndexKeyName(stateEntry.EntityType); transaction.SetAddAsync(redisPrimaryKeyIndexKeyName, compositePrimaryKeyValues); }
public ColumnModification( [NotNull] StateEntry stateEntry, [NotNull] IProperty property, [CanBeNull] string parameterName, bool isRead, bool isWrite, bool isKey, bool isCondition) { Check.NotNull(stateEntry, "stateEntry"); Check.NotNull(property, "property"); _stateEntry = stateEntry; _property = property; _columnName = property.StorageName; _parameterName = parameterName; _isRead = isRead; _isWrite = isWrite; _isKey = isKey; _isCondition = isCondition; }
private void AddInsertEntryCommands(ITransaction transaction, StateEntry stateEntry) { var compositePrimaryKeyValues = string.Join( PropertyValueSeparator, stateEntry.EntityType.GetKey().Properties.Select(p => EncodeKeyValue(stateEntry, p))); var redisDataKeyName = string.Format(CultureInfo.InvariantCulture, DataHashNameFormat, stateEntry.EntityType.Name, compositePrimaryKeyValues); // Note: null entries are stored as the absence of the property_name-property_value pair in the hash var entries = stateEntry.EntityType.Properties .Where(p => stateEntry[p] != null) .Select(p => new HashEntry(p.Name, EncodeAsBytes(stateEntry[p]))).ToArray(); transaction.HashSetAsync(redisDataKeyName, entries); var redisPrimaryKeyIndexKeyName = string.Format(CultureInfo.InvariantCulture, PrimaryKeyIndexNameFormat, stateEntry.EntityType.Name); transaction.SetAddAsync(redisPrimaryKeyIndexKeyName, compositePrimaryKeyValues); }
public virtual async Task PropagateValueAsync( [NotNull] StateEntry stateEntry, [NotNull] IProperty property, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(stateEntry, "stateEntry"); Check.NotNull(property, "property"); Debug.Assert(property.IsForeignKey()); if (!TryPropagateValue(stateEntry, property) && property.IsKey()) { var valueGenerator = TryGetValueGenerator(property); if (valueGenerator != null) { stateEntry[property] = (await valueGenerator.NextAsync(property, _storeServices, cancellationToken).WithCurrentCulture()); } } }
public async Task <ActionResult> Transcribe(TradiureTranscriptionRequest request, CancellationToken cancellationToken) { try { _logger.LogInformation($"{request.TranscriptionId}. {request.BlobUri} was successfullly received by Dapr PubSub"); state = await _client.GetStateEntryAsync <TraduireTranscription>(Components.StateStoreName, request.TranscriptionId.ToString()); state.Value ??= new TraduireTranscription(); (TranscriptionResults result, HttpStatusCode code) = await _cogsClient.DownloadTranscriptionResultAsync(new Uri(request.BlobUri)); switch (code) { case HttpStatusCode.OK: _logger.LogInformation($"{request.TranscriptionId}. Transcription from '{request.BlobUri}' was saved to state store "); var firstChannel = result.CombinedRecognizedPhrases.FirstOrDefault(); await _serviceClient.PublishNotification(request.TranscriptionId.ToString(), state.Value.Status.ToString()); await UpdateStateRepository(TraduireTranscriptionStatus.Completed, firstChannel.Display); _logger.LogInformation($"{request.TranscriptionId}. All working completed on request"); return(Ok(request.TranscriptionId)); default: _logger.LogInformation($"{request.TranscriptionId}. Transcription Failed for an unexpected reason. Added to Failed Queue for review"); var failedEvent = await UpdateStateRepository(TraduireTranscriptionStatus.Failed, code, request.BlobUri); await _client.PublishEventAsync(Components.PubSubName, Topics.TranscriptionFailedTopicName, failedEvent, cancellationToken); break; } } catch (Exception ex) { _logger.LogWarning($"Nuts. Something really bad happened processing {request.BlobUri} - {ex.Message}"); } return(BadRequest()); }
public static Dictionary <IProperty, object> GetDatabaseValues(this StateEntry stateEntry, DbContext context) { if (stateEntry.EntityType.Type == typeof(Driver)) { var id = (int)stateEntry.GetPrimaryKeyValue().Value; return(context.Set <Driver>() .Where(d => d.Id == id) .Select(d => d.GetValues(stateEntry.EntityType)) .SingleOrDefault()); } if (stateEntry.EntityType.Type == typeof(Engine)) { var id = (int)stateEntry.GetPrimaryKeyValue().Value; return(context.Set <Engine>() .Where(d => d.Id == id) .Select(d => d.GetValues(stateEntry.EntityType)) .SingleOrDefault()); } return(null); }
protected TableOperationRequest CreateRequest(AtsTable table, StateEntry entry) { var entity = EntityFactory.CreateFromStateEntry(entry); switch (entry.EntityState) { case EntityState.Added: return(new CreateRowRequest(table, entity)); case EntityState.Deleted: return(new DeleteRowRequest(table, entity)); case EntityState.Modified: return(new MergeRowRequest(table, entity)); case EntityState.Unchanged: case EntityState.Unknown: return(null); default: throw new ArgumentOutOfRangeException("entry", "Unknown entity state"); } }
public override object Next(StateEntry entry, IProperty property) { Check.NotNull(entry, "entry"); Check.NotNull(property, "property"); var guidBytes = Guid.NewGuid().ToByteArray(); var counterBytes = BitConverter.GetBytes(Interlocked.Increment(ref _counter)); if (!BitConverter.IsLittleEndian) { Array.Reverse(counterBytes); } guidBytes[08] = counterBytes[1]; guidBytes[09] = counterBytes[0]; guidBytes[10] = counterBytes[7]; guidBytes[11] = counterBytes[6]; guidBytes[12] = counterBytes[5]; guidBytes[13] = counterBytes[4]; guidBytes[14] = counterBytes[3]; guidBytes[15] = counterBytes[2]; return(new Guid(guidBytes)); }
private void AddModifyEntryCommands(ITransaction transaction, StateEntry stateEntry) { var compositePrimaryKeyValues = ConstructKeyValue(stateEntry, (se, prop) => stateEntry.OriginalValues[prop]); var redisPrimaryKeyIndexKeyName = ConstructRedisPrimaryKeyIndexKeyName(stateEntry.EntityType); var redisDataKeyName = ConstructRedisDataKeyName(stateEntry.EntityType, compositePrimaryKeyValues); transaction.AddCondition(Condition.KeyExists(redisPrimaryKeyIndexKeyName)); // first delete all the hash entries which have changed to null var changingToNullEntries = stateEntry.EntityType.Properties .Where(p => stateEntry.IsPropertyModified(p) && stateEntry[p] == null) .Select(p => (RedisValue)p.Name).ToArray(); transaction.HashDeleteAsync(redisDataKeyName, changingToNullEntries); // now update all the other entries var updatedEntries = stateEntry.EntityType.Properties .Where(p => stateEntry.IsPropertyModified(p) && stateEntry[p] != null) .Select(p => new HashEntry(p.Name, EncodeAsBytes(stateEntry[p]))).ToArray(); transaction.HashSetAsync(redisDataKeyName, updatedEntries); }
public virtual async Task <object> NextAsync(StateEntry stateEntry, IProperty property, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(stateEntry, "stateEntry"); Check.NotNull(property, "property"); var newValue = GetNextValue(); // If the chosen value is outside of the current block then we need a new block. // It is possible that other threads will use all of the new block before this thread // gets a chance to use the new new value, so use a while here to do it all again. while (newValue.Current >= newValue.Max) { // Once inside the lock check to see if another thread already got a new block, in which // case just get a value out of the new block instead of requesting one. using (await _lock.LockAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false)) { if (newValue.Max == _currentValue.Max) { var commandInfo = PrepareCommand(stateEntry.Configuration); var newCurrent = (long)await _executor .ExecuteScalarAsync(commandInfo.Item1.DbConnection, commandInfo.Item1.DbTransaction, commandInfo.Item2, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); newValue = new SequenceValue(newCurrent, newCurrent + _blockSize); _currentValue = newValue; } else { newValue = GetNextValue(); } } } return(Convert.ChangeType(newValue.Current, property.PropertyType)); }
public void PrincipalKeyPropertyChanged(StateEntry entry, IProperty property, object oldValue, object newValue) { }
public static void Reload(this StateEntry stateEntry, DbContext context) { stateEntry.ReloadAsync(context).Wait(); }
public void NavigationReferenceChanged(StateEntry entry, INavigation navigation, object oldValue, object newValue) { }
public virtual void NavigationCollectionChanged(StateEntry entry, INavigation navigation, ISet <object> added, ISet <object> removed) { }
public void StateChanged(StateEntry entry, EntityState oldState) { }
public void ForeignKeyPropertyChanged(StateEntry entry, IProperty property, object oldValue, object newValue) { }
public void Post(StateEntry <Subscription> bogusEntry) { }
public async Task AddOneWithStateEntryAndCustomKey([FromState("testStore", "widget")] StateEntry <Widget> state) { state.Value.Count++; await state.SaveAsync(); }
public void PropertyChanging(StateEntry entry, IPropertyBase property) { Changing = property; }
protected override Sidecar CreateSidecar(StateEntry entry = null) { return(new OriginalValuesFactory().Create(entry ?? CreateStateEntry())); }
public void PropertyChanged(StateEntry entry, IPropertyBase property) { Changed = property; }
public InlineLeaveStateNode(Automata <TInstruction, TOperand> automata, Graph graph, StateEntry stateEntry) : base(automata, graph, stateEntry) { }
protected abstract Sidecar CreateSidecar(StateEntry entry = null);
protected virtual void ResolveConcurrencyTokens(StateEntry stateEntry) { // default do nothing. Allow provider-specific entry reset }
public void StateChanging(StateEntry entry, EntityState newState) { }
public ActionResult <Widget> Get([FromState("testStore")] StateEntry <Widget> widgetStateEntry) { return(widgetStateEntry.Value); }
public async Task AddOneWithStateEntry([FromState("testStore")] StateEntry <Widget> widget) { widget.Value.Count++; await widget.SaveAsync(); }
public override void DetectChanges(StateEntry entry) { Entries.Add(entry); base.DetectChanges(entry); }
public void SidecarPropertyChanging(StateEntry entry, IPropertyBase property) { }