Example #1
0
        public static string GetPrinterService(LaptopInformation laptop)
        {
            string result = string.Empty;

            if (laptop.StoreType == "IFocus")
            {
                //连接远程计算机
                ConnectionOptions co = new ConnectionOptions();
                co.Username = "******";
                co.Password = "******";
                ManagementScope ms = new ManagementScope("\\\\" + laptop.IPs[laptop.Count - 1] + "\\root\\cimv2", co);
                //查询远程计算机
                ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_Service");
                ManagementObjectSearcher   query1           = new ManagementObjectSearcher(ms, oq);
                ManagementObjectCollection queryCollection1 = query1.Get();
                foreach (ManagementObject mo in queryCollection1)
                {
                    if (Convert.ToString(mo["Name"]) == "Spooler")
                    {
                        result = (mo["Started"].ToString() == "True") ? "打印机服务已启动" : "打印机服务未启动";
                    }
                }
            }
            return(result);
        }
Example #2
0
        private static void LaptopCallback(object sender, PingCompletedEventArgs e)
        {
            LaptopInformation laptop = (LaptopInformation)e.UserState;

            laptop.LaptopNetwork = (e.Reply.Status == IPStatus.Success) ? "Up" : "Down";
            laptop.Count++;
            if (laptop.LaptopNetwork == "Down" && laptop.Count != laptop.IPs.Count)
            {
                flag.Set();
                LaptopAssist(laptop, laptop.Count);
            }
            else
            {
                // 获取打印机服务 待添加
                laptop.Date = DateTime.Now.ToString();
                laptop.IP   = laptop.IPs[laptop.Count - 1];
                if (!laptop.IsIndexQuery)
                {
                    LaptopList.Add(laptop);
                    laptopComplete[laptop.I] = 1; // 置1表示该打印机已经Ping完
                    Console.WriteLine((laptop.I + 1).ToString() + "/" + laptop.Total.ToString() + " " + laptop.StoreNo + ": " + laptop.LaptopNetwork);
                }
                else
                {
                    indexlapCount++;
                }
            }
            flag.Set();
        }
Example #3
0
        private static void LaptopAssist(LaptopInformation laptop, int i)
        {
            Ping p = new Ping();

            p.PingCompleted += LaptopCallback;
            p.SendAsync(laptop.IPs[i], 1000, laptop);
            flag.WaitOne();
        }
Example #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string url = Request.Url.ToString();
        ArrayList list = new ArrayList();
        string str = string.Empty;

        if (url.IndexOf("status") != -1)
        {
            string query = Request.QueryString["status"].ToString();
            switch (query.ToUpper())
            {
                case "ALL":
                    {
                        DataSet ds = SqlHelper.GetLaptopInformation();
                        int count = ds.Tables[0].Rows.Count;
                        for (int i = 0; i < count; i++)
                        {
                            LaptopInformation laptop = new LaptopInformation();
                            laptop.StoreNo = ds.Tables[0].Rows[i]["storeNo"].ToString();
                            laptop.StoreRegion = ds.Tables[0].Rows[i]["storeRegion"].ToString();
                            laptop.StoreType = ds.Tables[0].Rows[i]["storeType"].ToString();
                            laptop.LaptopNetwork = ds.Tables[0].Rows[i]["laptopNetwork"].ToString();
                            laptop.IP = ds.Tables[0].Rows[i]["ip"].ToString();
                            laptop.PrinterService = ds.Tables[0].Rows[i]["printerService"].ToString();
                            laptop.Date = ds.Tables[0].Rows[i]["date"].ToString();
                            list.Add(laptop);
                        }
                    }
                    break;
                case "LAPTOP":
                    {
                        IMonitorTask.GetTaskData(TaskCondition.Laptop);
                        Response.Write("笔记本信息获取成功");
                        Response.End();
                        return;
                    }
            }
        }
        else
        {
            Response.Write("This is Iwooo Monitor System");
            Response.End();
            return;
        }

        JavaScriptSerializer json = new JavaScriptSerializer();
        str = json.Serialize(list);

        Response.Write(str);
        Response.End();
        return;
    }
