public override string ToPresentation(JobMode jobMode)
            {
                var values = GetPresentableCharacteristics(jobMode, withDontClone: true)
                             .Select(c => CharacteristicPresenter.ToPresentation(jobMode, c));

                return(string.Join(Separator, values));
            }
            public override string ToPresentation(JobMode jobMode)
            {
                var values = GetPresentableCharacteristics(jobMode)
                             .Select(c => c.Id + EqualsSeparator + CharacteristicPresenter.ToPresentation(jobMode, c));

                return(string.Join(Separator, values));
            }
            public override string ToPresentation(JobMode jobMode)
            {
                var values = GetPresentableCharacteristics(jobMode, includeIgnoreOnApply: true)
                             .Select(c => CharacteristicPresenter.ToPresentation(jobMode, c));

                return(string.Join(Separator, values));
            }
Exemple #4
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())
            {
                object value;
                if (oldValues.TryGetValue(characteristic, out value))
                {
                    oldValues.Remove(characteristic);
                    SetValueCore(characteristic, value);
                }
            }
        }
            public override string ToPresentation(JobMode jobMode, Characteristic characteristic)
            {
                // TODO: DO NOT hardcode Characteristic suffix
                var id    = characteristic.Id;
                var type  = characteristic.DeclaringType.FullName;
                var value = SourceCodeHelper.ToSourceCode(characteristic[jobMode]);

                return($"{type}.{id}Characteristic[job] = {value}");
            }
Exemple #6
0
        internal override object ResolveValueCore(JobMode obj, object currentValue)
        {
            if (Resolver == null)
            {
                return((T)base.ResolveValueCore(obj, currentValue));
            }

            return(Resolver(obj, (T)base.ResolveValueCore(obj, currentValue)));
        }
        public T Resolve <T>(JobMode jobMode, Characteristic <T> characteristic)
        {
            var resolver = resolvers.FirstOrDefault(r => r.CanResolve(characteristic));

            if (resolver != null)
            {
                return(resolver.Resolve(jobMode, characteristic));
            }
            throw new InvalidOperationException($"There is no default resolver for {characteristic.FullId}");
        }
Exemple #8
0
        private IEnumerable <Characteristic> GetCharacteristicsToApply(JobMode other)
        {
            var result = other.GetCharacteristicsToApply();

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

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

                var value = characteristic[jobMode];

                return((value as IFormattable)?.ToString(null, HostEnvironmentInfo.MainCultureInfo)
                       ?? value?.ToString()
                       ?? "");
            }
Exemple #10
0
        private void SetOwnerCore(JobMode newOwnerJob)
        {
            if (newOwnerJob == null)
            {
                throw new ArgumentNullException(nameof(newOwnerJob));
            }

            AssertNotFrozen();
            newOwnerJob.AssertIsNonFrozenRoot();

            owner        = newOwnerJob;
            sharedValues = newOwnerJob.sharedValues;
            frozen       = false;
        }
Exemple #11
0
        public T Resolve <T>(JobMode jobMode, Characteristic <T> characteristic)
        {
            if (jobMode.HasValue(characteristic))
            {
                return(characteristic[jobMode]);
            }

            Func <object> resolver;

            if (resolvers.TryGetValue(characteristic, out resolver))
            {
                return((T)resolver());
            }
            throw new InvalidOperationException($"There is no default resolver for {characteristic.FullId}");
        }
Exemple #12
0
        protected static string ResolveId(JobMode obj, string actual)
        {
            if (!string.IsNullOrEmpty(actual) && actual != IdCharacteristic.FallbackValue)
            {
                return(actual);
            }

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

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

            return(result);
        }
Exemple #13
0
        private JobMode ApplyCore(
            [CanBeNull] JobMode 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 jobMode = (JobMode)ResolveCore(characteristic, value);
                        if (jobMode != null)
                        {
                            value = Activator.CreateInstance(jobMode.GetType());
                        }

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

            return(this);
        }
Exemple #14
0
        private JobMode ApplyCore(
            JobMode other,
            IEnumerable <Characteristic> characteristicsToApply)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }
            AssertNotFrozen();

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

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

                        SetValueCore(characteristic, value);
                    }
                }
                else if (!characteristic.DontClone)
                {
                    SetValueCore(characteristic, value);
                }
            }

            return(this);
        }
Exemple #15
0
        private void AttachToOwner(JobMode newOwnerJob, Characteristic thisCharacteristic)
        {
            if (newOwnerJob == null)
            {
                throw new ArgumentNullException(nameof(newOwnerJob));
            }
            if (IsPropertyBag)
            {
                throw new InvalidOperationException(
                          $"The property bag {this} cannot be used as characteristic's value.");
            }

            AssertIsNonFrozenRoot();
            newOwnerJob.AssertIsNonFrozenRoot();

            var oldValues = sharedValues;

            newOwnerJob.SetValueOnAttach(thisCharacteristic, this);
            foreach (var pair in oldValues)
            {
                newOwnerJob.SetValueOnAttach(pair.Key, pair.Value);
            }
        }
 public abstract string ToPresentation(JobMode jobMode, Characteristic characteristic);
 public override string ToPresentation(JobMode jobMode, Characteristic characteristic)
 {
     return(jobMode.HasValue(characteristic)
         ? characteristic[jobMode]?.ToString() ?? ""
         : "Default");
 }
 public abstract string ToPresentation(JobMode jobMode);
 public static IReadOnlyList <Characteristic> GetAllCharacteristics(this JobMode obj) =>
 GetAllCharacteristics(obj.GetType());
Exemple #20
0
 internal virtual object ResolveValueCore(JobMode obj, object currentValue) =>
 ReferenceEquals(currentValue, EmptyValue) ? FallbackValue : currentValue;
Exemple #21
0
 public new T this[JobMode obj]
 {
     get { return(obj.GetValue(this)); }
     set { obj.SetValue(this, value); }
 }
 protected virtual IEnumerable <Characteristic> GetPresentableCharacteristics(JobMode jobMode, bool withDontClone = false) =>
 jobMode
 .GetCharacteristicsWithValues()
 .Where(c => c.IsPresentableCharacteristic(withDontClone));
Exemple #23
0
 protected JobMode()
 {
     owner        = null;
     sharedValues = new Dictionary <Characteristic, object>();
 }
 public CharacteristicSet(JobMode other)
 {
     Apply(other);
 }
Exemple #25
0
 protected JobMode ApplyCore(JobMode other) =>
 ApplyCore(
     other,
     GetCharacteristicsToApply(other));
Exemple #26
0
 public void Apply(JobMode other) => ApplyCore(other);
 public override string ToPresentation(JobMode jobMode, Characteristic characteristic)
 {
     return(jobMode.HasValue(characteristic)
         ? FolderNameHelper.ToFolderName(characteristic[jobMode])
         : "Default");
 }
 protected virtual IEnumerable <Characteristic> GetPresentableCharacteristics(JobMode jobMode, bool includeIgnoreOnApply = false) =>
 jobMode
 .GetCharacteristicsWithValues()
 .Where(c => c.IsPresentableCharacteristic(includeIgnoreOnApply));