Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
13bbdcdc
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
13bbdcdc
编写于
3月 14, 2016
作者:
L
Larry Golding
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ProcessWatchdog: Save screenshot on timeout
上级
deb0d74a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
143 addition
and
11 deletion
+143
-11
src/Tools/ProcessWatchdog/ConsoleUtils.cs
src/Tools/ProcessWatchdog/ConsoleUtils.cs
+9
-3
src/Tools/ProcessWatchdog/Options.cs
src/Tools/ProcessWatchdog/Options.cs
+7
-0
src/Tools/ProcessWatchdog/ProcessWatchdog.csproj
src/Tools/ProcessWatchdog/ProcessWatchdog.csproj
+3
-0
src/Tools/ProcessWatchdog/Program.cs
src/Tools/ProcessWatchdog/Program.cs
+7
-8
src/Tools/ProcessWatchdog/Resources.Designer.cs
src/Tools/ProcessWatchdog/Resources.Designer.cs
+36
-0
src/Tools/ProcessWatchdog/Resources.resx
src/Tools/ProcessWatchdog/Resources.resx
+12
-0
src/Tools/ProcessWatchdog/ScreenShotSaver.cs
src/Tools/ProcessWatchdog/ScreenShotSaver.cs
+69
-0
未找到文件。
src/Tools/ProcessWatchdog/ConsoleUtils.cs
浏览文件 @
13bbdcdc
...
...
@@ -7,12 +7,18 @@ namespace ProcessWatchdog
{
internal
static
class
ConsoleUtils
{
internal
static
void
ReportError
(
string
messageFormat
,
params
string
[]
args
)
internal
static
void
LogMessage
(
string
format
,
params
object
[]
args
)
{
Console
.
WriteLine
(
string
.
Format
(
CultureInfo
.
CurrentCulture
,
format
,
args
));
}
internal
static
void
LogError
(
string
messageFormat
,
params
object
[]
args
)
{
string
fullMessage
=
string
.
Format
(
CultureInfo
.
Invaria
ntCulture
,
CultureInfo
.
Curre
ntCulture
,
Resources
.
ErrorFormat
,
string
.
Format
(
CultureInfo
.
Invaria
ntCulture
,
messageFormat
,
args
));
string
.
Format
(
CultureInfo
.
Curre
ntCulture
,
messageFormat
,
args
));
Console
.
Error
.
WriteLine
(
fullMessage
);
}
...
...
src/Tools/ProcessWatchdog/Options.cs
浏览文件 @
13bbdcdc
...
...
@@ -28,5 +28,12 @@ internal class Options
"arguments"
,
HelpText
=
"Command line arguments to pass to the executable, enclosed in quotes if necessary."
)]
public
string
Arguments
{
get
;
set
;
}
[
Option
(
'o'
,
"output-directory"
,
HelpText
=
"Directory to which process dumps and screen shots will be written."
,
Default
=
"."
)]
public
string
OutputDirectory
{
get
;
set
;
}
}
}
\ No newline at end of file
src/Tools/ProcessWatchdog/ProcessWatchdog.csproj
浏览文件 @
13bbdcdc
...
...
@@ -21,6 +21,8 @@
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Drawing"
/>
<Reference
Include=
"System.Windows.Forms"
/>
<Reference
Include=
"System.Xml.Linq"
/>
<Reference
Include=
"Microsoft.CSharp"
/>
<Reference
Include=
"System.Xml"
/>
...
...
@@ -34,6 +36,7 @@
<DesignTime>
True
</DesignTime>
<DependentUpon>
Resources.resx
</DependentUpon>
</Compile>
<Compile
Include=
"ScreenshotSaver.cs"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"project.json"
/>
...
...
src/Tools/ProcessWatchdog/Program.cs
浏览文件 @
13bbdcdc
...
...
@@ -16,8 +16,6 @@ internal sealed class Program
{
private
Options
_options
;
private
TimeSpan
_timeout
;
private
bool
_exited
;
private
DateTime
_startTime
;
public
Program
(
Options
options
)
{
...
...
@@ -32,7 +30,7 @@ private int Run()
}
catch
(
Exception
ex
)
{
ConsoleUtils
.
Report
Error
(
Resources
.
ErrorInvalidTimeoutInterval
,
_options
.
Timeout
,
ex
.
Message
);
ConsoleUtils
.
Log
Error
(
Resources
.
ErrorInvalidTimeoutInterval
,
_options
.
Timeout
,
ex
.
Message
);
return
1
;
}
...
...
@@ -46,14 +44,15 @@ private int Run()
{
if
(
DateTime
.
Now
-
process
.
StartTime
>
_timeout
)
{
ConsoleUtils
.
ReportError
(
Resources
.
ErrorProcessTimedOut
,
_options
.
Executable
,
_options
.
Timeout
);
ConsoleUtils
.
LogError
(
Resources
.
ErrorProcessTimedOut
,
_options
.
Executable
,
_options
.
Timeout
);
ScreenshotSaver
.
SaveScreen
(
_options
.
Executable
,
_options
.
OutputDirectory
);
return
1
;
}
Thread
.
Sleep
(
1000
);
}
Console
.
WriteLin
e
(
Resources
.
ProcessExited
,
_options
.
Executable
,
process
.
ExitTime
-
process
.
StartTime
);
Console
Utils
.
LogMessag
e
(
Resources
.
ProcessExited
,
_options
.
Executable
,
process
.
ExitTime
-
process
.
StartTime
);
}
return
0
;
...
...
@@ -81,13 +80,13 @@ private static void Banner()
IEnumerable
<
Attribute
>
attributes
=
entryAssembly
.
GetCustomAttributes
();
string
version
=
entryAssembly
.
GetName
().
Version
.
ToString
();
Console
.
WriteLine
(
string
.
Format
(
CultureInfo
.
CurrentCulture
,
Resources
.
Banner
,
Resources
.
ApplicationName
,
version
)
);
Console
Utils
.
LogMessage
(
Resources
.
Banner
,
Resources
.
ApplicationName
,
version
);
var
copyrightAttribute
=
attributes
.
Single
(
a
=>
a
is
AssemblyCopyrightAttribute
)
as
AssemblyCopyrightAttribute
;
string
copyright
=
copyrightAttribute
.
Copyright
;
Console
.
WriteLin
e
(
copyright
);
Console
.
WriteLine
(
);
Console
Utils
.
LogMessag
e
(
copyright
);
Console
Utils
.
LogMessage
(
string
.
Empty
);
}
}
}
src/Tools/ProcessWatchdog/Resources.Designer.cs
浏览文件 @
13bbdcdc
...
...
@@ -78,6 +78,24 @@ internal class Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Could not take screenshot for process {0}, because this process does not have a UI..
/// </summary>
internal
static
string
ErrorCannotTakeScreenshotNoConsoleSession
{
get
{
return
ResourceManager
.
GetString
(
"ErrorCannotTakeScreenshotNoConsoleSession"
,
resourceCulture
);
}
}
/// <summary>
/// Looks up a localized string similar to Could not take screenshot for process {0}..
/// </summary>
internal
static
string
ErrorCannotTakeScreenshotUnexpectedError
{
get
{
return
ResourceManager
.
GetString
(
"ErrorCannotTakeScreenshotUnexpectedError"
,
resourceCulture
);
}
}
/// <summary>
/// Looks up a localized string similar to Error: {0}.
/// </summary>
...
...
@@ -105,6 +123,24 @@ internal class Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Created screenshot folder {0}..
/// </summary>
internal
static
string
InfoCreatedScreenshotfolder
{
get
{
return
ResourceManager
.
GetString
(
"InfoCreatedScreenshotfolder"
,
resourceCulture
);
}
}
/// <summary>
/// Looks up a localized string similar to Saved screenshot to file {0}..
/// </summary>
internal
static
string
InfoSavedScreenshot
{
get
{
return
ResourceManager
.
GetString
(
"InfoSavedScreenshot"
,
resourceCulture
);
}
}
/// <summary>
/// Looks up a localized string similar to The process {0} exited successfully after {1}..
/// </summary>
...
...
src/Tools/ProcessWatchdog/Resources.resx
浏览文件 @
13bbdcdc
...
...
@@ -123,6 +123,12 @@
<data
name=
"Banner"
xml:space=
"preserve"
>
<value>
{0} version {1}
</value>
</data>
<data
name=
"ErrorCannotTakeScreenshotNoConsoleSession"
xml:space=
"preserve"
>
<value>
Could not take screenshot for process {0}, because this process does not have a UI.
</value>
</data>
<data
name=
"ErrorCannotTakeScreenshotUnexpectedError"
xml:space=
"preserve"
>
<value>
Could not take screenshot for process {0}.
</value>
</data>
<data
name=
"ErrorFormat"
xml:space=
"preserve"
>
<value>
Error: {0}
</value>
</data>
...
...
@@ -132,6 +138,12 @@
<data
name=
"ErrorProcessTimedOut"
xml:space=
"preserve"
>
<value>
The process {0} timed out after {1}.
</value>
</data>
<data
name=
"InfoCreatedScreenshotfolder"
xml:space=
"preserve"
>
<value>
Created screenshot folder {0}.
</value>
</data>
<data
name=
"InfoSavedScreenshot"
xml:space=
"preserve"
>
<value>
Saved screenshot to file {0}.
</value>
</data>
<data
name=
"ProcessExited"
xml:space=
"preserve"
>
<value>
The process {0} exited successfully after {1}.
</value>
</data>
...
...
src/Tools/ProcessWatchdog/ScreenShotSaver.cs
0 → 100644
浏览文件 @
13bbdcdc
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System
;
using
System.ComponentModel
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.IO
;
using
System.Windows.Forms
;
namespace
ProcessWatchdog
{
public
static
class
ScreenshotSaver
{
public
static
void
SaveScreen
(
string
description
,
string
outputDirectory
)
{
try
{
var
fileName
=
GenerateScreenshotFileName
(
description
,
outputDirectory
);
SaveScreenToFile
(
fileName
);
ConsoleUtils
.
LogMessage
(
Resources
.
InfoSavedScreenshot
,
fileName
);
}
catch
(
Win32Exception
ex
)
{
// System.ComponentModel.Win32Exception (0x80004005): The handle is invalid. This
// means we're not running in a console session, hence there's no UI to take a
// screenshot of. This is perfectly normal on the server.
ConsoleUtils
.
LogError
(
Resources
.
ErrorCannotTakeScreenshotNoConsoleSession
,
ex
);
}
catch
(
Exception
ex
)
{
// This is something else, we'd better know about this.
ConsoleUtils
.
LogError
(
Resources
.
ErrorCannotTakeScreenshotUnexpectedError
,
ex
);
}
}
private
static
void
SaveScreenToFile
(
string
fileName
)
{
int
width
=
SystemInformation
.
VirtualScreen
.
Width
;
int
height
=
SystemInformation
.
VirtualScreen
.
Height
;
int
screenLeft
=
SystemInformation
.
VirtualScreen
.
Left
;
int
screenTop
=
SystemInformation
.
VirtualScreen
.
Top
;
using
(
Bitmap
screenshot
=
new
Bitmap
(
width
,
height
,
PixelFormat
.
Format32bppArgb
))
{
using
(
Graphics
graphics
=
Graphics
.
FromImage
(
screenshot
))
{
graphics
.
CopyFromScreen
(
screenLeft
,
screenTop
,
0
,
0
,
new
Size
(
width
,
height
));
}
screenshot
.
Save
(
fileName
,
ImageFormat
.
Png
);
}
}
private
static
string
GenerateScreenshotFileName
(
string
description
,
string
outputDirectory
)
{
var
screenshotsFolder
=
new
DirectoryInfo
(
outputDirectory
);
if
(!
screenshotsFolder
.
Exists
)
{
screenshotsFolder
.
Create
();
ConsoleUtils
.
LogMessage
(
Resources
.
InfoCreatedScreenshotfolder
,
screenshotsFolder
.
FullName
);
}
var
fileName
=
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd_HH-mm-ss_ff"
)
+
" - "
+
description
+
".png"
;
fileName
=
Path
.
Combine
(
screenshotsFolder
.
FullName
,
fileName
);
return
fileName
;
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录