Exemplo n.º 1
0
 /// <summary>
 /// Writes bytes to the stream
 /// </summary>
 /// <param name="buffer">byte array which contains the bytes to write</param>
 /// <param name="offset">offset where to write the bytes</param>
 /// <param name="count">number of bytes to write</param>
 public override void Write(byte[] buffer, int offset, int count)
 {
     if (fileStream == null)
     {
         throw new ObjectDisposedException("theStream");
     }
     if (offset != 0)
     {
         int    i  = (int)buffer.Length - offset;
         byte[] bs = new byte[i];
         Array.Copy(buffer, offset, bs, 0, i);
         fileStream.Write(bs, i, IntPtr.Zero);
         return;
     }
     fileStream.Write(buffer, count, IntPtr.Zero);
 }
Exemplo n.º 2
0
        void UCOMIStream.CopyTo(UCOMIStream destination, long count, IntPtr pcbRead, IntPtr pcbWritten)
        {
            //////////
            // Copy the lot using 4k chunks
            //////////
            byte [] _buffer    = new byte[4096];
            int     _cbRead    = 0;
            int     _cbWritten = 0;

            while (count > 0)
            {
                int _chunk     = (int)Math.Min(count, _buffer.Length);
                int _chunkRead = this.Read(_buffer, _cbRead, _chunk);
                destination.Write(_buffer, _chunk, IntPtr.Zero);

                _cbRead    += _chunkRead;
                _cbWritten += _chunkRead;
            }

            //////////
            // Update the counts, if they were provided
            //////////
            if (pcbRead != IntPtr.Zero)
            {
                Marshal.WriteInt64(pcbRead, _cbRead);
            }

            if (pcbWritten != IntPtr.Zero)
            {
                Marshal.WriteInt64(pcbWritten, _cbWritten);
            }
        }
Exemplo n.º 3
0
        void foo(UCOMIStream iStream)
        {
            // Load the Encrypted file into a stream.
            FileStream fsIn = new FileStream("C:\\test.pdf", FileMode.Open, FileAccess.Read);

            // Create a MemoryStream to hold the decrypted data.
            MemoryStream ms = new MemoryStream();

            // Create a reader for the data.
            BinaryReader r = new BinaryReader(ms);

            // Get length of the file.
            int fileLen = Convert.ToInt32(ms.Length);

            // Create a buffer for the data.
            byte[] fileBytes = new byte[fileLen];

            // Read the data from Memory
            for (int i = 0; i < fileLen; i++)
            {
                fileBytes[i] = r.ReadByte();
            }

            // declare the COM stream
            //UCOMIStream iStream;

            // Write the data from buffer into COM Stream
            iStream.Write(fileBytes, fileLen, System.IntPtr.Zero);

            // Set size of COM stream
            iStream.SetSize(fileLen);
        }
Exemplo n.º 4
0
        void UCOMIStream.CopyTo(UCOMIStream destination, long count, IntPtr pcbRead, IntPtr pcbWritten)
        {
            //////////
            // Copy the lot using 4k chunks
            //////////
            byte [] _buffer = new byte[4096];
            int _cbRead = 0;
            int _cbWritten = 0;
            while (count > 0)
            {
                int _chunk = (int)Math.Min(count, _buffer.Length);
                int _chunkRead = this.Read(_buffer, _cbRead, _chunk);
                destination.Write(_buffer, _chunk, IntPtr.Zero);

                _cbRead += _chunkRead;
                _cbWritten += _chunkRead;
            }

            //////////
            // Update the counts, if they were provided
            //////////
            if (pcbRead != IntPtr.Zero)
            {
                Marshal.WriteInt64(pcbRead, _cbRead);
            }

            if (pcbWritten != IntPtr.Zero)
            {
                Marshal.WriteInt64(pcbWritten, _cbWritten);
            }
        }
Exemplo n.º 5
0
        // Not used - But there are things here that may be useful some day
