aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Graphics/account.png
blob: 46f0d38fcdb137ab6e4847bc958d328bb93c7a69 (plain) pre { line-height: 125%; } td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Tango.Core.Helpers;
using Tango.BL.Entities;
using Tango.Logging;
using Tango.MachineStudio.Common.Update;
using Tango.BL;
using Tango.BL.Enumerations;

namespace Tango.MachineStudio.UpdateService
{
    public class MachineStudioUpdateService : IMachineStudioUpdateService
    {
        private LogManager LogManager = LogManager.Default;

        private class PendingUpload
        {
            public String Token { get; set; }

            public String Version { get; set; }

            public String UserGuid { get; set; }

            public String Comments { get; set; }

            public String FilePath { get; set; }
        }

        private static List<PendingUpload> _pendingUploads;

        static MachineStudioUpdateService()
        {
            _pendingUploads = new List<PendingUpload>();
        }

        public CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request)
        {
            LogManager.Log("Request received...");

            try
            {
                CheckForUpdatesResponse response = new CheckForUpdatesResponse();

                using (ObservablesContext db = ObservablesContext.CreateDefaultForWeb())
                {
                    db.Configuration.LazyLoadingEnabled = false;

                    //Load relation first...
                    db.Roles.ToList();
                    db.Permissions.ToList();
                    db.UsersRoles.ToList();
                    db.RolesPermissions.ToList();

                    var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password);

                    if (user != null && user.HasPermission(Permissions.RunMachineStudio))
                    {
                        var latestVersion = db.MachineStudioVersions.FirstOrDefault();
                        Version currentVersion = Version.Parse(request.Version);

                        if (latestVersion != null && Version.Parse(latestVersion.Version) > currentVersion)
                        {
                            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());
            }
        }

        public UploadVersionResponse UploadVersion(UploadVersionRequest request)
        {
            try
            {
                UploadVersionResponse response = new UploadVersionResponse();

                using (ObservablesContext db = ObservablesContext.CreateDefaultForWeb())
                {
                    db.Configuration.LazyLoadingEnabled = false;

                    //Load relation first...
                    db.Roles.ToList();
                    db.Permissions.ToList();
                    db.UsersRoles.ToList();
                    db.RolesPermissions.ToList();

                    var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password);

                    if (user != null && user.HasPermission(Permissions.PublishMachineStudioVersion))
                    {
                        var latestVersion = db.MachineStudioVersions.FirstOrDefault();
                        Version currentVersion = Version.Parse(request.Version);

                        String newVersionFileName = Path.GetRandomFileName() + ".zip";

                        String newVersionFilePath = "/machine studio versions/" + newVersionFileName;

                        if (currentVersion > Version.Parse(latestVersion.Version))
                        {
                            response.FtpHost = ConfigurationManager.AppSettings["FtpHost"].ToString();
                            response.UserName = ConfigurationManager.AppSettings["UserName"].ToString();
                            response.Password = ConfigurationManager.AppSettings["Password"].ToString();
                            response.FilePath = newVersionFilePath;
                            response.FileName = newVersionFileName;
                            response.Token = Guid.NewGuid().ToString();

                            _pendingUploads.Add(new PendingUpload()
                            {
                                UserGuid = user.Guid,
                                Comments = request.Comments,
                                Token = response.Token,
                                Version = request.Version,
                                FilePath = response.FilePath,
                            });
                        }
                        else
                        {
                            throw new FaultException("New version must be greater than latest version.");
                        }
                    }
                    else
                    {
                        throw new FaultException("Invalid user credentials.");
                    }
                }

                return response;
            }
            catch (Exception ex)
            {
                LogManager.Log(ex);
                throw new FaultException(ex.ToString());
            }
        }

