Skip to content

Commit

Permalink
新增拍照、播放、暂停、上一首、下一首五个命令
Browse files Browse the repository at this point in the history
新增帮助菜单
新增捐助菜单
新增推荐给粉丝菜单
新增命令列表菜单
新增产品主页菜单
新增使用技巧菜单
  • Loading branch information
terryso committed Mar 20, 2011
1 parent e924830 commit 7a59d10
Show file tree
Hide file tree
Showing 15 changed files with 1,604 additions and 0 deletions.
65 changes: 65 additions & 0 deletions PCRemote.Core/PhotoCommand.cs
@@ -0,0 +1,65 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Windows.Forms;
using PCRemote.Core.Utilities;
using Weibo.Contracts;

namespace PCRemote.Core
{
public class PhotoCommand : ICommand
{
private readonly IWeiboClient _client;
private readonly Control _control;

public PhotoCommand(IWeiboClient client, Control control)
{
_client = client;
_control = control;
}

public void Execute()
{
Bitmap bitmap = null;
EncoderParameters encoderParams = null;
EncoderParameter parameter = null;
try
{
var temp = Environment.GetEnvironmentVariable("TEMP");
var picPath = temp + "\\" + Guid.NewGuid() + ".bmp";


var webcam = new WebCamUtility(_control.Handle, 600, 480);
webcam.StartWebCam();
webcam.GrabImage(_control.Handle, picPath);
webcam.CloseWebcam();

bitmap = new Bitmap(picPath);
var codecInfo = GetCodecInfo("image/jpeg");
var quality = Encoder.Quality;
encoderParams = new EncoderParameters(1);
const long num = 0x5fL;
parameter = new EncoderParameter(quality, num);
encoderParams.Param[0] = parameter;

var newPicPath = picPath.Replace("bmp", "jpg");
bitmap.Save(newPicPath, codecInfo, encoderParams);

_client.UploadStatus("我正在使用#PC遥控器#分享我的WebCam抓拍 " + DateTime.Now.ToLongTimeString(), newPicPath);
}
finally
{
if (parameter != null) parameter.Dispose();
if (encoderParams != null) encoderParams.Dispose();
if (bitmap != null) bitmap.Dispose();
}
}

private static ImageCodecInfo GetCodecInfo(string mimeType)
{
var imageEncoders = ImageCodecInfo.GetImageEncoders();
return imageEncoders.FirstOrDefault(info => info.MimeType == mimeType);
}
}
}
24 changes: 24 additions & 0 deletions PCRemote.Core/ProcessListCommand.cs
@@ -0,0 +1,24 @@
using System;
using Weibo.Contracts;

namespace PCRemote.Core
{
public class ProcessListCommand : ICommand
{
private readonly IWeiboClient _client;

public ProcessListCommand(IWeiboClient client)
{
_client = client;
}

#region ICommand Members

public void Execute()
{
throw new NotImplementedException();
}

#endregion
}
}
29 changes: 29 additions & 0 deletions PCRemote.Core/Utilities/DosCommandUtility.cs
@@ -0,0 +1,29 @@
using System.Diagnostics;

