Ejemplo n.º 1
0
        private static WcfServiceClient GetWcfClient(RequestSettings setting)
        {
            WcfServiceClient wcfClient = WcfServiceClientManager.Current.Get(setting.GameId, setting.ServerId);

            if (wcfClient == null)
            {
                throw new KeyNotFoundException(string.Format("Not found setting for game:{0} server:{1}", setting.GameId, setting.ServerId));
            }
            return(wcfClient);
        }
Ejemplo n.º 2
0
        private static bool DoCall(RequestSettings setting, out byte[] buffer, bool isRoute = false)
        {
            buffer = new byte[0];
            WcfServiceClient wcfClient = GetWcfClient(setting);

            if (wcfClient.Connect())
            {
                if (isRoute)
                {
                    return(wcfClient.TryCallRemote(setting.RouteName, setting.ParamString, setting.RemoteAddress, out buffer));
                }
                return(wcfClient.TryRequest(setting.ParamString, setting.RemoteAddress, out buffer));
            }
            return(false);
        }
Ejemplo n.º 3
0
 private void BindWcfConection(string ip, int port, int timeout, WcfServiceClient client, int receiveTimeout, int inactivityTimeout)
 {
     if (timeout > 0 && receiveTimeout > 0 && inactivityTimeout > 0)
     {
         client.Bind(ip, port, _receivedCallback, timeout, new TimeSpan(0, 0, receiveTimeout), inactivityTimeout);
     }
     else if (timeout > 0 && inactivityTimeout > 0)
     {
         client.Bind(ip, port, _receivedCallback, timeout, TimeSpan.MaxValue, inactivityTimeout);
     }
     else if (timeout > 0)
     {
         client.Bind(ip, port, _receivedCallback, timeout);
     }
     else
     {
         client.Bind(ip, port, _receivedCallback);
     }
 }
Ejemplo n.º 4
0
        private void ParaseConfig(string moduleName)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(moduleName);
                var childList = xmlDoc.SelectNodes("//connection");
                if (childList == null || _pools == null)
                {
                    return;
                }
                HashSet <int> keys = new HashSet <int>();
                var           er   = _pools.Keys.GetEnumerator();
                while (er.MoveNext())
                {
                    keys.Add(er.Current);
                }

                foreach (var child in childList)
                {
                    XmlElement el = child as XmlElement;
                    if (el == null)
                    {
                        continue;
                    }
                    int    gameid            = el.GetAttribute("gameid").ToInt();
                    int    serverid          = el.GetAttribute("serverid").ToInt();
                    string ip                = el.GetAttribute("ip");
                    int    port              = el.GetAttribute("port").ToInt();
                    int    timeout           = el.GetAttribute("connectTimeout").ToInt();
                    int    receiveTimeout    = el.GetAttribute("receiveTimeout").ToInt();
                    int    inactivityTimeout = el.GetAttribute("inactivityTimeout").ToInt();
                    int    identityId        = ToIdentityId(gameid, serverid);
                    //过滤Key
                    keys.Remove(identityId);
                    TraceLog.ReleaseWrite("Load wcfclient config:{0},ip:{1}:{2}", identityId, ip, port);
                    WcfServiceClient client;
                    try
                    {
                        if (!_pools.TryGetValue(identityId, out client))
                        {
                            client = new WcfServiceClient(identityId);
                            BindWcfConection(ip, port, timeout, client, receiveTimeout, inactivityTimeout);
                            _pools.TryAdd(identityId, client);
                        }
                        else if (client.Ip != ip ||
                                 client.Port != port ||
                                 (timeout > 0 && client.ConnectTimeout.TotalSeconds != (double)timeout))
                        {
                            BindWcfConection(ip, port, timeout, client, receiveTimeout, inactivityTimeout);
                        }
                    }
                    catch (Exception se)
                    {
                        TraceLog.WriteError("Binding wcfclient-{0} error:{0}", identityId, se);
                    }
                }

                //remove key
                foreach (var key in keys)
                {
                    WcfServiceClient client;
                    if (_pools.TryRemove(key, out client))
                    {
                        client.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("ParaseConfig error:{0}", ex);
            }
        }
