Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObservableValue{T}"/> class.
 /// </summary>
 /// <param name="sharedState">The shared state this Observable will be attached to.</param>
 /// <param name="name">The name of this observable value.</param>
 /// <param name="enhancer">The enhancer to use on the type.</param>
 /// <param name="value">The initial value of the Observable.</param>
 public ObservableValue(ISharedState sharedState, string name, IEnhancer enhancer, T value = default)
     : base(
         sharedState ?? throw new ArgumentNullException(nameof(sharedState)),
         string.IsNullOrEmpty(name) ? $"{nameof(ObservableValue<T>)}@{sharedState.GetUniqueId()}" : name)
 {
     this.enhancer = enhancer ?? throw new ArgumentNullException(nameof(enhancer));
     this.value    = this.enhancer.Enhance(value, default, this.Name);
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObservableCollection{T}"/> class.
        /// </summary>
        /// <param name="sharedState">The <see cref="ISharedState"/> instance this observableCollection belongs to.</param>
        /// <param name="enhancer">The <see cref="IEnhancer"/> implementation to use.</param>
        /// <param name="name">The name of the ObservableCollection.</param>
        /// <param name="initialValues">The initial values to use.</param>
        public ObservableCollection(ISharedState sharedState, IEnhancer enhancer, IEnumerable <T> initialValues, string name = null)
        {
            this.SharedState = sharedState ?? throw new ArgumentNullException(nameof(sharedState));
            this.enhancer    = enhancer ?? throw new ArgumentNullException(nameof(enhancer));

            if (string.IsNullOrEmpty(name))
            {
                name = $"{nameof(ObservableCollection<T>)}@{this.SharedState.GetUniqueId()}";
            }

            this.Name      = name;
            this.innerList = initialValues != null ? new List <T>(initialValues) : new List <T>();
            this.atom      = new Atom(sharedState, name);
        }
Exemple #3
0
 public Enhancement(string title, string description, string changedParameter,
                    string changedOldValue, string changedNewValue, IEnhancer enhancer
                    )
 {
     this.Title       = title;
     this.Description = description;
     this.Changed     = new Enhancers.Enhancement.Change()
     {
         ParameterName = changedParameter,
         PreviousValue = changedOldValue,
         NewValue      = changedNewValue
     };
     this.EnhancerType = enhancer.GetType().FullName;
 }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObservableDictionary{TKey, TValue}"/> class.
        /// </summary>
        /// <param name="sharedState">The <see cref="ISharedState"/> instance this observableDictionary belongs to.</param>
        /// <param name="enhancer">The <see cref="IEnhancer"/> implementation to use.</param>
        /// <param name="initialValues">The initial values.</param>
        /// <param name="name">The name of the ObservableDictionary.</param>
        public ObservableDictionary(ISharedState sharedState, IEnhancer enhancer, IDictionary <TKey, TValue> initialValues, string name = null)
        {
            this.SharedState = sharedState ?? throw new ArgumentNullException(nameof(sharedState));
            this.enhancer    = enhancer ?? throw new ArgumentNullException(nameof(enhancer));

            if (string.IsNullOrEmpty(name))
            {
                name = $"{nameof(ObservableDictionary<TKey, TValue>)}@{this.SharedState.GetUniqueId()}";
            }

            this.Name            = name;
            this.innerDictionary = initialValues != null ? new Dictionary <TKey, TValue>(initialValues) : new Dictionary <TKey, TValue>();
            this.hasDictionary   = new Dictionary <TKey, ObservableValue <bool> >();

            this.atom = new Atom(sharedState, name);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ObservableObject"/> class.
        /// </summary>
        /// <param name="sharedState">The shared state for this ObservableObject.</param>
        /// <param name="name">The name of the objservable ovject.</param>
        /// <param name="defaultEnhancer">The default enhancer to use for newly created values.</param>
        /// <param name="values">A dictionary with values.</param>
        public ObservableObject(string name, IEnhancer defaultEnhancer, ISharedState sharedState, IDictionary <string, IValue> values = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (values is null)
            {
                this.values = new Dictionary <string, IValue>();
            }
            else
            {
                this.values = values;
            }

            this.Name            = name;
            this.defaultEnhancer = defaultEnhancer ?? throw new ArgumentNullException(nameof(defaultEnhancer));
            this.SharedState     = sharedState;
        }
Exemple #6
0
 public Serializers(IEnhancer enhancer, ISerializers serializers)
     : base(new AlteredSource <TypeInfo, ISerializer>(enhancer, serializers))
 {
 }
Exemple #7
0
        public static List <IEnhancer> GetEnhancers(string moreFromPath = null)
        {
            if (enhancers != null)
            {
                return(enhancers);
            }

            lock (objLock)
            {
                if (enhancers != null)
                {
                    return(enhancers);
                }

                ////load DLL's from disk
                List <System.Reflection.Assembly> dlls = new List <System.Reflection.Assembly>();
                string pathForDlls = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                foreach (var file in System.IO.Directory.EnumerateFiles(pathForDlls, "*plugin*.dll"))
                {
                    try
                    {
                        string filename = System.IO.Path.GetFileNameWithoutExtension(file);
                        dlls.Add(System.Reflection.Assembly.Load(filename));
                    }
                    catch (Exception)
                    {
                    }
                }



                var typeI = typeof(IEnhancer);
                List <System.Type> types = null;
                try
                {
                    types = AppDomain.CurrentDomain.GetAssemblies()
                            .Union(dlls)
                            .SelectMany(s => s.GetTypes())
                            .Where(p =>
                                   typeI.IsAssignableFrom(p) &&
                                   p.IsAbstract == false
                                   )
                            .ToList();
                }
                catch (System.Reflection.ReflectionTypeLoadException lex)
                {
                    StringBuilder sb = new StringBuilder();
                    if (lex.LoaderExceptions != null)
                    {
                        foreach (Exception ex in lex.LoaderExceptions)
                        {
                            sb.AppendFormat("{0}\n----------------\n", ex.ToString());
                        }
                    }

                    HlidacStatu.Util.Consts.Logger.Fatal("Cannot make list of enhancer instances, reason: " + sb.ToString(), lex);
                }
                catch (Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Fatal("Cannot make list of enhancer instances ", e);

                    throw;
                }

                var ps = new List <IEnhancer>();
                foreach (var type in types)
                {
                    try
                    {
                        IEnhancer parser = (IEnhancer)Activator.CreateInstance(type);
                        ps.Add(parser);
                        if (parser.Name == "FormalNormalizer")
                        {
                            //parser.SetInstanceData(StaticData.CiziStaty);
                        }

                        HlidacStatu.Util.Consts.Logger.Info("Creating instance of enhancer plugin " + type.FullName);
                    }
                    catch (Exception)
                    {
                        //NoveInzeraty.Lib.Constants.NIRoot.Error("Cannot make instance of parser " + type.FullName, e);
                    }
                }
                enhancers = ps;

                return(enhancers);
            }
        }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObservableCollection{T}"/> class.
 /// </summary>
 /// <param name="sharedState">The <see cref="ISharedState"/> instance this observableCollection belongs to.</param>
 /// <param name="enhancer">The <see cref="IEnhancer"/> implementation to use.</param>
 /// <param name="name">The name of the ObservableCollection.</param>
 public ObservableCollection(ISharedState sharedState, IEnhancer enhancer, string name = null)
     : this(sharedState, enhancer, null, name)
 {
 }
 public void InjectGearData(IEnhancer enhcer)
 {
     MyEnhencer = enhcer;
 }
 public Contents(IEnhancer enhancer, IContents contents)
     : base(new AlteredSource <TypeInfo, ISerializer>(enhancer, contents))
 {
 }
Exemple #11
0
        /// <summary>
        /// Boxes the value T inside an <see cref="IObservableValue{T}" /> instance.
        /// </summary>
        /// <typeparam name="T">The type to box.</typeparam>
        /// <param name="sharedState">The shared state to operate on.</param>
        /// <param name="initialValue">The initial value to use.</param>
        /// <param name="name">The name of the observable value.</param>
        /// <param name="enhancer">The optional enhancer to use. default enhancer is the referenceEnhancer.</param>
        /// <returns>The observable.</returns>
        public static IObservableValue <T> Box <T>(this ISharedState sharedState, T initialValue, string name = null, IEnhancer enhancer = null)
        {
            if (sharedState is null)
            {
                throw new ArgumentNullException(nameof(sharedState));
            }

            if (enhancer is null)
            {
                enhancer = sharedState.ReferenceEnhancer();
            }

            if (string.IsNullOrEmpty(name))
            {
                name = $"{nameof(ObservableValue<T>)}@{sharedState.GetUniqueId()}";
            }

            return(new ObservableValue <T>(sharedState, name, enhancer, initialValue));
        }
Exemple #12
0
        /// <summary>
        /// Creates an observable Dictionary from an initial dictionary.
        /// </summary>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="sharedState">The shared state to operate on.</param>
        /// <param name="initialValues">The initial values to use.</param>
        /// <param name="name">The name of the observable collection.</param>
        /// <param name="enhancer">The optional enhancer to use. default enhancer is the deep enhancer.</param>
        /// <returns>The observable.</returns>
        public static IDictionary <TKey, TValue> Dictionary <TKey, TValue>(this ISharedState sharedState, IDictionary <TKey, TValue> initialValues = null, string name = null, IEnhancer enhancer = null)
        {
            if (sharedState is null)
            {
                throw new ArgumentNullException(nameof(sharedState));
            }

            if (enhancer is null)
            {
                enhancer = sharedState.DeepEnhancer();
            }

            if (string.IsNullOrEmpty(name))
            {
                name = $"{nameof(ObservableDictionary<TKey, TValue>)}@{sharedState.GetUniqueId()}";
            }

            return(new ObservableDictionary <TKey, TValue>(sharedState, enhancer, initialValues, name));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ObservableValue{T}"/> class.
 /// </summary>
 /// <param name="sharedState">The shared state this Observable will be attached to.</param>
 /// <param name="name">The name of this observable value.</param>
 /// <param name="enhancer">The enhancer to use on the type.</param>
 /// <param name="value">The initial value of the Observable.</param>
 public ObservableValue(ISharedState sharedState, string name, IEnhancer enhancer, T value = default)
     : base(sharedState, name)
 {
     this.enhancer = enhancer ?? throw new ArgumentNullException(nameof(enhancer));
     this.value    = this.enhancer.Enhance(value, default, this.Name);
Exemple #14
0
 public void SelectEnhancer(IEnhancer enhancer)
 {
     UnselectEnhancer();
     m_Enhancer = enhancer;
 }
Exemple #15
0
 void UnselectEnhancer()
 {
     m_Enhancer = null;
     OnSelectEnhcer();
 }