protected void BasePublish <T>(string exchangeType, string routingKey, params T[] msgs)
        {
            var channel = channelPool.Rent();

            try
            {
                if (!string.IsNullOrEmpty(__exchangeName))
                {
                    channel.ExchangeDeclare(__exchangeName, exchangeType, false, false, null);
                }
                foreach (var msg in msgs)
                {
                    var sendBytes = Encoding.UTF8.GetBytes(msg.ToJson());
                    channel.BasicPublish(__exchangeName, routingKey, __basicProperties, sendBytes);
                }
            }
            catch (Exception ero)
            {
                throw ero;
            }
            finally
            {
                channelPool.Return(channel);
            }
        }
Beispiel #2
0
        public void UpdateAllSustainerScopes()
        {
            playingPerDef.Clear();
            for (int i = 0; i < allSustainers.Count; i++)
            {
                Sustainer sustainer = allSustainers[i];
                if (!playingPerDef.ContainsKey(sustainer.def))
                {
                    List <Sustainer> list = SimplePool <List <Sustainer> > .Get();

                    list.Add(sustainer);
                    playingPerDef.Add(sustainer.def, list);
                }
                else
                {
                    playingPerDef[sustainer.def].Add(sustainer);
                }
            }
            foreach (KeyValuePair <SoundDef, List <Sustainer> > item in playingPerDef)
            {
                SoundDef         key   = item.Key;
                List <Sustainer> value = item.Value;
                if (value.Count - key.maxVoices < 0)
                {
                    for (int j = 0; j < value.Count; j++)
                    {
                        value[j].scopeFader.inScope = true;
                    }
                    continue;
                }
                for (int k = 0; k < value.Count; k++)
                {
                    value[k].scopeFader.inScope = false;
                }
                value.Sort(SortSustainersByCameraDistanceCached);
                int num = 0;
                for (int l = 0; l < value.Count; l++)
                {
                    value[l].scopeFader.inScope = true;
                    num++;
                    if (num >= key.maxVoices)
                    {
                        break;
                    }
                }
                for (int m = 0; m < value.Count; m++)
                {
                    if (!value[m].scopeFader.inScope)
                    {
                        value[m].scopeFader.inScopePercent = 0f;
                    }
                }
            }
            foreach (KeyValuePair <SoundDef, List <Sustainer> > item2 in playingPerDef)
            {
                item2.Value.Clear();
                SimplePool <List <Sustainer> > .Return(item2.Value);
            }
            playingPerDef.Clear();
        }
Beispiel #3
0
        public void End(SplineExtruder se)
        {
            Aggregate(se);
            se.Reset();

            m_SplineExtruders.Return(se);
        }
Beispiel #4
0
        public async Task <string> SendDataAsync(string url, string method, string data)
        {
            //httpclient的问题
            //https://www.cnblogs.com/jlion/p/12813692.html
            var httpClient = httpClientPool.Rent();

            httpClient.DefaultRequestHeaders.Clear();
            //httpClient.BaseAddress = new Uri(url);
            httpClient.DefaultRequestHeaders.Add("ContentType", ContentType);
            httpClient.DefaultRequestHeaders.Add("Accept", Accept);
            foreach (var kv in heads)
            {
                httpClient.DefaultRequestHeaders.Add(kv.Key, kv.Value.ToString());
            }
            var content = new StringContent(data, ContentEncoding);

            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(ContentType);
            HttpResponseMessage response;

            switch (method)
            {
            case "POST":
                response = await httpClient.PostAsync(url, content);

                break;

            case "PUT":
                response = await httpClient.PutAsync(url, content);

                break;

            case "DELETE":
                response = await httpClient.DeleteAsync(url);

                break;

            default:
                response = await httpClient.GetAsync(url);

                break;
            }
            httpClientPool.Return(httpClient);
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception("服务器错误:" + response.StatusCode);
            }
            string result;

            using (var myResponseStream = await response.Content.ReadAsStreamAsync())
            {
                using (var myStreamReader = new StreamReader(myResponseStream, ResponseEncoding))
                {
                    result = myStreamReader.ReadToEnd();
                }
            }
            //httpClientPool.Return(httpClient);
            return(result);
        }
        public void Return(IPixelBuffer buffer)
        {
            if (buffer is not TBuffer b)
            {
                throw new ArgumentException("Invalid buffer type!");
            }

            _pool.Return(b);
        }
Beispiel #6
0
        public override void ReturnToPool()
        {
            depth       = 0;
            iters       = 0;
            thingId     = 0;
            thingDef    = null;
            factionName = null;
            moreInfo    = null;

            SimplePool <StackTraceLogItemRaw> .Return(this);
        }
Beispiel #7
0
        public static Dictionary <ThingDef, float> CalculateDistancesToNearbyClusters2(WildPlantSpawner __instance, IntVec3 c)
        {
            Map map2 = map(__instance);
            //nearbyClusters.Clear();
            //nearbyClustersList.Clear();
            Dictionary <ThingDef, List <float> >           nearbyClusters     = new Dictionary <ThingDef, List <float> >();
            List <KeyValuePair <ThingDef, List <float> > > nearbyClustersList = new List <KeyValuePair <ThingDef, List <float> > >();

            int num = GenRadial.NumCellsInRadius(map2.Biome.MaxWildAndCavePlantsClusterRadius * 2);

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec = c + GenRadial.RadialPattern[i];
                if (!intVec.InBounds(map2))
                {
                    continue;
                }

                List <Thing> list = map2.thingGrid.ThingsListAtFast(intVec);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing = list[j];
                    if (thing.def.category == ThingCategory.Plant && thing.def.plant.GrowsInClusters)
                    {
                        float item = intVec.DistanceToSquared(c);
                        if (!nearbyClusters.TryGetValue(thing.def, out List <float> value))
                        {
                            value = new List <float>(); //SimplePool<List<float>>.Get();
                            nearbyClusters.Add(thing.def, value);
                            nearbyClustersList.Add(new KeyValuePair <ThingDef, List <float> >(thing.def, value));
                        }

                        value.Add(item);
                    }
                }
            }

            //distanceSqToNearbyClusters.Clear();
            Dictionary <ThingDef, float> distanceSqToNearbyClusters = new Dictionary <ThingDef, float>();

            for (int k = 0; k < nearbyClustersList.Count; k++)
            {
                List <float> value2 = nearbyClustersList[k].Value;
                value2.Sort();
                distanceSqToNearbyClusters.Add(nearbyClustersList[k].Key, value2[value2.Count / 2]);
                value2.Clear();
                SimplePool <List <float> > .Return(value2);
            }
            return(distanceSqToNearbyClusters);
        }
        public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish)
        {
            base.DeSpawn(mode);
            this.cellsToAffect.Clear();
            SimplePool <List <IntVec3> > .Return(this.cellsToAffect);

            this.cellsToAffect = null;
            this.damagedThings.Clear();
            SimplePool <List <Thing> > .Return(this.damagedThings);

            this.damagedThings = null;
            this.addedCellsAffectedOnlyByDamage.Clear();
            SimplePool <HashSet <IntVec3> > .Return(this.addedCellsAffectedOnlyByDamage);

            this.addedCellsAffectedOnlyByDamage = null;
        }
Beispiel #9
0
        public static int RemoveAll <TKey, TValue>(this Dictionary <TKey, TValue> dictionary, Func <TKey, TValue, bool> predicate)
        {
            List <TKey> list = null;
            int         result;

            try
            {
                foreach (var(key, value) in dictionary)
                {
                    if (predicate(key, value))
                    {
                        list ??= SimplePool <List <TKey> > .Get();

                        list.Add(key);
                    }
                }

                if (list != null)
                {
                    int i     = 0;
                    int count = list.Count;
                    while (i < count)
                    {
                        dictionary.Remove(list[i]);
                        i++;
                    }
                    result = list.Count;
                }
                else
                {
                    result = 0;
                }
            }
            finally
            {
                if (list != null)
                {
                    list.Clear();
                    SimplePool <List <TKey> > .Return(list);
                }
            }

            return(result);
        }
