コード例 #1
0
        static void SetSolutionConfigValue(CFStream cfStream, IEnumerable<string> startupProjectGuids)
        {
            var single = Encoding.GetEncodings().Single(x => x.Name == "utf-16");
            var encoding = single.GetEncoding();
            var nul = '\u0000';
            var dc1 = '\u0011';
            var etx = '\u0003';
            var soh = '\u0001';

            var builder = new StringBuilder();
            builder.Append(dc1);
            builder.Append(nul);
            builder.Append("MultiStartupProj");
            builder.Append(nul);
            builder.Append('=');
            builder.Append(etx);
            builder.Append(soh);
            builder.Append(nul);
            builder.Append(';');
            foreach (var startupProjectGuid in startupProjectGuids)
            {
                builder.Append('4');
                builder.Append(nul);
                builder.AppendFormat("{{{0}}}.dwStartupOpt", startupProjectGuid);
                builder.Append(nul);
                builder.Append('=');
                builder.Append(etx);
                builder.Append(dc1);
                builder.Append(nul);
                builder.Append(';');
            }

            var newBytes = encoding.GetBytes(builder.ToString());
            cfStream.SetData(newBytes);
        }
コード例 #2
0
        /// <summary>
        /// Create a new child stream inside the current <see cref="T:OpenMcdf.CFStorage">storage</see>
        /// </summary>
        /// <param name="streamName">The new stream name</param>
        /// <returns>The new <see cref="T:OpenMcdf.CFStream">stream</see> reference</returns>
        /// <exception cref="T:OpenMcdf.CFDuplicatedItemException">Raised when adding an item with the same name of an existing one</exception>
        /// <exception cref="T:OpenMcdf.CFDisposedException">Raised when adding a stream to a closed compound file</exception>
        /// <exception cref="T:OpenMcdf.CFException">Raised when adding a stream with null or empty name</exception>
        /// <example>
        /// <code>
        ///
        ///  String filename = "A_NEW_COMPOUND_FILE_YOU_CAN_WRITE_TO.cfs";
        ///
        ///  CompoundFile cf = new CompoundFile();
        ///
        ///  CFStorage st = cf.RootStorage.AddStorage("MyStorage");
        ///  CFStream sm = st.AddStream("MyStream");
        ///  byte[] b = Helpers.GetBuffer(220, 0x0A);
        ///  sm.SetData(b);
        ///
        ///  cf.Save(filename);
        ///
        /// </code>
        /// </example>
        public ICFStream AddStream(String streamName)
        {
            CheckDisposed();

            if (String.IsNullOrEmpty(streamName))
            {
                throw new CFException("Stream name cannot be null or empty");
            }

            CFStream cfo = null;


            // Add new Stream directory entry
            cfo = new CFStream(this.CompoundFile);
            cfo.DirEntry.SetEntryName(streamName);


            try
            {
                // Add object to Siblings tree
                this.Children.Add(cfo);

                //Rethread children tree...
                CompoundFile.RefreshIterative(Children.Root);

                //... and set the root of the tree as new child of the current item directory entry
                this.DirEntry.Child = Children.Root.Value.DirEntry.SID;
            }
            catch (BSTDuplicatedException)
            {
                CompoundFile.ResetDirectoryEntry(cfo.DirEntry.SID);
                cfo = null;
                throw new CFDuplicatedItemException("An entry with name '" + streamName + "' is already present in storage '" + this.Name + "' ");
            }

            return(cfo as CFStream);
        }
コード例 #3
0
ファイル: CFStorage.cs プロジェクト: Notalib/OpenMCDF
        /// <summary>
        /// Create a new child stream inside the current <see cref="T:OpenMcdf.CFStorage">storage</see>
        /// </summary>
        /// <param name="streamName">The new stream name</param>
        /// <returns>The new <see cref="T:OpenMcdf.CFStream">stream</see> reference</returns>
        /// <exception cref="T:OpenMcdf.CFDuplicatedItemException">Raised when adding an item with the same name of an existing one</exception>
        /// <exception cref="T:OpenMcdf.CFDisposedException">Raised when adding a stream to a closed compound file</exception>
        /// <exception cref="T:OpenMcdf.CFException">Raised when adding a stream with null or empty name</exception>
        /// <example>
        /// <code>
        /// 
        ///  String filename = "A_NEW_COMPOUND_FILE_YOU_CAN_WRITE_TO.cfs";
        ///
        ///  CompoundFile cf = new CompoundFile();
        ///
        ///  CFStorage st = cf.RootStorage.AddStorage("MyStorage");
        ///  CFStream sm = st.AddStream("MyStream");
        ///  byte[] b = Helpers.GetBuffer(220, 0x0A);
        ///  sm.SetData(b);
        ///
        ///  cf.Save(filename);
        ///  
        /// </code>
        /// </example>
        public ICFStream AddStream(String streamName)
        {
            CheckDisposed();

            if (String.IsNullOrEmpty(streamName))
                throw new CFException("Stream name cannot be null or empty");

            CFStream cfo = null;


            // Add new Stream directory entry
            cfo = new CFStream(this.CompoundFile);
            cfo.DirEntry.SetEntryName(streamName);


            try
            {
                // Add object to Siblings tree
                this.Children.Add(cfo);

                //Rethread children tree...
                CompoundFile.RefreshIterative(Children.Root);

                //... and set the root of the tree as new child of the current item directory entry
                this.DirEntry.Child = Children.Root.Value.DirEntry.SID;
            }
            catch (BSTDuplicatedException)
            {
                CompoundFile.ResetDirectoryEntry(cfo.DirEntry.SID);
                cfo = null;
                throw new CFDuplicatedItemException("An entry with name '" + streamName + "' is already present in storage '" + this.Name + "' ");
            }

            return cfo as CFStream;
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the DynamicByteProvider class.
 /// </summary>
 /// <param name="bytes"></param>
 public StreamDataProvider(CFStream modifiedStream)
 {
     _bytes = new ByteCollection(modifiedStream.GetData());
     _modifiedStream = modifiedStream;
 }