示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OperationInfo"/> class.
 /// </summary>
 public OperationInfo(
     OperationId id,
     string title,
     CommandInfo command,
     IList <FileId> declaredInput,
     IList <FileId> declaredOutput,
     IList <FileId> readAccess,
     IList <FileId> writeAccess,
     IList <OperationId> children,
     uint dependencyCount,
     bool wasSuccessfulRun,
     DateTime evaluateTime,
     IList <FileId> observedInput,
     IList <FileId> observedOutput)
 {
     Id               = id;
     Title            = title;
     Command          = command;
     DeclaredInput    = declaredInput;
     DeclaredOutput   = declaredOutput;
     ReadAccess       = readAccess;
     WriteAccess      = writeAccess;
     Children         = children;
     DependencyCount  = dependencyCount;
     WasSuccessfulRun = wasSuccessfulRun;
     EvaluateTime     = evaluateTime;
     ObservedInput    = observedInput;
     ObservedOutput   = observedOutput;
 }
示例#2
0
        public async Task GivenTagKeys_WhenGettingExtentendedQueryTags_ThenShouldPassArguments()
        {
            Guid operationId    = Guid.NewGuid();
            var  expectedOutput = new List <ExtendedQueryTagStoreEntry>
            {
                new ExtendedQueryTagStoreEntry(1, "01010101", "AS", null, QueryTagLevel.Instance, ExtendedQueryTagStatus.Adding, QueryStatus.Enabled, 0)
            };

            // Arrange input
            IDurableActivityContext context = Substitute.For <IDurableActivityContext>();

            context.InstanceId.Returns(OperationId.ToString(operationId));

            _extendedQueryTagStore
            .GetExtendedQueryTagsAsync(operationId, CancellationToken.None)
            .Returns(expectedOutput);

            // Call the activity
            IReadOnlyList <ExtendedQueryTagStoreEntry> actual = await _reindexDurableFunction.GetQueryTagsAsync(
                context,
                NullLogger.Instance);

            // Assert behavior
            Assert.Same(expectedOutput, actual);
            await _extendedQueryTagStore
            .Received(1)
            .GetExtendedQueryTagsAsync(operationId, CancellationToken.None);
        }
        /// <summary> Stops tracking the activity and emits a telemetry event. </summary>
        public void Dispose()
        {
            _stopwatch.Stop();

            if (NuGetTelemetryService != null && TelemetryEvent != null)
            {
                var endTime = DateTime.UtcNow;
                TelemetryEvent["StartTime"] = _startTime.ToString("O");
                TelemetryEvent["EndTime"]   = endTime.ToString("O");
                TelemetryEvent["Duration"]  = _stopwatch.Elapsed.TotalSeconds;

                if (ParentId != Guid.Empty)
                {
                    TelemetryEvent[nameof(ParentId)] = ParentId.ToString();
                }

                if (OperationId != Guid.Empty)
                {
                    TelemetryEvent[nameof(OperationId)] = OperationId.ToString();
                }

                foreach (var interval in _intervalList)
                {
                    TelemetryEvent[interval.Item1] = interval.Item2.TotalSeconds;
                }

                NuGetTelemetryService.EmitTelemetryEvent(TelemetryEvent);
            }

            _telemetryActivity?.Dispose();
        }
 private IOperationManager <SessionState, TaskState> CreateOperationManager()
 {
     return(new SessionBuilder <SessionState, TaskState>()
            .ConfigureSessionManager(managerConfiguration => managerConfiguration.MaxConcurrencyLevel = 4)
            .WithLogging(LoggerFactory)
            .CreateOperationManager(OperationId.CreateWithGuid(), new SessionState()));
 }
示例#5
0
        public async Task Handle(
            DateTimeOffset date, UserId user, BrokerId broker, AccountId account,
            decimal amount, ExpenseCategory category, AssetId?asset)
        {
            if (amount == 0)
            {
                throw new InvalidPriceException();
            }
            if (string.IsNullOrWhiteSpace(category.ToString()))
            {
                throw new InvalidCategoryException();
            }
            var state       = _stateManager.ReadState(date, user);
            var brokerState = state.Brokers.FirstOrDefault(b => b.Id == broker);

            if (brokerState == null)
            {
                throw new BrokerNotFoundException();
            }
            if (brokerState.Accounts.All(a => a.Id != account))
            {
                throw new AccountNotFoundException();
            }
            if ((asset != null) && brokerState.Inventory.All(a => a.Id != asset))
            {
                throw new AssetNotFoundException();
            }
            var id = new OperationId(_idGenerator.GenerateNewId());
            await _stateManager.AddCommand(new AddExpenseCommand(
                                               date, user, broker, account, id, amount, category, asset));
        }
        /// <inheritdoc/>
        public async Task <Guid> StartReindexingInstancesAsync(IReadOnlyCollection <int> tagKeys, CancellationToken cancellationToken = default)
        {
            EnsureArg.IsNotNull(tagKeys, nameof(tagKeys));
            EnsureArg.HasItems(tagKeys, nameof(tagKeys));

            // Start the re-indexing orchestration
            Guid instanceGuid = _guidFactory.Create();

            // TODO: Pass token when supported
            string instanceId = await _durableClient.StartNewAsync(
                FunctionNames.ReindexInstances,
                OperationId.ToString(instanceGuid),
                new ReindexInput { QueryTagKeys = tagKeys });

            _logger.LogInformation("Successfully started new orchestration instance with ID '{InstanceId}'.", instanceId);

            // Associate the tags to the operation and confirm their processing
            IReadOnlyList <ExtendedQueryTagStoreEntry> confirmedTags = await _extendedQueryTagStore.AssignReindexingOperationAsync(
                tagKeys,
                instanceGuid,
                returnIfCompleted : true,
                cancellationToken : cancellationToken);

            return(confirmedTags.Count > 0 ? instanceGuid : throw new ExtendedQueryTagsAlreadyExistsException());
        }
