Ejemplo n.º 1
0
            public override string ToPresentation(CharacteristicObject obj)
            {
                var values = GetPresentableCharacteristics(obj)
                             .Select(c => c.Id + "=" + CharacteristicPresenter.ToPresentation(obj, c));

                return(string.Join(Separator, values));
            }
Ejemplo n.º 2
0
        private void DetachFromOwner(Characteristic thisCharacteristic)
        {
            AssertNotFrozen();
            if (IsPropertyBag)
            {
                throw new InvalidOperationException("The property bag has no owner.");
            }

            if (Owner == null)
            {
                return;
            }

            var oldValues = sharedValues;

            owner        = null;
            sharedValues = new Dictionary <Characteristic, object>();
            frozen       = false;

            oldValues.Remove(thisCharacteristic);
            foreach (var characteristic in GetCharacteristicsToApply())
            {
                if (oldValues.TryGetValue(characteristic, out object value))
                {
                    oldValues.Remove(characteristic);
                    SetValueCore(characteristic, value);
                }
            }
        }
Ejemplo n.º 3
0
        internal override object ResolveValueCore(CharacteristicObject obj, object currentValue)
        {
            if (Resolver == null)
            {
                return((T)base.ResolveValueCore(obj, currentValue));
            }

            return(Resolver(obj, (T)base.ResolveValueCore(obj, currentValue)));
        }
Ejemplo n.º 4
0
            public override string ToPresentation(CharacteristicObject obj, Characteristic characteristic)
            {
                // TODO: DO NOT hardcode Characteristic suffix
                var id    = characteristic.Id;
                var type  = characteristic.DeclaringType.FullName;
                var value = SourceCodeHelper.ToSourceCode(characteristic[obj]);

                return($"{type}.{id}Characteristic[job] = {value}");
            }
Ejemplo n.º 5
0
        public T Resolve <T>(CharacteristicObject obj, Characteristic <T> characteristic)
        {
            var resolver = resolvers.FirstOrDefault(r => r.CanResolve(characteristic));

            if (resolver != null)
            {
                return(resolver.Resolve(obj, characteristic));
            }
            throw new InvalidOperationException($"There is no default resolver for {characteristic.FullId}");
        }
Ejemplo n.º 6
0
        private IEnumerable <Characteristic> GetCharacteristicsToApply(CharacteristicObject other)
        {
            var result = other.GetCharacteristicsToApply();

            if (GetType() != other.GetType() && !IsPropertyBag)
            {
                result = result.Intersect(this.GetAllCharacteristics());
            }

            return(result);
        }
Ejemplo n.º 7
0
            public override string ToPresentation(CharacteristicObject obj, Characteristic characteristic)
            {
                if (characteristic == CharacteristicObject.IdCharacteristic && obj is Job job)
                {
                    return(job.ResolvedId);
                }

                return(obj.HasValue(characteristic)
                    ? ToPresentation(characteristic[obj], characteristic)
                    : "Default");
            }
Ejemplo n.º 8
0
        public T Resolve <T>(CharacteristicObject obj, Characteristic <T> characteristic)
        {
            if (obj.HasValue(characteristic))
            {
                return(characteristic[obj]);
            }

            if (resolvers.TryGetValue(characteristic, out var resolver))
            {
                return((T)resolver(obj));
            }
            throw new InvalidOperationException($"There is no default resolver for {characteristic.FullId}");
        }
Ejemplo n.º 9
0
            public override string ToPresentation(CharacteristicObject obj, Characteristic characteristic)
            {
                if (!obj.HasValue(characteristic))
                {
                    return("Default");
                }

                var value = characteristic[obj];

                return((value as IFormattable)?.ToString(null, HostEnvironmentInfo.MainCultureInfo)
                       ?? value?.ToString()
                       ?? "");
            }
Ejemplo n.º 10
0
        private void SetOwnerCore(CharacteristicObject newOwner)
        {
            if (newOwner == null)
            {
                throw new ArgumentNullException(nameof(newOwner));
            }

            AssertNotFrozen();
            newOwner.AssertIsNonFrozenRoot();

            Owner        = newOwner;
            sharedValues = newOwner.sharedValues;
            frozen       = false;
        }
Ejemplo n.º 11
0
        public object Resolve(CharacteristicObject obj, Characteristic characteristic, object defaultValue)
        {
            if (obj.HasValue(characteristic))
            {
                return(characteristic[obj]);
            }

            if (resolvers.TryGetValue(characteristic, out var resolver))
            {
                return(resolver(obj));
            }

            return(defaultValue);
        }
Ejemplo n.º 12
0
        public object Resolve(CharacteristicObject obj, Characteristic characteristic, object defaultValue)
        {
            if (obj.HasValue(characteristic))
            {
                return(characteristic[obj]);
            }

            var resolver = resolvers.FirstOrDefault(r => r.CanResolve(characteristic));

            if (resolver != null)
            {
                return(resolver.Resolve(obj, characteristic, defaultValue));
            }
            return(defaultValue);
        }
Ejemplo n.º 13
0
        public object Resolve(CharacteristicObject obj, Characteristic characteristic)
        {
            if (obj.HasValue(characteristic))
            {
                return(characteristic[obj]);
            }

            var resolver = resolvers.FirstOrDefault(r => r.CanResolve(characteristic));

            if (resolver != null)
            {
                return(resolver.Resolve(obj, characteristic));
            }
            throw new InvalidOperationException($"There is no default resolver for {characteristic.FullId}");
        }
