ZennoLab Assemblies Documentation
UseTrafficMonitoring Property
Example 
ZennoLab.CommandCenter Namespace > Instance Class : UseTrafficMonitoring Property
Gets or sets a value that indicates whether use detailed traffic monitoring.
Syntax
public bool UseTrafficMonitoring {get; set;}

Property Value

Type: System.Boolean

The true if use detailed traffic monitoring; otherwise, false.

Example
The following code example demonstrates uses of the UseTrafficMonitoring property.
instance.SetContentPolicy("BlockList", new []{ "mc.yandex.ru" }, null);
instance.UseTrafficMonitoring = false;
Tab tab = instance.ActiveTab;
// navigate to url
instance.ClearCache();
instance.ClearCookie();
tab.Navigate("http://lessons.zennolab.com");
if (tab.IsBusy) tab.WaitDownloading();
// get list of requests
var traffic = instance.ActiveTab.GetTraffic();
// print count of items, it will be more than 0
project.SendInfoToLog("First count of traffic elements = " + traffic.Count());
// get some data from items and log it
foreach(var t in traffic)
    project.SendInfoToLog(string.Format("Url: {0}\r\n Method: {1}\r\n Result: {2}", t.Url, t.Method, t.ResultCode));
// get list of request second time
traffic = instance.ActiveTab.GetTraffic();
// print count of items, it will be 0, because the previous method call removed the old items
project.SendInfoToLog("Second count of traffic elements = " + traffic.Count());
            
// navigate to url
instance.ClearCache();
instance.ClearCookie();
tab.Navigate("http://lessons.zennolab.com");
if (tab.IsBusy) tab.WaitDownloading();
// get reqest by urls filter collection
traffic = instance.ActiveTab.GetTraffic(new [] {"http://lessons.zennolab.com/main.css"});
project.SendInfoToLog("Request by urls filter:");
foreach(var t in traffic)
    project.SendInfoToLog("Url: " + t.Url);
// result collection must has one item
if (traffic.Count(t => !t.IsBlocked) != 1)
    throw new Exception("Traffic collection count != 1");
// this item must match the filter collection
if (traffic.First().Url != "http://lessons.zennolab.com/main.css")
    throw new Exception("Traffic item url != http://lessons.zennolab.com/main.css");
// RequestHeaders and other additional fields must be null while instance.UseTrafficMonitoring == false 
if (!string.IsNullOrWhiteSpace(traffic.First().RequestHeaders))
    throw new Exception("Instance.UseTrafficMonitoring (false) is not working, value = " + instance.UseTrafficMonitoring);
// get list of request second time, second result list must be empty
traffic = instance.ActiveTab.GetTraffic().ToList();
if (traffic.Count(t => !t.IsBlocked) != 0)
	throw new Exception("Second traffic collection count != 0");
            
// enable additional traffic monitoring
instance.UseTrafficMonitoring = true;
            
// navigate to url
instance.ClearCache();
instance.ClearCookie();
tab.Navigate("http://lessons.zennolab.com");
if (tab.IsBusy) tab.WaitDownloading();
// get list of requests by urls filter collection and headers filter collection
traffic = instance.ActiveTab.GetTraffic(new [] {"http://lessons.zennolab.com/main.css"}, new [] { "image/png" });
project.SendInfoToLog("Request by urls filter collection and headers filter collection:");
foreach(var t in traffic)
    project.SendInfoToLog("Url: " + t.Url);
// result collection must has two item, first match url regex, second match header regex
if (traffic.Count(t => !t.IsBlocked) != 2)
    throw new Exception("Traffic collection count != 2");
// all items must contains RequestHeaders and other fields, because instance.UseTrafficMonitoring == true 
if (traffic.Any(t => string.IsNullOrWhiteSpace(t.RequestHeaders)))
    throw new Exception("Instance.UseTrafficMonitoring (true) is not working, value = " + instance.UseTrafficMonitoring);
// get list of request second time, second result list must be empty
traffic = instance.ActiveTab.GetTraffic().ToList();
if (traffic.Count(t => !t.IsBlocked) != 0)
    throw new Exception("Second traffic collection count != 0");
            
// navigate to url
instance.ClearCache();
instance.ClearCookie();
tab.Navigate("http://lessons.zennolab.com");
if (tab.IsBusy) tab.WaitDownloading();
// get list of requests by urls, headers and body filter collection
traffic = instance.ActiveTab.GetTraffic(new [] {"http://lessons.zennolab.com/main.css"}, new [] { "image/png" }, new [] { "DOCTYPE HTML PUBLIC" });
project.SendInfoToLog("Request by urls filter collection and headers filter collection:");
foreach(var t in traffic)
    project.SendInfoToLog("Url: " + t.Url);
// result collection must has three item
if (traffic.Count(t => !t.IsBlocked) != 3)
    throw new Exception("Traffic collection count != 3");
// all items must contains RequestHeaders and other fields, because instance.UseTrafficMonitoring == true 
if (traffic.Any(t => string.IsNullOrWhiteSpace(t.RequestHeaders)))
   throw new Exception("Instance.UseTrafficMonitoring (true) is not working, value = " + instance.UseTrafficMonitoring);
// get list of request second time, second result list must be empty
traffic = instance.ActiveTab.GetTraffic().ToList();
if (traffic.Count(t => !t.IsBlocked) != 0)
    throw new Exception("Second traffic collection count != 0");
Requirements

Target Platforms: Desktop: Windows XP SP3 and older. Server: Windows Server 2003 and older.

See Also

Reference

Instance Class
Instance Members
GetTraffic Method