/// <summary> /// This function is responsible for building a PropertyBag from the metatags that are used in a given job spec. It /// parses the job spec to identify and build a list of metatags as the properties in the PropertyBag. /// The PropertyBag properties are then initialized and assigned from the Environment Metatags that were set earlier and made /// available in the GlobalConfig.GlobalParameters (also a PropertyBag). Any runtime parameters will not be found in the /// GlobalConfig.GlobalParameters object and those properties in the new PropertyBag will be set to null. /// </summary> /// <param name="jobName"></param> /// <param name="jobSpec"></param> /// <param name="jobParameters"></param> public static PropertyBag GetJobParametersPB(string jobName, string jobSpec) { PropertyBag jobParameters = new PropertyBag(); List<string> metaTagNameCandidates = jobSpec.Split('*').ToList<string>(); if (metaTagNameCandidates.Count > 1) { for (int index = 1; index < metaTagNameCandidates.Count - 1; index++) { string metaTagKey = "*" + metaTagNameCandidates[index] + "*"; string metaTagValue = metaTagKey; if (!jobParameters.Contains(metaTagKey) && IsValidMetatag(metaTagKey, null)) { jobParameters[metaTagKey] = null; log.InfoFormat("[Job = {0}] Initialized property from metatag: {1}", jobName, metaTagKey); } else { log.DebugFormat("[Job = {0}] Unable to initialize property from metatag: {1}", jobName, metaTagKey); } } } return jobParameters; }
/// <summary> /// This function is responsible for building a PropertyBag from the metatags that are used in a given job spec. It /// parses the job spec to identify and build a list of metatags as the properties in the PropertyBag. /// The PropertyBag properties are then initialized and assigned from the Environment Metatags that were set earlier and made /// available in the GlobalConfig.GlobalParameters (also a PropertyBag). Any runtime parameters will not be found in the /// GlobalConfig.GlobalParameters object and those properties in the new PropertyBag will be set to null. /// </summary> /// <param name="jobName"></param> /// <param name="jobSpec"></param> /// <param name="jobParameters"></param> public static PropertyBag GetJobParametersPB(string jobName, string jobSpec) { PropertyBag jobParameters = new PropertyBag(); List<string> metaTagNameCandidates = jobSpec.Split('*').ToList<string>(); if (metaTagNameCandidates.Count > 1) { for (int index = 1; index < metaTagNameCandidates.Count - 1; index++) { string metaTagKey = "*" + metaTagNameCandidates[index] + "*"; string metaTagValue = metaTagKey; if (!jobParameters.Contains(metaTagKey) && IsValidMetatag(metaTagKey, null)) { jobParameters[metaTagKey] = null; log.DebugFormat("[Job = {0}] Initialized property from metatag: {1}", jobName, metaTagKey); } else { log.DebugFormat("[Job = {0}] Unrecognized string is not a known metatag: {1}", jobName, metaTagKey); } } } log.DebugFormat("[Job = {0}] Found {1} metatags from {2} candidates (i.e. split no '*')", jobName, jobParameters.Count(), metaTagNameCandidates.Count); return jobParameters; }
/// <summary> /// To retrieve meta tag value from PropertyBag where it is should already be available /// no replacement in this case /// </summary> /// <param name="metaTagKey"></param> /// <param name="pb"></param> /// <returns></returns> public static string GetMetaTagValueFromPB(string metaTagKey, PropertyBag pb) { string metaTagValue = pb[metaTagKey] as string; return metaTagValue; }
/// <summary> /// This method replaces all metatags in a string with their values from the Dynamic PropertyBag /// </summary> /// <param name="inStr"></param> /// <param name="metaTagParameters"></param> /// <returns></returns> public static string InlineMetatagSubstitution(string inStr, PropertyBag metaTagParameters) { string result = inStr; foreach (string metaTagName in metaTagParameters.Names) { string metaTagValue = metaTagParameters[metaTagName] as string; if (metaTagValue != null) result = result.Replace(metaTagName, metaTagValue); } return result; }
/// <summary> /// This method loads environmental properties from Config database /// for use by BITS itself as well as individual jobs (and UI ???) /// </summary> /// <param name="environmentProperties"></param> public static void LoadEnvironmentProperties(ref PropertyBag environmentProperties) { IList<string> tagNames = ConfigUtils.GlobalConfig.Hierarchy.LevelNames(@"appgroup\METATAGS\Environment"); foreach (string tagName in tagNames) { environmentProperties[tagName] = GetMetaTagValueFromConfig(tagName, null); log.InfoFormat("Added to environment properties: {0} = {1}", tagName, environmentProperties[tagName]); } // MetaTagReplacerFunctions.LoadReplacerFunctions(); }
public static Job BuildJobFromXml(JobDetails detail) { Job job = null; try { XmlDocument doc = new XmlDocument(); doc.LoadXml(detail.Xml); XmlNode jobNode = doc.SelectSingleNode("Job"); if (jobNode.Attributes["isHistoricalMode"] != null) detail.IsHistoricalMode = Convert.ToBoolean(jobNode.Attributes["isHistoricalMode"].Value); if (jobNode.Attributes["ifWaitingForFirstTrigger"] != null) detail.IfWaitingForFirstTrigger = Convert.ToBoolean(jobNode.Attributes["ifWaitingForFirstTrigger"].Value); if (jobNode.Attributes["skipTodayIfPassed"] != null) detail.SkipTodayIfPassed = Convert.ToBoolean(jobNode.Attributes["skipTodayIfPassed"].Value); if (jobNode.Attributes["runOnce"] != null) detail.RunOnce = Convert.ToBoolean(jobNode.Attributes["runOnce"].Value); if (jobNode.Attributes["limitTrigger"] != null) { detail.UserLimit = Convert.ToInt32(jobNode.Attributes["limitTrigger"].Value); } if (jobNode.Attributes["inDate"] != null || jobNode.Attributes["runDate"] != null) { if (jobNode.Attributes["inDate"] != null) detail.InDate = Convert.ToString(jobNode.Attributes["inDate"].Value); else if (jobNode.Attributes["runDate"] != null) detail.InDate = Convert.ToString(jobNode.Attributes["runDate"].Value); } if (jobNode.Attributes["MaxRetries"] != null) detail.MaxRetries = Convert.ToInt32(jobNode.Attributes["MaxRetries"].Value); if (jobNode.Attributes["DelayBetweenRetries"] != null) detail.DelayBetweenRetries = Convert.ToInt32(jobNode.Attributes["DelayBetweenRetries"].Value); if (jobNode.Attributes["RetryFromTop"] != null) detail.RetryFromTop = Convert.ToBoolean(jobNode.Attributes["RetryFromTop"].Value); job = new Job( jobNode.Attributes["name"].Value.ToString().Trim(), jobNode.Attributes["dependencyTraversalMode"].Value.ToString().Trim(), detail, ConfigUtils.GlobalConfig); IModule root = BuildModule(job.JobName, "NullModule"); job.Modules.Add(root.Name.Trim(), root); XmlNodeList modules = doc.SelectNodes("Job/Module"); foreach (XmlNode moduleNode in modules) { string moduleTypeName = moduleNode.Attributes["moduleType"].Value.ToString(); PropertyBag moduleOriginalPropertyValues = new PropertyBag(); IModule module = BuildModule(moduleNode, moduleTypeName, moduleOriginalPropertyValues); job.OrderedModuleList.Add(module.Name); if (job.Modules.ContainsKey(module.Name)) job.Modules.Remove(module.Name); job.Modules.Add(module.Name, module); job.JobState.CurrentParameters.SetOriginalModulePropertyValuesPB(module.Name, moduleOriginalPropertyValues); job.JobState.CurrentStatusCollection.Add(module.Name, new DependencyStatus()); log.DebugFormat("Job {0}: Instantiated module {1}", job.JobName, moduleNode.Attributes["name"].Value.ToString()); } DependencyEngine dsb = new DependencyEngine(); dsb.Build(ref job); } catch (Exception ex) { log.Error(ex); } return job; }
private static IModule BuildModule(XmlNode moduleNode, string moduleTypeName, PropertyBag moduleOriginalPropertyValues) { IModule module = ModuleFactory.TryCreate(moduleTypeName); if (module == null) { log.ErrorFormat("Unable to build module {0}", moduleTypeName); return null; } PropertyInfo[] pis = module.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo pi in pis) { foreach (XmlAttribute attribute in moduleNode.Attributes) { if (pi.Name.ToLower().CompareTo(attribute.Name.ToLower()) == 0) { moduleOriginalPropertyValues[pi.Name] = attribute.Value; SetModulePropertyValueFromString(module, pi, attribute.Value); break; } } } return module; }
private static void HandleSpecialCurrencies(string targetTag, ref XmlDocument trades, ref XmlNode trade, ref PropertyBag htTradeDetail, ref XmlNode cChildNode, string nsuri) { if ((htTradeDetail.Contains("SourceInvestmentType") && (htTradeDetail["SourceInvestmentType"].ToString().ToUpper().Equals("SWAP") || htTradeDetail["SourceInvestmentType"].ToString().ToUpper().Equals("SWAPUS") || htTradeDetail["SourceInvestmentType"].ToString().ToUpper().Equals("SWAPI"))) && // tests for NDF currencies (htTradeDetail.Contains("PriceDenomination") && htTradeDetail["PriceDenomination"].ToString().ToUpper().Equals("AUD") && htTradeDetail.Contains("CounterInvestment") && htTradeDetail["CounterInvestment"].ToString().ToUpper().Equals("AUD")) || (htTradeDetail.Contains("PriceDenomination") && htTradeDetail["PriceDenomination"].ToString().ToUpper().Equals("NZD") && htTradeDetail.Contains("CounterInvestment") && htTradeDetail["CounterInvestment"].ToString().ToUpper().Equals("NZD")) || (htTradeDetail.Contains("PriceDenomination") && htTradeDetail["PriceDenomination"].ToString().ToUpper().Equals("HKD") && htTradeDetail.Contains("CounterInvestment") && htTradeDetail["CounterInvestment"].ToString().ToUpper().Equals("HKD")) || (htTradeDetail.Contains("PriceDenomination") && htTradeDetail["PriceDenomination"].ToString().ToUpper().Equals("EUR") && htTradeDetail.Contains("CounterInvestment") && htTradeDetail["CounterInvestment"].ToString().ToUpper().Equals("EUR")) || (htTradeDetail.Contains("PriceDenomination") && htTradeDetail["PriceDenomination"].ToString().ToUpper().Equals("GBP") && htTradeDetail.Contains("CounterInvestment") && htTradeDetail["CounterInvestment"].ToString().ToUpper().Equals("GBP")) && //Added for Dual Currency support (note that this clause must follow those clauses above that test for NDF currencies) (htTradeDetail.Contains("PriceDenomination") && htTradeDetail.Contains("CounterInvestment") && htTradeDetail["PriceDenomination"].ToString().ToUpper().Equals(htTradeDetail["CounterInvestment"].ToString().ToUpper())) ) { switch (targetTag) { case "CounterTDateFx": case "CounterSDateFx": double fx = double.NaN; double.TryParse(htTradeDetail[targetTag].ToString(), out fx); if (!fx.Equals(double.NaN) && !double.IsNaN(1.0/fx)) { htTradeDetail[targetTag] = 1.0/fx; cChildNode.InnerXml = htTradeDetail[targetTag].ToString(); } break; case "tradeFX": double tfx = double.NaN; if (htTradeDetail.Contains("DualCurrencyFlag") && htTradeDetail["DualCurrencyFlag"].ToString() == "DC" && htTradeDetail.Contains("DualCurrencyFXRate") && double.TryParse(htTradeDetail["DualCurrencyFXRate"].ToString(), out tfx)) { htTradeDetail["tradeFX"] = tfx.ToString(); cChildNode.InnerXml = tfx.ToString(); } else { htTradeDetail["tradeFX"] = String.Empty; cChildNode.InnerXml = String.Empty; } //do only once XmlNode CounterFxDenominationNode = trades.CreateNode(XmlNodeType.Element, "CounterFXDenomination", nsuri); CounterFxDenominationNode.InnerXml = "USD"; if (TestIfValidForSchema(CounterFxDenominationNode, htTradeDetail)) trade.AppendChild(CounterFxDenominationNode); break; } } else if (htTradeDetail.Contains("PriceDenomination") && htTradeDetail.Contains("CounterInvestment") && htTradeDetail["PriceDenomination"].ToString().ToUpper().Equals(htTradeDetail["CounterInvestment"].ToString().ToUpper()) == false) { switch (targetTag) { case "CounterTDateFx": case "CounterSDateFx": if (htTradeDetail.Contains(targetTag)) { double fx = double.NaN; double.TryParse(htTradeDetail[targetTag].ToString(), out fx); if (!fx.Equals(double.NaN) && !double.IsNaN(1.0/fx)) { htTradeDetail[targetTag] = 1.0/fx; cChildNode.InnerXml = htTradeDetail[targetTag].ToString(); } } break; case "tradeFX": double tfx = double.NaN; if (htTradeDetail.Contains("DualCurrencyFxRate") && double.TryParse(htTradeDetail["DualCurrencyFxRate"].ToString(), out tfx)) { htTradeDetail["tradeFX"] = tfx.ToString(); cChildNode.InnerXml = tfx.ToString(); } else { htTradeDetail["tradeFX"] = String.Empty; cChildNode.InnerXml = String.Empty; } break; } } else if (htTradeDetail.Contains("PriceDenomination") && htTradeDetail.Contains("CounterInvestment") && htTradeDetail["PriceDenomination"].ToString().ToUpper().Equals(htTradeDetail["CounterInvestment"].ToString().ToUpper())) { switch (targetTag) { case "CounterTDateFx": htTradeDetail["CounterTDateFx"] = ""; cChildNode.InnerXml = ""; break; case "CounterSDateFx": htTradeDetail["CounterSDateFx"] = ""; cChildNode.InnerXml = ""; break; case "tradeFX": htTradeDetail["tradeFX"] = "1.0"; cChildNode.InnerXml = "1.0"; break; } } else { cChildNode.InnerXml = ""; } }
/// <summary> /// Sets PropertyBag containing module's original property values /// to be replaced with dynamic "current" parameters, i.e. metatags, etc. /// </summary> /// <param name="module"></param> /// <param name="properties_original_values"></param> public void SetOriginalModulePropertyValuesPB(string module, PropertyBag properties_original_values) { _original_parameters[module] = properties_original_values; }
/// <summary> /// Sets module property meta tag override PropertyBag /// Can be used for historical job rerun and to access module dynamic parameters during module execution /// </summary> /// <param name="module"></param> /// <param name="property"></param> /// <param name="original_value"></param> public void SetModulePropertyOverridesPB(string module, string property, PropertyBag overridesPB) { if (!_module_override_parameters.ContainsKey(module)) _module_override_parameters.Add(module, new PropertyBag()); if (_module_override_parameters[module].Contains(property)) _module_override_parameters[module][property] = overridesPB; else _module_override_parameters[module].Add(property, overridesPB); }
protected static bool TestIfValidForSchema(XmlNode node, PropertyBag data, XmlDocument xdocValidationRules) { bool res = true; try { if (data["loaderAction"].Equals("Delete") && !node.Name.Equals("KeyValue")) res = false; else if (!data["loaderAction"].Equals("InsertUpdate") && node.Name.Equals("KeyName")) res = false; else if (data["loaderAction"].Equals("New") && data["loaderType"].Equals("Buy") && node.Name.Equals("KeyValue")) res = false; else if (data["loaderType"].Equals("Buy") && node.Name.Equals("SecFeeAmount")) res = false; else if (data["loaderType"].Equals("CoverShort") && node.Name.Equals("SecFeeAmount")) res = false; //use this section for filtering out specific fields before load if (data["SourceInvestmentType"] != null && (data["SourceInvestmentType"].Equals("FXForward") || data["SourceInvestmentType"].Equals("FX") || data["SourceInvestmentType"].Equals("FXNDF"))) { switch (node.Name) { case "AccruedInterest": case "InvestmentAccruedInterest": case "CounterFXDenomination": case "CounterSDateFx": case "CounterTDateFx": case "tradeFX": case "TotCommission": case "PriceDenomination": case "Price": case "Quantity": case "OriginalFace": case "ContractExpirationDate": res = false; break; } } else { //switch (node.Name) //{ // case "ContractFxRate": // res = false; // break; //} } } catch (Exception ex) { log.ErrorFormat("Trade data (loaderAction/loaderType not found for validation\n{0}", ex); } if (xdocValidationRules != null && xdocValidationRules.SelectSingleNode("ValidationRules/TradeRules") != null) { foreach (XmlNode validationNode in xdocValidationRules.SelectSingleNode("ValidationRules/TradeRules")) { try { string[] validationPairs = validationNode.Attributes["rule"].Value.Split(new string[] { "AND" }, StringSplitOptions.RemoveEmptyEntries); foreach (string validationPair in validationPairs) { string[] validationKeys = validationPair.Trim().Split(' '); if (!validationKeys[0].Equals("nodename")) { if (validationKeys[1].Equals("==")) if (!data.Contains(validationKeys[0]) || !data[validationKeys[0]].Equals(validationKeys[2])) break; } else { if (validationKeys[1].Equals("==")) if (node.Name.Equals(validationKeys[2])) res = false; } } } catch (Exception ex) { log.ErrorFormat("Could not validate schema using rule {0}", validationNode.ToString()); log.ErrorFormat("{0}", ex.ToString()); } } } return res; }
protected static bool TestIfValidForSchema(XmlNode node, PropertyBag data) { return TestIfValidForSchema(node, data, null); }
protected string ConvertToGenevaOption(int jobKeyCode, string ezeOption, PropertyBag htTradeDetail, XmlDocument xdocEzeToGenevaMap) { string[] tokensEze = ezeOption.ToString().ToUpper().Split(' '); string retval = ezeOption; try { char side = ' '; double strike = 0.0; string residual = String.Empty; OptionSideAndStrike(tokensEze, ref side, ref strike, ref residual); string cust = String.Empty; if (tokensEze.Length == 5 && !ezeOption.EndsWith("-OPTO")) { String mappedVal = String.Empty; EzeToGenevaManualMap(jobKeyCode, xdocEzeToGenevaMap, EzeToGenevaMapType.Broker, htTradeDetail["Broker"].ToString(), out mappedVal); cust = String.Format("{0}-OPTO", mappedVal); } else if (tokensEze.Length == 5 && ezeOption.EndsWith("-OPTO")) cust = tokensEze[4]; else if (tokensEze.Length == 4 && tokensEze[3].Contains("-") && residual.Length == 0) cust = CleanOTCCust(tokensEze[3]); else if (tokensEze.Length == 3 && ezeOption.EndsWith("-OPTO") && residual.Length > 0) cust = CleanOTCCust(residual); else cust = String.Empty; switch (OptionElement2(tokensEze[1])) { case 0: // date case 1: // int retval = String.Format("{0} {1} {2}{3} {4}", tokensEze[0], tokensEze[1], side, (Math.Round(strike) < strike ? strike.ToString("0.00") : strike.ToString("0")), cust).Trim(); break; case 2: //exchange retval = String.Format("{0} {1} {2} {3}{4} {5}", tokensEze[0], tokensEze[1], tokensEze[2], side, (Math.Round(strike) < strike ? strike.ToString("0.00") : strike.ToString("0")), cust).Trim(); break; } } catch (Exception ex) { log.ErrorFormat("Error converting Geneva option: {0}", ex); } return retval; }
public object Clone() { PropertyBag bag=new PropertyBag(); bag.m_Properties=(Hashtable)m_Properties.Clone(); return bag; }
/// <summary> /// This method is the sole method responsible for assigning values to job's Dynamic Properties. /// It does this based on one of the [only] two types of metatags (Environment or RunTime) /// </summary> /// <param name="jobParameters"></param> /// <param name="replaceMode"></param> /// <param name="inputDates"></param> /// <param name="inputArgs"></param> public static bool SetParametersValuesPB(ref PropertyBag jobParameters, ConfigUtils.MetatagMode replaceMode, MetaTagReplacerInputDates inputDates, object[] inputArgs ) { bool retval = true; MetaTagReplacerInputDates inputDateParms = inputDates; if (inputDateParms == null) inputDateParms = new MetaTagReplacerInputDates(DateTime.Now); log.InfoFormat("Input Date used to initialize run-time properties: {0}", inputDateParms.InDate); PropertyBag tempPropBag = new PropertyBag(); foreach (string metaTagKey in jobParameters.Names) { string metaTagValue = GetMetaTagValue(metaTagKey, inputDateParms, replaceMode, inputArgs); if (metaTagValue != null) { tempPropBag[metaTagKey] = metaTagValue; } else { if (IsValidMetatag(metaTagKey, replaceMode)) { log.WarnFormat("Unable to assign property value for {0}", metaTagKey); } else retval = false; //not a valid meta tag - should never happen at this point as illegal MTs should not make it to PB in a first place } } foreach (string metaTagKey in tempPropBag.Names) { jobParameters[metaTagKey] = tempPropBag[metaTagKey]; log.InfoFormat("Assigned property value: {0} = {1}", metaTagKey, jobParameters[metaTagKey]); } return retval; }
public Object GetMetaTagReplacement(object arg) { //VJ New MetaTag substitution logic //return ConfigUtils.MetaTagReplacer(arg.ToString(),ConfigUtils.MetatagMode.Environment); // string result = string.Empty; string[] arguments = arg.ToString().Split(Convert.ToChar(252)); string replace_in = (string) arguments.GetValue(0); DateTime in_date = DateTime.MinValue; bool useInDate = false; if (arguments.Length > 1) { string in_date_str = (string) arguments.GetValue(1); if (!string.IsNullOrEmpty(in_date_str)) { if (DateTime.TryParse(in_date_str, out in_date)) useInDate = true; } } // Check if explicit "bag of parameters" is passed then if true use it for 1st pass of meta tag replacement //Should be list of "Name;Vlaue" delimited pairs if (arguments.Length > 2) { PropertyBag in_parameters = new PropertyBag(); for (int incr = 2; incr < arguments.Length; incr++) { string[] in_parms = ((string)arguments.GetValue(incr)).Split(Convert.ToChar(253)); if (in_parms.Length == 2) { string in_parm_name = (string) in_parms.GetValue(0); string in_parm_value = (string)in_parms.GetValue(1); if (!string.IsNullOrEmpty(in_parm_name) && !string.IsNullOrEmpty(in_parm_value)) in_parameters.Add(in_parm_name, in_parm_value); } } if (in_parameters.Count() > 0) result = MetaTagReplacer.InlineMetatagSubstitution(replace_in, in_parameters); } //Second, replace the rest of the tags if (useInDate) //use "Full" replacement driven by InDate parameter when it is passed result = MetaTagReplacer.InlineMetatagSubstitution(replace_in, in_date); else //Dafault: replace Environment parameters only (as before) result = MetaTagReplacer.InlineMetatagSubstitution(replace_in, ConfigUtils.GlobalConfig.GlobalParameters); return result; }
private void CalcExchangeFeeAmount(ref PropertyBag htTradeInfo, ref XmlDocument newAttributesToAdd) { if (!htTradeInfo["SecFeeAmount"].Equals(htTradeInfo["TotalFees"])) { double totalFees = double.MinValue; double secFees = double.MinValue; double.TryParse(htTradeInfo["TotalFees"].ToString(), out totalFees); double.TryParse(htTradeInfo["SecFeeAmount"].ToString(), out secFees); if (totalFees.Equals(double.MinValue) || secFees.Equals(double.MinValue)) log.WarnFormat("Could not calculate Exchange Fees on {0}", htTradeInfo["investment"]); else if (totalFees != 0.0 || secFees != 0.0) { htTradeInfo["ExchangeFeeAmount"] = totalFees - secFees; XmlNamespaceManager nsmgrFee = new XmlNamespaceManager(newAttributesToAdd.NameTable); nsmgrFee.AddNamespace("gv", nsuri); if (Convert.ToDouble(htTradeInfo["tradeFX"]) != 0.0) { XmlNode exchangeFeeAtttribute = CreateCapExpenseNode( nsuri, newAttributesToAdd, newAttributesToAdd.SelectNodes("gv:TradeExpenses", nsmgrFee).Count + 1, "InternationalExchangeFee", Convert.ToDouble(htTradeInfo["ExchangeFeeAmount"])/Convert.ToDouble(htTradeInfo["tradeFX"])); if (newAttributesToAdd.SelectNodes("gv:TradeExpenses", nsmgrFee).Count == 0) newAttributesToAdd.AppendChild(exchangeFeeAtttribute); } } } }