Example #1
0
        /// <summary>
        /// Returns a list of all ip and mac results
        /// </summary>
        /// <param name="iconTheme">The theme to use for the icons</param>
        /// <param name="culture">The culture to use for the result's title and sub title</param>
        /// <returns>The list of available results</returns>
        internal static List <Result> GetNetworkConnectionResults(string iconTheme, CultureInfo culture)
        {
            var results = new List <Result>();

            var interfaces = NetworkInterface.GetAllNetworkInterfaces().Where(x => x.NetworkInterfaceType != NetworkInterfaceType.Loopback && x.GetPhysicalAddress() != null);

            foreach (NetworkInterface i in interfaces)
            {
                NetworkConnectionProperties intInfo = new NetworkConnectionProperties(i);

                if (!string.IsNullOrEmpty(intInfo.IPv4))
                {
                    results.Add(new Result()
                    {
                        Title       = intInfo.IPv4,
                        SubTitle    = string.Format(CultureInfo.InvariantCulture, Resources.ResourceManager.GetString("Microsoft_plugin_sys_ip4_description", culture), intInfo.ConnectionName) + " - " + Resources.ResourceManager.GetString("Microsoft_plugin_sys_SubTitle_CopyHint", culture),
                        IcoPath     = $"Images\\networkAdapter.{iconTheme}.png",
                        ToolTipData = new ToolTipData(Resources.Microsoft_plugin_sys_ConnectionDetails, intInfo.GetConnectionDetails()),
                        ContextData = new SystemPluginContext {
                            Type = ResultContextType.NetworkAdapterInfo, Data = intInfo.GetConnectionDetails()
                        },
                        Action = _ => ResultHelper.CopyToClipBoard(intInfo.IPv4),
                    });
                }

                if (!string.IsNullOrEmpty(intInfo.IPv6Primary))
                {
                    results.Add(new Result()
                    {
                        Title       = intInfo.IPv6Primary,
                        SubTitle    = string.Format(CultureInfo.InvariantCulture, Resources.ResourceManager.GetString("Microsoft_plugin_sys_ip6_description", culture), intInfo.ConnectionName) + " - " + Resources.ResourceManager.GetString("Microsoft_plugin_sys_SubTitle_CopyHint", culture),
                        IcoPath     = $"Images\\networkAdapter.{iconTheme}.png",
                        ToolTipData = new ToolTipData(Resources.Microsoft_plugin_sys_ConnectionDetails, intInfo.GetConnectionDetails()),
                        ContextData = new SystemPluginContext {
                            Type = ResultContextType.NetworkAdapterInfo, Data = intInfo.GetConnectionDetails()
                        },
                        Action = _ => ResultHelper.CopyToClipBoard(intInfo.IPv6Primary),
                    });
                }

                if (!string.IsNullOrEmpty(intInfo.PhysicalAddress))
                {
                    results.Add(new Result()
                    {
                        Title       = intInfo.PhysicalAddress,
                        SubTitle    = string.Format(CultureInfo.InvariantCulture, Resources.ResourceManager.GetString("Microsoft_plugin_sys_mac_description", culture), intInfo.Adapter, intInfo.ConnectionName) + " - " + Resources.ResourceManager.GetString("Microsoft_plugin_sys_SubTitle_CopyHint", culture),
                        IcoPath     = $"Images\\networkAdapter.{iconTheme}.png",
                        ToolTipData = new ToolTipData(Resources.Microsoft_plugin_sys_AdapterDetails, intInfo.GetAdapterDetails()),
                        ContextData = new SystemPluginContext {
                            Type = ResultContextType.NetworkAdapterInfo, Data = intInfo.GetAdapterDetails()
                        },
                        Action = _ => ResultHelper.CopyToClipBoard(intInfo.PhysicalAddress),
                    });
                }
            }

            return(results);
        }
