コード例 #1
0
        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); });
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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());
                }
            }
        }
コード例 #7
0
        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());
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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");
            }
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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));
        }
コード例 #13
0
 public void PrincipalKeyPropertyChanged(StateEntry entry, IProperty property, object oldValue, object newValue)
 {
 }
コード例 #14
0
 public static void Reload(this StateEntry stateEntry, DbContext context)
 {
     stateEntry.ReloadAsync(context).Wait();
 }
コード例 #15
0
 public void NavigationReferenceChanged(StateEntry entry, INavigation navigation, object oldValue, object newValue)
 {
 }
コード例 #16
0
 public virtual void NavigationCollectionChanged(StateEntry entry, INavigation navigation, ISet <object> added, ISet <object> removed)
 {
 }
コード例 #17
0
 public void StateChanged(StateEntry entry, EntityState oldState)
 {
 }
コード例 #18
0
 public void ForeignKeyPropertyChanged(StateEntry entry, IProperty property, object oldValue, object newValue)
 {
 }
コード例 #19
0
 public void Post(StateEntry <Subscription> bogusEntry)
 {
 }
コード例 #20
0
 public async Task AddOneWithStateEntryAndCustomKey([FromState("testStore", "widget")] StateEntry <Widget> state)
 {
     state.Value.Count++;
     await state.SaveAsync();
 }
コード例 #21
0
 public void PropertyChanging(StateEntry entry, IPropertyBase property)
 {
     Changing = property;
 }
コード例 #22
0
 protected override Sidecar CreateSidecar(StateEntry entry = null)
 {
     return(new OriginalValuesFactory().Create(entry ?? CreateStateEntry()));
 }
コード例 #23
0
 public void PropertyChanged(StateEntry entry, IPropertyBase property)
 {
     Changed = property;
 }
コード例 #24
0
ファイル: Automata.Node.Kind.cs プロジェクト: Egaros/lib
 public InlineLeaveStateNode(Automata <TInstruction, TOperand> automata, Graph graph, StateEntry stateEntry) : base(automata, graph, stateEntry)
 {
 }
コード例 #25
0
 protected abstract Sidecar CreateSidecar(StateEntry entry = null);
コード例 #26
0
 protected virtual void ResolveConcurrencyTokens(StateEntry stateEntry)
 {
     // default do nothing. Allow provider-specific entry reset
 }
コード例 #27
0
 public void StateChanging(StateEntry entry, EntityState newState)
 {
 }
コード例 #28
0
 public ActionResult <Widget> Get([FromState("testStore")] StateEntry <Widget> widgetStateEntry)
 {
     return(widgetStateEntry.Value);
 }
コード例 #29
0
 public async Task AddOneWithStateEntry([FromState("testStore")] StateEntry <Widget> widget)
 {
     widget.Value.Count++;
     await widget.SaveAsync();
 }
コード例 #30
0
            public override void DetectChanges(StateEntry entry)
            {
                Entries.Add(entry);

                base.DetectChanges(entry);
            }
コード例 #31
0
 public void SidecarPropertyChanging(StateEntry entry, IPropertyBase property)
 {
 }