Click here to Skip to main content
15,892,298 members
Articles / Programming Languages / C#

Network Assistant for mobile PCs

Rate me:
Please Sign up or sign in to vote.
4.86/5 (3 votes)
21 Apr 2007Public Domain8 min read 40.9K   366   33  
A small tool that reacts to change in your network environment and changes your settings accordingly.
using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using System.Xml;

namespace NAst.Common
{
    /// <summary>
    /// Test if the MobilePC is connected to a network
    /// </summary>
    public class IsConnectedTester : INetworkTest
    {
        private bool _expectedValue = false;
        
        #region INetworkTest Members

        /// <summary>
        /// Check if the current network availability
        /// equals the expected availability.
        /// </summary>
        /// <returns></returns>
        public bool Test()
        {
            return System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() == _expectedValue;
        }

        public void Initialize(string stateName, XmlElement config)
        {
            string val = config.GetAttribute("value");
            if (val.Equals("true", StringComparison.InvariantCultureIgnoreCase)
                || val.Equals("true", StringComparison.InvariantCultureIgnoreCase))
            {
                _expectedValue = true;
            }
        }
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Web Developer
France France
I'm french, do I need to say more ?

Comments and Discussions