/// <summary>
        /// Adds <see cref="Array1DPropertyObject"/> or <see cref="Array2DPropertyObject"/>
        /// Throws <see cref="NotSupportedException"/> if <see cref="System.Array"/> of <see cref="System.Array.Rank"/> greater than 2 is given
        /// </summary>
        /// <param name="name"></param>
        /// <param name="a"></param>
        /// <param name="propertyBuilder"></param>
        /// <returns></returns>
        public PropertyContainerBuilder Array(string name, Array a, Action <PropertyObjectBuilder> propertyBuilder = null)
        {
            if (config.ContainsData(name))
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {name}");

                return(this);
            }

            if (a.GetType().GetElementType().IsPrimitive == false)
            {
                throw new NotSupportedException("Arrays of non primitive types not supported");
            }

            PropertyObject obj = null;

            if (a.Rank == 1)
            {
                obj = new Array1DPropertyObject(name, a);
            }
            else if (a.Rank == 2)
            {
                obj = new Array2DPropertyObject(name, a);
            }
            else
            {
                throw new NotSupportedException("Arrays of more than 2 dimensions not supported");
            }

            propertyBuilder?.Invoke(new PropertyObjectBuilder(obj));

            config.Add(obj);

            return(this);
        }
        /// <summary>
        /// Creates a DataObject implementation that serializes to <paramref name="format"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="format"></param>
        /// <param name="propertyBuilder"></param>
        /// <returns></returns>
        public PropertyContainerBuilder Property <T>(string name, T value, SerializationFormat format, Action <PropertyObjectBuilder> propertyBuilder = null)
            where T : class, new()
        {
            if (config.ContainsData(name) || value is null)
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {name}");

                return(this);
            }

            PropertyObject obj;

            if (format == SerializationFormat.Container)
            {
                obj = DataObjectFactory.GetPropertyObjectFor(name, value);
            }
            else if (format == SerializationFormat.Json)
            {
                obj = new JsonPropertyObject(name, value);
            }
            else if (format == SerializationFormat.Xml)
            {
                obj = new XmlPropertyObject(name, value);
            }
            else
            {
                throw new NotImplementedException();
            }

            propertyBuilder?.Invoke(new PropertyObjectBuilder(obj));

            config.Add(obj);

            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a DataObject for storing CLR objects based on <paramref name="format"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public DataContainerBuilder Data <T>(string name, T value, SerializationFormat format)
            where T : class, new()
        {
            if (config.ContainsData(name) || value is null)
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {name}");

                return(this);
            }

            DataObject obj;

            if (format == SerializationFormat.Container)
            {
                obj = DataObjectFactory.GetDataObjectFor(name, value);
            }
            else if (format == SerializationFormat.Json)
            {
                obj = new JsonDataObject(name, value);
            }
            else if (format == SerializationFormat.Xml)
            {
                obj = new XmlDataObject(name, value);
            }
            else
            {
                throw new NotImplementedException();
            }

            config.Add(obj);

            return(this);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Method to add password data, need separate function to avoid ambiguity between <see cref="StringDataObject"/>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public DataContainerBuilder Password(string name, string value)
        {
            if (config.ContainsData(name) || value is null || string.IsNullOrWhiteSpace(value.ToString()))
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {name}");

                return(this);
            }

            config.Add(new PasswordDataObject(name, value));

            return(this);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Generic method to add <see cref="DataObject"/> based on <see cref="Type"/> of <paramref name="value"/>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public DataContainerBuilder Data(string name, object value)
        {
            if (config.ContainsData(name) || value is null)
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {name}");

                return(this);
            }

            config.Add(DataObjectFactory.GetDataObjectFor(name, value));

            return(this);
        }
        /// <summary>
        /// Create a nested property container.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="containerBuilder"></param>
        /// <returns></returns>
        public PropertyContainerBuilder PropertyContainer(string name, Action <PropertyContainerBuilder> containerBuilder)
        {
            if (config.ContainsData(name))
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {name}");
            }

            var builder = Create(name);

            containerBuilder?.Invoke(builder);

            config.Add(new ContainerPropertyObject(name, builder.Build()));

            return(this);
        }
        /// <summary>
        /// Adds <see cref="FolderPropertyObject"/>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public PropertyContainerBuilder Folder(string name, string value, Action <PropertyObjectBuilder> propertyBuilder = null)
        {
            if (config.ContainsData(name))
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {name}");

                return(this);
            }

            var obj = new FolderPropertyObject(name, value);

            propertyBuilder?.Invoke(new PropertyObjectBuilder(obj));

            config.Add(obj);

            return(this);
        }
        /// <summary>
        /// Method to add password data, need separate function to avoid ambiguity between <see cref="StringDataObject"/>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="propertyBuilder"></param>
        /// <returns></returns>
        public PropertyContainerBuilder Password(string name, string value, Action <PropertyObjectBuilder> propertyBuilder = null)
        {
            if (config.ContainsData(name) || value is null || string.IsNullOrWhiteSpace(value.ToString()))
            {
                DataContainerEvents.NotifyInformation($"Attempted to add duplication value : {name}");

                return(this);
            }

            var obj = new PasswordPropertyObject(name, value);

            propertyBuilder?.Invoke(new PropertyObjectBuilder(obj));

            config.Add(obj);

            return(this);
        }
        /// <summary>
        /// Generic method to create all types of objects
        /// Addes a different implementation of <see cref="PropertyObject"/> based on <see cref="Type"/>
        /// of <paramref name="value"/>
        /// </summary>
        /// <param name="name">name of property to be added</param>
        /// <param name="value">value of property</param>
        /// <param name="propertyBuilder">builder to set additional properties of <see cref="PropertyObject"/></param>
        /// <returns></returns>
        public PropertyContainerBuilder Property(string name, object value, Action <PropertyObjectBuilder> propertyBuilder = null)
        {
            if (config.ContainsData(name) || value is null)
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {name}");
                return(this);
            }

            if (DataObjectFactory.GetPropertyObjectFor(name, value) is PropertyObject obj)
            {
                propertyBuilder?.Invoke(new PropertyObjectBuilder(obj));

                config.Add(obj);
            }

            return(this);
        }
        /// <summary>
        /// Generic method for adding numeric types
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="propertyBuilder"></param>
        /// <returns></returns>
        public PropertyContainerBuilder Number <T>(string name, T value, Action <NumericPropertyObjectBuilder <T> > propertyBuilder = null)
            where T : struct, IComparable, IComparable <T>, IConvertible, IEquatable <T>, IFormattable
        {
            if (config.ContainsData(name))
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {name}");

                return(this);
            }

            if (DataObjectFactory.GetPropertyObjectFor(name, value) is PropertyObject obj)
            {
                propertyBuilder?.Invoke(new NumericPropertyObjectBuilder <T>(obj));

                config.Add(obj);
            }

            return(this);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Internal method to create <see cref="IDataContainer"/> from CLR Objects
        /// </summary>
        /// <param name="pi"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        private DataContainerBuilder Data(PropertyInfo pi, object obj)
        {
            var value = pi.GetValue(obj);

            if (value is null)
            {
                DataContainerEvents.NotifyInformation($"Attempted to add invalid value : {pi.Name}");

                return(this);
            }

            // ??
            if (value is IDataContainer dc && dc.Count == 0)
            {
                return(this);
            }

            config.Add(DataObjectFactory.GetDataObjectFor(pi.Name, value));

            return(this);
        }