aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Graphics/break-big.png
blob: 363ee88a1d693dfba9b2a522ed0ac569d585b606 (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 01 00 00 00 01 00 08 06 00 00 00 5c 72 a8 .PNG........IHDR.............\r.
0020 66 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 06 ec 00 00 06 f....sBIT....|.d.....pHYs.......
0040 ec 01 1e 75 38 35 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 ...u85....tEXtSoftware.www.inksc
0060 61 70 65 2e 6f 72 67 9b ee 3c 1a 00 00 12 e0 49 44 41 54 78 9c ed dd 4b 8c 1c 47 19 07 f0 7f 6f ape.org..<.....IDATx...K..G....o
0080 8f 77 d7 5e db 71 00 9b 98 04 21 f1 10 c4 2b 44 e2 75 e2 38 46 36 e6 b8 1c 40 8a bc 12 ca 09 2e .w.^.q....!...+D.u.8F6...@......
00a0 3c 4e bc 02 42 b1 6c 9c d8 8a 04 02 6e 28 b7 e4 90 5c e2 1c e0 80 0f 39 60 6c 09 4c 02 4e 90 90 <N..B.l.....n(...\.....9`l.L.N..
00c0 81 44 89 05 22 28 e1 25 82 f7 e1 dd de 9d 29 0e 9e b5 76 76 76 fb 59 f5 d5 57 5d ff 9f 84 44 ec .D.."(.%......)...vvv.Y..W]...D.
00e0 c9 f4 a4 7a e6 df 5f 75 d5 37 93 18 63 40 44 71 1a f1 fd 02 88 c8 1f 06 00 51 c4 18 00 44 11 63 ...z.._u.7..c@Dq.........Q...D.c
0100 00 10 45 8c 01 40 14 31 06 00 51 c4 18 00 44 11 eb f8 7e 01 24 6b ea 4c 96 bb f1 e3 ca 89 d1 44 ..E..@.1..Q...D...~.$k.L.......D
0120 ea b5 90 7f ac 00 88 22 c6 00 20 8a 18 03 80 28 62 0c 00 a2 88 31 00 88 22 c6 00 20 8a 18 03 80 .......".......(b....1..".......
0140 28 62 0c 00 a2 88 31 00 88 22 c6 00 20 8a 18 03 80 28 62 0c 00 a2 88 31 00 88 22 c6 00 20 8a 18 (b....1..".......(b....1..".....
0160 03 80 28 62 09 7f 17 80 28 5e ac 00 88 22 c6 00 20 8a 18 03 80 28 62 0c 00 a2 88 31 00 88 22 c6 ..(b....(^...".......(b....1..".
0180 00 20 8a 18 03 80 28 62 fc 5d 80 c8 f0 77 01 68 2d 56 00 44 11 63 00 10 45 8c 01 40 14 31 06 00 ......(b.]...w.h-V.D.c..E..@.1..
01a0 51 c4 18 00 44 11 63 00 10 45 8c 01 40 14 31 06 00 51 c4 18 00 44 11 63 00 10 45 8c 01 40 14 31 Q...D.c..E..@.1..Q...D.c..E..@.1
01c0 06 00 51 c4 18 00 44 11 63 00 10 45 8c 01 40 14 31 fe 2e 00 51 c4 58 01 10 45 8c 01 40 14 31 06 ..Q...D.c..E..@.1...Q.X..E..@.1.
01e0 00 51 c4 18 00 44 11 63 00 10 45 8c 01 40 14 31 06 00 51 c4 f8 bb 00 91 e1 ef 02 d0 5a ac 00 88 .Q...D.c..E..@.1..Q.........Z...
0200 22 c6 00 20 8a 18 03 80 28 62 0c 00 a2 88 31 00 88 22 c6 00 20 8a 18 03 80 28 62 0c 00 a2 88 31 ".......(b....1..".......(b....1
0220 00 88 22 c6 00 20 8a 18 03 80 28 62 0c 00 a2 88 31 00 5a e4 93 df c7 8e 36 1c 83 e4 30 00 5a e0 ..".......(b....1.Z.....6...0.Z.
0240 13 a7 e7 f6 4c 3d 9e 3d 7f 23 cb 5e 98 39 87 d4 d5 71 66 ce 21 bd 91 65 2f 4c 3d 9e 3d ff 89 d3 ....L=.=.#.^.9...qf.!..e/L=.=...
0260 73 7b 5c 1d 87 e4 30 00 02 77 e0 6c 76 bc 93 6e b9 8a 04 0f 01 78 e0 8d 57 97 be e1 ea 58 fd e7 s{\...0..w.lv..n.....x..W....X..
0280 7e 00 09 1e ea a4 5b ae 1e 38 9b 1d 77 75 2c 92 c1 df 05 08 d4 81 d3 78 8f 49 b3 9f 00 58 ff 21 ~.....[..8..wu,........x.I...X.!
02a0 5c 4c 52 dc fb bb ef 8e fe d9 ea f1 9e c8 3e 66 ba 78 05 c0 f8 ba bf 3a 97 74 47 bf fa bb 53 f8 \LR...........>f.x.....:.tG...S.
02c0 b7 cd e3 91 0c 56 00 01 da 7f 36 7b c8 a4 cb 57 31 fc e1 07 80 71 d3 c5 d3 36 a7 02 33 e7 90 9a .....V....6{...W1....q...6..3...
02e0 2e 9e c6 f0 87 1f 00 8e 9b 74 f9 ea fe b3 d9 43 b6 8e 47 72 18 00 81 b9 e7 ec 8d 3b 13 83 67 00 .........t.....C..Gr.......;..g.
0300 93 37 07 3f f8 c6 6b d9 37 6d 1d b3 ff 5c 07 37 7f 84 d9 93 18 3c 73 cf d9 1b 77 da 3a 26 c9 60 .7.?..k.7m...\.7.....<s...w.:&.`
0320 00 04 e6 f7 8f 6e fd 3b 60 4e 16 3e d0 e0 b1 a9 33 d9 dd 4d 8f 37 75 26 bb 1b 06 8f 15 3f d2 9c .....n.;`N.>....3..M.7u&.....?..
0340 bc f9 da 28 24 0c 80 00 7d e8 a3 63 3f 02 f0 9b 82 87 8d 19 34 9b 0a cc 9c 43 6a 80 a7 01 8c 15 ...($...}..c?.......4....Cj.....
0360 3c f4 37 2f 77 c7 7e 58 f7 38 e4 0f 03 20 40 cf 1d 47 37 49 f1 05 00 8b 79 8f 4b 80 fb 5f 7f 35 <.7/w.~X.8....@..G7I....y.K.._.5
0380 fb 56 dd e3 bc fe 6a f6 ad 04 b8 bf e0 61 8b 49 8a 2f 98 53 e8 d5 3d 0e f9 c3 00 08 d4 cd bb fc .V....j......a.I./.S..=.........
03a0 c5 53 81 04 38 bd ff 89 6c 5f d5 e7 df ff 44 b6 2f 01 4e 17 3f d2 9c b4 bd e2 40 72 18 00 01 2b .S..8...l_....D./.N.?.....@r...+
03c0 3b 15 40 17 4f 55 99 0a cc 9c 43 8a 2e 9e 02 4b ff d6 63 00 04 ac ca 54 e0 da 6b d9 23 65 9f f7 ;.@.OU....C....K..c....T..k.#e..
03e0 da 6b d9 23 2c fd e3 c0 00 08 5c d9 a9 80 31 f8 5e 99 a9 c0 fe 27 b2 7d c6 e0 7b c5 47 66 e9 df .k.#,.....\...1.^....'.}..{.Gf..
0400 06 0c 80 16 28 3b 15 48 0a 36 08 cd 9c 43 9a 74 79 d7 3f 26 0c 80 16 28 3b 15 00 70 df b5 57 b3 ....(;.H.6...C.ty.?&...(;..p..W.
0420 6f 6f f6 97 fd bf bb af e0 39 58 fa b7 08 03 a0 25 4a 4f 05 80 53 f7 3c 9e 4d ae ff f3 7b 1e cf oo.......9X.....%JO..S.<.M...{..
0440 26 0d 70 aa f8 48 2c fd db 84 01 d0 22 65 a7 02 69 32 38 15 98 39 87 34 4d 58 fa c7 88 01 d0 22 &.p..H,....."e..i28..9.4MX....."
0460 15 a6 02 07 de 78 2d fb ce ea 3f f4 ff ff 81 82 7f 87 a5 7f 0b b1 1d b8 85 a6 ce 2c 3d 02 24 df .....x-...?................,=.$.
0480 2f 78 58 d6 35 d8 0f 00 69 82 97 01 8c e6 3f dc 7c fb ca 89 b1 1f d8 79 85 a4 05 2b 80 16 2a 39 /xX.5...i.....?.|......y...+..*9
04a0 15 18 4d 13 3c dd 2f fd 0b 3e fc 2c fd db 8a 15 40 4b e5 7c 81 47 55 4e be 60 84 74 60 05 d0 52 ..M.<./..>.,....@K.|.GUN.`.t`..R
04c0 65 57 05 8a f1 ae 7f 9b 31 00 5a ac e4 54 20 0f 4b ff 96 2b 9c 02 64 97 f7 9b 74 b4 68 75 c8 aa eW......1.Z..T..K..+..d...t.hu..
04e0 c9 74 ea f2 1f 25 0f d8 66 0d a6 02 2c fd 1d eb 5e 39 b4 0f c0 55 67 cf 9f 2d 61 f4 d0 cb 49 de .t...%..f...,...^9...Ug..-a...I.
0500 63 0a 2b 80 e5 d9 77 ec bd a2 72 f8 4d b3 16 d5 9f 0a b0 f4 17 30 e3 f2 c9 cb 7c 76 0b 03 a0 b7 c.+...w...r.M........0....|v....
0520 bc 8c ee e2 82 95 17 54 92 d3 41 89 51 8d a9 00 4b 7f 19 ce 2e 76 dd c5 05 f4 96 97 0b 1f 57 ea .......T..A.Q...K....v........W.
0540 1e 40 36 7b 1d 80 d8 6a c1 be 7e 69 44 96 54 d8 20 04 70 c3 8f 88 fe 7b dc d1 fb dc f4 3f b3 c5 .@6{...j..~iD.T...p....{.....?..
0560 4a 05 80 e9 ae 60 65 61 be d1 4b aa 88 d3 00 cb ca 4f 05 58 fa 0b 71 56 e9 ae 2c cc c3 74 57 4a J....`ea..K......O.X..qV..,..tWJ
0580 3d b6 f4 2a c0 f2 dc 75 40 6e cf 00 a7 01 0e 94 98 0a b0 f4 97 e3 e6 22 67 cc cd cf 6a 49 a5 03 =..*...u@n............."g...jI..
05a0 c0 f4 7a 58 9e 9f ad f5 9a 6a e0 34 c0 81 e7 8e a3 db eb f6 3e 8f 04 d7 86 fe 32 c1 b5 5e b7 f7 ..zX.....j.4........>.....2..^..
05c0 79 96 fe ee b9 2c ff 97 e7 67 61 7a e5 4f 61 a5 7d 00 55 9f bc 21 4e 03 1c 78 e5 d4 f8 5f d2 95 y....,...gaz.Oa.}.U..!N..x..._..
05e0 e5 c3 00 9e 02 f0 d7 fe ff 9e 4a 57 96 0f bf 72 6a fc 2f 5e 5f 5c 3c 9c 54 b8 75 2e d2 9d 6a 47 ..........JW...rj./^_\<.T.u...jG
0600 b8 59 5e 8c ee dc 55 e9 5f ab 69 06 a5 be 95 96 aa 7a e9 d4 c4 db 00 be 38 f8 a7 45 ed 00 64 91 .Y^...U._.i......z......8..E..d.
0620 93 8b 5b 9d 69 7a e5 9d 80 55 6e 30 34 c4 69 00 b5 8e ab f2 bf ee 8d fa 1a 5b 81 cb 2f 31 58 c0 ..[.iz...Un04.i..........[../1X.
0640 69 00 b5 8d 93 f2 bf ee 52 7d ad 5e 80 b2 9b 0c 2c e0 6a 00 b5 8d f5 8b 5a 93 cd 7a b5 9b 81 84 i.......R}.^....,.j.....Z..z....
0660 b6 08 73 1a 40 ad e1 aa fc 6f f2 59 ac 1d 00 dd 6c 09 dd 6c a9 f6 81 2b e0 34 80 da c2 7a 45 db ..s.@....o.Y....l..l...+.4...zE.
0680 f4 73 d8 a8 1d 58 a8 0a e0 34 80 da c2 fa c5 ac e9 67 b0 51 00 08 35 0a 71 1a 40 c1 73 51 fe db .s...X...4.......g.Q..5.q.@.sQ..
06a0 b8 17 d7 f8 0b 41 84 1a 85 38 0d a0 d0 59 ae 64 ed ac c6 35 0e 00 a1 46 21 4e 03 28 74 56 2f 62 .....A...8...Y.d...5...F!N.(tV/b
06c0 b6 f6 e3 58 f9 4a 30 81 46 21 4e 03 28 58 d6 cb ff 8a 0d 3f 79 ac 04 80 50 a3 10 a7 01 14 2a ab ...X.J0.F!N.(X.....?y...P.....*.
06e0 15 ac cd 9e 1c 6b 5f 0a 2a d0 28 c4 69 00 85 ca da c5 cb f6 c5 d6 de b7 02 5b 2c 4b 36 c1 69 00 .....k_.*.(.i............[,K6.i.
0700 05 c7 76 f9 6f 7b ba 6d f5 6b c1 05 1a 85 38 0d a0 d0 58 ab 5c 5d dc 70 b7 fc bb 00 ce 1b 85 38 ..v.o{.m.k....8...X.\].p.......8
0720 0d a0 d0 58 bb 68 b9 58 72 b7 fe c3 20 8e 1b 85 38 0d a0 60 d8 2c ff 5d 6d ba 73 f2 cb 40 8e b7 ...X.h.Xr.......8..`.,.]m.s..@..
0740 08 73 1a 40 a1 b0 56 b1 ba fa 4c 39 09 00 c7 8d 42 9c 06 50 28 ac 5c ac 5c 7e 9e 9c fd 36 a0 c3 .s.@..V...L9....B..P(.\.\~...6..
0760 2a 80 d3 00 52 cf 66 f9 ef b2 a2 76 16 00 8e 1b 85 38 0d 20 ed ac 54 aa ae bf 7c c7 e9 af 03 3b *...R.f....v.....8....T...|....;
0780 6c 14 e2 34 80 b4 b3 70 91 72 ff f5 7b 4e 03 c0 61 a3 10 a7 01 a4 96 ad f2 5f e2 0b 78 9d 06 00 l..4...p.r..{N..a........_..x...
07a0 e0 b4 51 88 d3 00 d2 aa 79 85 ea 7e 67 2d 00 81 00 70 d8 28 c4 69 00 69 d5 f8 e2 24 f5 23 3c ce ..Q.....y..~g-...p.(.i.i...$.#<.
07c0 03 00 70 f6 1f c3 69 00 a9 63 a3 fc 97 fc 19 3e 91 00 70 58 ce 70 1a 40 da 34 ae 4c 25 7f 88 57 ..p...i..c.....>..pX.p.@.4.L%..W
07e0 26 00 e0 ec 86 06 a7 01 a4 4d a3 8b 92 d0 37 6c dd 52 ed b7 01 1b b9 b9 a4 31 b6 eb 5d 36 9f 74 &........M....7l.R.......1..]6.t
0800 5f f7 ca 21 d7 51 b9 27 9d ba fc 2f c7 c7 20 07 ba 57 0e ed 06 f0 4f df af a3 0a a1 ef d8 bc 45 _..!.Q.'.../.....W....O........E
0820 ac 02 00 44 7f 51 c8 26 de 67 08 57 50 e7 4e e8 5b b6 07 88 06 00 20 f6 5b 02 36 4d fa 7e 01 54 ...D.Q.&.g.WP.N.[.......[.6M.~.T
0840 5b 50 e7 ce c7 67 43 3c 00 04 7f 51 c8 96 a0 de 44 34 20 98 73 e7 eb 73 21 1e 00 40 70 55 40 50 [P...gC<...Q....D4..s..s!..@pU@P
0860 65 24 0d 08 e6 dc f9 fa 4c 78 09 00 1f 73 9d 06 82 b9 8a d0 90 20 ce 9d cf 7b 63 5e 02 00 90 bf e$......Lx...s...........{c^....
0880 db d9 c0 ee fe dd 64 0a 48 ff 9c 05 70 de dc 37 fc e4 f1 16 00 d2 eb 9d 0d 05 53 4a d2 2d 41 9c ......d.H...p..7..........SJ.-A.
08a0 33 89 86 9f 3c 82 fb 00 86 2d cf 5d 47 67 eb 04 90 24 3e 5f 46 19 93 00 2e fa 7e 11 36 4c bc 72 3...<....-.]Gg...$>_F.....~.6L.r
08c0 2d b7 ec 9a bf f7 83 ea 4f 46 49 fa cb 7f a1 86 9f 3c de 2a 00 40 76 cf 73 43 fa df 4c b4 9e fa -.......OFI......<.*.@v.sC..L...
08e0 73 26 d5 f0 93 c7 6b 00 00 3a 06 a1 84 20 ca 49 1a a0 fa 9c 69 b9 f8 79 0f 00 0d 65 50 09 ea af s&....k..:.....I....i..y...eP...
0900 26 34 44 f5 39 93 6c f8 c9 e3 3f 00 e0 ff 46 48 09 5c 09 08 88 f6 15 00 4d 37 c0 55 04 80 ef a5 &4D.9.l...?...FH.\......M7.U....
0920 90 92 54 97 94 34 40 f5 b9 d2 b4 04 ae 24 00 82 68 14 52 5d 52 d2 00 b5 e7 4a db 26 38 35 01 00 ..T..4@......$..h.R]R....J.&85..
0940 a8 df 22 ac f6 4d 45 43 d4 9e 2b 6d ef 71 55 01 a0 bc 51 48 75 59 49 03 54 9e 2b 8d ef 6f 55 01 .."..MEC..+m.qU...QHuYI.T.+..oU.
0960 00 e8 4b c8 35 d4 5e 55 68 88 ca 73 a5 f1 bd ad 2e 00 b4 cd 91 d6 e0 4a 40 00 b4 ae 00 68 bd c7 ..K.5.^Uh
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
using Tango.Core.Helpers;
using Tango.Explorer;
using Tango.PPC.Common;
using Tango.PPC.Common.MachineUpdate;
using Tango.PPC.Common.Publish;
using Tango.PPC.Common.Web;
using Tango.PPC.UI.Dialogs;
using Tango.PPC.UI.Notifications.NotificationItems;
using Tango.PPC.UI.ViewsContracts;

namespace Tango.PPC.UI.ViewModels
{
    public class MachineUpdateViewVM : PPCViewModel<IMachineUpdateView>
    {
        public enum MachineUpdateView
        {
            UpdateCheckView,
            UpdateCheckErrorView,
            UpdateAvailableView,
            UpToDateView,
            UpdateProgressView,
            UpdateDbProgressView,
            UpdateCompletedView,
            UpdateFailedView,
            UpdateFromPackageView,
            UpdateFailedFromPackageView,
        }

        private MachineUpdateResult _update_result;
        private DbCompareResult _db_compare_result;
        private bool _isChecking;
        private CheckForUpdateResponse _checkUpdateResponse;
        private UpdateAvailableNotificationItem _updateNotificationItem;

        #region Properties

        /// <summary>
        /// Gets or sets the machine update manager.
        /// </summary>
        public IMachineUpdateManager MachineUpdateManager { get; set; }

        private String _latestVersion;
        /// <summary>
        /// Gets or sets the latest version.
        /// </summary>
        public String LatestVersion
        {
            get { return _latestVersion; }
            set { _latestVersion = value; RaisePropertyChangedAuto(); }
        }

        private bool _isDbUpdate;
        /// <summary>
        /// Gets or sets a value indicating whether this instance is database update.
        /// </summary>
        public bool IsDbUpdate
        {
            get { return _isDbUpdate; }
            set { _isDbUpdate = value; RaisePropertyChangedAuto(); }
        }

        private String _failedError;
        /// <summary>
        /// Gets or sets the setup failed error.
        /// </summary>
        public String FailedError
        {
            get { return _failedError; }
            set { _failedError = value; RaisePropertyChangedAuto(); }
        }

        #endregion

        #region Commands

        /// <summary>
        /// Gets or sets the complete command.
        /// </summary>
        public RelayCommand CompleteCommand { get; set; }

        /// <summary>
        /// Gets or sets the install command.
        /// </summary>
        public RelayCommand UpdateCommand { get; set; }

        /// <summary>
        /// Gets or sets the restart command.
        /// </summary>
        public RelayCommand RestartCommand { get; set; }

        /// <summary>
        /// Gets or sets the close command.
        /// </summary>
        public RelayCommand CloseCommand { get; set; }

        /// <summary>
        /// Gets or sets to application command.
        /// </summary>
        public RelayCommand ToApplicationCommand { get; set; }

        #endregion

        #region Constructors

        public MachineUpdateViewVM(IMachineUpdateManager machineUpdateManager)
        {
            MachineUpdateManager = machineUpdateManager;

            CompleteCommand = new RelayCommand(CompleteUpdate);
            UpdateCommand = new RelayCommand(Update);
            RestartCommand = new RelayCommand(CheckForUpdates);
            CloseCommand = new RelayCommand(() =>
            {
                NavigationManager.NavigateTo(Common.Navigation.NavigationView.HomeModule);
                NavigateTo(MachineUpdateView.UpdateCheckView);
            });

            ToApplicationCommand = new RelayCommand(() =>
            {
                NavigationManager.NavigateTo(Common.Navigation.NavigationView.HomeModule);
                NavigateTo(MachineUpdateView.UpdateCheckView);
            });

            machineUpdateManager.UpdateAvailable += MachineUpdateManager_UpdateAvailable;
        }

        #endregion

        #region Update

        public async void CheckForUpdates()
        {
            await NavigateTo(MachineUpdateView.UpdateCheckView);

            if (_isChecking) return;

            try
            {
                _isChecking = true;
                IsDbUpdate = false;

                await Task.Delay(2000);
                if (!await ConnectivityProvider.CheckInternetConnection())
                {
                    _isChecking = false;
                    await NavigateTo(MachineUpdateView.UpdateCheckErrorView);
                    return;
                }

                var response = await MachineUpdateManager.CheckForUpdate(MachineProvider.Machine.SerialNumber);
                _checkUpdateResponse = response;

                if (response.IsUpdateAvailable)
                {
                    LatestVersion = response.Version;
                    await NavigateTo(MachineUpdateView.UpdateAvailableView);
                }
                else if (response.IsDatabaseUpdateAvailable)
                {
                    IsDbUpdate = true;
                    _db_compare_result = new DbCompareResult()
                    {
                        RequiresUpdate = true,
                        UpdateDBResponse = response.UpdateDBResponse
                    };
                    await NavigateTo(MachineUpdateView.UpdateAvailableView);
                }
                else
                {
                    _db_compare_result = await MachineUpdateManager.UpdateDBCheck(MachineProvider.Machine.SerialNumber);

                    if (_db_compare_result.RequiresUpdate)
                    {
                        IsDbUpdate = true;
                        await NavigateTo(MachineUpdateView.UpdateAvailableView);
                    }
                    else
                    {
                        await NavigateTo(MachineUpdateView.UpToDateView);
                    }
                }
            }
            catch (Exception ex)
            {
                FailedError = ex.FlattenMessage();
                LogManager.Log(ex, "Error while trying to check for updates.");
                await NavigateTo(MachineUpdateView.UpdateFailedView);
            }
            finally
            {
                _isChecking = false;
            }
        }

        private async void Update()
        {
            if (!IsDbUpdate)
            {
                await NavigateTo(MachineUpdateView.UpdateProgressView);

                LogManager.Log("Starting machine update...");

                try
                {
                    _update_result = await MachineUpdateManager.Update(_checkUpdateResponse.SetupFirmware, _checkUpdateResponse.SetupFPGA);
                    LogManager.Log("Machine update completed.");
                    await NavigateTo(MachineUpdateView.UpdateCompletedView);
                }
                catch (Exception ex)
                {
                    FailedError = ex.FlattenMessage();
                    LogManager.Log(ex, "Machine update failed.");
                    await NavigateTo(MachineUpdateView.UpdateFailedView);
                }
            }
            else
            {
                await NavigateTo(MachineUpdateView.UpdateDbProgressView);
                LogManager.Log("Starting database update...");

                try
                {
                    await MachineUpdateManager.UpdateDB(_db_compare_result, MachineProvider.Machine.SerialNumber);
                    LogManager.Log("Database update completed.");
                    await NavigateTo(MachineUpdateView.UpdateCompletedView);
                }
                catch (Exception ex)
                {
                    FailedError = ex.FlattenMessage();
                    LogManager.Log(ex, "Database update failed.");
                    await NavigateTo(MachineUpdateView.UpdateFailedView);
                }
            }
        }

        #endregion

        #region Complete

        private void CompleteUpdate()
        {
            LogManager.Log("Completing machine update...");

            if (IsDbUpdate || !_update_result.RequiresBinariesUpdate)
            {
                LogManager.Log("Restarting Application...");
                ApplicationManager.Restart();
            }
            else
            {
                String updater_exe = Path.Combine(_update_result.UpdatePackagePath, "Tango.PPC.Updater.exe");
                ApplicationManager.UpdateApplication(updater_exe, PathHelper.GetStartupPath());
            }
        }

        #endregion

        #region Override Methods

        /// <summary>
        /// Called when the application has been started.
        /// </summary>
        public override void OnApplicationStarted()
        {

        }

        /// <summary>
        /// Navigates to the specified view.
        /// </summary>
        /// <param name="view">The view.</param>
        private Task NavigateTo(MachineUpdateView view)
        {
            return View.NavigateTo(view);
        }

        /// <summary>
        /// Called when the application is ready and all modules views are loaded.
        /// </summary>
        public override void OnApplicationReady()
        {
            base.OnApplicationReady();

            StorageProvider.RegisterFileHandler(ExplorerFileDefinition.Update.Extension, HandleSoftwareUpdatePackageLoaded);

            if (ApplicationManager.IsAfterUpdate)
            {
                RunPostUpdatePackages();
            }
            else
            {
                MachineUpdateManager.EnableAutoCheckForUpdates = true;
            }
        }

        /// <summary>
        /// Called when the navigation system has navigated to this VM view.
        /// </summary>
        public override void OnNavigatedTo()
        {
            base.OnNavigatedTo();

            if (_updateNotificationItem != null)
            {
                _updateNotificationItem.Close();
                _updateNotificationItem = null;
            }
        }

        #endregion

        #region Post Update Packages

        private async void RunPostUpdatePackages()
        {
            await Task.Delay(1000);

            LogManager.Log("Application was loaded after an update. Checking for required post-update packages...");

            bool required = false;

            try
            {
                required = await MachineUpdateManager.PostUpdatePackagesRequired();
            }
            catch (Exception ex)
            {
                LogManager.Log(ex, "Error checking for post-update packages.");
            }

            if (required)
            {
                LogManager.Log("Post-update packages found and needs to be installed. Navigating to machine update and running post-update packages...");
                await NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView);
                await NavigateTo(MachineUpdateView.UpdateProgressView);
                try
                {
                    var result = await MachineUpdateManager.RunPostUpdatePackages();

                    LogManager.Log("Post-update packages installed successfully.");

                    await Task.Delay(2000);

                    if (result.RestartRequired)
                    {
                        LogManager.Log("Restart required. Restarting...");
                        ApplicationManager.Restart();
                    }
                    else
                    {
                        await NavigationManager.NavigateTo(Common.Navigation.NavigationView.LayoutView);
                    }
                }
                catch (Exception ex)
                {
                    LogManager.Log(ex, "Error occurred while running post-update packages.");
                }
            }
            else
            {
                LogManager.Log("No post-update packages installation required.");
            }
        }

        #endregion

        #region Handle USB Update

        private async void HandleSoftwareUpdatePackageLoaded(ExplorerFileItem fileItem)
        {
            PublishInfo packageFile = null;

            try
            {
                packageFile = await MachineUpdateManager.GetUpdatePackageFileInfo(fileItem.Path);
            }
            catch (Exception ex)
            {
                LogManager.Log(ex, $"Error loading publish info from {fileItem.Path}.");
                await NotificationProvider.ShowError("An error occurred while trying to load the selected software update package. Please make sure the package is valid.");
                return;
            }

            UpdateFromFileViewVM vm = new UpdateFromFileViewVM();
            vm.Version = packageFile.ApplicationVersion;

            await NotificationProvider.ShowDialog(vm);

            if (vm.DialogResult)
            {
                await NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView);
                await NavigateTo(MachineUpdateView.UpdateProgressView);

                LogManager.Log("Starting machine update from package...");

                try
                {
                    _update_result = await MachineUpdateManager.UpdateFromTUP(fileItem.Path, MachineProvider.Machine.SetupFirmware, MachineProvider.Machine.SetupFpga);
                    LogManager.Log("Machine update from package completed.");
                    await NavigateTo(MachineUpdateView.UpdateCompletedView);
                }
                catch (Exception ex)
                {
                    LogManager.Log(ex, "Machine update from package failed.");
                    FailedError = ex.FlattenMessage();
                    await NavigateTo(MachineUpdateView.UpdateFailedFromPackageView);
                }
            }
        }

        #endregion

        #region Auto Check For Update

        private void MachineUpdateManager_UpdateAvailable(object sender, CheckForUpdateResponse e)
        {
            if (!IsVisible && _updateNotificationItem == null)
            {
                LogManager.Log($"New {(e.IsDatabaseUpdateAvailable ? "database updates" : "application version")} detected ({e.Version}). Pushing notification...");

                InvokeUI(() =>
                {
                    _updateNotificationItem = new UpdateAvailableNotificationItem();
                    _updateNotificationItem.Version = Version.Parse(e.Version).ToString(3);
                    _updateNotificationItem.IsDatabaseUpdate = e.IsDatabaseUpdateAvailable && !e.IsUpdateAvailable;
                    _updateNotificationItem.Pressed += (_, __) =>
                    {
                        _updateNotificationItem = null;

                        if (!IsVisible)
                        {
                            LogManager.Log("Update available notification pressed. Navigating to update view...");
                            NavigationManager.NavigateTo(Common.Navigation.NavigationView.MachineUpdateView);
                            CheckForUpdates();
                        }
                    };
                    _updateNotificationItem.Closed += (_, __) =>
                    {
                        _updateNotificationItem = null;
                    };
                    NotificationProvider.PushNotification(_updateNotificationItem);
                });
            }
        }

        #endregion
    }
}