public List <COUNModel> GetOPICSCountryByLabel(string label) { List <COUNModel> countries = null; try { using (IDbConnection connection = Oracle.CreateOpenConnection()) { using (IDbCommand command = connection.CreateCommand()) { command.CommandText = "SELECT TRIM(CCODE) AS CCODE , TRIM(COUN) AS COUN FROM OPICS.COUN WHERE CCODE LIKE '" + label + "%' "; command.CommandType = CommandType.Text; LoggingHelper.Debug("====" + command.CommandText + "======"); using (IDataReader reader = command.ExecuteReader()) { countries = this.MapDataReaderToList <COUNModel>(reader); } } } } catch (Exception ex) { LoggingHelper.Debug("Error: " + ex.Message); } return(countries); }
public List <CASHFLOWModel> GetOPICSCashflow(DateTime processdate) { List <CASHFLOWModel> cashflows = null; try { using (IDbConnection connection = Oracle.CreateOpenConnection()) { using (IDbCommand command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM OPICS.V_DMK_CASHFLOW WHERE MATDATE > TO_DATE('" + processdate.ToString("yyyyMMdd") + "', 'YYYYMMDD')"; command.CommandType = CommandType.Text; LoggingHelper.Debug("====" + command.CommandText + "======"); using (IDataReader reader = command.ExecuteReader()) { cashflows = this.MapDataReaderToList <CASHFLOWModel>(reader); } } } } catch (Exception ex) { LoggingHelper.Debug("Error: " + ex.Message); } return(cashflows); }
public static Database CreateDatabase() { LoggingHelper.Debug("===CresteDatabase==="); // Verify a DatabaseFactoryConfiguration line exists in the web.config. if (sectionHandler.Name.Length == 0) { LoggingHelper.Debug("Database name not defined in DatabaseFactoryConfiguration section of web.config."); throw new Exception("Database name not defined in DatabaseFactoryConfiguration section of web.config."); } try { // Find the class Type database = Type.GetType(sectionHandler.Name); // Get it's constructor ConstructorInfo constructor = database.GetConstructor(new Type[] { }); // Invoke it's constructor, which returns an instance. Database createdObject = (Database)constructor.Invoke(null); // Initialize the connection string property for the database. createdObject.connectionString = sectionHandler.ConnectionString; // Pass back the instance as a Database return(createdObject); } catch (Exception excep) { LoggingHelper.Debug("Error instantiating database " + sectionHandler.Name + ". " + excep.Message); throw new Exception("Error instantiating database " + sectionHandler.Name + ". " + excep.Message); } }
public List <SECMModel> GetOPICSInstrumentByLabel(string label) { List <SECMModel> secm = null; try { using (IDbConnection connection = Oracle.CreateOpenConnection()) { using (IDbCommand command = connection.CreateCommand()) { command.CommandText = "SELECT trim(SECID) SECID, trim(ISSUER) ISSUER, DENOM, COUPRATE_8, TO_CHAR(MDATE , 'mm/dd/yyyy') MDATE, INTCALCRULE, PMTFREQ, CCY FROM OPICS.SECM WHERE SECID LIKE '" + label + "%' "; command.CommandType = CommandType.Text; LoggingHelper.Debug("====" + command.CommandText + "======"); using (IDataReader reader = command.ExecuteReader()) { secm = this.MapDataReaderToList <SECMModel>(reader); } } } } catch (Exception ex) { LoggingHelper.Debug("Error: " + ex.Message); } return(secm); }
public static object GetConfigByFilter(SessionInfo sessioninfo, string name, int jtStartIndex, int jtPageSize, string jtSorting) { try { LoggingHelper.Debug("Begin Get config by " + name); //Return result to jTable PCCFConfigBusiness _factorBusiness = new PCCFConfigBusiness(); //Get data from database List <MA_PCCF_CONFIG> factors = _factorBusiness.GetConfigByFilter(sessioninfo, name, jtSorting); LoggingHelper.Debug("End Get config"); //Return result to jTable return(new { Result = "OK" , Records = jtPageSize > 0 ? factors.Skip(jtStartIndex).Take(jtPageSize).ToList() : factors , TotalRecordCount = factors.Count }); } catch (BusinessWorkflowsException bex) { return(new { Result = "ERROR", Message = bex.Message }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public List <CUSTModel> GetOPICSCustomerByName(string name) { List <CUSTModel> custs = null; try { using (IDbConnection connection = Oracle.CreateOpenConnection()) { using (IDbCommand command = connection.CreateCommand()) { command.CommandText = "SELECT trim(CNO) CNO, trim(CMNE) CMNE, trim(SN) SN, trim(CTYPE) CTYPE, trim(CCODE) CCODE FROM OPICS.CUST WHERE CMNE LIKE '" + name + "%' "; command.CommandType = CommandType.Text; LoggingHelper.Debug("====" + command.CommandText + "======"); using (IDataReader reader = command.ExecuteReader()) { custs = this.MapDataReaderToList <CUSTModel>(reader); } } } } catch (Exception ex) { LoggingHelper.Debug("Error: " + ex.Message); } return(custs); }
public void UpdateDealReconcile(SessionInfo sessioninfo, List <DealTranModel> trns) { DealBusiness _dealBusiness = new DealBusiness(); LoggingHelper.Debug("Begin UpdateDealReconcile...."); using (EFUnitOfWork unitOfWork = new EFUnitOfWork()) { foreach (DealTranModel tran in trns) { switch (tran.UpdateStates) { case UpdateStates.Adding: unitOfWork.DA_TRNRepository.Add(tran.Transaction); LoggingHelper.Debug(String.Format("Insert DA_TRN {0} [{1}] is completed", tran.Transaction.INT_DEAL_NO, tran.Transaction.ID.ToString())); break; case UpdateStates.Editing: var update = unitOfWork.DA_TRNRepository.All().FirstOrDefault(p => p.ID == tran.Transaction.ID); if (update == null) { throw this.CreateException(new Exception(), "Data not found!"); } else { update.EXT_DEAL_NO = tran.Transaction.EXT_DEAL_NO; update.EXT_PORTFOLIO = tran.Transaction.EXT_PORTFOLIO; update.MATURITY_DATE = tran.Transaction.MATURITY_DATE; update.STATUS_ID = tran.Transaction.STATUS_ID; update.LOG.MODIFYBYUSERID = tran.Transaction.LOG.MODIFYBYUSERID; update.LOG.MODIFYDATE = tran.Transaction.LOG.MODIFYDATE; update.INSERT_BY_EXT = tran.Transaction.INSERT_BY_EXT; } LoggingHelper.Debug(String.Format("Update DA_TRN {0} [{1}] is completed", update.INT_DEAL_NO, update.ID.ToString())); break; case UpdateStates.Deleting: var delete = unitOfWork.DA_TRNRepository.All().FirstOrDefault(p => p.ID == tran.Transaction.ID); if (delete == null) { throw this.CreateException(new Exception(), "Data not found!"); } else { unitOfWork.DA_TRNRepository.Delete(delete); } LoggingHelper.Debug(String.Format("Delete DA_TRN {0} [{1}] is completed", delete.INT_DEAL_NO, delete.ID.ToString())); break; } } unitOfWork.Commit(); LoggingHelper.Debug("Commit UpdateDealReconcile...."); } }
public SessionInfo LogOn(string username, string userIP) { MA_USER user; SessionInfo sessioninfo = new SessionInfo(); AuditBusiness _auditBusiness = new AuditBusiness(); LoggingHelper.Debug("Begin Logon by " + username); using (EFUnitOfWork unitOfWork = new EFUnitOfWork()) { sessioninfo.ConnectionString = (string)ConfigurationManager.AppSettings[AppSettingName.CONNECTION_STRING]; sessioninfo.Local = "Localhost"; sessioninfo.StartSession = DateTime.Now; LoggingHelper.Debug("Begin get user data"); user = unitOfWork.MA_USERRepository.GetByUserCode(username); if (user == null) { LoggingHelper.Debug(username + " error: " + Messages.USER_NOT_UNAVAILABLE); throw this.CreateException(new Exception(), Messages.USER_NOT_UNAVAILABLE); } sessioninfo.ID = Guid.NewGuid(); sessioninfo.CurrentUserId = user.ID; sessioninfo.UserFullName = user.NAME; sessioninfo.UserLogon = username; sessioninfo.IsActive = user.ISACTIVE.Value; sessioninfo.IsLocked = user.ISLOCKED.Value; sessioninfo.ProfileId = user.USER_PROFILE_ID; sessioninfo.ProfileName = user.MA_USER_PROFILE.LABEL; sessioninfo.IPAddress = userIP; LoggingHelper.Debug("End get user data"); //Get from MA_PROCESS_DATE //LoggingHelper.Debug("Begin get processing date from OPICS"); //OpicsBusiness _opicsBusiness = new OpicsBusiness(); //PROCDateModel prcDate = _opicsBusiness.GetDateProcessing(DateTime.Today); //sessioninfo.Process.CurrentDate = prcDate.CURRDATE; //sessioninfo.Process.PreviousDate = prcDate.PREVDATE; //sessioninfo.Process.NextDate = prcDate.NEXTDATE; //LoggingHelper.Debug("End get processing date from OPICS"); LoggingHelper.Debug("Begin get processing date from MA_PROCESS_DATE"); MA_PROCESS_DATE PROC = unitOfWork.MA_PROCESS_DATERepository.All().FirstOrDefault(); sessioninfo.Process.CurrentDate = PROC != null ? PROC.PROC_DATE : DateTime.Today; sessioninfo.Process.PreviousDate = PROC != null ? PROC.PREV_PROC_DATE : DateTime.Today.AddDays(-1); sessioninfo.Process.NextDate = PROC != null ? PROC.NEXT_PROC_DATE : DateTime.Today.AddDays(1); LoggingHelper.Debug("End get processing date from MA_PROCESS_DATE"); //AUDIT USER TRANSACTION LoggingHelper.Debug("Begin Trace Audit User " + user.NAME); _auditBusiness.TraceAuditLoginUser(sessioninfo); LoggingHelper.Debug("End Trace Audit User " + user.NAME); } return(sessioninfo); }
public string LogOn(string username, string password) { ResultData rs = null; bool passLogon = true; try { LoggingHelper.Debug("Start Logon"); //Put verify code for USER SessionInfo sessioninfo = null; sessioninfo = UserUIP.LogOn(username, password); if (sessioninfo == null) { LoggingHelper.Debug(username + " unsuccessfully logged in."); Tracing.WriteLine(Tracing.Category.Trace, username + " unsuccessfully logged in.", TraceLevel.Info, Guid.Empty, Guid.Empty); rs = new ResultData(new Exception(username + " unsuccessfully logged in."), username + " unsuccessfully logged in."); passLogon = false; } else { // We need to keep token here. FormsAuthentication.SetAuthCookie(username, false); // Add a cookie here so we can retrieve later. HttpCookie cookie = new HttpCookie(AppSettingName.TOKEN); cookie.Value = SessionInfoSerializer.SessionInfoToString(sessioninfo); Context.Response.Cookies.Add(cookie); AddUsernameToCookie(sessioninfo); // Check User Active if (!sessioninfo.IsActive) { LoggingHelper.Debug(username + " has been inactive"); Tracing.WriteLine(Tracing.Category.Trace, username + " has been inactive", TraceLevel.Info, Guid.Empty, sessioninfo.CurrentUserId); //rs = new ResultData(new Exception(username + " has been inactive"), username + " has been inactive"); //passLogon = false; } } if (passLogon) { LoggingHelper.Debug(username + " successfully logged in."); Tracing.WriteLine(Tracing.Category.Trace, username + " successfully logged in.", TraceLevel.Info, Guid.Empty, sessioninfo.CurrentUserId); rs = new ResultData("Success"); } return(rs.ToString()); } catch (Exception ex) { rs = new ResultData(ex); return(rs.ToString()); } }
public OpicsBusiness() { try { if (_oracle == null) { _oracle = OracleHelper.GetOracleInstance(OracleConnectionString); } } catch (Exception excep) { LoggingHelper.Debug("Error BaseBusiness: " + excep.Message); } }
public List <DEALModel> GetOPICSDealExternal(DateTime processdate) { List <DEALModel> deals = null; try { Oracle.OpenConnection(); Oracle.CreateCommand(string.Format("{0}.{1}", Owner, ProcedureName.SP_KKB_TRO_DMK_OS), CommandType.StoredProcedure); Oracle.SetInputParameter("p_date", processdate.ToString(FormatTemplate.DATETIME_LABEL)); DataSet result = Oracle.ExecuteReader("ref_rpt_cur", "DataSet"); deals = CollectionHelper.ConvertTo <DEALModel>(result.Tables[0]).ToList(); } catch (Exception ex) { LoggingHelper.Debug("Error: " + ex.Message); } return(deals); }
public static object UpdateFactor(SessionInfo sessioninfo, MA_CONFIG_ATTRIBUTE record) { try { LoggingHelper.Debug("Update Factor by " + record.ATTRIBUTE); PCCFConfigBusiness _factorBusiness = new PCCFConfigBusiness(); record.ISACTIVE = record.ISACTIVE == null || !record.ISACTIVE ? false : true; record.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId; record.LOG.MODIFYDATE = DateTime.Now; var updated = _factorBusiness.UpdateFactor(sessioninfo, record); LoggingHelper.Debug("End Update"); return(new { Result = "OK" }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public static object UpdateConfig(SessionInfo sessioninfo, MA_PCCF_CONFIG record) { try { LoggingHelper.Debug("Update Config by " + record.LABEL); PCCFConfigBusiness _factorBusiness = new PCCFConfigBusiness(); record.ISACTIVE = record.ISACTIVE == null || !record.ISACTIVE.Value ? false : true; record.LABEL = record.LABEL.ToUpper(); record.DESCRIPTION = record.DESCRIPTION.ToUpper(); record.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId; record.LOG.MODIFYDATE = DateTime.Now; var updated = _factorBusiness.UpdateConfig(sessioninfo, record); LoggingHelper.Debug("End Update"); return(new { Result = "OK" }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public static object CreateFactor(SessionInfo sessioninfo, MA_CONFIG_ATTRIBUTE record) { try { LoggingHelper.Debug("Create Factor by " + record.ATTRIBUTE); PCCFConfigBusiness _factorBusiness = new PCCFConfigBusiness(); record.ID = Guid.NewGuid(); record.ISACTIVE = record.ISACTIVE == null || !record.ISACTIVE ? false : true; record.LOG.INSERTBYUSERID = sessioninfo.CurrentUserId; record.LOG.INSERTDATE = DateTime.Now; LoggingHelper.Debug("End Create"); var added = _factorBusiness.CreateFactor(sessioninfo, record); return(new { Result = "OK", Record = added }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public static object GetFactorByFilter(SessionInfo sessioninfo, Guid ID) { try { LoggingHelper.Debug("Begin Get Factor by " + ID); //Return result to jTable PCCFConfigBusiness _factorBusiness = new PCCFConfigBusiness(); //Get data from database List <MA_CONFIG_ATTRIBUTE> factors = _factorBusiness.GetFactorByFilter(sessioninfo, ID); LoggingHelper.Debug("End Get Factor"); //Return result to jTable return(new { Result = "OK", Records = factors, TotalRecordCount = factors.Count }); } catch (BusinessWorkflowsException bex) { return(new { Result = "ERROR", Message = bex.Message }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public string LogOn(string username, string password) { ResultData rs = null; bool passLogon = true; try { LoggingHelper.Debug("Start Logon"); //Put verify code for USER SessionInfo sessioninfo = null; sessioninfo = UserUIP.LogOn(username, password , Context.Request.UserHostAddress , Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings[AppSettingName.AD_LOGIN])); if (sessioninfo == null) { LoggingHelper.Debug(username + " unsuccessfully logged in."); Tracing.WriteLine(Tracing.Category.Trace, username + " unsuccessfully logged in.", TraceLevel.Info, Guid.Empty, Guid.Empty); rs = new ResultData(new Exception(username + " unsuccessfully logged in."), username + " unsuccessfully logged in."); passLogon = false; ShowErrorMessage(username + " unsuccessfully logged in."); } else { //Additional information for overwrite limit sessioninfo.PCEOverwrite = ConfigurationManager.AppSettings[AppSettingName.PCE_OVERWRITE].ToString() == "1" ? true : false; sessioninfo.SETOverwrite = ConfigurationManager.AppSettings[AppSettingName.SET_OVERWRITE].ToString() == "1" ? true : false; sessioninfo.CountryOverwrite = ConfigurationManager.AppSettings[AppSettingName.COUNTRY_OVERWRITE].ToString() == "1" ? true : false; // We need to keep token here. FormsAuthentication.SetAuthCookie(username, false); // Add a cookie here so we can retrieve later. HttpCookie cookie = new HttpCookie(AppSettingName.TOKEN); cookie.Value = SessionInfoSerializer.SessionInfoToString(sessioninfo); Context.Response.Cookies.Add(cookie); AddUsernameToCookie(sessioninfo); // Check User Active if (!sessioninfo.IsActive) { LoggingHelper.Debug(username + " has been inactive"); Tracing.WriteLine(Tracing.Category.Trace, username + " has been inactive", TraceLevel.Info, Guid.Empty, sessioninfo.CurrentUserId); rs = new ResultData(new Exception(username + " has been inactive"), username + " has been inactive"); //passLogon = false; ShowErrorMessage(username + " has been inactive"); } } if (passLogon) { LoggingHelper.Debug(username + " successfully logged in."); Tracing.WriteLine(Tracing.Category.Trace, username + " successfully logged in.", TraceLevel.Info, Guid.Empty, sessioninfo.CurrentUserId); rs = new ResultData("Success"); Response.Redirect("Main.aspx?type=logon"); } } catch (Exception ex) { rs = new ResultData(ex); //return rs.ToString(); ShowErrorMessage("Error::" + ex.Message); } return(rs.ToString()); }
public MA_PCCF ValidatePCCFConfig(SessionInfo sessioninfo, DA_TRN record) { MA_PCCF val = null; bool blnResult; //enter conditions LoggingHelper.Debug("Begin validate PCCF from config"); using (EFUnitOfWork unitOfWork = new EFUnitOfWork()) { var props = record.GetType().GetProperties(); var configs = unitOfWork.MA_PCCF_CONFIGRepository.GetAll() .Where(p => p.PRODUCT_ID.Equals(record.PRODUCT_ID)) .OrderBy(p => p.PRIORITY); //bool isBond = string.Compare(unitOfWork.MA_PRODUCTRepository.GetById(record.PRODUCT_ID.Value).LABEL, ProductCode.BOND.ToString(), true) == 0; if (configs != null) { List <bool> ismatchs = new List <bool>(); object obj; foreach (MA_PCCF_CONFIG p in configs.ToList()) { ismatchs.Clear(); blnResult = false; //List<MA_CONFIG_ATTRIBUTE> atts = unitOfWork.MA_CONFIG_ATTRIBUTERepository.All().Where(t => t.PCCF_CONFIG_ID == p.ID && t.ISACTIVE == true).ToList() ; foreach (MA_CONFIG_ATTRIBUTE ca in p.MA_CONFIG_ATTRIBUTE.Where(t => t.ISACTIVE == true).ToList()) { //Fix for Tables switch (ca.TABLE) { case "DA_TRN": var sel = props.FirstOrDefault(t => t.Name.Equals(ca.ATTRIBUTE)); if (sel != null) { if (sel.GetValue(record, null).GetType() == typeof(Guid)) { switch (ca.ATTRIBUTE) { //Fix for fields case "INSTRUMENT_ID": obj = new MA_INSTRUMENT(); obj = unitOfWork.MA_INSTRUMENTRepository.GetByIDWithOutInclude(new Guid(sel.GetValue(record, null).ToString())); blnResult = ((MA_INSTRUMENT)obj).LABEL.Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase); //ismatchs.Add(blnResult); break; default: break; } } else if (sel.GetValue(record, null).GetType() == typeof(Boolean)) { blnResult = sel.GetValue(record, null).Equals(ca.VALUE == "0" ? false : true); // ismatchs.Add(fsel.GetValue(record.FIRST, null).Equals(ca.VALUE=="0" ? false : true)); } else { blnResult = sel.GetValue(record, null).ToString().Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase); //ismatchs.Add(blnResult); } } break; case "BOND_MARKET": MA_INSTRUMENT insMkt = unitOfWork.MA_INSTRUMENTRepository.GetByIDWithInsMarket(record.INSTRUMENT_ID.Value); if (insMkt.MA_BOND_MARKET != null) { blnResult = insMkt.MA_BOND_MARKET.LABEL.Equals(ca.VALUE); //ismatchs.Add(blnResult); } //else //ismatchs.Add(false); break; case "FIRST": var fsel = record.FIRST.GetType().GetProperties().FirstOrDefault(f => f.Name.Equals(ca.ATTRIBUTE)); if (fsel != null) { if (fsel.GetValue(record.FIRST, null) != null) { if (fsel.GetValue(record.FIRST, null).GetType() == typeof(Guid)) { switch (ca.ATTRIBUTE) { //Fix for fields case "CCY_ID": obj = new MA_CURRENCY(); obj = unitOfWork.MA_CURRENCYRepository.GetByID(new Guid(fsel.GetValue(record.FIRST, null).ToString())); blnResult = ((MA_CURRENCY)obj).LABEL.Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase); //ismatchs.Add(); break; default: break; } } else if (fsel.GetValue(record.FIRST, null).GetType() == typeof(Boolean)) { blnResult = fsel.GetValue(record.FIRST, null).Equals(ca.VALUE == "0" ? false : true); // ismatchs.Add(fsel.GetValue(record.FIRST, null).Equals(ca.VALUE=="0" ? false : true)); } else { blnResult = fsel.GetValue(record.FIRST, null).ToString().Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase); //ismatchs.Add(fsel.GetValue(record.FIRST, null).ToString().Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase)); } } //else ismatchs.Add(false); } break; case "SECOND": //var secprop = props.FirstOrDefault(f => f.Name.Equals("SECOND")); var ssel = record.SECOND.GetType().GetProperties().FirstOrDefault(f => f.Name.Equals(ca.ATTRIBUTE)); if (ssel != null) { if (ssel.GetValue(record.SECOND, null) != null) { if (ssel.GetValue(record.SECOND, null).GetType() == typeof(Guid)) { switch (ca.ATTRIBUTE) { //Fix for fields case "CCY_ID": obj = new MA_CURRENCY(); obj = unitOfWork.MA_CURRENCYRepository.GetByID(new Guid(ssel.GetValue(record.SECOND, null).ToString())); blnResult = ((MA_CURRENCY)obj).LABEL.Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase); //ismatchs.Add(((MA_CURRENCY)obj).LABEL.Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase)); break; default: break; } } else if (ssel.GetValue(record.SECOND, null).GetType() == typeof(Boolean)) { blnResult = ssel.GetValue(record.SECOND, null).Equals(ca.VALUE == "0" ? false : true); // ismatchs.Add(ssel.GetValue(record.SECOND, null).Equals(ca.VALUE == "0" ? false : true)); } else { blnResult = ssel.GetValue(record.SECOND, null).ToString().Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase); // ismatchs.Add(ssel.GetValue(record.SECOND, null).ToString().Equals(ca.VALUE, StringComparison.CurrentCultureIgnoreCase)); } } //else ismatchs.Add(false); } break; case "COUNTERPARTY": MA_COUTERPARTY ctpy = unitOfWork.MA_COUTERPARTYRepository.GetAll().FirstOrDefault(z => z.ID == record.CTPY_ID); switch (ca.ATTRIBUTE) { case "SNAME": blnResult = ctpy.SNAME.ToUpper() == ca.VALUE.ToUpper(); break; case "CSA_TYPE": MA_CSA_AGREEMENT csa = unitOfWork.MA_CSA_AGREEMENTRepository.GetAll().FirstOrDefault(y => y.ID == record.CTPY_ID); if (csa != null && csa.MA_CSA_TYPE.LABEL.ToUpper() == ca.VALUE.ToUpper() && csa.MA_CSA_PRODUCT.FirstOrDefault(y => y.PRODUCT_ID == record.PRODUCT_ID) != null) { blnResult = true; } //else if (csa == null && ca.VALUE == "") // blnResult = true; else { blnResult = false; } break; default: break; } break; } ismatchs.Add(blnResult); //Check result -> if false then go to next config if (!blnResult) { break; } } if (ismatchs.Where(m => m.Equals(false)).Count() == 0) { val = unitOfWork.MA_PCCFRepository.GetByID(p.PCCF_ID); LoggingHelper.Debug("PCCF: " + val.LABEL); break; } else { continue; } } } else { val = null; } } LoggingHelper.Debug("End validate PCCF from config"); return(val); }
public bool SendNotification(BizTalkEnvironment environment, Alarm alarm, string globalProperties, Dictionary <MonitorGroupTypeName, MonitorGroupData> notifications) { try { XDocument globalDocument = XDocument.Parse(globalProperties); string uriString = globalDocument.XPathSelectElement("/*[local-name() = 'GlobalProperties']/*[local-name() = 'Section']/*[local-name() = 'TextBox' and @Name = 'servicenow-url']")?.Attribute("Value")?.Value; string userName = globalDocument.XPathSelectElement("/*[local-name() = 'GlobalProperties']/*[local-name() = 'Section']/*[local-name() = 'TextBox' and @Name = 'username']")?.Attribute("Value")?.Value; string password = globalDocument.XPathSelectElement("/*[local-name() = 'GlobalProperties']/*[local-name() = 'Section']/*[local-name() = 'TextBox' and @Name = 'password']")?.Attribute("Value")?.Value; bool useProxy = Convert.ToBoolean(globalDocument.XPathSelectElement( "/*[local-name() = 'GlobalProperties']/*[local-name() = 'Section']/*[local-name() = 'CheckBox' and @Name = 'use-proxy']") ?.Attribute("Value")?.Value); bool useDefaultCredentials = Convert.ToBoolean(globalDocument.XPathSelectElement( "/*[local-name() = 'GlobalProperties']/*[local-name() = 'Section']/*[local-name() = 'Group']/*[local-name() = 'CheckBox' and @Name = 'use-default-credentials']") ?.Attribute("Value")?.Value); WebProxy proxy = new WebProxy(); if (useProxy) { string serverName = globalDocument.XPathSelectElement( "/*[local-name() = 'GlobalProperties']/*[local-name() = 'Section']/*[local-name() = 'Group']/*[local-name() = 'TextBox' and @Name = 'server-name']") ?.Attribute("Value")?.Value; string domainName = globalDocument.XPathSelectElement( "/*[local-name() = 'GlobalProperties']/*[local-name() = 'Section']/*[local-name() = 'Group']/*[local-name() = 'TextBox' and @Name = 'domain']") ?.Attribute("Value")?.Value; string portName = globalDocument.XPathSelectElement( "/*[local-name() = 'GlobalProperties']/*[local-name() = 'Section']/*[local-name() = 'Group']/*[local-name() = 'TextBox' and @Name = 'port']") ?.Attribute("Value")?.Value; string proxyUsername = globalDocument.XPathSelectElement( "/*[local-name() = 'GlobalProperties']/*[local-name() = 'Section']/*[local-name() = 'Group']/*[local-name() = 'TextBox' and @Name = 'user-name']") ?.Attribute("Value")?.Value; string proxyPassword = globalDocument.XPathSelectElement( "/*[local-name() = 'GlobalProperties']/*[local-name() = 'Section']/*[local-name() = 'Group']/*[local-name() = 'TextBox' and @Name = 'proxy-password']") ?.Attribute("Value")?.Value; if (!string.IsNullOrEmpty(serverName) && !string.IsNullOrEmpty(portName)) { proxy = new WebProxy(serverName, Convert.ToInt32(portName)); if (!string.IsNullOrEmpty(proxyUsername) && !string.IsNullOrEmpty(proxyPassword) && !string.IsNullOrEmpty(domainName)) { proxy.Credentials = new NetworkCredential(proxyUsername, proxyPassword, domainName); } } if (useDefaultCredentials) { proxy.UseDefaultCredentials = true; } } XDocument alarmProperties = XDocument.Parse(alarm.AlarmProperties); string shortDescription = alarmProperties.XPathSelectElement("/*[local-name() = 'AlarmProperties']/*[local-name() = 'TextBox' and @Name = 'short-description']").Attribute("Value").Value; string impact = alarmProperties.XPathSelectElement("/*[local-name() = 'AlarmProperties']/*[local-name() = 'TextBox' and @Name = 'impact']").Attribute("Value").Value; string urgency = alarmProperties.XPathSelectElement("/*[local-name() = 'AlarmProperties']/*[local-name() = 'TextBox' and @Name = 'urgency']").Attribute("Value").Value; string assignmentgroup = alarmProperties.XPathSelectElement("/*[local-name() = 'AlarmProperties']/*[local-name() = 'TextBox' and @Name = 'assignment-group']").Attribute("Value").Value; string category = alarmProperties.XPathSelectElement("/*[local-name() = 'AlarmProperties']/*[local-name() = 'TextBox' and @Name = 'category']").Attribute("Value").Value; string subcategory = alarmProperties.XPathSelectElement("/*[local-name() = 'AlarmProperties']/*[local-name() = 'TextBox' and @Name = 'subcategory']").Attribute("Value").Value; string configItem = alarmProperties.XPathSelectElement("/*[local-name() = 'AlarmProperties']/*[local-name() = 'TextBox' and @Name = 'configuration-item']").Attribute("Value").Value; string additionalcomments = alarmProperties.XPathSelectElement("/*[local-name() = 'AlarmProperties']/*[local-name() = 'TextBox' and @Name = 'additional-comments']").Attribute("Value").Value; Dictionary <string, string> dictionary = new Dictionary <string, string> { { "short_description", shortDescription }, { "impact", impact }, { "urgency", urgency }, { "assignment_group", assignmentgroup }, { "category", category }, { "subcategory", subcategory }, { "cmdb_ci", configItem }, { "comments", additionalcomments } }; string incidentMessage = string.Empty + string.Format($"\nAlarm Name: {alarm.Name} \n\nAlarm Desc: {alarm.Description} \n" + "\n----------------------------------------------------------------------------------------------------\n" + $"\nEnvironment Name: {environment.Name} \n\nMgmt Sql Instance Name: { Regex.Escape(environment.MgmtSqlInstanceName)} \nMgmt Sql Db Name: {environment.MgmtSqlDbName}\n" + "\n----------------------------------------------------------------------------------------------------\n"); foreach (KeyValuePair <MonitorGroupTypeName, MonitorGroupData> keyValuePair in notifications.OrderBy <KeyValuePair <MonitorGroupTypeName, MonitorGroupData>, MonitorGroupTypeName>(n => n.Key)) { string monitorGroupType = keyValuePair.Key.ToString(); LoggingHelper.Debug($"Populate the monitor Status{monitorGroupType}"); foreach (MonitorGroup monitorGroup in keyValuePair.Value.monitorGroups) { incidentMessage += string.Format("{0} {1}\n", monitorGroupType, monitorGroup.name); if (monitorGroup.monitors != null) { foreach (Monitor monitor in monitorGroup.monitors) { incidentMessage += string.Format(" - {0} {1}\n", monitor.name, monitor.monitorStatus); } } } foreach (MonitorGroup monitorGroup in keyValuePair.Value.monitorGroups) { if (monitorGroup.monitors != null) { foreach (Monitor monitor in monitorGroup.monitors) { if (monitor.issues != null) { incidentMessage += string.Format("\n{0} Issues for {1}\n", monitorGroupType, monitor.name); foreach (Issue issue in monitor.issues) { incidentMessage += string.Format(" - {0}\n", issue.description); if (issue.monitoringErrorDescriptions != null) { foreach (MonitorErrorDescription monitorErrorDescription in issue.monitoringErrorDescriptions) { incidentMessage += $" {monitorErrorDescription.key} ({monitorErrorDescription.count}) -> {monitorErrorDescription.value} \n"; } } if (!string.IsNullOrEmpty(issue.optionalDetails)) { incidentMessage += string.Format("{0}\n", issue.optionalDetails); } } } } } } incidentMessage += "\n"; } dictionary.Add("work_notes", incidentMessage); LoggingHelper.Debug($"Successfully added to the Incident Object, Message: {incidentMessage}"); string content = JsonConvert.SerializeObject((object)dictionary); HttpClientHandler handler = new HttpClientHandler() { Proxy = proxy, UseProxy = useProxy }; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; using (HttpClient httpClient = new HttpClient(handler)) { httpClient.BaseAddress = new Uri(uriString); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage result = httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, "/api/now/table/incident") { Headers = { Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", userName, password)))) }, Content = new StringContent(content, Encoding.UTF8, "application/json") }).Result; if (result.IsSuccessStatusCode) { LoggingHelper.Info("ServiceNow Incident Creation was Successful"); } else { LoggingHelper.Error(string.Format("ServiceNow Incident Creation was Unsuccessful. \n Response: {0}", result)); } return(result.IsSuccessStatusCode); } } catch (Exception ex) { LoggingHelper.Fatal(ex.ToString()); LoggingHelper.Fatal(ex.StackTrace); LoggingHelper.Error(ex.Message); return(false); } }