public void AddPackage() { var ret = new SetPackageItemViewModel() { ItemSource = PackageItems, Parent = this }; PackageItems.Add(ret); SelectedPackage = ret; RaisePropertyChanged("SelectedPackage"); }
protected override void UnpackResponse() { base.UnpackResponse(); // Create the streams we will be reading from. var responseStream = new MemoryStream(m_responsePayload); var responseReader = new BinaryReader(responseStream, Encoding.Unicode); // Check the response length. if (responseStream.Length < MinResponseMessageLength) { throw new MessageWrongSizeException("Get Package Item"); } // Try to unpack the data. try { // Seek past return code. responseReader.BaseStream.Seek(sizeof(int), SeekOrigin.Begin); // Get the count of Packages. var packageItemCount = responseReader.ReadUInt16(); // Clear the Package Item array. PackageItems.Clear(); // Get all the Package Items for (ushort x = 0; x < packageItemCount; x++) { var packageItem = new PackageItem { PackageId = responseReader.ReadInt32(), ChargeDeviceFee = responseReader.ReadBoolean() }; // Package Name var stringLen = responseReader.ReadUInt16(); packageItem.PackageName = new string(responseReader.ReadChars(stringLen)); // Receipt Text stringLen = responseReader.ReadUInt16(); packageItem.ReceiptText = new string(responseReader.ReadChars(stringLen)); // Package Price stringLen = responseReader.ReadUInt16(); packageItem.PackagePrice = new string(responseReader.ReadChars(stringLen)); //read override packageItem.OverrideValidation = responseReader.ReadBoolean(); //read override quantity packageItem.ValidationQuantity = responseReader.ReadInt32(); //read if requires validation to purchase packageItem.RequiresValidation = responseReader.ReadBoolean(); PackageItems.Add(packageItem); } } catch (EndOfStreamException e) { throw new MessageWrongSizeException("Get Package Item", e); } catch (Exception e) { throw new ServerException("Get Package Item", e); } // Close the streams. responseReader.Close(); }
public void RefreshAllPackages() { PackageItems.Clear(); var repo = PackageRepositoryFactory.Default.CreateRepository(PackagesDir); var pkgList = repo.GetPackages(); var pkgSet = new SortedSet <string>(); foreach (var pkg in pkgList) { //通过set去重 pkgSet.Add(pkg.Id); } Dictionary <string, IPackage> installedPkgDict = new Dictionary <string, IPackage>(); var packageManager = new PackageManager(repo, InstalledPackagesDir); foreach (IPackage pkg in packageManager.LocalRepository.GetPackages()) { installedPkgDict[pkg.Id] = pkg; } foreach (var name in pkgSet) { var item = new PackageItem(); item.Name = name; var version = repo.FindPackagesById(name).Max(p => p.Version); item.Version = version.ToString(); var pkgNameList = repo.FindPackagesById(name); foreach (var i in pkgNameList) { item.VersionList.Add(i.Version.ToString()); } bool isNeedUpdate = false; if (installedPkgDict.ContainsKey(item.Name)) { var installedVer = installedPkgDict[item.Name].Version; if (version > installedVer) { isNeedUpdate = true; } } else { isNeedUpdate = true; } item.IsNeedUpdate = isNeedUpdate; var pkg = repo.FindPackage(name, version); item.Package = pkg; var publishedTime = pkg.Published.Value.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"); string toolTip = ResxIF.GetString("PackageToolTip"); //"名称:{0}\r\n版本:{1}\r\n发布说明:{2}\r\n项目描述:{3}\r\n发布时间:{4}" item.ToolTip = string.Format(toolTip, item.Name, item.Version, pkg.ReleaseNotes, pkg.Description, (publishedTime == null ? "未知" : publishedTime)); if (IsWorkflowRunning && item.Name == WorkflowRunningName) { item.IsRunning = true;//如果当前该包工程已经在运行,则要设置IsRunning } PackageItems.Add(item); } doSearch(); }