Exemplo n.º 1
0
        public static cConversionResult ConvertFile(string drawingName, string polygonID)
        {
            cConversionResult ConversionResult = new cConversionResult();
            string            URL = null;



            try
            {
                URL = string.Format(ExportSettings.ApertureWebServiceUrl111, drawingName, polygonID);

                // string RemoteURL = "https://www9.cor-asp.ch/ApWebServices/ApDrawingPDFs.aspx?p=SwisscomTest_Portal&d={0}&L=Z_Export&S=Z_Export";
                // string LocalURL = "http://vm-wincasa/ApWebServices/ApDrawingPDFs.aspx?p=Swisscom_Portal&d={0}&L=Z_Export&S=Z_Export";

                //baReturnValue = DownloadPdf("https://www9.cor-asp.ch/ApWebServices/ApDrawingPDFs.aspx?p=SwisscomTest_Portal&d=1002_GB01_OG01_0000&L=Z_Export");
                //baReturnValue = DownloadPdf("http://vm-wincasa/ApWebServices/ApDrawingPDFs.aspx?p=Swisscom_Portal&d=1002_GB01_OG01_0000&L=Z_Export");
                //baReturnValue = DownloadPdf("http://vm-wincasa/ApWebServices/ApDrawingPDFs.aspx?p=Swisscom_Portal&d=1010_GB01_UG02_0000&L=Z_Export");
                // http://vm-wincasa/ApWebServices/ApDrawingPDFs.aspx?p=Swisscom_Portal&d=1010_GB01_UG02_0000&L=Z_Export&S=Z_Export

                ConversionResult.PDF = DownloadPdf(URL);
            }
            catch (System.Net.WebException we)
            {
                System.Console.WriteLine(we.Message);
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }


#if WITH_ASPOSE
            string temporaryOutFileName = System.IO.Path.GetTempFileName();

            using (System.IO.Stream ms = new System.IO.MemoryStream(ConversionResult.PDF))
            {
                // using (Aspose.Pdf.Document doc = new Aspose.Pdf.Document(@"dwg17.pdf"))
                using (Aspose.Pdf.Document doc = new Aspose.Pdf.Document(ms))
                {
                    Aspose.Pdf.SvgSaveOptions saveOptions = new Aspose.Pdf.SvgSaveOptions();

                    // do not compress SVG image to Zip archive
                    saveOptions.CompressOutputToZipArchive = false;

                    doc.Save(temporaryOutFileName, saveOptions);
                } // End Using doc

                ms.Close();
            } // End Using ms

            ConversionResult.SVG = RemoveEvalString(temporaryOutFileName, URL);
            if (System.IO.File.Exists(temporaryOutFileName))
            {
                System.IO.File.Delete(temporaryOutFileName);
            }
#endif

            return(ConversionResult);
        } // End Function ConvertFile
Exemplo n.º 2
0
        }     // End Sub InsertDocument

        public static void SaveSVG(string strGS_UID, string strDrawing, string polygonId, string strSO_Nr, string strGB_Nr)
        {
            if (!ExportSettings.ConfigurationCorrect)
            {
                return;
            }

            if (!ExportSettings.ExecuteExport) // ExecuteExport: Export ausführen
            {
                return;
            }

            // EXPType_ Export-Typ - Deine Code läuft nur wenn Wert = "SVG"
            if (
                !(
                    ExportSettings.ExportFileType.IsFlagSet(ExportFileType_t.svg) ||
                    ExportSettings.ExportFileType.IsFlagSet(ExportFileType_t.pdf)
                    )
                )
            {
                return;
            }


            if (ExportSettings.AskBeforeExport) // ASCExp: vor Export nachfragen
            {
                DialogResult diagRes = MessageBox.Show("Wollen Sie die Datei aktualisieren ?", "Aktualisieren", MessageBoxButtons.YesNo);
                if (diagRes != DialogResult.Yes)
                {
                    return;
                }
                else if (diagRes == DialogResult.No)
                {
                    //do something else
                    return;
                }
            } // End if (SvgSettings.AskBeforeExport)


            string strPath = ExportSettings.ExportDirectory;

            if (ExportSettings.ExportWithSubdirectories)
            {
                strPath = Helpers.CombinePaths(strPath, strSO_Nr, strGB_Nr); //, strGS_DisplayNr);
            }
            if (!System.IO.Directory.Exists(strPath))
            {
                System.IO.Directory.CreateDirectory(strPath);
            }

            string dateToAppend   = System.DateTime.Now.ToString("'_'yyyyMMdd_HHmmss");
            string strRawFileName = strDrawing;
            string strFileName    = strRawFileName;


            // DateTimeExp: Datum u. Zeitstempel im Dateinamen
            // DWGReplace: vorhandene Datei ohne Datum u. Zeitstempel im Dateinamen überschreiben
            if (ExportSettings.DateTimeInFileName)
            {
                strFileName += dateToAppend;
            }

            string saveFileNameWithDate    = System.IO.Path.Combine(strPath, strFileName);
            string saveFileNameWithoutDate = System.IO.Path.Combine(strPath, strRawFileName);


            cConversionResult ConversionResult = ConvertFile(strDrawing, polygonId);



            if (ExportSettings.DateTimeInFileName)
            {
                if (ExportSettings.ExportFileType.IsFlagSet(ExportFileType_t.svg))
                {
                    if (ConversionResult.SVG != null)
                    {
                        System.IO.File.WriteAllText(saveFileNameWithDate + ".svg", ConversionResult.SVG, System.Text.Encoding.UTF8);
                    }
                }

                if (ExportSettings.ExportFileType.IsFlagSet(ExportFileType_t.pdf))
                {
                    if (ConversionResult.PDF != null)
                    {
                        System.IO.File.WriteAllBytes(saveFileNameWithDate + ".pdf", ConversionResult.PDF);
                    }
                }
            }


            if (!ExportSettings.DateTimeInFileName || ExportSettings.DateTimeInFileName && ExportSettings.OverwriteFileIfExists)
            {
                string svgFile = saveFileNameWithoutDate + ".svg";
                string pdfFile = saveFileNameWithoutDate + ".pdf";


                if (ExportSettings.ExportFileType.IsFlagSet(ExportFileType_t.svg))
                {
                    if (ConversionResult.SVG != null)
                    {
                        System.IO.File.WriteAllText(svgFile, ConversionResult.SVG, System.Text.Encoding.UTF8);
                    }
                }

                if (ExportSettings.ExportFileType.IsFlagSet(ExportFileType_t.pdf))
                {
                    if (ConversionResult.PDF != null)
                    {
                        System.IO.File.WriteAllBytes(pdfFile, ConversionResult.PDF);
                    }
                }
            }

            if (ConversionResult.SVG != null)
            {
                if (ExportSettings.ExportFileType.IsFlagSet(ExportFileType_t.svg) && ExportSettings.SaveToDatabase)
                {
                    byte[] bom        = System.Text.Encoding.UTF8.GetPreamble();
                    byte[] baSVG      = System.Text.Encoding.UTF8.GetBytes(ConversionResult.SVG);
                    byte[] baDestFile = new byte[baSVG.Length + bom.Length];
                    System.Array.Copy(bom, baDestFile, bom.Length);
                    System.Array.Copy(baSVG, 0, baDestFile, bom.Length, baSVG.Length);

                    int BE_ID = 12768;
                    InsertDocument(BE_ID, strGS_UID, baDestFile, strDrawing, strFileName);
                } // End if (SvgSettings.SaveToDatabase)
            }     // End if (svg != null)
        }         // End Sub SaveSVG