Exemplo n.º 1
0
 public JobAgentMiddleware(ILogger <JobAgentMiddleware> logger, IOptions <JobAgentOptions> options, ILoggerFactory loggerFactory)
 {
     _loggerFactory = loggerFactory;
     _logger        = logger;
     _options       = options;
     transitentJob  = new LazyConcurrentDictionary();
 }
        public void LazyConcurrentDictionaryIsThreadSafe()
        {
            List <int> listRunCount = new List <int>();
            string     key          = "key";
            var        i            = 0;

            while (i++ < 1000 * 1000)
            {
                var runCount = 0;
                LazyConcurrentDictionary <string, string> dic = new LazyConcurrentDictionary <string, string>();
                var task1 = Task.Run(() =>
                {
                    dic.GetOrAdd(key, (v) => { runCount++;
                                               return(key); });
                });
                var task2 = Task.Run(() =>
                {
                    dic.GetOrAdd(key, (v) => { runCount++;
                                               return(key); });
                });
                Task.WaitAll(task1, task2);
                listRunCount.Add(runCount);
            }

            Assert.DoesNotContain(listRunCount, t => t == 2);
        }
 public GymService(IGymRepository gymRepository, ILocalizationService localizationService, IConfigurationService configurationService)
 {
     GymRepository        = gymRepository;
     LocalizationService  = localizationService;
     ConfigurationService = configurationService;
     GymsByFences         = new LazyConcurrentDictionary <FenceConfiguration, int[]>();
 }
Exemplo n.º 4
0
 /// <constructor />
 public AttachmentBag(Document parentDocument)
 {
     this.parentDocument = parentDocument;
     attachmentObjects   = new LazyConcurrentDictionary <string, Attachment>(
         id => new WrappingAttachment(id, parentDocument)
         );
 }
