Esempio n. 1
0
        private void CreateLogicByType(LogicManagerBase <TContext> logicManager, Type type)
        {
            if (!Maps.ContainsKey(type))
            {
                throw new NotSupportedException($"Not support type {type.Name}");
            }

            //建構組件
            AssemblyBuilder tempAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName()
            {
                Name = "TempAssembly_" + Guid.NewGuid().ToString().Replace('-', '_')
            }, AssemblyBuilderAccess.RunAndCollect);

            //建構模組
            ModuleBuilder tempModuleBuilder = tempAssemblyBuilder
                                              .DefineDynamicModule("TempModule_" + Guid.NewGuid().ToString().Replace('-', '_'));


            var logicType = typeof(LogicBase <, ,>).MakeGenericType(typeof(TContext), type, type.GetProperty(Maps[type]).PropertyType);


            //建構實作介面類別
            TypeBuilder tempTypeBuilder = tempModuleBuilder.DefineType(
                $"Anon_{Guid.NewGuid().ToString().Replace("-", "_")}",
                TypeAttributes.Class,
                logicType, Type.EmptyTypes);

            CreatePassThroughConstructors(tempTypeBuilder, logicType);

            var tempType = tempTypeBuilder.CreateTypeInfo();
            var ctor     = tempType.GetConstructors().Single(x => x.GetParameters().Length > 1 && x.GetParameters()[1].ParameterType == typeof(string));

            runtimeLogicMaps[type]
                = ctor.Invoke(new object[] { logicManager, Maps[type] });
        }
Esempio n. 2
0
 public void Remove(string name)
 {
     if (Maps.ContainsKey(name))
     {
         Maps.Remove(name);
     }
 }
Esempio n. 3
0
        public void Navigate(string name, Intent intent, params string[] parameters)
        {
            var topVc = TopViewController;
            var navVc = topVc.NavigationController;

            if (!Maps.ContainsKey(name))
            {
                throw new KeyNotFoundException(name);
            }
            var  type      = Maps [name];
            bool isPush    = false;
            bool isPresent = false;
            Tuple <MethodInfo, object> convert = null;

            foreach (var item in parameters)
            {
                isPush    |= _toPush == item;
                isPresent |= _toPresent == item;
                convert    = Converts.FirstOrDefault(x => x.Key == item).Value;
            }
            var view = Create(type, intent) as UIViewController;

            if (convert != null)
            {
                view = CreateByConvert <UIViewController> (convert, view);
            }
            if (view == null)
            {
                throw new TypeInitializationException(type.FullName, new Exception("does not initialize"));
            }
            if (intent != null)
            {
                if (isPush && navVc != null)
                {
                    navVc.PushViewController(view, UseAnimated);
                    return;
                }
                if (isPresent)
                {
                    topVc.PresentViewController(view, UseAnimated, null);
                    return;
                }
            }
            if (navVc != null)
            {
                if (navVc.GetType() == view.GetType())
                {
                    throw new ArgumentException("The navigation controller does not push to the navigation controller");
                }
                navVc.PushViewController(view, UseAnimated);
            }
            else
            {
                topVc.PresentViewController(view, UseAnimated, null);
            }
        }
