Exemplo n.º 1
0
        /// <summary>
        /// Returns an Enumerator to insert format the data for a SQL Database
        /// </summary>
        /// <returns></returns>
        IEnumerator <SqlDataRecord> IEnumerable <SqlDataRecord> .GetEnumerator()
        {
            var sdr = new SqlDataRecord(
                new SqlMetaData("PointName", SqlDbType.VarChar, 400),
                new SqlMetaData("PointGuid", SqlDbType.UniqueIdentifier),
                new SqlMetaData("PointType", SqlDbType.VarChar, 400),
                new SqlMetaData("ItemReference", SqlDbType.VarChar, 400),
                new SqlMetaData("IsReliable", SqlDbType.Bit),
                new SqlMetaData("TimeStamp", SqlDbType.DateTime),
                new SqlMetaData("Units", SqlDbType.VarChar, 100),
                new SqlMetaData("Value", SqlDbType.VarChar, 400));

            foreach (var desc in this)
            {
                sdr.SetSqlString(0, desc.PointName);
                sdr.SetSqlGuid(1, desc.PointGuid);
                sdr.SetSqlString(2, desc.PointType);
                sdr.SetSqlString(3, desc.ItemReference);
                sdr.SetSqlBoolean(4, desc.IsReliable);
                sdr.SetSqlDateTime(5, desc.TimeStamp);
                sdr.SetSqlString(6, desc.Units);
                sdr.SetSqlString(7, desc.Value.ToString());


                yield return(sdr);
            }
        }
        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.º 3
0
    public static void usp_GetEnvInfo()
    {
        // Create a record - object representation of a row
        // Include the metadata for the SQL table
        SqlDataRecord record = new SqlDataRecord(
            new SqlMetaData("EnvProperty", SqlDbType.NVarChar, 20),
            new SqlMetaData("Value", SqlDbType.NVarChar, 256));

        // Marks the beginning of the result set to be sent back to the client
        // The record parameter is used to construct the metadata
        // for the result set
        SqlContext.Pipe.SendResultsStart(record);
        // Populate some records and send them through the pipe
        record.SetSqlString(0, @"Machine Name");
        record.SetSqlString(1, Environment.MachineName);
        SqlContext.Pipe.SendResultsRow(record);
        record.SetSqlString(0, @"Processors");
        record.SetSqlString(1, Environment.ProcessorCount.ToString());
        SqlContext.Pipe.SendResultsRow(record);
        record.SetSqlString(0, @"OS Version");
        record.SetSqlString(1, Environment.OSVersion.ToString());
        SqlContext.Pipe.SendResultsRow(record);
        record.SetSqlString(0, @"CLR Version");
        record.SetSqlString(1, Environment.Version.ToString());
        SqlContext.Pipe.SendResultsRow(record);
        // End of result set
        SqlContext.Pipe.SendResultsEnd();
    }
Exemplo n.º 4
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);
    }
        public static SqlDataRecord buildRecord(SqlMetaData[] metadata, string[] entry)
        {
            SqlDataRecord record = new SqlDataRecord(metadata);

            record.SetSqlString(0, entry[1]);
            return(record);
        }
        IEnumerator <SqlDataRecord> IEnumerable <SqlDataRecord> .GetEnumerator()
        {
            var sqlRow = new SqlDataRecord(
                new SqlMetaData("TagName", SqlDbType.VarChar),
                new SqlMetaData("NumOfGoodData", SqlDbType.Int),
                new SqlMetaData("NumOfGoodQltyPercentage", SqlDbType.Decimal),
                new SqlMetaData("NumOfGoodMANData", SqlDbType.Int),
                new SqlMetaData("NumOfGoodQltyMANPercentage", SqlDbType.Decimal),
                new SqlMetaData("NumOfGoodAUTData", SqlDbType.Int),
                new SqlMetaData("NumOfGoodQltyAUTPercentage", SqlDbType.Int)
                );

            foreach (var d in this)
            {
                sqlRow.SetSqlString(0, d.HistTagName);
                sqlRow.SetSqlInt32(1, d.NumOfGoodData);
                sqlRow.SetSqlDecimal(2, d.NumOfGoodQltyPercentage);
                sqlRow.SetSqlInt32(3, d.NumOfGoodMANData);
                sqlRow.SetSqlDecimal(4, d.NumOfGoodQltyMANPercentage);
                sqlRow.SetSqlInt32(5, d.NumOfGoodAUTData);
                sqlRow.SetSqlDecimal(6, d.NumOfGoodQltyAUTPercentage);

                yield return(sqlRow);
            }
        }
        public void AddSurveyTokensMultiple(int surveyId, DateTime creationDate, IEnumerable <string> tokens)
        {
            SqlMetaData[]        tab       = { new SqlMetaData("value", SqlDbType.VarChar, 40) };
            List <SqlDataRecord> tokenList =
                tokens.Select(x => { var y = new SqlDataRecord(tab); y.SetSqlString(0, x); return(y); }).ToList <SqlDataRecord>();

            SqlParameter p = new SqlParameter("@tblTokenList", SqlDbType.Structured);

            p.Direction = ParameterDirection.Input;
            p.TypeName  = "dbo.VarcharTableType";
            p.Value     = tokenList;

            SqlCommand cmd = new SqlCommand();

            using (SqlConnection conn = new SqlConnection(DbConnection.NewDbConnectionString))
            {
                conn.Open();
                cmd.Connection  = conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "vts_spSurveyTokenAddMultiple";
                cmd.Parameters.Add(p);
                cmd.Parameters.Add(new SqlParameter("@SurveyID", surveyId));
                cmd.Parameters.Add(new SqlParameter("@CreationDate", creationDate));

                cmd.ExecuteNonQuery();
            }
            //   SqlHelper.ExecuteNonQuery(SqlHelper.DbConnectionString, "vts_spSurveyTokenAddMultiple", pars);
        }
