网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > C# > 正文
C# Server Enumerator
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/14
下载{$ArticleTitle}原创论文样式

Introduction

needing to list servers for a project I was working on, Marty Cerisano''s article A C# Server Drop-down Control seemed perfect. Downloading and attempting to compile left me a little frustrated. The original code appears to be developed under a BETA version of Visual Studio .NET and would not compile under the released version. (MarshalAs.LPVoid was not defined, this has been updated in his May 30, 2002 release of his code).

i decided to rewrite the code and make it a bit more modular. I separated the code to enumerate the servers to it''s own class. I removed the use of pointers and removed the use of the unsafe block.

the tricky part I found was removing the pointer use. Calculating the offset in the structure and using the Marshal.PtrToStructure() method to get correct data took some digging into the class library documentation.

there are three classes and an enumeration. They are:

  • ServerType - Enumeration listing possible server types, such as SQL Server or Terminal Server. ServerTypes can be logically OR''ed, i.e. the ServerType has the Flags attribute.
  • Servers - Collection of servers of specified type. Implements IEnumerable which allows foreach to be used.
  • ServerEnumerator - Enumerator to loop over the list of servers.
  • ServerComboBox - Example ComboBox control that uses the other classes.

Notes

  • The code will not allow you to get a list based on an AND conjunction. For example, you cannot ask for all SQL Servers that also are Terminal Servers. Attempting this, you will only get back a list of all server that are SQL Servers OR Terminal Servers. (It may be true that your SQL Server is also Terminal Server). You will have to manually query for each type and perform the intersection operation manually.
  • The AutoRefresh property will not automatically rescan the network. Setting AutoRefresh to true will cause any changes to the ServerType property to automatically call the Refresh() method. This is not an auto update setting.

Running the demo application

  1. Download both the source and the demo application.
  2. Extract each zip file to the same parent folder.
  3. Open the the source''s solution and build.
  4. Open the demo''s solution, build and run.

Using the Servers collection

using System;using NetworkManagement;        //// List all the SQL Server database to the // console (using foreach)//Servers servers = new Servers( ServerType.SQLServer );foreach (String name in servers){    Console.WriteLine(name);}//// List all the Domains to the console.//Servers servers = new Servers( ServerType.DomainEnum );IEnumerator i = servers.GetEnumerator()while ( i.MoveNext() ){    string domainName = (string) i.Current;    Console.WriteLine(domainName);}

Using the ServerComboBox

using System;using NetworkManagement;        public class ServerComboBoxForm : System.Windows.Forms.Form{    private ServerComboBox sCombo1;    private void InitializeComponent()    {        sCombo1 = new NetworkManagement.ServerComboBox();        sCombo1.AutoRefresh = true; // turn force chang	

	
			
  • 上一篇资讯: NET 连接池救生员
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号