Esempio n. 4
0
        /// <inheritdoc />
        public void RemovePlayer(int characterId)
        {
            Character player;

            if (Players.TryRemove(characterId, out player))
            {
                _logger.LogDebug($"Player {characterId} left game world");

                TradeManagers.TryRemove(characterId, out var tradeManager);
                tradeManager.Dispose();

                PartyManagers.TryRemove(characterId, out var partyManager);
                partyManager.Dispose();

                DuelManagers.TryRemove(characterId, out var duelManager);
                duelManager.Dispose();

                player.Client.OnPacketArrived -= Client_OnPacketArrived;

                IMap map = null;

                // Try find player's map.
                if (Maps.ContainsKey(player.MapId))
                {
                    map = Maps[player.MapId];
                }
                else if (player.Party != null && PartyMaps.ContainsKey(player.Party.Id))
                {
                    map = PartyMaps[player.Party.Id];
                }
                else if (PartyMaps.ContainsKey(player.PreviousPartyId))
                {
                    map = PartyMaps[player.PreviousPartyId];
                }

                if (map is null)
                {
                    _logger.LogError($"Couldn't find character's {characterId} map {player.MapId}.");
                }
                else
                {
                    map.UnloadPlayer(player);
                }

                player.Dispose();
            }
            else
            {
                // 0 means, that connection with client was lost, when he was in character selection screen.
                if (characterId != 0)
                {
                    _logger.LogError($"Couldn't remove player {characterId} from game world");
                }
            }
        }
Esempio n. 5
0
 private static MapEntryBase GetMap(int mapId)
 {
     if (Maps.ContainsKey(mapId))
     {
         return(Maps[mapId]);
     }
     else
     {
         return(Maps[50]); // Return Lions Gate if map isn't available;
     }
 }
Esempio n. 6
0
 public void SetChosenMap(string name)
 {
     if (Maps.ContainsKey(name))
     {
         chosenMap = Maps[name];
     }
     else
     {
         chosenMap = null;
     }
 }
Esempio n. 7
0
 public bool DestroyMap(int mapid)
 {
     lock (Maps)
     {
         if (Maps.ContainsKey(mapid))
         {
             return(Maps.Remove(mapid));
         }
     }
     return(false);
 }
Esempio n. 8
0
 public IMapData GetMapDataForWorld(string i_world)
 {
     if (Maps.ContainsKey(i_world))
     {
         return(Maps[i_world]);
     }
     else
     {
         EasyLogger.Instance.Log(LogTypes.Fatal, "No map data for world: " + i_world, "");
         return(new MapData());
     }
 }
        public Map LookupMap(string id, out string errMsg)
        {
            errMsg = string.Empty;
            var idd = id.NormalizeId();

            if (!Maps.ContainsKey(idd))
            {
                errMsg = string.Format(Constants.Instance.ErrorMessage.Cant_Find_Map, id);
                return(null);
            }
            return(Maps[idd]);
        }
 public void RegisterMap(Map map)
 {
     if (string.IsNullOrWhiteSpace(map.Id))
     {
         throw new Exception(Constants.Instance.ErrorMessage.Cant_Create_Map_Without_Id);
     }
     if (Maps.ContainsKey(map.Id))
     {
         throw new Exception(Constants.Instance.ErrorMessage.Duplicate_Map_Id_Detected);
     }
     Maps.Add(map.Id, map);
 }
Esempio n. 11
0
        private void QueueTimer(object sender)
        {
            try
            {
                int Number = Queue.Count <= 12 ? Queue.Count : 12;
                for (int i = 0; i < Number; i++)
                {
                    xCoreLevel[] ls = GetArenas();
                    if (ls.Count() >= 1)
                    {
                        Player player;
                        if (Queue.TryDequeue(out player))
                        {
                            if (player != null)
                            {
                                if (!((xPlayer)player).isFindingGame)
                                {
                                    lock (((xPlayer)player).isFindingGameSync)
                                        ((xPlayer)player).isFindingGame = true;
                                    lock (ls[0]._playerQueueLock)
                                        ls[0].TempPlayers.TryAdd(player, player);
                                    player.IsSpectator = false;
                                    player.SetAllowFly(false);
                                    Task.Run(delegate { player.SpawnLevel(ls[0], null, true); });
                                }
                            }
                        }
                    }
                }

                xCoreLevel[] Arena = GetArenas();
                if (Arena.Count() == 0)
                {
                    Random rand = new Random();
                    string map  = Maps.Keys.ElementAt(rand.Next(0, Maps.Keys.Count - 1));
                    if (Maps.ContainsKey(map))
                    {
                        NewArena(Maps[map]);
                    }
                }
                else if (Arena.Count() >= 5 && Levels.Count() >= 15)
                {
                    RemoveArena(Arena.Last());
                }
            }
            catch (Exception e)
            {
                Log.Error("Game on " + Game.NameGame, e);
                Log.Info("Game on " + Game.NameGame, e);
            }
        }
