private void Continuer(Task<HttpResponseMessage> task, log4net.Core.IErrorHandler errorHandler = null) { if (task.IsFaulted) { // Should always be true var flattened = task.Exception.Flatten(); if (errorHandler != null) { // If there is a log4net error handler defined, send the error(s)... otherwise ignore foreach (var inner in flattened.InnerExceptions) { errorHandler.Error("Log4Netly PostAsync error.", inner); } } } }
public static void LogError(log4net.ILog log, string message, Exception e) { if (log == null || e == null) return; if (log.IsErrorEnabled) { log.Error(message); log.Error(e.Message); log.Error(e.Source); log.Error(e.StackTrace); if (e.InnerException != null) { log.Error(e.InnerException.Message); log.Error(e.InnerException.Source); log.Error(e.InnerException.StackTrace); } } }
private void Log(log4net.ILog logger, LogLevel logLevel, string message, Exception excpetion) { switch (logLevel) { case LogLevel.Debug: if (logger.IsDebugEnabled) logger.Debug(message, excpetion); break; case LogLevel.Info: if (logger.IsInfoEnabled) logger.Info(message, excpetion); break; case LogLevel.Warn: if (logger.IsWarnEnabled) logger.Warn(message, excpetion); break; case LogLevel.Error: if (logger.IsErrorEnabled) logger.Error(message, excpetion); break; case LogLevel.Fatal: if (logger.IsFatalEnabled) logger.Fatal(message, excpetion); break; case LogLevel.Off: break; default: throw new Exception(string.Format("Unrecognized log level '{0}'.", logLevel.ToString())); } }
//http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011 public static void UploadImages(string location, string folderTcmId, CoreService2010Client client, log4net.ILog Log) { //create a reference to the directory of where the images are DirectoryInfo directory = new DirectoryInfo(location); //create global Tridion Read Options ReadOptions readOptions = new ReadOptions(); //use Expanded so that Tridion exposes the TcmId of the newly created component readOptions.LoadFlags = LoadFlags.Expanded; try { //loop through the files foreach (FileInfo fileInfo in directory.GetFiles()) { //only allow images if (IsAllowedFileType(fileInfo.Extension)) { try { //create a new multimedia component in the folder specified ComponentData multimediaComponent = (ComponentData)client.GetDefaultData(Tridion.ItemType.Component, folderTcmId); multimediaComponent.Title = fileInfo.Name.ToLower(); multimediaComponent.ComponentType = ComponentType.Multimedia; multimediaComponent.Schema.IdRef = ConfigurationManager.AppSettings["MultimediaSchemaId"]; //create a string to hold the temporary location of the image to use later string tempLocation = ""; //use the StreamUpload2010Client to upload the image into Tridion UploadResponse us = new UploadResponse(); using (Tridion.StreamUpload2010Client streamClient = new StreamUpload2010Client()) { FileStream objfilestream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read); tempLocation = streamClient.UploadBinaryContent(fileInfo.Name.ToLower(), objfilestream); } //creat a new binary component BinaryContentData binaryContent = new BinaryContentData(); //set this temporary upload location to the source of this binary binaryContent.UploadFromFile = tempLocation; binaryContent.Filename = fileInfo.Name.ToLower(); //get the multimedia type id binaryContent.MultimediaType = new LinkToMultimediaTypeData() { IdRef = GetMultimediaTypeId(fileInfo.Extension) }; multimediaComponent.BinaryContent = binaryContent; //save the image into a new object IdentifiableObjectData savedComponent = client.Save(multimediaComponent, readOptions); //check in using the Id of the new object client.CheckIn(savedComponent.Id, null); } catch (Exception ex) { Log.Debug("Error creating image " + fileInfo.Name, ex); } } } } catch (Exception ex) { Log.Error("Error processing images", ex); } finally { //clean up temp objects } }
public static int QuanShiPush(TaskDto task, string[] actions, log4net.ILog logger) { //_sem.Wait(); try { //var CreateQuanShiToKenAsync = TaskPush.CreateQuanShiToKenAsync(); //_sem.Wait(); string data = TaskPush.CreateQuanShiToKen(); LoginRequestModel re = new LoginRequestModel(); re = JsonConvert.DeserializeObject<LoginRequestModel>(data); if (re.crrorCode == 0) { OANewsModel oa = new OANewsModel(); oa.username = re.data.username; oa.token = re.data.token; OANewsDataModel oaData = new OANewsDataModel(); List<string> users = new List<string>(); if (string.IsNullOrEmpty(IsEmail)) { users.Add(task.Destination.Replace(WindowDomain + @"\", "")); } else { users.Add(task.Destination.Replace(WindowDomain + @"\", "") + IsEmail); } oaData.toUsers = users.ToArray(); oaData.toPartyIds = new int[] { }; oaData.appId = 136; oaData.title = task.Folio; oaData.color = "red"; oaData.status = 11; oaData.elements = new List<object>(); string sharedUser = string.IsNullOrEmpty(task.SharedUser) ? "null" : task.SharedUser; oaData.detailURL = string.Format(TaskUrl + "task/{0}/{1}/{2}/{3}", task.SN, task.ProcInstID, System.Web.HttpUtility.UrlEncode(task.Destination), sharedUser); oaData.detailAuth = 1; //申请信息 OANewsDataTextRichModel text1 = new OANewsDataTextRichModel(); text1.type = "text"; //text1.status = 11; text1.content = new List<OANewsDataTextContentModel>(); OANewsDataTextContentModel content = new OANewsDataTextContentModel() { size = 2, bold = 1, text = "申请信息" }; text1.content.Add(content); oaData.elements.Add(text1); OANewsDataTextModel text6 = new OANewsDataTextModel() { type = "text", content = " " }; oaData.elements.Add(text6); //申请人 OANewsDataTextRichModel text2 = new OANewsDataTextRichModel(); text2.type = "text"; //text2.status = 11; text2.content = new List<OANewsDataTextContentModel>(); content = new OANewsDataTextContentModel() { bold = 1, text = "申请人:" }; text2.content.Add(content); content = new OANewsDataTextContentModel() { bold = 0, text = task.Originator }; text2.content.Add(content); oaData.elements.Add(text2); OANewsDataTextRichModel text3 = new OANewsDataTextRichModel(); text3.type = "text"; //text3.status = 11; text3.content = new List<OANewsDataTextContentModel>(); content = new OANewsDataTextContentModel() { bold = 1, text = "申请时间:" }; text3.content.Add(content); content = new OANewsDataTextContentModel() { bold = 0, text = task.StartDate.ToString("yyyy-MM-dd HH:mm") }; text3.content.Add(content); oaData.elements.Add(text3); OANewsDataTextRichModel text4 = new OANewsDataTextRichModel(); text4.type = "text"; //text4.status = 11; text4.content = new List<OANewsDataTextContentModel>(); content = new OANewsDataTextContentModel() { bold = 1, text = "当前环节:" }; text4.content.Add(content); content = new OANewsDataTextContentModel() { bold = 0, text = task.ActivityName }; text4.content.Add(content); oaData.elements.Add(text4); OANewsDataTextModel text7 = new OANewsDataTextModel() { type = "text", content = " " }; oaData.elements.Add(text7); //操作 OANewsDataTextRichModel text5 = new OANewsDataTextRichModel(); text5.type = "text"; text5.status = 11; text5.content = new List<OANewsDataTextContentModel>(); content = new OANewsDataTextContentModel() { size = 2, bold = 1, text = "操作" }; text5.content.Add(content); oaData.elements.Add(text5); //操作 OANewsDataTextRichModel text11 = new OANewsDataTextRichModel(); text11.type = "text"; text11.status = 12; text11.content = new List<OANewsDataTextContentModel>(); content = new OANewsDataTextContentModel() { size = 2, bold = 1, text = "操作" }; text11.content.Add(content); oaData.elements.Add(text11); OANewsDataTextRichModel text10 = new OANewsDataTextRichModel(); text10.type = "text"; text10.status = 12; text10.content = new List<OANewsDataTextContentModel>(); content = new OANewsDataTextContentModel() { color = "#FF0000", bold = 1, text = "审批过程中出现错误,请重试或联系管理员处理!" }; text10.content.Add(content); oaData.elements.Add(text10); // status=11 OANewsDataActionModel action = new OANewsDataActionModel(); action.type = "action"; action.status = 11; action.buttons = new List<OANewsDataButtonModel>(); Guid sysId = Guid.NewGuid(); foreach (var item in actions) { string actionUrl = string.Format(TaskUrl + "quanShiExecuteTask?ActionName={0}&SN={1}&Destination={2}&SharedUser={3}&ProcInstID={4}", System.Web.HttpUtility.UrlEncode(item), task.SN, System.Web.HttpUtility.UrlEncode(task.Destination), sharedUser, sysId); OANewsDataButtonModel button = new OANewsDataButtonModel() { title = item, url = actionUrl }; action.buttons.Add(button); } oaData.elements.Add(action); // status=11 action = new OANewsDataActionModel(); action.type = "action"; action.status = 12; action.buttons = new List<OANewsDataButtonModel>(); foreach (var item in actions) { string actionUrl = string.Format(TaskUrl + "quanShiExecuteTask?ActionName={0}&SN={1}&Destination={2}&SharedUser={3}&ProcInstID={4}", System.Web.HttpUtility.UrlEncode(item), task.SN, System.Web.HttpUtility.UrlEncode(task.Destination), sharedUser, sysId); OANewsDataButtonModel button = new OANewsDataButtonModel() { title = item, url = actionUrl }; action.buttons.Add(button); } oaData.elements.Add(action); //状态 OANewsDataTextRichModel text8 = new OANewsDataTextRichModel(); text8.type = "text"; text8.status = 1; text8.content = new List<OANewsDataTextContentModel>(); content = new OANewsDataTextContentModel() { bold = 1, color = "#808080", text = "状态:" }; text8.content.Add(content); content = new OANewsDataTextContentModel() { bold = 0, color = "#FF0000", text = "已处理" }; text8.content.Add(content); oaData.elements.Add(text8); OANewsDataTextRichModel text9 = new OANewsDataTextRichModel(); text9.type = "text"; text9.status = 9; text9.content = new List<OANewsDataTextContentModel>(); content = new OANewsDataTextContentModel() { bold = 1, color = "#808080", text = "状态:" }; text9.content.Add(content); content = new OANewsDataTextContentModel() { bold = 0, color = "#FF0000", text = "任务已经被处理" }; text9.content.Add(content); oaData.elements.Add(text9); oa.data = oaData; string psp = JsonConvert.SerializeObject(oa); //var CreateQuanShiOAAsync = TaskPush.CreateQuanShiOAAsync(psp); string dataCheck = TaskPush.PostWebRequest(QuanShiOASendAPIUrl, psp, Encoding.UTF8); JObject obj = JObject.Parse(dataCheck); if (obj["errorCode"].ToString() == "0") { QuanShiMsgModel msg = new QuanShiMsgModel() { sysId = sysId.ToString(), msgId = obj["data"][0]["msgId"].ToString() }; SaveMsgId(msg); logger.Info("QuanShiPush_任务推送请求成功,请求消息:" + psp + ";返回消息:" + dataCheck); } else { logger.Error("QuanShiPush_任务推送请求失败,请求消息:" + psp + ";返回消息:" + dataCheck); } } //_sem.Release(); return 1; } catch (Exception ex) { logger.Error("QuanShiPush_请求失败,在执行过程中出现异常", ex); //_sem.Release(); return 2; } }
public static void QuanShiPushChange(string sysId, int newStatus, log4net.ILog logger) { string msgId = GetMsgId(sysId); try { string data = TaskPush.CreateQuanShiToKen(); LoginRequestModel re = new LoginRequestModel(); re = JsonConvert.DeserializeObject<LoginRequestModel>(data); if (re.crrorCode == 0) { OANewsChangeModel ch = new OANewsChangeModel() { username = re.data.username, token = re.data.token }; OANewsChangeDataModel item = new OANewsChangeDataModel(); item.msgId = msgId; item.newStatus = newStatus; ch.data = item; string psp = JsonConvert.SerializeObject(ch); string dataCheck = TaskPush.PostWebRequest(QuanShiOASendChangeAPIUrl, psp, Encoding.UTF8); JObject obj = JObject.Parse(dataCheck); if (obj["errorCode"].ToString() == "0") { logger.Info("QuanShiPushChange_OA消息状态更新成功,请求数据:" + sysId + ",返回数据:" + dataCheck); } else { logger.Warn("QuanShiPushChange_OA消息状态更新失败,请求数据:" + sysId + ",返回数据:" + dataCheck); } } else { logger.Warn("QuanShiPushChange_管理员登录失败,请求数据:" + sysId + ",返回数据:" + data); } } catch (Exception ex) { logger.Error("QuanShiPushChange_Login请求失败,在执行过程中出现异常", ex); } }
/// <summary> /// Log Exception Into Database Table And Local Log File /// </summary> /// <param name="Logger"></param> /// <param name="Ex"></param> /// <param name="ExceptionLevel"></param> /// <param name="UserIn"></param> public static void LogException(log4net.ILog Logger, Exception Ex, ExceptionLevelEnum ExceptionLevel, int UserIn) { aspException.Insert(DataManager.defaultInstance.ServerDateTime, Environment.UserName, Ex.Message, Ex.StackTrace, Logger.Logger.Name, ExceptionLevel.ToString(), UserIn); Logger.Error(Ex.Message, Ex); }
/* * A utility function to open the File Geodatabase workspace */ public static IWorkspace openFileGeodatabaseWorkspace(ref log4net.ILog log, string workspaceDirectory, string workspaceFolderName) { // attempting to open the file geodatabase log.Debug("Attempting to open the File Geodatabase."); log.Debug("Workspace: " + workspaceDirectory); log.Debug("Directory: " + workspaceFolderName); try { // verify the workspace does already exist log.Debug("Checking to see if the referenced File Geodatabase exists or not."); if (System.IO.Directory.Exists(workspaceDirectory + "\\" + workspaceFolderName)) { // File Geodatabase exist, create/configure a properties set log.Debug("Creating a property set object."); IPropertySet propertySet = new PropertySetClass(); // set the database value log.Debug("Setting the DATABASE value of the property set."); propertySet.SetProperty("DATABASE", workspaceDirectory + "\\" + workspaceFolderName); // create a new workspace factory to open the FDGB log.Debug("Creating a new workspace factory to open the file geodatabase."); IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass(); // Open the FDGB and return it log.Debug("Opening and returning the workspace."); return workspaceFactory.Open(propertySet, 0); } else { // Referenced File Geodatabase (FGDB) does ont exist log.Warn("Referenced File Geodatabase (FGDB) does not exist"); throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_openFileGeodatabaseWorkspace_notfound); } } catch (System.Exception ex) { // an error occured, log and throw log.Error(ex); throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_openFileGeodatabaseWorkspace_unknown); } }
public static IFeatureClass createGoogleMapsEngineCatalogFeatureClass(ref log4net.ILog log, ref GoogleMapsEngineToolsExtensionForArcGIS ext) { try { // temporary directory to store workspace string workspacedirectory = ext.getLocalWorkspaceDirectory().FullName; // add the directory to the cleanup list // TODO: Replace with scratch ext.addTemporaryDirectory(new System.IO.DirectoryInfo(workspacedirectory)); // determine the workspace name for the geodatabase //string workspacefoldername = Properties.Settings.Default.extension_gdb_workspacename; // TODO: Use sctach workspace instead of creating a temporary one string workspacefoldername = "GME_Data_" + System.Guid.NewGuid().ToString().Replace("-", ""); // define a workspace to do work IWorkspace workspace = null; // attempt to open or create the workspace try { // check to see if the workspace already exists, if so, open it if (System.IO.Directory.Exists(workspacedirectory + "\\" + workspacefoldername)) { workspace = Extension.Data.GeodatabaseUtilities.openFileGeodatabaseWorkspace(ref log, workspacedirectory, workspacefoldername); ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(Properties.Resources.GeodatabaseUtilities_schema_FeatureClassName); ESRI.ArcGIS.Geodatabase.IDataset pdataset = (ESRI.ArcGIS.Geodatabase.IDataset)featureClass; if (pdataset.CanDelete()) pdataset.Delete(); pdataset = null; featureClass = null; featureWorkspace = null; // TODO: Open instead of delete/replace //if (arcgis.ext.gdb.GeodatabaseUtilities.deleteFileGeodatabaseWorkspace(workspacedirectory, workspacefoldername)) //workspace = arcgis.ext.gdb.GeodatabaseUtilities.createFileGeodatabaseWorkspace(workspacedirectory, workspacefoldername); } else { // workspace doesn't exist, create the workspace workspace = Extension.Data.GeodatabaseUtilities.createFileGeodatabaseWorkspace(ref log, workspacedirectory, workspacefoldername); } } catch (System.Exception ex) { // unable to create the fgdb or unable to delete the fc within the fgdb log.Error(ex); System.Windows.Forms.MessageBox.Show("Unable to create or delete an existing feature class."); } // verify the workspace is open if (workspace != null) { // create a new feature workspace to work spatially IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace; // create a spatial reference for the Google Earth Builder data (always in 4326) SpatialReferenceEnvironment sRefEnvGEB = new SpatialReferenceEnvironment(); ISpatialReference sGEBRef = sRefEnvGEB.CreateGeographicCoordinateSystem(4326); // for this feature class, create and determine the field IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields; fieldsEdit.FieldCount_2 = 10; //Create the Object ID field. IField fusrDefinedField = new Field(); IFieldEdit fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_OBJECTID_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_OBJECTID_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; fieldsEdit.set_Field(0, fusrDefinedField); //Create the CustomerId field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_CustomerId_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_CustomerId_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(1, fusrDefinedField); //Create the MapAssetId field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_MapAssetId_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_MapAssetId_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(2, fusrDefinedField); //Create the AssetId field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetId_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetId_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(3, fusrDefinedField); //Create the ParentAssetId field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_ParentAssetId_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_ParentAssetId_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(4, fusrDefinedField); //Create the AssetType field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetType_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetType_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(5, fusrDefinedField); //Create the AssetName field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetName_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetName_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(6, fusrDefinedField); //Create the AssetDescription field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetDescription_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetDescription_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(7, fusrDefinedField); //Create the MapSharedWith field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_MapSharedWith_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_MapSharedWith_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(8, fusrDefinedField); // Create the Shape field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; // Set up the geometry definition for the Shape field. IGeometryDef geometryDef = new GeometryDefClass(); IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef; geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon; // By setting the grid size to 0, you're allowing ArcGIS to determine the appropriate grid sizes for the feature class. // If in a personal geodatabase, the grid size will be 1000. If in a file or ArcSDE geodatabase, the grid size // will be based on the initial loading or inserting of features. geometryDefEdit.GridCount_2 = 1; geometryDefEdit.set_GridSize(0, 0); geometryDefEdit.HasM_2 = false; geometryDefEdit.HasZ_2 = false; //Assign the spatial reference that was passed in, possibly from //IGeodatabase.SpatialReference for the containing feature dataset. geometryDefEdit.SpatialReference_2 = sGEBRef; // Set standard field properties. fusrDefinedFieldEdit.Name_2 = "SHAPE"; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; fusrDefinedFieldEdit.GeometryDef_2 = geometryDef; fusrDefinedFieldEdit.IsNullable_2 = true; fusrDefinedFieldEdit.Required_2 = true; fieldsEdit.set_Field(9, fusrDefinedField); // Create a feature class description object to use for specifying the CLSID and EXTCLSID. IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass(); IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc; IFeatureClass fc = featureWorkspace.CreateFeatureClass( Properties.Resources.GeodatabaseUtilities_schema_FeatureClassName, // Feature Class Name fields, // Feature Class Fields (defined above) ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, // Shape Field Name "" // Keyword Configurations ); // return the feature class return fc; } else { // end gracefully, maybe prompt the user that the toolbar wasn't able to create a workspcae throw new Exception("Unable to open local geodatabase."); } } catch (System.Exception ex) { // an error occured log.Error(ex); // throw an exception throw new Exception("An unknown exception occured while attempting to create a local feature class."); } }
/* * A utility class to delete a File Geodatabase (FGDB). */ public static bool deleteFileGeodatabaseWorkspace(ref log4net.ILog log, string workspaceDirectory, string workspaceFolderName) { // attempt to delete the referenced File Geodatabase (FGDB) log.Debug("Attempting to delete the referenced File Geodatabase (FGDB)."); log.Debug("workspaceDirectory: " + workspaceDirectory); log.Debug("workspaceFolderName: " + workspaceFolderName); try { // verify the workspace does already exist log.Debug("Verifying if the File Geodatabase exists."); if (!System.IO.Directory.Exists(workspaceDirectory + "\\" + workspaceFolderName)) { // the File Geodatabase does not exist log.Warn("File Geodatabase does not exist. Unable to delete."); throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_deleteFileGeodatabaseWorkspace_notfound); } else { // File Geodatabase exists, create a new DirecotryInfo object to represent the <name>.gdb log.Debug("File Geodatabase exists, creating a new DirectoryInfo object to represent the .gdb."); System.IO.DirectoryInfo dinfo = new System.IO.DirectoryInfo(workspaceDirectory + "\\" + workspaceFolderName); // once again, verifying the folder itself exists log.Debug("Checking again to see if the folder itself exists."); if (dinfo.Exists) { // the File Geodatabase folder exists. Attempt to delete it. log.Debug("File Geodatabase folder exists, attempt to delete it."); dinfo.Delete(true); // return true log.Debug("Returning true/successful."); return true; } else { // the <name>.gdb folder does not exist, return false log.Debug("File Geodatabase folder does not exist, return false."); return false; } } } catch (System.Exception ex) { // an unknown error occured, log and throw log.Error(ex); throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_deleteFileGeodatabaseWorkspace_unknown); } }
protected void identifyPendingContexts(long delay,log4net.ILog log) { try { foreach (OrderContext cntx in _activeContextMap.Values) { if (cntx.isPending(delay)) { log.Info("identifyPendingContexts:pending:" + cntx.ToString()); } } } catch (Exception myE) { log.Error("identifyPendingContexts", myE); } }