Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class FrmMain : Form
- {
- public FrmMain()
- {
- InitializeComponent();
- InitializeNetworkConnectionChecks();
- InitializeConnectionTimer();
- }
- private LyncClient client;
- private ConversationManager conversationManager;
- private Timer connectionTimer;
- private bool networkAvailable;
- private void InitializeNetworkConnectionChecks()
- {
- NetworkChange.NetworkAddressChanged += NetworkAddress_Changed;
- NetworkChange.NetworkAvailabilityChanged += NetworkAvailability_Changed;
- }
- private void InitializeConnectionTimer()
- {
- connectionTimer = new Timer
- {
- Interval = 1000
- };
- connectionTimer.Tick += connectionTimer_Tick;
- connectionTimer.Start();
- }
- private void CheckConnection()
- {
- CheckNetworkConnection();
- TrySetClient();
- SetConversationManager();
- }
- private void CheckNetworkConnection()
- {
- networkAvailable = NetworkInterface.GetIsNetworkAvailable();
- }
- private void TrySetClient()
- {
- client = null;
- try
- {
- client = LyncClient.GetClient();
- client.ClientDisconnected += Client_Disconnected;
- client.StateChanged += Client_StateChanged;
- }
- catch (Exception)
- {
- }
- }
- private void SetConversationManager()
- {
- if (client != null)
- {
- conversationManager = client.ConversationManager;
- conversationManager.ConversationAdded += Conversation_Added;
- conversationManager.ConversationRemoved += Conversation_Removed;
- }
- else
- {
- conversationManager = null;
- }
- }
- private void Client_Disconnected(object sender, EventArgs e)
- {
- CheckConnection();
- }
- private void Client_StateChanged(object sender, ClientStateChangedEventArgs e)
- {
- CheckConnection();
- }
- private void connectionTimer_Tick(object sender, EventArgs e)
- {
- CheckConnection();
- }
- private void Conversation_Added(object sender, ConversationManagerEventArgs e)
- {
- System.Diagnostics.Process.Start("https://www.google.com/");
- }
- private void Conversation_Removed(object sender, ConversationManagerEventArgs e)
- {
- // ...
- }
- private void NetworkAddress_Changed(object sender, EventArgs e)
- {
- CheckConnection();
- }
- private void NetworkAvailability_Changed(object sender, EventArgs e)
- {
- CheckConnection();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement