Ejemplo n.º 1
0
        private static byte[] GetRawBasicFileInfo(string revitFileName)
        {
            if (StructuredStorageUtils.IsFileStucturedStorage(revitFileName))
            {
                StructuredStorageRoot ssRoot = new StructuredStorageRoot(revitFileName);
                if (ssRoot.BaseRoot != null)
                {
                    if (ssRoot.BaseRoot.StreamExists(StreamName))
                    {
                        StreamInfo imageStreamInfo =
                            ssRoot.BaseRoot.GetStreamInfo(StreamName);

                        using (Stream stream = imageStreamInfo.GetStream(
                                   FileMode.Open, FileAccess.Read))
                        {
                            byte[] buffer = new byte[stream.Length];
                            stream.Read(buffer, 0, buffer.Length);
                            return(buffer);
                        }
                    }
                    else
                    {
                        return(null);
                    };
                    //throw new NotSupportedException(string.Format("File doesn't contain {0} stream", StreamName));
                }
                else
                {
                    return(null);
                };
                //will not run when someone has the file open.
                //using (StructuredStorageRoot ssRoot = new StructuredStorageRoot(revitFileName))
                //{
                //if (ssRoot.BaseRoot.StreamExists(StreamName) && ssRoot.BaseRoot != null)
                //{
                //    StreamInfo imageStreamInfo =
                //    ssRoot.BaseRoot.GetStreamInfo(StreamName);

                //    using (Stream stream = imageStreamInfo.GetStream(
                //      FileMode.Open, FileAccess.Read))
                //    {
                //        byte[] buffer = new byte[stream.Length];
                //        stream.Read(buffer, 0, buffer.Length);
                //        return buffer;
                //    }
                //}
                //else
                //{
                //    return null;
                //}
                //throw new NotSupportedException(string.Format("File doesn't contain {0} stream", StreamName));
            }
            else
            {
                throw new NotSupportedException(
                          "File is not a structured storage file");
            }
        }
Ejemplo n.º 2
0
        internal static List <string> Main(string args)
        {
            string pathToRevitFile = args;

            System.Diagnostics.Debug.WriteLine("Path: " + pathToRevitFile);
            List <string> infoData = new List <string>();

            if (StructuredStorageUtils.IsFileStucturedStorage(pathToRevitFile))
            {
                var rawData = GetRawBasicFileInfo(pathToRevitFile);
                //testing here
                if (rawData != null)
                {
                    var rawString = System.Text.Encoding.Unicode.GetString(
                        rawData);

                    var fileInfoData = rawString.Split(
                        new string[] { "\0", "\r\n" },
                        StringSplitOptions.RemoveEmptyEntries);

                    foreach (var info in fileInfoData)
                    {
                        //Console.WriteLine(info);
                        infoData.Add(info);
                    }
                    ;
                    return(infoData);
                }
                else
                {
                    infoData.Add(null);
                    return(infoData);
                };
            }
            else
            {
                infoData.Add(null);
                return(infoData);
                //throw new NotSupportedException("File is not a structured storage file");
            };
        }