Archive for category .net
C# OCR Library
Tessnet2
Download URL: http://www.pixel-technology.com/freeware/tessnet2/
1. Remember to download the 2.0 tessdata (tesseract-2.00.eng.tar.gz) instead of the one for 3.0
2. The image size has to be larger, otherwise it will always show result (Confidence: 100 ; Word : “~”)
3. Copy the “tessdata” folder to the exe folder OR to hardcode the path in the program
Recording HTTPS Traffic with JMeter’s Proxy Server & asp.net login
Recording HTTPS Traffic with JMeter’s Proxy Server _ BlazeMeter
JMeter Expert_ Testing performance of web page with Apache JMeter
Jmeter is an open source web performance testing tool.
The easiest way is to use “proxy” to record what you have done in browser, says firefox, and generate the script required.
For testing an asp.net based web application, below are important
- Regular Expression Extractor to get the viewstate and eventvalidation value generated by asp.net (Web Form only; no need for MVC)
- Adding Cookie Manager for storing cookie for asp.net
Regular Expression Extractors
Our first regular expression extractor will grab the page’s VIEWSTATE element and store it in the JMeterviewState
variable. Add a new Regular Expression Extractor in JMeter by:
- Right click on your Thread Group
- Choose Add -> Post Processors -> Regular Expression Extractor
- Configure as follows
- Reference Name:
viewState
- Regular Expression:
name="__VIEWSTATE" id="__VIEWSTATE" value="(.+?)"
- Template:
$1$
- Math No:
1
- Default Value:
ERROR
- Reference Name:
We also need to include a regex extractor that stores the EVENTVALIDATION element in the eventValidation
variable. Again:
- Right click on your Thread Group
- Choose Add -> Post Processors -> Regular Expression Extractor
- Configure as follows
- Reference Name:
eventValidation
- Regular Expression:
name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.+?)"
- Template:
$1$
- Math No:
1
- Default Value:
ERROR
- Reference Name:
Using the Extracted Values
Now that we have populated the viewState
and eventValidation
values, we need to include them when we POST to our application. In my run, this only happened on the login page.
- Select your login page POST in the Test Plan’s Recording Controller
- Set the
__VIEWSTATE
parameter to${viewState}
- Set the
__EVENTVALIDATION
parameter to${eventValidation}
HTTP Cookie Manager
If you run your test plan now, you will see that it is still not working. This is because ASP.NET WebForms uses a cookie to store the login session. We can solve this with JMeter’s “HTTP Cookie Manager”.
- Right click on your Thread Group
- Choose Add -> Config Element -> HTTP Cookie Manager
Finally, run your Test Plan. You should see that your WebForms application returns the correct responses to JMeter’s requests. If not, double check that you are using the viewState
and eventValidation
variables in your login page POST (or any other post, for that matter) and that you have added the Cookie Manager.
Bonus – Parameterize Credentials Across Threads
Application performance for multiple concurrent logins with the same user is probably not a very interesting test case for your system. Luckily, it is extremely easy to parameterize login credentials for JMeter threads with a “CSV Data Set Config” element.
Store Credentials in CSV File
- Create a text file named
credentials.csv
in the same directory as your Test Plan.jmx
file - Populate
credentials.csv
with the login credentials you want to use (mind extra spaces)
login_1,password_1
login_2,password_2
login_3,password_3
Add CSV Data Set Config
- Select your Thread Group
- Choose Add -> Config Element -> CSV Data Set Config
- Configure as follows
- Filename:
credentials.csv
- Variable Names:
username,password
- Filename:
Use Variable Credentials in Login Post
- Select your login page POST in the Test Plan’s Recording Controller
- Configure as follows
- <Your Login Element ID> :
${username}
- <Your Password Element ID> :
${password}
- <Your Login Element ID> :
Now the threads in your Test Plan will cycle through the credentials specified in your CSV.
Acknowledgements
The following articles were extremely helpful in figuring all of this out:
- Technically Works: Load Testing SharePoint (MOSS) Sites with JMeter
- Technically Works: Load Testing ASP.NET Sites with JMeter
- JMeter Tips: Tip #7: How to add cookie support to your Test Plan
- http://www.markschabacker.com/blog/2013/05/10/jmeter_with_webforms_authentication/
Sample VBA for looping thru rows and copying data
Posted by allenkwc in .net, Technology on August 16, 2013
Sub CopyData()
Dim iLastRow As Integer
Dim Rng As Range
iLastRow = Cells(Rows.Count, “K”).End(xlUp).Row
Dim ws1 As Worksheet
Set ws1 = Sheets(“Worksheet”)
Dim lastPo As String
Dim lastPoLine As String
Dim lastStyle As String
Dim lastDim As String
For i = 1 To iLastRow
‘handle style
If Not IsEmpty(ws1.Cells(i, “D”).Value) Then
lastStyle = ws1.Cells(i, “D”).Value
Else
ws1.Cells(i, “D”).Value = lastStyle
End If
‘handle values
If Not IsEmpty(ws1.Cells(i, “E”).Value) Then
lastPo = ws1.Cells(i, “E”).Value
lastPoLine = ws1.Cells(i, “F”).Value
lastDim = ws1.Cells(i, “G”).Value
Else
ws1.Cells(i, “E”).Value = lastPo
ws1.Cells(i, “F”).Value = lastPoLine
ws1.Cells(i, “G”).Value = lastDim
End If
Next i
End Sub
Team Foundation Server
There are few useful features to keep control the source code, following are few methods may be used in different scenario.
For example, when the project is under construction, while the current production version of the project is required to bug fix, there are few approaches to cater the needs,
1. Multiple workspace with labeling different versions of source code
– The workspace acts as the local working folder. By creating creating 2 different workspaces, one can contain the version under construction (e.g. v2.0), and get back the historical version which is labeled before (e.g. v1.0).
– Once the bug is fixed (v1.1), then check-in back the changed source code to TFS, added back to v2.0 or create a new label called v2.1
This is useful for small team development, while only one to two developers will fix the bug within limited time period.
2. Branching
– Create another branched version at the same time
– Both version is actually kept track in TFS (server side) instead of client side mentioned above (workspace)
– The branched version have to be merged to mainstream version after completion
This supports many developers working on the branched version and the main version at the same time.
3. Shelves
– Shelve acts as a temp location in TFS for putting existing incomplete changes
– By putting the changes into the shelves, the file is “undo” to previous version, for testing or developing another feature
Get Email Address from AD for Different Trusted Domains
public string GetADEmailAddress(string adFullUserName) { if (!adFullUserName.Contains(@"\")) return string.Empty; // init var string domain = adFullUserName.Contains(@"\") ? adFullUserName.Substring(0, adFullUserName.IndexOf(@"\")) : null; string adusername = adFullUserName.Contains(@"\") ? adFullUserName.Substring(adFullUserName.IndexOf(@"\") + 1) : ""; string adConnectionStringWithDomain = adConnectionString + "/CN=" + domain; DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain); DirectorySearcher dSearch = new DirectorySearcher(entry); dSearch.Filter = "(&(objectClass=user)(samAccountName=" + adusername + "))"; SearchResult r = dSearch.FindOne(); if (r != null) { DirectoryEntry UserDirectoryEntry = r.GetDirectoryEntry(); return UserDirectoryEntry.Properties["mail"].Value.ToString(); } return string.Empty; }
asp.net performance monitoring / debuging
Posted by allenkwc in .net, Technology on July 26, 2012
Performance Analysis of Logs (PAL) Tool
Analysis Performance Monitor Data
Debug Diagnostic Tool v1.2
http://www.microsoft.com/en-us/download/details.aspx?id=26798
Network Monitoring
http://www.microsoft.com/en-us/download/details.aspx?id=4865
Download and Install Debugging Tools for
Windows
http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx
Error while creating Excel object
Microsoft Excel Application entry missing in DCOMCNFG
On 64 bit system with 32 bit Office try this:
- Start
- Run
- mmc -32
- File
- Add Remove Snap-in
- Component Services
- Add
- OK
- Console Root
- Component Services
- Computers
- My Computer
- DCOM Config
- Microsoft Excel Application
- …
Error while creating Excel object
1. In DCOMCNFG, right click on the My Computer and select properties.
2. Choose the COM Securities tab
3. In Access Permissions, click “Edit Defaults” and add Network Service to it and give it “Allow local access” permission. Do the same for <Machine_name>\Users.
4. In launch and Activation Permissions, click “Edit Defaults” and add Network Service to it and give it “Local launch” and “Local Activation” permission. Do the same for <Machine_name>\Users
Solution fails on 64 bit system with error “Microsoft.Jet.OLEDB.4.0 provider is not registered on the local machine” and “Microsoft.ACE.OLEDB.12.0 provider is not registered on the local machine”.
Install: Microsoft Access Database Engine 2010 Redistributable
http://www.microsoft.com/en-us/download/details.aspx?id=13255
** Probably may need to install the Access 2007 version **
http://www.microsoft.com/en-us/download/confirmation.aspx?id=23734
If Offce 2003 (32 bits) already installed on the system, please
1. Remove the Office 2003 (32 bits)
2. Install above Access DB Engine (64bits)
3. Install back Office 2003 (32 bits)
IDictionary : Using custom class as key
I was using IDictionary
public class KeyClass { public int ValueA{get;set;} public int ValueB{get;set;} }
I was accessing values from dictionary like follows:
var k = new KeyClass(1, 1); var v = myDictionary[k];
The dictionary for sure contained KeyClass key with ValueA = 1 and ValueB = 1 and simillarly many other keys. But I got exception:
The given key is not present in the dictionary.
I implemented IComparable in class KeyClass but it did not solve my problem. I googled and found this CodeProject article. It describes following technique to use a class implementing IEqualityComparer
public class KeyClass { public int ValueA{get;set;} public int ValueB{get;set;} public class EqualityComparer : IEqualityComparer<KeyClass> { public bool Equals(KeyClass a, KeyClass b) { return a.ValueA == b.ValueA && a.ValueB == b.ValueB; } public int GetHashCode(KeyClass k) { return k.ValueA ^ k.ValueB; } } }
Now I have to declare IDictionary
var d = new Dictionary<KeyClass, ValueClass>(new KeyClass.EqualityComparer());
Things worked fine afterwards.