Example #5
0
        public static void SetLaptopInformation(IndexQuery iq)
        {
            LaptopInformation laptop = new LaptopInformation();

            laptop.StoreNo      = iq.StoreNo;
            laptop.StoreRegion  = iq.StoreRegion;
            laptop.StoreType    = iq.StoreType;
            laptop.I            = 0;
            laptop.Total        = 1;
            laptop.Count        = 0;
            laptop.IPs          = iq.IPs;
            laptop.IsIndexQuery = true;
            LaptopAssist(laptop, laptop.Count);
            while (true)
            {
                if (indexlapCount == 1)
                {
                    iq.LaptopNetwork = laptop.LaptopNetwork;
                    iq.LaptopIP      = laptop.IP;
                    break;
                }
            }
        }
Example #6
0
        public static void DoGetLaptopInformationTask()
        {
            LaptopList = new List <LaptopInformation>();
            DataSet ds    = SqlHelper.GetStoreInformation();
            int     count = ds.Tables[0].Rows.Count;

            laptopComplete = new int[count];
            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int i = 0; i < count; i++)
            {
                laptopComplete[i] = 0;
            }
            for (int i = 0; i < count; i++)
            {
                LaptopInformation laptop = new LaptopInformation();
                laptop.StoreNo      = ds.Tables[0].Rows[i]["storeNo"].ToString();
                laptop.StoreRegion  = ds.Tables[0].Rows[i]["storeRegion"].ToString();
                laptop.StoreType    = ds.Tables[0].Rows[i]["storeType"].ToString();
                laptop.I            = i;
                laptop.Total        = count;
                laptop.Count        = 0;
                laptop.IsIndexQuery = false;

                string[] ip1 = ds.Tables[0].Rows[i]["laptopIP1"].ToString().Split(';');
                for (int j = 0; j < ip1.Length; j++)
                {
                    laptop.IPs.Add(ip1[j]);
                }

                string[] ip2 = ds.Tables[0].Rows[i]["laptopIP2"].ToString().Split(';');
                for (int k = 0; k < ip2.Length; k++)
                {
                    laptop.IPs.Add(ip2[k]);
                }

                laptop.LaptopNetwork = string.Empty;
                LaptopAssist(laptop, laptop.Count);
            }
            while (true)
            {
                if (count == GetArraySum(laptopComplete))
                {
                    string[]  clist = { "storeNo", "storeRegion", "storeType", "laptopNetwork", "ip", "printerService", "date" };
                    DataTable dt    = new DataTable();
                    foreach (string colName in clist)
                    {
                        dt.Columns.Add(colName);
                    }
                    int rowCount = LaptopList.Count;
                    for (int i = 0; i < rowCount; i++)
                    {
                        DataRow row = dt.NewRow();
                        row["storeNo"]        = LaptopList[i].StoreNo;
                        row["storeRegion"]    = LaptopList[i].StoreRegion;
                        row["storeType"]      = LaptopList[i].StoreType;
                        row["laptopNetwork"]  = LaptopList[i].LaptopNetwork;
                        row["ip"]             = LaptopList[i].IP;
                        row["printerService"] = LaptopList[i].PrinterService;
                        row["date"]           = LaptopList[i].Date;
                        dt.Rows.Add(row);
                    }
                    SqlHelper.DeleteLaptopInformation();
                    SqlHelper.CommonBulkInsert(dt, "LaptopInformation");
                    sw.Stop();
                    double ms = sw.ElapsedMilliseconds / 1000.0;
                    Console.WriteLine("耗时: " + ms.ToString());
                    break;
                }
            }
        }
Example #7
0
 private static void LaptopAssist(LaptopInformation laptop, int i)
 {
     Ping p = new Ping();
     p.PingCompleted += LaptopCallback;
     p.SendAsync(laptop.IPs[i], 1000, laptop);
     flag.WaitOne();
 }
