关注开源代码的实际应用
下载AStyle.Net.Interface.rar,然后在项目中引用AStyle.Net.dll:
- string input = File.ReadAllText("in.txt");
- string temp = "";
- temp = AStyle.Net.Interface.Format(input, "--mode=cs --style=ansi --indent=tab");
- File.WriteAllText("out.txt",temp.Trim());
Berkeley DB是历史悠久的嵌入式数据库系统,早期主要应用在UNIX/LINUX操作系统上,现在也有大量的Windows应用程序使用Berkeley DB存储数据。Berkeley DB的存储的是key/value键值对,可以理解为硬盘上的超级hash表,可以管理256TB数据,而且能支撑几千个并发访问。BerkeleyDB 相关资料可以从这里下载:http://www.oracle.com/technology/products/berkeley-db/index.html。
由于SQLite只支持单写多读,大多数情况下无法满足大访问量Web站点应用的并发性要求;而DB4O的Embed模式完全不支持并发;可以考虑使用Berkeley DB作为Asp.Net的Embed数据库。
目前Berkeley DB官方有C++版和Java版。要想在.NET中使用,可以使用Berkeley DB for .NET的Binding(Wrapper)。Berkeley DB for .NET 最 新版本为0.95,支持BDB 4.3和4.5。下载到libdb-dotnet_0_95.zip后,解压,在解压缩后的bin目录找到libdb_dotNET45.dll,这就是 BDB 4.5的.NET Binding,在.NET项目中引用此DLL就可以开始使用了。