Ejemplo n.º 5
0
        private void ParaseConfig(string moduleName)
        {
            try
            {

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(moduleName);
                var childList = xmlDoc.SelectNodes("//connection");
                if (childList == null || _pools == null)
                {
                    return;
                }
                HashSet<int> keys = new HashSet<int>();
                var er = _pools.Keys.GetEnumerator();
                while (er.MoveNext())
                {
                    keys.Add(er.Current);
                }

                foreach (var child in childList)
                {
                    XmlElement el = child as XmlElement;
                    if (el == null)
                    {
                        continue;
                    }
                    int gameid = el.GetAttribute("gameid").ToInt();
                    int serverid = el.GetAttribute("serverid").ToInt();
                    string ip = el.GetAttribute("ip");
                    int port = el.GetAttribute("port").ToInt();
                    int timeout = el.GetAttribute("connectTimeout").ToInt();
                    int receiveTimeout = el.GetAttribute("receiveTimeout").ToInt();
                    int inactivityTimeout = el.GetAttribute("inactivityTimeout").ToInt();
                    int identityId = ToIdentityId(gameid, serverid);
                    //过滤Key
                    keys.Remove(identityId);
                    TraceLog.ReleaseWrite("Load wcfclient config:{0},ip:{1}:{2}", identityId, ip, port);
                    WcfServiceClient client;
                    try
                    {
                        if (!_pools.TryGetValue(identityId, out client))
                        {
                            client = new WcfServiceClient(identityId);
                            BindWcfConection(ip, port, timeout, client, receiveTimeout, inactivityTimeout);
                            _pools.TryAdd(identityId, client);
                        }
                        else if (client.Ip != ip ||
                            client.Port != port ||
                            (timeout > 0 && client.ConnectTimeout.TotalSeconds != (double)timeout))
                        {
                            BindWcfConection(ip, port, timeout, client, receiveTimeout, inactivityTimeout);
                        }
                    }
                    catch (Exception se)
                    {
                        TraceLog.WriteError("Binding wcfclient-{0} error:{0}", identityId, se);
                    }
                }

                //remove key
                foreach (var key in keys)
                {
                    WcfServiceClient client;
                    if (_pools.TryRemove(key, out client))
                    {
                        client.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("ParaseConfig error:{0}", ex);
            }
        }
Ejemplo n.º 6
0
 private void BindWcfConection(string ip, int port, int timeout, WcfServiceClient client, int receiveTimeout, int inactivityTimeout)
 {
     if (timeout > 0 && receiveTimeout > 0 && inactivityTimeout > 0)
     {
         client.Bind(ip, port, _receivedCallback, timeout, new TimeSpan(0, 0, receiveTimeout), inactivityTimeout);
     }
     else if (timeout > 0 && inactivityTimeout > 0)
     {
         client.Bind(ip, port, _receivedCallback, timeout, TimeSpan.MaxValue, inactivityTimeout);
     }
     else if (timeout > 0)
     {
         client.Bind(ip, port, _receivedCallback, timeout);
     }
     else
     {
         client.Bind(ip, port, _receivedCallback);
     }
 }
Ejemplo n.º 7
0
        private void ParaseConfig(string moduleName)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(moduleName);
            var childList = xmlDoc.SelectNodes("//connection");
            if (childList == null)
            {
                return;
            }
            _pools.Clear();

            foreach (var child in childList)
            {
                XmlElement el = child as XmlElement;
                if (el == null)
                {
                    continue;
                }
                int gameid = el.GetAttribute("gameid").ToInt();
                int serverid = el.GetAttribute("serverid").ToInt();
                string ip = el.GetAttribute("ip");
                int port = el.GetAttribute("port").ToInt();
                int identityId = ToIdentityId(gameid, serverid);
                WcfServiceClient oldValue;
                if (_pools.TryRemove(identityId, out oldValue))
                {
                    oldValue.Dispose();
                }
                var client = new WcfServiceClient(ip, port, identityId);
                _pools.TryAdd(identityId, client);
            }
        }