Exemplo n.º 5
0
 public LazyConcurrentDictionaryTests()
 {
     _lazyDictionary = new LazyConcurrentDictionary <int, string>(
         new List <KeyValuePair <int, Lazy <string> > >
     {
         new (0, new Lazy <string>(() => "First")),
         new (1, new Lazy <string>(() => "Second"))
     },
Exemplo n.º 6
0
 public RabbitMqPublishEndpointProvider(IRabbitMqHost host, IMessageSerializer serializer, Uri sourceAddress, IPublishPipe publishPipe)
 {
     _host              = host;
     _serializer        = serializer;
     _sourceAddress     = sourceAddress;
     _publishPipe       = publishPipe;
     _cachedEndpoints   = new LazyConcurrentDictionary <Type, ISendEndpoint>(CreateSendEndpoint);
     _publishObservable = new PublishObservable();
 }
 public PokemonService(IRaidbossService raidbossService, ILocalizationService localizationService, IFileWatcherService fileWatcherService)
 {
     LocalizationService = localizationService;
     FileWatcherService  = fileWatcherService;
     RaidbossService     = raidbossService;
     PokemonPerCulture   = new LazyConcurrentDictionary <CultureInfo, List <IPokemon> >();
     LoadPokemon("de-DE");
     LoadPokemon("en-US");
 }
 public RabbitMqPublishEndpointProvider(IRabbitMqHost host, IMessageSerializer serializer, Uri sourceAddress, IPublishPipe publishPipe)
 {
     _host = host;
     _serializer = serializer;
     _sourceAddress = sourceAddress;
     _publishPipe = publishPipe;
     _cachedEndpoints = new LazyConcurrentDictionary<Type, ISendEndpoint>(CreateSendEndpoint);
     _publishObservable = new PublishObservable();
 }
Exemplo n.º 9
0
        /// <constructor />
        public NewtonsoftSerializer(
            Func <JsonSerializerSettings> createDefaultSerializerSettings = null,
            Func <IEntityConfig, JsonSerializerSettings> createEntitySerializerSettings = null)
        {
            createDefaultSerializerSettings =
                createDefaultSerializerSettings ?? NewtonsoftSerializerDefautSettings.CreateDefaultSerializerSettingsDefault;
            createEntitySerializerSettings =
                createEntitySerializerSettings ?? NewtonsoftSerializerDefautSettings.CreateEntitySerializerSettingsDefault;

            defaultSerializer = new Lazy <JsonSerializer>(
                () => JsonSerializer.Create(createDefaultSerializerSettings()), LazyThreadSafetyMode.PublicationOnly);
            entitySerializers = new LazyConcurrentDictionary <IEntityConfig, JsonSerializer>(
                entityConfig => JsonSerializer.Create(createEntitySerializerSettings(entityConfig)));
        }
Exemplo n.º 10
0
        /// <constructor />
        public NewtonsoftSerializer(
            Func<JsonSerializerSettings> createDefaultSerializerSettings = null,
            Func<IEntityConfig, JsonSerializerSettings> createEntitySerializerSettings = null)
        {
            createDefaultSerializerSettings =
                createDefaultSerializerSettings ?? NewtonsoftSerializerDefautSettings.CreateDefaultSerializerSettingsDefault;
            createEntitySerializerSettings =
                createEntitySerializerSettings ?? NewtonsoftSerializerDefautSettings.CreateEntitySerializerSettingsDefault;

            defaultSerializer = new Lazy<JsonSerializer>(
                () => JsonSerializer.Create(createDefaultSerializerSettings()), LazyThreadSafetyMode.PublicationOnly);
            entitySerializers = new LazyConcurrentDictionary<IEntityConfig, JsonSerializer>(
                entityConfig => JsonSerializer.Create(createEntitySerializerSettings(entityConfig)));
        }
Exemplo n.º 11
0
 static DependencyInjectionServiceExtensions()
 {
     Types = new LazyConcurrentDictionary <IServiceCollection, NamedServiceDicionary>();
 }
Exemplo n.º 12
0
 public Cache(ICacheContextAccessor cacheContextAccessor)
 {
     _cacheContextAccessor = cacheContextAccessor;
     _entries = new LazyConcurrentDictionary <TKey, CacheEntry>();
 }
Exemplo n.º 13
0
 public SendEndpointCache(ISendEndpointProvider sendEndpointProvider)
 {
     _sendEndpointProvider = sendEndpointProvider;
     _cache = new LazyConcurrentDictionary<Uri, ISendEndpoint>(GetSendEndpointFromProvider, AddressEqualityComparer.Comparer);
 }
Exemplo n.º 14
0
 public SendEndpointCache(ISendEndpointProvider sendEndpointProvider)
 {
     _sendEndpointProvider = sendEndpointProvider;
     _cache = new LazyConcurrentDictionary <Uri, ISendEndpoint>(GetSendEndpointFromProvider, AddressEqualityComparer.Comparer);
 }
Exemplo n.º 15
0
 public NamedServiceDicionary()
 {
     Types = new LazyConcurrentDictionary <KeyValuePair <string, Type>, ConcurrentDictionary <Type, Type> >();
 }
Exemplo n.º 16
0
        protected override void RenderContent(RenderComposer composer)
        {
            ImGui.Text(UnmanagedMemoryAllocator.GetDebugInformation());

            var assetBytes = 0;

            foreach (Asset asset in Engine.AssetLoader.LoadedAssets)
            {
                assetBytes += asset.ByteSize;
            }

            ImGui.Text($"Assets Rough Estimate: {Helpers.FormatByteAmountAsString(assetBytes)}");
            var totalBytes = 0;

            for (var i = 0; i < Texture.AllTextures.Count; i++)
            {
                Texture texture  = Texture.AllTextures[i];
                int     byteSize = (int)(texture.Size.X * texture.Size.Y) * Gl.PixelTypeToByteCount(texture.PixelType) *
                                   Gl.PixelFormatToComponentCount(texture.PixelFormat);
                totalBytes += byteSize;
            }

            ImGui.Text($"Texture Memory Estimate: {Helpers.FormatByteAmountAsString(totalBytes)}");
            ImGui.Text($"Audio Buffer Memory: {Helpers.FormatByteAmountAsString(AudioLayer.MetricAllocatedDataBlocks)}");
            ImGui.Text($"Managed Memory (Game): {Helpers.FormatByteAmountAsString(GC.GetTotalMemory(false))}");

            long usedRam     = _p.WorkingSet64;
            long usedRamMost = _p.PrivateMemorySize64;

            ImGui.Text($"Total Memory Used: {Helpers.FormatByteAmountAsString(usedRam)} | Allocated: {Helpers.FormatByteAmountAsString(usedRamMost)}");

            ImGui.NewLine();
            ImGui.BeginGroup();
            ImGui.BeginTabBar("TabBar");
            if (ImGui.BeginTabItem("Assets"))
            {
                ImGui.BeginChild("Assets", new Vector2(450, 500), true, ImGuiWindowFlags.HorizontalScrollbar);

                Asset[] loadedAssets = Engine.AssetLoader.LoadedAssets;
                IOrderedEnumerable <Asset> orderedEnum = loadedAssets.OrderByDescending(x => x.ByteSize);
                foreach (Asset asset in orderedEnum)
                {
                    float percent = (float)asset.ByteSize / assetBytes;
                    ImGui.Text($"{asset.Name} {Helpers.FormatByteAmountAsString(asset.ByteSize)} {percent * 100:0}%%");
                    ImGui.Text($"\t{asset.GetType()}");
                }

                ImGui.EndChild();
                ImGui.EndTabItem();
            }

            if (ImGui.BeginTabItem("XML Cache"))
            {
                ImGui.BeginChild("XMLType", new Vector2(450, 500), true, ImGuiWindowFlags.HorizontalScrollbar);

                LazyConcurrentDictionary <Type, XMLTypeHandler?> xmlCachedHandlers = XMLHelpers.Handlers;

                var counter = 0;
                foreach ((Type type, Lazy <XMLTypeHandler?> typeHandlerLazy) in xmlCachedHandlers)
                {
                    if (!typeHandlerLazy.IsValueCreated)
                    {
                        continue;
                    }

                    counter++;
                    ImGui.PushID(counter);

                    XMLTypeHandler typeHandler = typeHandlerLazy.Value !;
                    if (ImGui.TreeNode($"{typeHandler.TypeName} ({typeHandler.GetType().ToString().Replace("Emotion.Standard.XML.TypeHandlers.", "")})"))
                    {
                        ImGui.Text($"\t Full TypeName: {type}");
                        if (typeHandler is XMLComplexTypeHandler complexHandler)
                        {
                            ImGui.Text($"\t Fields: {complexHandler.FieldCount()}");
                        }

                        ImGui.TreePop();
                    }

                    ImGui.PopID();
                }

                ImGui.EndChild();
                ImGui.EndTabItem();
            }

            ImGui.EndTabBar();
            ImGui.EndGroup();
        }