Example #1
0
 /// <summary>
 /// Creates an instance of the class
 /// </summary>
 public Core()
 {
     CoreDomain              = new CurrentAppDomain(this);
     InternalObjectRegister  = new CoreManagement(this);
     InternalObjectActivator = new CoreActivator(this);
     InternalObjectResolver  = new CoreResolver(this);
     InternalObjectEvents    = new CoreEvents(this);
     InternalFactories       = new CoreFactories(this);
     InternalCache           = new CoreCache(this);
     Console  = OnCreateConsole();
     Settings = OnCreateSettings();
     Invoker  = OnCreateInvoker();
     OnCreate();
 }
        /// <summary>
        /// Create a new ContentDownloadManager
        /// DownloadConcurrency = Environment.ProcessorCount * ConcurrencyMultiplier;
        /// ImageDownloadConcurrency = DownloadConcurrency / 2;
        /// </summary>
        /// <param name="ConcurrencyMultiplier">Default is 1.</param>
        public ContentDownloadManager(
            CoreManagement CORE = null)
        {
            #region CORE
            App App = App.Current as App;
            if (!Equals(CORE, null))
            {
                this.CORE = CORE;
            }
            else if (!Equals(App, null))
            {
                this.CORE = App.CORE;
            }
            else
            {
                this.CORE = new CoreManagement(log4net.LogManager.GetLogger(typeof(ContentDownloadManager)));
            }
            #endregion

            // Store the SerializeType on startup.
            SerializeType = CORE.UserConfiguration.SerializeType;

            ActiveDownloadsCache = new MemoryCache("ActiveDownloadsCache");

            Int32 ConcurrencyMultiplier = CORE.UserConfiguration.ConcurrencyMultiplier;
            if (ConcurrencyMultiplier < 1)
            {
                ConcurrencyMultiplier = 1;
            }
            else if (ConcurrencyMultiplier > 10)
            {
                ConcurrencyMultiplier = 10;
            }

            DownloadConcurrency           = Environment.ProcessorCount * ConcurrencyMultiplier;
            ImageDownloadConcurrency      = DownloadConcurrency / 2;
            TaskConcurrencySemaphore      = new SemaphoreSlim(DownloadConcurrency, DownloadConcurrency);
            ImageTaskConcurrencySemaphore = new SemaphoreSlim(ImageDownloadConcurrency, ImageDownloadConcurrency);
            ServicePointManager.DefaultConnectionLimit = DownloadConcurrency + ImageDownloadConcurrency;

            cts = new CancellationTokenSource();
            ContentTaskFactory = Task.Factory;
        }