private static void ConfigureDataLayerNotToLoadClassInfoFromDatabase(IDataLayer dataLayer)
        {
            SimpleObjectLayer objectLayer = new SimpleObjectLayer(dataLayer);
            Dictionary <XPClassInfo, XPObjectType> loadedTypes = new Dictionary <XPClassInfo, XPObjectType>();

            objectLayer.SetObjectLayerWideObjectTypes(loadedTypes);
        }
Beispiel #2
0
        private static IObjectLayer FillObjectLayer(
            IAtlas atlas,
            ObjectGroup objectLayer,
            LayerType layerType,
            Action <GameActor> initializer,
            List <Tileset> tilesets,
            int tileWidth,
            int tileHeight,
            int worldHeight
            )
        {
            List <TmxObject> tmxMapObjects = objectLayer.TmxMapObjects;

            tmxMapObjects.ForEach(x => NormalizeObjectPosition(x, tileWidth, tileHeight, worldHeight));
            tmxMapObjects.ForEach(TransformObjectPosition);

            var simpleObjectLayer = new SimpleObjectLayer(layerType);

            // avatars list
            List <TmxObject> avatars = tmxMapObjects.Where(x => x.Type == "Avatar").ToList();

            foreach (TmxObject avatar in avatars)
            {
                Avatar gameAvatar = LoadAgent(avatar, tilesets);
                initializer.Invoke(gameAvatar);
                simpleObjectLayer.AddGameObject(gameAvatar);
                atlas.AddAvatar(gameAvatar);
            }

            List <TmxObject> others     = tmxMapObjects.Except(avatars).ToList();
            List <TmxObject> characters = others.Where(x => x.Gid != 0).ToList();

            foreach (TmxObject tmxObject in characters)
            {
                Character character = LoadCharacter(tmxObject, tilesets);
                initializer.Invoke(character);
                simpleObjectLayer.AddGameObject(character);
                atlas.Characters.Add(character);
            }
            others = others.Except(characters).ToList();

            // TODO : other objects



            return(simpleObjectLayer);
        }
