Example #1
0
        /// <summary>
        /// Sets the rendering purpose title for the <c>table</c> via <see cref="imbSCI.Data.enums.fields.templateFieldDataTable.data_tablename"/> entry in the <see cref="DataTable.ExtendedProperties"/>, without changing the <see cref="DataTable.TableName"/>
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="content">The content.</param>
        /// <param name="policy">The policy.</param>
        /// <returns></returns>
        public static DataTable SetTitle(this DataTable table, String content, existingDataMode policy = existingDataMode.overwriteExisting)
        {
            if (table.TableName.isNullOrEmpty())
            {
                table.TableName = content.getFilename();
            }

            if (table.TableName.isNullOrEmpty())
            {
                table.TableName = "Untitled";
            }

            table.ExtendedProperties.Append(templateFieldDataTable.data_tablename, content, policy);
            return(table);
        }
        /// <summary>
        /// Combines two PropertyCollections according <c>policy</c> specified
        /// </summary>
        /// <param name="existing">Collection that will be changed</param>
        /// <param name="data">New data to append</param>
        /// <param name="policy">How to manage key duplicates</param>
        /// \ingroup_disabled ace_ext_collections_highlight
        public static void AppendData(this PropertyCollection existing, PropertyCollection data, existingDataMode policy, Boolean showException = true)
        {
            PropertyCollection temp = new PropertyCollection();

            if ((data == null) && showException)
            {
                throw new ArgumentNullException("data", "AppendData failed because data is null");
                return;
            }
            if (data == null)
            {
                return;
            }

            switch (policy)
            {
            case existingDataMode.clearExisting:
                existing.Clear();
                existing.AddRange(data);
                break;

            case existingDataMode.filterAndLeaveExisting:
                foreach (DictionaryEntry input in data)
                {
                    if (existing.ContainsKey(input.Key))
                    {
                        temp.Add(input.Key, existing[input.Key]);
                    }
                }
                existing.Clear();
                existing.AddRange(temp);
                break;

            case existingDataMode.filterNewOverwriteExisting:
                foreach (DictionaryEntry input in data)
                {
                    if (existing.ContainsKey(input.Key))
                    {
                        existing[input.Key] = input.Value;
                    }
                }
                break;

            case existingDataMode.leaveExisting:
                existing.AddRange(data, true);
                break;

            case existingDataMode.overwriteExistingIfEmptyOrNull:
                foreach (DictionaryEntry input in data)
                {
                    if (existing.ContainsKey(input.Key))
                    {
                        if (imbSciStringExtensions.isNullOrEmptyString(existing[input.Key].toStringSafe("")))
                        {
                            existing[input.Key] = input.Value;
                        }
                    }
                    else
                    {
                        existing.Add(input.Key, input.Value);
                    }
                }
                break;

            case existingDataMode.overwriteExisting:
                foreach (DictionaryEntry input in data)
                {
                    if (existing.ContainsKey(input.Key))
                    {
                        existing[input.Key] = input.Value;
                    }
                    else
                    {
                        existing.Add(input.Key, input.Value);
                    }
                }
                break;

            case existingDataMode.sumWithExisting:
                foreach (DictionaryEntry input in data)
                {
                    if (existing.ContainsKey(input.Key))
                    {
                        Object result = existing[input.Key].sumValues(input.Value);
                    }
                    else
                    {
                        existing.Add(input.Key, input.Value);
                    }
                }
                break;

            default:
                throw new NotImplementedException(imbStringFormats.toStringSafe(policy) + " called but not implemented");
                break;
            }
        }
        // -------------------------- ADD and APPEND

#pragma warning disable CS1574 // XML comment has cref attribute 'existingDataMode' that could not be resolved
        /// <summary>
        /// Appends the specified key and value accordint the specified <see cref="aceCommonTypes.enums.existingDataMode"/>. Returns TRUE if <c>newValueCandidate</c> was written as result of the <c>policy</c> specified.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="key">The key.</param>
        /// <param name="newValueCandidate">The new value candidate - it will be or not written under specified <c>key</c> depending on <c>policy</c> and current <c>data</c> </param>
        /// <param name="policy">The policy on handling existing entry for the <c>key</c> specified</param>
        /// <returns>FALSE if <c>newValueCandidate</c> was not written into <c>data</c> collection</returns>
        public static Boolean Append(this PropertyCollection data, Object key, Object newValueCandidate, existingDataMode policy)
