private void RenderPreview(ISymbolInstance symInst, ListViewItem item) { string previewKey = null; if (!string.IsNullOrEmpty(item.ImageKey)) { previewKey = item.ImageKey; } else { previewKey = Guid.NewGuid().ToString(); } if (imgPreviews.Images.ContainsKey(previewKey)) { Image img = imgPreviews.Images[previewKey]; imgPreviews.Images.RemoveByKey(previewKey); img.Dispose(); } var conn = _edSvc.CurrentConnection; ISymbolDefinitionBase previewSymbol = null; string resId = "Session:" + conn.SessionID + "//" + Guid.NewGuid().ToString() + ".SymbolDefinition"; switch (symInst.Reference.Type) { case SymbolInstanceType.Inline: previewSymbol = (ISymbolDefinitionBase)((ISymbolInstanceReferenceInline)symInst.Reference).SymbolDefinition.Clone(); //Inline symbol definitions will have schema and version stripped. We need to add them back previewSymbol.SetSchemaAttributes(); previewSymbol.ResourceID = resId; using (var stream = ApplyOverrides(previewSymbol, symInst.ParameterOverrides)) { conn.ResourceService.SetResourceXmlData(resId, stream); } previewSymbol = (ISymbolDefinitionBase)conn.ResourceService.GetResource(resId); break; case SymbolInstanceType.Reference: previewSymbol = (ISymbolDefinitionBase)conn.ResourceService.GetResource(((ISymbolInstanceReferenceLibrary)symInst.Reference).ResourceId); previewSymbol = (ISymbolDefinitionBase)previewSymbol.Clone(); previewSymbol.ResourceID = resId; using (var stream = ApplyOverrides(previewSymbol, symInst.ParameterOverrides)) { conn.ResourceService.SetResourceXmlData(resId, stream); } previewSymbol = (ISymbolDefinitionBase)conn.ResourceService.GetResource(resId); break; } var res = DefaultResourcePreviewer.GenerateSymbolDefinitionPreview(conn, previewSymbol, imgPreviews.ImageSize.Width, imgPreviews.ImageSize.Height); imgPreviews.Images.Add(previewKey, res.ImagePreview); item.ImageKey = previewKey; }
private void RenderPreview(ResourceListResourceDocument doc) { BusyWaitDialog.Run(Strings.PrgPreparingResourcePreview, () => { var res = _conn.ResourceService.GetResource(doc.ResourceId); return(DefaultResourcePreviewer.GenerateSymbolDefinitionPreview(_conn, res, picPreview.Width, picPreview.Height)); }, (res, ex) => { if (ex != null) { ErrorDialog.Show(ex); } else { picPreview.Image = ((DefaultResourcePreviewer.ImagePreviewResult)res).ImagePreview; } }); }