public void AppStoreMsgs_Ack() { EnhancedStream es = new EnhancedMemoryStream(); AppPackageInfo[] packages = new AppPackageInfo[] { new AppPackageInfo(AppRef.Parse("appref://myapps/app01.zip?version=1.2.3.4"), "app01.zip", "", new byte[] { 0, 1, 2 }, 55, DateTime.MinValue), new AppPackageInfo(AppRef.Parse("appref://myapps/app02.zip?version=5.6.7.8"), "app02.zip", "", new byte[] { 3, 4, 5 }, 66, DateTime.MinValue) }; AppStoreAck msgIn, msgOut; msgOut = new AppStoreAck(); msgOut.StoreEP = "logical://foo/bar"; msgOut.Packages = packages; Msg.Save(es, msgOut); es.Position = 0; msgIn = (AppStoreAck)Msg.Load(es); Assert.IsNotNull(msgIn); Assert.AreEqual("logical://foo/bar", msgIn.StoreEP); Assert.AreEqual(2, msgIn.Packages.Length); Assert.AreEqual(AppRef.Parse("appref://myapps/app01.zip?version=1.2.3.4"), msgIn.Packages[0].AppRef); CollectionAssert.AreEqual(new byte[] { 0, 1, 2 }, msgIn.Packages[0].MD5); Assert.AreEqual(55, msgIn.Packages[0].Size); Assert.AreEqual(AppRef.Parse("appref://myapps/app02.zip?version=5.6.7.8"), msgIn.Packages[1].AppRef); CollectionAssert.AreEqual(new byte[] { 3, 4, 5 }, msgIn.Packages[1].MD5); Assert.AreEqual(66, msgIn.Packages[1].Size); }
public void AppPackageInfo_Serialize() { AppRef appRef = new AppRef("appref://myapps/app.zip?version=1.2.3.4"); AppPackageInfo infoOut, infoIn; string s; infoIn = new AppPackageInfo(appRef, appRef.FileName, "test", new byte[] { 0, 1, 2, 3, 4 }, 77, DateTime.UtcNow); s = infoIn.ToString(); infoOut = AppPackageInfo.Parse(s); Assert.AreEqual(infoIn.AppRef, infoOut.AppRef); CollectionAssert.AreEqual(infoIn.MD5, infoOut.MD5); Assert.AreEqual(infoIn.FileName, infoOut.FileName); Assert.AreEqual(infoIn.Size, infoOut.Size); Assert.IsNull(infoOut.FullPath); Assert.AreEqual(DateTime.MinValue, infoOut.WriteTimeUtc); }
/// <summary> /// Returns information about the set of packages currently loaded into /// the folder. /// </summary> /// <returns>An array of <see cref="AppPackageInfo" /> instances.</returns> public AppPackageInfo[] GetPackages() { if (isDisposed) { throw new ObjectDisposedException(typeof(AppPackageFolder).Name); } using (TimedLock.Lock(syncLock)) { var arr = new AppPackageInfo[packages.Count]; int i; i = 0; foreach (AppPackageInfo info in packages.Values) { arr[i++] = info; } return(arr); } }
/// <summary> /// Completes the loading of an application package file. /// </summary> /// <param name="path">The fully qualified path returned by <see cref="BeginTransit" />.</param> /// <param name="commit"> /// Pass <c>true</c> to commit the package to the folder, <c>false</c> to /// delete the transit file without committing it. /// </param> public void EndTransit(string path, bool commit) { if (commit) { AppPackage package; AppPackageInfo info; int size; string destPath; using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read)) size = (int)fs.Length; using (TimedLock.Lock(syncLock)) { try { fileWatcher.EnableRaisingEvents = false; destPath = packageFolder + Path.GetFileName(path); if (File.Exists(destPath)) { File.Delete(destPath); } File.Move(path, destPath); package = null; try { package = AppPackage.Open(destPath); info = new AppPackageInfo(package.AppRef, Path.GetFileName(destPath), destPath, package.MD5, size, File.GetLastWriteTimeUtc(destPath)); } catch { if (package == null) { // The package must be bad so delete it. Helper.DeleteFile(destPath); } throw; } finally { if (package != null) { package.Close(); } } packages[info.AppRef] = info; } finally { fileWatcher.EnableRaisingEvents = true; } } RaiseChangeEvent(); } else { Helper.DeleteFile(path); } }