Exemplo n.º 1
0
 public PartConversionVm(Unit unit, PartConversion conversion)
 {
     this.unit       = unit;
     this.Conversion = conversion;
     this.IsEditable = this.Conversion.Name != unit.Name;
     unit.PartConversions.ObservePropertyChangedSlim()
     .Subscribe(_ => this.OnPropertyChanged(nameof(this.IsUsed)));     // no need for IDisposable
 }
Exemplo n.º 2
0
        public void SetUnit(Unit value)
        {
            this.unit = value;
            this.conversions.Clear();

            if (this.unit == null)
            {
                this.OnPropertyChanged(nameof(this.HasItems));
                return;
            }

            if (this.unit.Parts.BaseParts.Count == 1)
            {
                var part = this.unit.Parts.BaseParts.Single();
                if (part.Power == 1)
                {
                    return;
                }
                var unitParts  = this.unit.Parts.BaseParts.ToArray();
                var powerParts = CreatePowerParts(unitParts, 0);

                var partConversionVms = powerParts.Select(x => new PartConversionVm(this.unit, PartConversion.Create(this.unit, x)))
                                        .ToArray();
                if (partConversionVms.Any())
                {
                    this.conversions.Add(partConversionVms);
                }
            }

            else if (this.unit.Parts.Count == 2)
            {
                var unitParts = this.unit.Parts.ToArray();
                var p0s       = CreatePowerParts(unitParts, 0);
                var p1s       = CreatePowerParts(unitParts, 1);
                foreach (var c1 in p0s)
                {
                    var cs = new List <PartConversionVm>();

                    foreach (var c2 in p1s)
                    {
                        cs.Add(new PartConversionVm(this.unit, PartConversion.Create(this.unit, c1, c2)));
                    }

                    var conversionVms = cs.ToArray();
                    if (conversionVms.Any())
                    {
                        this.conversions.Add(conversionVms);
                    }
                }
            }

            this.OnPropertyChanged(nameof(this.HasItems));
        }
Exemplo n.º 3
0
        private bool IsMatch(PartConversion x)
        {
            if (this.Conversion.Factor != x.Factor)
            {
                return(false);
            }

            if (this.Conversion.Name != x.Name)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        private bool IsMatch(PartConversion x)
        {
            //// ReSharper disable once CompareOfFloatsByEqualityOperator
            if (((PartConversion)this.Conversion).Factor != x.Factor)
            {
                return(false);
            }

            if (this.Conversion.Name != x.Name)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
 public PartConversionVm(Unit unit, PartConversion conversion)
     : base(conversion)
 {
     this.unit       = unit;
     this.IsEditable = this.Conversion.Name != unit.Name;
     this.disposable = new CompositeDisposable
     {
         unit.PartConversions.ObservePropertyChangedSlim()
         .SubscribeOn(TaskPoolScheduler.Default)
         .Subscribe(_ => this.OnPropertyChanged(nameof(this.IsUsed))),
         conversion.ObservePropertyChanged(x => x.Symbol)
         .SubscribeOn(TaskPoolScheduler.Default)
         .Where(_ => this.IsUsed)
         .SubscribeAsync(() => this.UpdateAsync()),
     };
 }