public void EndSection()
            {
                writer.WriteLine("  0\nENDSEC\n  0\nEOF");
                writer.Flush();
                writer.Close();



                //if (MainParameter.generating_dxf)
                //{
                //Main.main.Add_logo_time = new System.Diagnostics.Stopwatch();
                //Main.main.Add_logo_time.Start();
                //Main.main.LoadDXF(true, dxfFilePath);
                //}
                //Calculate the DXF File Size in KB
                double size = new System.IO.FileInfo(dxfFilePath).Length;

                MainParameter.TotalDXFFileSize += Math.Round(size / 1024.0, 2);
                //<><><>

                if (encrypt)
                {
                    Encrypt();
                }
            }
        public bool GenerateDefineFile()
        {
            //string headerFile = Application.CommonAppDataPath + "\\composition\\Header.txt";
            string headerFile = MainParameter.AppdataPath + MainParameter.AssemblyFileVersion + "\\composition\\Autodesk.txt";

            MainParameter.DefineFile = headerFile;
            FileStream           fs     = File.Open(headerFile, FileMode.Create);
            EnglishStreamWriter2 writer = new EnglishStreamWriter2(fs);

            try
            {
                writer.WriteLine("This file generate by XYZSDK for Autodesk.");
                writer.Flush();
                writer.Close();
                return(true);
            }
            catch (Exception ex)
            {
                SVGTo3WL.logFile.writer.WriteLine("3WL Data, Error encountered: GenerateDefineFile.");
                SVGTo3WL.logFile.writer.WriteLine("3WL Data exception: {0}", ex.ToString());
                SVGTo3WL.logFile.writer.Flush();
                Console.WriteLine("3WL Data, Error encountered: GenerateDefineFile");
                Console.WriteLine("3WL Data exception: {0}", ex.ToString());
                gCode.Release();
                return(false);
            }
        }
        public bool GenerateHeaderFile()
        {
            //string headerFile = Application.CommonAppDataPath + "\\composition\\Header.txt";
            string               headerFile = MainParameter.AppdataPath + MainParameter.AssemblyFileVersion + "\\composition\\Header.txt";
            FileStream           fs         = File.Open(headerFile, FileMode.Create);
            EnglishStreamWriter2 writer     = new EnglishStreamWriter2(fs);

            try
            {
                writer.WriteLine("; total dxf file size (kb): " + Math.Round(MainParameter.TotalDXFFileSize, 2));
                writer.Write("; total Estimated Marking time (secs): " + Math.Round(MainParameter.totalEstimatedTime, 4));
                writer.Flush();
                writer.Close();
                return(true);
            }
            catch (Exception ex)
            {
                SVGTo3WL.logFile.writer.WriteLine("3WL Data, Error encountered: GenerateHeaderFile.");
                SVGTo3WL.logFile.writer.WriteLine("3WL Data exception: {0}", ex.ToString());
                SVGTo3WL.logFile.writer.Flush();
                Console.WriteLine("3WL Data, Error encountered: GenerateHeaderFile");
                Console.WriteLine("3WL Data exception: {0}", ex.ToString());
                gCode.Release();
                return(false);
            }
        }
        public bool EditGcodeContent()
        {
            string temp_gcodePath = MainParameter.AppdataPath + MainParameter.AssemblyFileVersion + "\\composition\\tempgcode.gcode";
            //string temp_gcodePath = Application.CommonAppDataPath + "\\composition\\tempgcode.gcode";
            string               content = "";
            string               checker = "non-sintered powder";
            FileStream           fs      = File.Open(temp_gcodePath, FileMode.Create);
            EnglishStreamWriter2 writer  = new EnglishStreamWriter2(fs);

            if (!File.Exists(gcodePath))
            {
                return(false);
            }
            try
            {
                using (StreamReader streamReader = new StreamReader(gcodePath /*, Encoding.UTF8*/))
                {
                    //var est_factor = Main.main.threedview.ui.ProfileSettings_UI.EstimatedTime_Factor;
                    //asd
                    double est_time = 0;// Main.main.totalEstimatedTime;
                    //if (!Main.main.IsComputeMarkingTime)
                    //    est_time = 0.00;
                    while (!streamReader.EndOfStream)
                    {
                        content = streamReader.ReadLine();
                        writer.Write(content + "\n");
                        if (content.Contains(checker))
                        {
                            writer.Write("; total dxf file size (kb): " + Convert.ToInt64(MainParameter.TotalDXFFileSize) + "\n");
                            writer.Write("; total Estimated Marking time (ms): " + est_time.ToString("0.00") + "\n");
                            //writer.WriteLine("; total dxf file size (kb): " + Math.Round(Main.main.TotalDXFFileSize, 2) + "\n");
                            //writer.Write("; total Estimated Marking time (ms): " + est_time.ToString("0.00") + "\n");
                        }
                    }
                    writer.Flush();
                    writer.Close();
                }

                File.Delete(gcodePath);
                File.Move(temp_gcodePath, gcodePath);

                return(true);
            }
            catch (Exception ex)
            {
                SVGTo3WL.logFile.writer.WriteLine("3WL Data, Error encountered: EditGcodeContent.");
                SVGTo3WL.logFile.writer.WriteLine("3WL Data exception: {0}", ex.ToString());
                SVGTo3WL.logFile.writer.Flush();
                Console.WriteLine("3WL Data, Error encountered: EditGcodeContent");
                Console.WriteLine("3WL Data exception: {0}", ex.ToString());
                gCode.Release();
                return(false);
            }
        }
            public void Output(string path)
            {
                average = (int)Math.Ceiling(layerPowderAmounts.Average(a => a));
                sum     = layerPowderAmounts.Sum(b => b);
                FileStream fs = File.Open(path, FileMode.Create);

                using (EnglishStreamWriter2 writer = new EnglishStreamWriter2(fs))
                {
                    writer.WriteLine(String.Format("Sum-{0}", sum));
                    for (int i = 0; i < layerPowderAmounts.Count; i++)
                    {
                        writer.WriteLine(String.Format("Layer{0}-{1}", i, layerPowderAmounts[i]));
                    }
                    writer.Flush();
                }
            }
 public void Release()
 {
     writer.Flush();
     writer.Dispose();
 }
        public bool GenerateRecordFile()
        {
            try
            {
                //Main.main.LogMessage("Main", "Generating Record file ....." , "");
                //string recordFilePath = Application.CommonAppDataPath + "\\composition\\RecordFile.txt";
                string recordFilePath = MainParameter.AppdataPath + MainParameter.AssemblyFileVersion + "\\composition\\RecordFile.txt";
                //StringBuilder shortPath = new StringBuilder(255);
                //Main.GetShortPathName(recordFilePath, shortPath, shortPath.Capacity);
                //recordFilePath = shortPath.ToString();
                FileStream           fs     = File.Open(recordFilePath, FileMode.Create);
                EnglishStreamWriter2 writer = new EnglishStreamWriter2(fs);
                //Main.main.threedview.ui.ProfileSettings_UI.Dispatcher.Invoke(new Action(() =>{
                //writer.WriteLine("Infill Scan Speed: "+Main.main.threedview.ui.ProfileSettings_UI.txt_InfillScanningSpeed.Text);
                //writer.WriteLine("Contour Scan Speed: " + Main.main.threedview.ui.ProfileSettings_UI.txt_ContourScanningSpeed.Text);
                //writer.WriteLine("Beam Offset: " + Main.main.threedview.ui.ProfileSettings_UI.txt_InfillContourOffset.Text);
                //writer.WriteLine("Fill Round Pitch: " + Main.main.threedview.ui.ProfileSettings_UI.txt_InfillBorderOffset.Text);
                //writer.WriteLine("Border: 0.12");
                //writer.WriteLine("Step Angle: 90");
                //writer.WriteLine("Offset Angle: 180");
                //writer.WriteLine("Infill Pitch: " + Main.main.threedview.ui.ProfileSettings_UI.txt_InfillSinterPitch.Text);
                //writer.WriteLine("Start Angle: " + Main.main.threedview.ui.ProfileSettings_UI.txt_StartAngle.Text);
                //writer.WriteLine("Powder Density:" + Main.main.threedview.ui.ProfileSettings_UI.Powder_Density.Text);
                //writer.WriteLine("Sintered Density:" + Main.main.threedview.ui.ProfileSettings_UI.Sintered_Density.Text);
                //writer.WriteLine("Laser Sintering Twice: " + Main.main.threedview.ui.ProfileSettings_UI.SelectedProfileSettings.SinteringTwice.ToString());
                ////<timmy><9-15-2020><add base/cover in RecordFile.txt>
                //writer.WriteLine("Base Layers: " + Main.main.threedview.ui.ProfileSettings_UI.SelectedProfileSettings.baselayercyclecount.ToString());
                //writer.WriteLine("Cover Layers: " + Main.main.threedview.ui.ProfileSettings_UI.SelectedProfileSettings.coverlayer.ToString());
                ////<><><>
                //}));

                writer.WriteLine("Infill Scan Speed: 0");
                writer.WriteLine("Contour Scan Speed: 0");
                writer.WriteLine("Beam Offset: 0");
                writer.WriteLine("Fill Round Pitch: 0");
                writer.WriteLine("Border: 0");
                writer.WriteLine("Step Angle: 0");
                writer.WriteLine("Offset Angle: 0");
                writer.WriteLine("Infill Pitch: 0");
                writer.WriteLine("Start Angle: 0");
                writer.WriteLine("Powder Density:0");
                writer.WriteLine("Sintered Density:0");
                writer.WriteLine("Laser Sintering Twice: 0");
                //<timmy><9-15-2020><add base/cover in RecordFile.txt>
                writer.WriteLine("Base Layers: 0");
                writer.WriteLine("Cover Layers: 0");
                //<><><>



                writer.Flush();
                writer.Dispose();

                //Main.main.LogMessage("Main", "Success: Record File was Generated.", "");
                return(true);
            }
            catch (Exception ex)
            {
                //Main.main.LogMessage("Main", "Failed: Generating record file.", "");
                SVGTo3WL.logFile.writer.WriteLine("3WL Data, Error encountered: GenerateRecordFile.");
                SVGTo3WL.logFile.writer.WriteLine("3WL Data exception: {0}", ex.ToString());
                SVGTo3WL.logFile.writer.Flush();
                Console.WriteLine("3WL Data, Error encountered: GenerateRecordFile");
                Console.WriteLine("3WL Data exception: {0}", ex.ToString());
                gCode.Release();
                return(false);
            }
        }