Mono是一个多平台支持的开源的.NET framework的实现,支持的操作系统有Unix, Windows, MacOS 和一些其他操作系统。
Mono 2.0包括ADO.NET 2.0/ASP.NET 2.0/Windows.Forms 2.0/System.XML 2.0/System.Drawing/Linq/GTK#等类库的实现。还包括C# 3.0/VB 8/IL编译器和很丰富的工具。 这个release比1.x更为完整和成熟了。其中,C#编译器对C# 3的支持已经完整;标准库方面,WinForms 2.0的API已经完整支持,LINQ和ASP.NET的支持也比之前更为完善;执行引擎开始共享泛型代码后占用内存量减少了。
现在的MONO已经是完全胜任.NET 2.0的工作,并且有众多3.0的特性了,连Linq都有了,SQLite的Provider也有了,现在的MONO已经走出实验室,可以进行小规模的Linux平台上应用开发了。
These compilers are part of the Mono 2.0 release:
Mono includes profiling tools, the standard development kit tools that are part of the .NET framework
2.0 Release Notes: http://www.mono-project.com/Release_Notes_Mono_2.0
Mono Project Announces Mono 2.0 for Cross-Platform Microsoft .NET Development: http://www.novell.com/news/press/mono-project-announces-mono-2-0-for-cross-platform-microsoft-net-development/
Miguel de Icaza's :http://tirania.org/blog/archive/2008/Oct-06.html
Managed Extensibility Framework(MEF)是.NET平台下的一个扩展性管理框架,它是一系列特性的集合,包括依赖注入(DI)以及Duck Typing等。MEF为开发人员提供了一个工具,让我们可以轻松的对应用程序进行扩展并且对已有的代码产生最小的影响,开发人员在开发过程中根据功能要 求定义一些扩展点,之后扩展人员就可以使用这些扩展点与应用程序交互;同时MEF让应用程序与扩展程序之间不产生直接的依赖,这样也允许在多个具有同样的 扩展需求之间共享扩展程序。进一步了解MEF可以看看TerryLee的文章:使用Managed Extensibility Framework方便的扩展应用程序
MEF之前放到了CodePlex的时候所使用的协议并不是开源协议,MS-LPL或者叫Microsoft Limited Permissive,这个协议要求代码只能在Windows平台上运行,不能在*unix平台上运行,在这个项目在CodePlex上放出来后,在开发社区,包括Mono之父Miguel De Icaza 对它提出了批评,微软积极听取社区的意见,意识到开源社区的价值,Glenn宣布了将这个项目的协议更改为开源的 MS-PL 协议。
MEF现在采用MS-PL协议和社区的声音和微软员工的努力分不开,以及微软认同开源社区的价值。大家也许已经知道开源项目Castle项目的创始人Hamilton Verissimo,加入了微软,担任微软MEF项目经理,这是它在Msdn的 Hamilton Verissimo blog。
刚刚看到开源运动和MVP,里面有很多回帖,对微软和开源之间存在很大的误解,需要有时间来修正。微软已经改变了 Enterprise Library 4 源代码的许可协议, 以基于开源友好的 Microsoft Public License (Ms-PL) 许可协议发布,可以在Mono下使用Enterprise Library 4.0。微软还在CodePlex上开源的很多项目都将将有利于在Unix上通过Mono重用这些类库,繁荣开源社区。
Reflexil是一个.NET程序集编辑器,方便开发人员对.NET程序进行修改;可以作为一个Reflector插件修改程序集的IL并保存到磁盘文件,也可以在自己的.NET程序中调用进行更为灵活的.NET程序集修改。Reflexil使用的Mono.Cecil[作者:Jb Evain ]。
Reflexil是个开源项目,位于http://sourceforge.net/projects/reflexil/ ,作者:Sebastien LEBRETON ,blog:http://sebastien.lebreton.free.fr/blog/,使用GPL License。
CodeProject上一篇详细介绍文章:Assembly Manipulation and C#/VB.NET Code Injection
本文仅记录一些简单的使用方法,供初学者参考。[from:http://www.rainsts.net/article.asp?id=313]
Lucene.Net是一个性能很好的信息检索库(或者叫搜索引擎内核)。Lucene.Net提供一套完整的API供应用程序实现全文索引与精确查询功能。这里只描述最基本的应用:
- //state the file location of the index
- string indexFileLocation = @"C:\Index";
- Lucene.Net.Store.Directory dir =
- Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation, true);
- //create an analyzer to process the text
- Lucene.Net.Analysis.Analyzer analyzer = new
- Lucene.Net.Analysis.Standard.StandardAnalyzer();
- //create the index writer with the directory and analyzer defined.
- Lucene.Net.Index.IndexWriter indexWriter = new
- Lucene.Net.Index.IndexWriter(dir, analyzer,
- /*true to create a new index*/ true);
- //create a document, add in a single field
- Lucene.Net.Documents.Document doc = new
- Lucene.Net.Documents.Document();
- Lucene.Net.Documents.Field fldContent =
- new Lucene.Net.Documents.Field("content",
- "The quick brown fox jumps over the lazy dog",
- Lucene.Net.Documents.Field.Store.YES,
- Lucene.Net.Documents.Field.Index.TOKENIZED,
- Lucene.Net.Documents.Field.TermVector.YES);
- doc.Add(fldContent);
- //write the document to the index
- indexWriter.AddDocument(doc);
- //optimize and close the writer
- indexWriter.Optimize();
- indexWriter.Close();
这里用到了5个主要类:Directory、Analyzer、IndexWriter、Document和Field。通过Directory 实例记录需要存储的索引;Analyzer用于分析目标文本;结合Directory与Analyzer创建IndexWriter实例;结合 Document实例与Field实例保存文档要被IndexWriter存储的内容。然后调用IndexWriter的Optimize方法与 Close方法。
1、Lucene.Net.Store.Directory - Directory代表目标索引目录。Lucene.Net中包含了两种实现:FSDirectory与RAMDirectory,分别将索引结果存放于 文件系统与内存。开发人员也可以通过继承Directory来实现自己的存储方法。
2、Lucene.Net.Analysis.Analyzer - Analyzer用于将文本分割成词语或词组,同时可去除多余的词语(比如英语里的and、a、the等等)。StandardAnalyzer实例化时 可传递要忽略的词语列表,如果传递的参数为空则使用Lucene.Net默认的设置。开发人员可通过继承Analyzer实现自己的文档索引方式。
3、Lucene.Net.Index.IndexWriter - 用于配合Analyzer将分析结果保存到Directory。
4、Lucene.Net.Docuemnts.Docuemnt - 用于代表一封EMail、或者一个网页、一篇文章等。
5、Lucene.Net.Documents.Field - Docement包含一个用于描述文档的Field列表。每个Field包括一个name与相应的value,其中value包含了可用于查询的文本。 Field.Store用于告诉IndexWriter将field的value保存到索引以便检索时取出。此外,Field.Index用于告诉 IndexWriter如何索引当前field,比如Field.Index.TOKENIZED表示将文本拆 分,Field.Index.UNTOKENIZED则相反。
- //state the file location of the index
- string indexFileLocation = @"C:\Index";
- Lucene.Net.Store.Directory dir =
- Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation, true);
- //create an index searcher that will perform the search
- Lucene.Net.Search.IndexSearcher searcher = new
- Lucene.Net.Search.IndexSearcher(dir);
- //build a query object
- Lucene.Net.Index.Term searchTerm =
- new Lucene.Net.Index.Term("content", "fox");
- Lucene.Net.Search.Query query = new Lucene.Net.Search.TermQuery(searchTerm);
- //execute the query
- Lucene.Net.Search.Hits hits = searcher.Search(query);
- //iterate over the results.
- for (int i = 0; i < hits.Length(); i++)
- {
- Document doc = hits.Doc(i);
- string contentValue = doc.Get("content");
- Console.WriteLine(contentValue);
- }
涉及的类有:Directory、IndexSearch、Query、Hits、Term。其中Query有多种实现:TermQuery, BooleanQuery, PhraseQuery, PrefixQuery, PhrasePrefixQuery, RangeQuery, FilteredQuery, 及 SpanQuery。Lucene.Net.Search.Hits用于表示查找的结果。