示例#1
0
 /// <summary>
 /// logging the error
 /// </summary>
 /// <param name="messageData"></param>
 public void Error(MessageData messageData)
 {
     logger.Error(messageBuilder.BuildMessage(messageData));
 }
示例#2
0
 /// <summary>
 /// logging the debugging info
 /// </summary>
 /// <param name="messageData"></param>
 public void Debug(MessageData messageData)
 {
     logger.Debug(messageBuilder.BuildMessage(messageData));
 }
示例#3
0
 /// <summary>
 /// logging the fatal error
 /// </summary>
 /// <param name="messageData"></param>
 public void Fatal(MessageData messageData)
 {
     logger.Fatal(messageBuilder.BuildMessage(messageData));
 }
示例#4
0
 /// <summary>
 /// logging the warning
 /// </summary>
 /// <param name="messageData"></param>
 public void Warn(MessageData messageData)
 {
     logger.Warn(messageBuilder.BuildMessage(messageData));
 }
示例#5
0
 /// <summary>
 /// logging the information
 /// </summary>
 /// <param name="messageData"></param>
 public void Info(MessageData messageData)
 {
     logger.Info(messageBuilder.BuildMessage(messageData));
 }
        /// <summary>
        /// executing transaction
        /// </summary>
        /// <param name="cbm"></param>
        /// <param name="vo"></param>
        /// <returns></returns>
        internal static ValueObject Invoke(CbmController cbm, ValueObject vo, UserData userData, TransactionContextFactory trxFactory, string connectionString)
        {
            if (cbm == null)
            {
                MessageData messageData = new MessageData("ffce00001", Properties.Resources.ffce00001, System.Reflection.MethodBase.GetCurrentMethod().Name);
                logger.Error(messageData, new NullReferenceException());
                throw new SystemException(messageData, new NullReferenceException());
            }

            if (trxFactory == null)
            {
                //please write code here
                defaultTrxFactory.GetTransactionContext(userData);
                trxFactory = defaultTrxFactory;
            }


            IDbTransaction dbTransaction = null;
            IDbConnection  connection    = null;
            //Get TransactionContext
            TransactionContext trxContext = trxFactory.GetTransactionContext(userData);

            try
            {
                connection = new NpgsqlConnection(connectionString);

                trxContext.DbConnection = connection;
                trxContext.DbConnection.Open();

                dbTransaction = trxContext.DbConnection.BeginTransaction();

                //Get DB Processing Time
                CbmController GetDBProcessingTimeCbm = trxFactory.GetDBProcessingTimeCbm();

                TimeVo time = (TimeVo)GetDBProcessingTimeCbm.Execute(trxContext, vo);

                trxContext.ProcessingDBDateTime = time.CurrentDateTime;

                //Start transaction
                ValueObject returnedVo = cbm.Execute(trxContext, vo);



                //commit
                dbTransaction.Commit();

                return(returnedVo);
            }
            catch (ApplicationException appEx)
            {
                //rollback
                if (dbTransaction != null)
                {
                    dbTransaction.Rollback();
                }

                MessageData messageData = new MessageData("ffce00003", Properties.Resources.ffce00003, appEx.Message);
                logger.Error(messageData, appEx);
                throw appEx;
            }
            catch (SystemException sysEx)
            {
                //rollback
                if (dbTransaction != null)
                {
                    dbTransaction.Rollback();
                }

                MessageData messageData = new MessageData("ffce00003", Properties.Resources.ffce00003, sysEx.Message);
                logger.Error(messageData, sysEx);

                throw sysEx;
            }
            catch (Exception Ex)
            {
                //rollback
                if (dbTransaction != null)
                {
                    dbTransaction.Rollback();
                }

                MessageData messageData = new MessageData("ffce00003", Properties.Resources.ffce00003, Ex.Message);
                logger.Error(messageData, Ex);

                throw new SystemException(messageData);
            }
            finally
            {
                try
                {
                    if (connection != null)
                    {
                        connection.Close();
                    }
                }
                catch (Exception ex)
                {
                    //need to be implemented
                    MessageData messageData = new MessageData("ffce00003", Properties.Resources.ffce00003, ex.Message);
                    logger.Error(messageData, ex);

                    throw new SystemException(messageData);
                }
            }
        }
        private void ShowMessage(MessageData messageData)
        {
            InitializationErrorMessageForm messageForm = new InitializationErrorMessageForm(messageData);

            messageForm.ShowDialog();
        }
 /// <summary>
 /// shows confirmation error  with Yes/No/Cancel
 /// </summary>
 /// <param name="messagedata"></param>
 /// <param name="title"></param>
 /// <returns></returns>
 public DialogResult ConfirmationYesNoCancel(MessageData messagedata, string title)
 {
     return(ShowMessage(MessageForm.MessageTypeEnum.ConfirmationYesNoCancel, messagedata, title));
 }
        /// <summary>
        /// need to execute from Synchronized method
        /// </summary>
        /// <param name="keyName"></param>
        /// <returns></returns>
        private string GetValueImple(string keyName)
        {
            if (configValueMap.ContainsKey(keyName))
            {
                return((string)configValueMap[keyName]);
            }

            Configuration config = null;

            try
            {
                Assembly ass = Assembly.GetEntryAssembly();
                if (ass != null)
                {
                    config = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);
                }
                else
                {
                    config             = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
                    SECTION_GROUP_NAME = "applicationSettings";
                }
            }
            catch (ConfigurationErrorsException Ex)
            {
                //implement system exception
                MessageData messageData = new MessageData("ffce00003", Properties.Resources.ffce00003, Ex.Message);
                logger.Error(messageData, Ex);

                throw new SystemException(messageData);
            }

            if (!config.HasFile)
            {
                //implement system exception
                MessageData messageData = new MessageData("ffce00004", Properties.Resources.ffce00004);
                logger.Error(messageData);

                throw new SystemException(messageData);
            }

            ConfigurationSectionGroup sectionGroup = config.SectionGroups[SECTION_GROUP_NAME];

            if (sectionGroup == null)
            {
                //implement system exception
                MessageData messageData = new MessageData("ffce00005", Properties.Resources.ffce00005);
                logger.Error(messageData);

                throw new SystemException(messageData);
            }

            string value = null;

            foreach (ConfigurationSection configurationSection in sectionGroup.Sections)
            {
                ClientSettingsSection section = null;
                try
                {
                    section = (ClientSettingsSection)ConfigurationManager
                              .GetSection(configurationSection.SectionInformation.SectionName);
                }
                catch (ConfigurationErrorsException ex)
                {
                    //implement system exception
                    MessageData messageData = new MessageData("ffce00006", Properties.Resources.ffce00006, ex.Message);
                    logger.Error(messageData, ex);

                    throw new SystemException(messageData);
                }

                SettingElement element = section.Settings.Get(keyName);
                if (element == null)
                {
                    //implement system exception
                    MessageData messageData = new MessageData("ffce00007", Properties.Resources.ffce00007, keyName);
                    logger.Error(messageData);

                    throw new SystemException(messageData);
                }

                value = element.Value.ValueXml.InnerText;
                break;
            }

            //set to cache
            configValueMap.Add(keyName, value);

            return(value);
        }
 /// <summary>
 /// shows system  error
 /// </summary>
 /// <param name="messagedata"></param>
 /// <param name="title"></param>
 /// <returns></returns>
 public DialogResult SystemError(MessageData messagedata, string title)
 {
     return(ShowMessage(MessageForm.MessageTypeEnum.SystemError, messagedata, title));
 }
 /// <summary>
 /// shows warning  error
 /// </summary>
 /// <param name="messagedata"></param>
 /// <param name="title"></param>
 /// <returns></returns>
 public DialogResult Warning(MessageData messagedata, string title)
 {
     return(ShowMessage(MessageForm.MessageTypeEnum.Warning, messagedata, title));
 }
 /// <summary>
 /// shows information error
 /// </summary>
 /// <param name="messagedata"></param>
 /// <param name="title"></param>
 /// <returns></returns>
 public DialogResult Information(MessageData messagedata, string title)
 {
     return(ShowMessage(MessageForm.MessageTypeEnum.Information, messagedata, title));
 }
 /// <summary>
 /// shows application  error
 /// </summary>
 /// <param name="messagedata"></param>
 /// <param name="title"></param>
 /// <returns></returns>
 public DialogResult ApplicationError(MessageData messagedata, string title, Size pgSize = new Size())
 {
     return(ShowMessage(MessageForm.MessageTypeEnum.ApplicationError, messagedata, title, pgSize));
 }
        /// <summary>
        /// ldap authentication
        /// </summary>
        /// <param name="user"></param>
        /// <param name="pass"></param>
        /// <returns></returns>
        public Boolean Authentificate(string user, string pass)
        {
            if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pass))
            {
                return(false);
            }

            string ldapConnectionHost = ConfigurationDataTypeEnum.LDAP_CONNECTION_HOST.GetValue(); //Properties.Settings.Default.LdapConnectionHost;
            string searchDN           = "dc=nidec,dc=com";
            string searchFilterFormat = "(&(exgEnabledFlag=enabled)(uid={0}))";
            string distinguishedName  = string.Empty;

            // search DistinguishedName
            LdapConnection ldapconnection = new LdapConnection(ldapConnectionHost);

            ldapconnection.AuthType = AuthType.Anonymous;
            ldapconnection.SessionOptions.ProtocolVersion = 3;
            ldapconnection.Bind();

            SearchRequest searchRequest = new SearchRequest(
                searchDN,
                string.Format(searchFilterFormat, user),
                SearchScope.Subtree
                );
            SearchResponse response = null;

            try
            {
                response = (SearchResponse)ldapconnection.SendRequest(searchRequest);
            }
            catch (ObjectDisposedException ex)
            {
                MessageData messageData = new MessageData("llce00007", Properties.Resources.llce00001, ex.Message);
                logger.Info(messageData, ex);
                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (ArgumentNullException ex)
            {
                MessageData messageData = new MessageData("llce00007", Properties.Resources.llce00001, ex.Message);
                logger.Info(messageData, ex);
                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (NotSupportedException ex)
            {
                MessageData messageData = new MessageData("llce00007", Properties.Resources.llce00001, ex.Message);
                logger.Info(messageData, ex);
                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (LdapException ex)
            {
                MessageData messageData = new MessageData("llce00007", Properties.Resources.llce00001, ex.Message);
                logger.Info(messageData, ex);
                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (DirectoryOperationException ex)
            {
                MessageData messageData = new MessageData("llce00007", Properties.Resources.llce00001, ex.Message);
                logger.Info(messageData, ex);
                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }


            if (response != null)
            {
                SearchResultEntryCollection collection = response.Entries;

                foreach (SearchResultEntry searchResultEntry in collection)
                {
                    distinguishedName = searchResultEntry.DistinguishedName;
                    break;
                }
            }

            // authenticate
            if (string.IsNullOrEmpty(distinguishedName))
            {
                return(false);// user does not exist.
            }

            ldapconnection.AuthType = AuthType.Basic;
            ldapconnection.SessionOptions.ProtocolVersion = 3;
            try
            {
                ldapconnection.Bind(new NetworkCredential(distinguishedName, pass));
            }
            catch (ObjectDisposedException ex)
            {
                MessageData messageData = new MessageData("llce00007", Properties.Resources.llce00001, ex.Message);
                logger.Info(messageData, ex);
                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (LdapException ex)
            {
                MessageData messageData = new MessageData("llce00007", Properties.Resources.llce00001, ex.Message);
                logger.Info(messageData, ex);
                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (InvalidOperationException ex)
            {
                MessageData messageData = new MessageData("llce00007", Properties.Resources.llce00001, ex.Message);
                logger.Info(messageData, ex);
                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            return(true);
        }
示例#15
0
        /// <summary>
        /// executing transaction
        /// </summary>
        /// <param name="cbm">cbm  to be executed</param>
        /// <param name="vo">input vo for the cbm</param>
        /// <param name="userData">userdata</param>
        /// <param name="trxFactory">TransactionContextFactory to get transactioncontext using userdata</param>
        /// <param name="connectionString">connectionString for connecting with another database</param>
        /// <exception cref="Com.Nidec.Mes.Framework.ApplicationException">application exception handled in cbm access and cbm invoke</exception>
        /// <exception cref="Com.Nidec.Mes.Framework.SystemException">system exception handled in cbm access and cbm invoke</exception>
        /// <exception cref="System.Exception">Unhandled exception occured has been thrown as system exception in cbm access and cbm invoke</exception>
        /// <returns>output vo will be returned / exception will be thrown for error cases</returns>
        internal static ValueObject Invoke(CbmController cbm, ValueObject vo, UserData userData, TransactionContextFactory trxFactory, string connectionString)
        {
            if (cbm == null)
            {
                MessageData messageData = new MessageData("ffce00041", Properties.Resources.ffce00041, System.Reflection.MethodBase.GetCurrentMethod().Name);
                logger.Error(messageData, new NullReferenceException());
                throw new SystemException(messageData, new NullReferenceException());
            }

            if (trxFactory == null)
            {
                //please write code here
                defaultTrxFactory.GetTransactionContext(userData);
                trxFactory = defaultTrxFactory;
            }


            IDbTransaction dbTransaction = null;
            IDbConnection  connection    = null;
            //Get TransactionContext
            TransactionContext trxContext = trxFactory.GetTransactionContext(userData);

            try
            {
                connection = new MySqlConnection(connectionString);

                trxContext.DbConnection = connection;
                trxContext.DbConnection.Open();

                dbTransaction = trxContext.DbConnection.BeginTransaction();

                //Start transaction
                ValueObject returnedVo = cbm.Execute(trxContext, vo);

                //commit
                dbTransaction.Commit();

                return(returnedVo);
            }
            catch (ApplicationException appEx)
            {
                //rollback
                DbTransactionRollback(dbTransaction);

                MessageData messageData = new MessageData("ffce00042", Properties.Resources.ffce00042, appEx.Message);
                logger.Error(messageData, appEx);

                throw appEx; //throw original app exception
            }
            catch (SystemException sysEx)
            {
                //rollback
                DbTransactionRollback(dbTransaction);

                MessageData messageData = new MessageData("ffce00043", Properties.Resources.ffce00043, sysEx.Message);
                logger.Error(messageData, sysEx);

                throw sysEx; //throw original sys exception
            }
            catch (Exception Ex)
            {
                //rollback
                DbTransactionRollback(dbTransaction);

                MessageData messageData = new MessageData("ffce00044", Properties.Resources.ffce00044, Ex.Message);
                logger.Error(messageData, Ex);

                throw new SystemException(messageData, Ex); //throw original exception as sys exception
            }
            finally
            {
                try
                {
                    if (connection != null)
                    {
                        connection.Close();
                    }
                }
                catch (Exception ex)
                {
                    //need to be implemented
                    MessageData messageData = new MessageData("ffce00045", Properties.Resources.ffce00045, ex.Message);
                    logger.Error(messageData, ex);

                    throw new SystemException(messageData, ex); //throw original exception as sys exception
                }
            }
        }
        /// <summary>
        /// get and return the value of the configuration settings for keyname
        /// </summary>
        /// <param name="config">Configuration of the assembly</param>
        /// <param name="keyName">keyName to be found from the settings file</param>
        /// <exception cref="System.NullReferenceException">if keyname not found in the configuration file</exception>
        /// <exception cref="System.NullReferenceException">if DEFAULT_APPLICATION_ENVIRONMENT_SETTINGS not found in the configuration file</exception>
        /// <exception cref="System.NullReferenceException">if element is not found </exception>
        /// <exception cref="System.NullReferenceException">if value is not found </exception>
        /// <returns>return the value in the configuration for the keyname</returns>
        private string GetConfigurationValue(Configuration config, string keyName)
        {
            //userSettings for windows application settings/applicationSettings for webservices
            ConfigurationSectionGroup sectionGroup = config.SectionGroups[SECTION_GROUP_NAME];

            if (sectionGroup == null) // failed to get sectiongroup
            {
                //implement system exception
                MessageData messageData = new MessageData("ffce00005", Properties.Resources.ffce00005);
                logger.Error(messageData, new NullReferenceException());

                throw new SystemException(messageData, new NullReferenceException());
            }

            //read default settings file first
            SettingElement element = GetConfigurationElement(sectionGroup, DEFAULT_SETTINGS_NAME, keyName);

            if (element == null)  // if element not found in default settings file then get from applicatoin setting file
            {
                string applicationSettingsFileName = configValueMap.ContainsKey(APPLICATION_ENVIRONMENT_SETTINGS) ? (string)configValueMap[APPLICATION_ENVIRONMENT_SETTINGS] : null;

                if (applicationSettingsFileName == null) //if APPLICATION_ENVIRONMENT_SETTINGS not found in cache memory throw exception
                {
                    //temporary solution to get APPLICATION_ENVIRONMENT_SETTINGS
                    applicationSettingsFileName = GetConfigurationValue(config, APPLICATION_ENVIRONMENT_SETTINGS);

                    if (applicationSettingsFileName == null)
                    {
                        //implement system exception
                        MessageData messageData = new MessageData("ffce00030", Properties.Resources.ffce00030, keyName);
                        logger.Error(messageData, new NullReferenceException());

                        throw new SystemException(messageData, new NullReferenceException());
                    }
                }

                element = GetConfigurationElement(sectionGroup, applicationSettingsFileName, keyName);
            }

            if (element == null) // failed to get element
            {
                //implement system exception
                MessageData messageData = new MessageData("ffce00036", Properties.Resources.ffce00036, keyName);
                logger.Error(messageData, new NullReferenceException());

                throw new SystemException(messageData, new NullReferenceException());
            }

            //get the exact value from innertext of the element
            string value = element.Value.ValueXml.InnerText;

            if (value == null) //value is not available for the keyname
            {
                //implement system exception
                MessageData messageData = new MessageData("ffce00034", Properties.Resources.ffce00034, keyName);
                logger.Error(messageData, new NullReferenceException());

                throw new SystemException(messageData, new NullReferenceException());
            }

            return(value);
        }