Пример #1
0
        private void DatasetInfo(Map map)
        {
            IDataset dataset = null;
            int      index   = 0;

            while ((dataset = map[index]) != null)
            {
                Console.WriteLine($"Dataset {index}");
                Console.WriteLine("==============================================================================");
                Console.WriteLine($"Type: { dataset.GetType() }");

                Console.WriteLine(Environment.NewLine);
                Console.WriteLine($"ConnectionString:");
                Console.WriteLine("------------------------------------------------------------------------------");

                var connectionParameters = ConfigTextStream.Extract(dataset.ConnectionString);
                foreach (string key in connectionParameters.Keys)
                {
                    Console.WriteLine($"{ key }={ ConfigTextStream.SecureConfigValue(key, connectionParameters[key]) }");
                }

                if (!String.IsNullOrEmpty(dataset.LastErrorMessage))
                {
                    Console.WriteLine(Environment.NewLine);
                    Console.WriteLine("Errors:");
                    Console.WriteLine("------------------------------------------------------------------------------");
                    Console.WriteLine(dataset.LastErrorMessage);
                }

                Console.WriteLine(Environment.NewLine);

                index++;
            }
        }
Пример #2
0
        private int MaximumFieldLength(IDataset dataset)
        {
            MaximumFieldnameLength maxLength = Attribute.GetCustomAttribute(dataset.GetType(), typeof(MaximumFieldnameLength)) as MaximumFieldnameLength;

            if (maxLength != null)
            {
                return(maxLength.Value);
            }

            return(255);
        }
Пример #3
0
        private void MakeGui()
        {
            if (_dataset != null)
            {
                txtName.Text      = _dataset.DatasetName;
                txtType.Text      = _dataset.GetType().ToString();
                txtGroupName.Text = _dataset.DatasetGroupName;
                txtProvider.Text  = _dataset.ProviderName;

                txtConnectionString.Text = ConfigTextStream.SecureConfig(_dataset.ConnectionString);
            }
        }
Пример #4
0
        /// <summary>
        /// Writes CSV data to specified file.
        /// </summary>
        public static void WriteData(IDataset dataset, string fileName, string separator, CancellationToken token)
        {
            using (StreamWriter file = new StreamWriter(fileName, false, Encoding.UTF8))
            {
                token.ThrowIfCancellationRequested();

                int width = dataset.ColumnsCount;
                if (width == 0)
                {
                    return;
                }

                int length = dataset.RowsCount;

                string[] columnNames = dataset.Columns.Select(c => c.Name).ToArray();


                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < width; i++)
                {
                    if (i > 0)
                    {
                        sb.Append(separator);
                    }

                    AppendValue(sb, columnNames[i]);
                }

                if (length > 0)
                {
                    sb.Append(Environment.NewLine);
                }

                file.Write(sb.ToString());
                sb.Clear();

                token.ThrowIfCancellationRequested();

                // Values.
                for (int row = 0; row < length; row++)
                {
                    for (int column = 0; column < width; column++)
                    {
                        token.ThrowIfCancellationRequested();

                        if (column > 0)
                        {
                            sb.Append(separator);
                        }

                        string value;
                        switch (dataset.GetType(column, row))
                        {
                        case CellType.Boolean:
                            value = dataset.GetBoolean(column, row).GetValueOrDefault() ? "TRUE" : "FALSE";
                            break;

                        case CellType.Text:
                            value = dataset.GetText(column, row);
                            break;

                        case CellType.Error:
                            value = dataset.GetError(column, row);
                            break;

                        case CellType.Number:
                            value = dataset.GetNumber(column, row).GetValueOrDefault()
                                    .ToString(CultureInfo.InvariantCulture);
                            break;

                        case CellType.Nothing:
                            value = "";
                            break;

                        default:
                            throw new Exception("Unknown cell type");
                        }

                        AppendValue(sb, value);
                    }

                    if (row < length - 1)
                    {
                        sb.Append(Environment.NewLine);
                    }

                    file.Write(sb.ToString());
                    sb.Clear();
                }
            }
        }