private void ReadInternal(BinaryReader r) { Version = new BdsVersion(); Version.Read(r); int serFmtVer = r.ReadInt32(); if (serFmtVer > SERIALIZATION_FORMAT_VERSION) { throw new ApplicationException(string.Format( "Unsupported serialization format: {0}, max supported: {1}", serFmtVer, SERIALIZATION_FORMAT_VERSION)); } if (serFmtVer == 1) { throw new ApplicationException("Serialization format version 1 is not supported"); } int nodeSerFmtVer = 0; if (serFmtVer >= 3) { nodeSerFmtVer = r.ReadInt32(); } IClusterNode root; string typeName = r.ReadString(); ClassFactoryParams p = new ClassFactoryParams(typeName, ""); root = ClassFactory.CreateInstance <IClusterNode>(p); root.Read(r, nodeSerFmtVer); Root = root; }
static IGameLogReport CreateGameLogReport(string name) { IGameLogReport rep; if (String.IsNullOrEmpty(_cmdLine.ReportClass)) { rep = new TotalResult(); } else { ClassFactoryParams cfp = new ClassFactoryParams(_cmdLine.ReportClass); rep = ClassFactory.CreateInstance <IGameLogReport>(cfp); } rep.Name = name; rep.Configure(_reportParameters); // Show help only once if (_cmdLine.ShowReportHelp && !_isHelpShown) { rep.ShowHelp(_output); _isHelpShown = true; } return(rep); }
public void Test_CreateByAssemblyName_BaseClass() { string typeName = "ai.lib.utils.nunit.ClassFactory_Test+TestClass1,ai.lib.utils.nunit"; ClassFactoryParams p = new ClassFactoryParams { TypeName = typeName }; TestClass1 tc = (TestClass1)ClassFactory.CreateInstance <TestClassBase>(p); Assert.IsNotNull(tc); }
public void Test_CreateByAssemblyFileAndAssemblyName_AnotherAssembly() { string typeName = "ai.lib.utils.testlib.DerivedTestClass1, ai.lib.utils.testlib"; ClassFactoryParams p = new ClassFactoryParams { AssemblyFile = "", TypeName = typeName }; TestClassBase tc = ClassFactory.CreateInstance <TestClassBase>(p); Assert.IsNotNull(tc); }
public void Test_CreateByAssemblyFile_BaseClass() { string assemblyFile = Path.GetFileName(CodeBase.Get(Assembly.GetExecutingAssembly())); string typeName = "ai.lib.utils.nunit.ClassFactory_Test+TestClass1"; ClassFactoryParams p = new ClassFactoryParams { AssemblyFile = assemblyFile, TypeName = typeName }; TestClass1 tc = (TestClass1)ClassFactory.CreateInstance <TestClassBase>(p); Assert.IsNotNull(tc); }
static IPlayer CreatePlayer() { ClassFactoryParams cfp = new ClassFactoryParams(_cmdLine.BotClass.Get(Props.Global)); IPlayer iplayer = ClassFactory.CreateInstance <IPlayer>(cfp); if (iplayer != null) { Props creationParams = XmlSerializerExt.Deserialize <Props>(_cmdLine.CreationParametersFileName.Get(Props.Global)); iplayer.OnCreate(_botName, creationParams); } return(iplayer); }
public void Test_CreateByAssemblyName_Params() { string typeName = "ai.lib.utils.nunit.ClassFactory_Test+TestClass2,ai.lib.utils.nunit"; ClassFactoryParams p = new ClassFactoryParams { TypeName = typeName, Arguments = new object[] { 113, "bla-bla" } }; TestClass2 tc = ClassFactory.CreateInstance <TestClass2>(p); Assert.IsNotNull(tc); Assert.AreEqual(113, tc.P1); Assert.AreEqual("bla-bla", tc.P2); }
public void Test_CreateByAssemblyFile_NonReferencedAssembly() { string assemblyFile = "ai.lib.utils.testlib.dll"; string assemblyName = Path.GetFileNameWithoutExtension(assemblyFile); // First do not use assembly name in the type name string typeName = "ai.lib.utils.testlib.DerivedTestClass1"; ClassFactoryParams p = new ClassFactoryParams { AssemblyFile = assemblyFile, TypeName = typeName }; TestClassBase tc = ClassFactory.CreateInstance <TestClassBase>(p); Assert.IsNotNull(tc); }
public void Test_CreateByAssemblyFile_Params() { string assemblyFile = Path.GetFileName(CodeBase.Get(Assembly.GetExecutingAssembly())); string typeName = "ai.lib.utils.nunit.ClassFactory_Test+TestClass2"; ClassFactoryParams p = new ClassFactoryParams { AssemblyFile = assemblyFile, TypeName = typeName, Arguments = new object[] { 113, "bla-bla" } }; TestClass2 tc = ClassFactory.CreateInstance <TestClass2>(p); Assert.IsNotNull(tc); Assert.AreEqual(113, tc.P1); Assert.AreEqual("bla-bla", tc.P2); }
public static IChanceAbstraction CreateFromProps(Props props) { ClassFactoryParams cfp = new ClassFactoryParams { TypeName = props.Get("TypeName"), AssemblyFile = props.Get("AssemblyFileName"), Arguments = new object[] { props } }; if (string.IsNullOrEmpty(cfp.TypeName)) { throw new ApplicationException("Missing required property 'TypeName'"); } IChanceAbstraction ca = ClassFactory.CreateInstance <IChanceAbstraction>(cfp); return(ca); }
static IPlayer CreatePlayer() { ClassFactoryParams cfp = new ClassFactoryParams(_cmdLine.BotClass.Get(Props.Global)); IPlayer iplayer = ClassFactory.CreateInstance <IPlayer>(cfp); if (iplayer != null) { Props creationParams = XmlSerializerExt.Deserialize <Props>(_cmdLine.CreationParametersFileName.Get(Props.Global)); iplayer.OnCreate(BotName, creationParams); PlayerInfo pi = iplayer.OnServerConnect(); if (_cmdLine.Verbose) { Console.WriteLine("Player.OnServerConnect() returned:"); Console.WriteLine("Name: {0}", pi.Name); Console.WriteLine("Version: {0}", pi.Version); } iplayer.OnSessionBegin(SessionName, null, null); } return(iplayer); }