Exemplo n.º 1
0
        private DelimiterSeparatedValues.DsvTable CreateTable()
        {
            var theTable = new DelimiterSeparatedValues.DsvTable(_Settings);

            // create columns
            theTable.Columns.Add("Group", false, "", "", typeof(string));
            theTable.Columns.Add("Item", false, "", "", typeof(string));
            theTable.Columns.Add("Type", true, "", "", typeof(string));
            theTable.Columns.Add("Value", true, "", "", typeof(string));
            //
            return(theTable);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts the specified <paramref name="source"/>, a <see cref="StringBuilder"/> type, to an <see cref="IConfigurationGroup"/>.
        /// </summary>
        /// <param name="source">The object, a <see cref="StringBuilder"/> type, to convert into an <see cref="IConfigurationGroup"/>.</param>
        /// <returns>The object converted into an <see cref="IConfigurationGroup"/>.</returns>
        public IConfigurationGroup Deserialize(StringBuilder source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (source.Length == 0)
            {
                throw new ArgumentNullException(nameof(source), $"Parameter {nameof(source)} cannot be an empty string.");
            }
            IConfigurationGroup workGroup = new ConfigurationGroup("");
            var table = new DelimiterSeparatedValues.DsvTable(_Settings);

            table.ReadString(source.ToString());
            foreach (var row in table.Rows)
            {
                var groupName = row[0].ToString();
                if (string.IsNullOrWhiteSpace(groupName))
                {
                    workGroup.Items.Add(DeserializeItem(row));
                }
                else
                {
                    var group = ConfigurationShared.FindGroup(workGroup, groupName, _CsvGroupNameSeparator_);
                    var item  = DeserializeItem(row);
                    if (item != null)
                    {
                        group.Items.Add(item);
                    }
                }
            }
            if ((string.IsNullOrWhiteSpace(workGroup.Key)) && (workGroup.Items.Count == 0) && (workGroup.Count == 1))
            {
                workGroup = workGroup.ElementAt(0);
            }
            workGroup.MarkDirty();
            workGroup.MarkNew();
            return(workGroup);
        }
Exemplo n.º 3
0
        private void InternalSerializeGroup(string parentGroupAddress, IConfigurationGroup group, DelimiterSeparatedValues.DsvTable table)
        {
            // get local Group Address
            var groupAddress = group.Key;

            if (!string.IsNullOrWhiteSpace(parentGroupAddress))
            {
                groupAddress = parentGroupAddress + _CsvGroupNameSeparator_ + group.Key;
            }
            // process items
            if (group.Items.Count > 0)
            {
                // serialize items
                foreach (var item in group.Items)
                {
                    var row = table.NewRow(groupAddress, item.Key, ConfigurationShared.ConvertItemTypeToString(item), ConfigurationShared.ConvertItemObjectToString(item, _Compressor));
                    table.Rows.Add(row);
                }
            }
            else
            {
                var row = table.NewRow(groupAddress);
                if (row != null)
                {
                    if (!string.IsNullOrWhiteSpace((string)row[0]))
                    {
                        table.Rows.Add(row);
                    }
                    else if ((!string.IsNullOrWhiteSpace((string)row[1])) &&
                             (!string.IsNullOrWhiteSpace((string)row[2])) &&
                             (!string.IsNullOrWhiteSpace((string)row[3])))
                    {
                        table.Rows.Add(row);
                    }
                }
            }
            // process groups
            if (group.Count > 0)
            {
                foreach (var subGroup in group)
                {
                    InternalSerializeGroup(groupAddress, subGroup, table);
                }
            }
        }