Beispiel #1
0
        /// <summary>
        /// Creates a <seealso cref="DataTable"/> object with 1 column and n rows
        /// that represnts the values of a list of values.
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="columnSchema"></param>
        /// <param name="handler"></param>
        /// <param name="masterRow"></param>
        /// <returns></returns>
        private static DataTable CreateListTable(string tableName,
                                                 IOptionsSchema columnSchema,
                                                 IAlternativeDataTypeHandler handler,
                                                 DataRow masterRow)
        {
            DataTable dataTable = new DataTable(tableName);

            DataColumn col = new DataColumn(columnSchema.OptionName,
                                            (columnSchema.TypeOfValue == typeof(SecureString) ? typeof(string) :
                                             columnSchema.TypeOfValue));

            col.AllowDBNull = columnSchema.IsOptional;
            dataTable.Columns.Add(col);

            ////var list = columnSchema.Value as IEnumerable<object>;

            bool IsFirstRow = true;

            foreach (var item in columnSchema.List_GetListOfValues())
            {
                if (IsFirstRow == true)
                {
                    IsFirstRow = false;

                    // Initialize row for caller this must be non-null to make it storeable
                    if (handler != null)
                    {
                        masterRow[columnSchema.OptionName] = handler.Convert(item as SecureString);
                    }
                    else
                    {
                        masterRow[columnSchema.OptionName] = item;
                    }
                }


                var row = dataTable.NewRow();

                if (handler != null)
                {
                    row[columnSchema.OptionName] = handler.Convert(item as SecureString);
                }
                else
                {
                    row[columnSchema.OptionName] = item;
                }

                dataTable.Rows.Add(row);
            }

            return(dataTable);
        }
Beispiel #2
0
        /// <summary>
        /// Finds an alternative datatype handler to handle datatypes that are not
        /// supported through equivalent conversion in alternative datatypes.
        /// </summary>
        /// <param name="typeOfDataType2Handle"></param>
        /// <returns></returns>
        public IAlternativeDataTypeHandler FindHandler(Type typeOfDataType2Handle)
        {
            IAlternativeDataTypeHandler ret = null;

            try
            {
                converters.TryGetValue(typeOfDataType2Handle, out ret);
            }
            catch
            {
            }

            return(ret);
        }
Beispiel #3
0
        /// <summary>
        /// Finds an alternative datatype handler to handle datatypes that are not
        /// supported through equivalent conversion in alternative datatypes.
        /// </summary>
        /// <param name="typeOfDataType2Handle"></param>
        /// <returns></returns>
        public IAlternativeDataTypeHandler FindHandler(Type typeOfDataType2Handle)
        {
            IAlternativeDataTypeHandler ret = null;

            try
            {
                converters.TryGetValue(typeOfDataType2Handle, out ret);
            }
            catch
            {
                // Make sure that exceptions in converter do not crash the application
            }

            return(ret);
        }