Beispiel #1
0
        public async Task StartBroadcastHandlers()
        {
            if (Config.UpdateSelf == true)
            {
                var officialExe = CurrentExe.GetFullPath();

                if (await _verWatchr.NewVersionInstalled("FC-Updater"))
                {
                    CurrentExe.Shutdown();
                    Process.Start(officialExe);
                }

                await StartNewHandler <BinaryFileChangeBroadcastHandlerVM>(
                    CheckerRelease.FileKey, CurrentExe.GetFullPath());
            }

            await SetFirebaseHandler();

            foreach (var kv in Config.BinaryFiles)
            {
                await StartNewHandler <BinaryFileChangeBroadcastHandlerVM>(kv.Key, kv.Value);
            }

            foreach (var kv in Config.AppendOnlyDBs)
            {
                await StartNewHandler <AppendOnlyDbChangeBroadcastHandlerVM>(kv.Key, kv.Value);
            }

            foreach (var kv in Config.Executables)
            {
                await StartNewHandler <BinaryFileChangeBroadcastHandlerVM>(kv.Key, kv.Value);
            }
        }
 public MainWindowVmBase()
 {
     _exeVer     = CurrentExe.GetVersion();
     ExitCmd     = R2Command.Async(_ => ExitApp(false));
     RelaunchCmd = R2Command.Async(_ => ExitApp(true));
     AppendToCaption("...");
 }
Beispiel #3
0
        public async Task <bool> NewVersionInstalled(string fileId, string exeFilePath = null)
        {
            if (exeFilePath.IsBlank())
            {
                exeFilePath = CurrentExe.GetFullPath();
            }

            var loccSHA1 = exeFilePath.SHA1ForFile();
            await _agtState.SetState("Checking for updates", loccSHA1);

            var node = await _conn.GetNode <PublicFileInfo>(ROOTKEY, fileId, SUBKEY);

            if (node == null)
            {
                return(false);
            }
            if (loccSHA1 == node.SHA1)
            {
                await _agtState.SetRunningTask("Already running the latest version.");

                return(false);
            }

            await _agtState.SetRunningTask("Downloading newer version");

            var tmp = await DownloadToTemp(node);

            var bkp = CreateBackupPath(exeFilePath);

            File.Move(exeFilePath, bkp);
            File.Move(tmp, exeFilePath);

            return(true);
        }
Beispiel #4
0
 private static void ExitOnError(Action action, string context)
 {
     try { action.Invoke(); }
     catch (Exception ex)
     {
         OnError(ex, context);
         CurrentExe.Shutdown();
     }
 }
 public static void Show(string caption,
                         string message,
                         MessageBoxImage messageBoxImage   = MessageBoxImage.Information,
                         MessageBoxButton messageBoxButton = MessageBoxButton.OK)
 => new Thread(new ThreadStart(delegate
 {
     var longCap = $"   {caption}  [{DateTime.Now.ToShortTimeString()}]  -  {CurrentExe.GetShortName()} v.{CurrentExe.GetVersion()}";
     MessageBox.Show(message, longCap, messageBoxButton, messageBoxImage);
 }
                               )).Start();
 public ErrorReport(FirebaseCredentials usr, Exception exception, string context)
 {
     HumanName  = usr.HumanName;
     Roles      = usr.Roles;
     Email      = usr.Email;
     Context    = context;
     ExeVersion = CurrentExe.ShortNameAndVersion();
     HumanTime  = DateTime.Now.ToString("d-MMM-yyyy h:mm tt");
     Details    = exception.Info(true, true)
                  .Split(new[] { "\r\n", "\r", "\n" },
                         StringSplitOptions.None).ToList();
 }
 private static void SafeExecute(Action action, string context)
 {
     try
     {
         action.Invoke();
     }
     catch (Exception ex)
     {
         Alert.Show(ex, context);
         CurrentExe.Shutdown();
     }
 }
