static SqlDataRecord PopulateOrchestrationMessage(TaskMessage msg, SqlDataRecord record)
        {
            string instanceId = msg.OrchestrationInstance.InstanceId;

            record.SetSqlString(ColumnOrdinals.InstanceID, instanceId);
            record.SetSqlString(ColumnOrdinals.ExecutionID, msg.OrchestrationInstance.ExecutionId);
            record.SetSqlInt64(ColumnOrdinals.SequenceNumber, msg.SequenceNumber);
            record.SetSqlString(ColumnOrdinals.EventType, msg.Event.EventType.ToString());
            record.SetSqlString(ColumnOrdinals.Name, SqlUtils.GetName(msg.Event));
            record.SetSqlString(ColumnOrdinals.RuntimeStatus, SqlUtils.GetRuntimeStatus(msg.Event));
            record.SetSqlInt32(ColumnOrdinals.TaskID, SqlUtils.GetTaskId(msg.Event));
            record.SetDateTime(ColumnOrdinals.VisibleTime, SqlUtils.GetVisibleTime(msg.Event));

            SqlString reason = SqlUtils.GetReason(msg.Event);

            record.SetSqlString(ColumnOrdinals.Reason, reason);
            SqlString payloadText = SqlUtils.GetPayloadText(msg.Event);

            record.SetSqlString(ColumnOrdinals.PayloadText, payloadText);

            // If the message contains a payload (including Reason data), then we generate a random payload ID for it.
            // We could have done this in the stored procedure directly, but doing in in C# is quite a bit simpler.
            record.SetSqlGuid(
                ColumnOrdinals.PayloadId,
                payloadText.IsNull && reason.IsNull ? SqlGuid.Null : new SqlGuid(Guid.NewGuid()));

            record.SetSqlString(ColumnOrdinals.ParentInstanceID, SqlUtils.GetParentInstanceId(msg.Event));
            record.SetSqlString(ColumnOrdinals.Version, SqlUtils.GetVersion(msg.Event));

            return(record);
        }
Exemplo n.º 2
0
 private static void BindFile(FileInfo _file, SqlDataRecord record)
 {
     record.SetSqlDateTime(0, _file.Exists ? _file.CreationTime : SqlDateTime.Null);
     record.SetSqlDateTime(1, _file.Exists ? _file.LastAccessTime : SqlDateTime.Null);
     record.SetSqlDateTime(2, _file.Exists ? _file.LastWriteTime : SqlDateTime.Null);
     record.SetSqlBoolean(3, _file.Exists);
     record.SetString(4, _file.Name);
     record.SetString(5, _file.DirectoryName);
     record.SetString(6, _file.Extension);
     record.SetSqlInt64(7, _file.Exists ? _file.Length : SqlInt64.Null);
 }
Exemplo n.º 3
0
    private static SqlDataRecord buildRecord(SqlMetaData[] metadata, EventLogEntry entry)
    {
        SqlDataRecord record = new SqlDataRecord(metadata);

        record.SetSqlInt32(0, entry.Index);
        record.SetSqlInt64(1, entry.InstanceId);
        record.SetSqlDateTime(2, entry.TimeWritten);
        record.SetSqlString(3, entry.MachineName);
        record.SetSqlString(4, entry.Source);
        record.SetSqlString(5, entry.UserName);
        record.SetSqlString(6, entry.Message);

        return(record);
    }
