/// <summary> /// Initializes a new instance of the HostSessionEventArgs class. /// </summary> /// <param name="session">See <see cref="Lebowski.Net.HostSessionEventArgs.Session">Session</see></param> /// <param name="connection">See <see cref="Lebowski.Net.HostSessionEventArgs.Connection">Connection</see></param> public HostSessionEventArgs(ISynchronizationSession session, IConnection connection) { Session = session; Connection = connection; }
/// <inheritdoc/> /// <remarks> /// Calling this will display a form to the user to enter sharing /// settings. /// </remarks> public void Share(ISynchronizationSession session) { TcpShareForm form = new TcpShareForm(); form.Submit += delegate { form.Enabled = false; session.State = SessionStates.AwaitingConnection; form.Invoke((Action) delegate { form.Dispose(); }); TcpServerConnection connection = new TcpServerConnection(form.Port); connection.ClientConnected += delegate { OnHostSession(new HostSessionEventArgs(session, connection)); }; }; form.ShowDialog(); }
/// <inheritdoc/> public void Share(ISynchronizationSession session) { if(!isInitialized) { throw new ConnectionFailedException("The Skype API is not yet initialized or Skype rejected our API requests."); } UpdateFriends(); SkypeShareForm form = new SkypeShareForm(this); Exception lastException = null; form.Submit += delegate { // TODO: calls to Share should be made asynchronously, so the UI doesn't block /* As skype does not report when a session is closed, we might at this point think that we have already established a connection to a user, but it will fail at the Send(...) call. Therefore, we have to allow for 2 connection attempts before giving up */ bool succeeded = false; for(int attempt = 1; attempt <= 2 && !succeeded; ++attempt) { try { int maxWaitTime = 5000; // Create channel for this session SkypeConnection connection = Connect(form.SelectedUser, maxWaitTime); if(connection == null) { throw new ConnectionFailedException(string.Format("Could not connect to Skype user {0}", form.SelectedUser)); } // Send out the invite SharingInvitationMessage invitationMessage = new SharingInvitationMessage(++numInvitations, session.FileName, form.SelectedUser, connection.IncomingChannel); invitations[invitationMessage.InvitationId] = invitationMessage; invitationChannels[invitationMessage.InvitationId] = connection; invitationSessions[invitationMessage.InvitationId] = session; Send(form.SelectedUser, ApplicationConnectionId, invitationMessage); succeeded = true; } catch(Exception e) { lastException = e; } } if(!succeeded) { throw lastException; } session.State = SessionStates.AwaitingConnection; form.Close(); }; form.ShowDialog(); }