Exemplo n.º 8
0
        private static SqlDataRecord CreateStringIdRecord(string id)
        {
            var record = new SqlDataRecord(new SqlMetaData("Id", SqlDbType.NVarChar, 16));

            record.SetSqlString(0, id);

            return(record);
        }
Exemplo n.º 9
0
        public void Should_be_able_to_map_from_a_data_record()
        {
            var record = new SqlDataRecord(new[] { new SqlMetaData("column-1", SqlDbType.VarChar, 65) });

            record.SetSqlString(0, new SqlString(null));

            var column1 = new MappedColumn <string>("column-1", DbType.AnsiString, 65);
            var column2 = new MappedColumn <string>("column-2", DbType.AnsiString, 65);

            Assert.AreEqual(default(string), column1.MapFrom(record));
            Assert.AreEqual(default(string), column2.MapFrom(record));

            record.SetSqlString(0, new SqlString("value-1"));

            Assert.AreEqual("value-1", column1.MapFrom(record));
            Assert.AreEqual(default(string), column2.MapFrom(record));
        }
Exemplo n.º 10
0
        static SqlDataRecord PopulateTaskMessageRecord(TaskMessage msg, SqlDataRecord record)
        {
            record.SetSqlString(ColumnOrdinals.InstanceID, msg.OrchestrationInstance.InstanceId);
            record.SetSqlString(ColumnOrdinals.ExecutionID, msg.OrchestrationInstance.ExecutionId);
            record.SetSqlString(ColumnOrdinals.Name, SqlUtils.GetName(msg.Event));
            record.SetSqlString(ColumnOrdinals.EventType, msg.Event.EventType.ToString());
            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);

            // If the message contains a payload, then we generate a random payload ID for it.
            record.SetSqlGuid(
                ColumnOrdinals.PayloadId,
                payloadText.IsNull && reasonText.IsNull ? SqlGuid.Null : new SqlGuid(Guid.NewGuid()));

            // Optionally, the LockedBy and LockExpiration fields can be specified
            // to pre-lock task work items for this particular node.

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

            return(record);
        }