Beispiel #10
0
        private void CalculateDistancesToNearbyClusters(IntVec3 c)
        {
            WildPlantSpawner.nearbyClusters.Clear();
            WildPlantSpawner.nearbyClustersList.Clear();
            int num = GenRadial.NumCellsInRadius((float)(this.map.Biome.MaxWildAndCavePlantsClusterRadius * 2));

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec = c + GenRadial.RadialPattern[i];
                if (intVec.InBounds(this.map))
                {
                    List <Thing> list = this.map.thingGrid.ThingsListAtFast(intVec);
                    for (int j = 0; j < list.Count; j++)
                    {
                        Thing thing = list[j];
                        if (thing.def.category == ThingCategory.Plant && thing.def.plant.GrowsInClusters)
                        {
                            float        item = (float)intVec.DistanceToSquared(c);
                            List <float> list2;
                            if (!WildPlantSpawner.nearbyClusters.TryGetValue(thing.def, out list2))
                            {
                                list2 = SimplePool <List <float> > .Get();

                                WildPlantSpawner.nearbyClusters.Add(thing.def, list2);
                                WildPlantSpawner.nearbyClustersList.Add(new KeyValuePair <ThingDef, List <float> >(thing.def, list2));
                            }
                            list2.Add(item);
                        }
                    }
                }
            }
            WildPlantSpawner.distanceSqToNearbyClusters.Clear();
            for (int k = 0; k < WildPlantSpawner.nearbyClustersList.Count; k++)
            {
                List <float> value = WildPlantSpawner.nearbyClustersList[k].Value;
                value.Sort();
                WildPlantSpawner.distanceSqToNearbyClusters.Add(WildPlantSpawner.nearbyClustersList[k].Key, value[value.Count / 2]);
                value.Clear();
                SimplePool <List <float> > .Return(value);
            }
        }
        private void CalculateDistancesToNearbyClusters(IntVec3 c)
        {
            nearbyClusters.Clear();
            nearbyClustersList.Clear();
            int num = GenRadial.NumCellsInRadius(map.Biome.MaxWildAndCavePlantsClusterRadius * 2);

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec = c + GenRadial.RadialPattern[i];
                if (!intVec.InBounds(map))
                {
                    continue;
                }
                List <Thing> list = map.thingGrid.ThingsListAtFast(intVec);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing = list[j];
                    if (thing.def.category == ThingCategory.Plant && thing.def.plant.GrowsInClusters)
                    {
                        float item = intVec.DistanceToSquared(c);
                        if (!nearbyClusters.TryGetValue(thing.def, out var value))
                        {
                            value = SimplePool <List <float> > .Get();

                            nearbyClusters.Add(thing.def, value);
                            nearbyClustersList.Add(new KeyValuePair <ThingDef, List <float> >(thing.def, value));
                        }
                        value.Add(item);
                    }
                }
            }
            distanceSqToNearbyClusters.Clear();
            for (int k = 0; k < nearbyClustersList.Count; k++)
            {
                List <float> value2 = nearbyClustersList[k].Value;
                value2.Sort();
                distanceSqToNearbyClusters.Add(nearbyClustersList[k].Key, value2[value2.Count / 2]);
                value2.Clear();
                SimplePool <List <float> > .Return(value2);
            }
        }
