Esempio n. 1
0
        public static void ExportSubfile([DefaultVar] ppParser parser, string name, string path)
        {
            for (int i = 0; i < parser.Subfiles.Count; i++)
            {
                if (parser.Subfiles[i].Name == name)
                {
                    FileInfo      file = new FileInfo(path);
                    DirectoryInfo dir  = file.Directory;
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }

                    using (FileStream fs = file.Create())
                    {
                        IWriteFile subfile   = parser.Subfiles[i];
                        ppSubfile  ppSubfile = subfile as ppSubfile;
                        if (ppSubfile != null)
                        {
                            ppSubfile.SourceStream = ppSubfile.CreateReadStream();
                        }
                        subfile.WriteTo(fs);
                        if (ppSubfile != null)
                        {
                            ppSubfile.SourceStream = null;
                        }
                    }
                    break;
                }
            }
        }
Esempio n. 2
0
 public static ToolOutputParser OpenToolOutput([DefaultVar] ppParser parser, string name)
 {
     for (int i = 0; i < parser.Subfiles.Count; i++)
     {
         if (parser.Subfiles[i].Name == name)
         {
             IReadFile subfile = parser.Subfiles[i] as IReadFile;
             if (subfile != null)
             {
                 return(new ToolOutputParser(subfile.CreateReadStream(), subfile.Name));
             }
             IWriteFile writeFile = parser.Subfiles[i] as IWriteFile;
             if (writeFile != null)
             {
                 using (MemoryStream memStream = new MemoryStream())
                 {
                     writeFile.WriteTo(memStream);
                     memStream.Position = 0;
                     ToolOutputParser outParser = new ToolOutputParser(memStream, writeFile.Name);
                     outParser.readFromOtherParser = true;
                     return(outParser);
                 }
             }
             break;
         }
     }
     return(null);
 }
Esempio n. 3
0
        public static MemoryStream ToStream(this IWriteFile iw)
        {
            MemoryStream mem = new MemoryStream();

            iw.WriteTo(mem);
            mem.Position = 0;
            return(mem);
        }
Esempio n. 4
0
        public static Stream GetReadStream(IWriteFile iw)
        {
            Stream str;

            if (iw is MemSubfile)
            {
                MemSubfile m = iw as MemSubfile;
                str = m.CreateReadStream();
            }
            else if (iw is IReadFile)
            {
                IReadFile p = iw as IReadFile;
                str = p.CreateReadStream();
            }
            else
            {
                str = new MemoryStream();
                iw.WriteTo(str);

                str.Position = 0;
            }

            return(str);
        }
Esempio n. 5
0
        public static Stream GetReadStream(IWriteFile iw)
        {
            Stream str;

            if (iw is MemSubfile)
            {
                MemSubfile m = iw as MemSubfile;
                str = m.CreateReadStream();
            }
            else if (iw is IReadFile)
            {
                IReadFile p = iw as IReadFile;
                str = p.CreateReadStream();
            }
            else
            {
                str = new MemoryStream();
                iw.WriteTo(str);

                str.Position = 0;
            }

            return str;
        }
Esempio n. 6
0
        public ppSwapfile(string ppPath, IWriteFile source)
        {
            this.Name = source.Name;
            this.swapFilePath = tmpFolder + @"\" + ppPath.Replace('\\', '#').Replace(':', '~') + "#" + source.Name;

            if (!Directory.Exists(tmpFolder))
            {
                Directory.CreateDirectory(tmpFolder);
            }
            else
            {
                string rnd = string.Empty;
                Random rand = new Random();
                while (File.Exists(swapFilePath + rnd))
                {
                    rnd = "-" + rand.Next();
                }
                swapFilePath += rnd;
            }
            using (FileStream stream = File.OpenWrite(swapFilePath))
            {
                source.WriteTo(stream);
            }
        }
Esempio n. 7
0
        public ppSwapfile(string ppPath, IWriteFile source)
        {
            this.Name         = source.Name;
            this.swapFilePath = tmpFolder + @"\" + ppPath.Replace('\\', '#').Replace(':', '~') + "#" + source.Name;

            if (!Directory.Exists(tmpFolder))
            {
                Directory.CreateDirectory(tmpFolder);
            }
            else
            {
                string rnd  = string.Empty;
                Random rand = new Random();
                while (File.Exists(swapFilePath + rnd))
                {
                    rnd = "-" + rand.Next();
                }
                swapFilePath += rnd;
            }
            using (FileStream stream = File.OpenWrite(swapFilePath))
            {
                source.WriteTo(stream);
            }
        }