Beispiel #1
0
        public static void LoadFpml(ILogger logger, ICoreCache targetClient)
        {
            Assembly     assembly = Assembly.GetExecutingAssembly();
            const string prefix   = "Orion.Configuration.Config.FpMLCodes";
            Dictionary <string, string> chosenFiles = ResourceHelper.GetResources(assembly, prefix, "xml");

            if (chosenFiles.Count == 0)
            {
                throw new InvalidOperationException("Missing FpML Code Lists");
            }

            foreach (var file in chosenFiles)
            {
                var    data         = XmlSerializerHelper.DeserializeFromString <CodeListDocument>(file.Value);
                string classDefName = GetClassDefName(data.Identification.ShortName);

                // determine primary key
                string primaryKey = null;
                foreach (Key key in data.ColumnSet.Key)
                {
                    if (key.Id == "PrimaryKey")
                    {
                        if (primaryKey != null)
                        {
                            throw new ApplicationException("PrimaryKey defined more than once!");
                        }
                        primaryKey = key.ColumnRef[0].Ref;
                    }
                }
                if (primaryKey == null)
                {
                    throw new ApplicationException("PrimaryKey is not defined!");
                }

                // load rows
                IFpMLCodeScheme scheme = FpMLCodeSchemeFactory.CreateCodeScheme(classDefName);
                foreach (Row row in data.SimpleCodeList.Row)
                {
                    IFpMLCodeValue codeValue = scheme.CreateCodeValue(row);
                    if (scheme is DayCountFractionScheme)
                    {
                        var dcfValue = (DayCountFractionValue)codeValue;
                        if (dcfValue.HLClassName == null)
                        {
                            dcfValue.HLClassName = "DefaultClassName";
                        }
                    }
                    scheme.AddCodeValue(codeValue);
                }
                targetClient.SaveTypedObject(scheme.GetType(), scheme, scheme.GetItemName(null), scheme.GetItemProps());
            } // foreach file
            logger.LogDebug("Loaded FpML code lists.");
        }
        public static void LoadFpMLCodes(ILogger logger, ICoreCache targetClient, string nameSpace)
        {
            Assembly     assembly = Assembly.GetExecutingAssembly();
            const string prefix   = "Orion.V5r3.Configuration.Config.FpMLCodes";
            Dictionary <string, string> chosenFiles = ResourceHelper.GetResources(assembly, prefix, "xml");

            if (chosenFiles.Count == 0)
            {
                throw new InvalidOperationException("Missing FpML Code Lists");
            }

            foreach (var file in chosenFiles)
            {
                var    data         = XmlSerializerHelper.DeserializeFromString <CodeListDocument>(file.Value);
                string classDefName = GetClassDefName(data.Identification.ShortName);

                // determine primary key
                string primaryKey = null;
                foreach (Key key in data.ColumnSet.Key)
                {
                    if (key.Id == "PrimaryKey")
                    {
                        if (primaryKey != null)
                        {
                            throw new ApplicationException("PrimaryKey defined more than once!");
                        }
                        primaryKey = key.ColumnRef[0].Ref;
                    }
                }
                if (primaryKey == null)
                {
                    throw new ApplicationException("PrimaryKey is not defined!");
                }

                // load rows
                IFpMLCodeScheme scheme = FpMLCodeSchemeFactory.CreateCodeScheme(classDefName);
                foreach (Row row in data.SimpleCodeList.Row)
                {
                    IFpMLCodeValue codeValue = scheme.CreateCodeValue(row);
                    if (scheme is DayCountFractionScheme)
                    {
                        var dcfValue = (DayCountFractionValue)codeValue;
                        if (dcfValue.HLClassName == null)
                        {
                            dcfValue.HLClassName = "DefaultClassName";
                        }
                    }
                    scheme.AddCodeValue(codeValue);
                }
                var type = scheme.GetItemProps().Get("FpMLCodeScheme");
                scheme.GetItemProps().Set(EnvironmentProp.DataGroup, "Orion.V5r3.Reporting.Configuration." + type);
                scheme.GetItemProps().Set(EnvironmentProp.SourceSystem, "Orion");
                scheme.GetItemProps().Set(EnvironmentProp.Function, FunctionProp.Configuration.ToString());
                scheme.GetItemProps().Set(EnvironmentProp.Type, "FpMLCodeScheme");
                scheme.GetItemProps().Set(EnvironmentProp.Schema, "V5r3.Reporting");
                scheme.GetItemProps().Set(EnvironmentProp.NameSpace, nameSpace);
                string identifier = "Configuration.FpMLCodeScheme." + type;
                string itemName   = nameSpace + "." + identifier;
                scheme.GetItemProps().Set(CurveProp.UniqueIdentifier, identifier);
                targetClient.SaveTypedObject(scheme.GetType(), scheme, itemName, scheme.GetItemProps());
            } // foreach file
            logger.LogDebug("Loaded FpML code lists.");
        }