Exemplo n.º 11
0
    private static List <SqlDataRecord> CreateSqlDataRecords(DataTable dt)
    {
        List <SqlMetaData> metaData = new List <SqlMetaData> {
            new SqlMetaData("student_id", SqlDbType.VarChar, 9),
            new SqlMetaData("firstname", SqlDbType.VarChar, 20),
            new SqlMetaData("lastname", SqlDbType.VarChar, 20),
            new SqlMetaData("phone", SqlDbType.VarChar, 20),
            new SqlMetaData("email", SqlDbType.VarChar, 30),
            new SqlMetaData("house", SqlDbType.VarChar, 10),
            new SqlMetaData("room", SqlDbType.VarChar, 4)
        };


        List <SqlDataRecord> records = new List <SqlDataRecord>();

        foreach (DataRow row in dt.Rows)
        {
            if (row["student_id"] == DBNull.Value)
            {
                continue;
            }
            SqlDataRecord record = new SqlDataRecord(metaData.ToArray());
            record.SetSqlString(0, Convert.ToString(row["student_id"]));
            record.SetSqlString(1, Convert.ToString(row["firstname"]));
            record.SetSqlString(2, Convert.ToString(row["lastname"]));
            record.SetSqlString(3, Convert.ToString(row["phone"]));
            record.SetSqlString(4, Convert.ToString(row["email"]));
            record.SetSqlString(5, Convert.ToString(row["house"]));
            record.SetSqlString(6, Convert.ToString(row["room"]));

            records.Add(record);
        }

        return(records);
    }
        /// <summary>
        /// Sets the Enumerator to assist in saving the data to a SQL Database
        /// </summary>
        /// <returns></returns>
        IEnumerator <SqlDataRecord> IEnumerable <SqlDataRecord> .GetEnumerator()
        {
            var sdr = new SqlDataRecord(
                new SqlMetaData("SetId", SqlDbType.Int),
                new SqlMetaData("MemberId", SqlDbType.Int),
                new SqlMetaData("SetDesc", SqlDbType.VarChar, 300),
                new SqlMetaData("MemberDesc", SqlDbType.VarChar, 300));

            foreach (EnumDescDataStoreModel desc in this)
            {
                sdr.SetInt32(0, desc.SetId);
                sdr.SetInt32(1, desc.MemberId);
                sdr.SetSqlString(2, desc.SetDesc);
                sdr.SetSqlString(3, desc.MemberDesc);

                yield return(sdr);
            }
        }
Exemplo n.º 13
0
        ///<summary>SendTransientResultSet</summary>
        public static void SendTransientResultSet()
        {
            // Create a record object that represents an individual row, including it's metadata.
            SqlDataRecord sqlDataRecord = new SqlDataRecord(new SqlMetaData("Greeting", SqlDbType.VarChar, 128));

            // Populate the record.
            sqlDataRecord.SetSqlString(0, "Welcome");
            // Send the record to the client.
            SqlContext.Pipe.Send(sqlDataRecord);
        }
Exemplo n.º 14
0
    public static void DecodeBase62(SqlString s)
    {
        SqlString res = "";
        string    s2  = s.ToString();

        res = (s2.Aggregate(0, (current, c) => current * 62 + Base62Decode(c))).ToString();
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData("stringcol", SqlDbType.NVarChar, 128));

        record.SetSqlString(0, res);
        SqlContext.Pipe.Send(record);
    }
Exemplo n.º 15
0
        public static void MyHelloProcedure(SqlString name, SqlInt32 number)
        {
            var pipe = SqlContext.Pipe;

            var columns = new SqlMetaData[2];

            columns[0] = new SqlMetaData("НомерСтроки", SqlDbType.NVarChar, 100);
            columns[1] = new SqlMetaData("Приветствие", SqlDbType.NVarChar, 500);

            var row = new SqlDataRecord(columns);

            pipe.SendResultsStart(row);
            for (int i = 0; i < number; i++)
            {
                row.SetSqlString(0, string.Format("Строка №{0} ", i));
                row.SetSqlString(1, string.Format("Добрый день, уважаемый {0}", name));
                pipe.SendResultsRow(row);
            }

            pipe.SendResultsEnd();
        }
Exemplo n.º 16
0
        /// <summary>
        /// To TableType <see cref="TableType.Company"/>
        /// </summary>
        /// <param name="companies">Collection of data to change</param>
        /// <returns>List of <see cref="SqlDataRecord"/> objects</returns>
        public static List <SqlDataRecord> ToTableTypeCompanies(this IList <Company> companies)
        {
            if (companies == null || companies.Count == 0)
            {
                return(null);
            }

            var returnList = new List <SqlDataRecord>();

            foreach (var company in companies)
            {
                var sqlDataRecord = new SqlDataRecord(
                    new SqlMetaData("Name", SqlDbType.NVarChar, 400),
                    new SqlMetaData("BusinessCode", SqlDbType.NVarChar, 50),
                    new SqlMetaData("VatNo", SqlDbType.NVarChar, 200),
                    new SqlMetaData("Status", SqlDbType.VarChar, 20),
                    new SqlMetaData("FullAddress", SqlDbType.NVarChar, 1024),
                    new SqlMetaData("Url", SqlDbType.VarChar, 200)
                    );

                sqlDataRecord.SetSqlString(sqlDataRecord.GetOrdinal("Name"), company.CompanyName);
                sqlDataRecord.SetSqlString(sqlDataRecord.GetOrdinal("BusinessCode"), company.BusinessCode);
                sqlDataRecord.SetSqlString(sqlDataRecord.GetOrdinal("VatNo"), company.VatNo);
                sqlDataRecord.SetSqlString(sqlDataRecord.GetOrdinal("Status"), company.Status.ToString());
                sqlDataRecord.SetSqlString(sqlDataRecord.GetOrdinal("FullAddress"), company.CompanyAddress.FullAddress);
                sqlDataRecord.SetSqlString(sqlDataRecord.GetOrdinal("Url"), company.UrlOfAriregister);

                returnList.Add(sqlDataRecord);
            }

            return(returnList);
        }
