Example #1
0
        /// <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;
        }
Example #2
0
        /// <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;
        }
Example #3
0
        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;
        }
Example #4
0
        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 = "";
            }
        }