Beispiel #3
0
        public void import(String filename)
        {
//            CsvEngine engine = new CsvEngine(new CsvOptions("ImportPartyRecord", ';',6));
//            engine.Options.IgnoreFirstLines = 1;
//            Npgsql.NpgsqlConnection con = new Npgsql.NpgsqlConnection("Server=npomash;User Id=pg_adm;Password='******';Database=ermdev;Encoding=UNICODE;");
//            IXpoDataStoreProvider dsp = new ConnectionDataStoreProvider(con);

//            IDbConnection con = PostgreSqlConnectionProvider.CreateConnection("Server=npomash;User Id=pg_adm;Password='******';Database=ermdev;Encoding=UNICODE;");
            IDbConnection con = PostgreSqlConnectionProvider.CreateConnection("Server=alt-dev;User Id=pg_adm;Password='******';Database=ermprod;Encoding=UNICODE;");
//
            IDataLayer   data_layer   = XpoDefault.GetDataLayer(con, AutoCreateOption.None);
            IObjectLayer object_layer = new SimpleObjectLayer(data_layer);
            Int32        count        = 0;

//            ObjectSpaceProvider osp = new ObjectSpaceProvider(dsp);
            //
//            XafApplication application = new ImportApplication();
//            ModuleBase testModule = new ModuleBase();
//            testModule.AdditionalExportedTypes.Add(typeof(crmCParty));
//            testModule.AdditionalExportedTypes.Add(typeof(crmCBusinessman));
//            testModule.AdditionalExportedTypes.Add(typeof(crmCPhysicalParty));
//            testModule.AdditionalExportedTypes.Add(typeof(crmCLegalPerson));
//            application.Modules.Add(testModule);
//            application.Setup("ImportApplication", osp);
//            using (IObjectSpace os = application.CreateObjectSpace()) {
            using (UnitOfWork uow_base = new UnitOfWork(object_layer)) {
                DataTable tbl = (new CsvEngine("ImportPartyRecord", ';', 6)).ReadFileAsDT(filename);
                foreach (DataRow row in tbl.Rows)
                {
                    using (UnitOfWork uow = uow_base.BeginNestedUnitOfWork()) {
                        ImportPartyRecord rec = new ImportPartyRecord();
                        rec.Type = ((String)row.ItemArray[0]).Trim();
                        rec.Code = ((String)row.ItemArray[1]).Trim();
                        rec.INN  = ((String)row.ItemArray[2]).Trim();
                        rec.KPP  = ((String)row.ItemArray[3]).Trim();
                        rec.Name = ((String)row.ItemArray[4]).Trim();
                        rec.Addr = ((String)row.ItemArray[5]).Trim();
                        System.Console.WriteLine(rec.Type + "@" + rec.Code + "@" + rec.INN + "@" + rec.KPP + "@" + rec.Name + "@" + rec.Addr);
                        XPQuery <crmCParty> q_party = new XPQuery <crmCParty>(uow, true);
                        crmCParty           party   = q_party.FirstOrDefault(obj => obj.Code == rec.Code);
                        if (party != null)
                        {
                            continue;
                        }
                        switch (rec.Type)
                        {
                        case "ИП":
                            crmCBusinessman bm = new crmCBusinessman(uow);
                            bm.Code = rec.Code;
                            bm.Name = rec.Name;
                            bm.INN  = rec.INN;
                            bm.AddressLegal.AddressHandmake = rec.Addr;
                            bm.AddressFact.AddressHandmake  = rec.Addr;
                            break;

                        case "ФЛ":
                            crmCPhysicalParty phl = new crmCPhysicalParty(uow);
                            phl.Code = rec.Code;
                            phl.Name = rec.Name;
                            phl.INN  = rec.INN;
                            phl.AddressLegal.AddressHandmake = rec.Addr;
                            phl.AddressFact.AddressHandmake  = rec.Addr;
                            break;

                        default:
                            crmCLegalPerson lp = new crmCLegalPerson(uow);
                            lp.Code = rec.Code;
                            lp.Name = rec.Name;
                            lp.INN  = rec.INN;
                            lp.KPP  = rec.KPP;
                            lp.AddressLegal.AddressHandmake = rec.Addr;
                            lp.AddressFact.AddressHandmake  = rec.Addr;
                            break;
                        }
                        uow.CommitChanges();
                        count++;
                    }
                }
                uow_base.CommitChanges();
                System.Console.WriteLine("All count: " + count);
            }
        }
Beispiel #4
0
        private static IObjectLayer FillObjectLayer(
            IAtlas atlas,
            ObjectGroup objectLayer,
            LayerType layerType,
            Action<GameActor> initializer,
            List<Tileset> tilesets,
            int tileWidth,
            int tileHeight,
            int worldHeight
            )
        {
            List<TmxObject> tmxMapObjects = objectLayer.TmxMapObjects;
            tmxMapObjects.ForEach(x => NormalizeObjectPosition(x, tileWidth, tileHeight, worldHeight));
            tmxMapObjects.ForEach(TransformObjectPosition);

            var simpleObjectLayer = new SimpleObjectLayer(layerType);

            // avatars list
            List<TmxObject> avatars = tmxMapObjects.Where(x => x.Type == "Avatar").ToList();

            foreach (TmxObject avatar in avatars)
            {
                Avatar gameAvatar = LoadAgent(avatar, tilesets);
                initializer.Invoke(gameAvatar);
                simpleObjectLayer.AddGameObject(gameAvatar);
                atlas.AddAvatar(gameAvatar);
            }

            List<TmxObject> others = tmxMapObjects.Except(avatars).ToList();
            List<TmxObject> characters = others.Where(x => x.Gid != 0).ToList();

            foreach (TmxObject tmxObject in characters)
            {
                Character character = LoadCharacter(tmxObject, tilesets);
                initializer.Invoke(character);
                simpleObjectLayer.AddGameObject(character);
                atlas.Characters.Add(character);
            }
            others = others.Except(characters).ToList();

            // TODO : other objects



            return simpleObjectLayer;
        }