当前位置: 首页>>代码示例>>C#>>正文


C# Context.LogData方法代码示例

本文整理汇总了C#中Context.LogData方法的典型用法代码示例。如果您正苦于以下问题:C# Context.LogData方法的具体用法?C# Context.LogData怎么用?C# Context.LogData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Context的用法示例。


在下文中一共展示了Context.LogData方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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(System.Xml.XmlNode testConfig, Context context)
		{
			string queueManager = testConfig.SelectSingleNode("QueueManager").InnerText;
			string queue = testConfig.SelectSingleNode("Queue").InnerText;
			string path = testConfig.SelectSingleNode("SourcePath").InnerText;

			var reader = new StreamReader(path);
			string testData = reader.ReadToEnd();

			context.LogData("MSMQ input message:", testData);

			MQSeriesHelper.WriteMessage(queueManager, queue, testData, context);
		}
开发者ID:RobBowman,项目名称:BizUnit,代码行数:18,代码来源:MQSeriesPutStep.cs

示例2: Execute


//.........这里部分代码省略.........
                        }
                    case "DataConnectionFact":
                        {
                            var fact = currentFact as DataConnectionFact;
                            var conn = new SqlConnection(fact.ConnectionString);
                            conn.Open();
                            var dc = new DataConnection(fact.Dataset, fact.TableName, conn);
                            facts[i] = dc;
                            break;
                        }
                    case "dataTable":
                    case "dataRow":
                        {
                            var fact = currentFact as DataTableFact;

                            var dAdapt = new SqlDataAdapter();
                            dAdapt.TableMappings.Add("Table", fact.TableName);
                            var conn = new SqlConnection(fact.ConnectionString);
                            conn.Open();
                            var myCommand = new SqlCommand(fact.Command, conn) {CommandType = CommandType.Text};
                            dAdapt.SelectCommand = myCommand;
                            var ds = new DataSet(fact.Dataset);
                            dAdapt.Fill(ds);
                            var tdt = new TypedDataTable(ds.Tables[fact.TableName]);
                            if (fact.Type == "dataRow")
                            {
                                var tdr = new TypedDataRow(ds.Tables[fact.TableName].Rows[0], tdt);
                                facts[i] = tdr;
                            }
                            else
                            {
                                facts[i] = tdt;
                            }
                            break;
                        }
                }
                i++;
            }

            // Execute Policy Tester
            try
            {
                policyTester.Execute(facts, dti);
            }
            catch (Exception e)
            {
                context.LogException(e);
                throw;
            }
            finally
            {
                dti.CloseTraceFile();
            }

            // write out all document instances passed in
            foreach (object fact in facts)
            {
                switch (fact.GetType().Name)
                {
                    case "TypedXmlDocument":
                        {
                            var txd = (TypedXmlDocument)fact;

                            context.LogData("TypedXmlDocument result: ", txd.Document.OuterXml);
                            Stream data = StreamHelper.LoadMemoryStream(txd.Document.OuterXml);

                            // Validate if configured...
                            // HACK: We need to prevent ExecuteValidator for /each/ TypedXmlDocument
                            if (txd.DocumentType == "UBS.CLAS.PoC.Schemas.INSERTS")
                            {
                                foreach (var subStep in SubSteps)
                                {
                                    data = subStep.Execute(data, context);
                                }

                            }

                            break;
                        }
                    case "DataConnection":
                        {
                            var dc = (DataConnection)fact;
                            dc.Update(); // persist any changes
                            break;
                        }
                    case "TypedDataTable":
                        {
                            var tdt = (TypedDataTable)fact;
                            tdt.DataTable.AcceptChanges();
                            break;
                        }
                    case "TypedDataRow":
                        {
                            var tdr = (TypedDataRow)fact;
                            tdr.DataRow.AcceptChanges();
                            break;
                        }
                }
            }
        }
开发者ID:RobBowman,项目名称:BizUnit,代码行数:101,代码来源:FactBasedRuleEngineStep.cs