Esempio n. 12
0
 protected void AddMap()
 {
     MapPath = "./wwwroot/MapTemplates\\" + MapTemplate.Name;
     if (Maps.ContainsKey(MapPath))
     {
         ShowMessage = true;
         message     = "Map with this name already exists.";
         StateHasChanged();
     }
     else
     {
         SaveMap();
     }
 }
Esempio n. 13
0
        /// <inheritdoc />
        public void LoadPlayerInMap(int characterId)
        {
            var player = Players[characterId];

            if (Maps.ContainsKey(player.MapId))
            {
                Maps[player.MapId].LoadPlayer(player);
            }
            else
            {
                var mapDef = _mapDefinitions.Maps.FirstOrDefault(d => d.Id == player.MapId);

                // Map is not found.
                if (mapDef is null)
                {
                    _logger.LogWarning($"Unknown map {player.MapId} for character {player.Id}. Fallback to 0 map.");
                    var town = Maps[0].GetNearestSpawn(player.PosX, player.PosY, player.PosZ, player.Country);
                    player.Teleport(0, town.X, town.Y, town.Z);
                    return;
                }

                if (mapDef.CreateType == CreateType.Party)
                {
                    IPartyMap map;
                    Guid      partyId;

                    if (player.Party is null)
                    // This is very uncommon, but if:
                    // * player is an admin he can load into map even without party.
                    // * player entered portal, while being in party, but while he was loading, all party members left.
                    {
                        partyId = player.PreviousPartyId;
                    }
                    else
                    {
                        partyId = player.Party.Id;
                    }

                    PartyMaps.TryGetValue(partyId, out map);
                    if (map is null)
                    {
                        map = _mapFactory.CreatePartyMap(mapDef.Id, mapDef, _mapsLoader.LoadMapConfiguration(mapDef.Id), player.Party);
                        map.OnAllMembersLeft += PartyMap_OnAllMembersLeft;
                        PartyMaps.TryAdd(partyId, map);
                    }

                    map.LoadPlayer(player);
                }
            }
        }
Esempio n. 14
0
 private void LoadMaps(string directoryPath)
 {
     if (Directory.Exists(directoryPath))
     {
         string[]    paths = Directory.GetFiles(directoryPath);
         MapTemplate map;
         foreach (var path in paths)
         {
             if (!Maps.ContainsKey(path))
             {
                 map = ReadFromFile(path);
                 Maps.Add(path, map);
             }
         }
     }
 }
Esempio n. 15
0
        public Boolean BuiltInMapExists(UInt32 checksum, String name)
        {
            if (Maps == null)
            {
                return(false);
            }

            if (!Maps.ContainsKey(checksum))
            {
                return(false);
            }

            if (name == (String)Maps[checksum])
            {
                return(true);
            }

            return(false);
        }
