示例#1
0
        static void Main(string[] args)
        {
            DressRehearsal_InputToOutput();
            //var s = new List<string> { "test", "test2" };
            //var res = PrelimReverseMarshaller.marshalFrom(s);
            //var res = PrelimReverseMarshaller.marshalFromObject(new testObj());
            Player player = new Player();
            player = Marshaller.unmarshalFrom<Player>(test_target);
            var res2 = Marshaller.marshalFromObject(player);
            var resStr2 = Marshaller.marshalFromListBlock(res2);
            var res = Marshaller.marshalFromObject(new testObj());
            var resStr = Marshaller.marshalFromListBlock(res);
            Debug.WriteLine(resStr);
            Debug.WriteLine(resStr2);

            var i = 0;

            while (i < 1)
            {
                using (var ctx = new WastelandA23.Model.CodeFirstModel.LoadoutContext())
                {
                    Database.SetInitializer(new WastelandA23.Model.Init.LoadoutContextSeed(true));
                    ctx.Database.Initialize(true);
                }

                using (var ctx = new WastelandA23.Model.CodeFirstModel.LoadoutContext())
                {
                    var type_maps = Mapper.GetAllTypeMaps();
                    //Mapper.CreateMap<Item, WastelandA23.Model.CodeFirstModel.Item>().Include<Magazine, WastelandA23.Model.CodeFirstModel.Magazine>();
                    var model_player = Mapper.Map<WastelandA23.Model.CodeFirstModel.Player>(player);
                    ctx.Players.Add(model_player);
                    ctx.SaveChanges();

                }

                using (var ctx = new WastelandA23.Model.CodeFirstModel.LoadoutContext())
                {
                    var backpack = ctx.Backpacks.First();
                    ctx.Backpacks.Remove(backpack);
                    ctx.SaveChanges();

                    var p = ctx.Players.FirstOrDefault();
                    ctx.Players.Remove(p);
                    ctx.SaveChanges();
                }

                i++;
            }

            Console.ReadLine();
        }
示例#2
0
        private static void DressRehearsal_InputToOutput()
        {
            TypeMapper.Map<Player, WastelandA23.Model.CodeFirstModel.Player>(new Player(), new WastelandA23.Model.CodeFirstModel.Player());

            TypeConverter.SetConverters(new WastelandTypeConversionDictionary());

            string input = test_target;
            // from SQF-String to player class hierarchy
            Player player = Marshaller.unmarshalFrom<Player>(input);
            var typeMap = Mapper.GetAllTypeMaps();
            //var CFItemMag = typeMap.Where(_ => _.SourceType == typeof(WastelandA23.Model.CodeFirstModel.Item)).FirstOrDefault();
            //CFItemMag.IncludeDerivedTypes(typeof(WastelandA23.Model.CodeFirstModel.Magazine), typeof(Magazine));

            //var MapsWithInheritance = typeMap.Where(_ => _.IncludedDerivedTypes.Any());
            WastelandA23.Model.CodeFirstModel.Player db_player = null;
            string output = null;

            // drop and recreate database
            using (var ctx = new WastelandA23.Model.CodeFirstModel.LoadoutContext())
            {
                Database.SetInitializer(new WastelandA23.Model.Init.LoadoutContextSeed(true));
                ctx.Database.Initialize(true);
            }

            // from player class hierarchy to database via AutoMapper and Entity Framework
            using (var ctx = new WastelandA23.Model.CodeFirstModel.LoadoutContext())
            {
                var type_maps = Mapper.GetAllTypeMaps();
                //Mapper.CreateMap<Item, WastelandA23.Model.CodeFirstModel.Item>().Include<Magazine, WastelandA23.Model.CodeFirstModel.Magazine>();
                var model_player = Mapper.Map<WastelandA23.Model.CodeFirstModel.Player>(player);
                ctx.Players.Add(model_player);
                ctx.SaveChanges();
            }
                using (var ctx = new WastelandA23.Model.CodeFirstModel.LoadoutContext())
                {
                    db_player = ctx.Players.Where(_ => _.PlayerInfo.UID == player.PlayerInfo.UID).Include(_ => _.Loadout.AssignedItems).FirstOrDefault();
                    Player outputPlayer = new Player();
                    //Mapper.CreateMap<WastelandA23.Model.CodeFirstModel.Player, Player>();
                    outputPlayer = Mapper.Map(db_player, outputPlayer);
                    output = Marshaller.marshalFromListBlock(Marshaller.marshalFromObject(outputPlayer));
                    Debug.WriteLine(output);
                }
        }