Beispiel #8
0
        public Task SetState(string taskDesc, string exeSHA1 = null, string exeVersion = null)
        {
            var exe = CurrentExe.GetFullPath();

            return(_conn.UpdateNode(new AgentState
            {
                RunningTask = taskDesc,
                LastActivity = DateTime.Now,
                ExeSHA1 = exeSHA1 ?? exe.SHA1ForFile(),
                ExeVersion = exeVersion ?? exe.GetVersion(),
            },
                                    NodePath));
        }
Beispiel #9
0
 private static void SafeExecute(Action <AppArguments> action, AppArguments args)
 {
     try
     {
         action.Invoke(args);
     }
     catch (Exception ex)
     {
         //Log.Error(ex.Info(true, true));
         Alert.Show(ex, "Initialize -> SafeExecute");
         CurrentExe.Shutdown();
     }
 }
        private static string ComposeSessionJson(IHubClientSettings cfg)
        {
            var sess = new HubClientSession
            {
                UserAgent    = cfg.UserAgent,
                AgentVersion = CurrentExe.GetVersion(),
                ComputerName = Environment.MachineName,
                //JsonConfig   = JsonConvert.SerializeObject(cfg),
                JsonConfig = cfg.ReadSavedFile(),
            };

            return(JsonConvert.SerializeObject(sess));
        }
Beispiel #11
0
        public static T ShowMainWindow <T>(this ILifetimeScope scope, bool hideOnWindowClose = false)
            where T : Window, new()
        {
            if (!scope.TryResolveOrAlert <MainWindowVmBase>(out MainWindowVmBase vm))
            {
                CurrentExe.Shutdown();
                return(null);
            }
            var win = new T();

            vm.HandleWindowEvents(win, scope, hideOnWindowClose);
            win.Show();
            return(win);
        }
Beispiel #12
0
        internal static List <UploaderSettings> LoadAll()
        {
            var dir     = CurrentExe.GetDirectory();
            var ext     = "*.cfg";
            var matches = Directory.EnumerateFiles(dir, ext);

            return(matches.Select(file =>
            {
                var cfg = JsonFile.Read <UploaderSettings>(file);
                cfg.Filename = Path.GetFileNameWithoutExtension(file);
                return cfg;
            }
                                  ).ToList());
        }
Beispiel #13
0
        private void _requestr_ResponseReceived(object sender, ApprovalEnvelope <string> envelope)
        {
            DoCancel();
            if (envelope.IsApproved != true)
            {
                return;
            }

            var jobs = MarketDayCloser.GetActions(_main.ColxnsDB, _main.AppArgs,
                                                  envelope.ResponderName);

            Parallel.Invoke(jobs.ToArray());

            CurrentExe.RelaunchApp();
        }
Beispiel #14
0
        private static async void Vm_OnWindowHidden(object sender, EventArgs e)
        {
            if (_isChecking)
            {
                return;
            }
            _isChecking = true;
            var oldExe = CurrentExe.GetFullPath();

            if (await _vChkr.NewVersionInstalled(_fileKey))
            {
                CurrentExe.Shutdown();
                Process.Start(oldExe);
            }
            _isChecking = false;
        }
        private async Task RequestAndWait()
        {
            BadMessage = "";
            StartBeingBusy(Default.RequestingMessage);

            if (await SendAndCheckTwice())
            {
                MessageBox.Show("Target received the request.");
                CurrentExe.Shutdown();
            }
            else
            {
                BadMessage = "Target did not respond to the request.";
            }

            StopBeingBusy();
        }
