コード例 #1
0
 public void TestSerialisingInterfaceTypes()
 {
     // tests control of the serialisation type
     // - interface types
     using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true)))
     {
         using (CoreServer server = new CoreServer(loggerRef, "UTT", NodeType.Router))
         {
             // start server
             server.Start();
             using (ICoreClient client = new CoreClientFactory(loggerRef).SetEnv("UTT").Create())
             {
                 AssetMeasureValue codeValueInstance = new AssetMeasureValue()
                 {
                     Code        = "Test",
                     Description = "This is a test",
                     Source      = "UnitTest"
                 };
                 IFpMLCodeValue codeValueInterface = codeValueInstance;
                 // save reference item
                 client.SaveObject(codeValueInstance, "Test0", null, TimeSpan.MaxValue);
                 ICoreItem itemA = client.LoadItem("Test0");
                 Assert.AreEqual(typeof(AssetMeasureValue).FullName, itemA.DataTypeName);
                 // test interface and instance both serialise identically
                 {
                     client.SaveUntypedObject(codeValueInterface, "Test1", null);
                     ICoreItem itemB = client.LoadItem("Test1");
                     Assert.AreEqual(typeof(AssetMeasureValue).FullName, itemB.DataTypeName);
                     Assert.AreEqual(itemA.Text, itemB.Text);
                 }
                 {
                     client.SaveObject((AssetMeasureValue)codeValueInterface, "Test2", null, TimeSpan.MaxValue);
                     ICoreItem itemB = client.LoadItem("Test2");
                     Assert.AreEqual(typeof(AssetMeasureValue).FullName, itemB.DataTypeName);
                     Assert.AreEqual(itemA.Text, itemB.Text);
                 }
                 {
                     // this should fail because interfaces cant be serialised
                     UnitTestHelper.AssertThrows <ArgumentException>("Cannot be an interface type!\r\nParameter name: dataType", () =>
                     {
                         client.SaveObject(codeValueInterface, "Test3", null, TimeSpan.MaxValue);
                     });
                 }
                 {
                     // note: this silently binds to SaveObject<IFpMLCodeValue>(...) which should fail
                     UnitTestHelper.AssertThrows <ArgumentException>("Cannot be an interface type!\r\nParameter name: dataType", () =>
                     {
                         client.SaveObject(codeValueInterface, "Test4", null, TimeSpan.MaxValue);
                     });
                 }
             }
             // shutdown
             server.Stop();
         }
     }
 }
コード例 #2
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.");
        }
コード例 #3
0
 public void AddCodeValue(IFpMLCodeValue codeValue)
 {
     try
     {
         if (codeValue.GetType() != typeof(ProductTaxonomyValue))
         {
             throw new ApplicationException(
                       String.Format("Cannot convert type '{0}' to '{1}'!", codeValue.GetType().Name, typeof(ProductTaxonomyValue).Name));
         }
         int newLength = 1;
         //if (schemeValuesField != null)
         //    newLength = schemeValuesField.Length + 1;
         //var newValues = new ProductTaxonomyValue[newLength];
         //if (schemeValuesField != null)
         //    schemeValuesField.CopyTo(newValues, 0);
         //newValues[newLength - 1] = (ProductTaxonomyValue)codeValue;
         //schemeValuesField = newValues;
     }
     catch (Exception excp)
     {
         Trace.WriteLine(String.Format("ProductTypeSimpleScheme.AddCodeValue failed: {0}", excp));
     }
 }
コード例 #4
0
        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.");
        }