Ejemplo n.º 1
0
 private static bool TryConvert(string rpt1Path, ModelType modelType, out string xmlPath)
 {
     try
     {
         xmlPath = RptToXml.ConvertRptToXml(rpt1Path, modelType);
         return(true);
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         xmlPath = null;
         return(false);
     }
 }
Ejemplo n.º 2
0
        static int Main(string[] args)
        {
            string diffPath = "", xmlFilePath1 = "", xmlFilePath2 = "", rptFile1 = "", rptFile2 = "", rptFolder = "";
            int    ModelNumber = 1; // vychozi je ReportClientDocument

            Getopt opt = new Getopt("", args, "mp:f:s:d:");
            int    c;

            while ((c = opt.getopt()) != (-1))
            {
                switch ((char)c)
                {
                case 'p':
                    if (!File.Exists(opt.Optarg))
                    {
                        Console.Error.WriteLine("Error: Unknown diff application - Bad DiffUtilPath");
                        WriteUsage();
                        return((int)ExitCode.WrongDiffApp);
                    }
                    else
                    {
                        diffPath = opt.Optarg;
                    }
                    break;

                case 'f':
                    if (!File.Exists(opt.Optarg))
                    {
                        Console.Error.WriteLine("Error: Can't find RPT file - Bad RPTPath1");
                        WriteUsage();
                        return((int)ExitCode.WrongRptFile);
                    }
                    else
                    {
                        rptFile1 = opt.Optarg;
                    }
                    break;

                case 's':
                    if (!File.Exists(opt.Optarg))
                    {
                        Console.Error.WriteLine("Error: Can't find RPT file - Bad RPTPath2");
                        WriteUsage();
                        return((int)ExitCode.WrongRptFile);
                    }
                    else
                    {
                        rptFile2 = opt.Optarg;
                    }
                    break;

                case 'm':
                    // pokud je zadan prepinac m tak pouzijem model ReportDocument
                    ModelNumber = 0;
                    break;

                case 'd':
                    if (!Directory.Exists(opt.Optarg))
                    {
                        Console.Error.WriteLine("Error: Can't find RPT directory - Bad RPTDirectory");
                        WriteUsage();
                        return((int)ExitCode.WrongRptFile);
                    }
                    else
                    {
                        rptFolder = opt.Optarg;
                    }
                    break;

                default:
                    WriteUsage();
                    return((int)ExitCode.WrongArgs);
                }
            }

            try
            {
                if (File.Exists(rptFile1))
                {
                    Console.WriteLine("Using object model: \"" + ((ModelNumber == 0) ? "ReportDocument" : "ReportClientDocument") + "\"");
                    Console.WriteLine("Converting file: \"" + rptFile1 + "\"");
                    xmlFilePath1 = RptToXml.ConvertRptToXml(rptFile1, ModelNumber);
                    Console.WriteLine("File \"" + rptFile1 + "\" converted to \"" + xmlFilePath1 + "\"");
                }
                if (File.Exists(rptFile2))
                {
                    Console.WriteLine("Using object model: \"" + ((ModelNumber == 0) ? "ReportDocument" : "ReportClientDocument") + "\"");
                    Console.WriteLine("Converting file: \"" + rptFile2 + "\"");
                    xmlFilePath2 = RptToXml.ConvertRptToXml(rptFile2, ModelNumber);
                    Console.WriteLine("File \"" + rptFile2 + "\" converted to \"" + xmlFilePath2 + "\"");
                }
                if (Directory.Exists(rptFolder))
                {
                    string[] files = Directory.GetFiles(rptFolder, "*.rpt", SearchOption.AllDirectories);
                    string   xmlFilePath;
                    foreach (string file in files)
                    {
                        Console.WriteLine("Using object model: \"" + ((ModelNumber == 0) ? "ReportDocument" : "ReportClientDocument") + "\"");
                        Console.WriteLine("Converting file: \"" + file + "\"");
                        xmlFilePath = RptToXml.ConvertRptToXml(file, ModelNumber);
                        Console.WriteLine("File \"" + file + "\" converted to \"" + xmlFilePath + "\"");
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error: Convert to XML error");
                Console.Error.WriteLine(e);
                return((int)ExitCode.ConvertError);
            }
            if (File.Exists(diffPath) && (File.Exists(xmlFilePath1) || File.Exists(xmlFilePath2)))
            {
                Console.WriteLine("Starting diff application: \"" + diffPath + "\"");
                Process diffProc = Process.Start(diffPath, String.Format("\"{0}\" \"{1}\"", xmlFilePath1, xmlFilePath2));
                diffProc.WaitForExit();
                Console.WriteLine("Diff application exited");
                // delete xml files after closing diff application
                if (File.Exists(xmlFilePath1))
                {
                    Console.WriteLine("Deleting file: \"" + xmlFilePath1 + "\"");
                    File.Delete(xmlFilePath1);
                }
                if (File.Exists(xmlFilePath2))
                {
                    Console.WriteLine("Deleting file: \"" + xmlFilePath2 + "\"");
                    File.Delete(xmlFilePath2);
                }
            }

            return((int)ExitCode.Success);
        }
Ejemplo n.º 3
0
        static int Main(string[] args)
        {
            string diffPath = "", xmlFilePath1 = "", xmlFilePath2 = "";
            int    ModelNumber = 0;

            switch (args.Length)
            {
            case 3:
            {
                if (!File.Exists(args[1]))
                {
                    Console.Error.WriteLine("Error: Can't find RPT file - Bad RPTPath1");
                    WriteUsage();
                    return((int)ExitCode.WrongRptFile);
                }
                if (!Int32.TryParse(args[2], out ModelNumber) || (ModelNumber != 0 && ModelNumber != 1))
                {
                    Console.Error.WriteLine("Error: Wrong ModelNumber select - must be 0 or 1");
                    WriteUsage();
                    return((int)ExitCode.WrongModel);
                }
                Console.WriteLine("Using object model: \"" + ((ModelNumber == 0)?"ReportDocument":"ReportClientDocument") + "\"");
                Console.WriteLine("Converting file: \"" + args[1] + "\"");
                try
                {
                    xmlFilePath1 = RptToXml.ConvertRptToXml(args[1], ModelNumber);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("Error: Convert to XML error");
                    Console.Error.WriteLine(e);
                    return((int)ExitCode.ConvertError);
                }
                Console.WriteLine("File \"" + args[1] + "\" converted to \"" + xmlFilePath1 + "\"");
                break;
            }

            case 4:
            {
                if (!File.Exists(args[1]))
                {
                    Console.Error.WriteLine("Error: Can't find RPT file - Bad RPTPath1");
                    WriteUsage();
                    return((int)ExitCode.WrongRptFile);
                }
                if (!Int32.TryParse(args[3], out ModelNumber) || (ModelNumber != 0 && ModelNumber != 1))
                {
                    Console.Error.WriteLine("Error: Wrong ModelNumber select - must be 0 or 1");
                    WriteUsage();
                    return((int)ExitCode.WrongModel);
                }
                Console.WriteLine("Using object model: \"" + ((ModelNumber == 0) ? "ReportDocument" : "ReportClientDocument") + "\"");
                Console.WriteLine("Converting file: \"" + args[1] + "\"");
                try
                {
                    xmlFilePath1 = RptToXml.ConvertRptToXml(args[1], ModelNumber);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("Error: Convert to XML error");
                    Console.Error.WriteLine(e);
                    return((int)ExitCode.ConvertError);
                }
                Console.WriteLine("File \"" + args[1] + "\" converted to \"" + xmlFilePath1 + "\"");
                if (!File.Exists(args[2]))
                {
                    Console.Error.WriteLine("Error: Can't find RPT file - Bad RPTPath2");
                    WriteUsage();
                    return((int)ExitCode.WrongRptFile);
                }
                Console.WriteLine("Converting file: \"" + args[2] + "\"");
                try
                {
                    xmlFilePath2 = RptToXml.ConvertRptToXml(args[2], ModelNumber);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("Error: Convert to XML error");
                    Console.Error.WriteLine(e);
                    return((int)ExitCode.ConvertError);
                }
                Console.WriteLine("File \"" + args[2] + "\" converted to \"" + xmlFilePath2 + "\"");
                break;
            }

            default:
            {
                Console.Error.WriteLine("Error: Wrong number of parameters");
                WriteUsage();
                return((int)ExitCode.WrongArgs);
            }
            }
            if (!File.Exists(args[0]))
            {
                Console.Error.WriteLine("Error: Unknown diff application - Bad DiffUtilPath");
                WriteUsage();
                return((int)ExitCode.WrongDiffApp);
            }
            diffPath = args[0];
            Console.WriteLine("Starting diff application: \"" + diffPath + "\"");
            Process diffProc = Process.Start(diffPath, String.Format("\"{0}\" \"{1}\"", xmlFilePath1, xmlFilePath2));

            diffProc.WaitForExit();
            Console.WriteLine("Diff application exited");
            // delete xml files after closing diff application
            if (File.Exists(xmlFilePath1))
            {
                Console.WriteLine("Deleting file: \"" + xmlFilePath1 + "\"");
                File.Delete(xmlFilePath1);
            }
            if (File.Exists(xmlFilePath2))
            {
                Console.WriteLine("Deleting file: \"" + xmlFilePath2 + "\"");
                File.Delete(xmlFilePath2);
            }

            return((int)ExitCode.Success);
        }