コード例 #1
0
        public HResult Stop()
        {
            Debug.WriteLine("StreamSink:Stop");

            lock (this)
            {
                HResult hr = CheckShutdown();
                if (hr.Failed())
                {
                    return(hr);
                }

                if (State == StreamState.TypeNotSet || State == StreamState.Finalized)
                {
                    return(MF_E_INVALIDREQUEST);
                }

                hr = QueueEvent(MediaEventType.MEStreamSinkStopped, Guid.Empty, S_OK, null);
                if (hr.Failed())
                {
                    return(hr);
                }

                State = StreamState.Stopped;
            }

            return(S_OK);
        }
コード例 #2
0
        /// <summary>
        /// Retrieves a string associated with a key.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="guidKey">Guid that identifies which value to retrieve.</param>
        /// <param name="value">Receives the string.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult GetString(this IMFAttributes attributes, Guid guidKey, out string value)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            value = null;

            int stringLength;

            HResult hr = attributes.GetStringLength(guidKey, out stringLength);

            if (hr.Failed())
            {
                return(hr);
            }

            StringBuilder sb = new StringBuilder(stringLength + 1);

            hr = attributes.GetString(guidKey, sb, sb.Capacity, out stringLength);
            if (hr.Failed())
            {
                return(hr);
            }

            value = sb.ToString();

            return(hr);
        }
コード例 #3
0
        public HResult Restart()
        {
            Debug.WriteLine("StreamSink:Restart");

            lock (this)
            {
                HResult hr = CheckShutdown();
                if (hr.Failed())
                {
                    return(hr);
                }

                if (State != StreamState.Paused)
                {
                    return(MF_E_INVALIDREQUEST);
                }

                hr = QueueEvent(MediaEventType.MEStreamSinkStarted, Guid.Empty, S_OK, null);
                if (hr.Failed())
                {
                    return(hr);
                }

                hr = QueueEvent(MediaEventType.MEStreamSinkRequestSample, Guid.Empty, S_OK, null);
                if (hr.Failed())
                {
                    return(hr);
                }

                State = StreamState.Started;
            }
            return(S_OK);
        }
コード例 #4
0
 public static void ThrowIfFailed(this HResult hr)
 {
     if (hr.Failed())
     {
         throw Marshal.GetExceptionForHR((int)hr);
     }
 }
コード例 #5
0
        /// <summary>
        /// Gets the native document from the running doc table given a document cookie.
        /// </summary>
        /// <param name="docCookie">Abstract value representing the document to be located.</param>
        /// <returns>
        /// The object representing the document if found, or <see langword="null" /> if not.
        /// </returns>
        public static Document GetDocumentFromCookie(uint docCookie)
        {
            uint         pgrfRDTFlags;
            uint         pdwReadLocks;
            uint         pdwEditLocks;
            string       pbstrMkDocument; // This will be the full file path to the document.
            IVsHierarchy ppHier;
            uint         pitemid;
            IntPtr       ppunkDocData;
            int          hresult = VisualStudioServices.VsRunningDocumentTable.GetDocumentInfo(
                docCookie,
                out pgrfRDTFlags,
                out pdwReadLocks,
                out pdwEditLocks,
                out pbstrMkDocument,
                out ppHier,
                out pitemid,
                out ppunkDocData);

            if (HResult.Failed(hresult))
            {
                return(null);
            }
            Document foundDoc = CodeRush.Documents.Get(pbstrMkDocument);

            // This is how you'd find the DTE document if you wanted it.
            //var foundDoc = VisualStudioServices.DTE.Documents.OfType<EnvDTE.Document>().Single(document => document.FullName.Equals(pbstrMkDocument));
            return(foundDoc);
        }
コード例 #6
0
 /// <summary>
 /// Throw a relevant exception if <paramref name="result"/> is a failure.
 /// </summary>
 /// <param name="path">Optional path or other input detail.</param>
 public static void ThrowIfFailed(this HResult result, string?path = null)
 {
     if (result.Failed())
     {
         result.Throw(path);
     }
 }
コード例 #7
0
 public static void ThrowIfFailed(this HResult result, string path = null)
 {
     if (result.Failed())
     {
         throw result.GetException(path);
     }
 }
コード例 #8
0
        public void Advise(object sink)
        {
            if (sink == null)
            {
                throw new ArgumentNullException("sink");
            }
            var handler = sink as IVsRunningDocTableEvents;

            if (handler == null)
            {
                throw new ArgumentException("The event sink must implement IVsRunningDocTableEvents.");
            }
            if (!Connected)
            {
                lock (_syncroot) {
                    if (Connected)
                    {
                        return;
                    }

                    int hresult = VisualStudioServices.VsRunningDocumentTable.AdviseRunningDocTableEvents(handler,
                                                                                                          out _cookie);
                    if (HResult.Failed(hresult))
                    {
                        Log.SendErrorWithStackTrace("Failed to advise IVsRunningDocTableEvents sink (0x{0:x8}).",
                                                    hresult);
                        return;
                    }

                    Connected = true;
                }
            }
        }