示例3: WriteStreamToConsole

		/// <summary>
		/// Helper method to write the data in a stream to the console
		/// </summary>
		/// <param name="description">The description text that will be written before the stream data</param>
		/// <param name="ms">Stream containing the data to write</param>
		/// <param name="context">The BizUnit context object which holds state and is passed between test steps</param>
		public static void WriteStreamToConsole(string description, MemoryStream ms, Context context)
		{
			ms.Seek(0, SeekOrigin.Begin);
			var sr = new StreamReader(ms);
			context.LogData( description, sr.ReadToEnd() );
			ms.Seek(0, SeekOrigin.Begin);
		}
开发者ID:RobBowman,项目名称:BizUnit,代码行数:13,代码来源:StreamHelper.cs

示例4: Execute

        /// <summary>
        /// ITestStep.Execute() implementation
        /// </summary>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public override void Execute(Context context)
        {
            if (DelayBeforeCheck > 0)
            {
                context.LogInfo("Waiting for {0} seconds before checking the event log.", DelayBeforeCheck);
                System.Threading.Thread.Sleep(DelayBeforeCheck * 1000);
            }

            DateTime cutOffTime = context.TestCaseStart;
            // Note: event log time is always truncated, so the cut off time also need sto be!
            cutOffTime = cutOffTime.Subtract(new TimeSpan(0, 0, 0, 0, context.TestCaseStart.Millisecond + 1));

            bool found = false;
            using (var log = new System.Diagnostics.EventLog(EventLog, Machine))
            {
                EventLogEntryCollection entries = log.Entries;

                context.LogInfo("Scanning {0} event log entries from log: '{1}' on machine: '{2}', cutOffTime: '{3}'.", entries.Count, EventLog, Machine, cutOffTime.ToString("HH:mm:ss.fff dd/MM/yyyy"));
                for (int i = entries.Count - 1; i >= 0; i--)
                {
                    EventLogEntry entry = entries[i];
                    if (0 > (DateTime.Compare(entry.TimeGenerated, cutOffTime)))
                    {
                        context.LogInfo("Scanning of event log stopped, event.TimeGenerated: {0}, cutOffTime: {1}", entry.TimeGenerated.ToString("HH:mm:ss.fff dd/MM/yyyy"), cutOffTime.ToString("HH:mm:ss.fff dd/MM/yyyy"));
                        break;
                    }

                    context.LogInfo("Checking entry, Source: {0}, EntryType: {1}, EventId: {2}", entry.Source, entry.EntryType, entry.InstanceId);

                    // Note: EventId is optional...
                    if (((entry.Source == Source) && (entry.EntryType == EntryType)) &&
                         (((EventId > 0) && (entry.InstanceId == EventId)) || (EventId == 0)))
                    {
                        foreach (string validationRegex in ValidationRegExs)
                        {
                            string matchPattern = validationRegex;
                            Match match = Regex.Match(entry.Message, matchPattern);

                            if (match.Success)
                            {
                                found = true;
                                context.LogInfo("Successfully matched event log entry generated at '{0}'.", entry.TimeGenerated);
                                context.LogData("Event log entry.", entry.Message);
                                break;
                            }
                        }
                    }

                    if (found)
                    {
                        break;
                    }
                }
            }

            // Check that its ok
            if (!FailIfFound && !found)
            {
                throw new ApplicationException("Failed to find expected event log entry.");
            }

            if (FailIfFound && found)
            {
                throw new ApplicationException("Found event log entry which should not be present.");
            }
        }
开发者ID:RobBowman,项目名称:BizUnit,代码行数:70,代码来源:EventLogCheckStep.cs

示例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();
                }
            }
        }
开发者ID:RobBowman,项目名称:BizUnit,代码行数:55,代码来源:BinaryValidationStep.cs