Esempio n. 16
0
 protected void RemoveMap()
 {
     if (!String.IsNullOrEmpty(MapPath))
     {
         if (Maps.ContainsKey(MapPath))
         {
             Maps.Remove(MapPath);
             if (File.Exists(MapPath))
             {
                 File.Delete(MapPath);
                 MapPath = null;
             }
         }
     }
     else
     {
         CreateMapTemplate();
     }
 }
        public void AddLicence(string licenceKey, Action <LicenceBuilder> configureBuilder)
        {
            if (string.IsNullOrWhiteSpace(licenceKey))
            {
                throw new ArgumentNullException(nameof(licenceKey));
            }
            if (licenceKey == SA.LicenceKey)
            {
                throw new InvalidOperationException("licenseKey already exists: " + licenceKey);
            }
            if (Maps.ContainsKey(licenceKey))
            {
                throw new InvalidOperationException("licenseKey already exists: " + licenceKey);
            }
            var builder = new LicenceBuilder(licenceKey);

            configureBuilder(builder);
            Maps.Add(licenceKey, builder);
        }
        public void AddLicence(string licenceKey, string displayName = null, string description = null)
        {
            if (string.IsNullOrWhiteSpace(licenceKey))
            {
                throw new ArgumentNullException(nameof(licenceKey));
            }
            if (licenceKey == SA.LicenceKey)
            {
                throw new InvalidOperationException("licenseKey already exists: " + licenceKey);
            }
            if (Maps.ContainsKey(licenceKey))
            {
                throw new InvalidOperationException("licenseKey already exists: " + licenceKey);
            }
            var builder = new LicenceBuilder(licenceKey, displayName)
            {
                Description = description
            };

            Maps.Add(licenceKey, builder);
        }
Esempio n. 19
0
        /// <inheritdoc />
        public void LoadPlayerInMap(int characterId)
        {
            var player = Players[characterId];

            if (Maps.ContainsKey(player.MapId))
            {
                Maps[player.MapId].LoadPlayer(player);
            }
            else
            {
                var mapDef = _mapDefinitions.Maps.FirstOrDefault(d => d.Id == player.MapId);

                // Map is not found.
                if (mapDef is null)
                {
                    _logger.LogWarning($"Unknown map {player.MapId} for character {player.Id}. Fallback to 0 map.");
                    var town = Maps[0].GetNearestSpawn(player.PosX, player.PosY, player.PosZ, player.Country);
                    player.Teleport(0, town.X, town.Y, town.Z);
                    return;
                }
            }
        }
Esempio n. 20
0
 protected void SaveMap()
 {
     if (!String.IsNullOrEmpty(MapPath) && MapPath != "./wwwroot/MapTemplates\\" + MapTemplate.Name)
     {
         if (File.Exists(MapPath))
         {
             File.Delete(MapPath);
             if (Maps.ContainsKey(MapPath))
             {
                 Maps.Remove(MapPath);
             }
             MapPath = null;
         }
     }
     MapPath = String.IsNullOrEmpty(MapPath) ? ("./wwwroot/MapTemplates\\" + MapTemplate.Name) : MapPath;
     IOModule.WriteToBinaryFile <MapTemplate>(MapPath, MapTemplate);
     if (!Maps.ContainsKey(MapPath))
     {
         Maps.Add(MapPath, MapTemplate);
     }
     message     = "Map successfully modiffied.";
     ShowMessage = true;
 }
Esempio n. 21
0
        internal TransformMetaData FindFirstMapMatch(ContextProperty property, string messageType)
        {
            string[]          mapsArray = _mapName.Split(new char[] { '|' }, StringSplitOptions.None);
            TransformMetaData mapMatch  = null;

            //Check Cache
            if (Maps.ContainsKey(messageType))
            {
                for (int i = 0; i < mapsArray.Length; i++)
                {
                    if (Maps[messageType].TryGetValue(mapsArray[i], out mapMatch) == true)
                    {
                        return(mapMatch);
                    }
                }
            }
            else
            {
                //Add cache for this messagetype
                Maps.TryAdd(messageType, new ConcurrentDictionary <string, TransformMetaData>());
            }

            //Check MapCache
            for (int i = 0; i < mapsArray.Length; i++)
            {
                try
                {
                    //When map exists in the same assembly as the pipeline you do not need to specify assembly
                    if (mapsArray[i].Contains(",") == false)
                    {
                        mapsArray[i] = String.Format("{0}, {1}", mapsArray[i], pipelineAssembly);
                    }

                    Type mapType = Type.GetType(mapsArray[i], true);

                    mapMatch = TransformMetaData.For(mapType);

                    SchemaMetadata sourceSchema = mapMatch.SourceSchemas[0];



                    if (property.PropertyName == "SchemaStrongName")
                    {
                        if (sourceSchema.ReflectedType.AssemblyQualifiedName == messageType)
                        {
                            Maps[messageType].TryAdd(mapsArray[i], mapMatch);
                            break;
                        }
                    }
                    else if (property.PropertyName == "MessageType" && sourceSchema.SchemaName == messageType)
                    {
                        Maps[messageType].TryAdd(mapsArray[i], mapMatch);
                        break;
                    }

                    mapMatch = null;
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(string.Format("Error while trying to load MapType specification: {0}", mapsArray[i]), ex);
                }
            }

            return(mapMatch);
        }