Exemplo n.º 17
0
        public static IEnumerable <SqlDataRecord> CreateSqlDataRecord(this IEnumerable <string> records)
        {
            var metaData = new SqlMetaData[1];

            metaData[0] = new SqlMetaData("Code", System.Data.SqlDbType.VarChar);

            foreach (var item in records)
            {
                var sqlDataRecord = new SqlDataRecord(metaData);
                sqlDataRecord.SetSqlString(0, item);
                yield return(sqlDataRecord);
            }
        }
Exemplo n.º 18
0
        public override IEnumerator <SqlDataRecord> GetEnumerator()
        {
            foreach (MyGenericObject obj in Records)
            {
                SqlMetaData mdLocalPart  = new SqlMetaData("MyId", SqlDbType.Int);
                SqlMetaData mdDomainPart = new SqlMetaData("MyName", SqlDbType.NVarChar, 50);

                SqlDataRecord record = new SqlDataRecord(mdLocalPart, mdDomainPart);
                record.SetSqlInt32(0, new SqlInt32(obj.id));
                record.SetSqlString(1, new SqlString(obj.name));

                yield return(record);
            }
        }
Exemplo n.º 19
0
        public static IEnumerable <SqlDataRecord> CreateSqlDataRecord(this IDictionary <int, string> records)
        {
            var metaData = new SqlMetaData[2];

            metaData[0] = new SqlMetaData("IntegerID", System.Data.SqlDbType.Int);
            metaData[1] = new SqlMetaData("Code", System.Data.SqlDbType.VarChar);
            foreach (var item in records)
            {
                var sqldataRecord = new SqlDataRecord(metaData);
                sqldataRecord.SetInt32(0, item.Key);
                sqldataRecord.SetSqlString(1, item.Value);
                yield return(sqldataRecord);
            }
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 22
0
    public static void EncodeBase62(SqlString n)
    {
        int n2  = int.Parse(n.ToString());
        var res = "";

        while (n2 != 0)
        {
            res = Base62Digit(n2 % 62) + res;
            n2 /= 62;
        }
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData("stringcol", SqlDbType.NVarChar, 128));

        record.SetSqlString(0, res);
        SqlContext.Pipe.Send(record);
    }
Exemplo n.º 23
0
        public static IEnumerable <SqlDataRecord> CreateSqlDataRecord(this IEnumerable <Tuple <int, string, bool> > records)
        {
            var metaData = new SqlMetaData[3];

            metaData[0] = new SqlMetaData("IntegerID", System.Data.SqlDbType.Int);
            metaData[1] = new SqlMetaData("Code", System.Data.SqlDbType.VarChar);
            metaData[2] = new SqlMetaData("IsSelected", System.Data.SqlDbType.Bit);
            foreach (var item in records)
            {
                var sqldataRecord = new SqlDataRecord(metaData);
                sqldataRecord.SetInt32(0, item.Item1);
                sqldataRecord.SetSqlString(1, item.Item2);
                sqldataRecord.SetSqlBoolean(2, item.Item3);
                yield return(sqldataRecord);
            }
        }
        private static void Send(SqlPipe p, SqlDataRecord r, string m, bool d)
        {
            if (!d)
            {
                return;
            }

            if (r != null)
            {
                r.SetSqlString(0, m);
                p.SendResultsRow(r);
            }
            else
            {
                p.Send(m);
            }
        }
Exemplo n.º 25
0
        private static void Send(SqlPipe pipe, string m, bool debug)
        {
            if (!debug)
            {
                return;
            }

            if (pipe.IsSendingResults)
            {
                SqlDataRecord rec = new SqlDataRecord(DeFunctions.m);
                rec.SetSqlString(0, m);
                pipe.SendResultsRow(rec);
            }
            else
            {
                pipe.Send(m);
            }
        }