示例6: 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 queueManager = context.ReadConfigAsString(testConfig, "QueueManager");
			string queue = context.ReadConfigAsString(testConfig, "Queue");
			int waitTimeout = context.ReadConfigAsInt32(testConfig, "WaitTimeout");
			XmlNode validationConfig = testConfig.SelectSingleNode("ValidationStep");

		    string message = MQSeriesHelper.ReadMessage(queueManager, queue, waitTimeout, context);

            context.LogData("MQSeries output message:", message);

            context.ExecuteValidator(StreamHelper.LoadMemoryStream(message), validationConfig);
		}
开发者ID:RobBowman,项目名称:BizUnit,代码行数:18,代码来源:MQSeriesGetStep.cs

示例7: Execute

        /// <summary>
        /// ITestStep.Execute() implementation
        /// </summary>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public void Execute(Context context)
	    {
            MemoryStream data = null;

            try
            {
                context.LogInfo("Searching for files in: \"{0}{1}\"", _directory, _searchPattern);

                DateTime endTime = DateTime.Now + TimeSpan.FromMilliseconds(_timeout);
                FileInfo[] files;

                do
                {
                    var di = new DirectoryInfo(_directory);
                    files = di.GetFiles(_searchPattern);

                    Thread.Sleep(100);
                } while ((files.Length == 0) && (endTime > DateTime.Now));

                if (files.Length == 0)
                {
                    throw new ApplicationException(string.Format("No files were found at: {0}{1}", _directory, _searchPattern));
                }

                context.LogInfo("{0} fies were found at : \"{1}{2}\"", files.Length, _directory, _searchPattern);

                IOException ex = null;
                do
                {
                    try
                    {
                        using (var fs = new FileStream(files[0].FullName, FileMode.Open, FileAccess.Read))
                        {
                            data = StreamHelper.LoadMemoryStream(fs);
                        }
                    }
                    catch (IOException ioex)
                    {
                        context.LogWarning("IOException caught trying to load file, will re-try if within timeout");
                        ex = ioex;
                        Thread.Sleep(100);
                    }
                } while ((null == data) && (endTime > DateTime.Now));

                if (null != ex)
                {
                    throw ex;
                }

                context.LogData(string.Format("Loaded FILE: {0}", files[0].FullName), data);

                data.Seek(0, SeekOrigin.Begin);
                if (null != _contextLoaderStep)
                {
                    _contextLoaderStep.ExecuteContextLoader(data, context);
                }

                if (null != _contextConfig)
                {
                    context.ExecuteContextLoader(data, _contextConfig);
                }

                data.Seek(0, SeekOrigin.Begin);
                if (null != _validationStep)
                {
                    context.ExecuteValidator(data, _validationStep);
                }

                if (null != _validationConfig)
                {
                    context.ExecuteValidator(data, _validationConfig);
                }

                if (_deleteFile)
                {
                    File.Delete(files[0].FullName);
                }
            }
            finally
            {
                if (null != data)
                {
                    data.Close();
                }
            }
        }
开发者ID:RobBowman,项目名称:BizUnit,代码行数:90,代码来源:FileValidateStep.cs

示例8: 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();
                }
            }
        }
开发者ID:RobBowman,项目名称:BizUnit,代码行数:94,代码来源:SOAPHTTPRequestResponseStep.cs

