Exemplo n.º 1
0
        private bool PingEnabledRegions()
        {
            if (this.EnabledRegions == null || this.EnabledRegions.Count == 0)
            {
                //TODO: log
                //Debug.LogError("No regions available. Maybe all got filtered out or the AppId is not correctly configured.");
                return(false);
            }

            if (this.pingerList == null)
            {
                this.pingerList = new List <RegionPinger>();
            }
            else
            {
                lock (this.pingerList)
                {
                    this.pingerList.Clear();
                }
            }

            lock (this.pingerList)
            {
                foreach (Region region in this.EnabledRegions)
                {
                    RegionPinger rp = new RegionPinger(region, this.OnRegionDone);
                    this.pingerList.Add(rp);
                    rp.Start(); // TODO: check return value
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private bool PingEnabledRegions()
        {
            if (this.EnabledRegions == null || this.EnabledRegions.Count == 0)
            {
                //TODO: log
                //Debug.LogError("No regions available. Maybe all got filtered out or the AppId is not correctly configured.");
                return(false);
            }

            this.pingerList = new List <RegionPinger>();
            foreach (Region region in this.EnabledRegions)
            {
                RegionPinger rp = new RegionPinger(region, this.OnRegionDone);
                this.pingerList.Add(rp);
                #if PING_VIA_COROUTINE
                rp.Start(this.connectionHandler); // TODO: check return value
                #else
                rp.Start();                       // TODO: check return value
                #endif
            }

            return(true);
        }
Exemplo n.º 3
0
        public bool PingMinimumOfRegions(Action <RegionHandler> onCompleteCallback, string previousSummary)
        {
            if (this.EnabledRegions == null || this.EnabledRegions.Count == 0)
            {
                //TODO: log error
                //Debug.LogError("No regions available. Maybe all got filtered out or the AppId is not correctly configured.");
                return(false);
            }

            if (this.IsPinging)
            {
                //TODO: log warning
                //Debug.LogWarning("PingMinimumOfRegions() skipped, because this RegionHander is already pinging some regions.");
                return(false);
            }

            this.IsPinging               = true;
            this.onCompleteCall          = onCompleteCallback;
            this.previousSummaryProvided = previousSummary;

            if (string.IsNullOrEmpty(previousSummary))
            {
                return(this.PingEnabledRegions());
            }

            string[] values = previousSummary.Split(';');
            if (values.Length < 3)
            {
                return(this.PingEnabledRegions());
            }

            int  prevBestRegionPing;
            bool secondValueIsInt = Int32.TryParse(values[1], out prevBestRegionPing);

            if (!secondValueIsInt)
            {
                return(this.PingEnabledRegions());
            }

            string prevBestRegionCode       = values[0];
            string prevAvailableRegionCodes = values[2];


            if (string.IsNullOrEmpty(prevBestRegionCode))
            {
                return(this.PingEnabledRegions());
            }
            if (string.IsNullOrEmpty(prevAvailableRegionCodes))
            {
                return(this.PingEnabledRegions());
            }
            if (!this.availableRegionCodes.Equals(prevAvailableRegionCodes) || !this.availableRegionCodes.Contains(prevBestRegionCode))
            {
                return(this.PingEnabledRegions());
            }
            if (prevBestRegionPing >= RegionPinger.PingWhenFailed)
            {
                return(this.PingEnabledRegions());
            }

            // let's check only the preferred region to detect if it's still "good enough"
            this.previousPing = prevBestRegionPing;

            Region       preferred    = this.EnabledRegions.Find(r => r.Code.Equals(prevBestRegionCode));
            RegionPinger singlePinger = new RegionPinger(preferred, this.OnPreferredRegionPinged);

            #if PING_VIA_COROUTINE
            singlePinger.Start(this.connectionHandler);
            #else
            singlePinger.Start();
            #endif
            return(true);
        }