private void OpenGraphicsDevice(int imagewidth=0, int imageheight=0)//05May2013
{
DeleteOldGraphicFiles();//06May2013
/////// These lines moved here from isGrap block to entertain multi graph in one image ////// 02May2013
CommandRequest grpcmd = new CommandRequest();
string synedtimg = Path.Combine(System.IO.Path.GetTempPath().Replace("\\", "/"), confService.GetConfigValueForKey("sinkimage"));//23nov2012
// load default value if no path is set or invalid path is set
if (synedtimg.Trim().Length == 0 || !IsValidFullPathFilename(synedtimg, false))
{
MessageBox.Show(this, "Key 'sinkimage' not found in config file. Aborting...");
return;
}
//27May2015. if parameters are passed, parameter values will take over ( overrides the values set through 'Options'
if (imageheight > 0 && imagewidth > 0)
{
_currentGraphicWidth = imagewidth;
_currentGraphicHeight = imageheight;
}
else // use dimenstions set in 'Options' config. IF thats absent then use 580 as default.
{
_currentGraphicWidth = 580;
_currentGraphicHeight = 580;//defaults
//get image size from config
string imgwidth = confService.GetConfigValueForKey("imagewidth");//
string imgheight = confService.GetConfigValueForKey("imageheight");//
// load default value if no value is set or invalid value is set
if (imgwidth.Trim().Length != 0)
{
Int32.TryParse(imgwidth, out _currentGraphicWidth);
}
if (imgheight.Trim().Length != 0)
{
Int32.TryParse(imgheight, out _currentGraphicHeight);
}
}
grpcmd.CommandSyntax = "png(\"" + synedtimg + "\", width=" + _currentGraphicWidth + ",height=" + _currentGraphicHeight + ")";
analytics.ExecuteR(grpcmd, false, false);
//close graphic device to get the size of empty image and reopen it to keep it open for rest of the graphic processing.
CloseGraphicsDevice();
// Basically, make sure to find the exact first image name(with full path) that is created when graphic device is opened.
string tempimgname = synedtimg.Replace("%03d", "001");//this is hard code but should be good till you keep %03d. Otherwise write logic for substitution
if (File.Exists(tempimgname))
{
EMPTYIMAGESIZE = new FileInfo(tempimgname).Length;
}
EMPTYIMAGESIZE = EMPTYIMAGESIZE + 10;//increase it by some bytes just to make sure comparision does not fail.
//Now finally open graphic device to actually wait for graphic command to execute and capture it.
grpcmd.CommandSyntax = "png(\"" + synedtimg + "\", width=" + _currentGraphicWidth + ",height=" + _currentGraphicHeight + ")";
analytics.ExecuteR(grpcmd, false, false);
GraphicDeviceImageCounter = 0;//09Jun2015
}