示例9: Execute

		/// <summary>
		/// 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)
		{
			int delayBeforeCheck = context.ReadConfigAsInt32(testConfig, "DelayBeforeCheck", true);
			string server = context.ReadConfigAsString(testConfig, "Server");
			string user = context.ReadConfigAsString(testConfig, "User");
			string password = context.ReadConfigAsString(testConfig, "Password");
			string from = null;
			bool showBody = false;
			string subject = null;
			int attachments = -1;
			bool found = false;

			if (testConfig.SelectSingleNode("ShowBody") != null)
			{
				showBody = context.ReadConfigAsBool(testConfig, "ShowBody");
			}

			if (testConfig.SelectSingleNode("From") != null)
			{
				from = context.ReadConfigAsString(testConfig, "From");
			}

			if (testConfig.SelectSingleNode("Subject") != null)
			{
				subject = context.ReadConfigAsString(testConfig, "Subject");
			}

			if (testConfig.SelectSingleNode("Attachments") != null)
			{
				attachments = context.ReadConfigAsInt32(testConfig, "Attachments");
			}

			if ( delayBeforeCheck > 0 )
			{
				context.LogInfo("Waiting for {0} seconds before checking the mail.", delayBeforeCheck);
				System.Threading.Thread.Sleep(delayBeforeCheck*1000);
			}			

			var email = new Pop3Client(user, password, server);
			email.OpenInbox();

			try
			{
				while( email.NextEmail())
				{
					if (email.To == user && (email.From == from || from == null) && (email.Subject == subject || subject == null))
					{
						if (attachments > 0 && email.IsMultipart)
						{
							int a = 0;
							IEnumerator enumerator = email.MultipartEnumerator;
							while(enumerator.MoveNext())
							{
								var multipart = (Pop3Component)
									enumerator.Current;
								if( multipart.IsBody )
								{
									if (showBody)
									{
										context.LogData("Multipart body", multipart.Data);
									}
								}
								else
								{
									context.LogData("Attachment name", multipart.Name);
									a++;
								}
							}
							if (attachments == a)
							{
								found = true;
								break;
							}
						}
						else
						{
							if (showBody)
							{
								context.LogData("Single body", email.Body);
							}
							found = true;
							break;
						}							
					}
				}


				if (!found)
				{
					throw new Exception("Failed to find email message");
				}
				else
				{
					email.DeleteEmail();
				}
//.........这里部分代码省略.........
开发者ID:RobBowman,项目名称:BizUnit,代码行数:101,代码来源:CheckPop3MailStep.cs

示例10: Execute

        /// <summary>
        /// TestStepBase.Execute() implementation
		/// </summary>
		/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
		public override void Execute(Context context)
        {
            var endTime = DateTime.Now.AddMilliseconds(Timeout);
            bool found = false;
            string[] filelist;
            int timesLogged = 0;

            context.LogInfo("Searching directory: {0}, search pattern: {1}", DirectoryPath, SearchPattern);

            do
            {
                Thread.Sleep(100);

                // Get the list of files in the directory
                filelist = Directory.GetFiles(DirectoryPath, SearchPattern);

                if ( filelist.Length == ExpectedNumberOfFiles)
                    break;

            } while (endTime > DateTime.Now);

            context.LogInfo("Number of files found: {0}", filelist.Length);

            if (filelist.Length == 0)
            {
                // Expecting more than one file 
                throw new ApplicationException(String.Format("Directory contains no files matching the pattern!"));
            }

            if (0 < ExpectedNumberOfFiles && filelist.Length != ExpectedNumberOfFiles)
            {
                // Expecting a specified number of files
                throw new ApplicationException(String.Format("Directory contained: {0} files, but the step expected: {1} files", filelist.Length, ExpectedNumberOfFiles));
            }

            // For each file in the file list
            foreach (string filePath in filelist)
            {
                context.LogInfo("FileReadMultipleStep validating file: {0}", filePath);

                Stream fileData = StreamHelper.LoadFileToStream(filePath, Timeout);
                context.LogData("File: " + filePath, fileData);
                fileData.Seek(0, SeekOrigin.Begin);

                // Check it against the validate steps to see if it matches one of them
                foreach(var subStep in SubSteps)
                {
                    try
                    {
                        // Try the validation and catch the exception
                        fileData = subStep.Execute(fileData, context);
                    }
                    catch (Exception ex)
                    {
                        context.LogException(ex);
                        throw;
                    }
                }   

                if(DeleteFiles)
                {
                    System.IO.File.Delete(filePath);
                }
            }
        }
开发者ID:RobBowman,项目名称:BizUnit,代码行数:69,代码来源:FileReadMultipleStep.cs


注:本文中的Context.LogData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。