Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(931)

Side by Side Diff: obsolete/Microsoft.VisualStudio.Project/Misc/ConnectionPointContainer.cs

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /// Copyright (c) Microsoft Corporation. All rights reserved.
2
3 using System;
4 using System.Collections.Generic;
5 using System.Runtime.InteropServices;
6 using Microsoft.VisualStudio;
7 using Microsoft.VisualStudio.OLE.Interop;
8
9 namespace Microsoft.VisualStudio.Project
10 {
11 /// <summary>
12 /// Class used to identify a source of events of type SinkType.
13 /// </summary>
14 [ComVisible(false)]
15 internal interface IEventSource<SinkType>
16 where SinkType : class
17 {
18 void OnSinkAdded(SinkType sink);
19 void OnSinkRemoved(SinkType sink);
20 }
21
22 [ComVisible(true)]
23 public class ConnectionPointContainer : IConnectionPointContainer
24 {
25 private Dictionary<Guid, IConnectionPoint> connectionPoints;
26 internal ConnectionPointContainer()
27 {
28 connectionPoints = new Dictionary<Guid, IConnectionPoint >();
29 }
30 internal void AddEventSource<SinkType>(IEventSource<SinkType> so urce)
31 where SinkType : class
32 {
33 if(null == source)
34 {
35 throw new ArgumentNullException("source");
36 }
37 if(connectionPoints.ContainsKey(typeof(SinkType).GUID))
38 {
39 throw new ArgumentException("EventSource guid al ready added to the list of connection points", "source");
40 }
41 connectionPoints.Add(typeof(SinkType).GUID, new Connecti onPoint<SinkType>(this, source));
42 }
43
44 #region IConnectionPointContainer Members
45 void IConnectionPointContainer.EnumConnectionPoints(out IEnumCon nectionPoints ppEnum)
46 {
47 throw new NotImplementedException(); ;
48 }
49 void IConnectionPointContainer.FindConnectionPoint(ref Guid riid , out IConnectionPoint ppCP)
50 {
51 ppCP = connectionPoints[riid];
52 }
53 #endregion
54 }
55
56 internal class ConnectionPoint<SinkType> : IConnectionPoint
57 where SinkType : class
58 {
59 Dictionary<uint, SinkType> sinks;
60 private uint nextCookie;
61 private ConnectionPointContainer container;
62 private IEventSource<SinkType> source;
63 internal ConnectionPoint(ConnectionPointContainer container, IEv entSource<SinkType> source)
64 {
65 if(null == container)
66 {
67 throw new ArgumentNullException("container");
68 }
69 if(null == source)
70 {
71 throw new ArgumentNullException("source");
72 }
73 this.container = container;
74 this.source = source;
75 sinks = new Dictionary<uint, SinkType>();
76 nextCookie = 1;
77 }
78 #region IConnectionPoint Members
79 public void Advise(object pUnkSink, out uint pdwCookie)
80 {
81 SinkType sink = pUnkSink as SinkType;
82 if(null == sink)
83 {
84 Marshal.ThrowExceptionForHR(VSConstants.E_NOINTE RFACE);
85 }
86 sinks.Add(nextCookie, sink);
87 pdwCookie = nextCookie;
88 source.OnSinkAdded(sink);
89 nextCookie += 1;
90 }
91
92 public void EnumConnections(out IEnumConnections ppEnum)
93 {
94 throw new NotImplementedException(); ;
95 }
96
97 public void GetConnectionInterface(out Guid pIID)
98 {
99 pIID = typeof(SinkType).GUID;
100 }
101
102 public void GetConnectionPointContainer(out IConnectionPointCont ainer ppCPC)
103 {
104 ppCPC = this.container;
105 }
106
107 public void Unadvise(uint dwCookie)
108 {
109 // This will throw if the cookie is not in the list.
110 SinkType sink = sinks[dwCookie];
111 sinks.Remove(dwCookie);
112 source.OnSinkRemoved(sink);
113 }
114 #endregion
115 }
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698