Пример #1
0
        public static ExceptionData Handle(Exception e, Code? ec, string message, log4net.ILog log)
        {
            if ((log != null) && (log.IsWarnEnabled))
            {
                // If the client code has mapped the exception to a code and a message, it means some handling is in place. Use that info.
                if (ec != null)
                    log.Warn(String.Format("Code={0}; Message={1}", ec, message));
                else
                    log.Warn(e);    // if not, just log the full exception stack
            }

            return new ExceptionData(e, message ?? e.Message, ec ?? MapExceptionToExceptionCode(e));
        }
        /*
         * A utility class to create a File Geodatabase Workspace
         */
        public static IWorkspace createFileGeodatabaseWorkspace(ref log4net.ILog log, string workspaceDirectory, string workspaceFolderName)
        {
            log.Debug("Starting the process to create a new local File Geodatabase workspace.");

            // Instantiate a file geodatabase workspace factory and create a new file geodatabase.
            // The Create method returns a workspace name object.
            log.Debug("Initializing a new workspace factory to establish the FGB.");
            IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
            IWorkspaceName workspaceName = null;

            // verify the workspace does not already exist
            log.Debug("Determining if the workspace apready exists or not.");
            if (System.IO.Directory.Exists(workspaceDirectory + "\\" + workspaceFolderName))
            {
                // file geodatabase workspace already exist, throw warning
                log.Warn("File Geodatabase workspace already exists.");
                throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_createFileGeodatabaseWorkspace_exists);
            }
            else
            {
                // workspace doens't exist, good
                log.Debug("File Geodatabase does not exist.");

                // verify the directory exists
                log.Debug("Checking to see if the workspace directory exists or not (parent of the FGD).");
                if (!System.IO.Directory.Exists(workspaceDirectory))
                {
                    // workspace directory doens't exist, create the directory
                    log.Debug("Workspace folder/parent doesn't exist, creating the directory.");
                    System.IO.Directory.CreateDirectory(workspaceDirectory);
                }

                // create the workspace
                log.Debug("Creating the File Geodatabase workspace.");
                workspaceName = workspaceFactory.Create(workspaceDirectory, workspaceFolderName, null, 0);

                // Cast the workspace name object to the IName interface and open the workspace.
                log.Debug("Retreiving the workspace name.");
                IName name = (IName)workspaceName;

                // return the workspace
                log.Debug("Opening the workspace and returning it to the requestor.");
                return (IWorkspace)name.Open();
            }
        }
Пример #3
0
 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()));
     }
 }
Пример #4
0
        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);
            }
        }
Пример #5
0
        // BEGIN EXTRA METHODS (C:/dev/OpenADK-java/adk-generator/datadef/core/sif20/SIF_Request.txt.cs)
        /// <summary>
        /// Parses the list of SIF_Version elements and returns an array of SIFVersions
        /// </summary>
        /// <param name="failureLog">The log to write failures to, if any of the SIFVersions fail
        /// to be parsed.</param>
        /// <returns><An array of SIFVersion elements. This will never be null/returns>
        internal SifVersion[] parseRequestVersions( log4net.ILog failureLog )
        {
            if( failureLog == null ){
            failureLog = Adk.Log;
            }
            System.Collections.Generic.List<SifVersion> versionList = new System.Collections.Generic.List<SifVersion>();
               	foreach( SifElement element in GetChildList( InfraDTD.SIF_REQUEST_SIF_VERSION ) ){
            SIF_Version candidate = (SIF_Version)element;
            SifVersion version = null;
            try {
                // Check for "1.*" and "2.*"
                String ver = candidate.Value;
                if( ver != null ){
                    if( ver.IndexOf( ".*" ) > 0 ){
                        version = SifVersion.GetLatest( int.Parse( ver.Substring( 0, 1 ) ) );
                    } else {
                        version = SifVersion.Parse( ver );
                    }
                }
            } catch( ArgumentException exc ){
                failureLog.Warn( String.Format( "Unable to parse '{0}' from SIF_Request/SIF_Version as SIFVersion.", candidate.Value), exc  );
            }
            catch( FormatException exc )
            {
                failureLog.Warn( String.Format( "Unable to parse '{0}' from SIF_Request/SIF_Version as SIFVersion.", candidate.Value ), exc );
            }
            if( version != null && !versionList.Contains( version ) ){
                versionList.Add( version );
            }
            }

            return versionList.ToArray();
        }
        /*
         * 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);
            }
        }
        /*
         * 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);
            }
        }