Exemplo n.º 4
0
        static IEnumerable <SqlDataRecord> ToHistoryEventsParameter(
            IEnumerable <HistoryEvent> historyEvents,
            OrchestrationInstance instance,
            int nextSequenceNumber,
            EventPayloadMap eventPayloadMap)
        {
            var record = new SqlDataRecord(HistoryEventSchema);

            foreach (HistoryEvent e in historyEvents)
            {
                record.SetSqlInt64(ColumnOrdinals.SequenceNumber, nextSequenceNumber++);
                record.SetSqlString(ColumnOrdinals.InstanceID, instance.InstanceId);
                record.SetSqlString(ColumnOrdinals.ExecutionID, instance.ExecutionId);
                record.SetSqlString(ColumnOrdinals.EventType, e.EventType.ToString());
                record.SetSqlString(ColumnOrdinals.Name, SqlUtils.GetName(e));
                record.SetSqlString(ColumnOrdinals.RuntimeStatus, SqlUtils.GetRuntimeStatus(e));
                record.SetSqlInt32(ColumnOrdinals.TaskID, SqlUtils.GetTaskId(e));
                record.SetDateTime(ColumnOrdinals.Timestamp, e.Timestamp);
                record.SetBoolean(ColumnOrdinals.IsPlayed, e.IsPlayed);
                record.SetDateTime(ColumnOrdinals.VisibleTime, SqlUtils.GetVisibleTime(e));

                if (eventPayloadMap.TryGetPayloadId(e, out Guid existingPayloadId))
                {
                    // We already have a payload saved in the DB for this event. Send only the payload ID.
                    record.SetSqlString(ColumnOrdinals.Reason, SqlString.Null);
                    record.SetSqlString(ColumnOrdinals.PayloadText, SqlString.Null);
                    record.SetSqlGuid(ColumnOrdinals.PayloadID, existingPayloadId);
                }
                else
                {
                    // This path is expected for ExecutionCompleted, possibly others?
                    SqlString reason = SqlUtils.GetReason(e);
                    record.SetSqlString(ColumnOrdinals.Reason, reason);
                    SqlString payload = SqlUtils.GetPayloadText(e);
                    record.SetSqlString(ColumnOrdinals.PayloadText, payload);
                    SqlGuid newPayloadId = reason.IsNull && payload.IsNull ? SqlGuid.Null : new SqlGuid(Guid.NewGuid());
                    record.SetSqlGuid(ColumnOrdinals.PayloadID, newPayloadId);
                }

                yield return(record);
            }
        }
        static SqlDataRecord PopulateOrchestrationMessage(TaskMessage msg, SqlDataRecord record, EventPayloadMap?eventPayloadMap)
        {
            string instanceId = msg.OrchestrationInstance.InstanceId;

            record.SetSqlString(ColumnOrdinals.InstanceID, instanceId);
            record.SetSqlString(ColumnOrdinals.ExecutionID, msg.OrchestrationInstance.ExecutionId);
            record.SetSqlInt64(ColumnOrdinals.SequenceNumber, msg.SequenceNumber);
            record.SetSqlString(ColumnOrdinals.EventType, msg.Event.EventType.ToString());
            record.SetSqlString(ColumnOrdinals.Name, SqlUtils.GetName(msg.Event));
            record.SetSqlString(ColumnOrdinals.RuntimeStatus, SqlUtils.GetRuntimeStatus(msg.Event));
            record.SetSqlInt32(ColumnOrdinals.TaskID, SqlUtils.GetTaskId(msg.Event));
            record.SetDateTime(ColumnOrdinals.VisibleTime, SqlUtils.GetVisibleTime(msg.Event));

            SqlString reasonText = SqlUtils.GetReason(msg.Event);

            record.SetSqlString(ColumnOrdinals.Reason, reasonText);
            SqlString payloadText = SqlUtils.GetPayloadText(msg.Event);

            record.SetSqlString(ColumnOrdinals.PayloadText, payloadText);

            SqlGuid sqlPayloadId = SqlGuid.Null;

            if (eventPayloadMap != null && eventPayloadMap.TryGetPayloadId(msg.Event, out Guid payloadId))
            {
                // There is already a payload ID associated with this event
                sqlPayloadId = payloadId;
            }
            else if (!payloadText.IsNull || !reasonText.IsNull)
            {
                // This is a new event and needs a new payload ID
                // CONSIDER: Make this GUID a semi-human-readable deterministic value
                sqlPayloadId = Guid.NewGuid();
            }

            record.SetSqlGuid(ColumnOrdinals.PayloadId, sqlPayloadId);

            record.SetSqlString(ColumnOrdinals.ParentInstanceID, SqlUtils.GetParentInstanceId(msg.Event));
            record.SetSqlString(ColumnOrdinals.Version, SqlUtils.GetVersion(msg.Event));

            return(record);
        }
        public void SqlRecordFillTest()
        {
            SqlMetaData[] metaData = new SqlMetaData[]
            {
                new SqlMetaData("col1", SqlDbType.Bit),
                new SqlMetaData("col2", SqlDbType.TinyInt),
                new SqlMetaData("col3", SqlDbType.VarBinary, 1000),
                new SqlMetaData("col4", SqlDbType.NVarChar, 1000),
                new SqlMetaData("col5", SqlDbType.DateTime),
                new SqlMetaData("col6", SqlDbType.Float),
                new SqlMetaData("col7", SqlDbType.UniqueIdentifier),
                new SqlMetaData("col8", SqlDbType.SmallInt),
                new SqlMetaData("col9", SqlDbType.Int),
                new SqlMetaData("col10", SqlDbType.BigInt),
                new SqlMetaData("col11", SqlDbType.Real),
                new SqlMetaData("col12", SqlDbType.Decimal),
                new SqlMetaData("col13", SqlDbType.Money),
                new SqlMetaData("col14", SqlDbType.Variant)
            };

            SqlDataRecord record = new SqlDataRecord(metaData);

            for (int i = 0; i < record.FieldCount; i++)
            {
                Assert.Equal($"col{i + 1}", record.GetName(i));
            }

            record.SetBoolean(0, true);
            Assert.Equal(true, record.GetBoolean(0));

            record.SetByte(1, 1);
            Assert.Equal(1, record.GetByte(1));

            byte[] bb1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] bb2 = new byte[5];
            record.SetSqlBinary(2, new SqlBinary(new byte[0]));
            record.SetBytes(2, 0, bb1, 0, 3);
            record.SetBytes(2, 2, bb1, 6, 3);

            // Verify the length of the byte array
            Assert.Equal(5, record.GetBytes(2, 0, bb2, 0, 5));

            Assert.Equal(5, record.GetBytes(2, 0, null, 0, 0));

            byte[] expected = new byte[] { 1, 2, 7, 8, 9 };
            Assert.Equal <byte>(expected, bb2);

            char[] cb1 = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
            char[] cb2 = new char[5];
            record.SetChars(3, 0, cb1, 0, 3);
            record.SetChars(3, 2, cb1, 4, 3);

            char[] expectedValue = new char[] { 'a', 'b', 'e', 'f', 'g' };
            Assert.Equal(expectedValue.Length, record.GetChars(3, 0, cb2, 0, 5));
            Assert.Equal <char>(expectedValue, new string(cb2, 0, (int)record.GetChars(3, 0, null, 0, 0)));

            record.SetString(3, "");
            string xyz = "xyz";

            record.SetString(3, "xyz");
            Assert.Equal(xyz, record.GetString(3));
            Assert.Equal(xyz.Length, record.GetChars(3, 0, cb2, 0, 5));
            Assert.Equal(xyz, new string(cb2, 0, (int)record.GetChars(3, 0, null, 0, 0)));

            record.SetChars(3, 2, cb1, 4, 3);
            Assert.Equal(5, record.GetChars(3, 0, cb2, 0, 5));

            string interleavedResult = "xyefg";

            Assert.Equal(interleavedResult, new string(cb2, 0, (int)record.GetChars(3, 0, null, 0, 0)));
            Assert.Equal(interleavedResult, record.GetString(3));

            record.SetSqlDateTime(4, SqlDateTime.MaxValue);
            Assert.Equal(SqlDateTime.MaxValue, record.GetSqlDateTime(4));

            record.SetSqlDouble(5, SqlDouble.MaxValue);
            Assert.Equal(SqlDouble.MaxValue, record.GetSqlDouble(5));

            SqlGuid guid = new SqlGuid("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4");

            record.SetSqlGuid(6, guid);
            Assert.Equal(guid, record.GetSqlGuid(6));

            record.SetSqlInt16(7, SqlInt16.MaxValue);
            Assert.Equal(SqlInt16.MaxValue, record.GetSqlInt16(7));

            record.SetSqlInt32(8, SqlInt32.MaxValue);
            Assert.Equal(SqlInt32.MaxValue, record.GetSqlInt32(8));

            record.SetSqlInt64(9, SqlInt64.MaxValue);
            Assert.Equal(SqlInt64.MaxValue, record.GetSqlInt64(9));

            record.SetSqlSingle(10, SqlSingle.MinValue);
            Assert.Equal(SqlSingle.MinValue, record.GetSqlSingle(10));

            record.SetSqlDecimal(11, SqlDecimal.Null);
            record.SetSqlDecimal(11, SqlDecimal.MaxValue);
            Assert.Equal(SqlDecimal.MaxValue, record.GetSqlDecimal(11));

            record.SetSqlMoney(12, SqlMoney.MaxValue);
            Assert.Equal(SqlMoney.MaxValue, record.GetSqlMoney(12));


            // Try adding different values to SqlVariant type
            for (int i = 0; i < record.FieldCount - 1; ++i)
            {
                object valueToSet = record.GetSqlValue(i);
                record.SetValue(record.FieldCount - 1, valueToSet);
                object o = record.GetSqlValue(record.FieldCount - 1);

                if (o is SqlBinary)
                {
                    Assert.Equal <byte>(((SqlBinary)valueToSet).Value, ((SqlBinary)o).Value);
                }
                else
                {
                    Assert.Equal(valueToSet, o);
                }

                record.SetDBNull(record.FieldCount - 1);
                Assert.Equal(DBNull.Value, record.GetSqlValue(record.FieldCount - 1));

                record.SetDBNull(i);
                Assert.Equal(DBNull.Value, record.GetValue(i));
            }
        }