Esempio n. 1
0
            public void GrantChannelAccess(IRDPSRAPIVirtualChannel channel)
            {
                if (channel == null)
                {
                    throw new ArgumentNullException("channel");
                }

                lock (grantedVirtualChannels)
                {
                    // do nothing if already granted
                    if (grantedVirtualChannels.ContainsKey(channel.Name))
                    {
                        Marshal.ReleaseComObject(channel);
                        return;
                    }

                    // add the channel
                    grantedVirtualChannels.Add(channel.Name, channel);
                }

                // grant channel access to all established connections (best effort)
                int[] attendeeIds;
                lock (connectionLock)
                {
                    attendeeIds = new int[connectedAttendeeIds.Count];
                    connectedAttendeeIds.CopyTo(attendeeIds, 0);
                }
                foreach (var attendeeId in attendeeIds)
                {
                    try { channel.SetAccess(attendeeId, CHANNEL_ACCESS_ENUM.CHANNEL_ACCESS_ENUM_SENDRECEIVE); }
                    catch { }
                }
            }
Esempio n. 2
0
            public static UserData FromAttendee(IRDPSRAPIAttendee attendee)
            {
                if (attendee == null)
                {
                    throw new ArgumentNullException("attendee");
                }

                // get the attendee's invitation
                var invitation = attendee.Invitation;

                try
                {
                    // find the user data that corresponds to the given connection string
                    UserData data;
                    lock (dataLock)
                        if (!byConnectionString.TryGetValue(invitation.ConnectionString, out data))
                        {
                            return(null);
                        }

                    // remove a pending connection or ensure the attendee is connected
                    PendingConnection pendingConnection;
                    lock (data.connectionLock)
                    {
                        if (!data.pendingConnections.TryGetValue(attendee.RemoteName, out pendingConnection))
                        {
                            return(data.connectedAttendeeIds.Contains(attendee.Id) ? data : null);
                        }
                        data.pendingConnections.Remove(attendee.RemoteName);
                        data.connectedAttendeeIds.Add(attendee.Id);
                    }
                    pendingConnection.TimeoutTimer.Dispose();

                    // set the initial control level
                    if (pendingConnection.InitialControlLevel != CTRL_LEVEL.CTRL_LEVEL_INVALID)
                    {
                        attendee.ControlLevel = pendingConnection.InitialControlLevel;
                    }

                    // enable all virtual channels
                    IRDPSRAPIVirtualChannel[] channels;
                    lock (data.grantedVirtualChannels)
                    {
                        channels = new IRDPSRAPIVirtualChannel[data.grantedVirtualChannels.Values.Count];
                        data.grantedVirtualChannels.Values.CopyTo(channels, 0);
                    }
                    foreach (var channel in channels)
                    {
                        try { channel.SetAccess(attendee.Id, CHANNEL_ACCESS_ENUM.CHANNEL_ACCESS_ENUM_SENDRECEIVE); }
                        catch { }
                    }

                    // return the data
                    return(data);
                }
                finally { Marshal.ReleaseComObject(invitation); }
            }