Esempio n. 22
0
 public AuthoryMap GetMap(int reqeustedMapIndex)
 {
     return(Maps.ContainsKey(reqeustedMapIndex) ? Maps[reqeustedMapIndex] : null);
 }
Esempio n. 23
0
 public bool IsMapLoaded(int mapId)
 {
     return(Maps.ContainsKey(mapId));
 }
Esempio n. 24
0
        public MapleMap GetMap(int mapid)
        {
            var      omapid = mapid;
            MapleMap map;

            if (!Maps.TryGetValue(omapid, out map))
            {
                lock (this)
                {
                    // check if someone else who was also synchronized has loaded the map already
                    if (Maps.ContainsKey(omapid))
                    {
                        return(Maps[omapid]);
                    }
                    var mapName = GetMapName(mapid);
                    var mapData = m_mSource.GetData(mapName);
                    var link    = MapleDataTool.GetString(mapData.GetChildByPath("info/link"), "");
                    if (!link.Equals(""))
                    {
                        mapName = GetMapName(int.Parse(link));
                        mapData = m_mSource.GetData(mapName);
                    }
                    float monsterRate = 0;
                    var   mobRate     = mapData.GetChildByPath("info/mobRate");
                    if (mobRate != null)
                    {
                        monsterRate = (float)mobRate.Data;
                    }
                    map = new MapleMap(mapid, ChannelId, MapleDataTool.GetInt("info/returnMap", mapData), monsterRate)
                    {
                        OnFirstUserEnter = MapleDataTool.GetString(mapData.GetChildByPath("info/onFirstUserEnter"),
                                                                   mapid.ToString()),
                        OnUserEnter = MapleDataTool.GetString(mapData.GetChildByPath("info/onUserEnter"),
                                                              mapid.ToString()),
                        TimeMobId      = MapleDataTool.GetInt(mapData.GetChildByPath("info/timeMob/id"), -1),
                        TimeMobMessage = MapleDataTool.GetString(mapData.GetChildByPath("info/timeMob/message"), "")
                    };

                    var portalFactory = new PortalFactory();
                    foreach (var portal in mapData.GetChildByPath("portal"))
                    {
                        var portalresult =
                            portalFactory.MakePortal((PortalType)MapleDataTool.GetInt(portal.GetChildByPath("pt")),
                                                     portal);
                        map.Portals.Add(portalresult.PortalId, portalresult);
                    }
                    var allFootholds = new List <MapleFoothold>();

                    var lBound = new Point();
                    var uBound = new Point();
                    foreach (var footRoot in mapData.GetChildByPath("foothold"))
                    {
                        foreach (var footCat in footRoot)
                        {
                            foreach (var footHold in footCat)
                            {
                                var x1 = MapleDataTool.GetInt(footHold.GetChildByPath("x1"));
                                var y1 = MapleDataTool.GetInt(footHold.GetChildByPath("y1"));
                                var x2 = MapleDataTool.GetInt(footHold.GetChildByPath("x2"));
                                var y2 = MapleDataTool.GetInt(footHold.GetChildByPath("y2"));
                                var fh = new MapleFoothold(new Point(x1, y1), new Point(x2, y2),
                                                           int.Parse(footHold.Name));
                                fh.PrevFootholdId = MapleDataTool.GetInt(footHold.GetChildByPath("prev"));
                                fh.NextFootholdId = MapleDataTool.GetInt(footHold.GetChildByPath("next"));

                                if (fh.Point1.X < lBound.X)
                                {
                                    lBound.X = fh.Point1.X;
                                }
                                if (fh.Point2.X > uBound.X)
                                {
                                    uBound.X = fh.Point2.X;
                                }
                                if (fh.Point1.Y < lBound.Y)
                                {
                                    lBound.Y = fh.Point1.Y;
                                }
                                if (fh.Point2.Y > uBound.Y)
                                {
                                    uBound.Y = fh.Point2.Y;
                                }
                                allFootholds.Add(fh);
                            }
                        }
                    }

                    var fTree = new MapleFootholdTree(lBound, uBound);
                    foreach (var fh in allFootholds)
                    {
                        fTree.Insert(fh);
                    }
                    map.Footholds = fTree;

                    // load areas (EG PQ platforms)
                    if (mapData.GetChildByPath("area") != null)
                    {
                        foreach (var area in mapData.GetChildByPath("area"))
                        {
                            var x1      = MapleDataTool.GetInt(area.GetChildByPath("x1"));
                            var y1      = MapleDataTool.GetInt(area.GetChildByPath("y1"));
                            var x2      = MapleDataTool.GetInt(area.GetChildByPath("x2"));
                            var y2      = MapleDataTool.GetInt(area.GetChildByPath("y2"));
                            var mapArea = new Rectangle(x1, y1, x2 - x1, y2 - y1);
                            map.Areas.Add(mapArea);
                        }
                    }

                    // load life data (npc, monsters)
                    foreach (var life in mapData.GetChildByPath("life"))
                    {
                        var id           = MapleDataTool.GetString(life.GetChildByPath("id"));
                        var type         = MapleDataTool.GetString(life.GetChildByPath("type"));
                        var myLife       = LoadLife(life, id, type);
                        var mapleMonster = myLife as MapleMonster;
                        if (mapleMonster != null)
                        {
                            var monster = mapleMonster;
                            var mobTime = MapleDataTool.GetInt("mobTime", life, 0);
                            if (mobTime == -1)
                            {
                                //does not respawn, force spawn once
                                map.SpawnMonster(monster);
                            }
                            else
                            {
                                map.AddMonsterSpawn(monster, mobTime);
                            }
                        }
                        else
                        {
                            map.AddMapObject(myLife);
                        }
                    }

                    //load reactor data
                    if (mapData.GetChildByPath("reactor") != null)
                    {
                        foreach (var reactor in mapData.GetChildByPath("reactor"))
                        {
                            var id = MapleDataTool.GetString(reactor.GetChildByPath("id"));
                            if (id != null)
                            {
                                var newReactor = LoadReactor(reactor, id);
                                map.SpawnReactor(newReactor);
                            }
                        }
                    }

                    //try
                    //{
                    map.MapName = MapleDataTool.GetString("mapName", m_mNameData.GetChildByPath(GetMapStringName(omapid)),
                                                          "");
                    map.StreetName = MapleDataTool.GetString("streetName",
                                                             m_mNameData.GetChildByPath(GetMapStringName(omapid)), "");
                    //}
                    //catch
                    //{
                    //map.MapName = "";
                    //map.StreetName = "";
                    //}

                    map.Clock             = mapData.GetChildByPath("clock") != null;
                    map.Everlast          = mapData.GetChildByPath("everlast") != null;
                    map.Town              = mapData.GetChildByPath("town") != null;
                    map.AllowShops        = MapleDataTool.GetInt(mapData.GetChildByPath("info/personalShop"), 0) == 1;
                    map.DecHp             = MapleDataTool.ConvertToInt("decHP", mapData, 0);
                    map.ProtectItem       = MapleDataTool.ConvertToInt("protectItem", mapData, 0);
                    map.ForcedReturnMapId = MapleDataTool.GetInt(mapData.GetChildByPath("info/forcedReturn"), 999999999);
                    map.OnFirstUserEnter  = MapleDataTool.GetString(mapData.GetChildByPath("info/onFirstUserEnter"), "");
                    map.OnUserEnter       = MapleDataTool.GetString(mapData.GetChildByPath("info/onUserEnter"), "");

                    map.HasBoat = mapData.GetChildByPath("shipObj") != null;


                    map.FieldLimit = MapleDataTool.GetInt(mapData.GetChildByPath("info/fieldLimit"), 0);
                    map.TimeLimit  = MapleDataTool.ConvertToInt("timeLimit", mapData.GetChildByPath("info"), -1);
                    map.FieldType  = MapleDataTool.ConvertToInt("info/fieldType", mapData, 0);
                    Maps.Add(omapid, map);

                    //try
                    //{
                    //    PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM spawns WHERE mid = ?");
                    //    ps.setInt(1, omapid);
                    //    ResultSet rs = ps.executeQuery();
                    //    while (rs.next())
                    //    {
                    //        int id = rs.getInt("idd");
                    //        int f = rs.getInt("f");
                    //        bool hide = false;
                    //        string type = rs.getString("type");
                    //        int fh = rs.getInt("fh");
                    //        int cy = rs.getInt("cy");
                    //        int rx0 = rs.getInt("rx0");
                    //        int rx1 = rs.getInt("rx1");
                    //        int x = rs.getInt("x");
                    //        int y = rs.getInt("y");
                    //        int mobTime = rs.getInt("mobtime");
                    //        AbstractLoadedMapleLife myLife = loadLife(id, f, hide, fh, cy, rx0, rx1, x, y, type);
                    //        if (type.equals("n"))
                    //        {
                    //            map.addMapObject(myLife);
                    //        }
                    //        else if (type.equals("m"))
                    //        {
                    //            MapleMonster monster = (MapleMonster)myLife;
                    //            map.addMonsterSpawn(monster, mobTime);
                    //        }
                    //    }
                    //}
                    //catch (SQLException e)
                    //{
                    //    log.info(e.toString());
                    //}
                }
            }
            return(map);
        }
        /// <summary>
        /// This method transfers module defined parameters, maps, connections, and actions into a process.
        /// This is used to consolidate such things for easier maintenance.
        /// </summary>
        /// <param name="process">the transformalize process</param>
        public void ApplyCommonSettings(Process process)
        {
            // common parameters
            for (int i = 0; i < process.Parameters.Count; i++)
            {
                var parameter = process.Parameters[i];
                if (Parameters.ContainsKey(parameter.Name) && string.IsNullOrEmpty(parameter.Value) && parameter.T == string.Empty && !parameter.Transforms.Any() && parameter.V == string.Empty && !parameter.Validators.Any())
                {
                    process.Parameters[0] = Parameters[parameter.Name];
                }
            }

            // common maps
            for (int i = 0; i < process.Maps.Count; i++)
            {
                var map = process.Maps[i];
                if (Maps.ContainsKey(map.Name) && !map.Items.Any() && map.Query == string.Empty)
                {
                    process.Maps[i] = Maps[map.Name];
                }
            }

            // common actions
            for (int i = 0; i < process.Actions.Count; i++)
            {
                var action = process.Actions[i];
                if (action.Name != null && Actions.ContainsKey(action.Name) && action.Type == "internal")
                {
                    var key = action.Key;
                    process.Actions[i]     = Actions[action.Name];
                    process.Actions[i].Key = key;
                }
            }

            // common connections
            for (int i = 0; i < process.Connections.Count; i++)
            {
                var connection = process.Connections[i];
                if (connection.Provider == Transformalize.Constants.DefaultSetting)
                {
                    if (Connections.ContainsKey(connection.Name))
                    {
                        var key   = connection.Key;
                        var table = connection.Table;
                        process.Connections[i]       = Connections[connection.Name];
                        process.Connections[i].Key   = key;
                        process.Connections[i].Table = table;
                    }
                    else if (connection.Name == "orchard")
                    {
                        using (var cn = _dbConnectionAccessor.CreateConnection()) {
                            connection.ConnectionString = cn.ConnectionString;
                            connection.Provider         = _store.Dialect.Name.ToLower();
                        }
                    }
                }
            }

            // common fields
            if (Fields.Any() && process.Entities.Any())
            {
                for (int x = 0; x < process.Entities.Count; x++)
                {
                    var entity = process.Entities[x];

                    for (int y = 0; y < entity.Fields.Count; y++)
                    {
                        var field = process.Entities[x].Fields[y];

                        if (Fields.ContainsKey(field.Name) && !field.System && !field.Input && !field.Transforms.Any() && !field.Validators.Any())
                        {
                            var index       = field.Index;
                            var masterIndex = field.MasterIndex;
                            process.Entities[x].Fields[y]             = Fields[field.Name];
                            process.Entities[x].Fields[y].Index       = index;
                            process.Entities[x].Fields[y].MasterIndex = masterIndex;
                        }
                    }

                    for (int y = 0; y < entity.CalculatedFields.Count; y++)
                    {
                        var field = process.Entities[x].CalculatedFields[y];

                        if (Fields.ContainsKey(field.Name) && !field.System && !field.Input && !field.Transforms.Any() && !field.Validators.Any())
                        {
                            var index       = field.Index;
                            var masterIndex = field.MasterIndex;
                            process.Entities[x].CalculatedFields[y]             = Fields[field.Name];
                            process.Entities[x].CalculatedFields[y].Index       = index;
                            process.Entities[x].CalculatedFields[y].MasterIndex = masterIndex;
                        }
                    }
                }
            }
        }
