예제 #1
0
        private FileInfo GetFileInfo(string FileName, string type)
        {
            string versionString = string.Empty;

            OpenMcdf.CompoundFile file = new OpenMcdf.CompoundFile(FileName);
            CFStream stream            = file.RootStorage.GetStream("BasicFileInfo");
            string   s = Encoding.BigEndianUnicode.GetString(stream.GetData());
            //Revit 2019 uses the "Format" string to identify version instead of "Revit Build" as in
            //earlier versions
            Regex rgMatchLines = new Regex(@"Format:.*\d{4}");

            foreach (Match match in rgMatchLines.Matches(s))
            {
                versionString += match.Value + System.Environment.NewLine;
            }

            s = Encoding.Unicode.GetString(stream.GetData());
            //Revit 2018 and earlier use "Revit Build" to identify version
            rgMatchLines = new Regex(@"Revit Build:.*\d{4} ");
            foreach (Match match in rgMatchLines.Matches(s))
            {
                versionString += match.Value + System.Environment.NewLine;
            }

            return(new FileInfo(GetFileName(FileName), versionString, type));
        }
        public override WFState Run()
        {
            WFState retval = new WFState()
            {
                Value = "Success"
            };

            OpenMcdf.CompoundFile cf = null;
            try
            {
                cf = new CompoundFile(this.FileToProcess);
                bool attachfound = false;
                int  attachinc   = 0;
                do
                {
                    CFStorage cfstorage = this.GetStorage(cf.RootStorage, MakeAttachStorageName(attachinc));
                    if (cfstorage != null)
                    {
                        // check if attachment is embedded message - if so do not process
                        if (this.GetStorage(cfstorage, nameOfEmbeddedMessageStream) == null)
                        {
                            string filename = string.Format("attachment{0}", attachinc);

                            // first get filename
                            CFStream cfstream = this.GetStream(cfstorage, MakeSubStorageStreamName(0x3001, 0x001F));
                            if (cfstream != null)
                            {
                                filename = System.Text.UnicodeEncoding.Unicode.GetString(cfstream.GetData());
                            }
                            // second get filename
                            cfstream = this.GetStream(cfstorage, MakeSubStorageStreamName(0x3701, 0x0102));
                            if (cfstream != null)
                            {
                                string filedir = string.Format("{0}\\{1}", this.ExportDirectory, WFUtilities.GetNextDirectoryNumber(this.ExportDirectory));
                                if (!Directory.Exists(filedir))
                                {
                                    Directory.CreateDirectory(filedir);
                                }
                                if (Directory.Exists(filedir))
                                {
                                    using (var bw = new BinaryWriter(File.OpenWrite(string.Format("{0}\\{1}", filedir, filename))))
                                    {
                                        bw.Write(cfstream.GetData());
                                        this.OutputFiles.Add(string.Format("{0}\\{1}", filedir, filename), "Success");
                                    }
                                }
                            }
                        }
                        attachfound = true;
                    }
                    else
                    {
                        attachfound = false;
                    }
                    attachinc++;
                } while(attachfound);
            }
            catch (Exception)
            {
                retval.Value = "Fail";
            }
            finally
            {
                if (cf != null)
                {
                    cf.Close();
                }
            }

            return(retval);
        }