示例#7
0
        private static Period ChangeSpendingInfo(Amount amount = null, Label label = null, Pair pair = null, SpendingCategory category = null)
        {
            var period = Some.Period(p => p.WithEvent(new SpendingAdded(OperationId.From(1), Amount.From(10), Label.From("test"), Pair.First, SpendingCategory.Advance)));

            MakeChanges(period, amount, label, pair, category);
            return(period);
        }
示例#8
0
        public Result OperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
            ReadOnlySpan<byte> inBuffer)
        {
            if (IsDisposed) return ResultFs.PreconditionViolation.Log();

            return OperateRange(outBuffer, operationId, offset, size, inBuffer);
        }
示例#9
0
 public void Deserialize(Common.Serialization.IO.CompactReader reader)
 {
     _database           = reader.ReadString();
     _shard              = reader.ReadString();
     _lastOperationID    = reader.ReadObject() as OperationId;
     _lastFullBackupDate = reader.ReadDateTime();
 }
        private OperationId StartLoggingOnReplica(ArrayList bucketIds)
        {
            //opId is latest operation id at time when bucket logging been started so that we can use it during query
            OperationId opId = new OperationId();

            if (Context.OperationLog != null)
            {
                ILogOperation lastOperation = Context.OperationLog.LastOperation;

                if (lastOperation != null && lastOperation.OperationId != null)
                {
                    opId = Context.OperationLog.LastOperation.OperationId;
                }
            }

            foreach (int bucketID in bucketIds)
            {
                if (Context.OperationLog != null)
                {
                    Context.OperationLog.StartLogging(new LoggingIdentity(taskIdentity.DBName, taskIdentity.ColName, bucketID), LogMode.BeforeActualOperation);
                }
            }

            return(opId);
        }
示例#11
0
 public void SynchronousEventCallbackCaller(byte[] a, OperationId b)
 {
     if (SynchronousEvents != null)
     {
         SynchronousEvents(this, a, b);
     }
 }
示例#12
0
        protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan<byte> inBuffer)
        {
            switch (operationId)
            {
                case OperationId.InvalidateCache:
                case OperationId.QueryRange:
                    if (size == 0)
                    {
                        if (operationId == OperationId.QueryRange)
                        {
                            if (outBuffer.Length != Unsafe.SizeOf<QueryRangeInfo>())
                            {
                                return ResultFs.InvalidSize.Log();
                            }

                            Unsafe.As<byte, QueryRangeInfo>(ref outBuffer[0]) = new QueryRangeInfo();
                        }

                        return Result.Success;
                    }

                    Result rc = UpdateSize();
                    if (rc.IsFailure()) return rc;

                    if (size < 0 || offset < 0)
                    {
                        return ResultFs.OutOfRange.Log();
                    }

                    return BaseFile.OperateRange(outBuffer, operationId, offset, size, inBuffer);

                default:
                    return ResultFs.UnsupportedOperationInFileStorageOperateRange.Log();
            }
        }
 public void RemoveOperation(PeriodId periodId, OperationId operationId)
 {
     if (_operations.ContainsKey(periodId.Value))
     {
         _operations[periodId.Value].RemoveAll(o => o.OperationId == operationId.Value);
     }
 }
示例#14
0
        public void GetDocument_GeneratesDocumentWithMultipleMessagesPerChannel()
        {
            // Arrange
            var options           = new AsyncApiOptions();
            var schemaGenerator   = new SchemaGenerator(Options.Create(options));
            var documentGenerator = new DocumentGenerator(Options.Create(options), schemaGenerator);

            // Act
            var document = documentGenerator.GenerateDocument(new [] { typeof(TenantMessageConsumer).GetTypeInfo() });

            // Assert
            document.ShouldNotBeNull();
            document.Channels.Count.ShouldBe(1);

            var channel = document.Channels.First();

            channel.Key.ShouldBe("asw.tenant_service.tenants_history");
            channel.Value.Description.ShouldBe("Tenant events.");

            var subscribe = channel.Value.Subscribe;

            subscribe.ShouldNotBeNull();
            subscribe !.OperationId.ShouldBe("TenantMessageConsumer");
            subscribe.Summary.ShouldBe("Subscribe to domains events about tenants.");

            var messages = subscribe.Message.ShouldBeOfType <Messages>();

            messages.OneOf.Count.ShouldBe(3);

            messages.OneOf.ShouldContain(m => m.Name == "tenantCreated");
            messages.OneOf.ShouldContain(m => m.Name == "tenantUpdated");
            messages.OneOf.ShouldContain(m => m.Name == "tenantRemoved");
        }
