程序员 coding啥意思
I sat down with the Coding4Fun Developer Kit and immediately noticed the Preview Handler stuff. I got addicted to Preview Handlers back when Tim wrote one for PDFs. They are darned useful and it seems to me that any application that adds a new file type should add a preview handler for it. They are used in the Vista Explorer, in Outlook 2007 and in Windows Desktop Search. If you or your company makes an explorer replacement, you can also host a Preview Control and add Preview functionality to your own File Explorer application.
我坐在Coding4Fun开发人员套件中,立即注意到Preview Handler的内容。 提姆为PDF编写预览处理器时,我上瘾了。 它们非常有用,在我看来,任何添加新文件类型的应用程序都应为其添加预览处理程序。 它们在Vista资源管理器,Outlook 2007和Windows桌面搜索中使用。 如果您或您的公司替换了资源管理器,则还可以托管预览控件并将预览功能添加到您自己的文件资源管理器应用程序中。
I wanted to make a vCard Preview Handler so I could see what's inside a vCard on systems that don't have Outlook. Here's the process to create your own Preview Handler in no time (keeping in mind that the kit is BETA).
我想制作一个vCard预览处理程序,以便可以在没有Outlook的系统上看到vCard内部的内容。 这是立即创建您自己的预览处理程序的过程(请记住,该工具包是BETA )。
Create a new class like below and add the [PreviewHandler] attribute with a name for your project, the extension or extensions (like .foo;.bar), and another Guid for the COM Stuff.
创建一个如下所示的新类,并为[PreviewHandler]属性添加项目名称,一个或多个扩展名(例如.foo; .bar)和另一个用于COM Stuff的Guid。
You can get new GUIDs either via GuidGen.exe included with the Windows SDK or online at http://www.guidgen.com/ or in PowerShell via [Guid]::NewGuid().ToString().
您可以通过Windows SDK附带的GuidGen.exe或通过http://www.guidgen.com/在线获得新的GUID,也可以通过[Guid] :: NewGuid()。ToString()在PowerShell中获得新的GUID。
using C4F.DevKit.PreviewHandler.PreviewHandlerFramework;namespace C4F.DevKit.PreviewHandler.PreviewHandlers
{[PreviewHandler("Hanselman Silly vCard Preview Handler", ".vcf", "{42810C0B-FEA8-4dbf-A711-5634DFBA9F3B}")][ProgId("C4F.DevKit.PreviewHandler.PreviewHandlers.vCardPreviewHandler")][Guid("D193B258-AC07-4139-B334-C20F18F4FC7C")][ClassInterface(ClassInterfaceType.None)][ComVisible(true)]public sealed class vCardPreviewHandler : FileBasedPreviewHandler{protected override PreviewHandlerControl CreatePreviewHandlerControl(){return new vCardPreviewHandlerControl();}private sealed class vCardPreviewHandlerControl : FileBasedPreviewHandlerControl{public override void Load(FileInfo file){
//ADD STUFF HERE}}}
}
vCards are funky things, and there's multiple versions of the format. The general format is like this:
电子名片很时髦,并且有多种格式。 通用格式如下:
BEGIN:VCARDVERSION:2.1N;LANGUAGE=en-us:Hanselman;ScottFN:Scott HanselmanORG:MicrosoftTITLE:Senior Program ManagerTEL;WORK;VOICE:+1 (503) 766-2048TEL;HOME;VOICE:+1 (503) 766-2048TEL;CELL;VOICE:+1 (503) 766-2048ADR;WORK;PREF:;;One Microsoft Way;Redmond;WA;11111;United States of AmericaLABEL;WORK;PREF;ENCODING=QUOTED-PRINTABLE:One Microsoft Way=0D=0A=Redmond, WA 11111ADR;HOME:;;5 Main Street;Main Town;OR,;12345;United States of AmericaLABEL;HOME;ENCODING=QUOTED-PRINTABLE:5 Main Street=0D=0A=Main Town, OR, 12345URL;WORK:http://www.hanselman.comEMAIL;PREF;INTERNET:firstname@lastname.com REV:20070810T050105ZEND:VCARD
BEGIN:VCARDVERSION:2.1N; LANGUAGE = en-us:Hanselman; ScottFN:Scott HanselmanORG:MicrosoftTITLE:Senior Program ManagerTEL; WORK; VOICE:+1(503)766-2048TEL; HOME; VOICE:+1(503)766- 2048TEL; CELL; VOICE:+1(503)766-2048ADR; WORK; PREF:;; One Microsoft Way; Redmond; WA; 11111; United States of AmericaLABEL; WORK; PREF; ENCODING = QUOTED-PRINTABLE:One Microsoft Way = 0D = 0A =雷德蒙德,WA 11111ADR; HOME:;; 5 Main Street; Main Town; OR,; 12345; United States of AmericaLABEL; HOME; ENCODING = QUOTED-PRINTABLE:5 Main Street = 0D = 0A = Main Town ,12345URL; WORK: http : //www.hanselman.com EMAIL; PREF; INTERNET:firstname@lastname.com REV:20070810T050105ZEND:VCARD
But there's a million extensions to this format and things can get very complex very fast. I set myself a goal of getting something passable working in a few hours, so I decided to preview the vCard in a DataGrid. That made Load() look like this:
但是,这种格式有100万种扩展,事情很快就会变得非常复杂。 我设定的目标是在几个小时内使某些东西能够通过,因此我决定在DataGrid中预览vCard。 这使得Load()看起来像这样:
public override void Load(FileInfo file)
{DataGridView grid = new DataGridView();grid.DataSource = ConvertVCardToDataTable(file);grid.ReadOnly = true;grid.Dock = DockStyle.Fill;grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;Controls.Add(grid);
}
Next, I took the FileInfo and spun through it, breaking up each line and sticking it into a static DataTable, the format most friendly to the DataGridView.
接下来,我获取FileInfo并将其旋转通过,将每一行分开,并将其粘贴到静态DataTable中,该格式对DataGridView最友好。
private static DataTable ConvertVCardToDataTable(FileInfo file)
{DataTable table = new DataTable();table.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;table.TableName = file.Name;using (StreamReader sr = file.OpenText()){table.Columns.Add("Data");table.Columns.Add("Value");string line;while ((line = sr.ReadLine()) != null){if (line.Length > 3){string[] parts = ProcessVCardLine(line);if (parts != null && parts.Length == 2){table.Rows.Add(parts);}}}}return table;
}
ProcessVCardLine just returns a string array of "name,value" given a single vCard line. Again, I never said it was pretty, I just said it worked.
给定单个vCard行,ProcessVCardLine仅返回“名称,值”的字符串数组。 再说一次,我从未说过它很漂亮,我只是说它有效。
private static string[] ProcessVCardLine(string line)
{//This is by no means a complete or even passable parsing of the fairly complex vCard format.List
}private static void AddVCardLine(string[] parts, ref List
{if (parts[0].StartsWith(name) && parts[1] != null){nameValue.Add(friendlyName);nameValue.Add(parts[1].Replace(";", ",").Trim().Trim(','));}
}
因为这是一个需要COM dll的应用程序将调用的.NET程序集,所以您需要将其放入GAC并在其上运行Regasm。
I made this easier during development by adding these two lines to the Post-build event command line. You may need to search your system to find where Gacutil.exe and Regasm.exe are on your system, or you can download the .NET Framework 2.0 SDK.
通过在开发后事件命令行中添加这两行,我在开发过程中更加轻松了。 您可能需要搜索系统以找到Gacutil.exe和Regasm.exe在系统上的位置,或者可以下载.NET Framework 2.0 SDK 。
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\Gacutil.exe" /i "$(TargetPath)"
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\Regasm.exe" /codebase "$(TargetPath)"
“ C:\ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ bin \ Gacutil.exe” / i“ $(TargetPath)” “ C:\ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ bin \ Regasm.exe” /代码库“ $(TargetPath)”
Once registered, the new vCard Preview Handlers is available all over Windows to any app that cares to use it.
注册后,新的vCard预览处理程序可在Windows上供所有希望使用它的应用程序使用。
I've looked at this code a couple of times, not just because it's poopy, but because I felt there must be at least a few clean ways I could have made the code cleaner/terser using some of the new C# 3.0 features like Anonymous Types, and yield. Any ideas?
我已经看了几次这个代码,不仅仅是因为它很笨拙,而且因为我觉得至少必须有一些干净的方法可以使用一些新的C#3.0功能(例如Anonymous)来使代码更简洁/更简洁。类型和产量。 有任何想法吗?
Here's the real tragedy. After I wrote this very sad little "just barely good enough" vCard parser, I discovered that the Coding4Fun DevKit already included a very complete vCard parsing implementation.
这是真正的悲剧。 在我写了一个非常悲伤的小“勉强够用”的vCard解析器之后,我发现Coding4Fun DevKit已经包含了一个非常完整的vCard解析实现。
Curse my metal body! The vCard sample is in the Contacts project within C4FDevKit and it's scrumptious. Well, live and learn. Anyway, I had fun and it took less than an hour to get a useful (to me) PreviewHandler working. The C4FDevKit includes samples and compiled PreviewHandlers for CSV, generic binary, Icons, XML files via IE, MSIs, PDFs, Resx and Resources, SNK (keys) and Zip Files. Sweet.
诅咒我的金属身体! vCard示例位于C4FDevKit的“联系人”项目中,非常棒。 好吧,生活和学习。 无论如何,我很开心,并且花了不到一个小时的时间来获得有用的(对我而言)PreviewHandler。 C4FDevKit包括用于CSV,通用二进制文件,图标,通过IE的XML文件,MSI,PDF,Resx和资源,SNK(密钥)和Zip文件的示例和已编译的PreviewHandlers。 甜。
You can more easily test your Preview Handlers using the PreviewHandlerHost control on a simple WinForms app, or even easier by using the already-written PreviewHandlerHost at Coding4Fun\C4FDevKit2008v1\Preview Handlers\Samples\VB\PreviewHandlerHostSample as seen in the screenshot above.
您可以在简单的WinForms应用程序上使用PreviewHandlerHost控件更轻松地测试您的预览处理程序,甚至可以通过使用已编写的位于Coding4Fun \ C4FDevKit2008v1 \ Preview Handlers \ Samples \ VB \ PreviewHandlerHostSample的PreviewHandlerHost来更轻松地测试预览处理程序。
翻译自: https://www.hanselman.com/blog/a-vcard-preview-handler-using-the-coding4fun-devkit
程序员 coding啥意思