Exemplo n.º 1
0
        private void FinishJob(IJobResult jobResult)
        {
            var nextOperation = OperationManager.GetNextOperation(key: jobResult.Key);

            if (nextOperation != null)
            {
                nextOperation.StartConditions.PreCondition = true;
                Agent.DebugMessage(msg: $"PreCondition for operation {nextOperation.Operation.Name} at {_articleToProduce.Article.Name} was set true.");
                Agent.Send(instruction: BasicInstruction.UpdateStartConditions.Create(message: nextOperation.GetStartCondition(), target: nextOperation.HubAgent));
                return;
            }

            Agent.DebugMessage(msg: $"All operations for article {_articleToProduce.Article.Name} {_articleToProduce.Key} finished.");

            //TODO add production amount to productionresult, currently static 1
            var productionResponse = new FProductionResult(key: _articleToProduce.Key
                                                           , trackingId: _articleToProduce.StockExchangeId
                                                           , creationTime: 0
                                                           , amount: 1);

            Agent.Send(instruction: Storage.Instruction.ResponseFromProduction.Create(message: productionResponse, target: _articleToProduce.StorageAgent));

            if (_articleToProduce.IsHeadDemand)
            {
                var pub = new FThroughPutTime(articleKey: _articleToProduce.Key
                                              , articleName: _articleToProduce.Article.Name
                                              , start: _articleToProduce.CreationTime
                                              , end: Agent.CurrentTime);
                Agent.Context.System.EventStream.Publish(@event: pub);
            }
            Agent.TryToFinish();
        }
        private void ResponseFromProduction(FProductionResult productionResult)
        {
            Agent.DebugMessage(msg: $"{productionResult.Amount} {_stockElement.Article.Name} was send from {Agent.Sender.Path.Name}");

            // Add the Produced item to Stock
            _stockElement.Current += productionResult.Amount;
            LogValueChange(article: _stockElement.Article, value: Convert.ToDouble(value: _stockElement.Current) * Convert.ToDouble(value: _stockElement.Article.Price));


            var stockExchange = new T_StockExchange
            {
                StockId              = _stockElement.Id,
                ExchangeType         = ExchangeType.Insert,
                Quantity             = productionResult.Amount,
                State                = State.Finished,
                RequiredOnTime       = (int)Agent.CurrentTime,
                Time                 = (int)Agent.CurrentTime,
                ProductionArticleKey = productionResult.Key
            };

            _stockElement.StockExchanges.Add(item: stockExchange);

            _providerList.Add(item: stockExchange);
            // Check if the most Important Request can be provided.
            var mostUrgentRequest = _requestedArticles.First(predicate: x => x.DueTime == _requestedArticles.Min(selector: r => r.DueTime));

            //TODO: might be a problem
            if (mostUrgentRequest.IsHeadDemand && mostUrgentRequest.DueTime > Agent.CurrentTime)
            {
                Agent.DebugMessage(msg: $"{_stockElement.Article.Name} {mostUrgentRequest.Key} finished before due. CostumerOrder {mostUrgentRequest.CustomerOrderId} will ask at {mostUrgentRequest.DueTime} for article.");
                return;
            }
            // else if
            if (mostUrgentRequest.Quantity <= _stockElement.Current)
            {
                Agent.DebugMessage(msg: $"{_stockElement.Article.Name} {mostUrgentRequest.Key} is providable {mostUrgentRequest.Quantity} does match current Stock amount of {_stockElement.Current}.");
                ProvideArticle(articleKey: mostUrgentRequest.Key);
            }
        }
 public static ResponseFromProduction Create(FProductionResult message, IActorRef target)
 {
     return(new ResponseFromProduction(message: message, target: target));
 }