Esempio n. 26
0
        void LoadMaps(params string[] fileNames)
        {
            var items = new Dictionary <string, ListViewItem>();

            foreach (string f in fileNames)
            {
                items[f] = lvMaps.Items.Add(Path.GetFileName(f), "Loading");
            }

            bConvertAll.Enabled      = false;
            bConvertSelected.Enabled = false;

            Task.Run(() =>
            {
                foreach (string f in fileNames)
                {
                    MapsLoading.Add(f);

                    var containsMap = false;
                    try
                    {
                        var gbx = IslandConverter.LoadGBX(f, out TimeSpan? completionTime);

                        if (gbx != null)
                        {
                            containsMap = false;

                            var map    = gbx.MainNode;
                            var mapUid = map.MapUid;

                            if (Maps.ContainsKey(mapUid))
                            {
                                containsMap = true;
                            }

                            if (!Maps.ContainsKey(mapUid))
                            {
                                Maps.Add(mapUid, gbx);
                            }

                            Invoke(new Action(() =>
                            {
                                ListViewItem item = items[f];

                                item.Name = mapUid;

                                if (gbx.MainNode.Thumbnail == null)
                                {
                                    item.ImageKey = "";
                                }
                                else
                                {
                                    lvMaps.LargeImageList.Images.Add(mapUid, gbx.MainNode.GetThumbnailBitmap());
                                    item.ImageKey = mapUid;
                                }

                                item.Text = Formatter.Deformat(map.MapName);
                            }));
                        }
                        else
                        {
                            containsMap = true;
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Write(e.ToString());
                        MessageBox.Show(e.ToString(), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    Invoke(new Action(() =>
                    {
                        ListViewItem item = items[f];

                        UpdateSelectedMap();
                        if (containsMap)
                        {
                            item.Remove();
                        }
                    }));

                    MapsLoading.RemoveAll(x => x == f);
                }

                Invoke(new Action(() =>
                {
                    if (MapsLoading.Count == 0 && Maps.Count > 0)
                    {
                        bConvertAll.Enabled = true;
                    }
                }));
            });
        }