blob: 4cfea1b8a0700ea905c49e18fb14c6b147bf74fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Tango.Integration.Observables;
using Tango.Logging;
using Tango.MachineStudio.Common.Update;
namespace Tango.MachineStudio.UpdateService
{
public class MachineStudioUpdateService : IMachineStudioUpdateService
{
public CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request)
{
LogManager.Log("Request received...");
try
{
CheckForUpdatesResponse response = new CheckForUpdatesResponse();
using (ObservablesContext db = ObservablesContext.CreateDefaultForWeb())
{
db.Configuration.LazyLoadingEnabled = false;
var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password);
if (user != null)
{
var latestVersion = db.MachineStudioVersions.FirstOrDefault();
Version currentVersionNumber = Version.Parse(request.Version);
if (latestVersion != null && Version.Parse(latestVersion.Version) > currentVersionNumber)
{
response.IsUpdateAvailable = true;
response.FtpHost = ConfigurationManager.AppSettings["FtpHost"].ToString();
response.UserName = ConfigurationManager.AppSettings["UserName"].ToString();
response.Password = ConfigurationManager.AppSettings["Password"].ToString();
response.FilePath = latestVersion.FtpFilePath;
response.Version = latestVersion.Version;
}
}
else
{
throw new FaultException("Invalid user credentials.");
}
}
return response;
}
catch (Exception ex)
{
LogManager.Log(ex);
throw new FaultException(ex.ToString());
}
}
}
}
|