/// <summary> /// 计时器事件入口 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { int hour = System.DateTime.Now.Hour; int sethour = Utils.GetConfigInfo().hour; if (hour != sethour) { this.timer1.Enabled = false; //Utils.Log("$$服务正常扫描一次,但没有下载文件..."); this.timer1.Enabled = true; } else { this.timer1.Enabled = false; List <BakInfo> oldlist = new List <BakInfo>(); List <ServerInfo> list = Utils.GetServerList(); if (list != null && list.Count > 0) { for (int i = 0; i < list.Count; i++) { ServerInfo info = list[i]; List <BakInfo> files = FTPTools.GetNewFileList(info.ip, info.port, info.uid, info.password, ref oldlist); /// ///下载最新的文件 /// if (files != null && files.Count > 0) { for (int j = 0; j < files.Count; j++) { Console.WriteLine("开始下载:" + files[j].path + "/" + files[j].filename); Utils.WriteSuccess("=========================================================="); Utils.WriteSuccess("开始下载:" + files[j].path + "\\" + files[j].filename); DateTime begintime = System.DateTime.Now; int status = FTPTools.DownLoadFile(info.ip, info.port, info.uid, info.password, files[j]); if (status == 9) { DateTime endtime = System.DateTime.Now; TimeSpan ts = endtime - begintime; int min = (int)ts.TotalMinutes; int se = (int)ts.TotalSeconds; Console.WriteLine("@@下载成功@@ " + files[j].path + "/" + files[j].filename); Utils.WriteSuccess("@@下载成功 耗时约 " + min + " 分钟/ " + se + " 秒 " + files[j].path + "\\" + files[j].filename); } else if (status == 8) { Console.WriteLine("本地文件已存在..."); Utils.WriteSuccess("本地文件已存在..."); } else if (status == 0) { Console.WriteLine("!!下载失败!! " + files[j].path + "/" + files[j].filename); Utils.WriteSuccess("!!下载失败!! " + files[j].path + "\\" + files[j].filename); } else if (status == -1) { Console.WriteLine("本地目录配置错误..."); Utils.WriteSuccess("本地目录配置错误..."); } Utils.WriteSuccess("=========================================================="); Utils.WriteSuccess(""); Utils.WriteSuccess(""); } } /// ///删除旧文件. /// if (oldlist != null && oldlist.Count > 0) { for (int j = 0; j < oldlist.Count; j++) { FTPTools.DeleteFile(info.ip, info.port, info.uid, info.password, oldlist[j]); } } } } this.timer1.Enabled = true; } }
private void barButtonGetFiles_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { splashScreenManager1.ShowWaitForm(); } catch { } DataTable dtMaster = new DataTable(); dtMaster.TableName = "master"; dtMaster.Columns.Add("PlayerName", typeof(string)); dtMaster.Columns.Add("LastPlayed", typeof(DateTime)); dtMaster.Columns.Add("BattleCount", typeof(Int32)); dtMaster.Columns.Add("Victories", typeof(Int32)); dtMaster.Columns.Add("Defeats", typeof(Int32)); dtMaster.Columns.Add("Draws", typeof(Int32)); dtMaster.Columns.Add("Survived", typeof(Int32)); dtMaster.Columns.Add("Destroyed", typeof(Int32)); dtMaster.Columns.Add("Detected", typeof(Int32)); dtMaster.Columns.Add("HitRatio", typeof(double)); dtMaster.Columns.Add("Damage", typeof(Int32)); dtMaster.Columns.Add("CapturePoints", typeof(Int32)); dtMaster.Columns.Add("DefencePoints", typeof(Int32)); dtMaster.Columns.Add("TotalExperience", typeof(Int32)); dtMaster.Columns.Add("AvgExperience", typeof(double)); dtMaster.Columns.Add("AvgDamage", typeof(double)); DataTable dtChild = new DataTable(); dtChild.TableName = "child"; dtChild.Columns.Add("PlayerName", typeof(string)); dtChild.Columns.Add("Tank", typeof(string)); dtChild.Columns.Add("LastPlayed", typeof(DateTime)); dtChild.Columns.Add("BattleCount", typeof(Int32)); dtChild.Columns.Add("Victories", typeof(Int32)); dtChild.Columns.Add("Defeats", typeof(Int32)); dtChild.Columns.Add("Draws", typeof(Int32)); dtChild.Columns.Add("Survived", typeof(Int32)); dtChild.Columns.Add("Destroyed", typeof(Int32)); dtChild.Columns.Add("Detected", typeof(Int32)); dtChild.Columns.Add("HitRatio", typeof(double)); dtChild.Columns.Add("Damage", typeof(Int32)); dtChild.Columns.Add("CapturePoints", typeof(Int32)); dtChild.Columns.Add("DefencePoints", typeof(Int32)); dtChild.Columns.Add("TotalExperience", typeof(Int32)); dtChild.Columns.Add("AvgExperience", typeof(double)); dtChild.Columns.Add("AvgDamage", typeof(double)); dtChild.Columns.Add("Hits", typeof(Int32)); dtChild.Columns.Add("shots", typeof(Int32)); PlayerListing pl = new PlayerListing(new MessageQueue()); FTPTools ftpTools = new FTPTools(); FTPDetails ftpDetails = new FTPDetails(); Encoding byteConverter = Encoding.GetEncoding("UTF-8"); List <string> files = ftpTools.DirectoryListing(ftpDetails.Host, ftpDetails.UserID, ftpDetails.UserPWD); foreach (string item in files) { string playerName = byteConverter.GetString(Base32.Decode(item.Remove(item.IndexOf('.')))).Split(';')[1]; string fileName = ftpTools.Download(ftpDetails.Host, item, ftpDetails.UserID, ftpDetails.UserPWD, new MessageQueue(), playerName); ProcessDossierFile(fileName, dtChild, playerName); if (dtChild.Rows.Count > 0) { DataRow rowM = dtMaster.NewRow(); var totals = (from x in dtChild.AsEnumerable() group x by x["PlayerName"] into totalgroup where totalgroup.Key.ToString() == playerName select new { PlayerName = totalgroup.Key, LastPlayed = totalgroup.Max((r) => DateTime.Parse(r["LastPlayed"].ToString())), BattleCount = totalgroup.Sum((r) => int.Parse(r["BattleCount"].ToString())), Victories = totalgroup.Sum((r) => int.Parse(r["Victories"].ToString())), Defeats = totalgroup.Sum((r) => int.Parse(r["Defeats"].ToString())), Draws = totalgroup.Sum((r) => int.Parse(r["Draws"].ToString())), Survived = totalgroup.Sum((r) => int.Parse(r["Survived"].ToString())), Destroyed = totalgroup.Sum((r) => int.Parse(r["Destroyed"].ToString())), Detected = totalgroup.Sum((r) => int.Parse(r["Detected"].ToString())), Hits = totalgroup.Sum((r) => int.Parse(r["Hits"].ToString())), Shots = totalgroup.Sum((r) => int.Parse(r["Shots"].ToString())), Damage = totalgroup.Sum((r) => int.Parse(r["Damage"].ToString())), CapturePoints = totalgroup.Sum((r) => int.Parse(r["CapturePoints"].ToString())), DefencePoints = totalgroup.Sum((r) => int.Parse(r["DefencePoints"].ToString())), TotalExperience = totalgroup.Sum((r) => int.Parse(r["TotalExperience"].ToString())), }).FirstOrDefault(); if (totals != null) { rowM.SetField("PlayerName", totals.PlayerName); rowM.SetField("LastPlayed", totals.LastPlayed); rowM.SetField("BattleCount", totals.BattleCount); rowM.SetField("Victories", totals.Victories); rowM.SetField("Defeats", totals.Defeats); rowM.SetField("Draws", totals.Draws); rowM.SetField("Survived", totals.Survived); rowM.SetField("Destroyed", totals.Destroyed); rowM.SetField("Detected", totals.Detected); rowM.SetField("HitRatio", ((double)totals.Hits / (double)totals.Shots) * 100); rowM.SetField("Damage", totals.Damage); rowM.SetField("CapturePoints", totals.CapturePoints); rowM.SetField("DefencePoints", totals.DefencePoints); rowM.SetField("TotalExperience", totals.TotalExperience); rowM.SetField("AvgExperience", totals.TotalExperience / totals.BattleCount); rowM.SetField("AvgDamage", totals.Damage / totals.BattleCount); dtMaster.Rows.Add(rowM); } } //gridControl1.RefreshDataSource(); } DataSet ds = new DataSet(); ds.Tables.Add(dtMaster); ds.Tables.Add(dtChild); DataColumn keyColumn = ds.Tables["master"].Columns["PlayerName"]; DataColumn foreignKeyColumn = ds.Tables["child"].Columns["PlayerName"]; ds.Relations.Add("Player_Detail", keyColumn, foreignKeyColumn); gridControl1.DataSource = ds.Tables["master"]; gridControl1.ForceInitialize(); gridControl1.LevelTree.Nodes.Add("Player_Detail", PlayerDetail); try { if (splashScreenManager1.IsSplashFormVisible) { splashScreenManager1.CloseWaitForm(); } DevExpress.XtraSplashScreen.SplashScreenManager.Default.CloseWaitForm(); } catch { } //gridControl1.DataSource = ds.Tables["master"]; //gridControl1.ForceInitialize(); //gridControl1.LevelTree.Nodes.Add("Player_Detail", PlayerDetail); //PlayerDetail.PopulateColumns(ds.Tables["child"]); }