예제 #1
0
        /// <summary>
        /// 变量初始化 创建:fjl
        /// </summary>
        /// <returns>返回true</returns>
        public async Task <bool> InitAsync()
        {
            Lengend  = new ObservableCollection <LineChartLengend>();
            ChartDao = new ChartUtilImpl();
            siteDao  = new SiteDaoImpl();
            logDao   = new LogDaoImpl();
            Infos.LineChartCollection = new ObservableCollection <ObservableCollection <LineChartData> >();
            Infos.SiteInfoCompleted   = new ObservableCollection <AddSiteInfo>();
            Infos.SiteSelected        = new List <SiteModel>();
            Infos.Logs     = new List <LogModel>();
            Infos.BarChart = new ObservableCollection <BarChartData>();
            await Task.CompletedTask;

            return(true);
        }
        //变量初始化
        public async Task <bool> InitAsync()
        {
            Lengend                    = new ObservableCollection <ChartLengend>();
            ChartDao                   = new ChartUtilImpl();
            siteDao                    = new SiteDaoImpl();
            logDao                     = new LogDaoImpl();
            Chart1Collection           = new ObservableCollection <ObservableCollection <Chart1> >();
            Infos.Chart1CollectionCopy = new ObservableCollection <ObservableCollection <Chart1> >();
            Infos.SelectSites          = new ObservableCollection <SelectSite>();
            Infos.Sites                = new List <SiteModel>();
            Infos.Logs                 = new List <LogModel>();
            Infos.BarChart             = new ObservableCollection <BarChartData>();
            await Task.CompletedTask;

            return(true);
        }
예제 #3
0
        private async void BackGroundRequestTask(IBackgroundTaskInstance taskInstance)
        {
            MessageRemind toast    = new MessageRemind(); //初始化消息提醒
            var           sitelist = DBHelper.GetAllSite();
            var           len      = sitelist.Count;      //使用foreach会出现不在期望中的异常
            SiteModel     _presite = new SiteModel();

            _presite = DBHelper.GetSiteById(4);            //这里是指定了precheck的id为4
            var _precolor = _presite.Is_success;           //如果percheck为错误 就不进行请求了
            // 引入封装的工具类  --xb
            SiteDetailUtilImpl util = new SiteDetailUtilImpl();

            if (_precolor != 0)
            {
                //遍历sitelist 根据协议进行请求
                for (int i = 0; i < len; i++)
                {
                    // 获取站点对象   --xb
                    SiteModel siteElement = sitelist[i];
                    // 创建用于记录此次请求的Log对象   --xb
                    LogModel log = null;
                    if (!siteElement.Is_Monitor)
                    {
                        continue;
                    }
                    IPAddress _siteAddress_redress = await util.GetIPAddressAsync(siteElement.Site_address);

                    switch (siteElement.Protocol_type)//根据协议请求站点
                    {
                    // HTTP/HTTPS协议请求   --xb
                    // 目前HTTP与HTTPS没有做协议请求上的区分  --xb
                    case "HTTPS":
                    case "HTTP":
                        try
                        {
                            // 发起HTTP请求,生成请求记录并更新站点信息  --xb
                            log = await util.RequestHTTPSite(siteElement, HTTPRequest.Instance);
                        }
                        catch (Exception ex)
                        {
                            DBHelper.InsertErrorLog(ex);
                            log = null;
                        }
                        break;

                    // DNS协议请求   --xb
                    case "DNS":
                        // 发起DNS请求,生成请求记录并更新站点信息  --xb
                        log = await util.AccessDNSServer(siteElement, DNSRequest.Instance);

                        break;

                    // ICMP协议请求   --xb
                    case "ICMP":
                        ICMPRequest icmp = new ICMPRequest(_siteAddress_redress);
                        // 发起ICMP请求,生成请求记录并更新站点信息  --xb
                        log = await util.ConnectToServerWithICMP(siteElement, icmp);

                        break;

                    // FTP协议请求   --xb
                    case "FTP":
                        // 发起FTP请求,生成请求记录并更新站点信息  --xb
                        log = await util.AccessFTPServer(siteElement, FTPRequest.Instance);

                        break;

                    // SMTP协议请求   --xb
                    case "SMTP":
                        // 发起SMTP请求,生成请求记录并更新站点信息  --xb
                        SMTPRequest _smtpRequest = new SMTPRequest(siteElement.Site_address, siteElement.Server_port);
                        log = await util.AccessSMTPServer(siteElement, _smtpRequest);

                        break;

                    // 补充之前欠缺的Socket服务器请求   --xb
                    case "SOCKET":
                        // 初始化Socket请求对象
                        SocketRequest _socketRequest = new SocketRequest();
                        // 请求指定终端,并生成对应的请求记录,最后更新站点信息
                        log = await util.ConnectToServerWithSocket(siteElement, _socketRequest);

                        break;

                    // 补充之前欠缺的SSH服务器请求   --xb
                    case "SSH":
                        log = await util.AccessSSHServer(siteElement, new SSHRequest(siteElement.Site_address, SshLoginType.Anonymous));

                        break;

                    default:
                        break;
                    }
                    if (null != log)
                    {
                        // 将请求的记录插入数据库  --xb
                        LogDaoImpl logDao = new LogDaoImpl();
                        logDao.InsertOneLog(log);
                        // 如果请求失败,提醒用户  --xb
                        if (log.Is_error)
                        {
                            // 消息提醒  --xb
                            toast.ShowToast(siteElement);
                        }
                    }
                    // 说明此次请求处于异常状态,记录进数据库中
                    else
                    {
                        DBHelper.InsertErrorLog(new Exception("Insert Log failed!Beacuse log to insert is null"));
                    }
                }
            }
        }