Beispiel #1
0
        private async void App_OnStartup(object sender, StartupEventArgs e)
        {
            try
            {
                var info = await PanaceaRegistry.GetServerInformation();

                Server         = info.ManagementServer;
                HospitalServer = info.HospitalServer;
                if (string.IsNullOrEmpty(HospitalServer))
                {
                    Application.Current.Shutdown();
                    return;
                }
                new WebSocketCommunicator().Start();
            }
            catch
            {
                Application.Current.Shutdown();
                //exit
            }
        }
        private async void App_OnStartup(object sender, StartupEventArgs e)
        {
            Args = e.Args;
            string runtimePathFile = (await PanaceaRegistry.GetServerInformation(false)).RuntimePath;

            if (!string.IsNullOrEmpty(runtimePathFile))
            {
                try
                {
                    var runtimePath = runtimePathFile;
                    if (runtimePathFile.EndsWith("\\"))
                    {
                        runtimePath = Path.GetDirectoryName(runtimePathFile);
                    }

                    if (runtimePath + "\\Updater" != Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
                    {
                        Directory.CreateDirectory(runtimePath + "\\Updater");
                        await
                        Common.MoveDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                             runtimePath + "\\Updater", false, false);

                        ShutdownSafe();
                        Process.Start(runtimePath + "..\\Applications\\SystemSetup\\SystemSetup.exe", "/automatic");
                    }
                    else
                    {
                        ShowWindow();
                    }
                }
                catch
                {
                }
            }
            else
            {
                ShowWindow();
            }
        }
        internal override async Task <bool> OnPreUpdate(SafeDictionary <string, object> keys)
        {
            ReportProgress("Identifying...");

            int tries = 0;

            while (await TerminalIdentificationManager.GetIdentificationInfoAsync() == null && tries < 10)
            {
                tries++;
                await TerminalIdentificationManager.IdentifyAsync();

                if (await TerminalIdentificationManager.GetIdentificationInfoAsync() == null)
                {
                    await Task.Delay(30000);
                }
            }

            if (await TerminalIdentificationManager.GetIdentificationInfoAsync() == null)
            {
                App.ShutdownSafe();
                return(false);
            }


            keys["server"] = _server = (await PanaceaRegistry.GetServerInformation(false)).ManagementServer;
            if (string.IsNullOrEmpty(_server))
            {
                ReportProgress("Please add a terminal server in registry...");
                await Task.Delay(4000);

                App.ShutdownSafe();
                return(false);
            }
            //we can allow a failure to access TS if HS server is stored locally
            BrowserSettingsHelper.UpdateSettings(new[] { "WebBrowser.SubProcess.exe", "Panacea.exe" });
            ServerResponse <GetHospitalServersResponse> getHospitalServerResponse = null;

            try
            {
                getHospitalServerResponse =
                    await
                    ServerRequestHelper.GetObjectFromServerAsync <GetHospitalServersResponse>(_server,
                                                                                              "get_hospital_servers/");
            }
            catch
            {
                getHospitalServerResponse =
                    (await PanaceaRegistry.GetServerInformation(false)).ManagementServerResponse;
            }
            if (getHospitalServerResponse == null)
            {
                throw new Exception("Terminal Server unreachable and no information stored in registry...");
            }
            if (!getHospitalServerResponse.Success)
            {
                if (getHospitalServerResponse.Error != "self destruct")
                {
                    ReportProgress(getHospitalServerResponse.Error);
                    await Task.Delay(4000);

                    ProcessHelper.StartRegistrator(_server);
                    App.ShutdownSafe();
                    return(false);
                }
                var path = Path.GetFullPath(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\..\\");
                foreach (var directory in Directory.GetDirectories(path))
                {
                    try
                    {
                        if (!directory.EndsWith("\\Updater"))
                        {
                            Directory.Delete(directory, true);
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
                foreach (var directory in Directory.GetFiles(path))
                {
                    try
                    {
                        File.Delete(directory);
                    }
                    catch
                    {
                        // ignored
                    }
                }


                App.ShutdownSafe();
                return(false);
            }

            if (!await UpdateRegistry(getHospitalServerResponse))
            {
                return(false);
            }

            keys["hospitalserver"] = _hospitalServer = getHospitalServerResponse.Result.HospitalServers[0];
            if (string.IsNullOrEmpty(getHospitalServerResponse.Result.Crutch))
            {
                return(true);
            }

            _crutch = getHospitalServerResponse.Result.Crutch;

            ReportProgress("Waiting for traffic controller... Please wait...");

            var req =
                BuildHttpRequest(
                    new Uri(new Uri(_crutch), "api/" + Common.GetMacAddress() + "/requestAccessLock/")
                    .ToString());

            try
            {
                var resp = await req.GetHttpResponseAsync(120000);

                if (resp.StatusCode != HttpStatusCode.Conflict && resp.StatusCode != HttpStatusCode.OK)
                {
                    throw new WebException("Not conflict");
                }
            }
            catch (WebException)
            {
                ReportProgress("Traffic controller unreachable... Please wait...");
                await Task.Delay(new Random().Next(10000, 60000));

                App.Restart();
                return(false);
            }
            return(true);
        }