/// <summary> /// Returns true if the service is available /// </summary> /// <returns></returns> public bool IsAvailable() { try { //var restClient = ApplicationContext.Current.GetRestClient("hdsi"); var networkInformationService = ApplicationContext.Current.GetService <INetworkInformationService>(); if (networkInformationService.IsNetworkAvailable) { if (this.m_lastPing < DateTime.Now.AddSeconds(60)) { var amiClient = new AmiServiceClient(ApplicationContext.Current.GetRestClient("ami")); amiClient.Client.Credentials = new NullCredentials(); amiClient.Client.Description.Endpoint[0].Timeout = 5000; this.m_lastPing = DateTime.Now; return(amiClient.Ping()); } return(true); } return(false); } catch (Exception e) { this.m_tracer.TraceInfo($"Unable to determine network state: {e}"); return(false); } }
/// <summary> /// Check for updates /// </summary> public void AutoUpdate() { // Check for updates if (ApplicationContext.Current.GetService <INetworkInformationService>().IsNetworkAvailable) { try { ApplicationContext.Current.SetProgress(Strings.locale_updateCheck, 0.5f); // Check for new applications var amiClient = new AmiServiceClient(ApplicationContext.Current.GetRestClient("ami")); amiClient.Client.Credentials = this.GetCredentials(amiClient.Client); amiClient.Client.Description.Endpoint[0].Timeout = 10000; if (amiClient.Ping()) { amiClient.Client.Description.Endpoint[0].Timeout = 30000; foreach (var i in amiClient.GetApplets().CollectionItem) { var installed = ApplicationContext.Current.GetService <IAppletManagerService>().GetApplet(i.AppletInfo.Id); if (installed == null || new Version(installed.Info.Version) < new Version(i.AppletInfo.Version) && ApplicationContext.Current.Configuration.GetSection <AppletConfigurationSection>().AutoUpdateApplets&& ApplicationContext.Current.Confirm(String.Format(Strings.locale_upgradeConfirm, i.AppletInfo.Names[0].Value, i.AppletInfo.Version, installed.Info.Version))) { this.Install(i.AppletInfo.Id); } } } } catch (Exception ex) { this.m_tracer.TraceError("Error checking for updates: {0}", ex.Message); } } ; this.m_checkedForUpdates = true; }
/// <summary> /// Returns true if the service is available /// </summary> /// <returns></returns> public bool IsAvailable() { try { //var restClient = ApplicationContext.Current.GetRestClient("imsi"); var networkInformationService = ApplicationContext.Current.GetService <INetworkInformationService>(); if (networkInformationService.IsNetworkAvailable) { var amiClient = new AmiServiceClient(ApplicationContext.Current.GetRestClient("ami")); amiClient.Client.Credentials = new NullCredentials(); amiClient.Client.Description.Endpoint[0].Timeout = 10000; return(amiClient.Ping()); } else { return(false); } } catch (Exception e) { this.m_tracer.TraceError($"Unable to determine network state: {e}"); return(false); } }
/// <summary> /// Update all apps /// </summary> public void UpdateAll() { try { ApplicationContext.Current.SetProgress(Strings.locale_updateCheck, 0.5f); // Check for new applications var amiClient = new AmiServiceClient(ApplicationContext.Current.GetRestClient("ami")); using (this.Authenticate(amiClient.Client, out Credentials credentials)) { amiClient.Client.Credentials = credentials; amiClient.Client.Description.Endpoint[0].Timeout = 30000; if (amiClient.Ping()) { var solution = this.m_configuration.AppletSolution; IEnumerable <AppletManifestInfo> infos = null; if (!string.IsNullOrEmpty(solution)) { infos = amiClient.Client.Get <AmiCollection>($"AppletSolution/{solution}/applet").CollectionItem.OfType <AppletManifestInfo>(); } else { infos = amiClient.GetApplets().CollectionItem.OfType <AppletManifestInfo>(); } amiClient.Client.Description.Endpoint[0].Timeout = 30000; List <AppletManifestInfo> toInstall = new List <AppletManifestInfo>(); foreach (var i in infos) { var installed = ApplicationContext.Current.GetService <IAppletManagerService>().GetApplet(i.AppletInfo.Id); if ((installed == null || new Version(installed.Info.Version) < new Version(i.AppletInfo.Version) && this.m_configuration.AutoUpdateApplets)) { toInstall.Add(i); } } if (toInstall.Count > 0 && ApplicationContext.Current.Confirm(string.Format(Strings.locale_upgradeConfirm, String.Join(",", toInstall.Select(o => o.AppletInfo.GetName("en", true)))))) { foreach (var i in toInstall) { this.Install(i.AppletInfo.Id); } } } } } catch (Exception ex) { if (!this.m_errorTickle) { ApplicationServiceContext.Current.GetService <ITickleService>().SendTickle(new Tickle(Guid.Empty, TickleType.Danger, string.Format(Strings.locale_updateCheckFailed, ex.GetType().Name))); this.m_errorTickle = true; } this.m_tracer.TraceError("Error checking for updates: {0}", ex.Message); } finally { ApplicationContext.Current.SetProgress(Strings.locale_idle, 1.0f); } }