public NetworkConfigurationControl(NetworkConfiguration networkConfiguration)
            : this()
        {
            this.networkConfiguration = networkConfiguration;

            InitUI();
        }
        public static NetworkConfiguration CreateNewNetworkConfiguration()
        {
            var nc = new NetworkConfiguration();

            nc.Id = Guid.NewGuid();
            nc.Name = LanguageResources.NewNetworkName;
            nc.Active = true;

            // Pre populate
            string wlanSSID = string.Empty;
            string gateway = string.Empty;
            string gatewayMAC = string.Empty;
            string dnsSuffix = string.Empty;
            string ip = string.Empty;
            string location = string.Empty;

            NetworkManager.GetPrePopulatedNetworkMethods(out wlanSSID, out gateway, out gatewayMAC, out dnsSuffix, out ip, out location);

            // 1. Try WLAN
            if (!String.IsNullOrWhiteSpace(wlanSSID))
            {
                nc.Method = NetworkConfigurationMethod.WLANSSID;
                nc.Query = wlanSSID;
            }
            else
            {
                // 2. Try Gateway and DNS suffix
                if (!String.IsNullOrWhiteSpace(dnsSuffix))
                {
                    nc.Method = NetworkConfigurationMethod.DNSSuffix;
                    nc.Query = dnsSuffix;
                }
                else if (!String.IsNullOrWhiteSpace(gateway))
                {
                    nc.Method = NetworkConfigurationMethod.Gateway;
                    nc.Query = gateway;
                }
                else
                {
                    // 3. Try IP address
                    if (!String.IsNullOrWhiteSpace(ip))
                    {
                        nc.Method = NetworkConfigurationMethod.IP;
                        nc.Query = ip;
                    }
                }
            }

            return nc;
        }
        public NetworkTreeViewItem(NetworkConfiguration networkConfiguration, SwitcherActionBase[] actions)
            : base()
        {
            this.NetworkConfiguration = networkConfiguration;
            this.Header = CreateHeader();

            if (actions != null)
            {
                foreach (var item in actions)
                {
                    this.Items.Add(new ActionTreeViewItem(item, this));
                }
            }

            if (!this.NetworkConfiguration.Active)
                this.FontStyle = FontStyles.Italic;
        }
Esempio n. 4
0
        public void AddJumpTask(NetworkConfiguration nc)
        {
            JumpTask jumpTask1 = new JumpTask();

            string appPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

            jumpTask1.ApplicationPath = appPath;
            jumpTask1.IconResourcePath = appPath;
            jumpTask1.Arguments = "/activate " + nc.Id.ToString();
            jumpTask1.Title = nc.Name;
            jumpTask1.Description = string.Empty;
            jumpTask1.CustomCategory = LanguageResources.Networks_Label;

            JumpList jumpList = JumpList.GetJumpList(this.currentApp);
            if (jumpList == null)
            {
                jumpList = new JumpList();
                JumpList.SetJumpList(this.currentApp, jumpList);
            }

            jumpList.JumpItems.Add(jumpTask1);
        }
        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            if (this.networkConfiguration == null)
                this.networkConfiguration = new NetworkConfiguration();

            this.networkConfiguration.Name = textBoxName.Text;
            this.networkConfiguration.Query = textBoxQuery.Text;
            if (comboBoxMethod.SelectedItem != null)
                this.networkConfiguration.Method = ((NetworkConfigurationUIItem)comboBoxMethod.SelectedItem).Method;
            this.networkConfiguration.Active = checkBoxActive.IsChecked.Value;
            this.networkConfiguration.NetworkInterfaceId = ((ComboBoxItem)comboBoxSpecificNetworkInterface.SelectedItem).Tag.ToString();
            this.networkConfiguration.NetworkInterfaceName = ((ComboBoxItem)comboBoxSpecificNetworkInterface.SelectedItem).Content.ToString();

            if (buttonNetworkIcon.Tag != null && !String.IsNullOrEmpty(buttonNetworkIcon.Tag.ToString()))
                this.networkConfiguration.IconPath = buttonNetworkIcon.Tag.ToString();
            else
                this.networkConfiguration.IconPath = String.Empty;

            SettingsManager.Instance.SaveNetworkConfiguration(this.networkConfiguration);
        }
 public NetworkSwitchedEventArgs(NetworkConfiguration network)
     : base()
 {
     this.Network = network;
 }
 public UnknownNetworkTreeViewItem(NetworkConfiguration networkConfiguration, SwitcherActionBase[] actions)
     : base(networkConfiguration, actions)
 {
     this.Margin = new System.Windows.Thickness(0, 10, 0, 0);
     this.Header = LanguageResources.DeactivateNode_Name;
 }
        private void SetTaskbarTextAndIcon(string tooltipText, string ballonText, NetworkConfiguration network = null)
        {
            this.taskbarIcon.Tag = network;
            this.taskbarIcon.ToolTipText = tooltipText + " - Proxy Switcher";

            // highlight active network in context menu
            foreach (object item in this.taskbarIcon.ContextMenu.Items)
            {
                if (!(item is System.Windows.Controls.MenuItem))
                    continue;

                var mitem = item as System.Windows.Controls.MenuItem;

                if (mitem.Tag.ToString() == "AUTOSWITCH")
                    continue;

                if (network != null && mitem.Tag is Guid && (Guid)mitem.Tag == network.Id)
                    mitem.IsChecked = true;
                else
                    mitem.IsChecked = false;
            }

            // highlight tree item
            foreach (var item in this.treeViewNetworks.Items)
            {
                var nItem = item as NetworkTreeViewItem;
                if (nItem == null)
                    continue;

                if (network != null && nItem.NetworkId != SwitcherActionBase.DeactivateNetworkId && nItem.NetworkId == network.Id)
                    nItem.FontWeight = FontWeights.Bold;
                else
                    nItem.FontWeight = FontWeights.Normal;
            }

            if (network != null && !String.IsNullOrEmpty(network.IconPath) && network.IconPath.EndsWith(".ico"))
            {
                try
                {
                    SetTaskbarIcon(new System.Drawing.Icon(network.IconPath));
                }
                catch
                {
                    SetTaskbarIcon(new System.Drawing.Icon(Application.GetResourceStream(new Uri(this.Icon.ToString())).Stream));
                }
            }
            else
            {
                SetTaskbarIcon(new System.Drawing.Icon(Application.GetResourceStream(new Uri(this.Icon.ToString())).Stream));
            }

            this.taskbarIcon.ShowBalloonTip("Proxy Switcher", ballonText, BalloonIcon.Info);
        }
Esempio n. 9
0
        private void ActivateNetworkConfiguration(NetworkConfiguration nc)
        {
            if (CurrentNetworkConfigurationId == nc.Id)
                return;

            if (nc.Actions != null)
            {
                foreach (var actionId in nc.Actions)
                {
                    var action = this.addInManager.GetActionById(actionId);
                    if (action == null)
                        continue;

                    try
                    {
                        action.Activate(nc.Id, nc.Name);
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(String.Format("Action '{0}' could not be activated: {1}", actionId.ToString(), ex.Message), ex);
                    }
                }
            }

            CurrentNetworkConfigurationId = nc.Id;
            OnNetworkSwitched(nc);
        }
Esempio n. 10
0
 private void OnNetworkSwitched(NetworkConfiguration network)
 {
     if (NetworkSwitched != null)
         NetworkSwitched(this, new NetworkSwitchedEventArgs(network));
 }