コード例 #9
0
 /// <summary>
 ///  Throw a relevant exception if <paramref name="result"/> is a failure.
 /// </summary>
 /// <param name="detail">Optional path or other input detail.</param>
 public static void ThrowIfFailed(this HResult result, string?detail = null)
 {
     if (result.Failed())
     {
         result.Throw(detail);
     }
 }
コード例 #10
0
        public HResult Shutdown()
        {
            Debug.WriteLine("StreamSink:Shutdown");

            lock (this)
            {
                HResult hr = CheckShutdown();
                if (Failed(hr))
                {
                    return(hr);
                }

                if (EventQueue != null)
                {
                    hr = EventQueue.Shutdown();
                    if (hr.Failed())
                    {
                        Debug.WriteLine("Could not shutdown EventQueue: " + hr.ToString() + " " + hr.GetDescription());
                        Debug.WriteLine("EventQueue Shutdown: " + hr.ToString() + " " + hr.GetDescription());
                    }
                }

                SafeRelease(MediaType);
                MediaType = null;

                SafeRelease(BaseSink);
                BaseSink = null;

                SafeRelease(EventQueue);
                EventQueue = null;

                State = StreamState.Finalized;
            }
            return(S_OK);
        }
コード例 #11
0
        /// <summary>
        /// Coes the set proxy blanket.
        /// </summary>
        /// <param name="proxy">The proxy.</param>
        /// <param name="dwAuthnSvc">The dw authn SVC.</param>
        /// <param name="dwAuthzSvc">The dw authz SVC.</param>
        /// <param name="pServerPrincName">Name of the p server princ.</param>
        /// <param name="dwAuthnLevel">The dw authn level.</param>
        /// <param name="dwImpLevel">The dw imp level.</param>
        /// <param name="pAuthInfo">The p authentication information.</param>
        /// <param name="dwCapababilities">The dw capababilities.</param>
        /// <param name="throwOnError">if set to <c>true</c> [throw on error].</param>
        /// <returns>System.Int32.</returns>
        /// <exception cref="COMException">CoSetProxyBlanket failed with HRESULT {hr:X}</exception>
        private static int CoSetProxyBlanket(IntPtr proxy,
                                             uint dwAuthnSvc,
                                             uint dwAuthzSvc,
                                             string pServerPrincName,
                                             RpcAuthnLevel dwAuthnLevel,
                                             RpcImpLevel dwImpLevel,
                                             IntPtr pAuthInfo,
                                             OleAuthCapabilities dwCapababilities,
                                             bool throwOnError)
        {
            //should be called once for process to be able to call into ecs com api's
            int hr = Win32Helper.CoSetProxyBlanket(
                proxy,
                dwAuthnSvc,
                dwAuthzSvc,
                pServerPrincName,
                dwAuthnLevel,
                dwImpLevel,
                pAuthInfo,
                dwCapababilities);

            //expected is 0
            if (HResult.Failed(hr) && throwOnError)
            {
                throw new COMException($"{StorageSyncResources.ComError1} {hr:X}");
            }

            return(hr);
        }
コード例 #12
0
        private static void HandleComReturn(int hr)
        {
            if (!HResult.Failed(hr))
            {
                return;
            }
            if (hr == -2147213311)
            {
                throw new OperationCanceledException();
            }
            var exceptionForHr = Marshal.GetExceptionForHR(hr);

            throw new Exception(exceptionForHr.Message, exceptionForHr);
        }
コード例 #13
0
        private static bool Found(HResult hr)
        {
            if (hr.Failed())
            {
                if (hr == HResult.ElementNotFound || hr == HResult.InvalidArgument)
                {
                    return(false);
                }

                Marshal.ThrowExceptionForHR((int)hr);
            }

            return(true);
        }
コード例 #14
0
        public void Unadvise()
        {
            if (Connected)
            {
                lock (_syncroot) {
                    if (!Connected)
                    {
                        return;
                    }

                    int hresult = VisualStudioServices.VsRunningDocumentTable.UnadviseRunningDocTableEvents(_cookie);
                    if (HResult.Failed(hresult))
                    {
                        Log.SendErrorWithStackTrace("Failed to unadvise IVsRunningDocTableEvents sink (0x{0:x8}).",
                                                    hresult);
                        return;
                    }

                    Connected = false;
                    _cookie   = 0;
                }
            }
        }
コード例 #15
0
        public void Unadvise()
        {
            if (this.Connected)
            {
                lock (this._syncroot)
                {
                    if (!this.Connected)
                    {
                        return;
                    }

                    int hresult = VisualStudioServices.VsRunningDocumentTable.UnadviseRunningDocTableEvents(this._cookie);
                    if (HResult.Failed(hresult))
                    {
                        DevExpress.CodeRush.Diagnostics.Interop.Log.SendErrorWithStackTrace("Failed to unadvise IVsRunningDocTableEvents sink (0x{0:x8}).", hresult);
                        return;
                    }

                    this.Connected = false;
                    this._cookie   = 0;
                }
            }
        }