1、Arcengine调用GP服务,抛出异常方法
object sev = null; try { Application.DoEvents(); gp.Execute(gpBuildPyramidsandStatistics, null); Application.DoEvents(); Console.WriteLine(gp.GetMessages(ref sev)); } catch (Exception ex) { // Print geoprocessing execution error messages. MessageBox.Show(gp.GetMessages(ref sev)); } //ps:调用GP服务处理数据库中的数据,必须添加gp的环境变量workspace.http://www.ithao123.cn/content-7464230.html
2、日志生成
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Windows.Forms; namespace Geoway.IDB.FileCheck.Utility { ///<summary> ///目的:日志操作类 ///创建人:jwh ///创建日期:2016/7/11 ///修改描述: ///修改人: ///修改日期: ///备注: ///</summary> public class LogExport { private static object _lockerForLog = new object(); public static string LOGPATH = Application.StartupPath + "\\log\\checklog";//日志文件夹 /// <summary> /// 记录日志 /// </summary> /// <param name="content"></param> /// <param name="logPath"></param> public static void SaveLog(string content, string logPath = "") { try { if (string.IsNullOrEmpty(logPath)) { logPath = LOGPATH; } lock (_lockerForLog) { FileStream fs; if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } fs = new FileStream(Path.Combine(logPath, DateTime.Now.ToString("yyyyMMdd") + ".log"), FileMode.OpenOrCreate); StreamWriter streamWriter = new StreamWriter(fs); streamWriter.BaseStream.Seek(0, SeekOrigin.End); streamWriter.WriteLine(DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss") + " " + content); streamWriter.Flush(); streamWriter.Close(); fs.Close(); } } catch { } } } }
3、获取数据库中的镶嵌数据集
/// <summary> /// 获取界面上选择的镶嵌数据集 /// </summary> /// <returns></returns> public IMosaicDataset GetMosaicDataset() { try { _selMosicName = cmbMosicData.SelectedItem.ToString(); IPropertySet propertySet = new PropertySetClass(); propertySet.SetProperty("SERVER", ""); propertySet.SetProperty("INSTANCE", "sde:oracle11g:XXX.XXX.XXX/db11g"); propertySet.SetProperty("USER", "XXX"); propertySet.SetProperty("PASSWORD", "XXX"); propertySet.SetProperty("DATABASE", ""); propertySet.SetProperty("VERSION", ""); IWorkspaceFactory2 workspaceFactory2 = new SdeWorkspaceFactoryClass(); IWorkspace pWorkspace = workspaceFactory2.Open(propertySet, 0); IMosaicDataset pMosicDataset = null; IMosaicWorkspaceExtensionHelper pMosaicWsExHelper = new MosaicWorkspaceExtensionHelperClass(); IMosaicWorkspaceExtension pMosaicWsExt = pMosaicWsExHelper.FindExtension(pWorkspace); if (pMosaicWsExt != null) { try { pMosicDataset = pMosaicWsExt.OpenMosaicDataset(_selMosicName); } catch (Exception ex) { return pMosicDataset; } } return pMosicDataset; } catch (Exception ex) { return null; } }
时间: 2024-10-13 01:35:37