热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

程序员coding啥意思_使用Coding4FunDevKit的vCard预览处理程序

程序员coding啥意思IsatdownwiththeCoding4FunDeveloperKitandimmediatelynoticedthePreviewHandlerstu
程序员 coding啥意思

程序员 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 )。

  • After installing the C4F Developer Kit, make new Class Library project and add a reference to the PreviewHandlerFramework.

    安装C4F开发人员工具包后,创建新的类库项目,并添加对PreviewHandlerFramework的引用。
  • 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。

  • Also, include a ProgId for your new class. I just used the namespace.classname.

    另外,为您的新课程添加一个ProgId。 我只是使用了namespace.classname。
  • Notice that I derived from FileBasedPreviewHandler. You'll need to override CreatePreviewHandlerControl and return a new instance of your own Control that is derived from FileBasedPreviewHandlerControl. The boilerplate is below. It's inside Load() where you create whatever WinForms controls you need to and add them to the this.Controls collection.

    注意,我是从FileBasedPreviewHandler派生的。 您将需要重写CreatePreviewHandlerControl并返回派生自FileBasedPreviewHandlerControl的控件的新实例。 样板位于下方。 在Load()内部,您可以在其中创建所需的任何WinForms控件,并将它们添加到this.Controls集合中。

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 nameValue = new List();if (line.StartsWith("BEGIN:VCARD")) return null;if (line.StartsWith("VERSION:")) return null;string[] parts = line.Split(':');if (parts.Length == 2){AddVCardLine(parts, ref nameValue, "TZ", "TimeZone");AddVCardLine(parts, ref nameValue, "NICKNAME", "Nickname");AddVCardLine(parts, ref nameValue, "N", "Name");AddVCardLine(parts, ref nameValue, "FN", "Friendly Name");AddVCardLine(parts, ref nameValue, "ORG", "Organization");AddVCardLine(parts, ref nameValue, "TITLE", "Title");AddVCardLine(parts, ref nameValue, "TEL", "Phone");AddVCardLine(parts, ref nameValue, "ADR", "Address");AddVCardLine(parts, ref nameValue, "URL", "Website");AddVCardLine(parts, ref nameValue, "EMAIL", "Email");AddVCardLine(parts, ref nameValue, "X-MS-IMADDRESS", "IM");}return nameValue.ToArray();
}private static void AddVCardLine(string[] parts, ref List nameValue, string name, string friendlyName)
{if (parts[0].StartsWith(name) && parts[1] != null){nameValue.Add(friendlyName);nameValue.Add(parts[1].Replace(";", ",").Trim().Trim(','));}
}

Because this is a .NET assembly that will be called by an app expecting a COM dll, you'll need to put it in the GAC and run Regasm on it.

因为这是一个需要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啥意思



推荐阅读
  • vue使用
    关键词: ... [详细]
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • 深度学习中的Vision Transformer (ViT)详解
    本文详细介绍了深度学习中的Vision Transformer (ViT)方法。首先介绍了相关工作和ViT的基本原理,包括图像块嵌入、可学习的嵌入、位置嵌入和Transformer编码器等。接着讨论了ViT的张量维度变化、归纳偏置与混合架构、微调及更高分辨率等方面。最后给出了实验结果和相关代码的链接。本文的研究表明,对于CV任务,直接应用纯Transformer架构于图像块序列是可行的,无需依赖于卷积网络。 ... [详细]
  • 本文介绍了在Win10上安装WinPythonHadoop的详细步骤,包括安装Python环境、安装JDK8、安装pyspark、安装Hadoop和Spark、设置环境变量、下载winutils.exe等。同时提醒注意Hadoop版本与pyspark版本的一致性,并建议重启电脑以确保安装成功。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文介绍了Hyperledger Fabric外部链码构建与运行的相关知识,包括在Hyperledger Fabric 2.0版本之前链码构建和运行的困难性,外部构建模式的实现原理以及外部构建和运行API的使用方法。通过本文的介绍,读者可以了解到如何利用外部构建和运行的方式来实现链码的构建和运行,并且不再受限于特定的语言和部署环境。 ... [详细]
  • 本文介绍了Perl的测试框架Test::Base,它是一个数据驱动的测试框架,可以自动进行单元测试,省去手工编写测试程序的麻烦。与Test::More完全兼容,使用方法简单。以plural函数为例,展示了Test::Base的使用方法。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 本文介绍了PE文件结构中的导出表的解析方法,包括获取区段头表、遍历查找所在的区段等步骤。通过该方法可以准确地解析PE文件中的导出表信息。 ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • 本文介绍了在CentOS 6.4系统中更新源地址的方法,包括备份现有源文件、下载163源、修改文件名、更新列表和系统,并提供了相应的命令。 ... [详细]
  • 本文介绍了如何在使用emacs时去掉ubuntu的alt键默认功能,并提供了相应的操作步骤和注意事项。 ... [详细]
  • 从零基础到精通的前台学习路线
    随着互联网的发展,前台开发工程师成为市场上非常抢手的人才。本文介绍了从零基础到精通前台开发的学习路线,包括学习HTML、CSS、JavaScript等基础知识和常用工具的使用。通过循序渐进的学习,可以掌握前台开发的基本技能,并有能力找到一份月薪8000以上的工作。 ... [详细]
author-avatar
飞上天的鱼
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有