Пример #1
0
        private void DumpStorage(StorageInfo storageInfo, string storageName, XmlWriter writer)
        {
            writer.WriteStartElement("storage");
            writer.WriteAttributeString("name", storageName);

            StorageInfo[] subStorages = storageInfo.GetSubStorages();
            foreach (StorageInfo subStorage in subStorages)
            {
                DumpStorage(subStorage, subStorage.Name, writer);
            }

            StreamInfo[] streams = storageInfo.GetStreams();
            foreach (StreamInfo stream in streams)
            {
                string hexData = ConvertStreamBytesToHex(stream);
                writer.WriteStartElement("stream");
                using (var rawStream = new BinaryReader(stream.GetStream(FileMode.Open, FileAccess.Read)))
                {
                    var streamsBase = Path.Combine(BasePath, Path.GetFileName(_oleStorageFilePath.FullPathString) + "_streams");
                    FileSystem.CreateDirectory(streamsBase);
                    File.WriteAllBytes(Path.Combine(streamsBase, stream.Name).FullPathString, rawStream.ReadBytes((int)rawStream.BaseStream.Length));
                    writer.WriteAttributeString("name", stream.Name);
                    writer.WriteAttributeString("data", hexData);
                    writer.WriteEndElement();
                }
            }

            writer.WriteEndElement();
        }
Пример #2
0
        /***************************************************/

        public static XDocument XDocument(this string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return(null);
            }

            if (!File.Exists(path))
            {
                BH.Engine.Reflection.Compute.RecordError($"Revit file does not exist under path {path}.");
                return(null);
            }

            StorageInfo storageInfo = (StorageInfo)InvokeStorageRootMethod(null, "Open", path, FileMode.Open, FileAccess.Read, FileShare.Read);

            if (storageInfo != null)
            {
                XDocument     document   = null;
                StreamInfo[]  streamInfo = storageInfo.GetStreams();
                List <string> names      = streamInfo.ToList().ConvertAll(x => x.Name);
                foreach (StreamInfo sInfo in streamInfo)
                {
                    if (sInfo.Name.Equals("PartAtom"))
                    {
                        byte[] bytes = ParseStreamInfo(sInfo);

                        try
                        {
                            document = System.Xml.Linq.XDocument.Parse(Encoding.UTF8.GetString(bytes));
                        }
                        catch
                        {
                            BH.Engine.Reflection.Compute.RecordError($"Internal error occurred when attempting to convert a file under path {path} into RevitFilePreview.");
                            return(null);
                        }

                        if (document == null)
                        {
                            try
                            {
                                document = System.Xml.Linq.XDocument.Parse(Encoding.Default.GetString(bytes));
                            }
                            catch
                            {
                                BH.Engine.Reflection.Compute.RecordError($"Internal error occurred when attempting to convert a file under path {path} into RevitFilePreview.");
                                return(null);
                            }
                        }

                        break;
                    }
                }

                CloseStorageInfo(storageInfo);
                return(document);
            }

            return(null);
        }
Пример #3
0
        private void ReadStructuredStorageFile(StorageInfo storageInfo)
        {
            StreamInfo[]  streamInfos = storageInfo.GetStreams();
            List <string> names       = streamInfos.ToList().ConvertAll(x => x.Name);

            foreach (StreamInfo streamInfo in streamInfos)
            {
                if (streamInfo.Name.Equals("RevitPreview4.0"))
                {
                    previewData = ParseStreamInfo(streamInfo);
                }
                else if (streamInfo.Name.Equals("BasicFileInfo"))
                {
                    fileInfoData = ParseStreamInfo(streamInfo);
                }
                if (streamInfo.Name.Equals("PartAtom"))
                {
                    byte[] fileInfoData = ParseStreamInfo(streamInfo);
                    try
                    {
                        xDocument = XDocument.Parse(Encoding.UTF8.GetString(fileInfoData));
                    }
                    catch (Exception aException)
                    {
                        xDocument = null;
                    }

                    if (xDocument == null)
                    {
                        try
                        {
                            xDocument = XDocument.Parse(Encoding.Default.GetString(fileInfoData));
                        }
                        catch
                        {
                            xDocument = null;
                        }
                    }
                }
            }
        }
Пример #4
0
 public StreamInfo[] GetStreams()
 {
     ThrowIfDisposed();
     return(_storageRoot.GetStreams());
 }