public void ReloadFromServer(Action onSuccess, Action <string> onFail) { MediaDownloadManager.Reset(); m_completeSuccessHandler = onSuccess; m_completeFailHandler = onFail; foreach (var call in m_preloadActions.ToArray()) { call(); } SetDownloadState(WebServicesDownloadState.Resolving); Action configLoadComplete = () => { ThreadHelper.Instance.CallOnMainThread(() => { foreach (var obj in ScriptObjectDirectory.Instance.AllObjects) { if (obj is IMediaItemProvider) { MediaDownloadManager.AddMediaItemProvider((IMediaItemProvider)obj); } } if (m_catalogLoadActions.Count > 0) { BatchProcessor iter = new BatchProcessor(m_catalogLoadActions.Count, DownloadMedia); foreach (var call in m_catalogLoadActions) { call(() => { iter++; }); } } else { DownloadMedia(); } }); }; if (!string.IsNullOrEmpty(ConfigName)) { var cfgManager = StorageManager.GetAppStorageManager().GetManager("downloads", SpaceName, "config"); if (InternetReachability == NetworkReachability.NotReachable) { bool result = false; if (!RequireNetworkConnection) { result = ProjectConfigService.Instance.LoadFromCache(cfgManager, ConfigName, ShouldUseDevCatalogs); } if (result) { configLoadComplete(); } else { SetDownloadError(ServiceCallLoadStatus.ServiceCallFail); } } else { ProjectConfigService.Instance.Load(cfgManager, MotiveUrl, SpaceName, ConfigName, ShouldUseDevCatalogs, (status) => { if (status == ServiceCallLoadStatus.Success) { configLoadComplete(); } else { SetDownloadError(status); } }); } } else { configLoadComplete(); } }
public void LoadCatalog <T>(string spaceName, string catalogName, Action <Catalog <T> > onLoad, bool?useDevCatalogs = null) { if (string.IsNullOrEmpty(catalogName)) { return; } var fileName = StorageManager.GetCatalogFileName(spaceName, catalogName + ".json"); // If the caller has specified a preference for using dev catalogs, use that, // otherwise defer to the setting here | the debug setting bool useDev = useDevCatalogs ?? (ShouldUseDevCatalogs || SettingsHelper.IsDebugSet("Debug_UseDevCatalogs")); if (InternetReachability == NetworkReachability.NotReachable) { if (RequireNetworkConnection) { SetDownloadError(WebServicesDownloadErrorCode.NoNetworkConnection); } else { var catalog = CatalogLoader.LoadCatalogFromCache <T>(fileName); if (catalog == null) { if (m_completeFailHandler != null) { m_completeFailHandler("Please connect to the network and re-try"); } } else { MediaDownloadManager.AddMediaItemProvider(catalog); onLoad(catalog); } } } else { CatalogLoader.LoadCatalog <T>(fileName, spaceName, catalogName, useDev, (status, catalog) => { if (status == ServiceCallLoadStatus.Success) { m_logger.Debug("Loaded catalog {0} with {1} item(s)", catalogName, catalog.Items == null ? 0 : catalog.Items.Length); // This callback happens outside of the Unity thread, // use the Thread Helper to move into the Unity context ThreadHelper.Instance.CallOnMainThread(() => { MediaDownloadManager.AddMediaItemProvider(catalog); onLoad(catalog); // Since we're in the Unity thread here we don't need // to protect this in a critical section }); } else { m_logger.Error("Error loading catalog {0}", catalogName); SetDownloadError(status); if (m_completeFailHandler != null) { ThreadHelper.Instance.CallOnMainThread(() => { m_completeFailHandler("Error loading catalog " + catalogName); }); } } }); } }