Tag: .NET

Windows Search SDK

Setup Environment
1. Install Microsoft Windows SDK

2. Install Microsoft Windows Search SDK

How to Add Indexing Location

CSearchManager searchManager = new CSearchManager();
CSearchCatalogManager catalogManager = searchManager.GetCatalog("SystemIndex");
CSearchCrawlScopeManager crawlScopeManager = catalogManager.GetCrawlScopeManager();

crawlScopeManager.AddUserScopeRule(@"file:///D:\My Documents\", 1, 1, 1);
crawlScopeManager.SaveAll();

catalogManager.Reindex();

How to Search Indexed Location

CSearchManager searchManager = new CSearchManager();
CSearchCatalogManager catalogManager = searchManager.GetCatalog("SystemIndex");

CSearchQueryHelper queryHelper = catalogManager.GetQueryHelper();
queryHelper.QueryWhereRestrictions = @"AND scope='file:D:\My Documents\'";

string sql = queryHelper.GenerateSQLFromUserQuery("Hello World");

using (OleDbConnection conneciton = new OleDbConnection(queryHelper.ConnectionString))
{
	using (OleDbCommand command = new OleDbCommand(sql, conneciton))
	{
		conneciton.Open();
		using (OleDbDataReader dataReader = command.ExecuteReader())
		{
			while (dataReader.Read())
			{
				Console.WriteLine(dataReader[0]);
			}
		}
	}
}

References

Advertisements

svn:ignore property for ASP.NET Development

*.o
*.lo
*.la
#*#
.*.rej
*.rej
.*~
*~
.#*
.DS_Store
thumbs.db
Thumbs.db
*.bak
*.class
*.exe
*.dll
*.mine
*.obj
*.ncb
*.lib
*.log
*.idb
*.pdb
*.ilk
*.msi*
.res
*.pch
*.suo
*.exp
*.*~
*.~*
~*.*
cvs
CVS
.CVS
.cvs
release
Release
debug
Debug
ignore
Ignore
bin
Bin
obj
Obj
*.csproj.user
*.user
*.generated.cs
*.Publish.xml
pkg
pkgobj
.vs

References:

Visual Studio Code Metrics

How to Generate Code Metrics Data

  • Click Analysis menu, then click Calculate Code Metrics for Solution

1. Maintainability Index
+ Measures ease of code maintenance. Higher values are better.
+ No individual method or property should have a maintainability index lower than 40

2. Cyclomatic Complexity
+ Measures number of branches. Lower values are better.
+ No individual method or property should have a cyclomatic complexity greater than 10

3. Depth of Inheritance
+ Measures length of object inheritance hierarchy. Lower values are better.
+ No individual type should have object inheritance hierarchy greater than 4

4. Class Coupling
+ Measures number of classes that are referenced. Lower values are better.
+ No individual type, method or property should have class coupling greater than 10

5. Lines of Code
+ Approximates the lines of executable code (IL code). Lower values are better.
+ Not a good measure by itself

References

How to: Using SharpZipLib

Create a zip file

FastZip fastZip = new FastZip();

string zipFileName; // The name of the zip file to create.
string sourceDirectory; // The directory to obtain the files and directories from.
bool recurse;  // True to recurse directories, false for no recursion.
string fileFilter; // The file filter to apply, null = No filter
fastZip.CreateZip(zipFileName, sourceDirectory, recurse, fileFilter);

Extract the contents of a zip file

FastZip fastZip = new FastZip();

string zipFileName; // The zip file to extract from.
string targetDirectory; // The directory to save extracted information in.
string fileFilter; // The file filter to apply, null = No filter
fastZip.ExtractZip(zipFileName, targetDirectory, fileFilter);

References

Convert Traditional Chinese to Simplified Chinese in .NET (Vise versa)

Add Reference Microsoft.VisualBasic

Convert Traditional Chinese to Simplified Chinese

using Microsoft.VisualBasic;

string input = "繁體中文";
string output = Strings.StrConv(input, VbStrConv.SimplifiedChinese);  // 繁体中文

Convert Simplified Chinese to Traditional Chinese

using Microsoft.VisualBasic;

string input = "简体中文";
string output = Strings.StrConv(input, VbStrConv.TraditionalChinese);  // 簡體中文

References:

Microsoft Code Analysis Tool .NET (CAT.NET)

CAT.NET is a binary code analysis tool that helps identify common variants of certain prevailing vulnerabilities that can give rise to common attack vectors such as Cross-Site Scripting (XSS), SQL Injection and XPath Injection.

Using CAT.NET in Visual Studio 2010

By default, CAT.NET v1 cannot be run in Visual Studio 2010. The following tweak can be used to enable CAT.NET v1 in Visual Studio 2010.

  1. In notepad, open file %APPDATA%\Microsoft\MSEnvShared\Addins\Microsoft.ACESec.CATNet.AddIn
  2. Add a line “<Version>10.0</Version>” below the line “<Version>9.0</Version>”
  3. Open Visual Studio 2010, and navigate to Tools –> CAT.NET Code Analysis