/// <summary> /// Opens the <see cref="AppStoreClient" /> instance so that it is ready to /// process requests. /// </summary> /// <param name="router">The <see cref="MsgRouter" /> to be associated with the client.</param> /// <param name="settings">The <see cref="AppStoreClientSettings" /> to be used.</param> /// <exception cref="InvalidOperationException">Thrown if the instance is already open.</exception> public void Open(MsgRouter router, AppStoreClientSettings settings) { if (this.syncLock != null) { throw new InvalidOperationException("AppStoreClient is already open."); } // Make sure that the LillTek.Datacenter message types have been // registered with the LillTek.Messaging subsystem. LillTek.Datacenter.Global.RegisterMsgTypes(); // Initialize using (TimedLock.Lock(router.SyncRoot)) { this.syncLock = router.SyncRoot; this.router = router; this.settings = settings; this.bkTimer = new GatedTimer(new System.Threading.TimerCallback(OnBkTimer), null, settings.BkTaskInterval); this.nextPurgeTime = SysTime.Now; if (settings.LocalCache) { this.packageFolder = new AppPackageFolder(syncLock, settings.PackageFolder); } else { this.packageFolder = null; } router.Dispatcher.AddTarget(this); } }
public void AppStore_EndToEnd() { // This test peforms a simple end-to-end test of the AppStore // service by starting the service, uploading, downloading // and then deleting a package file. Process svcProcess = null; LeafRouter router = null; AppStoreClient client = null; Assembly assembly; string packageFolder; string tempFolder; AppRef appRef; Helper.InitializeApp(Assembly.GetExecutingAssembly()); assembly = typeof(LillTek.Datacenter.AppStore.Program).Assembly; tempFolder = Helper.AddTrailingSlash(Path.GetTempPath()); packageFolder = Helper.GetAssemblyFolder(assembly) + "packages\\"; appRef = AppRef.Parse("appref://MyApps/App00.zip?version=1.2.0.0"); try { // Start a local router and open a client. Config.SetConfig(@" //----------------------------------------------------------------------------- // LeafRouter Settings §ion MsgRouter AppName = LillTek.Test Router AppDescription = Unit Test RouterEP = physical://DETACHED/$(LillTek.DC.DefHubName)/$(Guid) CloudEP = $(LillTek.DC.CloudEP) CloudAdapter = ANY UdpEP = ANY:0 TcpEP = ANY:0 TcpBacklog = 100 TcpDelay = off BkInterval = 1s MaxIdle = 5m EnableP2P = yes AdvertiseTime = 1m DefMsgTTL = 5 Encryption = PLAINTEXT Key = 00 SessionCacheTime = 2m SessionRetries = 3 SessionTimeout = 10s MaxLogicalAdvertiseEPs = 256 DeadRouterTTL = 2s // This maps the abstract AppStore endpoints to their default logical endpoints. AbstractMap[abstract://LillTek/DataCenter/AppStore] = logical://LillTek/DataCenter/AppStore AbstractMap[abstract://LillTek/DataCenter/AppStore/*] = logical://LillTek/DataCenter/AppStore/* &endsection ".Replace('&', '#')); router = new LeafRouter(); router.Start(); client = new AppStoreClient(); client.Open(router, AppStoreClientSettings.LoadConfig("AppStore.Client")); // Start the application store service svcProcess = Helper.StartProcess(assembly, "-mode:form -start"); Thread.Sleep(10000); // Give the process a chance to spin up // Upload a package to the server CreatePackage(tempFolder, appRef); client.UploadPackage(null, appRef, tempFolder + appRef.FileName); Thread.Sleep(1000); CompareFiles(tempFolder + appRef.FileName, packageFolder + appRef.FileName); // Download the package File.Delete(tempFolder + appRef.FileName); client.DownloadPackage(null, appRef, tempFolder + appRef.FileName); Thread.Sleep(1000); CompareFiles(tempFolder + appRef.FileName, packageFolder + appRef.FileName); // Delete the package client.RemoveRemotePackage(null, appRef); Thread.Sleep(1000); Assert.IsFalse(File.Exists(packageFolder + appRef.FileName)); } finally { if (svcProcess != null) { svcProcess.Kill(); svcProcess.Close(); } if (client != null) { client.Close(); } if (router != null) { router.Stop(); } if (File.Exists(tempFolder + appRef.FileName)) { File.Delete(tempFolder + appRef.FileName); } Config.SetConfig(null); } }