Ejemplo n.º 14
0
        public object Resolve(CharacteristicObject obj, Characteristic characteristic)
        {
            if (obj.HasValue(characteristic))
            {
                return(characteristic[obj]);
            }

            Func <CharacteristicObject, object> resolver;

            if (resolvers.TryGetValue(characteristic, out resolver))
            {
                return(resolver(obj));
            }
            throw new InvalidOperationException($"There is no default resolver for {characteristic.FullId}");
        }
Ejemplo n.º 15
0
            public override string ToPresentation(CharacteristicObject obj, Characteristic characteristic)
            {
                if (!obj.HasValue(characteristic))
                {
                    return("Default");
                }

                var value = characteristic[obj];

                if (!(value is string) && value is IEnumerable collection)
                {
                    return(ToPresentation(collection));
                }

                return(ToPresentation(value));
            }
Ejemplo n.º 16
0
        protected static string ResolveId(CharacteristicObject obj, string actual)
        {
            if (!string.IsNullOrEmpty(actual) && actual != IdCharacteristic.FallbackValue)
            {
                return(actual);
            }

            string result = CharacteristicSetPresenter.Display.ToPresentation(obj);

            if (result.Length == 0)
            {
                result = IdCharacteristic.FallbackValue;
            }

            return(result);
        }
            public override string ToPresentation(CharacteristicObject obj, Characteristic characteristic)
            {
                if (!obj.HasValue(characteristic))
                {
                    return("Default");
                }

                var value      = characteristic[obj];
                var collection = value as IList;

                if (collection != null)
                {
                    return(ToPresentation(collection));
                }

                return(ToPresentation(value));
            }
        private CharacteristicObject ApplyCore(
            [CanBeNull] CharacteristicObject other,
            [NotNull] IEnumerable <Characteristic> characteristicsToApply)
        {
            AssertNotFrozen();

            if (other == null)
            {
                return(this);
            }

            foreach (var characteristic in characteristicsToApply)
            {
                object value;
                if (!other.sharedValues.TryGetValue(characteristic, out value))
                {
                    continue;
                }

                if (characteristic.HasChildCharacteristics)
                {
                    if (!HasValue(characteristic))
                    {
                        var characteristicObject = (CharacteristicObject)ResolveCore(characteristic, value);
                        if (characteristicObject != null)
                        {
                            value = Activator.CreateInstance(characteristicObject.GetType());
                        }

                        SetValueCore(characteristic, value);
                    }
                }
                else
                {
                    SetValueCore(characteristic, value);
                }
            }

            return(this);
        }
Ejemplo n.º 19
0
        private void AttachToOwner(CharacteristicObject newOwner, Characteristic thisCharacteristic)
        {
            if (newOwner == null)
            {
                throw new ArgumentNullException(nameof(newOwner));
            }
            if (IsPropertyBag)
            {
                throw new InvalidOperationException(
                          $"The property bag {this} cannot be used as characteristic's value.");
            }

            AssertIsNonFrozenRoot();
            newOwner.AssertIsNonFrozenRoot();

            var oldValues = sharedValues;

            newOwner.SetValueOnAttach(thisCharacteristic, this);
            foreach (var pair in oldValues)
            {
                newOwner.SetValueOnAttach(pair.Key, pair.Value);
            }
        }
Ejemplo n.º 20
0
 public void Apply(CharacteristicObject other) => ApplyCore(other);
Ejemplo n.º 21
0
 public abstract string ToPresentation(CharacteristicObject obj, Characteristic characteristic);
Ejemplo n.º 22
0
 protected override IEnumerable <Characteristic> GetPresentableCharacteristics(CharacteristicObject obj, bool includeIgnoreOnApply = false)
 => base.GetPresentableCharacteristics(obj, includeIgnoreOnApply)
 .Where(characteristic => !NonExportableTypes.Contains(characteristic.CharacteristicType));
Ejemplo n.º 23
0
 public override string ToPresentation(CharacteristicObject obj)
 => string.Join(Separator,
                GetPresentableCharacteristics(obj, includeIgnoreOnApply: true)
                .Select(c => CharacteristicPresenter.ToPresentation(obj, c)));
Ejemplo n.º 24
0
 protected virtual IEnumerable <Characteristic> GetPresentableCharacteristics(CharacteristicObject obj, bool includeIgnoreOnApply = false) =>
 obj
 .GetCharacteristicsWithValues()
 .Where(c => c.IsPresentableCharacteristic(includeIgnoreOnApply));
Ejemplo n.º 25
0
 public T ApplyAndFreeze(CharacteristicObject other) => Apply(other).Freeze();
Ejemplo n.º 26
0
 public new T Apply(CharacteristicObject other) => (T)ApplyCore(other);
Ejemplo n.º 27
0
 internal virtual object ResolveValueCore(CharacteristicObject obj, object currentValue) =>
 ReferenceEquals(currentValue, EmptyValue) ? FallbackValue : currentValue;
Ejemplo n.º 28
0
 public new T this[CharacteristicObject obj]
 {
     get { return(obj.GetValue(this)); }
     set { obj.SetValue(this, value); }
 }
Ejemplo n.º 29
0
 public override string ToPresentation(CharacteristicObject obj, Characteristic characteristic)
 {
     return(obj.HasValue(characteristic)
         ? FolderNameHelper.ToFolderName(characteristic[obj])
         : "Default");
 }
Ejemplo n.º 30
0
 protected CharacteristicObject ApplyCore(CharacteristicObject other) =>
 ApplyCore(
     other,
     GetCharacteristicsToApply(other));