Exemplo n.º 26
0
    public static void Get_ApiServiceData(string URL)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);

        request.Method = "GET";
        //request.ContentLength = 0;
        //request.Credentials = CredentialCache.DefaultCredentials;
        request.ContentType = "application/json";
        request.Accept      = "application/json";
        HttpWebResponse response      = (HttpWebResponse)request.GetResponse();
        Stream          receiveStream = response.GetResponseStream();
        StreamReader    readStream    = new StreamReader(receiveStream, Encoding.UTF8);
        string          strContent    = readStream.ReadToEnd();
        DataSet         data          = JsonConvert.DeserializeObject <DataSet>(strContent);

        if (data.Tables.Count > 0)
        {
            DataTable dt   = data.Tables[0];
            SqlPipe   pipe = SqlContext.Pipe;

            SqlMetaData[] cols = new SqlMetaData[dt.Columns.Count];

            for (int col = 0; col < dt.Columns.Count; col++)
            {
                cols[col] = new SqlMetaData(dt.Columns[col].ColumnName, SqlDbType.NVarChar, 4000);
            }
            SqlDataRecord record = new SqlDataRecord(cols);
            pipe.SendResultsStart(record);

            for (int row = 0; row < dt.Rows.Count; row++)
            {
                for (int col = 0; col < dt.Columns.Count; col++)
                {
                    record.SetSqlString(col, new SqlString(Convert.ToString(dt.Rows[row][dt.Columns[col].ColumnName])));
                }

                pipe.SendResultsRow(record);
            }



            pipe.SendResultsEnd();
        }
    }
Exemplo n.º 27
0
 private static void SetRecordValueFromString(SqlDataRecord outputRecord, SqlMetaData[] columns, int columnID, string valueString)
 {
     if (valueString == null)
     {
         outputRecord.SetValue(columnID, null);
     }
     else
     {
         if (columns[columnID].DbType == DbType.Binary)
         {
             byte[] binaryData = Convert.FromBase64String(valueString);
             outputRecord.SetBytes(columnID, 0, binaryData, 0, binaryData.Length);
         }
         else
         {
             outputRecord.SetSqlString(columnID, new SqlString(valueString));
         }
     }
 }
        public static void NameProcedure(SqlString name)
        {
            var pipe = SqlContext.Pipe;

            var columns = new SqlMetaData[1];

            columns[0] = new SqlMetaData("HelloColumn", SqlDbType.NVarChar, 100);

            var row = new SqlDataRecord(columns);

            pipe.SendResultsStart(row);
            for (int i = 0; i < 5; i++)
            {
                row.SetSqlString(0, string.Format("{0} Hello, {1}", i, name));
                pipe.SendResultsRow(row);
            }

            pipe.SendResultsEnd();
        }
    public static async void TextAnalyticsAPI(String APIBaseURL, String APIVersionURL, String APIKey, String FullText, String OperationID)
    {
        HttpClient client;

        byte[] byteData;
        string JSONCallString   = "";
        string JSONCallResponse = "";
        string uri = "";

        // Define client http request header
        client             = new HttpClient();
        client.BaseAddress = new Uri(APIBaseURL);
        client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", APIKey);
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        // Define JSON Call Request body
        JSONCallString = "{\"documents\":[{\"id\":\"" + 1 + "\",\"text\":\"" + FullText.Replace("\"", "") + "\"}]}";
        byteData       = Encoding.UTF8.GetBytes(JSONCallString);

        // Define JSON Call Request uri
        if (OperationID == "S")
        {
            uri = APIBaseURL + APIVersionURL + "sentiment";
        }
        if (OperationID == "P")
        {
            uri = APIBaseURL + APIVersionURL + "keyPhrases";
        }

        // Call the Text Analytics API
        var content = new ByteArrayContent(byteData);

        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
        JSONCallResponse            = await CallEndpoint(client, uri, byteData);

        // Return the JSON Result
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData("JSONDocument", SqlDbType.NVarChar, 4000));

        record.SetSqlString(0, JSONCallResponse);
        SqlContext.Pipe.Send(record);
    }
Exemplo n.º 30
0
        static SqlDataRecord PopulateTaskMessageRecord(
            TaskMessage msg,
            SqlDataRecord record,
            EventPayloadMap?eventPayloadMap)
        {
            record.SetSqlString(ColumnOrdinals.InstanceID, msg.OrchestrationInstance.InstanceId);
            record.SetSqlString(ColumnOrdinals.ExecutionID, msg.OrchestrationInstance.ExecutionId);
            record.SetSqlString(ColumnOrdinals.Name, SqlUtils.GetName(msg.Event));
            record.SetSqlString(ColumnOrdinals.EventType, msg.Event.EventType.ToString());
            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);

            // Optionally, the LockedBy and LockExpiration fields can be specified
            // to pre-lock task work items for this particular node.

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

            return(record);
        }