Beispiel #1
0
        public ItemViewModel(Item item)
            : base(item, DomainObjectRepositories.ItemRepository)
        {
            _transient = true;
            _metaData  = ItemMetaDataProvider.GetMetaData(item);
            //_metaData.Refreshed += (sender, args) => UpdateMetaDataProperties();

            item.ObjectSaved += (sender, args) =>
            {
                UpdateMetaDataProperties();
            };

            UpdateMetaDataProperties();

            MadeFrom = new RecipeCollectionViewModel(item.MadeFrom, item);
            foreach (var i in MadeFrom.Collection)
            {
                i.PropertyChanged += (sender, args) =>
                {
                    if (args.PropertyName == nameof(UnitCost))
                    {
                        _metaData.Recalculate();
                        UpdateMetaDataProperties();
                    }
                };
            }

            UsedIn = new RecipeCollectionViewModel(item.UsedIn);

            var primaryRecipe = item.MadeFrom.FirstOrDefault();

            if (primaryRecipe != null)
            {
                PrimarySourceRecipe = new RecipeViewModel(primaryRecipe);
            }


            MarketObservationCollection = new MarketObservationCollectionViewModel(item.AllMarketData, item);
            MarketObservationCollection.Collection.CollectionChanged += MarketObservationCollection_CollectionChanged;

            if (item.CurrentMarketData != null)
            {
                MostRecentMarketObservation = new MarketObservationViewModel(item.CurrentMarketData);
            }
            else
            {
                MessageLog.GetLog().LogMessage($"Couldn't find any market data for {item.Name}");
            }

            MarketCategories = CollectionHelper.MarketCategories;
            _transient       = item.Id == Guid.Empty;
        }
Beispiel #2
0
 void MarketObservationCollection_CollectionChanged(object sender,
                                                    NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
 {
     if (notifyCollectionChangedEventArgs.Action == NotifyCollectionChangedAction.Add)
     {
         if (DomainObject.CurrentMarketData != null)
         {
             MostRecentMarketObservation = new MarketObservationViewModel(DomainObject.CurrentMarketData);
             //this doesn't actually save the object, despite the incredibly straightforward name of the method
             DomainObject.Save();
         }
     }
     //Recalculate();
     //RefreshHelper.NotifyChanged(DomainObject);
 }
Beispiel #3
0
        public void RefreshMarket()
        {
            _transient = true;
            MessageLog.GetLog().LogMessage($"Refreshing market data for {DomainObject.Name}");
            MarketObservationCollection.Collection.CollectionChanged -= MarketObservationCollection_CollectionChanged;
            MarketObservationCollection = new MarketObservationCollectionViewModel(DomainObject.AllMarketData, DomainObject);
            MarketObservationCollection.Collection.CollectionChanged += MarketObservationCollection_CollectionChanged;

            if (DomainObject.CurrentMarketData != null)
            {
                MostRecentMarketObservation = new MarketObservationViewModel(DomainObject.CurrentMarketData);
            }
            else
            {
                MessageLog.GetLog().LogMessage($"Couldn't find any market data for {DomainObject.Name}");
            }
            UpdateMetaDataProperties();
            _transient = false;
        }