本文整理汇总了C#中Context.LogError方法的典型用法代码示例。如果您正苦于以下问题:C# Context.LogError方法的具体用法?C# Context.LogError怎么用?C# Context.LogError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context.LogError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
///<summary>
/// TestStepBase.Execute() implementation
///</summary>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
///<exception cref="ApplicationException"></exception>
public override void Execute(Context context)
{
context.LogInfo("Executing SSIS package: {0}", PackageLocation);
var ssisRuntime = new Microsoft.SqlServer.Dts.Runtime.Application();
using (var package = ssisRuntime.LoadPackage(PackageLocation, null))
{
var variables = package.Variables;
foreach (var variable in Variables)
{
context.LogInfo("Adding variable: {0}, value: {1}", variable.Name, variable.Value);
variables[variable.Name].Value = variable.Value;
}
var result = package.Execute();
var errors = package.Errors;
foreach (var error in errors)
{
context.LogError(error.Description);
}
if (Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success != result || 0 < errors.Count)
{
throw new ApplicationException("Package execution failed.");
}
context.LogInfo("Package executed successfully.");
}
}
示例2: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
_ctx = context;
string loadGenTestConfig = context.ReadConfigAsString(testConfig, "LoadGenTestConfig");
try
{
context.LogInfo("About to execute LoadGen script: {0}", loadGenTestConfig);
var doc = new XmlDocument();
doc.Load(loadGenTestConfig);
if (string.Compare(doc.FirstChild.Name, "LoadGenFramework", true, new CultureInfo("en-US")) != 0)
{
throw new ConfigException("LoadGen Configuration File Schema Invalid!");
}
var loadGen = new LoadGen(doc.FirstChild);
loadGen.LoadGenStopped += LoadGenStopped;
loadGen.Start();
}
catch (ConfigException cex)
{
context.LogError(cex.Message);
throw;
}
catch (Exception ex)
{
context.LogError(ex.Message);
throw;
}
while (!_bExitApp)
{
Thread.Sleep(0x3e8);
}
Thread.Sleep(0x1388);
}
示例3: ValidateXPathExpressions
private void ValidateXPathExpressions(XmlDocument doc, Context context)
{
foreach (XPathDefinition validation in _xPathValidations)
{
var xpathExp = validation.XPath;
var expectedValue = validation.Value;
if (null != validation.Description)
{
context.LogInfo("XPath: {0}", validation.Description);
}
context.LogInfo("Evaluting XPath {0} equals \"{1}\"", xpathExp, expectedValue);
XPathNavigator xpn = doc.CreateNavigator();
object result = xpn.Evaluate(xpathExp);
string actualValue = null;
if (result.GetType().Name == "XPathSelectionIterator")
{
var xpi = result as XPathNodeIterator;
xpi.MoveNext(); // BUGBUG!
actualValue = xpi.Current.ToString();
}
else
{
actualValue = result.ToString();
}
if (!string.IsNullOrEmpty(validation.ContextKey))
{
context.Add(validation.ContextKey, actualValue);
}
if (!string.IsNullOrEmpty(expectedValue))
{
if (0 != expectedValue.CompareTo(actualValue))
{
context.LogError("XPath evaluation failed. Expected:<{0}>. Actual:<{1}>.", expectedValue, actualValue);
throw new ApplicationException(
string.Format("XmlValidationStep failed, compare {0} != {1}, xpath query used: {2}",
expectedValue, actualValue, xpathExp));
}
context.LogInfo("XPath evaluation succeeded. Expected:<{0}>. Actual:<{1}>.", expectedValue, actualValue);
}
}
}
示例4: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
string qmgr = context.ReadConfigAsString(testConfig, "QueueManager");
MQQueueManager queueManager;
try
{
context.LogInfo("Opening queue manager '{0}'.", qmgr);
queueManager = new MQQueueManager(qmgr);
}
catch (Exception e)
{
throw new ApplicationException(string.Format("Failed to open queue manager {0}.", qmgr), e);
}
bool errors = false;
try
{
XmlNodeList queueNodes = testConfig.SelectNodes("Queue");
foreach (XmlNode queueNode in queueNodes)
{
string q = queueNode.InnerText;
context.LogInfo("Opening queue '{0}'.", q);
MQQueue queue = queueManager.AccessQueue(q, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
try
{
MQMessage mqMsg = new MQMessage();
MQGetMessageOptions mqMsgOpts = new MQGetMessageOptions();
int i = 0;
bool finished = false;
while (!finished)
{
try
{
// Get message from queue
queue.Get(mqMsg,mqMsgOpts);
i++;
}
catch (MQException mqe)
{
if (mqe.Reason == 2033) // No more messages.
{
finished = true;
}
else
{
throw;
}
}
}
context.LogInfo("Cleared {0} messages from queue '{1}'.", i, q);
}
catch (Exception e)
{
context.LogError("Failed to clear queue \"{0}\" with the following exception: {1}", q, e.ToString());
errors = true;
}
finally
{
if (queue != null)
{
queue.Close();
}
}
}
}
finally
{
if (queueManager != null)
{
queueManager.Close();
}
if (errors)
{
throw new ApplicationException("Failed to clear at least one queue.");
}
}
}
示例5: ExecuteValidation
public void ExecuteValidation(Stream data, Context context)
{
MemoryStream dataToValidateAgainst = null;
try
{
try
{
dataToValidateAgainst = StreamHelper.LoadFileToStream(_comparisonDataPath);
}
catch (Exception e)
{
context.LogError("BinaryValidationStep failed, exception caugh trying to open comparison file: {0}", _comparisonDataPath);
context.LogException(e);
throw;
}
try
{
data.Seek(0, SeekOrigin.Begin);
dataToValidateAgainst.Seek(0, SeekOrigin.Begin);
if (_compareAsUtf8)
{
// Compare the streams, make sure we are comparing like for like
StreamHelper.CompareStreams(StreamHelper.EncodeStream(data, System.Text.Encoding.UTF8), StreamHelper.EncodeStream(dataToValidateAgainst, System.Text.Encoding.UTF8));
}
else
{
StreamHelper.CompareStreams(data, dataToValidateAgainst);
}
}
catch (Exception e)
{
context.LogError("Binary validation failed while comparing the two data streams with the following exception: {0}", e.ToString());
// Dump out streams for validation...
data.Seek(0, SeekOrigin.Begin);
dataToValidateAgainst.Seek(0, SeekOrigin.Begin);
context.LogData("Stream 1:", data);
context.LogData("Stream 2:", dataToValidateAgainst);
throw;
}
}
finally
{
if (null != dataToValidateAgainst)
{
dataToValidateAgainst.Close();
}
}
}
示例6: ExecuteContextLoader
public void ExecuteContextLoader(Stream data, Context context)
{
var doc = new XmlDocument();
doc.Load(data);
foreach (var xPathExpression in _xPathExpressions)
{
var contextKey = (string)xPathExpression.First;
var xpathExp = (string)xPathExpression.Second;
string val;
context.LogInfo("XmlContextLoader loading key:{0} with value:\"{1}\"", contextKey, xpathExp);
try
{
val = doc.SelectSingleNode(xpathExp).InnerText;
}
catch (Exception ex)
{
context.LogError("The XPath expression: {0}, could not be evaluated", xpathExp);
context.LogException(ex);
throw;
}
context.Add(contextKey, val);
}
}
示例7: Execute
/// <summary>
/// ITestStep.Execute() implementation
/// </summary>
/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
public void Execute(XmlNode testConfig, Context context)
{
const string soapproxynamespace = "BizUnit.Proxy";
Stream request = null;
Stream response = null;
// Turn on shadow copying of asseblies for the current appdomain.
AppDomain.CurrentDomain.SetShadowCopyFiles();
try
{
string wsdlFile = context.ReadConfigAsString(testConfig, "WebServiceWSDLURL");
string soapMessagePath = context.ReadConfigAsString(testConfig, "MessagePayload", true);
string inputMessageTypeName = context.ReadConfigAsString(testConfig, "InputMessageTypeName", true);
string webMethod = context.ReadConfigAsString(testConfig, "WebMethod");
string serviceName = context.ReadConfigAsString(testConfig, "ServiceName");
Assembly proxyAssembly = GetProxyAssembly(wsdlFile, soapproxynamespace);
object objInputMessage = null;
if(null != inputMessageTypeName && null != soapMessagePath)
{
objInputMessage =
LoadMessage(proxyAssembly, soapproxynamespace + "." + inputMessageTypeName, soapMessagePath);
if (null != objInputMessage)
{
request = GetOutputStream(objInputMessage);
context.LogData("SOAPHTTPRequestResponseStep request data", request);
}
}
object proxy = Activator.CreateInstance(proxyAssembly.GetType(soapproxynamespace + "." + serviceName));
MethodInfo mi = proxy.GetType().GetMethod(webMethod);
context.LogInfo("SOAPHTTPRequestResponseStep about to post data from File: {0} to the Service: {1} defined in WSDL: {2}", soapMessagePath, serviceName, wsdlFile);
object outputMessage;
if (null != inputMessageTypeName && null != soapMessagePath)
{
outputMessage = mi.Invoke(proxy, new[] { objInputMessage });
}
else
{
outputMessage = mi.Invoke(proxy, null);
}
if (null != outputMessage)
{
response = GetOutputStream(outputMessage);
context.LogData("SOAPHTTPRequestResponseStep response data", response);
}
// Execute ctx loader step if present...
if (null != response)
{
context.ExecuteContextLoader(response, testConfig.SelectSingleNode("ContextLoaderStep"), true);
}
// Validate the response...
try
{
context.ExecuteValidator(response, testConfig.SelectSingleNode("ValidationStep"), true);
}
catch (Exception e)
{
throw new ApplicationException("SOAPHTTPRequestResponseStep response stream was not correct!", e);
}
}
catch(Exception ex)
{
context.LogError("SOAPHTTPRequestResponseStep Failed");
context.LogException(ex);
throw;
}
finally
{
if (null != response)
{
response.Close();
}
if (null != request)
{
request.Close();
}
}
}
示例8: Load
public override Stream Load(Context context)
{
var doc = new XmlDocument();
context.LogInfo("Loading file: {0}", FilePath);
doc.Load(FilePath);
if (null != UpdateXml)
{
foreach (var xpath in UpdateXml)
{
context.LogInfo("Selecting node in document, description: {0}, XPath: {1}", xpath.Description, xpath.XPath);
XPathNavigator xpn = doc.CreateNavigator();
XPathNavigator node = xpn.SelectSingleNode(xpath.XPath);
if (null == node)
{
context.LogError("XPath expression failed to find node");
throw new ApplicationException(String.Format("Node not found: {0}", xpath.Description));
}
if (!string.IsNullOrEmpty(xpath.ContextKey))
{
context.LogInfo("Updating XmlNode with value from context key: {0}", xpath.ContextKey);
node.SetValue(context.GetValue(xpath.ContextKey));
}
else
{
context.LogInfo("Updating XmlNode with value: {0}", xpath.Value);
node.SetValue(xpath.Value);
}
}
}
var ms = new MemoryStream();
doc.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
return ms;
}