首页 > 数据库技术 > 详细

关于DbUploader项目总结

时间:2017-02-22 13:34:35      阅读:140      评论:0      收藏:0      [点我收藏+]

项目背景,备份目标客户的电脑上某程序产生的数据库mdb文件。由于怕这些客户的PC出现问题,然后以前数据丢失,为了使数据更安全,我们选择把他们每天提取一份备份到服务器上。这是一个学习以及加强自己技术的一个过程。

首先项目开始时定了整体需要开发的模块。一个windows服务。一个wcf。

windows服务使用的技术包括:

 1.Quartz,Quartz是一个完全由java编写的开源作业调度框架,目前只有一个服务需要使用,暂时没有什么优势,只是为了使用而使用。

 2.Rsync,rsync是类unix系统下的数据镜像备份工具——remote sync。一款快速增量备份工具 Remote Sync,远程同步 支持本地复制,或者与其他SSH、rsync主机同步。然而我们是在win上使用,所以我们在服务端用的是deltacopy,另外还有一个叫cwRsync,由于deltacopy免费,而且也不难使用,所以我们选择了deltacopy。客户端直接用rsync的dll官方包就可以。

命令示例:rsync -vzrtopg --progress /cygdrive/c/test root@服务器地址::test

 

服务配置:

DeltaCopy service:

First: Install the DeltaCopy server,The module name  is xxxx。

Second: configure the log on for the administrator account. Set the firewall rule inbound to increase port 873.

Third: add a login server permissions NT account, and then share the module xxxx point to the folder to the account.

Finally, start the deltaCopy service and test that the connection is successful

 

3.日志模块使用log4net.AssemblyInfo配置:[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.xml", Watch = true)],添加log4net.xml文件。

4.测试使用Unit Tests+Moq。简单示例:Mock<Ixxxxx> mock = new Mock<Ixxxxxx>(MockBehavior.Strict);然后模拟方法返回数据,然后某些类里边使用其他方法了,那么moq可以代替模拟方法返回对应的值,测试一些复杂的方法。

5.然后就是一些编程小技巧的使用。比如获取注册表信息方法:Microsoft.Win32.Registry.LocalMachine.OpenSubKey();Path实用类。获得电脑位数的方法:

public static int GetOSBit()
{
int bitValue = 32;
try
{
string addressWidth = String.Empty;
ConnectionOptions mConnOption = new ConnectionOptions();
ManagementScope mMs = new ManagementScope("\\\\localhost", mConnOption);
ObjectQuery mQuery = new ObjectQuery("select AddressWidth from Win32_Processor");
ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(mMs, mQuery);
ManagementObjectCollection mObjectCollection = mSearcher.Get();
foreach (ManagementObject mObject in mObjectCollection)
{
addressWidth = mObject["AddressWidth"].ToString();
}
int bValue;
if (!int.TryParse(addressWidth, out bValue))
{
//
}
else
{
bitValue = bValue;
}
}
catch (Exception ex)
{
//
}
return bitValue;
}

6.WCF的webservice的使用。如果服务每次调用都需要输入用户名密码那么修改配置:

After the service is configured, if you do not create a folder successfully, you may need to set the service site application pool permissions:

技术分享

 

7.cmd等程序在开发软件中的使用:

ProcessStartInfo proStartInfo = new ProcessStartInfo("cmd");
proStartInfo.RedirectStandardInput = true;
proStartInfo.RedirectStandardOutput = true;
proStartInfo.UseShellExecute = false;
Process proCommand = Process.Start(proStartInfo);
proCommand.StandardInput.WriteLine("cd " + path);
proCommand.StandardInput.WriteLine(printCommand2);
proCommand.StandardInput.WriteLine("exit");
string rsyncFilesResult = proCommand.StandardOutput.ReadToEnd();

8.WCF的webservice在开发程序中的使用:xxxxService.NewxxxxxRemoteService.xxxxWebServiceClient webService = new xxxxService.NewxxxxxRemoteService.xxxxWebServiceClient();

config:

<client>
<endpoint address="服务器地址/xxxx.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IxxxxWebService"
contract="NewXXXXRemoteService.IxxxxWebService"
name="BasicHttpBinding_IxxxxWebService" />
</client>

9.Inno setup打包软件的使用。

简单示例:

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
UsePreviousAppDir=yes
AppId={{}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName}
AppPublisher={#MyAppPublisher}
DefaultDirName={pf}\..\{#MyAppName}
;DisableProgramGroupPage=yes
OutputBaseFilename=xxxx_1.0
Compression=lzma
SolidCompression=yes

DisableDirPage=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "{#SourcePath}\xxxx.exe"; DestDir: "{app}"; Flags: ignoreversion;

........

[Run]
Filename: {win}\System32\sc.exe; Parameters: stop 服务名
Filename: {win}\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe; Parameters: "/silent /suppressmsgboxes {app}\服务名.exe"
Filename: {win}\System32\sc.exe; Parameters: start 服务名
Filename: {win}\System32\sc.exe; Parameters: failure 服务名 reset= 86400 actions= restart/180000/restart/180000/restart/180000

[UninstallRun]
Filename: {win}\System32\sc.exe; Parameters: stop 服务名
Filename: {win}\System32\sc.exe; Parameters: delete 服务名
[Code]
function InitializeSetup(): Boolean;
var
sInstallUtilTool : string;
sSTE_HOME_Key: string;
sSTE_HOME_Value: string;
bSTE_HOME_Exist: Boolean;
sCommand: string;
ResultCode: Integer;
begin
sInstallUtilTool := ExpandConstant(‘{win}\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe‘);

Result := FileExists(sInstallUtilTool);

if not Result then
begin
MsgBox(‘Framework 4.0 is not found.Please install Framework 4.0‘,mbError,MB_OK);
Exit;
end
else
begin
if RegValueExists(HKEY_LOCAL_MACHINE,‘DbUploaderService/ImagePath‘, ‘config‘) then 
begin 
MsgBox(‘Has been installed, please uninstall the installation‘,mbConfirmation, MB_OK); 
Result := false; 
end else 
begin 
//MsgBox(‘Success‘,mbConfirmation, MB_OK); 
Result := true; 
end;
end
end;

 

 

总结:不管开发的系统是大是小,该需要的必须提前做好准备,不能觉得没有必要,为后期的扩展徒增麻烦。俗话说的好,麻雀虽小,五脏俱全。方法功能必须单一,降低耦合,方便复用。该提取的公共方法必须放到上层父类,降低开发复杂性。如果在业务不熟悉的情况下开发软件。那么开发完成的情况下,有条件最好进行一下重构,提高代码质量,方便后期维护。代码测试一定要全面,保证代码质量,减少bug率,代码健壮性大于华丽程度。最后,提高英语水平。

关于DbUploader项目总结

原文:http://www.cnblogs.com/SoFind-an/p/6428048.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!