Пример #1
0
        static public TaskLogEntity GetLogEntity(string GUID)
        {
            TaskLogEntity entity = new TaskLogEntity();

            //try
            //{
            //    XmlDocument xmlDoc = new XmlDocument();
            //    xmlDoc.Load(HttpContext.Current.Server.MapPath("/Log/Log.xml"));

            //    XmlNode node = xmlDoc.SelectSingleNode("/DataItem/Log[@GUID='" + GUID + "']");
            //    if (node != null)
            //    {//日志存在就进行修改
            //        //node.SelectSingleNode("ErrorMsg").InnerText = entity.ErrorMsg;
            //        //node.SelectSingleNode("Status").InnerText = entity.Status;
            //        //node.SelectSingleNode("Type").InnerText = entity.Type;
            //        //node.SelectSingleNode("ErrorDate").InnerText = DateTime.Now.ToString();

            //        PropertyInfo[] properties = entity.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
            //        foreach (PropertyInfo item in properties)
            //        {//循环遍历实体,取出字段和字段对应的值

            //            if (item.GetValue(entity, null) != null)
            //            {
            //                item.SetValue(entity, node.SelectSingleNode(item.Name).InnerText, null);
            //            }
            //        }

            //    }
            //}
            //catch (Exception ex)
            //{

            //}
            //return entity;

            try
            {
                System.Data.DataTable dt = AccessHelper.ExecuteDataSet(AccessHelper.conn, "select * from Log where [GUID]=@GUID", new OleDbParameter("@GUID", GUID)).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    PropertyInfo[] properties = entity.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
                    foreach (PropertyInfo item in properties)
                    {//循环遍历实体,取出字段和字段对应的值
                        if (item.GetValue(entity, null) != null)
                        {
                            item.SetValue(entity, dt.Rows[0][item.Name].ToString(), null);
                        }
                    }


                    return(entity);
                }
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
Пример #2
0
        //记录日志:尚未完成的task的名字和代码位置
        public static Task Log(this Task task, string tag = null,
                               [CallerMemberName] string callerMemberName = null,
                               [CallerFilePath] string callerFilePath     = null,
                               [CallerLineNumber] int callerLineNumber    = -1)
        {
            if (LogLevel == TaskLogLevel.None)
            {
                return(task);
            }
            var logEntity = new TaskLogEntity
            {
                Task             = task,
                LogTime          = DateTime.Now,
                CallerFilePath   = callerFilePath,
                CallerLineNumber = callerLineNumber,
                CallerMemberName = callerMemberName,
                Tag = tag
            };

            s_log[task] = logEntity;
            //如果task已经完成,则把这个task从记录中移除
            task.ContinueWith(t =>
            {
                TaskLogEntity entity;
                s_log.TryRemove(t, out entity);
            });
            return(task);
        }
Пример #3
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="GUID"></param>
        /// <returns></returns>
        public TaskLogEntity GetEntity(string GUID)
        {
            try
            {
                TaskLogEntity entity = new TaskLogEntity();

                DataTable dt = AccessHelper.ExecuteDataSet(AccessHelper.conn, "select * from TaskLogEntity where [GUID]=@GUID", new OleDbParameter("@GUID", GUID)).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    PropertyInfo[] properties = entity.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
                    foreach (PropertyInfo item in properties)
                    {//循环遍历实体,取出字段和字段对应的值
                        if (item.GetValue(entity, null) != null)
                        {
                            item.SetValue(entity, dt.Rows[0][item.Name].ToString(), null);
                        }
                    }


                    return(entity);
                }
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
Пример #4
0
        //public Log(LogEntity entity)
        //{
        //    XmlDocument xmlDoc = new XmlDocument();
        //    xmlDoc.Load(HttpContext.Current.Server.MapPath("/Log/Log.xml"));

        //    XmlNode node = xmlDoc.SelectSingleNode("/DataItem/Log[@GUID='" + entity.GUID + "']");
        //    if (node != null)
        //    {//日志存在就进行修改
        //        //node.SelectSingleNode("ErrorMsg").InnerText = entity.ErrorMsg;
        //        //node.SelectSingleNode("Status").InnerText = entity.Status;
        //        //node.SelectSingleNode("Type").InnerText = entity.Type;
        //        //node.SelectSingleNode("ErrorDate").InnerText = DateTime.Now.ToString();

        //        PropertyInfo[] properties = entity.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
        //        foreach (PropertyInfo item in properties)
        //        {//循环遍历实体,取出字段和字段对应的值

        //            if (item.GetValue(entity, null) != null)
        //            {
        //                node.SelectSingleNode(item.Name).InnerText = item.GetValue(entity, null).ToString();
        //            }
        //        }
        //    }
        //    else
        //    {//不存在日志就进行创建
        //        XmlNode root = xmlDoc.SelectSingleNode("DataItem");

        //        XmlElement xe1 = xmlDoc.CreateElement("Log");

        //        xe1.SetAttribute("GUID", entity.GUID);

        //        PropertyInfo[] properties = entity.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
        //        foreach (PropertyInfo item in properties)
        //        {//循环遍历实体,取出字段和字段对应的值

        //            if (item.GetValue(entity, null) != null)
        //            {
        //                XmlElement xe1sub1 = xmlDoc.CreateElement(item.Name);
        //                xe1sub1.InnerText = item.GetValue(entity, null).ToString();
        //                xe1.AppendChild(xe1sub1);
        //            }
        //        }



        //        //XmlElement xe1sub2 = xmlDoc.CreateElement("Status");
        //        //xe1sub2.InnerText = entity.Status;
        //        //xe1.AppendChild(xe1sub2);

        //        //XmlElement xe1sub3 = xmlDoc.CreateElement("Type");
        //        //xe1sub3.InnerText = entity.Type;
        //        //xe1.AppendChild(xe1sub3);

        //        //XmlElement xe1sub4 = xmlDoc.CreateElement("Name");
        //        //xe1sub4.InnerText = entity.Name;
        //        //xe1.AppendChild(xe1sub4);

        //        //XmlElement xe1sub5 = xmlDoc.CreateElement("Description");
        //        //xe1sub5.InnerText = entity.Description;
        //        //xe1.AppendChild(xe1sub5);

        //        //XmlElement xe1sub6 = xmlDoc.CreateElement("DataInfo");
        //        //xe1sub6.InnerText = entity.DataInfo;
        //        //xe1.AppendChild(xe1sub6);

        //        //XmlElement xe1sub7 = xmlDoc.CreateElement("ErrorMsg");
        //        //xe1sub7.InnerText = entity.ErrorMsg;
        //        //xe1.AppendChild(xe1sub7);

        //        //XmlElement xe1sub9 = xmlDoc.CreateElement("ErrorDate");
        //        //xe1sub9.InnerText = entity.ErrorMsg;
        //        //xe1.AppendChild(xe1sub9);

        //        //XmlElement xe1sub8 = xmlDoc.CreateElement("Parameter");

        //        //PropertyInfo[] properties = t.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);

        //        //string datajson = "{";
        //        //foreach (PropertyInfo item in properties)
        //        //{//循环遍历实体,取出字段和字段对应的值

        //        //    if (item.GetValue(t, null) != null)
        //        //    {
        //        //        //XmlElement xe1sub4su1 = xmlDoc.CreateElement("Item");
        //        //        //xe1sub4su1.SetAttribute("Field", item.Name);
        //        //        //xe1sub4su1.InnerText = item.GetValue(t, null).ToString();
        //        //        //xe1sub8.AppendChild(xe1sub4su1);
        //        //        datajson += (datajson == "{" ? "" : ",") + "\"" + item.Name + "\":\"" + item.GetValue(t, null).ToString() + "\"";
        //        //    }
        //        //}
        //        //datajson += "}";

        //        //xe1sub8.InnerText = datajson;

        //        //xe1.AppendChild(xe1sub8);

        //        root.AppendChild(xe1);//添加到<Data>节点中
        //    }

        //    xmlDoc.Save(HttpContext.Current.Server.MapPath("/Log/Log.xml"));
        //}

        /// <summary>
        /// 将日志存到数据库中
        /// </summary>
        /// <param name="entity"></param>
        public Log(TaskLogEntity entity)
        {
            try
            {
                System.Data.DataTable dt = AccessHelper.ExecuteDataSet(AccessHelper.conn, "select * from Log where [GUID]=@GUID", new OleDbParameter("@GUID", entity.GUID)).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    int mm = AccessHelper.ExecuteNonQuery(AccessHelper.conn, "update Log set Log.[Type]=@Type,[Name]=@Name,[Description]=@Description,[DataInfo]=@DataInfo,[ErrorMsg]=@ErrorMsg,[Parameter]=@Parameter,[AddTime]=@AddTime,[ErrorDate]=@ErrorDate,[CompleteTime]=@CompleteTime,[Status]=@Status,[Count]=@Count,[Current]=@Current,[SavePath]=@SavePath where [GUID]=@GUID ", new OleDbParameter("@Type", entity.Type), new OleDbParameter("@Name", entity.Name), new OleDbParameter("@Description", entity.Description), new OleDbParameter("@DataInfo", entity.DataInfo), new OleDbParameter("@ErrorMsg", entity.ErrorMsg), new OleDbParameter("@Parameter", entity.Parameter), new OleDbParameter("AddTime", entity.AddTime), new OleDbParameter("@ErrorDate", entity.ErrorDate), new OleDbParameter("@CompleteTime", entity.CompleteTime), new OleDbParameter("@Status", entity.Status), new OleDbParameter("@Count", entity.Count), new OleDbParameter("@Current", entity.Current), new OleDbParameter("@SavePath", entity.SavePath), new OleDbParameter("@GUID", entity.GUID));
                }
                else
                {
                    int mm = AccessHelper.ExecuteNonQuery(AccessHelper.conn, "insert into Log([GUID],[Type],[Name],[Description],[DataInfo],[ErrorMsg],[Parameter],[AddTime],[ErrorDate],[CompleteTime],[Status],[Count],[Current],[SavePath]) values(@GUID,@Type,@Name,@Description,@DataInfo,@ErrorMsg,@Parameter,@AddTime,@ErrorDate,@CompleteTime,@Status,@Count,@Current,@SavePath)", new OleDbParameter("@GUID", entity.GUID), new OleDbParameter("@Type", entity.Type), new OleDbParameter("@Name", entity.Name), new OleDbParameter("@Description", entity.Description), new OleDbParameter("@DataInfo", entity.DataInfo), new OleDbParameter("@ErrorMsg", entity.ErrorMsg), new OleDbParameter("@Parameter", entity.Parameter), new OleDbParameter("AddTime", entity.AddTime), new OleDbParameter("@ErrorDate", entity.ErrorDate), new OleDbParameter("@CompleteTime", entity.CompleteTime), new OleDbParameter("@Status", entity.Status), new OleDbParameter("@Count", entity.Count), new OleDbParameter("@Current", entity.Current), new OleDbParameter("@SavePath", entity.SavePath));
                }
            }
            catch (Exception ex)
            {
            }
        }
Пример #5
0
        /// <summary>
        /// 百度矢量要素下载(数据下载写入shp文件的时候可能出现问题,比如下载网络波动中断到时系统无法识别(解决办法先吧数据下载到数据在写入shp文件))
        /// </summary>
        /// <param name="Result"></param>
        /// <returns></returns>
        public WebApiResult <string> BaiduDownload(BaiduMapFeatureDownloadResult Result)
        {
            this.countdown       = new CountdownEvent(Result.TaskCount);
            this.Result_BFeature = Result;
            this.N = Result.TaskCount;

            UpdateLastLoc <BaiduMapFeatureDownloadResult>(Result.GUID);

            log = new TaskLogEntity()
            {
                GUID = Result.GUID, Name = Result.TName, Type = "矢量要素", Description = "BaiduDownload", Status = "进行中", Parameter = JsonHelper.ToJson(Result), SavePath = Result.SavePathText
            };
            //操作日志
            new Log <BaiduMapFeatureDownloadResult>(log);

            if (Result.LayerName == "道路")
            {
                xmlDoc.Load(MapFeatureConfig);

                ///////////////////////////////////////////////////////////////////////////////
                // GDAL创建shp文件
                // 注册所有的驱动
                Ogr.RegisterAll();
                // GDAL中文路径支持
                OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
                // 属性表字段中文支持
                OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", "CP936");
                // 设置坐标系存储文件夹gdal-data路径
                OSGeo.GDAL.Gdal.SetConfigOption("GDAL_DATA", System.Windows.Forms.Application.StartupPath + "\\gdal-data");
                Driver oDriver = Ogr.GetDriverByName("ESRI Shapefile");
                if (oDriver == null)
                {
                    return(new WebApiResult <string>()
                    {
                        success = 0, msg = "GDAL驱动不可用,请检查!"
                    });
                }
                // 创建数据源
                DataSource oDS = oDriver.CreateDataSource(Result.SavePathText, null);
                if (oDS == null)
                {
                    return(new WebApiResult <string>()
                    {
                        success = 0, msg = "创建数据源失败,请检查!"
                    });
                }
                oLayer = oDS.GetLayerByName(Result.TName);
                if (oLayer == null)
                {
                    // 创建图层,创建一个多线图层,并指定空间参考
                    OSGeo.OSR.SpatialReference oSRS = new OSGeo.OSR.SpatialReference("PROJCS[\"WGS_1984_Pseudo_Mercator\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Mercator\"],PARAMETER[\"false_easting\",0.0],PARAMETER[\"false_northing\",0.0],PARAMETER[\"central_meridian\",0.0],PARAMETER[\"standard_parallel_1\",0.0],UNIT[\"Meter\",1.0]]");
                    //OSGeo.OSR.SpatialReference oSRS = new OSGeo.OSR.SpatialReference("");
                    //oSRS.SetWellKnownGeogCS("EPSG:4326");
                    oLayer = oDS.CreateLayer(Result.TName, oSRS, wkbGeometryType.wkbMultiLineString, null);
                    if (oLayer == null)
                    {
                        return(new WebApiResult <string>()
                        {
                            success = 0, msg = "创建图层失败,请检查!"
                        });
                    }

                    // 创建属性表
                    // 先创建一个叫Name的字符型属性,字符长度为100
                    FieldDefn oFieldName = new FieldDefn("Name", FieldType.OFTString);
                    oFieldName.SetWidth(100);
                    oLayer.CreateField(oFieldName, 1);
                    // 再创建一个叫Type的字符型属性,字符长度为50
                    FieldDefn oFieldType = new FieldDefn("Type", FieldType.OFTString);
                    oFieldType.SetWidth(50);
                    oLayer.CreateField(oFieldType, 1);
                    // 再创建一个叫UID的字符型属性,字符长度为50
                    FieldDefn oFieldUID = new FieldDefn("UID", FieldType.OFTString);
                    oFieldUID.SetWidth(50);
                    oLayer.CreateField(oFieldUID, 1);
                }

                /////////////////////////////////////////////////////////////////////////////////
                threadlog = new ThreadTaskLogEntity()
                {
                    GUID = Result.GUID, TaskLog_GUID = Result.GUID, Status = "进行中", TStatus = 1, TName = Result.TName, IsPaused = false, URL = Result.URL, Parameter = JsonHelper.ToJson(Result)
                };
                //计算Total并更新
                threadlog.Total = GetList("SELECT KWName FROM mapbar_poi WHERE KWType = '道路'", "KWName").Count;
                new Log <BaiduMapFeatureDownloadResult>(threadlog);
                log.Count = threadlog.Total;
                new Log <BaiduMapFeatureDownloadResult>(log);

                Thread[] t = new Thread[Result.TaskCount];
                for (int num = 0; num < Result.TaskCount; num++)
                {
                    try
                    {
                        t[num] = new Thread(new ParameterizedThreadStart(run_BFeature))
                        {
                            Name = "Thread " + num.ToString()
                        };
                        t[num].Start(num);
                    }
                    catch (Exception ex)
                    {
                        threadlog.Status   = "错误";
                        threadlog.ErrorMsg = ex.ToString();
                        threadlog.TStatus  = 3;
                        new Log <BaiduMapFeatureDownloadResult>(threadlog);

                        log.Status    = "错误";
                        log.ErrorMsg  = ex.ToString();
                        log.ErrorDate = DateTime.Now.ToString();
                        //操作日志
                        new Log <BaiduMapFeatureDownloadResult>(log);

                        return(new WebApiResult <string>()
                        {
                            success = 0, msg = ex.ToString()
                        });
                    }
                }
                countdown.Wait();
                oLayer.Dispose();
                oDS.Dispose();
                for (int num = 0; num < Result.TaskCount; num++)
                {
                    t[num].Abort();
                }
                lock (obj)
                {
                    if (!Log <BaiduMapFeatureDownloadResult> .GetThreadLogEntity(this.Result_BFeature.GUID).IsPaused)
                    {
                        //配置文件参数信息更新
                        xmlDoc["MapFeature"]["bmap"]["dict_index"].InnerText = "0";
                        xmlDoc.Save(MapFeatureConfig);

                        log.Status            = "已完成";
                        log.CompleteTime      = DateTime.Now.ToString();
                        log.Current           = log.Count;
                        threadlog.Status      = "已完成";
                        threadlog.TStatus     = 2;
                        threadlog.Current     = threadlog.Total;
                        threadlog.Current_loc = List2Str(current_loc);
                        //操作日志
                        new Log <BaiduMapFeatureDownloadResult>(threadlog);
                        new Log <BaiduMapFeatureDownloadResult>(log);
                        return(new WebApiResult <string>()
                        {
                            success = 1, msg = "百度地图要素下载完成!"
                        });
                    }
                }
            }
            else
            {
                return(new WebApiResult <string>()
                {
                    success = 2, msg = "图层类型不符合"
                });
            }
            return(null);
        }
Пример #6
0
        //StreamWriter watch;

        #region 百度瓦片地图个性化下载

        /// <summary>
        /// 百度瓦片地图个性化下载(暂时不使用)
        /// </summary>
        /// <returns></returns>
        //public WebApiResult<string> BaiduMapTileDownload(BaiduMapTileDownloadRequest Request)
        //{
        //    var log = new TaskLogEntity() { GUID = Request.GUID, Name = "百度瓦片下载", Type = "瓦片下载", Description = "BaiduMapTileDownload1", Status = "进行中", Parameter = JsonHelper.ToJson(Request) };
        //    //操作日志
        //    new Log<BaiduMapTileDownloadRequest>(log);

        //    try
        //    {
        //        string URLtextBox = GetDownloadUrl(Request.List_TreeNode);
        //        //检查URL地址栏
        //        if (URLtextBox == "")
        //        {
        //            //MessageBox.Show(this, "URL地址为空,请检查!", "提示");
        //            return new WebApiResult<string>() { success = 2, msg = "URL地址为空,请检查!" };
        //        }

        //        //确定要下载的坐标范围信息,起始坐标为左下角,终点坐标为右上角
        //        double startcoord_x = Request.LefttextBox;
        //        double startcoord_y = Request.BottomtextBox;
        //        double endcoord_x = Request.RighttextBox;
        //        double endcoord_y = Request.UptextBox;
        //        LatLngPoint startcoord, endcoord;

        //        //if (startcoord_x > 0 && startcoord_x < endcoord_x && endcoord_x < 180 && startcoord_y > 0 && startcoord_y < endcoord_x && endcoord_y < 90)
        //        {
        //            startcoord = new LatLngPoint(startcoord_y, startcoord_x);
        //            endcoord = new LatLngPoint(endcoord_y, endcoord_x);
        //        }
        //        //else
        //        //{
        //        //    return new WebApiResult<string>() { success = 2, msg = "输入坐标值不正确,请检查!" };
        //        //}

        //        //检查下载层级是否勾选
        //        if (Request.LevelList.Length == 0)
        //        {
        //            return new WebApiResult<string>() { success = 2, msg = "下载地图层级未选择,请检查!" };
        //        }
        //        //获取要下载的地图层级
        //        foreach (int Level in Request.LevelList)
        //        {
        //            //int z = Level;
        //            Tuple<int, int, int, int> BoundTup = GetTileBound(startcoord, endcoord, Level);
        //            for (int i = BoundTup.Item1; i <= BoundTup.Item3; i++)
        //            {
        //                for (int j = BoundTup.Item2; j <= BoundTup.Item4; j++)
        //                {
        //                    try
        //                    {
        //                        String link = String.Format(URLtextBox, Math.Abs(i + j) % 3, i, j, Level);
        //                        String localpath = Request.SavePathText + String.Format("\\{0}\\{1}\\", Level, i);
        //                        String filename = String.Format("{0}.png", j);
        //                        //判断文件是否存在,若存在,直接下载下一个文件
        //                        if (File.Exists(localpath + filename)) continue;
        //                        //下载文件
        //                        String downloadedfile = "";
        //                        do
        //                        {
        //                            downloadedfile = DownloadFile(link, localpath, filename);
        //                            Thread.Sleep(100);
        //                            try
        //                            {
        //                                Image img = Image.FromFile(localpath + filename);
        //                            }
        //                            catch (Exception)
        //                            {
        //                                File.Delete(localpath + filename);
        //                                downloadedfile = "";
        //                            }
        //                        } while (downloadedfile == "");
        //                    }
        //                    catch (Exception ex)
        //                    {
        //                        log.Status = "错误";
        //                        log.ErrorMsg = ex.ToString();
        //                        log.ErrorDate = DateTime.Now.ToString();
        //                        new Log<BaiduMapTileDownloadRequest>(log);
        //                        return null;
        //                    }
        //                }
        //            }
        //        }

        //        log.Status = "已完成";
        //        log.CompleteTime = DateTime.Now.ToString();
        //        new Log<BaiduMapTileDownloadRequest>(log);
        //    }
        //    catch (Exception ex)
        //    {
        //        log.Status = "错误";
        //        log.ErrorMsg = ex.ToString();
        //        log.ErrorDate = DateTime.Now.ToString();
        //        new Log<BaiduMapTileDownloadRequest>(log);
        //    }
        //    return null;
        //}

        /// <summary>
        /// 百度瓦片地图个性化下载(当前使用)
        /// </summary>
        /// <returns></returns>
        public WebApiResult <string> BaiduMapTileDownload1(BaiduMapTileDownloadRequest Request)
        {
            //watch = new StreamWriter(new FileStream(System.AppDomain.CurrentDomain.BaseDirectory + "\\App_Data\\ThreadLog.txt", FileMode.Create));
            this.countdown = new CountdownEvent(Request.TaskCount);
            this.request   = Request;

            UpdateLastLoc(Request.GUID);

            log = new TaskLogEntity()
            {
                GUID = Request.GUID, Name = Request.TName, Type = "百度瓦片下载", Description = "BaiduMapTileDownload1", Status = "进行中", Parameter = JsonHelper.ToJson(Request), SavePath = request.SavePathText
            };
            //操作日志
            new Log <BaiduMapTileDownloadRequest>(log);
            try
            {
                if (Request.LayerStr == "sate")
                {
                    this.URLtextBox = "https://ss{0}.bdstatic.com/8bo_dTSlR1gBo1vgoIiO_jowehsv/starpic/?qt=satepc&u=x={1};y={2};z={3};v=009;type=sate";
                }
                else
                {
                    this.URLtextBox = "http://api{0}.map.bdimg.com/customimage/tile?&x={1}&y={2}&z={3}&scale=1&ak=8d6c8b8f3749aed6b1aff3aad6f40e37&" + Request.LayerStr; //GetDownloadUrl(Request.List_TreeNode);
                                                                                                                                                                         //检查URL地址栏http://api{0}.map.bdimg.com/customimage/tile?&x={1}&y={2}&z={3}&scale=1&ak=8d6c8b8f3749aed6b1aff3aad6f40e37&styles=t:background|e:all|v:off,t:poi|e:all|v:off,t:administrative|e:all|v:off
                }
                if (URLtextBox == "")
                {
                    //MessageBox.Show(this, "URL地址为空,请检查!", "提示");
                    return(new WebApiResult <string>()
                    {
                        success = 2, msg = "URL地址为空,请检查!"
                    });
                }

                //确定要下载的坐标范围信息,起始坐标为左下角,终点坐标为右上角
                double startcoord_x = Request.LefttextBox;
                double startcoord_y = Request.BottomtextBox;
                double endcoord_x   = Request.RighttextBox;
                double endcoord_y   = Request.UptextBox;

                //if (startcoord_x > 0 && startcoord_x < endcoord_x && endcoord_x < 180 && startcoord_y > 0 && startcoord_y < endcoord_y && endcoord_y < 90)
                //{
                this.startcoord = new LatLngPoint(startcoord_y, startcoord_x);
                this.endcoord   = new LatLngPoint(endcoord_y, endcoord_x);
                //}
                //else
                //{
                //    return new WebApiResult<string>() { success = 2, msg = "输入坐标值不正确,请检查!" };
                //}
                //检查下载层级是否勾选
                if (Request.LevelList.Length == 0)
                {
                    return(new WebApiResult <string>()
                    {
                        success = 2, msg = "下载地图层级未选择,请检查!"
                    });
                }

                threadlog = new ThreadTaskLogEntity()
                {
                    GUID = Request.GUID, TaskLog_GUID = Request.GUID, Status = "进行中", TStatus = 1, Total = 0, TName = Request.TName, IsPaused = false, Parameter = JsonHelper.ToJson(Request), URL = Request.URL
                };
                //计算Total并更新
                foreach (int Level in Request.LevelList)
                {
                    Tuple <int, int, int, int> BoundTup = GetTileBound(startcoord, endcoord, Level);
                    threadlog.Total += (BoundTup.Item3 - BoundTup.Item1 + 1) * (BoundTup.Item4 - BoundTup.Item2 + 1);
                }
                log.Count = threadlog.Total;
                new Log <BaiduMapTileDownloadRequest>(log);
                new Log <BaiduMapTileDownloadRequest>(threadlog);

                interval = new double[] { (endcoord.Lat - startcoord.Lat) / Request.TaskCount, (endcoord.Lng - startcoord.Lng) / Request.TaskCount };

                Thread[] t = new Thread[Request.TaskCount];
                for (int num = 0; num < Request.TaskCount; num++)
                {
                    try
                    {
                        t[num] = new Thread(new ParameterizedThreadStart(run))
                        {
                            Name = "Thread " + num.ToString()
                        };
                        t[num].Start(num);
                    }
                    catch (Exception ex)
                    {
                        threadlog.Status   = "错误";
                        threadlog.ErrorMsg = ex.ToString();
                        threadlog.TStatus  = 3;
                        new Log <BaiduMapTileDownloadRequest>(threadlog);

                        log.Status    = "错误";
                        log.ErrorMsg  = ex.ToString();
                        log.ErrorDate = DateTime.Now.ToString();
                        //操作日志
                        new Log <BaiduMapTileDownloadRequest>(log);

                        return(new WebApiResult <string>()
                        {
                            success = 0, msg = ex.ToString()
                        });
                    }
                }
                countdown.Wait();

                //watch.Close();
                for (int num = 0; num < Request.TaskCount; num++)
                {
                    t[num].Abort();
                }
                lock (obj)
                {
                    if (!Log <BaiduMapTileDownloadRequest> .GetThreadLogEntity(this.request.GUID).IsPaused)
                    {
                        log.Status            = "已完成";
                        log.CompleteTime      = DateTime.Now.ToString();
                        log.Current           = log.Count;
                        threadlog.Status      = "已完成";
                        threadlog.TStatus     = 2;
                        threadlog.Current     = threadlog.Total;
                        threadlog.Current_loc = List2Str(current_loc);
                        //操作日志
                        new Log <BaiduMapTileDownloadRequest>(threadlog);
                        new Log <BaiduMapTileDownloadRequest>(log);
                        return(new WebApiResult <string>()
                        {
                            success = 1, msg = "百度瓦片下载完成!"
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                log.Status    = "错误";
                log.ErrorMsg  = ex.ToString();
                log.ErrorDate = DateTime.Now.ToString();
                new Log <BaiduMapTileDownloadRequest>(log);
                return(new WebApiResult <string>()
                {
                    success = 0, msg = ex.ToString()
                });
            }

            return(null);
        }
Пример #7
0
        /// <summary>
        /// 百度瓦片地图拼接
        /// </summary>
        /// <param name="Result"></param>
        /// <returns></returns>
        public WebApiResult <string> BaiduTileSplicing(BaiduTileSplicingResult Result)
        {
            this.Result_baidu = Result;
            UpdateLastLoc <BaiduTileSplicingResult>(Result.GUID);

            log = new TaskLogEntity()
            {
                GUID = Result.GUID, Name = Result.TName, Type = "瓦片拼接", Description = "BaiduTileSplicing", Status = "进行中", Parameter = JsonHelper.ToJson(Result), SavePath = Result.SavePath
            };
            //操作日志
            new Log <BaiduTileSplicingResult>(log);
            threadlog = new ThreadTaskLogEntity()
            {
                GUID = this.Result_baidu.GUID, TaskLog_GUID = this.Result_baidu.GUID, Status = "进行中", Current = current, TStatus = 1, TName = Result_baidu.TName, IsPaused = false, URL = Result_baidu.URL, Parameter = JsonHelper.ToJson(Result_baidu)
            };
            new Log <BaiduTileSplicingResult>(threadlog);

            try
            {
                //监测瓦片地图拼接耗时
                //Stopwatch stopwatch = new Stopwatch();
                //stopwatch.Start();

                //百度地图瓦片相关信息获取,文件路径必须选取到z级(缩放层级)文件夹
                String          FilePath    = Result.FilePath;
                DirectoryInfo   TheFolder   = new DirectoryInfo(FilePath);
                DirectoryInfo[] folder_list = TheFolder.GetDirectories();
                ////百度瓦片地图拼接
                String savepath = Result.SavePath;
                var    restuls  = ParallelWriteImage(folder_list, savepath, 0, Result.crstype, Result.Size);

                if (restuls != null)
                {
                    log.Status       = "已完成";
                    log.CompleteTime = DateTime.Now.ToString();
                    log.Current      = log.Count;

                    threadlog.TStatus = 2;
                    threadlog.Status  = "已完成";
                    threadlog.Current = threadlog.Total;
                    //操作日志
                    new Log <BaiduTileSplicingResult>(threadlog);
                    new Log <BaiduTileSplicingResult>(log);

                    return(restuls);
                }
                //stopwatch.Stop();
            }
            catch (Exception ex)
            {
                threadlog.Status   = "错误";
                threadlog.ErrorMsg = ex.ToString();
                threadlog.TStatus  = 3;
                new Log <BaiduTileSplicingResult>(threadlog);

                log.Status    = "错误";
                log.ErrorMsg  = ex.ToString();
                log.ErrorDate = DateTime.Now.ToString();
                new Log <BaiduTileSplicingResult>(log);

                return(new WebApiResult <string>()
                {
                    success = 0, msg = ex.ToString()
                });
            }
            return(null);
        }
Пример #8
0
        /// <summary>
        /// 高德瓦片地图拼接
        /// </summary>
        /// <param name="Result"></param>
        /// <returns></returns>
        public WebApiResult <string> GaodeTileSplicing(GaodeTileSplicingResult Result)
        {
            this.Result_gaode = Result;
            UpdateLastLoc <GaodeTileSplicingResult>(Result.GUID);

            log = new TaskLogEntity()
            {
                GUID = Result.GUID, Name = Result.TName, Type = "瓦片拼接", Description = "GaodeTileSplicing", Status = "进行中", Parameter = JsonHelper.ToJson(Result), SavePath = Result.SavePath
            };
            //操作日志
            new Log <GaodeTileSplicingResult>(log);

            threadlog = new ThreadTaskLogEntity()
            {
                GUID = this.Result_gaode.GUID, TaskLog_GUID = this.Result_gaode.GUID, Status = "进行中", TStatus = 1, TName = Result_gaode.TName, IsPaused = false, URL = Result_gaode.URL, Parameter = JsonHelper.ToJson(Result_gaode)
            };
            new Log <BaiduTileSplicingResult>(threadlog);

            try
            {
                //耗时统计
                //Stopwatch stopwatch = new Stopwatch();
                //stopwatch.Start();

                //高德地图瓦片相关信息获取,文件路径必须选取到z级(缩放层级)文件夹
                String          FilePath    = Result.FilePath;
                DirectoryInfo   TheFolder   = new DirectoryInfo(FilePath);
                DirectoryInfo[] folder_list = TheFolder.GetDirectories();
                ////整个瓦片地图范围,用于创建拼接大影像
                //FileInfo[] file_list = GetFileList(TheFolder);
                //List<Point> TilePoints = GetTileCoor(file_list);
                //Tuple<int, int, int, int> TileBoundary = GetBoundary(TilePoints);

                ////高德瓦片地图拼接
                String savepath = Result.SavePath;
                var    restuls  = ParallelWriteImage(folder_list, savepath, 1, "", Result.Size);

                if (restuls != null)
                {
                    log.Status       = "已完成";
                    log.CompleteTime = DateTime.Now.ToString();
                    log.Current      = log.Count;

                    threadlog.TStatus = 2;
                    threadlog.Status  = "已完成";
                    threadlog.Current = threadlog.Total;
                    //操作日志
                    new Log <GaodeTileSplicingResult>(threadlog);
                    new Log <GaodeTileSplicingResult>(log);

                    string dir = FilePath;
                    FileDelete(dir);

                    return(restuls);
                }
                //stopwatch.Stop();
            }
            catch (Exception ex)
            {
                threadlog.Status   = "错误";
                threadlog.ErrorMsg = ex.ToString();
                threadlog.TStatus  = 3;
                new Log <GaodeTileSplicingResult>(threadlog);

                log.Status    = "错误";
                log.ErrorMsg  = ex.ToString();
                log.ErrorDate = DateTime.Now.ToString();
                new Log <GaodeTileSplicingResult>(log);

                return(new WebApiResult <string>()
                {
                    success = 0, msg = ex.ToString()
                });
            }
            return(null);
        }