Пример #1
0
 public override void Close()
 {
     stream.Commit(0);
     // Marshal.ReleaseComObject(stream);
     stream = null;
     GC.SuppressFinalize(this);
 }
Пример #2
0
 /// <summary>
 /// Flushes the stream
 /// </summary>
 public override void Flush()
 {
     if (fileStream == null)
     {
         throw new ObjectDisposedException("fileStream", "storage stream no longer available");
     }
     fileStream.Commit(0);
 }
Пример #3
0
 public override void Close()
 {
     if (originalStream_ != null)
     {
         originalStream_.Commit(0);
         // Marshal.ReleaseComObject( originalStream_ );
         originalStream_ = null;
         GC.SuppressFinalize(this);
     }
 }
Пример #4
0
        public HRESULT CreatePlaylist(IShellItemArray psia)
        {
            _ppd = new IProgressDialog();
            _ppd.StartProgressDialog(dwFlags: PROGDLG.PROGDLG_AUTOTIME);
            _ppd.SetTitle("Building Playlist");
            _ppd.SetLine(1, "Finding music files...", false);

            var pnsw = new INamespaceWalk();

            pnsw.Walk(psia, NAMESPACEWALKFLAG.NSWF_TRAVERSE_STREAM_JUNCTIONS | NAMESPACEWALKFLAG.NSWF_DONT_ACCUMULATE_RESULT, 4, this);
            _fCountingFiles = false;
            _ppd.SetLine(1, "Adding files...", false);
            _pstm = _GetPlaylistStream();
            var hr = WriteHeader();

            if (hr.Succeeded)
            {
                pnsw.Walk(psia, NAMESPACEWALKFLAG.NSWF_TRAVERSE_STREAM_JUNCTIONS | NAMESPACEWALKFLAG.NSWF_DONT_ACCUMULATE_RESULT | NAMESPACEWALKFLAG.NSWF_SHOW_PROGRESS, 4, this);
                hr = WriteFooter();
            }

            _pstm.Commit(0);

            if (hr.Succeeded)
            {
                var psiCreated = _GetPlaylistItem <IShellItem>();
                hr = OpenFolderAndSelectItem(psiCreated);
            }
            _ppd.StopProgressDialog();
            _ExitMessageLoop();
            return(0);
        }
Пример #5
0
        /// <include file='doc\WindowPane.uex' path='docs/doc[@for="WindowPane.IVsUIElementPane.SaveUIElementState"]/*' />
        /// <internalonly/>
        /// <devdoc>
        /// IVsUIElementPane implementation.
        /// </devdoc>
        int IVsUIElementPane.SaveUIElementState(IStream pstream)
        {
            Stream stateStream;

            int hresult = SaveUIState(out stateStream);

            if (ErrorHandler.Succeeded(hresult))
            {
                // Make sure the returned stream (if any) is properly disposed even if it's not readable or is empty
                using (stateStream)
                {
                    // If a stream was returned and is readable and have anything to read from it
                    if (stateStream != null && stateStream.CanRead && stateStream.Length > 0)
                    {
                        using (BinaryReader reader = new BinaryReader(stateStream))
                        {
                            byte[] bytes = new byte[stateStream.Length];
                            stateStream.Position = 0;
                            reader.Read(bytes, 0, bytes.Length);
                            uint written = 0;
                            pstream.Write(bytes, (uint)bytes.Length, out written);
                            pstream.Commit((uint)STGC.STGC_DEFAULT);
                        }
                    }
                }
            }

            return(hresult);
        }
Пример #6
0
 public override void Flush()
 {
     if (m_Commit)
     {
         const int STGC_DEFAULT = 0;
         m_ComStream.Commit(STGC_DEFAULT);
     }
 }
Пример #7
0
        /// <summary>
        /// When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
        /// </summary>
        /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
        public override void Flush()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("ComStreamWrapper");
            }

            _comStream.Commit(0);
        }
Пример #8
0
        /// <summary>
        /// When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
        /// </summary>
        /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
        public override void Flush()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_disposed)
            {
                throw new ObjectDisposedException("ComStreamWrapper");
            }

            _comStream.Commit(0);
        }