Beispiel #12
0
        static private void AddAllRelationships(WorldPawnGC __instance, Pawn pawn, Dictionary <Pawn, string> keptPawns)
        {
            if (pawn.relations == null || !pawn.relations.RelatedToAnyoneOrAnyoneRelatedToMe || !pawn.RaceProps.IsFlesh)
            {
                return;
            }
            Stack <Pawn>   stack   = null;
            HashSet <Pawn> visited = null;

            try {
                stack = SimplePool <Stack <Pawn> > .Get();

                visited = SimplePool <HashSet <Pawn> > .Get();

                stack.Push(pawn);
                visited.Add(pawn);
                while (stack.Count > 0)
                {
                    Pawn p = stack.Pop();
                    foreach (Pawn otherPawn in p.relations.DirectRelations.Select(r => r.otherPawn).Concat <Pawn>(
                                 (HashSet <Pawn>) typeof(Pawn_RelationsTracker).GetField("pawnsWithDirectRelationsWithMe",
                                                                                         BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(p.relations)))
                    {
                        if (!visited.Contains(otherPawn))
                        {
                            if (otherPawn.RaceProps.IsFlesh)
                            {
                                PawnRelationDef relation = AllAllowedRelationDefs.FirstOrDefault(def => def.Worker.InRelation(pawn, otherPawn));
                                if (relation != default(PawnRelationDef))
                                {
                                    if (logDotgraph != null)
                                    {
                                        string text = string.Format("{0}->{1} [label=<{2}> color=\"purple\"];", WorldPawnGC.DotgraphIdentifier(pawn),
                                                                    WorldPawnGC.DotgraphIdentifier(otherPawn), relation.ToString());
                                        if (!logDotgraphUniqueLinks.Contains(text))
                                        {
                                            logDotgraphUniqueLinks.Add(text);
                                            logDotgraph.AppendLine(text);
                                        }
                                    }
                                    if (!keptPawns.ContainsKey(otherPawn))
                                    {
                                        keptPawns[otherPawn] = "Relationship";
                                        //Not correct to have it here if the pairing between two pawns is filtered but if we allow all relations this is correct.
                                        //The pursuit of animal family trees if a human is bonded with an animal is pointless.
                                        if (relation != PawnRelationDefOf.Bond)
                                        {
                                            stack.Push(otherPawn);
                                        }
                                    }
                                }
                            }
                            visited.Add(otherPawn);
                        }
                    }
                }
            } finally {
                if (stack != null)
                {
                    stack.Clear();
                    stack.TrimExcess();
                    SimplePool <Stack <Pawn> > .Return(stack);
                }
                if (visited != null)
                {
                    visited.Clear();
                    stack.TrimExcess();
                    SimplePool <HashSet <Pawn> > .Return(visited);
                }
            }
        }
        public void UpdateAllSustainerScopes()
        {
            for (int i = 0; i < this.allSustainers.Count; i++)
            {
                Sustainer sustainer = this.allSustainers[i];
                if (!SustainerManager.playingPerDef.ContainsKey(sustainer.def))
                {
                    List <Sustainer> list = SimplePool <List <Sustainer> > .Get();

                    list.Add(sustainer);
                    SustainerManager.playingPerDef.Add(sustainer.def, list);
                }
                else
                {
                    SustainerManager.playingPerDef[sustainer.def].Add(sustainer);
                }
            }
            foreach (KeyValuePair <SoundDef, List <Sustainer> > keyValuePair in SustainerManager.playingPerDef)
            {
                SoundDef         key   = keyValuePair.Key;
                List <Sustainer> value = keyValuePair.Value;
                int num = value.Count - key.maxVoices;
                if (num < 0)
                {
                    for (int j = 0; j < value.Count; j++)
                    {
                        value[j].scopeFader.inScope = true;
                    }
                }
                else
                {
                    for (int k = 0; k < value.Count; k++)
                    {
                        value[k].scopeFader.inScope = false;
                    }
                    int num2 = 0;
                    foreach (Sustainer sustainer2 in from lo in value
                             orderby lo.CameraDistanceSquared
                             select lo)
                    {
                        sustainer2.scopeFader.inScope = true;
                        num2++;
                        if (num2 >= key.maxVoices)
                        {
                            break;
                        }
                    }
                    for (int l = 0; l < value.Count; l++)
                    {
                        if (!value[l].scopeFader.inScope)
                        {
                            value[l].scopeFader.inScopePercent = 0f;
                        }
                    }
                }
            }
            foreach (KeyValuePair <SoundDef, List <Sustainer> > keyValuePair2 in SustainerManager.playingPerDef)
            {
                keyValuePair2.Value.Clear();
                SimplePool <List <Sustainer> > .Return(keyValuePair2.Value);
            }
            SustainerManager.playingPerDef.Clear();
        }
Beispiel #14
0
        public async Task <HttpResponseResult> SendDataAsyncBase(string url, string method, string data)
        {
            //httpclient的问题
            //https://www.cnblogs.com/jlion/p/12813692.html
            HttpClient httpClient = _httpClient;

            if (_httpClient == null)
            {
                httpClient = httpClientPool.Rent();
            }
            httpClient.DefaultRequestHeaders.Clear();
            //httpClient.BaseAddress = new Uri(url);
            httpClient.DefaultRequestHeaders.Add("ContentType", ContentType);
            httpClient.DefaultRequestHeaders.Add("Accept", Accept);
            foreach (var kv in heads)
            {
                httpClient.DefaultRequestHeaders.Add(kv.Key, kv.Value.ToString());
            }
            if (RequestWidthCookie)
            {
                var cookies = new List <string>();
                foreach (Cookie c in GetCurrentCookie())
                {
                    var str = $"{c.Name}={c.Value}";
                    cookies.Add(str);
                }
                httpClient.DefaultRequestHeaders.Add("Cookie", string.Join("&", cookies));
            }
            var content = new StringContent(data, ContentEncoding);

            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(ContentType);
            HttpResponseMessage response;

            switch (method)
            {
            case "POST":
                response = await httpClient.PostAsync(url, content);

                break;

            case "PUT":
                response = await httpClient.PutAsync(url, content);

                break;

            case "DELETE":
                response = await httpClient.DeleteAsync(url);

                break;

            default:
                response = await httpClient.GetAsync(url);

                break;
            }
            if (_httpClient == null)
            {
                httpClientPool.Return(httpClient);
            }
            var stream = await response.Content.ReadAsStreamAsync();

            return(new HttpResponseResult(stream, response.StatusCode));
        }