        public void NotifyUploadCompleted(UploadCompletedRequest request)
        {
            try
            {
                PendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.Token);

                if (upload != null)
                {
                    _pendingUploads.RemoveAll(x => x.Token == upload.Token);

                    using (ObservablesContext db = ObservablesContext.CreateDefaultForWeb())
                    {
                        db.Configuration.LazyLoadingEnabled = false;

                        db.MachineStudioVersions.Add(new MachineStudioVersion()
                        {
                            Comments = upload.Comments,
                            FtpFilePath = upload.FilePath,
                            UserGuid = upload.UserGuid,
                            Version = upload.Version
                        });

                        db.SaveChanges();
                    }
                }
                else
                {
                    throw new FaultException("Invalid Token.");
                }
            }
            catch (Exception ex)
            {
                LogManager.Log(ex);
                throw new FaultException(ex.ToString());
            }
        }

        public string GetLatestVersion()
        {
            try
            {
                using (ObservablesContext db = ObservablesContext.CreateDefaultForWeb())
                {
                    return db.MachineStudioVersions.FirstOrDefault().Version;
                }
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.ToString());
            }
        }
    }
}
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 80 00 00 00 80 08 06 00 00 00 c3 3e 61 .PNG........IHDR..............>a
0020 cb 00 00 00 04 73 42 49 54 08 08 08 08 7c 08 64 88 00 00 00 09 70 48 59 73 00 00 1e 07 00 00 1e .....sBIT....|.d.....pHYs.......
0040 07 01 99 78 d9 32 00 00 00 19 74 45 58 74 53 6f 66 74 77 61 72 65 00 77 77 77 2e 69 6e 6b 73 63 ...x.2....tEXtSoftware.www.inksc
0060 61 70 65 2e 6f 72 67 9b ee 3c 1a 00 00 0c aa 49 44 41 54 78 da ed 9d 79 50 55 d7 1d c7 d3 aa d3 ape.org..<.....IDATx...yPU......
0080 c4 36 69 e3 8c c9 a4 9d 49 a6 b6 59 a6 93 a4 d3 a6 9a 4e 3b d3 4e 66 6a a7 93 4e a7 69 27 51 83 .6i.....I..Y......N;.Nfj..N.i'Q.
00a0 3b 0a 8a 80 0b 11 f7 28 bb 80 a2 12 91 25 a0 f0 44 14 51 76 84 a8 c0 7b c0 03 9e 04 41 59 65 13 ;......(.....%..D.Qv...{....AYe.
00c0 65 df 41 24 8a 71 b9 fd 1d 7b 9f f3 80 07 bc bb ff ee 7b e7 8f cf 38 ea e3 72 cf fd 7e de b9 e7 e.A$.q...{........{...8..r..~...
00e0 9e 73 ee 39 cf 31 0c f3 1c c5 76 51 f5 c9 7f b6 ca e3 47 c0 3b c0 3f 81 8d 40 30 90 06 68 81 62 .s.9.1....vQ......G.;.?..@0..h.b
0100 a0 1c a8 05 6e 01 6d 40 35 a0 67 3f 13 03 1c 02 b6 03 ff 02 7e 09 fc 80 0a 80 3b f0 79 c0 4a 20 ....n.m@5.g?........~.....;.y.J.
0120 0a a8 03 9e 00 8c 88 8c 00 25 40 34 b0 8e 48 41 05 50 36 f0 17 80 cf 80 33 40 87 c8 61 5b 4a 03 .........%@4..HA.P6.....3@..a[J.
0140 70 0c f8 37 f0 12 15 40 fa d0 67 01 1f 03 b1 c0 b0 42 a1 4f c6 28 10 0f 2c b4 96 db 05 a6 e0 5f p..7...@..g......B.O.(..,......_
0160 03 02 80 3e 64 a1 4f 06 69 57 ec 05 5e a7 02 08 0b fe 6d 20 92 fd 76 31 2a e4 11 5b 5b bd 45 05 ...>d.O.iW..^.....m...v1*..[[.E.
0180 e0 16 fc 7b 40 12 f0 58 a5 c1 9b 13 41 03 fc 9a 0a 30 75 f0 73 80 10 f6 82 31 56 c8 23 f6 29 e2 ...{@..X....A....0u.s....1V.#.).
01a0 55 2a c0 d8 e0 67 00 4e 2a ba c7 0b 65 00 58 8b bd b1 28 57 f8 ef b3 9d 32 8c 0d a2 23 ed 1c 9b U*...g.N*...e.X...(W....2...#...
01c0 15 80 ed a1 1b b5 d1 f0 4d 1f 1f 77 60 ac 0d a4 0c 7e 2e 70 c1 c6 83 1f 4f 06 f0 b2 d5 0b 00 85 ........M..w`....~.p....O.......
01e0 fc 08 e8 a4 81 9b a5 19 f8 c0 6a 05 80 c2 2d 07 be a7 41 4f 7b 4b 70 b0 3a 01 a0 50 bb 69 b8 9c ..........j...-...AO{Kp.:..P.i..
0200 f0 b2 0a 01 d8 47 bc 08 1a 28 2f be 52 b2 71 28 46 f8 33 d9 1e 3d 1a 26 7f 48 0f e2 0c d5 09 00 .....G...(/.R.q(F.3..=.&.H......
0220 27 fd 43 e0 14 a6 8b b9 68 b5 e7 80 9d 83 4f 83 bd 6b e0 d5 4d 3b 43 f4 1e 01 31 ba c3 61 e7 74 '.C.....h.....O..k..M;C...1..a.t
0240 e4 4f f2 77 f2 ef e4 ff c9 e7 90 49 40 be 44 33 d5 26 40 98 c2 17 ed 9e b3 fb 91 a2 94 2c bd a1 .O.w.......I@.D3.&@..........,..
0260 b6 b1 a5 ad ab 6f 60 b4 6f e8 0e 63 29 e4 f3 b5 8d b7 5b 93 2e 14 14 3b 6d 3d 4c 66 10 dd 57 b8 .....o`.o..c).....[....;m=Lf..W.
0280 3c 91 aa 11 00 4e 36 50 a9 be f6 35 ae 81 a5 b1 09 97 f2 db ba 7a 87 b9 04 3e 1d ad 9d 3d 77 34 <....N6P...5.........z...>...=w4
02a0 f1 17 0b ec 5d 02 cb 14 1c a4 da 85 5e 00 38 c9 4d 4a 5c 1c 08 fe db fa e6 b6 36 31 43 9f 8c 1b ....].......^.8.MJ\.......61C...
02c0 4d 2d ed f6 2e 01 65 0a 94 93 4c 73 b3 43 2b 00 9c dc 9f 81 87 32 5f 94 07 c1 11 89 b9 bd 83 77 M-....e...Ls.C+......2_........w
02e0 9e c8 11 be 91 de c1 a1 27 41 a1 09 79 4a 94 17 f8 0b 3a 01 e0 a4 5e 01 da e5 bc 18 4b d6 78 dd ........'A..yJ....:...^.....K.x.
0300 32 94 d5 54 cb 19 fc 78 0a 4b 2a 6b e0 3c 5a 65 96 80 f4 a4 be 82 46 00 f6 59 3f 57 e6 16 fd 20 2..T...x.K*k.<Ze......F..Y?W....
0320 69 dc 29 19 be 91 aa ba e6 b6 45 ab 3c ee ca 2c 41 a6 d4 7d 04 5c 04 f0 91 fb 7e 98 92 a9 37 60 i.).......E.<..,A..}.\....~...7`
0340 08 df 48 42 aa d6 a0 40 9b c0 4d 71 01 e0 24 7e 27 f7 0c 9e 5d 3e 51 3a 4c e1 1b 71 df 17 5e a0 ..HB...@..Mq..$~'...]>Q:L..q..^.
0360 40 7b e0 f7 8a 09 c0 56 fd a5 72 77 e6 74 f6 f6 df c7 28 40 7b 77 2f 79 79 44 ee 5b 41 0d 99 2e @{.....V..rw.t....(@{w/yyD.[A...
0380 af 94 00 6e 72 57 7b 7b 7c 8f a3 fc f6 1b d9 e6 11 91 67 2d b7 82 e9 c2 7f 83 7d 5d 4a d6 c2 5e ...nrW{{|.........g-......}]J..^
03a0 af 69 6a c2 2c 40 c9 b5 1b 37 14 10 60 48 8a a7 82 e9 04 90 7d 90 67 a9 a3 6f 1d e6 f0 8d 7c be .ij.,@...7..`H......}.g..o....|.
03c0 d6 fb a6 35 74 15 4f d7 f0 93 bd b7 6f cb ee 63 05 6a 10 c0 65 5b 70 a1 02 d7 e7 b1 d8 b3 89 a6 ...5t.O.....o..c.j..e[p.........
03e0 12 20 55 09 01 42 a2 92 75 6a 10 20 28 34 41 ab d0 58 41 96 e4 02 10 cb 94 1a 11 3b 9b a2 2d 54 ..U..B..uj..(4A..XA........;..-T
0400 83 00 b1 e7 2e eb 15 1c 35 7c 5f 6a 01 d2 15 14 a0 48 0d 02 9c 4e cc 51 52 80 53 92 09 c0 be b3 ........5|_j.....H...N.QR.S.....
0420 c7 50 01 a6 86 d4 54 0a 5e 27 32 38 f5 86 54 02 1c a1 02 58 24 40 91 c2 93 47 82 45 17 80 5d 73 .P....T.^'28..T....X$@...G.E..]s
0440 a7 8f 0a a0 0a 01 c8 e2 19 2f 88 2d c0 22 a5 e7 c6 51 01 38 f1 a9 d8 02 5c a4 02 a8 4a 80 44 d1 ........./.-."...Q.8....\...J.D.
0460 04 80 83 fd 02 c3 62 0d 54 00 4e dc 17 ba 70 95 a9 00 6b 30 4c 8f a6 02 70 66 a5 58 02 9c a5 02 ......b.T.N...p...k0L...pf.X....
0480 a8 52 80 74 c1 02 b0 2f 78 f4 51 01 54 29 c0 20 c9 4f a8 00 f3 b1 bc 21 43 05 90 b7 6b d8 28 c0 .R.t.../x.Q.T)...O.....!C...k.(.
04a0 2e 2a 80 aa 05 d8 20 54 80 0c 2c 85 49 48 d5 a9 42 00 72 9e 88 04 38 23 54 80 5b 18 0a 62 e7 e0 .*.....T..,.IH..B.r...8#T.[..b..