示例#1
0
        /// <summary> Read the contents of a file and place them in
        /// a string object.
        /// *
        /// </summary>
        /// <param name="file">path to file.
        /// </param>
        /// <returns>String contents of the file.
        ///
        /// </returns>
        public static String FileContentsToString(String file)
        {
            String contents = string.Empty;

            FileInfo f = new FileInfo(file);

            bool tmpBool;

            if (File.Exists(f.FullName))
            {
                tmpBool = true;
            }
            else
            {
                tmpBool = Directory.Exists(f.FullName);
            }
            if (tmpBool)
            {
                try
                {
                    StreamReader fr       = new StreamReader(f.FullName);
                    char[]       template = new char[(int)SupportClass.FileLength(f)];
                    fr.Read((Char[])template, 0, template.Length);
                    contents = new String(template);
                    fr.Close();
                }
                catch (System.Exception e)
                {
                    Console.Out.WriteLine(e);
                    SupportClass.WriteStackTrace(e, Console.Error);
                }
            }

            return(contents);
        }
示例#2
0
        public static void  Main(System.String[] args)
        {
            if (args.Length != 1)
            {
                System.Console.Error.WriteLine("Usage: DefaultApplication message_file");
                System.Environment.Exit(1);
            }

            //read test message file ...
            try
            {
                System.IO.FileInfo     messageFile = new System.IO.FileInfo(args[0]);
                System.IO.StreamReader in_Renamed  = new System.IO.StreamReader(new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default).CurrentEncoding);
                int    fileLength = (int)SupportClass.FileLength(messageFile);
                char[] cbuf       = new char[fileLength];
                in_Renamed.Read(cbuf, 0, fileLength);
                System.String messageString = new System.String(cbuf);

                //parse inbound message ...
                Parser  parser    = new PipeParser();
                Message inMessage = null;
                try
                {
                    inMessage = parser.parse(messageString);
                }
                catch (NuGenHL7Exception e)
                {
                    SupportClass.WriteStackTrace(e, Console.Error);
                }
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
示例#3
0
 /// <summary>this method generates conformance</summary>
 /// <param name="dm">the DeploymentManager
 /// </param>
 /// <param name="cp">the CommandParser which parses the command line argument of ConfGen
 /// </param>
 public virtual void  generateConf(DeploymentManager dm, CommandParser cp)
 {
     try
     {
         System.IO.FileInfo     f          = new System.IO.FileInfo(cp.Source);
         System.IO.StreamReader in_Renamed = new System.IO.StreamReader(new System.IO.StreamReader(f.FullName, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(f.FullName, System.Text.Encoding.Default).CurrentEncoding);
         char[] cbuf = new char[(int)SupportClass.FileLength(f)];
         in_Renamed.Read(cbuf, 0, (int)SupportClass.FileLength(f));
         dm.generate(System.Convert.ToString(cbuf));
     }
     catch (System.IO.FileNotFoundException e)
     {
         System.Console.Out.WriteLine("Filenotfoundexception: " + e.ToString());
     }
     catch (System.IO.IOException e)
     {
         System.Console.Out.WriteLine("IOexception:\n" + e.ToString() + "\n");
     }
     catch (ConformanceError e)
     {
         System.Console.Out.WriteLine("ConformanceError:\n" + e.ToString() + "\n");
     }
     catch (ConformanceException e)
     {
         System.Console.Out.WriteLine("ConformanceException:\n" + e.ToString() + "\n");
     }
 }
示例#4
0
        public static new void Main(System.String[] args)
        {
            if (args.Length != 1)
            {
                System.Console.Out.WriteLine("Usage: DefaultXMLParser pipe_encoded_file");
                System.Environment.Exit(1);
            }

            //read and parse message from file
            try
            {
                System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]);
                long fileLength          = SupportClass.FileLength(messageFile);
                System.IO.StreamReader r = new System.IO.StreamReader(
                    messageFile.FullName,
                    System.Text.Encoding.Default);
                char[] cbuf = new char[(int)fileLength];
                System.Console.Out.WriteLine(
                    "Reading message file ... " + r.Read(cbuf, 0, cbuf.Length) + " of " + fileLength + " chars");
                r.Close();
                System.String messString = System.Convert.ToString(cbuf);

                ParserBase inParser            = null;
                ParserBase outParser           = null;
                PipeParser pp                  = new PipeParser();
                NHapi.Base.Parser.XMLParser xp = new DefaultXMLParser();
                System.Console.Out.WriteLine("Encoding: " + pp.GetEncoding(messString));
                if (pp.GetEncoding(messString) != null)
                {
                    inParser  = pp;
                    outParser = xp;
                }
                else if (xp.GetEncoding(messString) != null)
                {
                    inParser  = xp;
                    outParser = pp;
                }

                IMessage mess = inParser.Parse(messString);
                System.Console.Out.WriteLine("Got message of type " + mess.GetType().FullName);

                System.String otherEncoding = outParser.Encode(mess);
                System.Console.Out.WriteLine(otherEncoding);
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
示例#5
0
        public static new void  Main(System.String[] args)
        {
            if (args.Length != 1)
            {
                System.Console.Out.WriteLine("Usage: DefaultXMLParser pipe_encoded_file");
                System.Environment.Exit(1);
            }

            //read and parse message from file
            try
            {
                System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]);
                long fileLength = SupportClass.FileLength(messageFile);
                //UPGRADE_TODO: Constructor 'java.io.FileReader.FileReader' was converted to 'System.IO.StreamReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                System.IO.StreamReader r = new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default);
                char[] cbuf = new char[(int)fileLength];
                //UPGRADE_TODO: Method 'java.io.Reader.read' was converted to 'System.IO.StreamReader.Read' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioReaderread_char[]'"
                System.Console.Out.WriteLine("Reading message file ... " + r.Read((System.Char[])cbuf, 0, cbuf.Length) + " of " + fileLength + " chars");
                r.Close();
                System.String messString = System.Convert.ToString(cbuf);

                Parser     inParser              = null;
                Parser     outParser             = null;
                PipeParser pp                    = new PipeParser();
                ca.uhn.hl7v2.parser.XMLParser xp = new DefaultXMLParser();
                System.Console.Out.WriteLine("Encoding: " + pp.getEncoding(messString));
                if (pp.getEncoding(messString) != null)
                {
                    inParser  = pp;
                    outParser = xp;
                }
                else if (xp.getEncoding(messString) != null)
                {
                    inParser  = xp;
                    outParser = pp;
                }

                Message mess = inParser.parse(messString);
                System.Console.Out.WriteLine("Got message of type " + mess.GetType().FullName);

                System.String otherEncoding = outParser.encode(mess);
                System.Console.Out.WriteLine(otherEncoding);
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
        /// <summary> Read the contents of a file and place them in
        /// a string object.
        ///
        /// </summary>
        /// <param name="file">path to file.
        /// </param>
        /// <returns> String contents of the file.
        /// </returns>
        public static System.String FileContentsToString(System.String file, Encoding encoding)
        {
            System.String contents = "";

            System.IO.FileInfo f = null;
            try
            {
                f = new System.IO.FileInfo(file);

                bool tmpBool;
                if (System.IO.File.Exists(f.FullName))
                {
                    tmpBool = true;
                }
                else
                {
                    tmpBool = System.IO.Directory.Exists(f.FullName);
                }
                if (tmpBool)
                {
                    System.IO.StreamReader fr = null;
                    try
                    {
                        fr = new System.IO.StreamReader(f.FullName, encoding);
                        char[] template = new char[(int)SupportClass.FileLength(f)];
                        fr.Read((System.Char[])template, 0, template.Length);
                        contents = new System.String(template);
                    }
                    catch (System.Exception e)
                    {
                        SupportClass.WriteStackTrace(e, Console.Error);
                    }
                    finally
                    {
                        if (fr != null)
                        {
                            fr.Close();
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
            return(contents);
        }
示例#7
0
        public TestClassloader()
        {
            try {
                System.IO.FileInfo f = new System.IO.FileInfo(testclass);

                sbyte[] barr = new sbyte[(int)SupportClass.FileLength(f)];

                System.IO.FileStream fis = new System.IO.FileStream(f.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                //UPGRADE_TODO: Equivalent of method 'java.io.FileInputStream.read' may not have an optimal performance in C#. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1117"'
                SupportClass.ReadInput(fis, ref barr, 0, barr.Length);
                fis.Close();

                //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.defineClass' was not converted. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1000_javalangClassLoader"'
                fooClass = defineClass("Foo", barr, 0, barr.Length);
            } catch (System.Exception e) {
                System.Console.Out.WriteLine("TestClassloader : exception : " + e);
            }
        }
示例#8
0
        /// <summary> Retrieves profile from persistent storage (by ID).  Returns null
        /// if the profile isn't found.
        /// </summary>
        public virtual System.String getProfile(System.String ID)
        {
            System.String profile = null;

            System.IO.FileInfo source = new System.IO.FileInfo(getFileName(ID));
            if (System.IO.File.Exists(source.FullName))
            {
                System.IO.StreamReader in_Renamed = new System.IO.StreamReader(new System.IO.StreamReader(source.FullName, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(source.FullName, System.Text.Encoding.Default).CurrentEncoding);
                char[] buf   = new char[(int)SupportClass.FileLength(source)];
                int    check = in_Renamed.Read(buf, 0, buf.Length);
                in_Renamed.Close();
                if (check != buf.Length)
                {
                    throw new System.IO.IOException("Only read " + check + " of " + buf.Length + " bytes of file " + source.FullName);
                }
                profile = new System.String(buf);
            }
            return(profile);
        }
示例#9
0
        public static string FileContentsToString(string file)
        {
            string   result   = "";
            FileInfo fileInfo = new FileInfo(file);
            bool     flag     = File.Exists(fileInfo.FullName) || Directory.Exists(fileInfo.FullName);

            if (flag)
            {
                try
                {
                    StreamReader streamReader = new StreamReader(fileInfo.FullName);
                    char[]       array        = new char[(int)SupportClass.FileLength(fileInfo)];
                    streamReader.Read(array, 0, array.Length);
                    result = new string(array);
                    streamReader.Close();
                }
                catch (System.Exception ex)
                {
                    Console.Out.WriteLine(ex);
                    SupportClass.WriteStackTrace(ex, Console.Error);
                }
            }
            return(result);
        }
示例#10
0
        public static void  Main(System.String[] args)
        {
            if (args.Length != 1)
            {
                System.Console.Out.WriteLine("Usage: ProfileParser profile_file");
                System.Environment.Exit(1);
            }

            try
            {
                System.IO.FileInfo     f          = new System.IO.FileInfo(args[0]);
                System.IO.StreamReader in_Renamed = new System.IO.StreamReader(new System.IO.StreamReader(f.FullName, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(f.FullName, System.Text.Encoding.Default).CurrentEncoding);
                char[] cbuf = new char[(int)SupportClass.FileLength(f)];
                in_Renamed.Read(cbuf, 0, (int)SupportClass.FileLength(f));
                System.String xml = System.Convert.ToString(cbuf);

                NuGenProfileParser pp   = new NuGenProfileParser(true);
                RuntimeProfile     spec = pp.parse(xml);
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
示例#11
0
        public static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.Out.WriteLine("Usage: XMLParser pipe_encoded_file");
                Environment.Exit(1);
            }

            // read and parse message from file
            try
            {
                var parser      = new PipeParser();
                var messageFile = new FileInfo(args[0]);
                var fileLength  = SupportClass.FileLength(messageFile);
                var r           = new StreamReader(messageFile.FullName, Encoding.Default);
                var cbuf        = new char[(int)fileLength];
                Console.Out.WriteLine(
                    $"Reading message file ... {r.Read((char[])cbuf, 0, cbuf.Length)} of {fileLength} chars");
                r.Close();
                var messString = Convert.ToString(cbuf);
                var mess       = parser.Parse(messString);
                Console.Out.WriteLine("Got message of type " + mess.GetType().FullName);

                XMLParser xp = new AnonymousClassXMLParser();

                // loop through segment children of message, encode, print to console
                var structNames = mess.Names;
                for (var i = 0; i < structNames.Length; i++)
                {
                    var reps = mess.GetAll(structNames[i]);
                    for (var j = 0; j < reps.Length; j++)
                    {
                        if (reps[j] is ISegment)
                        {
                            // ignore groups
                            var docBuilder = new XmlDocument();
                            var doc        = new XmlDocument(); // new doc for each segment
                            var root       = doc.CreateElement(reps[j].GetType().FullName);
                            doc.AppendChild(root);
                            xp.Encode((ISegment)reps[j], root);
                            var out_Renamed = new StringWriter();
                            Console.Out.WriteLine("Segment " + reps[j].GetType().FullName + ": \r\n" + doc.OuterXml);

                            var segmentConstructTypes = new Type[] { typeof(IMessage) };
                            var segmentConstructArgs  = new object[] { null };
                            var s = (ISegment)reps[j].GetType().GetConstructor(segmentConstructTypes).Invoke(segmentConstructArgs);
                            xp.Parse(s, root);
                            var doc2  = new XmlDocument();
                            var root2 = doc2.CreateElement(s.GetType().FullName);
                            doc2.AppendChild(root2);
                            xp.Encode(s, root2);
                            var out2 = new StringWriter();
                            var ser  = XmlWriter.Create(out2);
                            doc.WriteTo(ser);
                            if (out2.ToString().Equals(out_Renamed.ToString()))
                            {
                                Console.Out.WriteLine("Re-encode OK");
                            }
                            else
                            {
                                Console.Out.WriteLine(
                                    $"Warning: XML different after parse and re-encode: {Environment.NewLine}{out2}");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
示例#12
0
        public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
        {
            if (argv.Length < 2)
            {
                throw new TclNumArgsException(interp, 1, argv, "option ?arg ...?");
            }

            int    opt = TclIndex.get(interp, argv[1], validCmds, "option", 0);
            string path;

            System.IO.FileInfo fileObj = null;

            switch (opt)
            {
            case OPT_ATIME:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                // FIXME:  Currently returns the same thing as MTIME.
                // Java does not support retrieval of access time.



                fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString());

                interp.setResult(getMtime(interp, argv[2].ToString(), fileObj));
                return(TCL.CompletionCode.RETURN);


            case OPT_ATTRIBUTES:
                if (argv[3].ToString() == "-readonly")
                {
                    fileSetReadOnly(interp, argv);
                }
                else
                {
                    throw new TclException(interp, "sorry, \"file attributes\" is not implemented yet");
                }
                return(TCL.CompletionCode.RETURN);


            case OPT_CHANNELS:

                throw new TclException(interp, "sorry, \"file channels\" is not implemented yet");


            case OPT_COPY:
                fileCopyRename(interp, argv, true);
                return(TCL.CompletionCode.RETURN);


            case OPT_DELETE:
                fileDelete(interp, argv);
                return(TCL.CompletionCode.RETURN);


            case OPT_DIRNAME:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                path = argv[2].ToString();

                // Return all but the last component.  If there is only one
                // component, return it if the path was non-relative, otherwise
                // return the current directory.


                TclObject[] splitArrayObj = TclList.getElements(interp, FileUtil.splitAndTranslate(interp, path));

                if (splitArrayObj.Length > 1)
                {
                    interp.setResult(FileUtil.joinPath(interp, splitArrayObj, 0, splitArrayObj.Length - 1));
                }
                else if ((splitArrayObj.Length == 0) || (FileUtil.getPathType(path) == FileUtil.PATH_RELATIVE))
                {
                    if (JACL.PLATFORM == JACL.PLATFORM_MAC)
                    {
                        interp.setResult(":");
                    }
                    else
                    {
                        interp.setResult(".");
                    }
                }
                else
                {
                    interp.setResult(splitArrayObj[0].ToString());
                }
                return(TCL.CompletionCode.RETURN);


            case OPT_EXECUTABLE:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }
                bool isExe = false;

                fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString());

                // A file must exist to be executable.  Directories are always
                // executable.

                bool tmpBool;
                if (System.IO.File.Exists(fileObj.FullName))
                {
                    tmpBool = true;
                }
                else
                {
                    tmpBool = System.IO.Directory.Exists(fileObj.FullName);
                }
                if (tmpBool)
                {
                    isExe = System.IO.Directory.Exists(fileObj.FullName);
                    if (isExe)
                    {
                        interp.setResult(isExe);
                        return(TCL.CompletionCode.RETURN);
                    }

                    if (Util.Windows)
                    {
                        // File that ends with .exe, .com, or .bat is executable.


                        string fileName = argv[2].ToString();
                        isExe = (fileName.EndsWith(".exe") || fileName.EndsWith(".com") || fileName.EndsWith(".bat"));
                    }
                    else if (Util.Mac)
                    {
                        // FIXME:  Not yet implemented on Mac.  For now, return true.
                        // Java does not support executability checking.

                        isExe = true;
                    }
                    else
                    {
                        // FIXME:  Not yet implemented on Unix.  For now, return true.
                        // Java does not support executability checking.

                        isExe = true;
                    }
                }
                interp.setResult(isExe);
                return(TCL.CompletionCode.RETURN);


            case OPT_EXISTS:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString());
                bool tmpBool2;
                if (System.IO.File.Exists(fileObj.FullName))
                {
                    tmpBool2 = true;
                }
                else
                {
                    tmpBool2 = System.IO.Directory.Exists(fileObj.FullName);
                }
                interp.setResult(tmpBool2);
                return(TCL.CompletionCode.RETURN);


            case OPT_EXTENSION:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                interp.setResult(getExtension(argv[2].ToString()));
                return(TCL.CompletionCode.RETURN);


            case OPT_ISDIRECTORY:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString());
                interp.setResult(System.IO.Directory.Exists(fileObj.FullName));
                return(TCL.CompletionCode.RETURN);


            case OPT_ISFILE:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString());
                interp.setResult(System.IO.File.Exists(fileObj.FullName));
                return(TCL.CompletionCode.RETURN);


            case OPT_JOIN:
                if (argv.Length < 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name ?name ...?");
                }
                interp.setResult(FileUtil.joinPath(interp, argv, 2, argv.Length));
                return(TCL.CompletionCode.RETURN);


            case OPT_LINK:

                throw new TclException(interp, "sorry, \"file link\" is not implemented yet");


            case OPT_LSTAT:
                if (argv.Length != 4)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name varName");
                }

                // FIXME:  Not yet implemented.
                // Java does not support link access.


                throw new TclException(interp, "file command with opt " + argv[1].ToString() + " is not yet implemented");



            case OPT_MTIME:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString());

                interp.setResult(getMtime(interp, argv[2].ToString(), fileObj));
                return(TCL.CompletionCode.RETURN);


            case OPT_MKDIR:
                fileMakeDirs(interp, argv);
                return(TCL.CompletionCode.RETURN);


            case OPT_NATIVENAME:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }


                interp.setResult(FileUtil.translateFileName(interp, argv[2].ToString()));
                return(TCL.CompletionCode.RETURN);


            case OPT_NORMALIZE:

                throw new TclException(interp, "sorry, \"file normalize\" is not implemented yet");


            case OPT_OWNED:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString());
                interp.setResult(isOwner(interp, fileObj));
                return(TCL.CompletionCode.RETURN);


            case OPT_PATHTYPE:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                switch (FileUtil.getPathType(argv[2].ToString()))
                {
                case FileUtil.PATH_RELATIVE:
                    interp.setResult("relative");
                    return(TCL.CompletionCode.RETURN);

                case FileUtil.PATH_VOLUME_RELATIVE:
                    interp.setResult("volumerelative");
                    return(TCL.CompletionCode.RETURN);

                case FileUtil.PATH_ABSOLUTE:
                    interp.setResult("absolute");
                    break;
                }
                return(TCL.CompletionCode.RETURN);


            case OPT_READABLE:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString());

                // interp.setResult(fileObj.canRead());
                // HACK
                interp.setResult(true);
                return(TCL.CompletionCode.RETURN);


            case OPT_READLINK:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                // FIXME:  Not yet implemented.
                // Java does not support link access.


                throw new TclException(interp, "file command with opt " + argv[1].ToString() + " is not yet implemented");


            case OPT_RENAME:
                fileCopyRename(interp, argv, false);
                return(TCL.CompletionCode.RETURN);


            case OPT_ROOTNAME:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                string fileName2  = argv[2].ToString();
                string extension  = getExtension(fileName2);
                int    diffLength = fileName2.Length - extension.Length;
                interp.setResult(fileName2.Substring(0, (diffLength) - (0)));
                return(TCL.CompletionCode.RETURN);


            case OPT_SEPARATOR:

                throw new TclException(interp, "sorry, \"file separator\" is not implemented yet");


            case OPT_SIZE:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString());
                bool tmpBool3;
                if (System.IO.File.Exists(fileObj.FullName))
                {
                    tmpBool3 = true;
                }
                else
                {
                    tmpBool3 = System.IO.Directory.Exists(fileObj.FullName);
                }
                if (!tmpBool3)
                {
                    throw new TclPosixException(interp, TclPosixException.ENOENT, true, "could not read \"" + argv[2].ToString() + "\"");
                }
                interp.setResult((int)SupportClass.FileLength(fileObj));
                return(TCL.CompletionCode.RETURN);


            case OPT_SPLIT:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                interp.setResult(FileUtil.splitPath(interp, argv[2].ToString()));
                return(TCL.CompletionCode.RETURN);


            case OPT_STAT:
                if (argv.Length != 4)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name varName");
                }

                getAndStoreStatData(interp, argv[2].ToString(), argv[3].ToString());
                return(TCL.CompletionCode.RETURN);


            case OPT_SYSTEM:

                throw new TclException(interp, "sorry, \"file system\" is not implemented yet");


            case OPT_TAIL:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                interp.setResult(getTail(interp, argv[2].ToString()));
                return(TCL.CompletionCode.RETURN);


            case OPT_TYPE:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString());

                interp.setResult(getType(interp, argv[2].ToString(), fileObj));
                return(TCL.CompletionCode.RETURN);


            case OPT_VOLUMES:
                if (argv.Length != 2)
                {
                    throw new TclNumArgsException(interp, 2, argv, null);
                }

                // use Java 1.2's File.listRoots() method if available

                if (listRootsMethod == null)
                {
                    throw new TclException(interp, "\"file volumes\" is not supported");
                }

                try
                {
                    System.IO.FileInfo[] roots = (System.IO.FileInfo[])listRootsMethod.Invoke(null, (System.Object[]) new System.Object[0]);
                    if (roots != null)
                    {
                        TclObject list = TclList.newInstance();
                        for (int i = 0; i < roots.Length; i++)
                        {
                            string root = roots[i].FullName;
                            TclList.append(interp, list, TclString.newInstance(root));
                        }
                        interp.setResult(list);
                    }
                }
                catch (System.UnauthorizedAccessException ex)
                {
                    throw new TclRuntimeError("IllegalAccessException in volumes cmd");
                }
                catch (System.ArgumentException ex)
                {
                    throw new TclRuntimeError("IllegalArgumentException in volumes cmd");
                }
                catch (System.Reflection.TargetInvocationException ex)
                {
                    System.Exception t = ex.GetBaseException();

                    if (t is System.ApplicationException)
                    {
                        throw (System.ApplicationException)t;
                    }
                    else
                    {
                        throw new TclRuntimeError("unexected exception in volumes cmd");
                    }
                }

                return(TCL.CompletionCode.RETURN);

            case OPT_WRITABLE:
                if (argv.Length != 3)
                {
                    throw new TclNumArgsException(interp, 2, argv, "name");
                }

                fileObj = FileUtil.getNewFileObj(interp, argv[2].ToString());
                interp.setResult(SupportClass.FileCanWrite(fileObj));
                return(TCL.CompletionCode.RETURN);

            default:

                throw new TclRuntimeError("file command with opt " + argv[1].ToString() + " is not implemented");
            }
        }
示例#13
0
        private static void  getAndStoreStatData(Interp interp, string fileName, string varName)
        {
            System.IO.FileInfo fileObj = FileUtil.getNewFileObj(interp, fileName);

            bool tmpBool;

            if (System.IO.File.Exists(fileObj.FullName))
            {
                tmpBool = true;
            }
            else
            {
                tmpBool = System.IO.Directory.Exists(fileObj.FullName);
            }
            if (!tmpBool)
            {
                throw new TclPosixException(interp, TclPosixException.ENOENT, true, "could not read \"" + fileName + "\"");
            }

            try
            {
                int       mtime    = getMtime(interp, fileName, fileObj);
                TclObject mtimeObj = TclInteger.newInstance(mtime);
                TclObject atimeObj = TclInteger.newInstance(mtime);
                TclObject ctimeObj = TclInteger.newInstance(mtime);
                interp.setVar(varName, "atime", atimeObj, 0);
                interp.setVar(varName, "ctime", ctimeObj, 0);
                interp.setVar(varName, "mtime", mtimeObj, 0);
            }
            catch (System.Security.SecurityException e)
            {
                throw new TclException(interp, e.Message);
            }
            catch (TclException e)
            {
                throw new TclException(interp, "can't set \"" + varName + "(dev)\": variable isn't array");
            }

            try
            {
                TclObject sizeObj = TclInteger.newInstance((int)SupportClass.FileLength(fileObj));
                interp.setVar(varName, "size", sizeObj, 0);
            }
            catch (System.Exception e)
            {
                // Do nothing.
            }

            try
            {
                TclObject typeObj = TclString.newInstance(getType(interp, fileName, fileObj));
                interp.setVar(varName, "type", typeObj, 0);
            }
            catch (System.Exception e)
            {
            }

            try
            {
                TclObject uidObj = TclBoolean.newInstance(isOwner(interp, fileObj));
                interp.setVar(varName, "uid", uidObj, 0);
            }
            catch (TclException e)
            {
                // Do nothing.
            }
        }
示例#14
0
        public static void  Main(System.String[] args)
        {
            if (args.Length != 1)
            {
                System.Console.Out.WriteLine("Usage: XMLParser pipe_encoded_file");
                System.Environment.Exit(1);
            }

            //read and parse message from file
            try
            {
                PipeParser         parser      = new PipeParser();
                System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]);
                long fileLength = SupportClass.FileLength(messageFile);
                //UPGRADE_TODO: Constructor 'java.io.FileReader.FileReader' was converted to 'System.IO.StreamReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                System.IO.StreamReader r = new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default);
                char[] cbuf = new char[(int)fileLength];
                //UPGRADE_TODO: Method 'java.io.Reader.read' was converted to 'System.IO.StreamReader.Read' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioReaderread_char[]'"
                System.Console.Out.WriteLine("Reading message file ... " + r.Read((System.Char[])cbuf, 0, cbuf.Length) + " of " + fileLength + " chars");
                r.Close();
                System.String messString = System.Convert.ToString(cbuf);
                Message       mess       = parser.parse(messString);
                System.Console.Out.WriteLine("Got message of type " + mess.GetType().FullName);

                ca.uhn.hl7v2.parser.XMLParser xp = new AnonymousClassXMLParser();

                //loop through segment children of message, encode, print to console
                System.String[] structNames = mess.Names;
                for (int i = 0; i < structNames.Length; i++)
                {
                    Structure[] reps = mess.getAll(structNames[i]);
                    for (int j = 0; j < reps.Length; j++)
                    {
                        if (typeof(Segment).IsAssignableFrom(reps[j].GetType()))
                        {
                            //ignore groups
                            //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'"
                            //UPGRADE_ISSUE: Method 'javax.xml.parsers.DocumentBuilderFactory.newInstance' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxxmlparsersDocumentBuilderFactory'"
                            //DocumentBuilderFactory.newInstance();

                            System.Xml.XmlDocument docBuilder = new System.Xml.XmlDocument();
                            //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'"
                            System.Xml.XmlDocument doc  = new System.Xml.XmlDocument();                            //new doc for each segment
                            System.Xml.XmlElement  root = doc.CreateElement(reps[j].GetType().FullName);
                            doc.AppendChild(root);
                            xp.encode((Segment)reps[j], root);
                            System.IO.StringWriter out_Renamed = new System.IO.StringWriter();
                            System.Console.Out.WriteLine("Segment " + reps[j].GetType().FullName + ": \r\n" + doc.OuterXml);

                            System.Type[]   segmentConstructTypes = new System.Type[] { typeof(Message) };
                            System.Object[] segmentConstructArgs  = new System.Object[] { null };
                            Segment         s = (Segment)reps[j].GetType().GetConstructor(segmentConstructTypes).Invoke(segmentConstructArgs);
                            xp.parse(s, root);
                            //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'"
                            System.Xml.XmlDocument doc2  = new System.Xml.XmlDocument();
                            System.Xml.XmlElement  root2 = doc2.CreateElement(s.GetType().FullName);
                            doc2.AppendChild(root2);
                            xp.encode(s, root2);
                            System.IO.StringWriter   out2 = new System.IO.StringWriter();
                            System.Xml.XmlTextWriter ser  = new System.Xml.XmlTextWriter(out2);

                            //System.Xml.XmlWriter ser = System.Xml.XmlWriter.Create(out2);
                            doc.WriteTo(ser);
                            if (out2.ToString().Equals(out_Renamed.ToString()))
                            {
                                System.Console.Out.WriteLine("Re-encode OK");
                            }
                            else
                            {
                                System.Console.Out.WriteLine("Warning: XML different after parse and re-encode: \r\n" + out2.ToString());
                            }
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
示例#15
0
        public static void Main(System.String[] args)
        {
            if (args.Length != 1)
            {
                System.Console.Out.WriteLine("Usage: XMLParser pipe_encoded_file");
                System.Environment.Exit(1);
            }

            //read and parse message from file
            try
            {
                PipeParser         parser      = new PipeParser();
                System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]);
                long fileLength          = SupportClass.FileLength(messageFile);
                System.IO.StreamReader r = new System.IO.StreamReader(
                    messageFile.FullName,
                    System.Text.Encoding.Default);
                char[] cbuf = new char[(int)fileLength];
                System.Console.Out.WriteLine(
                    "Reading message file ... " + r.Read(cbuf, 0, cbuf.Length) + " of " + fileLength + " chars");
                r.Close();
                System.String messString = System.Convert.ToString(cbuf);
                IMessage      mess       = parser.Parse(messString);
                System.Console.Out.WriteLine("Got message of type " + mess.GetType().FullName);

                NHapi.Base.Parser.XMLParser xp = new AnonymousClassXMLParser();

                //loop through segment children of message, encode, print to console
                System.String[] structNames = mess.Names;
                for (int i = 0; i < structNames.Length; i++)
                {
                    IStructure[] reps = mess.GetAll(structNames[i]);
                    for (int j = 0; j < reps.Length; j++)
                    {
                        if (typeof(ISegment).IsAssignableFrom(reps[j].GetType()))
                        {
                            //ignore groups
                            System.Xml.XmlDocument docBuilder = new System.Xml.XmlDocument();
                            System.Xml.XmlDocument doc        = new System.Xml.XmlDocument(); //new doc for each segment
                            System.Xml.XmlElement  root       = doc.CreateElement(reps[j].GetType().FullName);
                            doc.AppendChild(root);
                            xp.Encode((ISegment)reps[j], root);
                            System.IO.StringWriter out_Renamed = new System.IO.StringWriter();
                            System.Console.Out.WriteLine(
                                "Segment " + reps[j].GetType().FullName + ": \r\n" + doc.OuterXml);

                            System.Type[]   segmentConstructTypes = { typeof(IMessage) };
                            System.Object[] segmentConstructArgs  = { null };
                            ISegment        s =
                                (ISegment)
                                reps[j].GetType().GetConstructor(segmentConstructTypes).Invoke(segmentConstructArgs);
                            xp.Parse(s, root);
                            System.Xml.XmlDocument doc2  = new System.Xml.XmlDocument();
                            System.Xml.XmlElement  root2 = doc2.CreateElement(s.GetType().FullName);
                            doc2.AppendChild(root2);
                            xp.Encode(s, root2);
                            System.IO.StringWriter out2 = new System.IO.StringWriter();
                            System.Xml.XmlWriter   ser  = System.Xml.XmlWriter.Create(out2);
                            doc.WriteTo(ser);
                            if (out2.ToString().Equals(out_Renamed.ToString()))
                            {
                                System.Console.Out.WriteLine("Re-encode OK");
                            }
                            else
                            {
                                System.Console.Out.WriteLine(
                                    "Warning: XML different after parse and re-encode: \r\n" + out2);
                            }
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }