Author: Hendry

Squirrel Framework 1.0.13 说明文档

Squirrel Framework – 是一个轻量级的 MongoDB 存储封装类库。同时,它还尝试为使用者提供了一系列的拓展类,方便日常的 .NET 开发需求。它致力于让你轻松、快速地构建基于 MongoDB 的应用程序。

下面我们简单介绍一下 Squirrel Framework 的核心功能,只要以下 4 个步骤,你就能完成持久化层的开发。

Continue reading

GitHub 提交忽略规则

我们可以在代码库的根目录创建一个名为 “.gitignore” 的文件,并在其中配置哪些文件或文件夹可以在提交的时候被忽略。以 .NET 项目为例,我们需要忽略与 VS 或 调试编译有关的 bin\obj\packages\.vs 等文件或文件夹,则只需要:

# Emacs backup files
*~

appsettings.local.json
local.settings.json
*.pfx


# The below are a selected subset from
# https://github.com/github/gitignore/blob/master/VisualStudio.gitignore


# Visual Studio user-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
*.dll
*.dll.config
*.exe
*.exe.config
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2015/2017 cache/options directory
.vs/

# Visual Studio 2017 auto generated files
Generated\ Files/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json

# Files built by Visual Studio
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# Visual Studio Trace Files
*.e2e

# Visual Studio code coverage results
*.coverage
*.coveragexml

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/

注意,按行配置约束,一行一个。

一键清除 .NET 无用文件,清爽一夏

工作几年,电脑里会有很多项目代码,随之而来的就是许许多多调试、编译时带来的 bin/obj/package 或者 .vs 文件(夹),如何清除这些文件,来一个大扫除呢?这里提供一个超有效的 Batch 脚本供参考。

@echo off
REM start to clean code folder
echo Start to clean all code folder

@for /d /r %%c in (obj) do @if exist "%%c" (@rd /s /q "%%c" & echo Delete %%c)
@for /d /r %%c in (bin) do @if exist "%%c" (@rd /s /q "%%c" & echo Delete %%c)
@for /d /r %%c in (packages) do @if exist "%%c" (@rd /s /q "%%c" & echo Delete %%c)
@for /d /r %%c in (.vs) do @if exist "%%c" (@rd /s /q "%%c" & echo Delete %%c)

echo Done.

存储为 .bat 文件后,通过命令提示符运行,在我的电脑上运行后,整整节约了 15G 的磁盘空间,泪流满面!

WP2CSDNBlog 已无法同步文章到 CSDN

WP2CSDNBlog 是 WordPress 下的一款优秀的文章同步插件,由于 CSDN 服务器不再支持离线编写了,所以我们无法继续使用这个插件同步新建的 WordPress 文章。(援引插件作者的评论

不过 博客园 依然可以被 WP2CSDNBlog 插件支持。具体配置信息如下:

  • 博客园(CNBlogs):https://rpc.cnblogs.com/metaweblog/nista(修改为你的用户名)
  • 开源中国(OSChina):https://my.oschina.net/action/xmlrpc
  • 51CTO:http://imguowei.blog.51cto.com/xmlrpc.php
  • CSDN: http://write.blog.csdn.net/xmlrpc/index
  • 新浪博客: http://upload.move.blog.sina.com.cn/blog_rebuild/blog/xmlrpc.php
  • 网易(163):http://os.blog.163.com/word

新人培养总结

毕业后的 5 年多时间里,在 AvePoint 一共带过 12 位研发新人,他们每个人各有自身的特点,我和他们每个人共处了很久都彼此了解,这期间有许许多多的回忆、讲不完的故事。如今,我已经离开 AvePoint,在此将这些年的带人经验做做总结,这些经验主要针对刚毕业的技术新人或者实习生来讲的,因人而异,只做参考。

新人培养可以考虑分为以下几个阶段。

Continue reading

如何获得在 SharePoint 中保存 Video 并生成缩略图

如果你需要需要在 SharePoint Online 中,上传一个 视频资源,并在自己的定制页面中,引用这个视频,你可以通过如下方法进行操作。

1. Open the SharePoint site and click on “Site Content” on the left panel.

2. Click the “New” button at the top of the site content page and click “Applications” on the menu.

3. Type “Repository” in the search box and click the Asset Library application in the search results.

4. Enter the name of the new asset library and click the “Create” button.

5. Click on the new asset library you created and upload the video file.

Continue reading

有你

有你,就像喧闹街边的那株新芽
是丛中一点非凡的绿

有你,就像匆忙表盘上的时针
是凌乱纷杂的时间里片刻的安宁

你是蛋糕夹心的薄荷与草莓
完整了酸甜

在海岸的石头堤坝上,
在狂乱暴虐的风雨下,
指尖相触
我们的脚下是无限的坚定
我们的背后是一片安宁

我想与你,去看每一片海
你是看得见的心
我们是看不见的盘根

2018.4.30 午后


阿尔伯特·奥布莱(Albert Aublet),《在海岸石头堤坝》(Sur Les Galets)

如何在 NuGet 发布自己的类库包

我们可以将自己实现的类库发布到 NuGet 上,方便在未来开发应用程序时,对已有代码或结构进行复用。以下是在 NuGet 发布自己类库的一个简单介绍。

1. 首先,我们需要到 nuget.org 注册并 获取 API key

2. 随后,下载 NuGet 命令行工具,建议将 nuget.exe 注册到系统的环境变量中,方便后续步骤的操作
Continue reading

最佳实践:根据条件获取集合的部分结果

很多场景下,我们需要根据一个条件判定某一集合中是否存在从中选取部分符合条件的元素用于后续操作。我们有很多方式可以实现这种需求,比如 纯手工对集合进行遍历,yield return,Any(),Count() 或 Count 属性,那么,这些实现方式对效率的影响如何?哪种实现效率较优呢?

我们来做一次实验。

首先我们定义一个类,并初始化包含有 1 万个该类型实例的集合。

    public class Item
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public bool Gender { get; set; }
        public int Age { get; set; }
        public DateTime Birthday { get; set; }
        public string Address { get; set; }
        public string Email { get; set; }
    }

