Skip to content

Commit 549394a

Browse files
committed
Initial code (migrated)
1 parent f99d280 commit 549394a

104 files changed

Lines changed: 32892 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.user
2+
obj
3+
bin
4+
*.suo
5+
packages

.vs/config/applicationhost.config

Lines changed: 1038 additions & 0 deletions
Large diffs are not rendered by default.

Console/.vs/config/applicationhost.config

Lines changed: 1038 additions & 0 deletions
Large diffs are not rendered by default.

Console/ServMon/App.config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
5+
</startup>
6+
<!--<appSettings>
7+
<add key="LogPath" value="" />
8+
</appSettings>-->
9+
</configuration>

Console/ServMon/CommonService.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Net;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace ServMon
10+
{
11+
abstract class CommonService : IServiceType
12+
{
13+
public string Name { get; set; }
14+
public string Url { get; set; }
15+
public ServTypes Type { get; set; }
16+
17+
public bool Enabled { get; set; }
18+
public bool EnableSms { get; set; }
19+
public string Content { get; set; }
20+
21+
public string Username { get; set; }
22+
public string Password { get; set; }
23+
24+
public int Interval { get; set; }
25+
public string ToEmails { get; set; }
26+
public string ToNumbers { get; set; }
27+
public DateTime LastUpdate { get; set; }
28+
public bool Success { get; set; }
29+
public string Message { get; set; }
30+
public string StackTrace { get; set; }
31+
32+
public abstract ServResponse Execute();
33+
34+
protected void PreExecute()
35+
{
36+
37+
}
38+
39+
protected void PostExecute(ServResponse response)
40+
{
41+
Success = response.Success;
42+
Message = response.Message;
43+
StackTrace = response.StackTrace;
44+
LastUpdate = DateTime.Now;
45+
}
46+
}
47+
}

Console/ServMon/Constants.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ServMon
8+
{
9+
enum ServTypes
10+
{
11+
HTTP = 1,
12+
FTP = 2,
13+
SMTP = 3
14+
}
15+
}

Console/ServMon/FtpService.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Net;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using WCMS.Common.Utilities;
9+
10+
namespace ServMon
11+
{
12+
class FtpService : CommonService
13+
{
14+
public override ServResponse Execute()
15+
{
16+
PreExecute();
17+
18+
var callSuccess = false;
19+
var text = string.Empty;
20+
var response = new ServResponse();
21+
var path = FtpHelper.UrlEncode(Url);
22+
try
23+
{
24+
var client = (FtpWebRequest)WebRequest.Create(path);
25+
client.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
26+
client.Proxy = WebRequest.GetSystemWebProxy();
27+
client.Credentials = new NetworkCredential(Username, Password);
28+
using (var res = client.GetResponse() as FtpWebResponse)
29+
{
30+
var reader = new StreamReader(res.GetResponseStream(), System.Text.Encoding.ASCII);
31+
text = reader.ReadToEnd();
32+
reader.Close();
33+
res.Close();
34+
callSuccess = true;
35+
}
36+
}
37+
catch (Exception ex)
38+
{
39+
response.Message = ex.Message;
40+
response.StackTrace = ex.ToString();
41+
}
42+
43+
if (callSuccess)
44+
{
45+
if (text.Contains(Content))
46+
response.Success = true;
47+
else
48+
response.Message = string.Format("Expected response not found - {0}", Content);
49+
}
50+
51+
PostExecute(response);
52+
return response;
53+
}
54+
}
55+
}

Console/ServMon/HttpService.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Net;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace ServMon
10+
{
11+
class HttpService : CommonService
12+
{
13+
public override ServResponse Execute()
14+
{
15+
PreExecute();
16+
17+
var callSuccess = false;
18+
var text = string.Empty;
19+
var response = new ServResponse();
20+
try
21+
{
22+
var req = WebRequest.Create(Url);
23+
var res = req.GetResponse();
24+
var data = res.GetResponseStream();
25+
using (var sr = new StreamReader(data))
26+
{
27+
text = sr.ReadToEnd();
28+
}
29+
res.Close();
30+
callSuccess = true;
31+
}
32+
catch (Exception ex)
33+
{
34+
response.Message = ex.Message;
35+
response.StackTrace = ex.ToString();
36+
}
37+
38+
if (callSuccess)
39+
{
40+
if (text.Contains(Content))
41+
response.Success = true;
42+
else
43+
response.Message = string.Format("Expected response not found - {0}", Content);
44+
}
45+
46+
PostExecute(response);
47+
return response;
48+
}
49+
}
50+
}

Console/ServMon/IServiceType.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
namespace ServMon
3+
{
4+
interface IServiceType
5+
{
6+
string Content { get; set; }
7+
bool Enabled { get; set; }
8+
bool EnableSms { get; set; }
9+
ServResponse Execute();
10+
string Name { get; set; }
11+
ServTypes Type { get; set; }
12+
string Url { get; set; }
13+
14+
string Username { get; set; }
15+
string Password { get; set; }
16+
int Interval { get; set; }
17+
string ToEmails { get; set; }
18+
string ToNumbers { get; set; }
19+
DateTime LastUpdate { get; set; }
20+
bool Success { get; set; }
21+
string Message { get; set; }
22+
}
23+
}

Console/ServMon/MailSender.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
using System.Net;
8+
using System.Net.Mail;
9+
using WCMS.Common.Utilities;
10+
11+
namespace ServMon
12+
{
13+
class MailSender
14+
{
15+
public string To { get; set; }
16+
public string Subject { get; set; }
17+
public string Message { get; set; }
18+
19+
public void Send()
20+
{
21+
var settings = ServManager.Instance.MailSettings;
22+
using (var mail = new MailMessage())
23+
{
24+
try
25+
{
26+
mail.From = new MailAddress(settings.From);
27+
mail.To.Add(To.TrimEnd(','));
28+
mail.Subject = Subject;
29+
mail.Body = Message;
30+
mail.IsBodyHtml = settings.IsBodyHtml;
31+
// Can set to false, if you are sending pure text.
32+
33+
//mail.Attachments.Add(new Attachment("C:\\SomeFile.txt"));
34+
//mail.Attachments.Add(new Attachment("C:\\SomeZip.zip"));
35+
36+
using (var smtp = new SmtpClient(settings.Host, settings.Port))
37+
{
38+
smtp.Credentials = new NetworkCredential(settings.From, settings.Password);
39+
smtp.EnableSsl = settings.EnableSsl;
40+
smtp.Send(mail);
41+
}
42+
}
43+
//catch (SmtpFailedRecipientsException) { }
44+
catch (Exception ex)
45+
{
46+
LogHelper.WriteLog(true, ex);
47+
}
48+
}
49+
}
50+
51+
}
52+
}

0 commit comments

Comments
 (0)