Beispiel #1
0
    public static T GetValue <T>(this DataRow dataRow, string name, T outputNullValue)
    {
        ArgumentNullException.ThrowIfNull(dataRow, nameof(dataRow));
        var valueObject = dataRow[name];

        return(ValueReader.GetValue(valueObject, outputNullValue));
    }
Beispiel #2
0
        /// <summary>
        /// Helper method used to build a <see cref="TrackingWorkflowInstance" />
        /// from the specified <see cref="IDataRecord" />.
        /// </summary>
        /// <param name="dataRecord">
        /// An <see cref="IDataRecord" />.
        /// </param>
        /// <returns>
        /// An instance of <see cref="TrackingWorkflowInstance" />.
        /// </returns>
        private TrackingWorkflowInstance buildTrackingWorkflowInstance(IDataRecord dataRecord, TrackingCommandName commandName)
        {
            String assemblyName = ValueReader.GetString(dataRecord,
                                                        _nameResolver.ResolveParameterName(commandName,
                                                                                           TrackingParameterName.AssemblyFullName));

            String typeName = ValueReader.GetString(dataRecord,
                                                    _nameResolver.ResolveParameterName(commandName,
                                                                                       TrackingParameterName.TypeFullName));

            return(new TrackingWorkflowInstance(
                       WorkflowInstanceHelper.DeserialiseActivity(ValueReader.GetString(
                                                                      dataRecord, _nameResolver.ResolveParameterName(commandName,
                                                                                                                     TrackingParameterName.ActivityXoml))),
                       ValueReader.GetGuid(dataRecord, _nameResolver.ResolveParameterName(
                                               commandName, TrackingParameterName.InstanceId)),
                       ValueReader.GetDateTime(dataRecord, _nameResolver.ResolveParameterName(
                                                   commandName, TrackingParameterName.InitialisedDateTime)),
                       ValueReader.GetValue(dataRecord, _nameResolver.ResolveParameterName(
                                                commandName, TrackingParameterName.WorkflowInstanceId)),
                       ValueReader.GetGuid(dataRecord, _nameResolver.ResolveParameterName(
                                               commandName, TrackingParameterName.CallerInstanceId)),
                       ValueReader.GetEnum <WorkflowStatus>(dataRecord,
                                                            _nameResolver.ResolveParameterName(commandName,
                                                                                               TrackingParameterName.WorkflowInstanceStatusId)),
                       Type.GetType(String.Format("{0}, {1}", assemblyName, typeName), false)));
        }
    public static T GetValue <T>(this DataRow dataRow, string name, T outputNullValue)
    {
        Assert.IsNotNull(dataRow, nameof(dataRow));
        var valueObject = dataRow[name];

        return(ValueReader.GetValue(valueObject, outputNullValue));
    }
Beispiel #4
0
        private void Schema_Click(object sender, EventArgs e)
        {
            using (new CursorManager(Cursors.WaitCursor))
            {
                var commandText = string.Format(
                    @"use [{0}]
exec sp_MShelpcolumns N'{1}.[{2}]', @orderby = 'id'
exec sp_MStablekeys N'{1}.[{2}]', null, 14
exec sp_MStablechecks N'{1}.[{2}]'", DatabaseNode.Name, _owner, _name);

                Log.Write(LogLevel.Trace, commandText);
                var     connectionString = DatabaseNode.Databases.Server.ConnectionString;
                DataSet dataSet;
                using (var connection = new SqlConnection(connectionString))
                {
                    var executor = connection.CreateCommandExecutor();
                    dataSet = executor.ExecuteDataSet(new ExecuteReaderRequest(commandText));
                }

                var columns = dataSet.Tables[0];
                var keys    = dataSet.Tables[1];

                var schema = new DataTable();
                schema.Columns.Add(" ", typeof(int));
                schema.Columns.Add("  ", typeof(string));
                schema.Columns.Add("Name", typeof(string));
                schema.Columns.Add("Type", typeof(string));
                schema.Columns.Add("Collation", typeof(string));
                schema.Columns.Add("Formula", typeof(string));

                foreach (DataRow column in columns.Rows)
                {
                    string identity;

                    if (Convert.ToBoolean(column["col_identity"]))
                    {
                        identity = "IDENTITY";
                    }
                    else
                    {
                        identity = string.Empty;
                    }

                    var sb     = new StringBuilder();
                    var dbType = column["col_typename"].ToString();
                    sb.Append(dbType);

                    switch (dbType)
                    {
                    case "decimal":
                    case "numeric":
                        var precision = Convert.ToInt32(column["col_prec"]);
                        var scale     = Convert.ToInt32(column["col_scale"]);

                        if (scale == 0)
                        {
                            sb.AppendFormat("({0})", precision);
                        }
                        else
                        {
                            sb.AppendFormat("({0},{1})", precision, scale);
                        }

                        break;

                    case "char":
                    case "nchar":
                    case "varchar":
                    case "nvarchar":
                    case "varbinary":
                        var    columnLength = (int)column["col_len"];
                        string columnlengthString;

                        if (columnLength == -1)
                        {
                            columnlengthString = "max";
                        }
                        else
                        {
                            columnlengthString = columnLength.ToString();
                        }

                        sb.AppendFormat("({0})", columnlengthString);
                        break;
                    }

                    if (!Convert.ToBoolean(column["col_null"]))
                    {
                        sb.Append(" not null");
                    }

                    var collation = ValueReader.GetValue(column["collation"], string.Empty);
                    var formula   = string.Empty;

                    if (column["text"] != DBNull.Value)
                    {
                        formula = column["text"].ToString();
                    }

                    schema.Rows.Add(column["col_id"], identity, column["col_name"], sb.ToString(), collation, formula);
                }

                if (keys.Rows.Count > 0)
                {
                    var pk = (from row in keys.AsEnumerable()
                              where row.Field <byte>("cType") == 1
                              select row).FirstOrDefault();

                    if (pk != null)
                    {
                        for (var i = 1; i <= 16; i++)
                        {
                            var keyColObj = pk["cKeyCol" + i];

                            if (keyColObj == DBNull.Value)
                            {
                                break;
                            }

                            var keyCol = keyColObj.ToString();

                            var filter   = $"Name = '{keyCol}'";
                            var dataRow  = schema.Select(filter)[0];
                            var identity = dataRow[1].ToString();

                            if (identity.Length > 0)
                            {
                                dataRow[1] = "PKEY," + dataRow[1];
                            }
                            else
                            {
                                dataRow[1] = "PKEY";
                            }
                        }
                    }
                }

                dataSet.Tables.Add(schema);

                var mainForm  = DataCommanderApplication.Instance.MainForm;
                var queryForm = (QueryForm)mainForm.ActiveMdiChild;
                queryForm.ShowDataSet(dataSet);
            }
        }