Example #2
0
        /// <summary>
        /// Returns a list of all ip and mac results
        /// </summary>
        /// <param name="iconTheme">The theme to use for the icons</param>
        /// <param name="culture">The culture to use for the result's title and sub title</param>
        /// <returns>The list of available results</returns>
        internal static List <Result> GetNetworkConnectionResults(string iconTheme, CultureInfo culture)
        {
            var results = new List <Result>();

            // We update the cache only if the last query is older than 'updateCacheIntervalSeconds' seconds
            DateTime timeOfLastNetworkQueryBefore = timeOfLastNetworkQuery;

            timeOfLastNetworkQuery = DateTime.Now;             // Set time of last query to this query
            if ((timeOfLastNetworkQuery - timeOfLastNetworkQueryBefore).TotalSeconds >= UpdateCacheIntervalSeconds)
            {
                networkPropertiesCache = NetworkConnectionProperties.GetList();
            }

            foreach (NetworkConnectionProperties intInfo in networkPropertiesCache)
            {
                if (!string.IsNullOrEmpty(intInfo.IPv4))
                {
                    results.Add(new Result()
                    {
                        Title       = intInfo.IPv4,
                        SubTitle    = string.Format(CultureInfo.InvariantCulture, Resources.ResourceManager.GetString("Microsoft_plugin_sys_ip4_description", culture), intInfo.ConnectionName) + " - " + Resources.ResourceManager.GetString("Microsoft_plugin_sys_SubTitle_CopyHint", culture),
                        IcoPath     = $"Images\\networkAdapter.{iconTheme}.png",
                        ToolTipData = new ToolTipData(Resources.Microsoft_plugin_sys_ConnectionDetails, intInfo.GetConnectionDetails()),
                        ContextData = new SystemPluginContext {
                            Type = ResultContextType.NetworkAdapterInfo, Data = intInfo.GetConnectionDetails()
                        },
                        Action = _ => ResultHelper.CopyToClipBoard(intInfo.IPv4),
                    });
                }

                if (!string.IsNullOrEmpty(intInfo.IPv6Primary))
                {
                    results.Add(new Result()
                    {
                        Title       = intInfo.IPv6Primary,
                        SubTitle    = string.Format(CultureInfo.InvariantCulture, Resources.ResourceManager.GetString("Microsoft_plugin_sys_ip6_description", culture), intInfo.ConnectionName) + " - " + Resources.ResourceManager.GetString("Microsoft_plugin_sys_SubTitle_CopyHint", culture),
                        IcoPath     = $"Images\\networkAdapter.{iconTheme}.png",
                        ToolTipData = new ToolTipData(Resources.Microsoft_plugin_sys_ConnectionDetails, intInfo.GetConnectionDetails()),
                        ContextData = new SystemPluginContext {
                            Type = ResultContextType.NetworkAdapterInfo, Data = intInfo.GetConnectionDetails()
                        },
                        Action = _ => ResultHelper.CopyToClipBoard(intInfo.IPv6Primary),
                    });
                }

                if (!string.IsNullOrEmpty(intInfo.PhysicalAddress))
                {
                    results.Add(new Result()
                    {
                        Title       = intInfo.PhysicalAddress,
                        SubTitle    = string.Format(CultureInfo.InvariantCulture, Resources.ResourceManager.GetString("Microsoft_plugin_sys_mac_description", culture), intInfo.Adapter, intInfo.ConnectionName) + " - " + Resources.ResourceManager.GetString("Microsoft_plugin_sys_SubTitle_CopyHint", culture),
                        IcoPath     = $"Images\\networkAdapter.{iconTheme}.png",
                        ToolTipData = new ToolTipData(Resources.Microsoft_plugin_sys_AdapterDetails, intInfo.GetAdapterDetails()),
                        ContextData = new SystemPluginContext {
                            Type = ResultContextType.NetworkAdapterInfo, Data = intInfo.GetAdapterDetails()
                        },
                        Action = _ => ResultHelper.CopyToClipBoard(intInfo.PhysicalAddress),
                    });
                }
            }

            return(results);
        }