public int storeOrderedWork(WorkConfig workConfig) { int orderedWorkId = orderedWorksKeyGenerator.generateKey(); OrderedWorks.Add(orderedWorkId, workConfig); return(orderedWorkId); }
public void Handle(NewWorkAckMessage message) { int orderedWorkId = message.OrderedWorkId; Task task; if (tasks.TryGetValue(message.TaskId, out task)) { Coordinator coordinator; bool isMapCoordinator; if (task.getCoordinatorByActorRef(Sender, out coordinator, out isMapCoordinator)) { WorkConfig orderedWorkConfig = coordinator.OrderedWorks [orderedWorkId]; coordinator.OrderedWorks.Remove(orderedWorkId); Work work = new Work(task.Id, message.WorkerId, orderedWorkConfig); coordinator.Works.Add(message.WorkerId, work); if (isMapCoordinator) { Console.WriteLine("map ack: " + task.Id + "-" + coordinator.Id + "-" + message.WorkerId); } else { Console.WriteLine("reduce ack: " + task.Id + "-" + coordinator.Id + "-" + message.WorkerId); } } else { //Console.WriteLine ("No coord found NewWorkAckMessage"); } } else { foreach (Coordinator mapCoordinator in validMapCoordinator) { if (mapCoordinator.OrderedWorks.ContainsKey(orderedWorkId)) { WorkConfig orderedWorkConfig = mapCoordinator.OrderedWorks [orderedWorkId]; Sender.Tell(new AbortWorkMessage(message.WorkerId)); mapCoordinator.OrderedWorks.Remove(orderedWorkId); } } foreach (Coordinator reduceCoordinator in validReduceCoordinator) { if (reduceCoordinator.OrderedWorks.ContainsKey(orderedWorkId)) { WorkConfig orderedWorkConfig = reduceCoordinator.OrderedWorks [orderedWorkId]; Sender.Tell(new AbortWorkMessage(message.WorkerId)); reduceCoordinator.OrderedWorks.Remove(orderedWorkId); } } } }
public void Handle(DivideResponseMessage message) { Task task = null; if (tasks.TryGetValue(message.TaskId, out task)) { if (message.Files.Count == 0) { abortTask(task, "No files to map"); return; } task.addDivideFiles(message.Files); NextCoordinatorInBulkGetter coordinatorGetter = null; try { coordinatorGetter = new NextCoordinatorInBulkGetter(validMapCoordinator); } catch (Exception e) { abortTask(task, "No coordinators"); return; } foreach (Dictionary <string, S3ObjectMetadata> files in message.Files) { Dictionary <string, List <S3ObjectMetadata> > workConfigFiles = new Dictionary <string, List <S3ObjectMetadata> > (); foreach (KeyValuePair <string, S3ObjectMetadata> pair in files) { workConfigFiles.Add(pair.Key, new List <S3ObjectMetadata> () { pair.Value }); } WorkConfig workConfig = new WorkConfig( task.Id, task.Username, workConfigFiles, task.AssemblyMetadata ); startNewMapWork(task, workConfig, coordinatorGetter.next()); } } else { foreach (Dictionary <string, S3ObjectMetadata> dict in message.Files) { foreach (S3ObjectMetadata file in dict.Values) { file.remove(); } } } }
private void startNewMapWork(Task task, WorkConfig workConfig, Coordinator coordinator) { Console.WriteLine("started map work: " + task.Id + "-" + coordinator.Id); if (!task.MapCoordinators.ContainsKey(coordinator.CoordinatorActor)) { task.MapCoordinators.Add(coordinator.CoordinatorActor, coordinator); } int orderedWorkConfigId = coordinator.storeOrderedWork(workConfig); coordinator.CoordinatorActor.Tell(new NewWorkMessage(orderedWorkConfigId, workConfig)); }
static void Main(string[] args) { ServerConfig config = new ServerConfig(); ListenConfig listenConfig = new ListenConfig(); listenConfig.Addresses = new ListenAddress[1]; listenConfig.Addresses[0] = new ListenAddress { Host = "127.0.0.1", Name = "1", Port = 8080 }; WorkConfig workConfig = new WorkConfig(); workConfig.ProcessQueueMaxLength = 2000; workConfig.WorkThreadNum = 8; HandlerConfig handlerConfig = new HandlerConfig(); handlerConfig.Handlers = new HandlerMatching[1]; handlerConfig.Handlers[0] = new HandlerMatching { Select = "http://127.0.0.1:8080/*:", Type = "Test,Test.TestHandler" }; StaticContentConfig staticContentConfig = new StaticContentConfig(); staticContentConfig.MimeMaps = new MimeMap[1]; staticContentConfig.MimeMaps[0] = new MimeMap { FileExtension = ".repx", MimeType = "test" }; config.RootDirectory = @"d:\test\web"; config.HandlerConfig = handlerConfig; config.WorkConfig = workConfig; config.ListenConfig = listenConfig; config.StaticContentConfig = staticContentConfig; XmlSerializer serializer = new XmlSerializer(typeof(ServerConfig)); using (FileStream stream = new FileStream("Server.config", FileMode.CreateNew, FileAccess.Write)) { serializer.Serialize(stream, config); } }
private void DownLoadTitle(WorkInfo workInfo, int j, int i, int zoom, string tempPath, string austerityFilePath) { if (workInfo.downStates == DownStates.stop) { return; } Bitmap vImage = this.GetTianDiMap(j, i, zoom, "vec_c"); if (vImage != null) { Bitmap cImage = this.GetTianDiMap(j, i, zoom, "cva_c"); if (!this.SaveImages(vImage, cImage, tempPath, ImageFormat.Png)) { workInfo.processDownImage.lose++; } else { if (workInfo.isAusterityFile) { var isAddQuequ = TaskQueue.GeTaskQueue() .AddTask(zoom, j, i, tempPath, austerityFilePath + "\\_alllayers"); if (!isAddQuequ) { this.AusterityFile(zoom, j, i, tempPath, austerityFilePath + "\\_alllayers"); } } workInfo.processDownImage.secess++; } } else { string picUrl = string.Format("{4}?T={0}&X={1}&Y={2}&L={3}", "vec_c", j, i, zoom, this.mapServer[0]); this.log.ErrorFormat("{0}", picUrl); workInfo.processDownImage.lose++; } if (this.DownImage != null) { this.DownImage( workInfo.id, workInfo.processDownImage.processIndex, workInfo.processDownImage.count, workInfo.processDownImage.secess, workInfo.processDownImage.lose); } if (workInfo.processDownImage.processIndex % 50 == 0) { WorkConfig.GetInstance().saveConfig(); GC.Collect(); } }
private void startNewReduceWork(Task task, WorkConfig workConfig, Coordinator coordinator) { Console.WriteLine("started reduce work: " + task.Id + "-" + coordinator.Id); int orderedWorkConfigId = coordinator.storeOrderedWork(workConfig); NewWorkMessage newWorkMessage = new NewWorkMessage(orderedWorkConfigId, workConfig); if (!task.ReduceCoordinators.ContainsKey(coordinator.CoordinatorActor)) { task.ReduceCoordinators.Add(coordinator.CoordinatorActor, coordinator); } coordinator.CoordinatorActor.Tell(newWorkMessage); }
private void downLoadTxb_Click(object sender, EventArgs e) { SetConfig(); if (string.IsNullOrEmpty(config.WorkInfo.filePath)) { MessageBox.Show("请选择切片保存地址"); return; } if (!System.IO.Directory.Exists(config.WorkInfo.filePath)) { MessageBox.Show("目录无效"); return; } if (config.CurrentExtent == null) { MessageBox.Show("地图范围无效"); return; } var main = this.Owner as FrmMain; System.Configuration.ConfigurationManager.AppSettings.Set("ezmapUrl", config.ServerUrl); System.Configuration.ConfigurationManager.AppSettings.Set("serviceVersion", config.ServerVersion); if (main != null) { var dataGridViewWorks = main.dataGridViewWorks; var count = config.WorkInfo.rcList.Sum(m => m.GetCount()); int index = dataGridViewWorks.Rows.Add( config.WorkInfo.workName, "0/" + count.ToString(), "0/" + count.ToString(), "0/" + count.ToString(), "0/" + count.ToString(), count.ToString(), "暂停下载"); dataGridViewWorks.Rows[index].Tag = config.WorkInfo; config.WorkInfo.processDownImage.count = count; WorkConfig.GetInstance().Commandconfig.workInfoList.Add(config.WorkInfo); WorkConfig.GetInstance().saveConfig(); main.StartDownLoad(config.WorkInfo, dataGridViewWorks.Rows[index]); main.BringToFront(); main.SetTileDownShow(); this.Close(); } }
private void tsbDelete_Click(object sender, EventArgs e) { List <DataGridViewRow> rows = new List <DataGridViewRow>(); for (int i = 0; i < this.dataGridViewWorks.SelectedRows.Count; i++) { rows.Add(this.dataGridViewWorks.SelectedRows[i]); } if (rows.Count > 0) { if (MessageBox.Show( "确定要删除该任务?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { foreach (DataGridViewRow row in rows) { WorkInfo workInfo = row.Tag as WorkInfo; workInfo.downStates = DownStates.stop; if (workInfo != null && myDicThreads.ContainsKey(workInfo.id)) { workInfo.rcList.ForEach( m => { var t = m.GetData() as Thread; if (t != null) { t.Abort(); } }); myDicThreads[workInfo.id].Abort(); myDicThreads[workInfo.id] = null; myDicThreads.Remove(workInfo.id); } lock (obj) { WorkConfig.GetInstance().Commandconfig.workInfoList.Remove(workInfo); WorkConfig.GetInstance().saveConfig(); } this.dataGridViewWorks.Rows.Remove(row); } } } }
public override void DownLoad(int minRow, int maxRow, int minCol, int maxCol, int zoom, WorkInfo workInfo) { string path = workInfo.filePath + "\\s"; path = path + "\\" + zoom.ToString(); string austerityFilePath = ""; string imgType = (workInfo.mapType == MapType.GaodeImage) ? "jpg" : "png"; if (workInfo.isAusterityFile) { austerityFilePath = Path.Combine(workInfo.filePath, "Layers"); } for (int i = minRow; i < maxRow + 1; i++) { string Dpath = path + "\\" + i.ToString(); if (!Directory.Exists(Dpath)) { Directory.CreateDirectory(Dpath); } for (int j = minCol; j < maxCol + 1; j++) { if (workInfo.downStates == DownStates.stop) { return; } string tempPath = Dpath + "\\" + j.ToString() + "." + imgType; workInfo.processDownImage.processIndex++; bool isSave = false; if (!File.Exists(tempPath)) { string url = this.GetTitleUrl(i, j, zoom); isSave = this.DownloadPicture(url, tempPath, 10000); if (isSave) { if (workInfo.isAusterityFile) { this.AusterityFile(zoom, i, j, tempPath, austerityFilePath + "\\_alllayers"); } workInfo.processDownImage.secess++; } else { workInfo.processDownImage.lose++; } if (this.DownImage != null) { this.DownImage( workInfo.id, workInfo.processDownImage.processIndex, workInfo.processDownImage.count, workInfo.processDownImage.secess, workInfo.processDownImage.lose); } if (workInfo.processDownImage.processIndex % 50 == 0) { lock (this.obj) { WorkConfig.GetInstance().saveConfig(); } } } else { workInfo.processDownImage.secess++; if (this.DownImage != null) { this.DownImage( workInfo.id, workInfo.processDownImage.processIndex, workInfo.processDownImage.count, workInfo.processDownImage.secess, workInfo.processDownImage.lose); } } } } }
private void btnOk_Click(object sender, EventArgs e) { if (!Directory.Exists(txbSavePath.Text)) { MessageBox.Show("请输入有效存储路径"); this.DialogResult = DialogResult.None; return; } if (txbName.Text.Trim() == string.Empty) { MessageBox.Show("请输入任务名称"); this.DialogResult = DialogResult.None; return; } try { this.minX = double.Parse(this.txbLeftBottom.Text.Split(',')[0]); this.minY = double.Parse(this.txbLeftBottom.Text.Split(',')[1]); this.maxX = double.Parse(this.txbRightTop.Text.Split(',')[0]); this.maxY = double.Parse(this.txbRightTop.Text.Split(',')[1]); } catch (Exception) { } int count = 0; NPMapTiles.ImageTools.MapTool mapTool = new ImageTools.MapTool(); List <RowColumns> rcList = new List <RowColumns>(); var tile = WorkInfo.CreateTitle(this.mapType); for (int i = 0; i < this.dataGridViewX.Rows.Count; i++) { if ((bool)this.dataGridViewX.Rows[i].Cells[0].Value) { int z = (int)this.dataGridViewX.Rows[i].Tag; count = count + (int)this.dataGridViewX.Rows[i].Cells[4].Value; RowColumns rc = tile.GetRowColomns(this.minX, this.minY, this.maxX, this.maxY, z); rcList.Add(rc); } } if (rcList.Count == 0) { MessageBox.Show("请至少选择一个层级"); this.DialogResult = DialogResult.None; return; } string name = this.txbName.Text.Trim(); int index = this.dataGridViewWorks.Rows.Add( name, "0/" + count.ToString(), "0/" + count.ToString(), "0/" + count.ToString(), "0/" + count.ToString(), count.ToString(), "暂停下载"); WorkInfo workInfo = new WorkInfo(); if (checkBoxAusterityFile.Checked) { workInfo.isAusterityFile = true; } else { workInfo.isAusterityFile = false; } workInfo.maxX = this.maxX; workInfo.maxY = this.maxY; workInfo.minX = this.minX; workInfo.minY = this.minY; workInfo.mapType = this.mapType; workInfo.rcList = rcList; workInfo.filePath = this.txbSavePath.Text.Trim(); workInfo.workName = name; workInfo.processDownImage.count = count; workInfo.id = System.Guid.NewGuid().ToString(); this.dataGridViewWorks.Rows[index].Tag = workInfo; WorkConfig.GetInstance().Commandconfig.workInfoList.Add(workInfo); WorkConfig.GetInstance().saveConfig(); }
public override void DownLoad(int minRow, int maxRow, int minCol, int maxCol, int zoom, WorkInfo workInfo) { string folderName = "\\s"; string austerityFilePath = ""; if (workInfo.isAusterityFile) { austerityFilePath = Path.Combine(workInfo.filePath, "Layers"); } string imgType = ".jpg"; string path = workInfo.filePath + folderName; path = path + "\\" + zoom.ToString(); for (int i = minRow; i < maxRow + 1; i++) { string Dpath = path + "\\" + i.ToString(); if (!Directory.Exists(Dpath)) { Directory.CreateDirectory(Dpath); } for (int j = minCol; j < maxCol + 1; j++) { if (workInfo.downStates == DownStates.stop) { return; } string tempPath = Dpath + "\\" + j.ToString() + imgType; workInfo.processDownImage.processIndex++; if (!File.Exists(tempPath)) { string url = string.Format(mapUrls[(i + j) % mapUrls.Length], zoom, i, j); var tempUrl = url; bool isSave = this.DownloadPicture(url, tempPath, 10000, ImageFormat.Jpeg); if (!isSave) { foreach (var mapUrl in mapUrls) { url = string.Format(mapUrl, zoom, i, j); isSave = this.DownloadPicture(url, tempPath, 10000, ImageFormat.Jpeg); if (isSave) { break; } } } if (isSave) { if (workInfo.isAusterityFile) { this.AusterityFile(zoom, i, j, tempPath, austerityFilePath + "\\_alllayers"); } workInfo.processDownImage.secess++; } else { workInfo.processDownImage.lose++; if (this.OnLog != null) { this.OnLog(tempUrl); } } if (this.DownImage != null) { this.DownImage( workInfo.id, workInfo.processDownImage.processIndex, workInfo.processDownImage.count, workInfo.processDownImage.secess, workInfo.processDownImage.lose); } if (workInfo.processDownImage.processIndex % 50 == 0) { lock (this.obj) { WorkConfig.GetInstance().saveConfig(); } } } else { workInfo.processDownImage.secess++; if (this.DownImage != null) { this.DownImage( workInfo.id, workInfo.processDownImage.processIndex, workInfo.processDownImage.count, workInfo.processDownImage.secess, workInfo.processDownImage.lose); } } } } }
public WorkerConfig(int workerId, WorkConfig workConfig, int coordinatorId) { this.WorkerId = workerId; this.WorkConfig = workConfig; this.CoordinatorId = coordinatorId; }
public override void DownLoad(int minRow, int maxRow, int minCol, int maxCol, int zoom, WorkInfo workInfo) { string folderName = "\\s"; string austerityFilePath = ""; if (workInfo.isAusterityFile) { austerityFilePath = Path.Combine(workInfo.filePath, "Layers"); } string imgType = ".png"; if (this.mapType == MapType.GoogleImage) { imgType = ".jpg"; } string path = workInfo.filePath + folderName; path = path + "\\" + zoom.ToString(); for (int i = minRow; i < maxRow + 1; i++) { string dpath = path + "\\" + i.ToString(); if (!Directory.Exists(dpath)) { Directory.CreateDirectory(dpath); } for (int j = minCol; j < maxCol + 1; j++) { if (workInfo.downStates == DownStates.stop) { return; } string tempPath = dpath + "\\" + j.ToString() + imgType; workInfo.processDownImage.processIndex++; bool isSave = false; if (!File.Exists(tempPath)) { string url = string.Format(mapUrl, (i + j) % 2, zoom, i, j); var tempUrl = url; if (this.mapType == MapType.GoogleImage) { string vUrl = string.Format(imageUrl, (i + j) % 2, zoom, i, j); tempUrl = vUrl; string cUrl = string.Format(biaozhuUrl, (i + j) % 2, zoom, i, j); Bitmap vImage = this.DownloadPicture(vUrl, 10000); if (vImage == null) { vUrl = string.Format(imageUrl, (i + j + 1) % 2, zoom, i, j); vImage = this.DownloadPicture(vUrl, 10000); } if (vImage != null) { Bitmap cImage = this.DownloadPicture(cUrl, 10000); if (cImage == null) { cUrl = string.Format(biaozhuUrl, (i + j + 1) % 2, zoom, i, j); cImage = this.DownloadPicture(cUrl, 10000); } if (cImage != null) { if (this.SaveImages(vImage, cImage, tempPath, ImageFormat.Jpeg)) { isSave = true; } } } } else { isSave = this.DownloadPicture(url, tempPath, 10000); if (!isSave) { url = string.Format(mapUrl, (i + j + 1) % 2, zoom, i, j); isSave = this.DownloadPicture(url, tempPath, 10000); } } if (isSave) { if (workInfo.isAusterityFile) { this.AusterityFile(zoom, i, j, tempPath, austerityFilePath + "\\_alllayers"); } workInfo.processDownImage.secess++; } else { workInfo.processDownImage.lose++; if (this.OnLog != null) { this.OnLog(tempUrl); } } if (this.DownImage != null) { this.DownImage( workInfo.id, workInfo.processDownImage.processIndex, workInfo.processDownImage.count, workInfo.processDownImage.secess, workInfo.processDownImage.lose); } if (workInfo.processDownImage.processIndex % 50 == 0) { lock (this.obj) { WorkConfig.GetInstance().saveConfig(); } } } else { workInfo.processDownImage.secess++; if (this.DownImage != null) { this.DownImage( workInfo.id, workInfo.processDownImage.processIndex, workInfo.processDownImage.count, workInfo.processDownImage.secess, workInfo.processDownImage.lose); } } } } }
public void ThreadMethod(object ParObject) { WorkInfo workInfo = ParObject as WorkInfo; workInfo = WorkConfig.GetInstance().GetWorkInfoByID(workInfo.id); if (workInfo != null) { ProcessDownImage processDown = new ProcessDownImage(); foreach (RowColumns rc in workInfo.rcList) { processDown.count = processDown.count + (rc.maxRow - rc.minRow + 1) * (rc.maxCol - rc.minCol + 1); } //if (workInfo.mapType == MapType.Tiandi) //{ // processDown.count = processDown.count; //} workInfo.processDownImage = processDown; int minZoom = 0; int maxZoom = 0; if (workInfo.rcList.Count > 0) { minZoom = workInfo.rcList[0].zoom; maxZoom = workInfo.rcList[0].zoom; } foreach (RowColumns rc in workInfo.rcList) { if (minZoom > rc.zoom) { minZoom = rc.zoom; } if (maxZoom < rc.zoom) { maxZoom = rc.zoom; } } workInfo.CreateTitle().CreateHtmlDemo(workInfo, minZoom, maxZoom); workInfo.CreateConfig(); //FileTools.HtmlTool.CreateHtmlDemo(workInfo, minZoom, maxZoom); //if (workInfo.isAusterityFile) //{ // string austerityFilePath = Path.Combine(workInfo.filePath, "Layers"); // if (!Directory.Exists(austerityFilePath)) // { // Directory.CreateDirectory(austerityFilePath); // } // workInfo.createAusterityConfig(austerityFilePath); //} var isMutilThread = WorkConfig.GetInstance() .Commandconfig.workInfoList.FirstOrDefault( m => m.downStates == DownStates.start && m.id != workInfo.id) != null; foreach (RowColumns rc in workInfo.rcList) { if (workInfo.downStates != DownStates.stop) { if (isMutilThread) { NewGetTiles(rc.minRow, rc.maxRow, rc.minCol, rc.maxCol, rc.zoom, workInfo); } else { Thread t = rc.GetData() as Thread; if (t != null && t.ThreadState == ThreadState.Stopped) { t.Resume(); } else { var result = System.Threading.ThreadPool.QueueUserWorkItem( new WaitCallback( o => { NewGetTiles( rc.minRow, rc.maxRow, rc.minCol, rc.maxCol, rc.zoom, workInfo); })); if (!result) // 加入线程池失败,则直接下载 { NewGetTiles(rc.minRow, rc.maxRow, rc.minCol, rc.maxCol, rc.zoom, workInfo); } } } } } if (workInfo.downStates == DownStates.start) { workInfo.downStates = DownStates.ready; } else if (workInfo.downStates == DownStates.stop) { if (this.DownImage != null) { this.DownImage(workInfo.id, 0, workInfo.processDownImage.count, 0, 0); } } workInfo.WriteConfigurationToFile(); lock (obj) { WorkConfig.GetInstance().saveConfig(); } } }
private void FrmMain_Load(object sender, EventArgs e) { Thread t = new Thread(this.AddCityNode); t.Start(); mapPanelNew.Controls.Clear(); mapControl = new MapControl(); mapControl.Dock = DockStyle.Fill; mapControl.mapMovingHandler += new MapControl.MapMovingHandler(this.mapMovingHandler); mapControl.mapZoomedHandler += new MapControl.MapZoomedHandler(this.mapZoomedHandler); mapControl.overlayEditedHandler += (extent) => { this.maxX = extent.maxX; this.maxY = extent.maxY; this.minX = extent.minX; this.minY = extent.minY; }; mapPanelNew.Controls.Add(mapControl); cmbMapType.DisplayMember = "Text"; cmbMapType.Items.Clear(); cmbMapType.Items.AddRange( new ComboxItem[] { new ComboxItem() { Tag = "Google", Value = MapType.Google, Text = "谷歌矢量图" }, new ComboxItem() { Tag = "GoogleImage", Value = MapType.GoogleImage, Text = "谷歌影像图" }, new ComboxItem() { Tag = "TianDi", Value = MapType.Tiandi, Text = "天地矢量图" }, new ComboxItem() { Tag = "TianDiImage", Value = MapType.TiandiImage, Text = "天地影像图" }, new ComboxItem() { Tag = "GaoDe", Value = MapType.Gaode, Text = "高德矢量图" }, new ComboxItem() { Tag = "GaoDeImage", Value = MapType.GaodeImage, Text = "高德影像图" }, new ComboxItem() { Tag = "initOSMMap", Value = MapType.OpenStreetMap, Text = "OpenStreet" }, new ComboxItem() { Tag = "BaiduImage", Value = MapType.Baidu, Text = "百度矢量图" }, new ComboxItem() { Tag = "BaiduImageTile", Value = MapType.BaiduImageTile, Text = "百度影像图" }, // new ComboxItem(){Tag = "InitQQMap",Value = MapType.QQMap,Text = "腾讯地图"}, }); cmbCoverteType.Items.Clear(); this.cmbCoverteType.DisplayMember = "Text"; this.cmbCoverteType.Items.AddRange( new ComboxItem[] { new ComboxItem() { Text = "WGS84-->GCJ-02", Value = CovertType.WGS2GCJ02 }, new ComboxItem() { Text = "WGS84-->百度", Value = CovertType.WGS2BAIDU }, new ComboxItem() { Text = "GCJ-02-->百度", Value = CovertType.GCJ022BAIDU }, new ComboxItem() { Text = "墨卡托平面-->经纬度", Value = CovertType.MOCTOR2LONLAT }, new ComboxItem() { Text = "经纬度(火星)-->墨卡托平面", Value = CovertType.LONLAT2MOCTOR }, new ComboxItem() { Text = "百度-->GCJ02", Value = CovertType.BAIDU2GCJ02 }, new ComboxItem() { Text = "WGS84-->墨卡托平面", Value = CovertType.WGS2MOCTOR }, }); if (this.cmbMapType.Items.Count > 0) { cmbMapType.SelectedIndex = 2; } if (this.cmbCoverteType.Items.Count > 0) { this.cmbCoverteType.SelectedIndex = 0; } this.OnProcessNotify += new Handlers.ProcessNotifyHandler(this.ShowMsg); this.OnProcessNotify2 += new Handlers.ProcessNotifyHandler(this.ShowMsg2); this.OnLog += new Handlers.LogHandler(this.WriteLog); this.DownImage += new Handlers.DownImageHandler(this.doNewThings); this.myTreeView.ExpandAll(); this.tabControl.SelectedTab = tabItemMap; this.WriteLog("启动结束"); List <WorkInfo> workInfos = WorkConfig.GetInstance().Commandconfig.workInfoList; foreach (WorkInfo workInfo in workInfos) { string x = "未完成下载:" + workInfo.processDownImage.processIndex.ToString() + "/" + workInfo.processDownImage.count.ToString(); string sta = "停止下载"; if (workInfo.downStates == DownStates.start) { sta = "暂停下载"; } else if (workInfo.downStates == DownStates.pause) { sta = "暂停下载"; } else if (workInfo.downStates == DownStates.stop) { sta = "停止下载"; } else if (workInfo.downStates == DownStates.ready) { sta = "完成下载"; } if (workInfo.processDownImage.processIndex == workInfo.processDownImage.count) { x = "已完成下载:" + workInfo.processDownImage.processIndex.ToString() + "/" + workInfo.processDownImage.count.ToString(); } int index = this.dataGridViewWorks.Rows.Add( workInfo.workName, x, workInfo.processDownImage.secess.ToString() + "/" + workInfo.processDownImage.count.ToString(), workInfo.processDownImage.lose.ToString() + "/" + workInfo.processDownImage.count.ToString(), workInfo.processDownImage.lose.ToString() + "/" + workInfo.processDownImage.count.ToString(), workInfo.processDownImage.count.ToString(), sta); this.dataGridViewWorks.Rows[index].Tag = workInfo; } this.WindowState = FormWindowState.Maximized; }
public override void DownLoad(int minRow, int maxRow, int minCol, int maxCol, int zoom, WorkInfo workInfo) { var path = Path.Combine(workInfo.filePath, "Vector"); path = Path.Combine(path, zoom.ToString()); int k = 0; string austerityFilePath = ""; if (workInfo.isAusterityFile) { austerityFilePath = Path.Combine(workInfo.filePath, "Layers"); } for (int i = minCol; i < maxCol + 1; i++) { string dpath = path + "\\" + i.ToString(); if (!Directory.Exists(dpath)) { Directory.CreateDirectory(dpath); } for (int j = minRow; j < maxRow + 1; j++) { if (workInfo.downStates == DownStates.stop) { return; } string tempPath = dpath + "\\" + j.ToString() + ".jpg"; k++; workInfo.processDownImage.processIndex++; if (!File.Exists(tempPath)) { string url = string.Format( "{4}?T={0}&X={1}&Y={2}&L={3}", this.mapType, j, i, zoom, this.mapServer[new Random().Next(0, this.mapServer.Length)]); bool isSave = this.DownloadPicture(url, tempPath, 10000); if (isSave) { if (workInfo.isAusterityFile) { this.AusterityFile(zoom, j, i, tempPath, austerityFilePath + "\\_alllayers"); } workInfo.processDownImage.secess++; } else { // 如果随机下载失败,则对所有的服务重新循环一遍重新下载数据 foreach (var s in this.mapServer) { url = string.Format("{4}?T={0}&X={1}&Y={2}&L={3}", this.mapType, j, i, zoom, s); isSave = this.DownloadPicture(url, tempPath, 10000); if (isSave) { if (workInfo.isAusterityFile) { this.AusterityFile(zoom, j, i, tempPath, austerityFilePath + "\\_alllayers"); } workInfo.processDownImage.secess++; break; } } if (!isSave) { workInfo.processDownImage.lose++; } } if (this.DownImage != null) { this.DownImage( workInfo.id, workInfo.processDownImage.processIndex, workInfo.processDownImage.count, workInfo.processDownImage.secess, workInfo.processDownImage.lose); } if (workInfo.processDownImage.processIndex % 50 == 0) { lock (this.obj) { WorkConfig.GetInstance().saveConfig(); } } } else { workInfo.processDownImage.secess++; if (this.DownImage != null) { this.DownImage( workInfo.id, workInfo.processDownImage.processIndex, workInfo.processDownImage.count, workInfo.processDownImage.secess, workInfo.processDownImage.lose); } } } } }
public Work(int taskId, int workId, WorkConfig workConfig) { this.TaskId = taskId; this.WorkId = workId; this.WorkConfig = workConfig; }