#if false
        void TestSave2()
        {
            int         hr;
            UCOMIStream uis = null;
            long        siz;

            hr = m_ips.GetSizeMax(out siz);
            myIStorage iStore = null;

            hr = StgCreateDocfile(@"C:\foo.out",
                                  //STGM.DIRECT|STGM.CREATE|STGM.READWRITE|STGM.SHARE_EXCLUSIVE,
                                  STGM.CREATE | STGM.WRITE | STGM.SHARE_EXCLUSIVE,
                                  0,
                                  ref iStore);
            DsError.ThrowExceptionForHR(hr);
            uis = iStore as UCOMIStream;

            //hr = iStore.CreateStream("asdf", STGM.DIRECT|STGM.CREATE|STGM.READWRITE|STGM.SHARE_EXCLUSIVE, 0, 0, out uis);
            hr = iStore.CreateStream("asdf", STGM.CREATE | STGM.WRITE | STGM.SHARE_EXCLUSIVE, 0, 0, out uis);

            hr = OleSaveToStream(m_ips, uis);

            hr = StgCreateStorageEx(@"c:\foo.out",
                                    (STGM)0,
                                    (STGFMT)0,
                                    0,
                                    IntPtr.Zero,
                                    IntPtr.Zero,
                                    typeof(myIStorage).GUID,
                                    ref iStore);
            DsError.ThrowExceptionForHR(hr);

            string s = typeof(UCOMIStream).GUID.ToString();

            // Create the stream (with no initial memory allocated)
            IntPtr ip = Marshal.AllocCoTaskMem((int)siz);

            ip = GlobalAlloc(0, (int)siz);
            hr = CreateStreamOnHGlobal(ip, false, out uis);
            //uis.SetSize(siz * 2);

            byte[] b = new byte[3];
            b[0] = 65;
            b[1] = 66;
            b[2] = 67;

            uis.Write(b, b.Length, IntPtr.Zero);

            hr = m_ips.Save(uis, true);
            DsError.ThrowExceptionForHR(hr);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Called to save the settings data to the given stream.
        /// </summary>
        /// <param name="stm">stream to save the settings to</param>
        /// <param name="clearDirty">if true, clear our 'dirty' flag</param>
        public void Save(UCOMIStream stm, bool clearDirty)
        {
            MemoryStream memStream = new MemoryStream();
            BinaryWriter binWriter = new BinaryWriter(memStream);

            // first our version
            binWriter.Write(dataVersion);
            // then the data.
            binWriter.Write(itemStart);
            // cleanup
            binWriter.Flush();

            // write to actual output stream
            byte[] data = memStream.ToArray();
            stm.Write(data, data.Length, IntPtr.Zero);

            if (clearDirty)
            {
                isDirty = false;
            }
        }
Exemplo n.º 7
0
 public void Write(byte[] data)
 {
     _Stream.Write(data, data.Length, IntPtr.Zero);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Called to save the settings data to the given stream.
        /// </summary>
        /// <param name="stm">stream to save the settings to</param>
        /// <param name="clearDirty">if true, clear our 'dirty' flag</param>
        public void Save(UCOMIStream stm, bool clearDirty)
        {
            MemoryStream memStream = new MemoryStream();
              BinaryWriter binWriter = new BinaryWriter(memStream);

              // first our version
              binWriter.Write(dataVersion);
              // then the data.
              binWriter.Write(itemStart);
              // cleanup
              binWriter.Flush();

              // write to actual output stream
              byte[] data = memStream.ToArray();
              stm.Write(data, data.Length, IntPtr.Zero);

              if (clearDirty)
            isDirty = false;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Called to save the settings data to the given stream.
        /// </summary>
        /// <param name="stm">stream to save the settings to</param>
        /// <param name="clearDirty">if true, clear our 'dirty' flag</param>
        public void Save(UCOMIStream stm, bool clearDirty)
        {
            try
            {
            MemoryStream memStream = new MemoryStream();
            BinaryWriter binWriter = new BinaryWriter(memStream);

            // first our version
            binWriter.Write(dataVersion);
            // then the data.

            // cleanup
            binWriter.Flush();

            // write to actual output stream
            byte[] data = memStream.ToArray();
            stm.Write(data, data.Length, IntPtr.Zero);

            if (clearDirty)
                isDirty = false;
            }
            catch (Exception E)
            {
                Log.Error("Save Error "+E.Message);
            }
        }