本文整理汇总了C#中IJobExecutionContext.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IJobExecutionContext.GetType方法的具体用法?C# IJobExecutionContext.GetType怎么用?C# IJobExecutionContext.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IJobExecutionContext
的用法示例。
在下文中一共展示了IJobExecutionContext.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute(IJobExecutionContext context)
{
JobDataMap data = context.MergedJobDataMap;
var jobName = context.JobDetail.Key.Name;
string actionType = GetRequiredParameter(data, ActionType, jobName);
string method = GetRequiredParameter(data, Method, jobName);
string uri = GetRequiredParameter(data, Uri, jobName);
string body = GetOptionalParameter(data, Body) ?? string.Empty;
string contentType = GetOptionalParameter(data, ContentType) ?? "text/plain";
// Parse tokens in uri. This allows passing context property values, such as FireInstanceId, in the query string
var r = new Regex(Regex.Escape("{$") + "(.*?)" + Regex.Escape("}"));
MatchCollection matches = r.Matches(uri);
foreach (object match in matches)
{
var token = match.ToString();
var tokenValue = token.Replace("{$", "").Replace("}", "");
PropertyInfo prop = context.GetType().GetProperty(tokenValue, BindingFlags.Public | BindingFlags.Instance);
if (null != prop && prop.CanRead)
{
var val = prop.GetValue(context);
if (null != val)
{
uri = uri.Replace(token, val.ToString());
}
}
}
if (uri.ToLower().StartsWith("http"))
{
uri = uri.Replace("http://", "");
uri = uri.Replace("https://", "");
uri = uri.Replace("HTTP://", "");
uri = uri.Replace("HTTPS://", "");
}
if (!actionType.Contains("://"))
{
actionType += "://";
}
// Execute WebRequest
System.Net.WebRequest request = System.Net.WebRequest.Create(actionType + uri);
request.Credentials = CredentialCache.DefaultNetworkCredentials;
request.Method = method;
Stream dataStream;
// Create POST/PUT data and convert it to a byte array.
if (method.ToUpper() == "PUT" || method.ToUpper() == "POST")
{
byte[] byteArray = Encoding.UTF8.GetBytes(body);
request.ContentType = contentType;
request.ContentLength = byteArray.Length;
dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
}
// Get the response.
try
{
WebResponse response = request.GetResponse();
Logger.InfoFormat("WebRequestJob server response status: {0}", ((HttpWebResponse) response).StatusDescription);
// Get the stream containing content returned by the server.
using (dataStream = response.GetResponseStream())
{
if (dataStream != null)
{
var reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
context.Result = responseFromServer;
Logger.InfoFormat("WebRequestJob server response content: {0}", responseFromServer);
reader.Close();
}
}
response.Close();
}
catch (WebException ex)
{
Logger.Error(string.Format("Error in WebRequestJob ({0}):", jobName), ex);
context.Result = ex.Message;
if (ex.Response != null)
{
using (var errorResponse = (HttpWebResponse) ex.Response)
{
var stream = errorResponse.GetResponseStream();
if (stream != null)
{
using (var reader = new StreamReader(stream))
{
string error = reader.ReadToEnd();
Logger.ErrorFormat("Error in WebRequestJob ({0}): {1}", jobName, error);
//.........这里部分代码省略.........