コード例 #1
0
        private void Calculate(object arg)
        {
            var materials = new List <RawMaterial> {
                InputA, InputB
            };

            if (InputC != null)
            {
                materials.Add(InputC);
            }

            TargetProduct.OutputBatchSize = ProductionHelper.GetOutputBatchSize(ProductionLevel);
            TargetProduct.ExportCost      = ProductionHelper.GetExportCost(ProductionLevel, AverageTax);
            foreach (var material in materials)
            {
                material.ImportCost     = ProductionHelper.GetImportCost(material.InputLevel, AverageTax);
                material.InputBatchSize = ProductionHelper.GetInputBatchSize(material.InputLevel);
            }

            var result = ProductionHelper.Calculate(TargetProduct, materials, BatchSize);

            InputQuantity  = result.InputQuantity;
            OutputQuantity = result.OutputQuantity;
            SaleCost       = result.SaleCost;
            Expenses       = result.Expenses;
            PurchaseCost   = result.PurchaseCost;
            ProfitMargin   = result.ProfitMargin;

            RaisePropertyChanged("InputQuantity");
            RaisePropertyChanged("OutputQuantity");
            RaisePropertyChanged("SaleCost");
            RaisePropertyChanged("PurchaseCost");
            RaisePropertyChanged("Expenses");
            RaisePropertyChanged("ProfitMargin");
            RaisePropertyChanged("RequiresThirdInput");
        }
コード例 #2
0
        private void Analyze(IProgress <AnalysisResult> progress)
        {
            int index     = 0;
            var itemTasks = new List <Task>();

            foreach (var item in AnalysisItems)
            {
                itemTasks.Add(Task.Factory.StartNew(() =>
                {
                    using (MarketDataHelper helper = new MarketDataHelper(MarketDataHelper.QuickLook))
                    {
                        MarketDataRequest request = new MarketDataRequest
                        {
                            TypeId   = item.Product.ItemId.ToString(),
                            SystemId = MarketDataHelper.Jita,
                            Duration = MarketDataHelper.Freshness
                        };

                        var productData = helper.GetData(request);
                        MarketDataResponse.ResequenceOrders(productData);
                        var order                    = productData.HighestBuyOrder;
                        item.Product.Price           = order != null ? order.Price : 0.0;
                        item.Product.ExportCost      = ProductionHelper.GetExportCost(ProductionLevel);
                        item.Product.OutputBatchSize = ProductionHelper.GetOutputBatchSize(ProductionLevel);
                        item.Product.Data            = productData;

                        foreach (var input in item.Materials)
                        {
                            request = new MarketDataRequest
                            {
                                TypeId   = input.ItemId.ToString(),
                                Duration = MarketDataHelper.Freshness,
                                SystemId = MarketDataHelper.Jita
                            };

                            var materialData = helper.GetData(request);
                            MarketDataResponse.ResequenceOrders(materialData);
                            order                = materialData.LowestSellOrder(null);
                            input.Price          = order != null ? order.Price : 0.0;
                            input.ImportCost     = ProductionHelper.GetImportCost(input.InputLevel);
                            input.InputBatchSize = ProductionHelper.GetInputBatchSize(input.InputLevel);
                            input.Data           = materialData;
                        }

                        var productionResult = ProductionHelper.Calculate(item.Product, item.Materials);
                        item.ProductionCost  = productionResult.PurchaseCost;
                        item.SaleValue       = productionResult.SaleCost;
                        item.ProfitMargin    = productionResult.ProfitMargin;
                        item.UpdateProperties();

                        var currentProgress = ((double)++index / AnalysisItems.Count) * 100;

                        progress.Report(new AnalysisResult
                        {
                            ProgressIndex = (int)currentProgress,
                            Item          = item
                        });

                        Task.Delay(2000).Wait();
                    }
                }, TaskCreationOptions.AttachedToParent));
            }

            Task.Factory.ContinueWhenAll(itemTasks.ToArray(), groupedTasks => {
            });
        }