namespace PCRemote.Core.Utilities
{
public class DosCommandUtility
{
public static string RunCmd(string command)
{
//实例一个Process类,启动一个独立进程
//Process类有一个StartInfo属性,这个是ProcessStartInfo类,包括了一些属性和方法,下面我们用到了他的几个属性:
var p = new Process
{
StartInfo =
{
FileName = "cmd.exe",
Arguments = "/c " + command,
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};
p.Start(); //启动
p.StandardInput.WriteLine("exit"); //不过要记得加上Exit要不然下一行程式执行的时候会当机
return p.StandardOutput.ReadToEnd(); //从输出流取得命令执行结果
}
}
}
116 changes: 116 additions & 0 deletions PCRemote.Core/Utilities/EmailUtility.cs
@@ -0,0 +1,116 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web;

namespace PCRemote.Core.Utilities
{
/// <summary>
/// 邮件优先级:high(高)、low(低)、normal(正常)
/// </summary>
public enum EmailPriorityEnum
{
#region///邮件优先级

/// <summary>
/// 高
/// </summary>
[Description("")] High,
/// <summary>
/// 低
/// </summary>
[Description("")] Low,
/// <summary>
/// 正常
/// </summary>
[Description("正常")] Normal

#endregion
}

public class EmailUtility
{
/// <summary>
/// 邮件发送
/// </summary>
/// <param name="toEmailAddress">发送目标邮箱列表</param>
/// <param name="toCcEmailAddress"></param>
/// <param name="attachmentList">电子邮件附件列表</param>
/// <param name="fromEmailAddress">发送账户</param>
/// <param name="fromEmailPassword">发送密码</param>
/// <param name="emailPersonName">发件人名</param>
/// <param name="emailSubject">邮件标题</param>
/// <param name="emailBody">邮件内容</param>
/// <param name="isBodyHtml">是否HTML内容 默认为是</param>
/// <param name="emailPriority">邮件优先级</param>
/// <param name="port">邮箱端口号</param>
/// <param name="emailHostName">邮箱服务器地址</param>
/// <param name="isEnableSsl">邮件是否加密:true(加密),false(不加密) 默认为true</param>
/// <param name="encodingType">编码格式</param>
public void Send(IList<string> toEmailAddress, IList<string> toCcEmailAddress, IList<Attachment> attachmentList,
string fromEmailAddress, string fromEmailPassword, string emailPersonName, string emailSubject,
string emailBody, bool isBodyHtml, EmailPriorityEnum emailPriority, int port,
string emailHostName, bool isEnableSsl, Encoding encodingType)
{
#region///邮件发送

var mails = new MailMessage();

//编码类型
var emaiEncodingType = encodingType;

//添加发送地址
foreach (var to in toEmailAddress)
{
mails.To.Add(to);
}

// 添加抄送地址
foreach (var to in toCcEmailAddress)
{
mails.CC.Add(to);
}

//添加附件
foreach (var attachment in attachmentList)
{
mails.Attachments.Add(attachment);
}

mails.From = new MailAddress(fromEmailAddress, emailPersonName, emaiEncodingType);
mails.Subject = emailSubject;
mails.SubjectEncoding = emaiEncodingType;
mails.Body = HttpUtility.HtmlDecode(emailBody);
mails.BodyEncoding = emaiEncodingType;
//设置邮件是否为HTML格式
mails.IsBodyHtml = isBodyHtml;
//设置邮件优级先级
switch (emailPriority)
{
case EmailPriorityEnum.Normal:
mails.Priority = MailPriority.Normal;
break;
case EmailPriorityEnum.Low:
mails.Priority = MailPriority.Low;
break;
default:
mails.Priority = MailPriority.High;
break;
}

var client = new SmtpClient
{
Credentials = new NetworkCredential(fromEmailAddress, fromEmailPassword),
Port = port,
Host = emailHostName,
EnableSsl = isEnableSsl
};

client.Send(mails);

#endregion
}
}
}
66 changes: 66 additions & 0 deletions PCRemote.Core/Utilities/WebCamUtility.cs
@@ -0,0 +1,66 @@
using System;
using System.Runtime.InteropServices;

namespace PCRemote.Core.Utilities
{
public class WebCamUtility
{
private IntPtr lwndC;
private IntPtr mControlPtr;
private int mHeight;
private int mWidth;

public WebCamUtility(IntPtr handle, int width, int height)
{
this.mControlPtr = handle;
this.mWidth = width;
this.mHeight = height;
}

public void CloseWebcam()
{
SendMessage(this.lwndC, 0x40b, (short) 0, 0);
}

public void GrabImage(IntPtr hWndC, string path)
{
SendMessage(this.lwndC, 0x419, (short) 0, Marshal.StringToHGlobalAnsi(path).ToInt32());
}

public void StartWebCam()
{
byte[] lpszName = new byte[100];
byte[] lpszVer = new byte[100];
capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100);
this.lwndC = capCreateCaptureWindowA(lpszName, 0x50000000, 0, 0, this.mWidth, this.mHeight, this.mControlPtr, 0);
if (SendMessage(this.lwndC, 0x40a, (short) 0, 0))
{
SendMessage(this.lwndC, 0x434, (short) 100, 0);
SendMessage(this.lwndC, 0x432, true, 0);
}
}

public const int SWP_NOMOVE = 2;
public const int SWP_NOZORDER = 4;
public const int WM_CAP_DRIVER_CONNECT = 0x40a;
public const int WM_CAP_DRIVER_DISCONNECT = 0x40b;
public const int WM_CAP_SAVEDIB = 0x419;
public const int WM_CAP_SET_CALLBACK_FRAME = 0x405;
public const int WM_CAP_SET_PREVIEW = 0x432;
public const int WM_CAP_SET_PREVIEWRATE = 0x434;
public const int WM_CAP_SET_VIDEOFORMAT = 0x42d;
public const int WM_CAP_START = 0x400;
public const int WM_USER = 0x400;
public const int WS_CHILD = 0x40000000;
public const int WS_VISIBLE = 0x10000000;

[DllImport("avicap32.dll")]
public static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);
[DllImport("avicap32.dll")]
public static extern bool capGetDriverDescriptionA(short wDriver, byte[] lpszName, int cbName, byte[] lpszVer, int cbVer);
[DllImport("User32.dll")]
public static extern bool SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam);
[DllImport("User32.dll")]
public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, int lParam);
}
}
19 changes: 19 additions & 0 deletions PCRemote.Tests/CommandTests.cs
@@ -0,0 +1,19 @@
using System;
using System.Diagnostics;
using NUnit.Framework;
using PCRemote.Core.Utilities;

namespace PCRemote.Tests
{
[TestFixture]
public class CommandTests
{
[Test]
public void TaskListCommand_Test()
{
var result = DosCommandUtility.RunCmd("tasklist");

Console.WriteLine(result.ToString());
}
}
}
63 changes: 63 additions & 0 deletions PCRemote.Tests/PCRemote.Tests.csproj
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C21E3D79-C061-4C20-9DF2-469380319E8D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PCRemote.Tests</RootNamespace>
<AssemblyName>PCRemote.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CommandTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PCRemote.Core\PCRemote.Core.csproj">
<Project>{16C31473-3884-41B5-818B-2E2230D4DD42}</Project>
<Name>PCRemote.Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

0 comments on commit 7a59d10

Please sign in to comment.