Continue reading

如何将 XML 的 XSD 定义转换为 C# 类

当我们将一些配置数据存储在 XML 文档中,或希望自定义某种 XML 格式的文档时,最好先去定义 XML 对应的 XSD 规范。定义 XSD 后,我们不仅可以在 VS 等 IDE 中对相应的 XML 文件的语法进行自动检查或属性匹配,同时也可以自动生成对应的实体类,简化 XML 的创建、修改以及读取。

打开 VS,在 XSD 文件上点击鼠标右键,点选 Open Command Prompt

Continue reading

Dynamics 365: Three way to get organization unique name

We have three ways to get organization unique name in Microsoft Dynamics 365.

A. Just click on the top right corner of the user avatar, and right here (org64e4ed31).

B. Get it with PowerShell, At first, you need to download the Dynamics 365 SDK to local, and then Run the PowerShell as administrator, cd to the SDK folder, and run .\RegisterXRMTooling.ps1

Add-PSSnapin Microsoft.Xrm.Tooling.Connector
Add-PSSnapin Microsoft.Xrm.Tooling.PackageDeployment

$Cred = Get-Credential
Get-CrmOrganizations -Credential $Cred -DeploymentRegion NorthAmerica –OnlineType Office365

C. Get it from the settings page of the Dynamics 365

Click Settings -> Customization -> Developer Resources -> Unique Name

Quick Tips: Open CMD here | 在当前位置打开命令行


We can right-click the mouse with Shift key to find the "Open command here" or "Open PowerShell window here" item to open the command line at current location.

But we often need to run the command line as an administrator, so you could register the following value to Windows Register to add a new item "Open command (as Admin) here" to Windows Explorer right-click menu.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
"Icon"="c:\\windows\\system32\\cmd.exe"
"MUIVerb"="Open command (as Admin) here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

[HKEY_CLASSES_ROOT\folder\shell\runas]
"Icon"="c:\\windows\\system32\\cmd.exe"
"MUIVerb"="Open command (as Admin) here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\folder\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""

Open the Notepad and paste the text of above, save the file as OpenCMDHere.reg, and then double click this file, and click the "Yes" button in the message box.

The meaning of the above code is that we will create a new Windows shell item called "runas" at folder and the empty space in a folder, and set the Icon and propmt text.

HKEY_CLASSES_ROOT\Directory\shell, the context menu when you right-click on a folder
HKEY_CLASSES_ROOT\Directory\background, the context menu when you right-click on the "background" empty space while in a folder 

Then to define the running command of "runas" item:

cmd.exe /s /k pushd \"%V\"

That means to run the cmd.exe at the current working folder, the /k carries out the command specified by the following string so it executes the command pushd %V and since the only argument pushd accepts is a path it follows that %V a variable delivered by explorer that contains the path of the folder right clicked.

See more:
cmd command, https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490880(v%3dtechnet.10)
Pushd command, https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490978(v=technet.10)


我们可以在 Windows 的任意位置,通过 按下 Shift + 鼠标右键,来在当前位置启动 CMD 或 PowerShell。

但是,我们经常需要以管理员身份取运行 CMD,所以我们可以通过加载上述的值到注册表,来为右键菜单添加一个新的选项。将上述值保存到一个记事本中,并保存为 .reg 文件,然后双击运行,在后续提示中都选择 是,即可。

SQL Server 下 K-V 形式存储 1亿条 数据对于查询效率的影响

这是一篇2年多以前带过的实习生 Peflapos 所整理的小文,拿出来缅怀下,也希望他在新的公司一切顺利。


对1亿条 K-V 型记录查询效率的验证

关于 K-V 型存储

1. 为什么考虑 K-V 存储形式?

假设有一个 Request 类如下:

	public class Request
	{
		public Guid RequestId {get; set;};
		public string RequestName {get; set;};
		public string RequestOwner {get; set;};
	}
	

我们可以按照如下的结构把它存入数据库:

Continue reading

JavaScript: 注册粘贴事件,将剪切板中的内容去除HTML标签,并粘贴到光标位置

$("#Subject").bind('paste', function (e) {
        var pasteData = "";
        if (e.originalEvent.clipboardData) {
            pasteData = e.originalEvent.clipboardData.getData('text');
        } else {
            // for IE
            pasteData = window.clipboardData.getData("Text");
        }
        var self = this;

        // 在等待一段时间后,在当前光标位置,粘贴处理后的文本
        setTimeout(function () {
            var selection = document.getSelection();
            var cursorPos = selection.anchorOffset;
            var oldContent = selection.anchorNode.nodeValue;
        // 通过 Jquery的text() 去除所有样式
            var toInsert = $("<div>" + pasteData + "</div>").text();
            var newContent = oldContent.substring(0, cursorPos) + toInsert + oldContent.substring(cursorPos);
            selection.anchorNode.nodeValue = newContent;            
        }, 200);
        return false;
    });