Пример #9
0
        public override void Flush()
        {
#if FEATURE_MUTABLE_COM_STREAMS
            _Validate();
            // Don't have enough context of the underlying object to reliably do anything here.
            try
            {
                _source.Commit(STGC_DEFAULT);
            }
            catch { }
#endif
        }
Пример #10
0
        public override void Flush()
        {
#if FEATURE_MUTABLE_COM_STREAMS
            _Validate();

            try
            {
                _source.Commit(STGC_DEFAULT);
            }
            catch { }
#endif
        }
Пример #11
0
        /// <summary>
        /// Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.
        /// </summary>
        public override void Close()
        {
            base.Close();

            if (stream == null)
            {
                return;
            }

            stream.Commit(0);  // STGC_DEFAULT
            System.Runtime.InteropServices.Marshal.ReleaseComObject(stream);
            stream = null;
        }
Пример #12
0
 public override void Flush()
 {
     if (_comStream != null)
     {
         try
         {
             _comStream.Commit(0);
         }
         catch (Exception)
         {
         }
     }
 }
Пример #13
0
 public override void Flush()
 {
     if (comStream != null)
     {
         try
         {
             comStream.Commit(StreamConsts.STGC_DEFAULT);
         }
         catch
         {
         }
     }
 }
Пример #14
0
 public override void Flush()
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     if (_comStream != null)
     {
         try
         {
             _comStream.Commit(0);
         }
         catch (Exception)
         {
         }
     }
 }
Пример #15
0
            private static Result CommitImpl(IntPtr thisPtr, CommitFlags flags)
            {
                Result result = Result.Ok;

                try
                {
                    IStreamShadow shadow   = ToShadow <IStreamShadow>(thisPtr);
                    IStream       callback = ((IStream)shadow.Callback);
                    callback.Commit(flags);
                }
                catch (SharpGenException exception)
                {
                    result = exception.ResultCode;
                }
                catch (Exception)
                {
                    result = Result.Fail.Code;
                }
                return(result);
            }
Пример #16
0
            public override void Flush()
            {
                HRESULT hr = _nativeStream.Commit(STGC.DEFAULT);

                Debug.Assert(hr == HRESULT.S_OK);
            }