示例#15
0
        public void raise_label_changed_if_just_changing_label()
        {
            var period = ChangeSpendingInfo(label: Label.From("coucou"));

            period.UncommittedEvents.GetStream().Should().HaveCount(1).And
            .ContainEquivalentOf(new LabelChanged(OperationId.From(1), Label.From("coucou")),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
示例#16
0
 private static void MakeChanges(Period period, Amount amount = null, Label label = null, Pair pair = null, SpendingCategory category = null)
 {
     period.ChangeSpending(OperationId.From(1),
                           amount ?? Amount.From(10),
                           label ?? Label.From("test"),
                           pair ?? Pair.First,
                           category ?? SpendingCategory.Advance);
 }
示例#17
0
        public void Raise_CategoryChanged_if_just_changing_category()
        {
            var period = ChangeSpendingInfo(category: SpendingCategory.Common);

            period.UncommittedEvents.GetStream().Should().HaveCount(2).And
            .ContainEquivalentOf(new SpendingCategoryChanged(OperationId.From(1), SpendingCategory.Common),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
示例#18
0
        public void RaisePairChangedIfJustChangingPair()
        {
            var period = ChangeSpendingInfo(pair: Pair.Second);

            period.UncommittedEvents.GetStream().Should().HaveCount(2).And
            .ContainEquivalentOf(new PairChanged(OperationId.From(1), Pair.Second),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
示例#19
0
        public void RaiseAmountChangedIfJustChangingAmount()
        {
            var period = ChangeSpendingInfo(amount: Amount.From(5));

            period.UncommittedEvents.GetStream().Should().HaveCount(2).And
            .ContainEquivalentOf(new AmountChanged(OperationId.From(1), Amount.From(5)),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
示例#20
0
 private ICollection GetLoggedOperations(OperationId operationId, LoggingIdentity identity)
 {
     //if (Context.OperationLog != null)
     //{
     //    return Context.OperationLog.GetLoggedOperations(identity,operationId);
     //}
     return(null);
 }
示例#21
0
        protected override AddRequest CreateNewThis()
        {
            AddRequest ar = base.CreateNewThis();

            ar.Attributes.Add(CreateAttribute(OPERATIONID, OperationId.ToString()));

            return(ar);
        }
示例#22
0
 public RecipeAdded(OperationId operationId, Amount amount, Label label, Pair pair, RecipeCategory category)
 {
     Pair        = pair;
     Label       = label;
     Amount      = amount;
     Category    = category;
     OperationId = operationId;
 }
示例#23
0
        public OperationId AddRecipe(Amount amount, Label label, Pair pair, RecipeCategory category)
        {
            var operationId = OperationId.From(State.GetNextOperationId());

            RaiseEvent(new RecipeAdded(operationId, amount, label, pair, category));
            RaiseBalanceChanged();
            return(operationId);
        }
示例#24
0
 private void ChangeOperation(OperationId operationId, Amount amount, Label label, Pair pair, RecipeCategory category)
 {
     ChangeOperation(operationId, amount, label, pair);
     if (State.CategoryNotEquals(operationId, category))
     {
         RaiseEvent(new RecipeCategoryChanged(operationId, category));
     }
 }
 private ICollection GetLoggedOperations(OperationId operationId, LoggingIdentity identity)
 {
     if (Context.OperationLog != null)
     {
         return(Context.OperationLog.GetLoggedOperations(identity, operationId));
     }
     return(null);
 }
示例#26
0
 public void ChangeSpending(OperationId operationId, Amount amount = null, Label label = null, Pair pair = null, SpendingCategory category = null)
 {
     ChangeOperation(operationId, amount, label, pair, category);
     if (UncommitedEventsHaveDifferentEventThatLabelChanged())
     {
         RaiseBalanceChanged();
     }
 }
示例#27
0
 public SpendingAdded(OperationId operationId, Amount amount, Label label, Pair pair, SpendingCategory category)
 {
     Pair        = pair;
     Label       = label;
     Amount      = amount;
     Category    = category;
     OperationId = operationId;
 }
示例#28
0
 public OperationDisposable(TelemetrySessionAggregator session, TelemetryScope <OperationEvent> scope, OperationId operationId, ILogMessage <T> message, CancellationToken token)
 {
     _session     = session;
     _operation   = scope;
     _operationId = operationId;
     _message     = message;
     _token       = token;
 }
示例#29
0
 public void UpdateLastOperationId(OperationId id)
 {
     _lastOpId = id;
     if (_strategy != null)
     {
         _strategy.LastOperationId = id;
     }
 }
示例#30
0
 public void SynchCallback(object sender, byte[] packet, OperationId oid)
 {
     lock (Synch)
     {
         SynchMsg  = Encoding.GetEncoding("Windows-1252").GetString(packet);
         SynchOpId = oid;
         Monitor.PulseAll(Synch);
     }
 }