Skip to content

Commit a6f06f0

Browse files
committed
First commit
1 parent 7781625 commit a6f06f0

13 files changed

+2144
-1
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/bin
2+
/obj
3+
*.bak
4+
/*.csproj.user
5+
/UpgradeLog.htm
6+
*.*~
7+

ConsoleArguments.cs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+

2+
#region Copyright (c) 2012, Roland Pihlakas
3+
/////////////////////////////////////////////////////////////////////////////////////////
4+
//
5+
// Copyright (c) 2012, Roland Pihlakas.
6+
//
7+
// Permission to copy, use, modify, sell and distribute this software
8+
// is granted provided this copyright notice appears in all copies.
9+
//
10+
/////////////////////////////////////////////////////////////////////////////////////////
11+
#endregion Copyright (c) 2012, Roland Pihlakas
12+
13+
14+
using System.Collections.Generic;
15+
using System.Diagnostics;
16+
17+
namespace HttpPingTool
18+
{
19+
partial class Program
20+
{
21+
private const string ArgShowHelp = "-help";
22+
private const string ArgOutageTimeBeforeGiveUpSeconds = "-outageTimeBeforeGiveUpSeconds";
23+
private const string ArgOutageConditionNumPings = "-outageConditionNumPings";
24+
private const string ArgPassedPingIntervalMs = "-passedPingIntervalMs";
25+
private const string ArgFailedPingIntervalMs = "-failedPingIntervalMs";
26+
private const string ArgPingTimeoutMs = "-pingTimeoutMs";
27+
private const string ArgHost = "-url";
28+
//private const string ArgSourceIP = "-sourceIP"; //TODO
29+
private const string ArgSuccessReplyBodyRegEx = "-successReplyBodyRegEx";
30+
31+
//TODO: target host IP: http://stackoverflow.com/questions/359041/request-web-page-in-c-sharp-spoofing-the-host and http://www.codeproject.com/Articles/6554/How-to-use-HttpWebRequest-and-HttpWebResponse-in-N
32+
//TODO: argument to print only first/last line of response
33+
//TODO: get/post method selection
34+
35+
#if DEBUG && false
36+
private static bool ValueShowHelp = false;
37+
private static int ValueOutageTimeBeforeGiveUpSeconds = 18;
38+
private static int ValueOutageConditionNumPings = 3;
39+
private static int ValuePassedPingIntervalMs = 1500;
40+
private static int ValueFailedPingIntervalMs = 500;
41+
private static int ValuePingTimeoutMs = 1000;
42+
private static List<string> ValueHosts = new List<string>();
43+
private static List<string> ValueSourceHosts = new List<string>();
44+
#else
45+
private static bool ValueShowHelp = false;
46+
private static int ValueOutageTimeBeforeGiveUpSeconds = 180;
47+
private static int ValueOutageConditionNumPings = 3;
48+
private static int ValuePassedPingIntervalMs = 15000;
49+
private static int ValueFailedPingIntervalMs = 5000;
50+
private static int ValuePingTimeoutMs = 10000;
51+
private static List<string> ValueHosts = new List<string>(); //TODO: use hashset instead
52+
//private static List<string> ValueSourceIPs = new List<string>(); //TODO: use hashset instead
53+
private static List<string> ValueSuccessReplyBodyRegExes = new List<string>();
54+
#endif
55+
56+
}
57+
}

ExitHandlers.cs

+554
Large diffs are not rendered by default.

GetConsoleArgumentsValues.cs

+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+

2+
#region Copyright (c) 2012, Roland Pihlakas
3+
/////////////////////////////////////////////////////////////////////////////////////////
4+
//
5+
// Copyright (c) 2012, Roland Pihlakas.
6+
//
7+
// Permission to copy, use, modify, sell and distribute this software
8+
// is granted provided this copyright notice appears in all copies.
9+
//
10+
/////////////////////////////////////////////////////////////////////////////////////////
11+
#endregion Copyright (c) 2012, Roland Pihlakas
12+
13+
14+
using System;
15+
using System.Diagnostics;
16+
17+
namespace HttpPingTool
18+
{
19+
partial class Program
20+
{
21+
22+
static void GetConsoleArgumentsValues(string[] args)
23+
{
24+
if (args.Length == 0)
25+
{
26+
ValueShowHelp = true;
27+
return;
28+
}
29+
30+
string[] tokens;
31+
32+
foreach (string arg in args)
33+
{
34+
tokens = arg.Split(new char[] { '=' }, 2);
35+
switch (tokens[0])
36+
{
37+
case ArgShowHelp:
38+
ValueShowHelp = true;
39+
return;
40+
}
41+
42+
// If no value for the argument is given, continue in next iteration
43+
if (tokens.Length < 2)
44+
{
45+
Console.WriteLine("Unknown command line argument '{0}' was passed", tokens[0]);
46+
continue;
47+
}
48+
49+
string t = tokens[1];
50+
51+
// Get the argument value
52+
switch (tokens[0])
53+
{
54+
case ArgOutageTimeBeforeGiveUpSeconds:
55+
GetConsoleArgumentValue2(t, ref ValueOutageTimeBeforeGiveUpSeconds);
56+
break;
57+
58+
case ArgOutageConditionNumPings:
59+
GetConsoleArgumentValue2(t, ref ValueOutageConditionNumPings);
60+
break;
61+
62+
case ArgPassedPingIntervalMs:
63+
GetConsoleArgumentValue2(t, ref ValuePassedPingIntervalMs);
64+
break;
65+
66+
case ArgFailedPingIntervalMs:
67+
GetConsoleArgumentValue2(t, ref ValueFailedPingIntervalMs);
68+
break;
69+
70+
case ArgPingTimeoutMs:
71+
GetConsoleArgumentValue2(t, ref ValuePingTimeoutMs);
72+
break;
73+
74+
case ArgHost:
75+
string ValueHost = null;
76+
GetConsoleArgumentValue2(t, ref ValueHost);
77+
if (ValueHost != null)
78+
ValueHosts.Add(string.Intern(ValueHost));
79+
else
80+
Debug.Assert(false);
81+
break;
82+
83+
case ArgSuccessReplyBodyRegEx:
84+
string SuccessReplyBodyRegEx = null;
85+
GetConsoleArgumentValue2(t, ref SuccessReplyBodyRegEx);
86+
if (SuccessReplyBodyRegEx != null)
87+
ValueSuccessReplyBodyRegExes.Add(string.Intern(SuccessReplyBodyRegEx));
88+
else
89+
Debug.Assert(false);
90+
break;
91+
#if false
92+
case ArgSourceIP:
93+
string ValueSourceIP = null;
94+
GetConsoleArgumentValue2(t, ref ValueSourceIP);
95+
if (ValueSourceIP != null)
96+
ValueSourceIPs.Add(string.Intern(ValueSourceIP));
97+
else
98+
Debug.Assert(false);
99+
break;
100+
#endif
101+
102+
default:
103+
Console.WriteLine("Unknown command line argument '-{0}={1}' was passed", tokens[0], t);
104+
break;
105+
} //switch (tokens[0])
106+
} //foreach (string arg in args)
107+
} //static void GetArgumentValues(string[] args)
108+
109+
// ############################################################################
110+
111+
public static void GetConsoleArgumentValue2(string arg, ref float defaultValue)
112+
{
113+
defaultValue = GetConsoleArgumentValue(arg, defaultValue);
114+
}
115+
116+
public static float GetConsoleArgumentValue(string arg, float defaultValue)
117+
{
118+
string value = GetConsoleArgumentValue(arg, (string)null);
119+
120+
if (string.IsNullOrEmpty(value))
121+
return defaultValue;
122+
123+
return Convert.ToSingle(value);
124+
}
125+
126+
public static void GetConsoleArgumentValue2(string arg, ref bool defaultValue)
127+
{
128+
defaultValue = GetConsoleArgumentValue(arg, defaultValue);
129+
}
130+
131+
public static bool GetConsoleArgumentValue(string arg, bool defaultValue)
132+
{
133+
string value = GetConsoleArgumentValue(arg, (string)null);
134+
135+
if (string.IsNullOrEmpty(value))
136+
return defaultValue;
137+
138+
139+
bool rval;
140+
if (Boolean.TryParse(value, out rval))
141+
{
142+
return rval;
143+
}
144+
else
145+
{
146+
value = value.ToLower();
147+
148+
if (value == "yes")
149+
return true;
150+
else if (value == "on")
151+
return true;
152+
else if (value == "true")
153+
return true;
154+
else if (value == "no")
155+
return false;
156+
else if (value == "off")
157+
return false;
158+
else if (value == "false")
159+
return false;
160+
161+
int val = Convert.ToInt32(value);
162+
163+
if (val == 0)
164+
return false;
165+
else if (val == 1)
166+
return true;
167+
else
168+
throw new FormatException();
169+
}
170+
} //public static bool GetConsoleArgumentValue(string arg, bool defaultValue)
171+
172+
public static void GetConsoleArgumentValue2(string arg, ref int defaultValue)
173+
{
174+
defaultValue = GetConsoleArgumentValue(arg, defaultValue);
175+
}
176+
177+
public static int GetConsoleArgumentValue(string arg, int defaultValue)
178+
{
179+
string value = GetConsoleArgumentValue(arg, (string)null);
180+
181+
if (string.IsNullOrEmpty(value))
182+
return defaultValue;
183+
184+
return Convert.ToInt32(value);
185+
}
186+
187+
public static void GetConsoleArgumentValue2(string arg, ref string defaultValue)
188+
{
189+
defaultValue = GetConsoleArgumentValue(arg, defaultValue);
190+
}
191+
192+
/// <summary>
193+
/// Converts empty string to default string
194+
/// </summary>
195+
/// <param name="arg"></param>
196+
/// <param name="defaultValue"></param>
197+
/// <returns></returns>
198+
public static string GetConsoleArgumentValue(string arg, string defaultValue)
199+
{
200+
if (string.IsNullOrEmpty(arg))
201+
return defaultValue;
202+
203+
return arg.Trim();
204+
}
205+
206+
// ############################################################################
207+
208+
}
209+
}

HttpPingTool.csproj

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
4+
<OutputPath>bin\x86\Release\</OutputPath>
5+
<DefineConstants>TRACE</DefineConstants>
6+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7+
<Optimize>true</Optimize>
8+
<DebugType>full</DebugType>
9+
<PlatformTarget>x86</PlatformTarget>
10+
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
11+
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
12+
<ErrorReport>prompt</ErrorReport>
13+
<WarningsAsErrors>0078;0108;0109;0642;0693;1699;1717</WarningsAsErrors>
14+
<DebugSymbols>true</DebugSymbols>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<OutputPath>bin\x86\Debug\</OutputPath>
19+
<DefineConstants>DEBUG;TRACE</DefineConstants>
20+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
21+
<DebugType>full</DebugType>
22+
<PlatformTarget>x86</PlatformTarget>
23+
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
24+
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningsAsErrors>0078;0108;0109;0642;0693;1699;1717</WarningsAsErrors>
27+
</PropertyGroup>
28+
<PropertyGroup>
29+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
30+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
31+
<ProductVersion>9.0.30729</ProductVersion>
32+
<SchemaVersion>2.0</SchemaVersion>
33+
<ProjectGuid>{3910F010-482A-4171-8997-DA496C4A0045}</ProjectGuid>
34+
<OutputType>Exe</OutputType>
35+
<AppDesignerFolder>Properties</AppDesignerFolder>
36+
<RootNamespace>HttpPingTool</RootNamespace>
37+
<AssemblyName>HttpPingTool</AssemblyName>
38+
<TargetFrameworkVersion>v3.0</TargetFrameworkVersion>
39+
<FileAlignment>512</FileAlignment>
40+
<StartupObject>HttpPingTool.Program</StartupObject>
41+
<FileUpgradeFlags>
42+
</FileUpgradeFlags>
43+
<UpgradeBackupLocation>
44+
</UpgradeBackupLocation>
45+
<OldToolsVersion>3.5</OldToolsVersion>
46+
</PropertyGroup>
47+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release .net 3.0|x86' ">
48+
<OutputPath>bin\x86\Release .net 3.0\</OutputPath>
49+
<DefineConstants>TRACE</DefineConstants>
50+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
51+
<Optimize>true</Optimize>
52+
<DebugType>full</DebugType>
53+
<PlatformTarget>x86</PlatformTarget>
54+
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
55+
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
56+
<ErrorReport>prompt</ErrorReport>
57+
<WarningsAsErrors>0078;0108;0109;0642;0693;1699;1717</WarningsAsErrors>
58+
<DebugSymbols>true</DebugSymbols>
59+
</PropertyGroup>
60+
<ItemGroup>
61+
<Reference Include="System" />
62+
<Reference Include="System.Windows.Forms" />
63+
<Reference Include="System.Data" />
64+
<Reference Include="System.Xml" />
65+
</ItemGroup>
66+
<ItemGroup>
67+
<Compile Include="ConsoleArguments.cs" />
68+
<Compile Include="ExitHandlers.cs" />
69+
<Compile Include="GetConsoleArgumentsValues.cs" />
70+
<None Include="app.config" />
71+
<Compile Include="NativeMethods.cs" />
72+
<Compile Include="OutputConsoleArgumentsHelp.cs" />
73+
<Compile Include="Program.cs" />
74+
<Compile Include="Properties\AssemblyInfo.cs" />
75+
<None Include="example.bat" />
76+
<None Include="LICENSE" />
77+
<None Include="README.md" />
78+
</ItemGroup>
79+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
80+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
81+
Other similar extension points exist, see Microsoft.Common.targets.
82+
<Target Name="BeforeBuild">
83+
</Target>
84+
<Target Name="AfterBuild">
85+
</Target>
86+
-->
87+
</Project>

LICENSE

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Copyright (c) 2010-2014 Roland Pihlakas, [email protected]
2+
13
GNU LESSER GENERAL PUBLIC LICENSE
24
Version 2.1, February 1999
35

0 commit comments

Comments
 (0)