예제 #1
0
        public void Conversions()
        {
            // ToByteArray ()
            Assert.AreEqual((byte)1, Test1.ToByteArray() [0], "#L01");
            Assert.AreEqual((byte)15, Test2.ToByteArray() [1], "#L02");

            // ToSqlBinary ()
            byte [] b = new byte [2];
            b [0] = 100;
            b [1] = 15;

            Assert.AreEqual(new SqlBinary(b), Test3.ToSqlBinary(), "#L03");

            // ToSqlString ()
            Assert.AreEqual("00000a01-0000-0000-0000-000000000000", Test1.ToSqlString().Value, "#L04");
            Assert.AreEqual("0000fafa-0000-0000-0000-000000000000", Test4.ToSqlString().Value, "#L05");

            // ToString ()
            Assert.AreEqual("00000a01-0000-0000-0000-000000000000", Test1.ToString(), "#L06");
            Assert.AreEqual("0000fafa-0000-0000-0000-000000000000", Test4.ToString(), "#L07");
        }
예제 #2
0
        public void Conversions()
        {
            // ToByteArray ()
            Assert.Equal((byte)1, _test1.ToByteArray()[0]);
            Assert.Equal((byte)15, _test2.ToByteArray()[1]);

            // ToSqlBinary ()
            byte[] b = new byte[2] {
                100, 15
            };

            Assert.Equal(new SqlBinary(b), _test3.ToSqlBinary());

            // ToSqlString ()
            Assert.Equal("00000a01-0000-0000-0000-000000000000", _test1.ToSqlString().Value);
            Assert.Equal("0000fafa-0000-0000-0000-000000000000", _test4.ToSqlString().Value);

            // ToString ()
            Assert.Equal("00000a01-0000-0000-0000-000000000000", _test1.ToString());
            Assert.Equal("0000fafa-0000-0000-0000-000000000000", _test4.ToString());
        }
예제 #3
0
 public override string ToString()
 {
     return(_guid.ToString());
 }
예제 #4
0
 public override string ToString() => _sql.ToString();
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(_sql.ToString());
 }
예제 #6
0
    public static string DoExternalRequest(SqlGuid workflowTemplateElementId, SqlGuid workflowParameterId)
    {
        var status           = "0";
        var parameters       = new Dictionary <string, string>();
        var externalRequests = new Dictionary <string, string>();
        var contact          = new DataTable();

        try
        {
            using (SqlConnection conn = new SqlConnection("context connection=true"))
            {
                conn.Open();
                var query = string.Empty;

                query = string.Format("SELECT * FROM tbl_WorkflowTemplateElementParameter WHERE WorkflowTemplateElementID=N'{0}'", workflowTemplateElementId);
                using (var command = new SqlCommand(query, conn))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                parameters.Add((string)reader["Name"], (string)reader["Value"]);
                            }
                            reader.NextResult();
                        }
                    }
                }

                query = string.Format("SELECT * FROM tbl_WorkflowTemplateElementExternalRequest WHERE WorkflowTemplateElementID=N'{0}'", workflowTemplateElementId);
                using (var command = new SqlCommand(query, conn))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                externalRequests.Add((string)reader["Name"], (string)reader["Value"]);
                            }
                            reader.NextResult();
                        }
                    }
                }

                query = string.Format("SELECT TOP 1 * FROM tbl_Contact WHERE ID='{0}'", workflowParameterId);
                using (var command = new SqlCommand(query, conn))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            contact.Load(reader);
                        }
                    }
                }

                conn.Close();
                conn.Dispose();
            }

            WebRequest request = WebRequest.Create(parameters.FirstOrDefault(a => a.Key == "ExternalRequestURL").Value);
            request.Method = parameters.FirstOrDefault(a => a.Key == "ExternalRequestType").Value;

            var postData = string.Empty;
            if (externalRequests.Count > 0)
            {
                foreach (var externalRequest in externalRequests)
                {
                    //postData += string.Format("{0}={1}&", externalRequest.Key, HttpUtility.UrlEncode(externalRequest.Value, Encoding.GetEncoding(1251)));
                    postData += string.Format("{0}={1}&", externalRequest.Key, externalRequest.Value);
                }
                postData = postData.TrimEnd(new[] { '&' });
            }

            postData = postData.Replace("#User.UserFullName#", contact.Rows[0]["UserFullName"].ToString())
                       .Replace("#User.LastName#", contact.Rows[0]["Surname"].ToString())
                       .Replace("#User.FirstName#", contact.Rows[0]["Name"].ToString())
                       .Replace("#User.MiddleName#", contact.Rows[0]["Patronymic"].ToString())
                       .Replace("#User.Email#", contact.Rows[0]["Email"].ToString())
                       .Replace("#User.Phone#", contact.Rows[0]["Phone"].ToString())
                       .Replace("#User.Score#", contact.Rows[0]["Score"].ToString());

            var r       = new Regex(@"#User.[\S]+?#");
            var results = r.Matches(postData);
            foreach (Match result in results)
            {
                var siteColumnId = GetSiteColumnId(contact.Rows[0]["SiteID"].ToString(), result.Value.Replace("#User.", "").Replace("#", ""));
                if (!string.IsNullOrEmpty(siteColumnId))
                {
                    var contactColumnValue = GetContactColumnValues(workflowParameterId.ToString(), siteColumnId);
                    if (contactColumnValue != null && contactColumnValue.Rows.Count > 0)
                    {
                        switch (contactColumnValue.Rows[0]["TypeID"].ToString())
                        {
                        case "1":
                        case "4":
                        case "5":
                            postData = postData.Replace(result.Value, contactColumnValue.Rows[0]["StringValue"].ToString().Replace("[BR]", "\n"));
                            break;

                        case "2":
                            postData = postData.Replace(result.Value, ((DateTime)contactColumnValue.Rows[0]["DateValue"]).ToString("dd.MM.yyyy HH:mm"));
                            break;

                        case "3":
                            postData = postData.Replace(result.Value, contactColumnValue.Rows[0]["Value"].ToString());
                            break;
                        }
                    }
                    else
                    {
                        postData = postData.Replace(result.Value, "");
                    }
                }
            }

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            WebResponse response = request.GetResponse();
            if ((int)(((HttpWebResponse)response)).StatusCode >= 200 &&
                (int)(((HttpWebResponse)response)).StatusCode < 400)
            {
                status = "1";
            }

            dataStream.Close();
            response.Close();
        }
        catch (Exception)
        {
        }

        return(status);
    }