Example #8
0
 public static void SetLaptopInformation(IndexQuery iq)
 {
     LaptopInformation laptop = new LaptopInformation();
     laptop.StoreNo = iq.StoreNo;
     laptop.StoreRegion = iq.StoreRegion;
     laptop.StoreType = iq.StoreType;
     laptop.I = 0;
     laptop.Total = 1;
     laptop.Count = 0;
     laptop.IPs = iq.IPs;
     laptop.IsIndexQuery = true;
     LaptopAssist(laptop, laptop.Count);
     while (true)
     {
         if (indexlapCount == 1)
         {
             iq.LaptopNetwork = laptop.LaptopNetwork;
             iq.LaptopIP = laptop.IP;
             break;
         }
     }
 }
Example #9
0
        public static void DoGetLaptopInformationTask()
        {
            LaptopList = new List<LaptopInformation>();
            DataSet ds = SqlHelper.GetStoreInformation();
            int count = ds.Tables[0].Rows.Count;
            laptopComplete = new int[count];
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                laptopComplete[i] = 0;
            }
            for (int i = 0; i < count; i++)
            {
                LaptopInformation laptop = new LaptopInformation();
                laptop.StoreNo = ds.Tables[0].Rows[i]["storeNo"].ToString();
                laptop.StoreRegion = ds.Tables[0].Rows[i]["storeRegion"].ToString();
                laptop.StoreType = ds.Tables[0].Rows[i]["storeType"].ToString();
                laptop.I = i;
                laptop.Total = count;
                laptop.Count = 0;
                laptop.IsIndexQuery = false;

                string[] ip1 = ds.Tables[0].Rows[i]["laptopIP1"].ToString().Split(';');
                for (int j = 0; j < ip1.Length; j++ )
                {
                    laptop.IPs.Add(ip1[j]);
                }

                string[] ip2 = ds.Tables[0].Rows[i]["laptopIP2"].ToString().Split(';');
                for (int k = 0; k < ip2.Length; k++ )
                {
                    laptop.IPs.Add(ip2[k]);
                }

                laptop.LaptopNetwork = string.Empty;
                LaptopAssist(laptop, laptop.Count);
            }
            while (true)
            {
                if( count == GetArraySum(laptopComplete))
                {
                    string[] clist = { "storeNo", "storeRegion", "storeType", "laptopNetwork", "ip", "printerService", "date" };
                    DataTable dt = new DataTable();
                    foreach (string colName in clist)
                    {
                        dt.Columns.Add(colName);
                    }
                    int rowCount = LaptopList.Count;
                    for (int i = 0; i < rowCount; i++)
                    {
                        DataRow row = dt.NewRow();
                        row["storeNo"] = LaptopList[i].StoreNo;
                        row["storeRegion"] = LaptopList[i].StoreRegion;
                        row["storeType"] = LaptopList[i].StoreType;
                        row["laptopNetwork"] = LaptopList[i].LaptopNetwork;
                        row["ip"] = LaptopList[i].IP;
                        row["printerService"] = LaptopList[i].PrinterService;
                        row["date"] = LaptopList[i].Date;
                        dt.Rows.Add(row);
                    }
                    SqlHelper.DeleteLaptopInformation();
                    SqlHelper.CommonBulkInsert(dt, "LaptopInformation");
                    sw.Stop();
                    double ms = sw.ElapsedMilliseconds / 1000.0;
                    Console.WriteLine("耗时: " + ms.ToString());
                    break;
                }
            }
        }
Example #10
0
 public static string GetPrinterService(LaptopInformation laptop)
 {
     string result = string.Empty;
     if (laptop.StoreType == "IFocus")
     {
         //连接远程计算机
         ConnectionOptions co = new ConnectionOptions();
         co.Username = "******";
         co.Password = "******";
         ManagementScope ms = new ManagementScope("\\\\" + laptop.IPs[laptop.Count - 1] + "\\root\\cimv2", co);
         //查询远程计算机
         ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_Service");
         ManagementObjectSearcher query1 = new ManagementObjectSearcher(ms, oq);
         ManagementObjectCollection queryCollection1 = query1.Get();
         foreach (ManagementObject mo in queryCollection1)
         {
             if (Convert.ToString(mo["Name"]) == "Spooler")
             {
                 result = (mo["Started"].ToString() == "True") ? "打印机服务已启动" : "打印机服务未启动";
             }
         }
     }
     return result;
 }