#pragma warning restore CS1574 // XML comment has cref attribute 'existingDataMode' that could not be resolved
        {
            if (newValueCandidate == null)
            {
                return(false);
            }
            switch (policy)
            {
            case existingDataMode.clearExisting:
                data.Clear();
                data.Add(key, data);
                break;

            case existingDataMode.filterAndLeaveExisting:
                if (data.ContainsKey(key))
                {
                    //data[key] = newValueCandidate;
                    return(false);
                }
                else
                {
                    if (key is Enum)
                    {
                        data.add((Enum)key, newValueCandidate, false);
                    }
                    else
                    {
                        data.Add(key.toStringSafe(), newValueCandidate);
                    }
                }
                break;

            case existingDataMode.filterNewOverwriteExisting:
                if (data.ContainsKey(key))
                {
                    data[key] = newValueCandidate;
                }
                return(false);

                break;

            case existingDataMode.leaveExisting:
                return(false);

                break;

            case existingDataMode.overwriteExistingIfEmptyOrNull:

                if (data.ContainsKey(key))
                {
                    if (imbSciStringExtensions.isNullOrEmptyString(data[key]))
                    {
                        data[key] = newValueCandidate;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    data.Add(key, newValueCandidate);
                }

                break;

            case existingDataMode.overwriteExisting:

                if (data.ContainsKey(key))
                {
                    data[key] = newValueCandidate;
                }
                else
                {
                    data.Add(key, newValueCandidate);
                }

                break;

            case existingDataMode.sumWithExisting:

                if (data.ContainsKey(key))
                {
                    Object result = data[key].sumValues(newValueCandidate);
                }
                else
                {
                    data.Add(key, newValueCandidate);
                }

                break;
            }
            return(true);
        }
Example #4
0
 /// <summary>
 /// Sets the color role
 /// </summary>
 /// <param name="table">The table.</param>
 /// <param name="color">The color.</param>
 /// <param name="policy">The policy.</param>
 /// <returns></returns>
 public static Boolean SetColor(this DataTable table, acePaletteRole color, existingDataMode policy = existingDataMode.overwriteExisting)
 {
     return(table.ExtendedProperties.Append(templateFieldStyling.color_paletteRole, color, policy));
 }
Example #5
0
 /// <summary>
 /// Sets the description into <see cref="DataTable.ExtendedProperties"/> under <see cref="imbSCI.Data.enums.fields.templateFieldDataTable.data_tabledesc"/>
 /// </summary>
 /// <param name="table">The table.</param>
 /// <param name="content">Description for the <c>table</c>.</param>
 /// <param name="policy">The policy.</param>
 /// <returns></returns>
 public static DataTable SetDescription(this DataTable table, String content, existingDataMode policy = existingDataMode.overwriteExisting)
 {
     table.ExtendedProperties.Append(templateFieldDataTable.data_tabledesc, content, policy);
     return(table);
 }
Example #6
0
 /// <summary>
 /// Descriptions the specified content.
 /// </summary>
 /// <param name="table">The table.</param>
 /// <param name="content">The content.</param>
 /// <param name="policy">The policy.</param>
 /// <returns></returns>
 public static DataTable Description(this DataTable table, String content, existingDataMode policy = existingDataMode.overwriteExisting)
 {
     table.SetDescription(content);
     return(table);
 }
Example #7
0
 /// <summary>
 /// Titles the specified content.
 /// </summary>
 /// <param name="table">The table.</param>
 /// <param name="content">The content.</param>
 /// <param name="policy">The policy.</param>
 /// <returns></returns>
 public static DataTable Title(this DataTable table, String content, existingDataMode policy = existingDataMode.overwriteExisting)
 {
     table.SetTitle(content, policy);
     return(table);
 }