BlueSky.SyntaxEditorWindow.CreateOuput C# (CSharp) Метод

CreateOuput() приватный Метод

private CreateOuput ( OutputWindow ow ) : void
ow OutputWindow
Результат void
        private void CreateOuput(OutputWindow ow)
        {
            if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Started creating output.", LogLevelEnum.Info);

            //////////////////// for fetching BSkyFormat object Queue and process each object //////////////////////
            int bskyformatobjectindex = 0;
            bool bskyQFetched = false;
            CommandRequest fetchQ = null;
            string sinkfileBSkyFormatMarker = "[1] \"BSkyFormatInternalSyncFileMarker\"";
            string sinkfileBSkyGraphicFormatMarker = "[1] \"BSkyGraphicsFormatInternalSyncFileMarker\""; //09Jun2015 
            //used to maintain the sequence of print in between BSkyFormats in case of block BSkyFormat
            bool isBlockCommand = false;
            //09Jun2015 used to maintain the sequence of print in between BSkyGraphicFormats in case of block commands
            bool isBlockGraphicCommand = false;

            //for deciding when to send output to output window in case of block BSkyFormat
            //for block BSkyFormat we wait and create all different UI elements first so as to maintain sequence and then send them to output
            //for non-block BSkFormat we send immediately after execution. No stacking up of UI elements ( AUXGrid, AUPara etc..)
            bool isBlock = false;
            ////////////////////////////////////////////////////////////////////////////////////////////////////////

            //if (true) return;
            CommandOutput lst = new CommandOutput(); ////one analysis////////
            CommandOutput grplst = new CommandOutput();//21Nov2013 Separate for Graphic. So Parent node name will be R-Graphic
            lst.IsFromSyntaxEditor = true;//lst belongs to Syn Editor
            if (saveoutput.IsChecked == true)//10Jan2013
                lst.SelectedForDump = true;
            XmlDocument xd = null;
            //string auparas = "";
            StringBuilder sbauparas = new StringBuilder("");
            //////////////// Read output ans message from file and create output then display /////
            //// read line by line  /////
            string sinkfilefullpathname = Path.Combine(System.IO.Path.GetTempPath().Replace("\\", "/"), confService.GetConfigValueForKey("tempsink"));//23nov2012
            // load default value if no path is set or invalid path is set
            if (sinkfilefullpathname.Trim().Length == 0 || !IsValidFullPathFilename(sinkfilefullpathname, true))
            {
                MessageBox.Show(this, "Key 'tempsink' not found in config file. Aborting...");
                return;
            }
            System.IO.StreamReader file = new System.IO.StreamReader(sinkfilefullpathname);// OpenSinkFile(@sinkfilefullpathname, "rt");
            object linetext = null; string line;
            bool insideblock = false;//20May2014
            bool readSinkFile = true;
            if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Started reading sink", LogLevelEnum.Info);
            //int imgcount = GraphicDeviceImageCounter;//couter that keeps track of how many images already got processed. Helps in creating a image filename.
            while ((line = file.ReadLine()) != null)//(readSinkFile)
            {
                {
                    linetext = line;
                }

                if (linetext == null || linetext.ToString().Equals("EOF"))
                {
                    break;
                }
                if (linetext != null && linetext.Equals("NULL") && lastcommandwasgraphic)//27May2015 to supress NULL for some listed graphic commands
                {
                    continue;
                }
                if (linetext.ToString().Trim().Contains(sinkfileBSkyFormatMarker))//Contains("[1] \"BSkyFormat\"")) //14Jun2014 if it is BSkyFormat in block (read from sink file)
                {
                    isBlockCommand = true;
                }
                else if (linetext.ToString().Trim().Contains(sinkfileBSkyGraphicFormatMarker))//Contains("[1] \"BSkyGraphicsFormat\"")) //09Jun2015 if it is BSkyGraphicsFormat in block (read from sink file)
                {
                    isBlockGraphicCommand = true;
                }
                else
                {
                    isBlockCommand = false;
                }
                //////// create XML doc /////////
                if (linetext != null)//06May2013 we need formatting so we print blank lines.. && linetext.ToString().Length > 0)
                {
                    /////// Trying to extract command from print //////
                    string commnd = linetext.ToString();
                    int opncurly = commnd.IndexOf("{");
                    int closcurly = commnd.IndexOf("}");
                    int lencommnd = closcurly - opncurly - 1;
                    if (opncurly != -1 && closcurly != -1)
                        commnd = commnd.Substring(opncurly + 1, lencommnd);//could be graphic or BSkyFormat in sink file.
                    if (false)//11Aug2015 fix for BSkyFormat not printed if inside R function. if (commnd.Contains("BSkyFormat("))//09Jun2015 || isGraphicCommand(_command)) // is BSKyFormat or isGraphic Command
                    {
                        SendToOutput(sbauparas.ToString(), ref lst, ow);//22May2014
                        sbauparas.Clear();
                    }
                    else if (isBlockCommand)//14Jun2014 for Block BSkyFormat.
                    {
                        if (sbauparas.Length > 0)
                        {
                            createAUPara(sbauparas.ToString(), lst);//Create & Add AUPara to lst 
                            sbauparas.Clear();
                        }
                    }
                    else
                    {
                        if (sbauparas.Length < 1)
                        {
                            sbauparas.Append(linetext.ToString());//First Line of AUPara. Without \n
                            if (sbauparas.ToString().Trim().IndexOf("BSkyFormat(") == 0)//21Nov2013
                                lst.NameOfAnalysis = "BSkyFormat-Command";
                        }
                        else
                        {
                            //auparas = auparas.Replace("<", "&lt;") + "\n" + linetext.ToString();//all lines separated by new line
                            sbauparas.Append("\n" + linetext.ToString());//all lines separated by new line
                        }
                    }



                    ////for graphics////   //09Jun2015 This whole 'if' may not be needed
                    if (false)
                    {
                        SendToOutput(commnd, ref lst, ow);
                        //////////// Here is new code///////20May2014
                        CommandRequest grpcmd = new CommandRequest();
                        CloseGraphicsDevice();
                        OpenGraphicsDevice();//05May2013
                        grpcmd.CommandSyntax = commnd;// linetext.ToString();
                        analytics.ExecuteR(grpcmd, false, false);
                        CloseGraphicsDevice();
                        insideblock = true;
                        //////////////////////////////////////////////////////////////////////////////////
                        //// add auparas first to lst to maintain order///
                        if (sbauparas.Length > 0)
                        {
                            createAUPara(sbauparas.ToString(), lst);//Create & Add AUPara to lst and empty dommid
                            sbauparas.Clear();
                        }
                        ////// now add image to lst ////
                        string synedtimg = Path.Combine(System.IO.Path.GetTempPath().Replace("\\", "/"), confService.GetConfigValueForKey("sinkimage"));//23nov2012
                        /////03May2013  Create zero padding string //// %03d means 000,  %04d means 0000
                        int percentindex = synedtimg.IndexOf("%");
                        int dindex = synedtimg.IndexOf("d", percentindex);
                        string percentstr = synedtimg.Substring(percentindex, (dindex - percentindex + 1));
                        string numbr = synedtimg.Substring(percentindex + 1, (dindex - percentindex - 1));
                        int zerocount = Convert.ToInt16(numbr);

                        string zeropadding = string.Empty;
                        for (int zeros = 1; zeros <= zerocount; zeros++)
                        {
                            zeropadding = zeropadding + "0";
                        }
                        int img_count = 0;//number of images to load in output
                        for (; ; )//03May2013 earlier there was no for loop for following code
                        {
                            img_count++;
                            string tempsynedtimg = synedtimg.Replace(percentstr, img_count.ToString(zeropadding));
                            // load default value if no path is set or invalid path is set
                            if (tempsynedtimg.Trim().Length == 0 || !IsValidFullPathFilename(tempsynedtimg, true))
                            {
                                break;
                            }
                            string source = @tempsynedtimg;
                            long imgsize = new FileInfo(synedtimg).Length;//find size of the imagefile
                            Image myImage = new Image();
                            ///////////RequestCachePolicy uriCachePolicy = new RequestCachePolicy(RequestCacheLevel.CacheOnly);
                            var bitmap = new BitmapImage();
                            try
                            {
                                var stream = File.OpenRead(source);
                                bitmap.BeginInit();
                                bitmap.CacheOption = BitmapCacheOption.OnLoad;
                                bitmap.StreamSource = stream;
                                bitmap.EndInit();
                                stream.Close();
                                stream.Dispose();
                                myImage.Source = bitmap;
                                bitmap.StreamSource.Close(); //trying to close stream 03Feb2014

                                if (isBlockCommand)
                                    createBSkyGraphic(myImage, lst); //20May2014 If graphic is inside block or loop
                                else
                                    createBSkyGraphic(myImage, grplst); //if graphic is outside block or loop
                                DeleteFileIfPossible(@tempsynedtimg);
                            }
                            catch (Exception ex)
                            {
                                logService.WriteToLogLevel("Error reading Image file " + source + "\n" + ex.Message, LogLevelEnum.Error);
                                MessageBox.Show(this, ex.Message);
                            }

                        }
                        if (img_count < 1) ////03May2013 if no images were added to output lst. then return.
                        {
                            return;
                        }

                    }
                    if (isBlockGraphicCommand)//for block graphics //09Jun2015
                    {
                        CloseGraphicsDevice();
                        insideblock = true;

                        ////// now add image to lst ////
                        string synedtimg = Path.Combine(System.IO.Path.GetTempPath().Replace("\\", "/"), confService.GetConfigValueForKey("sinkimage"));//23nov2012
                        /////03May2013  Create zero padding string //// %03d means 000,  %04d means 0000
                        int percentindex = synedtimg.IndexOf("%");
                        int dindex = synedtimg.IndexOf("d", percentindex);
                        string percentstr = synedtimg.Substring(percentindex, (dindex - percentindex + 1));
                        string numbr = synedtimg.Substring(percentindex + 1, (dindex - percentindex - 1));
                        int zerocount = Convert.ToInt16(numbr);

                        string zeropadding = string.Empty;
                        for (int zeros = 1; zeros <= zerocount; zeros++)
                        {
                            zeropadding = zeropadding + "0";
                        }

                        {
                            GraphicDeviceImageCounter++;//imgcount++;
                            string tempsynedtimg = synedtimg.Replace(percentstr, GraphicDeviceImageCounter.ToString(zeropadding));
                            // load default value if no path is set or invalid path is set
                            if (tempsynedtimg.Trim().Length == 0 || !IsValidFullPathFilename(tempsynedtimg, true))
                            {

                                isBlockGraphicCommand = false; //09Jun2015 reset, as we dont know what next command is. May or may not be graphic marker
                                // not needed if one graphic for one graphic marker imgcount--;
                                break;
                            }
                            string source = @tempsynedtimg;

                            Image myImage = new Image();

                            var bitmap = new BitmapImage();
                            try
                            {
                                var stream = File.OpenRead(source);
                                bitmap.BeginInit();
                                bitmap.CacheOption = BitmapCacheOption.OnLoad;
                                bitmap.StreamSource = stream;
                                bitmap.EndInit();
                                stream.Close();
                                stream.Dispose();
                                myImage.Source = bitmap;
                                bitmap.StreamSource.Close(); //trying to close stream 03Feb2014

                                if (isBlockGraphicCommand)
                                    createBSkyGraphic(myImage, lst); //20May2014 If graphic is inside block or loop
                                else
                                    createBSkyGraphic(myImage, grplst); //if graphic is outside block or loop
                                DeleteFileIfPossible(@tempsynedtimg);
                            }
                            catch (Exception ex)
                            {
                                logService.WriteToLogLevel("Error reading Image file " + source + "\n" + ex.Message, LogLevelEnum.Error);
                                MessageBox.Show(this, ex.Message);
                            }

                        }
                        if (GraphicDeviceImageCounter < 1) ////03May2013 if no images were added to output lst. then return.
                        {
                            sbauparas.Clear();//resetting
                            isBlockGraphicCommand = false;
                            return;
                        }
                        sbauparas.Clear();//resetting
                        isBlockGraphicCommand = false;
                    }
                    else if (isBlockCommand)// (linetext.ToString().Trim().Contains("[1] \"BSkyFormat\""))//21may2014
                    {
                        int bskyfrmtobjcount = 0;
                        if (!bskyQFetched)
                        {
                            fetchQ = new CommandRequest();
                            fetchQ.CommandSyntax = "BSkyQueue = BSkyGetHoldFormatObjList()";// Fetch Queue object
                            analytics.ExecuteR(fetchQ, false, false);

                            fetchQ.CommandSyntax = "is.null(BSkyQueue)";// check if Queue is null
                            object o = analytics.ExecuteR(fetchQ, true, false);//return false or true
                            if (o.ToString().ToLower().Equals("false"))//Queue has elements
                            {
                                bskyQFetched = true;
                            }
                        }
                        if (bskyQFetched)
                        {
                            bskyformatobjectindex++;
                            commnd = "BSkyFormat(BSkyQueue[[" + bskyformatobjectindex + "]])";

                            ExecuteSinkBSkyFormatCommand(commnd, ref bskyfrmtobjcount, lst);
                            lst = new CommandOutput();//"Child already has parent" error, fix
                            isBlock = true;
                        }
                        isBlockCommand = false;//09Jun2015 next command may or may not be BSkyFormat marker.
                    }
                }//if linetext!null
            }//while EOF sink file
            if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Finished reading sink", LogLevelEnum.Info);
            file.Close(); //CloseSinkFile();
            SendToOutput(sbauparas.ToString(), ref lst, ow, isBlock);//send output to window or disk file
            SendToOutput(null, ref grplst, ow, isBlock);//21Nov2013. separate node for graphic
            if (lst != null && lst.Count > 0 && isBlock) // Exceutes when there is block command
            {
                sessionlst.Add(lst);//15Nov2013
                lst = new CommandOutput();//after adding to session new object is allocated for futher output creation
            }

            if (AdvancedLogging) logService.WriteToLogLevel("ExtraLogs: Finished creating output.", LogLevelEnum.Info);
        }
SyntaxEditorWindow