Пример #17
0
        public void Upload(IWpdObject containerObject, string sourceFilePath, bool overwrite)
        {
            var fileInfo = new FileInfo(sourceFilePath);

            if ((fileInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
            {
                this.Upload(containerObject, sourceFilePath, overwrite, "*", true, false);
                return;
            }

            var fileName = Path.GetFileName(sourceFilePath);
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(sourceFilePath);
            var targetPath = containerObject.GetPath() + Path.DirectorySeparatorChar + fileName;

            var children = containerObject.GetChildren();

            foreach (var child in children)
            {
                if ((String.Compare(child.OriginalFileName, fileName, true) == 0))
                {
                    if (overwrite)
                    {
                        this.Delete(child);
                        break;
                    }
                    else
                    {
                        var ex = new IOException(String.Format("A file with the path \"{0}\" already exists on the device.", targetPath));

                        if (this.DataCopyError != null)
                        {
                            this.DataCopyError(this, new DataCopyErrorArgs(sourceFilePath, targetPath, ex));
                        }

                        throw ex;
                    }
                }
            }

            if (this.DataCopyStarted != null)
            {
                this.DataCopyStarted(this, new DataCopyStartedArgs(sourceFilePath, targetPath));
            }

            var values = new PortableDeviceTypesLib.PortableDeviceValues() as IPortableDeviceValues;

            // Parent ID of the new object.
            values.SetStringValue(ref PortableDevicePKeys.WPD_OBJECT_PARENT_ID, containerObject.ObjectID);

            // Size in bytes of the new object.
            values.SetUnsignedLargeIntegerValue(PortableDevicePKeys.WPD_OBJECT_SIZE, (ulong)fileInfo.Length);

            // The original file name of the object.
            values.SetStringValue(PortableDevicePKeys.WPD_OBJECT_ORIGINAL_FILE_NAME, fileName);

            // The name of the object on the device.
            values.SetStringValue(PortableDevicePKeys.WPD_OBJECT_NAME, fileNameWithoutExtension);

            IStream targetStream             = null;
            var     optimalTransferSizeBytes = 0U;

            containerObject.Content.CreateObjectWithPropertiesAndData(values, out targetStream, ref optimalTransferSizeBytes, null);

            try
            {
                using (var sourceStream = new FileStream(sourceFilePath, FileMode.Open, FileAccess.Read))
                {
                    var buffer       = new byte[optimalTransferSizeBytes];
                    var bytesRead    = 0;
                    var totalWritten = 0UL;

                    do
                    {
                        bytesRead = sourceStream.Read(buffer, 0, (int)optimalTransferSizeBytes);
                        if (bytesRead > 0)
                        {
                            var written = 0U;
                            targetStream.RemoteWrite(ref buffer[0], (uint)bytesRead, out written);
                            totalWritten += (ulong)written;

                            if (this.DataCopied != null)
                            {
                                this.DataCopied(this, new DataCopiedArgs(sourceFilePath, targetPath, (ulong)fileInfo.Length, totalWritten, (ulong)written));
                            }
                        }
                    }while (bytesRead > 0);
                }
                targetStream.Commit(0);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(String.Format("Failed to upload file \"{0}\": {1}", sourceFilePath, ex));

                if (this.DataCopyError != null)
                {
                    this.DataCopyError(this, new DataCopyErrorArgs(sourceFilePath, targetPath, ex));
                }
            }
            finally
            {
                if (targetStream != null)
                {
                    Marshal.ReleaseComObject(targetStream);
                }
            }

            if (this.DataCopyEnded != null)
            {
                this.DataCopyEnded(this, new DataCopyEndedArgs(sourceFilePath, targetPath));
            }
        }
Пример #18
0
        public override void Flush()
        {
            HResult hr = m_comStream.Commit(Misc.STGC.Default);

            hr.ThrowExceptionOnError();
        }
Пример #19
0
 /// <summary>
 /// When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
 /// </summary>
 /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception><filterpriority>2</filterpriority>
 public override void Flush()
 {
     _deviceStream.Commit(0);
 }
Пример #20
0
 public override void Flush()
 {
     stream.Commit(ShellAPI.STGC.DEFAULT);
 }
Пример #21
0
 public override void Flush()
 {
     _source.Commit(0);
 }
Пример #22
0
 public override void Flush()
 {
     Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
     _iStream.Commit(0);
 }
Пример #23
0
        /// <include file='doc\WindowPane.uex' path='docs/doc[@for="WindowPane.IVsUIElementPane.SaveUIElementState"]/*' />
        /// <internalonly/>
        /// <devdoc>
        /// IVsUIElementPane implementation.
        /// </devdoc>
        int IVsUIElementPane.SaveUIElementState(IStream pstream)
        {
            Stream stateStream;

            int hresult = SaveUIState(out stateStream);
            if (ErrorHandler.Succeeded(hresult))
            {
                // Make sure the returned stream (if any) is properly disposed even if it's not readable or is empty
                using (stateStream)
                {
                    // If a stream was returned and is readable and have anything to read from it
                    if (stateStream != null && stateStream.CanRead && stateStream.Length > 0)
                    {
                        using (BinaryReader reader = new BinaryReader(stateStream))
                        {
                            byte[] bytes = new byte[stateStream.Length];
                            stateStream.Position = 0;
                            reader.Read(bytes, 0, bytes.Length);
                            uint written = 0;
                            pstream.Write(bytes, (uint)bytes.Length, out written);
                            pstream.Commit((uint)STGC.STGC_DEFAULT);
                        }
                    }
                }
            }

            return hresult;
        }
Пример #24
0
 /// <summary>
 /// Commits data to be written to the stream if it is being cached.
 /// </summary>
 public override void Flush()
 {
     _stream.Commit((int)StorageStreamCommitOptions.None);
 }
Пример #25
0
 public override void Flush()
 {
     _stream.Commit(0);
 }