CreateSubgraphImagesInternal
(
CreateSubgraphImagesAsyncArgs oCreateSubgraphImagesAsyncArgs,
BackgroundWorker oBackgroundWorker,
DoWorkEventArgs oDoWorkEventArgs
)
{
Debug.Assert(oCreateSubgraphImagesAsyncArgs != null);
Debug.Assert(oBackgroundWorker != null);
Debug.Assert(oDoWorkEventArgs != null);
AssertValid();
// Create an object to keep track of the thumbnail images this method
// creates and stores in a temporary folder.
TemporaryImages oThumbnailImages = new TemporaryImages();
oThumbnailImages.ImageSizePx =
oCreateSubgraphImagesAsyncArgs.ThumbnailSizePx;
oDoWorkEventArgs.Result = oThumbnailImages;
ICollection<IVertex> oVertices;
if (oCreateSubgraphImagesAsyncArgs.SelectedVerticesOnly)
{
oVertices = oCreateSubgraphImagesAsyncArgs.SelectedVertices;
}
else
{
oVertices = oCreateSubgraphImagesAsyncArgs.Graph.Vertices;
}
Int32 iSubgraphsCreated = 0;
Boolean bSaveToFolder = oCreateSubgraphImagesAsyncArgs.SaveToFolder;
Boolean bCreateThumbnails =
oCreateSubgraphImagesAsyncArgs.CreateThumbnails;
if (bSaveToFolder || bCreateThumbnails)
{
foreach (IVertex oVertex in oVertices)
{
if (oBackgroundWorker.CancellationPending)
{
if (oThumbnailImages.Folder != null)
{
// Delete the entire temporary folder.
Directory.Delete(oThumbnailImages.Folder, true);
oThumbnailImages.Folder = null;
}
oDoWorkEventArgs.Cancel = true;
break;
}
String sVertexName = oVertex.Name;
oBackgroundWorker.ReportProgress(0,
String.Format(
"Creating subgraph image for \"{0}\"."
,
sVertexName
) );
// Create a subgraph for the vertex.
IGraph oSubgraph = CreateSubgraph(oVertex,
oCreateSubgraphImagesAsyncArgs);
// Create and save images for the subgraph.
CreateAndSaveSubgraphImages(oSubgraph, sVertexName,
oCreateSubgraphImagesAsyncArgs, oThumbnailImages);
iSubgraphsCreated++;
}
}
oBackgroundWorker.ReportProgress(0,
String.Format(
"Done. Created {0} subgraph {1}."
,
iSubgraphsCreated.ToString(ExcelTemplateForm.Int32Format),
StringUtil.MakePlural("image", iSubgraphsCreated)
) );
}