Beispiel #16
0
        private void GatherDetails()
        {
            _sessionKey = Guid.NewGuid().ToString();
            _userName   = Environment.UserName;
            _osName     = GetWindowsFriendlyName();

            _version      = CurrentExe.GetVersion();
            _application  = $"{ Assembly.GetEntryAssembly().GetName().Name} {_version}";
            _manufacturer = (from x in
                             new ManagementObjectSearcher("SELECT Manufacturer FROM Win32_ComputerSystem").Get()
                             .OfType <ManagementObject>()
                             select x.GetPropertyValue("Manufacturer")).FirstOrDefault()?.ToString() ?? "Unknown";
            _model = (from x in
                      new ManagementObjectSearcher("SELECT Model FROM Win32_ComputerSystem").Get()
                      .OfType <ManagementObject>()
                      select x.GetPropertyValue("Model")).FirstOrDefault()?.ToString() ?? "Unknown";
        }
Beispiel #17
0
        private async Task DownloadAndWriteToDisk()
        {
            Log("Downloading latest file from server ...");
            var b64 = await _client.GetContentB64(_fileKey);

            if (b64.IsBlank())
            {
                Log($"Something went wrong at {nameof(DownloadAndWriteToDisk)}!");
            }

            Log("Writing downloaded file to disk ...");
            DecodeB64ToDisk(b64);

            if (_fileKey == CheckerRelease.FileKey)
            {
                _listnr.Disconnect();
                CurrentExe.RelaunchApp();
            }
        }
Beispiel #18
0
        private async Task ExitApp(bool relaunchAfter)
        {
            try
            {
                OnWindowClose();
                await OnWindowCloseAsync();

                _scope?.Dispose();
                AppInsights.Flush();
                if (relaunchAfter)
                {
                    CurrentExe.RelaunchApp();
                }
                else
                {
                    CurrentExe.Shutdown();
                }
            }
            catch { }
        }
Beispiel #19
0
        public bool?Show <T>(bool hideWindow = false, bool showModal = false)
            where T : Window, new()
        {
            if (ShouldClose)
            {
                Alert.ShowModal("Exiting ...", WhyShouldClose);
                CurrentExe.Shutdown();
                return(false);
            }

            _win = new T();
            ApplyWindowTheme(_win);
            _win.DataContext = this;
            _win.MakeDraggable();
            _win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            _win.SnapsToDevicePixels   = true;
            _win.Loaded  += (s, e) => OnWindowLoaded();
            _win.Closing += async(s, e) => await OnWindowClosing(e);

            #if DEBUG
            _win.SetToCloseOnEscape();
            _win.WindowState = WindowState.Normal;
            #endif

            if (showModal)
            {
                return(_win.ShowDialog());
            }
            else
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                _win.ShowTemporarilyOnTop();
#pragma warning restore CS4014
                if (hideWindow)
                {
                    _win.Hide();
                }
                return(null);
            }
        }
Beispiel #20
0
 public MainWindowVmBase()
 {
     _exeVer = CurrentExe.GetVersion();
     ExitCmd = R2Command.Async(ExitApp);
     AppendToCaption("...");
 }
Beispiel #21
0
 private static string GetExeInfo()
 {
     try   { return($"{CurrentExe.GetShortName()} v.{CurrentExe.GetVersion()}"); }
     catch { return(""); }
 }
Beispiel #22
0
 public Task SetExeVersion()
 => _conn.UpdateNode(CurrentExe.GetVersion(),
                     NodePath,
                     nameof(AgentState.ExeVersion));
 protected void SetCaption(string message)
 {
     try   { Caption = $"   {CaptionPrefix}   (v{CurrentExe.GetShortVersion()})    {message}"; }
     catch { Caption = $"   {CaptionPrefix}   {message}"; }
 }
Beispiel #24
0
 protected override void OnInitialized(EventArgs e)
 {
     base.OnInitialized(e);
     this.Title += $"  {CurrentExe.GetVersion()}";
 }
 public void StartChecking()
 => _watchr.StartWatching(CurrentExe.GetFullPath());
 private string ExeDirIfBlank(string foldrPath)
 => foldrPath.IsBlank() ? CurrentExe.GetDirectory()
                            : foldrPath;