public void Run()
 {
     var scheduler = new LimitedConcurrencyLevelTaskScheduler(2);
     var taskFactory = new TaskFactory(scheduler);
     var tasks = Enumerable.Range(1, 2).Select(id => taskFactory.StartNew(() => DoWork(id)));
     Task.WaitAll(tasks.ToArray());
 }
 public LegacyConverter(int clientVersion, bool useAlpha, int maxThreads = 4)
 {
     m_ClientVersion = clientVersion;
     m_UseAlpha      = useAlpha;
     m_LCTS          = new LimitedConcurrencyLevelTaskScheduler(maxThreads);
     m_TaskFactory   = new TaskFactory(m_LCTS);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskExecution" /> class.
        /// </summary>
        /// <param name="frameworkHandle">The framework handle.</param>
        /// <param name="statLightWrapper">The stat light wrapper.</param>
        public TaskExecution(IFrameworkHandle frameworkHandle, StatLightWrapper statLightWrapper)
        {
            this.statLightWrapper = statLightWrapper;
            this.FrameworkHandle  = frameworkHandle;

            this.scheduler = new LimitedConcurrencyLevelTaskScheduler(1);
        }
 public static void ProcessFiles(CancellationToken cts)
 {
     try
     {
         LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(2);
         List <Task> tasks   = new List <Task>();
         TaskFactory factory = new TaskFactory(lcts);
         for (int i = 0; i < 1000; i++)
         {
             int i1 = i;
             var t  = factory.StartNew(() =>
             {
                 if (cts != null)
                 {
                     Console.WriteLine("{0} --- {1}", i1, GetGuid(cts));
                 }
             }, cts);
             tasks.Add(t);
         }
         Task.WaitAll(tasks.ToArray());
         Console.WriteLine("\n\nSuccessful completion.");
         Console.ReadLine();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
示例#5
0
        public void BasicSchedulingLimitedOnly()
        {
            LimitedConcurrencyLevelTaskScheduler lclts = new LimitedConcurrencyLevelTaskScheduler(5);
            TaskFactory factory = new TaskFactory(lclts);

            factory.StartNew(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("{0} on thread {1}", i, Thread.CurrentThread.ManagedThreadId);
                }
            }
                             );

            ParallelOptions options = new ParallelOptions();

            options.TaskScheduler = lclts;

            Parallel.For(
                0,
                50,
                options,
                (i) =>
            {
                Thread.Sleep(100);
                Console.WriteLine("Finish Thread={0}, i={1}", Thread.CurrentThread.ManagedThreadId, i);
            }
                );
        }
 public TaskManagerService(IServiceProvider serviceProvider, IConcurrencyStrategy concurrencyStrategy)
 {
     this._serviceProvider = serviceProvider;
     this._scheduler       = new LimitedConcurrencyLevelTaskScheduler(concurrencyStrategy.ComputeAvailableCores());
     this._factory         = new TaskFactory(_scheduler);
     SubscribeToEvents();
 }
示例#7
0
        /// <summary>
        /// Creates a task factory to handle all file partitioning tasks.
        /// </summary>
        /// <returns></returns>
        protected virtual TaskFactory GetFilePartitioningTaskFactory()
        {
            Log.InfoFormat("Setting file partitioning concurrency limit to {0} concurrent files.", tuningOptions.FilePartitionerConcurrencyLimit);
            LimitedConcurrencyLevelTaskScheduler taskScheduler = new LimitedConcurrencyLevelTaskScheduler(tuningOptions.FilePartitionerConcurrencyLimit);

            return(new TaskFactory(taskScheduler));
        }
示例#8
0
        /// <summary>
        /// Upload Folder by muti-thread
        /// </summary>
        /// <param name="folderName"></param>
        /// <param name="remoteFolderName"></param>
        /// <param name="siteName"></param>
        /// <param name="threadCount"></param>
        public void UploadFolder(string folderName, string remoteFolderName, string siteName, int threadCount = 1)
        {
            if (!Directory.Exists(folderName))
            {
                System.Console.WriteLine("folder not found.");
                return;
            }
            string[]      files         = Directory.GetFiles(folderName);
            TaskScheduler taskScheduler = new LimitedConcurrencyLevelTaskScheduler(threadCount);
            TaskFactory   taskFactory   = new TaskFactory(taskScheduler);
            int           fileCount     = files.Count();

            foreach (var item in files)
            {
                taskFactory.StartNew(() =>
                {
                    string uploadPath = Path.Combine(remoteFolderName, Path.GetFileName(item));
                    string uploadUrl  = this.GetUploadUrl(uploadPath, siteName).Result;
                    this.UploadFile(uploadUrl, item);
                    lock (o)
                    {
                        fileCount--;
                    }
                });
            }
            while (true)
            {
                if (fileCount == 0)
                {
                    System.Console.WriteLine("文件夹上传完毕");
                    return;
                }
                Thread.Sleep(TimeSpan.FromSeconds(2));
            }
        }
示例#9
0
        // test using request.GetResponse
        static async Task Test2()
        {
            int maxThreads, maxPorts;

            ThreadPool.GetMaxThreads(out maxThreads, out maxPorts);
            var scheduler = new LimitedConcurrencyLevelTaskScheduler(maxPorts);

            var tasks = Enumerable.Range(1, MAX_REQS).Select((i) =>
                                                             Task.Factory.StartNew(() =>
            {
                var request = WebRequest.Create("http://www.bing.com/search?q=item1=" + i);
                using (var response = request.GetResponse())
                    using (var stream = response.GetResponseStream())
                        using (var reader = new System.IO.StreamReader(stream))
                        {
                            return(reader.ReadToEnd());
                        }
            }, CancellationToken.None, TaskCreationOptions.PreferFairness, scheduler));

            Console.WriteLine("Threads before completion: " + Process.GetCurrentProcess().Threads.Count);

            await Task.WhenAll(tasks);

            Console.WriteLine("Threads after completion: " + Process.GetCurrentProcess().Threads.Count);
        }
        /// <summary>
        /// Creates a task factory to handle all file partitioning tasks.
        /// </summary>
        /// <returns></returns>
        private TaskFactory GetFilePartitioningTaskFactory()
        {
            Log.InfoFormat("Setting file partitioning concurrency limit to {0} concurrent files.", request.Configuration.TuningOptions.FilePartitionerConcurrencyLimit);
            LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(request.Configuration.TuningOptions.FilePartitionerConcurrencyLimit);

            return(new TaskFactory(lcts));
        }
示例#11
0
        public CountableThreadPool(int threadNum = 5)
        {
            _maxDegreeOfParallelism = threadNum;
            _maxTaskCount           = _maxDegreeOfParallelism + threadNum;

            LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(threadNum);

            _factory = new TaskFactory(lcts);

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    if (_end)
                    {
                        break;
                    }

                    lock (_tasks)
                    {
                        var finishedTasks = _tasks.Where(t => t.IsCompleted).ToList();
                        foreach (var finishedTask in finishedTasks)
                        {
                            _tasks.Remove(finishedTask);
                        }
                        Thread.Sleep(100);
                    }
                }
            });
        }
示例#12
0
        public AlphaMemory(ILoggerFactory loggerFactory)
        {
            _scheduler = new LimitedConcurrencyLevelTaskScheduler(1);
            _facts     = new OrderedHashSet <TFact>();

            _log = loggerFactory.CreateLogger <AlphaMemory <TFact> >();
        }
示例#13
0
        protected void ProcessDataEngineLogs(IMongoCollection <BsonDocument> collection)
        {
            Log.Info("Queueing Data Engine events for processing..");

            List <Task> tasks = new List <Task>();

            LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(dataenginePersister.GetPoolSize());
            TaskFactory factory = new TaskFactory(lcts);

            using (GetTaskStatusWriter(tasks, "Data Engine processing"))
            {
                int numWorkers = DataEngineMongoHelper.GetNumberOfWorkers(dataengineCollection);
                int currWorker = 0;
                while (currWorker <= numWorkers)
                {
                    var fileNames = DataEngineMongoHelper.GetDataEngineLogFilesForWorker(currWorker, dataengineCollection);
                    foreach (var fileName in fileNames)
                    {
                        IDictionary <int, IList <BsonDocument> > queriesBySession = DataEngineMongoHelper.GetQueriesBySessionIdForLogfile(fileName, dataengineCollection);

                        foreach (var session in queriesBySession.Keys)
                        {
                            tasks.Add(factory.StartNew(() => PersistSessionInformation(session, queriesBySession[session])));
                        }
                    }
                    currWorker++;
                }

                Task.WaitAll(tasks.ToArray());
            }
        }
示例#14
0
        static AsyncFunctions()
        {
            // This initialization could be lazy (and of course be any other TaskScheduler)
            var fourThreadScheduler = new LimitedConcurrencyLevelTaskScheduler(4);

            _fourThreadFactory = new TaskFactory(fourThreadScheduler);
        }
        private TaskFactory CreateTaskFactory()
        {
            ExpressUnitConfigurationSection      config = (ExpressUnitConfigurationSection)System.Configuration.ConfigurationManager.GetSection("ExpressUnitConfiguration");
            LimitedConcurrencyLevelTaskScheduler lcts   = new LimitedConcurrencyLevelTaskScheduler(config.DegreeOfParallelism);
            TaskFactory factory = new TaskFactory(lcts);

            return(factory);
        }
        public AmazonSqsConnectionContext(IConnection connection, IAmazonSqsHostConfiguration configuration, CancellationToken cancellationToken)
            : base(new PayloadCache(), cancellationToken)
        {
            _configuration = configuration;
            Connection     = connection;

            _taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);
        }
示例#17
0
    private static void Main(string[] args)
    {
        // setup the factory
        LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(9);
        TaskFactory f = new TaskFactory(lcts);
        // create my shared task queue
        ConcurrentDictionary <string, Task> waiting = new ConcurrentDictionary <string, Task>();
        ConcurrentBag <Task> finished = new ConcurrentBag <Task>();
        // some numbers....
        List <int> nums = new List <int>()
        {
            1, 2, 3, 4, 5, 6, 7, 8, 9, 0
        };

        foreach (int n in nums)
        {
            int  i = n;        // if you don't do this, n is 0 when it writes to the Debug console....
            Task t = f.StartNew(() =>
            {
                Debug.WriteLine(i);
                // some more numbers....
                List <int> other = new List <int>()
                {
                    10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
                };
                foreach (int nm in other)
                {
                    int j   = i;
                    int w   = nm;
                    Task tk = f.StartNew(() =>
                    {
                        Debug.WriteLine(j + "," + w);
                        Thread.Sleep(1000);
                    });
                    waiting.TryAdd(j + "," + w, tk);
                }
                Thread.Sleep(500);
            });
            waiting.TryAdd(i.ToString(), t);
        }
        // loop until no further tasks are waiting.
        while (waiting.Count > 0)
        {
            // run the tasks...
            Task.WaitAll(waiting.Values.ToArray());
            // remove the finised tasks from the waiting list.
            foreach (KeyValuePair <string, Task> pair in waiting)
            {
                if (pair.Value.IsCompleted)
                {
                    finished.Add(pair.Value);
                    Task o;
                    waiting.TryRemove(pair.Key, out o);
                }
            }
            Thread.Sleep(100);
        }
    }
示例#18
0
 public ClientRuntimeManager(IClientFactory clientFactory, IClientPersistor clientPersistor, IClientTemplateRepositoryBuilder builder)
 {
     lcts                 = new LimitedConcurrencyLevelTaskScheduler(5);
     factory              = new TaskFactory(lcts);
     this.clientFactory   = clientFactory;
     this.builder         = builder;
     this.clientPersistor = clientPersistor;
     clients              = new DefaultClientRepository();
 }
示例#19
0
        public InMemoryQueue(string name, int concurrencyLevel)
        {
            _name              = name;
            _scheduler         = new LimitedConcurrencyLevelTaskScheduler(concurrencyLevel);
            _cancellationToken = new CancellationTokenSource();

            _consumer = new TaskCompletionSource <IInMemoryQueueConsumer>();
            _cancellationToken.Token.Register(() => _consumer.TrySetCanceled());
        }
        public async override Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, Object options = null, CancellationToken cancellationToken = default)
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            if (Disabled != null && Disabled.GetValue(dc.State))
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            if (this.DialogsProperty == null)
            {
                throw new InvalidOperationException($"CallDialogs: operation couldn't be performed because the {nameof(DialogsProperty)} wasn't specified.");
            }

            // Get array of dialogs to call
            var property = this.DialogsProperty.GetValue(dc.State);
            var array    = dc.State.GetValue <JArray>(property, () => new JArray());

            // Begin dialog calls
            var tasks = new List <Task <JToken> >();

            // Call dialog sharing this thread.
            var taskScheduler = new LimitedConcurrencyLevelTaskScheduler(maxDegreeOfParallelism: 1);

            //var taskScheduler = new CurrentThreadTaskScheduler();

            for (int iItem = 0; iItem < array.Count; iItem++)
            {
                var item = array[iItem];
                if (item is JObject pair && pair.ContainsKey("id"))
                {
                    var taskDc = new DialogContext(dc.Dialogs, dc, new DialogState())
                    {
                        Parent = null
                    };
                    var dialogId      = pair["id"].ToString();
                    var dialogOptions = pair["options"];

                    tasks.Add(Task.Factory.StartNew(async() =>
                    {
                        Trace.WriteLine($"TaskBeginDialog {dialogId}({JsonConvert.SerializeObject(dialogOptions)})");
                        var result = await taskDc.BeginDialogAsync(dialogId, dialogOptions, cancellationToken);

                        // Ensure dialog completed
                        if (result.Status != DialogTurnStatus.Complete)
                        {
                            throw new InvalidOperationException($"CallDialogs: the dialog \"{dialogId}\" returned an invalid Status of \"{result.Status.ToString()}\".  Called dialogs should not wait for user input.");
                        }

                        Trace.WriteLine($"TaskBeginDialog {dialogId}({JsonConvert.SerializeObject(dialogOptions)}) RESULT => {JsonConvert.SerializeObject(result.Result ?? String.Empty)}");
                        // Return result value
                        return(result.Result != null ? JToken.FromObject(result.Result) : null);
                    }, cancellationToken, TaskCreationOptions.AttachedToParent, taskScheduler).Unwrap());
                }
示例#21
0
        private static async Task TPLDependent()
        {
            var lcts    = new LimitedConcurrencyLevelTaskScheduler(10);
            var factory = new TaskFactory(lcts);
            var cts     = new CancellationTokenSource();

            for (int n = 4; n <= 512; n *= 2)
            {
                var A1task = factory.StartNew(() => AllocateRandomSquareMatrix(n), cts.Token);
                var A2task = factory.StartNew(() => AllocateRandomSquareMatrix(n), cts.Token);
                var B2task = factory.StartNew(() => AllocateRandomSquareMatrix(n), cts.Token);
                var b1task = factory.StartNew(() => AllocateRandomVector(n), cts.Token);
                var c1task = factory.StartNew(() => AllocateRandomVector(n), cts.Token);

                var K1 = _rand.Next(100) * .00001;
                var K2 = _rand.Next(100) * .00001;

                /*
                 * b = even 3/(Math.Pow(i,2) +3)
                 * b = odd 3/i  */
                var btask = factory.StartNew(() => FindVectorB(n,
                                                               i => 3.0 / (Math.Pow(i, 2) + 3),
                                                               i => 3.0 / i), cts.Token);

                // Cij = 1/(i+j)*2;
                var C2task = factory.StartNew(() => FindMatrixC(n, (i, j) => 1.0 / (i + j) * 2), cts.Token);

                var y1task = factory.StartNew(async() => Multiply(await A1task, await btask), cts.Token).Unwrap();
                // y2 = A1*(3*b1+c1)
                var y2task = factory.StartNew(async() =>
                                              Multiply(await A1task, Add(Multiply(3, await b1task), await c1task)), cts.Token).Unwrap();
                var B2_C2_Addtask = factory.StartNew(async() => Add(await B2task, await C2task), cts.Token).Unwrap();
                var Y3task        = factory.StartNew(async() => Multiply(await A2task, await B2_C2_Addtask), cts.Token).Unwrap();
                var y3power3task  = factory.StartNew(async() => MatrixPower(await Y3task, 3), cts.Token).Unwrap();
                var y3power2task  = factory.StartNew(async() => MatrixPower(await Y3task, 2), cts.Token).Unwrap();

                var K1Y33task  = factory.StartNew(async() => Multiply(await y3power3task, K1), cts.Token).Unwrap();
                var y2y2Ttask  = factory.StartNew(async() => Multiply(await y2task, await y2task), cts.Token).Unwrap();
                var K1Y33y2y2T = factory.StartNew(async() => Multiply(await K1Y33task, await y2y2Ttask), cts.Token).Unwrap();

                var _2ph = factory.StartNew(async() => Add(await K1Y33y2y2T, await y3power3task), cts.Token).Unwrap();
                var _3ph = factory.StartNew(async() => Substract(await _2ph, await Y3task), cts.Token).Unwrap();
                var _4ph = factory.StartNew(async() => Multiply(await y2task, await y1task), cts.Token).Unwrap();
                var _5ph = factory.StartNew(async() => Add(await _3ph, await _4ph), cts.Token).Unwrap();
                var _6ph = factory.StartNew(async() => Multiply(Multiply(await y3power2task, K2), await y1task), cts.Token).Unwrap();
                var _7ph = factory.StartNew(async() => Add(await _5ph, await _6ph), cts.Token).Unwrap();
                // x = (K1 * Y3 * y2 * y2t) + Math.Pow(Y3,3) - Y3 - (y2 * y1t) + (K2 * Math.Pow(Y3,2) * y1t)
                Console.WriteLine($"Threads started.. Matrix size: {n}");
                Stopwatch s = new Stopwatch();
                s.Start();
                var u = await _7ph;
                s.Stop();
                Console.WriteLine($"Calculations done for {n}x{n} in {s.Elapsed.TotalMilliseconds}ms!");
                // u.Print();
            }
        }
示例#22
0
        public AmazonSqsConnectionContext(IConnection connection, IAmazonSqsHostConfiguration configuration, IAmazonSqsHostTopology hostTopology,
                                          CancellationToken cancellationToken)
            : base(cancellationToken)
        {
            _configuration = configuration;
            Topology       = hostTopology;
            Connection     = connection;

            _taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);
        }
示例#23
0
        public ActiveMqSessionContext(ConnectionContext connectionContext, ISession session, CancellationToken cancellationToken)
            : base(new PayloadCacheScope(connectionContext), cancellationToken)
        {
            _connectionContext = connectionContext;
            _session           = session;

            _taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);

            _messageProducerCache = new MessageProducerCache();
        }
示例#24
0
 public SnaffCon(Config.Config conf)
 {
     Config                  = conf;
     SharefinderLcts         = new LimitedConcurrencyLevelTaskScheduler(Config.MaxThreads);
     SharefinderTaskFactory  = new TaskFactory(SharefinderLcts);
     SharefinderCts          = new CancellationTokenSource();
     SharescannerLcts        = new LimitedConcurrencyLevelTaskScheduler(Config.MaxThreads);
     SharescannerTaskFactory = new TaskFactory(SharescannerLcts);
     SharescannerCts         = new CancellationTokenSource();
 }
        public AmazonSqsModelContext(ConnectionContext connectionContext, IAmazonSQS amazonSqs, IAmazonSimpleNotificationService amazonSns, IAmazonSqsHost host, CancellationToken cancellationToken)
            : base(new PayloadCacheScope(connectionContext), cancellationToken)
        {
            _connectionContext = connectionContext;
            _amazonSqs         = amazonSqs;
            _amazonSns         = amazonSns;
            _host = host;

            _taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);
        }
示例#26
0
        public TaskManager()
        {
            // Create a scheduler that uses two threads.
            var taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);

            _taskList = new List <Task>();

            // Create a TaskFactory and pass it our custom scheduler.
            _factory = new TaskFactory(taskScheduler);
        }
示例#27
0
        public CommandExecutor(Logger logger, IServiceFactory serviceFactory, ITrackCommands trackCommands, IEventAggregator eventAggregator)
        {
            var scheduler = new LimitedConcurrencyLevelTaskScheduler(3);

            _logger          = logger;
            _serviceFactory  = serviceFactory;
            _trackCommands   = trackCommands;
            _eventAggregator = eventAggregator;
            _taskFactory     = new TaskFactory(scheduler);
        }
示例#28
0
        public Indexer(ISearchIndex searchIndex)
        {
            if (searchIndex == null)
            {
                throw new ArgumentNullException(nameof(searchIndex));
            }

            _searchIndex = searchIndex;
            _scheduler   = new LimitedConcurrencyLevelTaskScheduler(Environment.ProcessorCount);
        }
示例#29
0
        /// <summary>
        /// Creates a task factory to handle all file processing tasks.
        /// </summary>
        /// <returns></returns>
        private TaskFactory GetFileProcessingTaskFactory()
        {
            int maxFileProcessingConcurrency = Environment.ProcessorCount * logsharkRequest.Configuration.TuningOptions.FileProcessorConcurrencyLimitPerCore;

            Log.InfoFormat("Setting file processing concurrency limit to {0} concurrent files. ({1} logical {2} present)",
                           maxFileProcessingConcurrency, Environment.ProcessorCount, "core".Pluralize(Environment.ProcessorCount));
            LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(maxFileProcessingConcurrency);
            TaskFactory factory = new TaskFactory(lcts);

            return(factory);
        }
        public WindowsLowLevelOcrService()
        {
            var taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);

            factory    = new TaskFactory(taskScheduler);
            powershell = PowerShell.Create();
            string psScript = GetResourceText("Get-Text-Win-OCR.ps1");

            powershell.AddScript(psScript, false);
            powershell.Invoke();
        }
        RabbitMqConnectionContext(IConnection connection, RabbitMqHostSettings hostSettings, ITaskParticipant participant)
            : base(new PayloadCache(), participant.StoppedToken)
        {
            _connection = connection;
            _hostSettings = hostSettings;

            _participant = participant;

            _taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);

            connection.ConnectionShutdown += OnConnectionShutdown;
        }
        public MandelbrotServer()
        {
            TileWidth = size;
            TileHeight = size;

            MinLevel = 0;
            MaxLevel = 31;

            ServerName = "Mandelbrot";

            // todo number of processors being used is a problem - too small is slow, too big blocks all other threads, including rendering thread, so
            // application stops to respond.
            //TaskManagerPolicy policy = new TaskManagerPolicy(1, Environment.ProcessorCount, 1, 0, ThreadPriority.Lowest);
            //manager = new TaskManager(policy);
            manager = new LimitedConcurrencyLevelTaskScheduler(Environment.ProcessorCount*10);
            factory = new TaskFactory(manager);
        }
        RabbitMqModelContext(ConnectionContext connectionContext, IModel model, IRabbitMqHost host, ITaskParticipant participant)
            : base(new PayloadCacheScope(connectionContext))
        {
            _connectionContext = connectionContext;
            _model = model;
            _host = host;

            _participant = participant;

            _published = new ConcurrentDictionary<ulong, PendingPublish>();
            _taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);

            _model.ModelShutdown += OnModelShutdown;
            _model.BasicAcks += OnBasicAcks;
            _model.BasicNacks += OnBasicNacks;
            _model.BasicReturn += OnBasicReturn;

            if (host.Settings.PublisherConfirmation)
            {
                _model.ConfirmSelect();
            }

            _participant.SetReady();
        }
示例#34
0
        protected override bool Setup()
        {
            ReadConfigs();
            CreateTasks();

            mMapExporter = new GorgonMapExporter() { atlasHeight = 4096, atlasWidth = 4096 };
            mImageExporter = new PngImageExporter();

            var setup = base.Setup();
            var ptr = TextureManager.Singleton.CreateManual("RttTex",
                                                            ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                                                            TextureType.TEX_TYPE_2D,
                                                            148,
                                                            148,
                                                            0,
                                                            PixelFormat.PF_R8G8B8A8,
                                                            (int)TextureUsage.TU_RENDERTARGET
                );
            mRTT = ptr.GetBuffer().GetRenderTarget();
            mRTVP = mRTT.AddViewport(mCamera);
            mRTVP.BackgroundColour = new ColourValue(0, 0, 0, 0);
            mRTVP.SetClearEveryFrame(true);
            mRTVP.OverlaysEnabled = false;

            //Calculate diagonal distance value
            //mPythDistance = (mDistance / Mogre.Math.Sqrt(2));

            var altitude = new Degree(mCameraAngle);
            var angles = new float[]{
                180f, // South
                135f, // Southeast
                 90f, // East
                 45f, // Northeast
                  0f, // North
                -45f, // Northwest
                -90f, // West
               -135f, // Southwest
            };
            mCameraDirections = new List<string> {
                "s",
                "se",
                "e",
                "ne",
                "n",
                "nw",
                "w",
                "sw"
            };
            mCameraPositions = new List<Vector3>();
            for (var i = 0; i < 8; i++)
            {
                float azimuth = angles[i];
                string dirname = mCameraDirections[i];
                Vector3 pos = getPosOnSphere(mDistance, new Degree(-azimuth), -altitude);
                mCameraPositions.Add(pos);
                Console.WriteLine("Determined camera pos: {0,2} is {1,5:F2},{2,5:F2},{3,5:F2}", dirname, pos.x, pos.y, pos.z);
            }
            /*
            mCameraPositions = new List<Vector3> {
                new Vector3(0, mDistance, mDistance),                   // Front / South
                new Vector3(-mPythDistance, mDistance, mPythDistance),  // Front-right / southwest
                new Vector3(-mDistance, mDistance, 0),                  // Right / west
                new Vector3(-mPythDistance, mDistance, -mPythDistance), // Back-right / northwest
                new Vector3(0, mDistance, -mDistance),                  // Back / north
                new Vector3(mPythDistance, mDistance, -mPythDistance),  // Back-left / northeast
                new Vector3(mDistance, mDistance, 0),                   // Left / east
                new Vector3(mPythDistance, mDistance, mPythDistance),   // Front-left / southeast
            };
            */

            //CompositorManager.Singleton.AddCompositor(vp, "EdgeDetectCompositor", 0);
            //CompositorManager.Singleton.AddCompositor(rtvp, "EdgeDetectCompositor", 0);
            //CompositorManager.Singleton.SetCompositorEnabled(vp, "EdgeDetectCompositor", true);
            //CompositorManager.Singleton.SetCompositorEnabled(rtvp, "EdgeDetectCompositor", true);

            /*CompositorManager.Singleton.AddCompositor(vp, "Pixelate", 0);
            CompositorManager.Singleton.AddCompositor(mRTVP, "Pixelate", 0);
            CompositorManager.Singleton.SetCompositorEnabled(vp, "Pixelate", true);
            CompositorManager.Singleton.SetCompositorEnabled(mRTVP, "Pixelate", true);*/

            //CompositorManager.Singleton.AddCompositor(vp, "Normal", 0);
            //CompositorManager.Singleton.AddCompositor(rtvp, "Normal", 0);
            //CompositorManager.Singleton.SetCompositorEnabled(vp, "Normal", true);
            //CompositorManager.Singleton.SetCompositorEnabled(rtvp, "Normal", true);

            //CompositorManager.Singleton.AddCompositor(vp, "SMAA", 0);
            //CompositorManager.Singleton.AddCompositor(rtvp, "SMAA", 0);
            //CompositorManager.Singleton.SetCompositorEnabled(vp, "SMAA", true);
            //CompositorManager.Singleton.SetCompositorEnabled(rtvp, "SMAA", true);

            //CompositorManager.Singleton.AddCompositor(vp, "FXAA", 0);
            //CompositorManager.Singleton.AddCompositor(rtvp, "FXAA", 0);
            //CompositorManager.Singleton.SetCompositorEnabled(vp, "FXAA", true);
            //CompositorManager.Singleton.SetCompositorEnabled(rtvp, "FXAA", true);

            //Set up task scheduler
            imageTrimScheduler = new LimitedConcurrencyLevelTaskScheduler(3);
            imageTrimTaskFactory = new TaskFactory(imageTrimScheduler);
            imagePackScheduler = new LimitedConcurrencyLevelTaskScheduler(1);
            imagePackTaskFactory = new TaskFactory(imagePackScheduler);
            return setup;
        }
示例#35
0
        Run()
        {
            Log.Detail("Running build");

            // TODO: should the rank collections be sorted, so that modules with fewest dependencies are first?

            var graph = Graph.Instance;
            var metaDataType = graph.BuildModeMetaData.GetType();
            var useEvaluation = CheckIfModulesNeedRebuilding(metaDataType);
            var explainRebuild = CommandLineProcessor.Evaluate(new Options.ExplainBuildReason());
            var immediateOutput = CommandLineProcessor.Evaluate(new Options.ImmediateOutput());

            ExecutePreBuild(metaDataType);

            if (!System.IO.Directory.Exists(graph.BuildRoot))
            {
                System.IO.Directory.CreateDirectory(graph.BuildRoot);
            }

            var threadCount = CommandLineProcessor.Evaluate(new Options.MultiThreaded());
            if (0 == threadCount)
            {
                threadCount = System.Environment.ProcessorCount;
            }

            System.Exception abortException = null;
            if (threadCount > 1)
            {
                var cancellationSource = new System.Threading.CancellationTokenSource();
                var cancellationToken = cancellationSource.Token;

                // LongRunning is absolutely necessary in order to achieve paralleism
                var creationOpts = System.Threading.Tasks.TaskCreationOptions.LongRunning;
                var continuationOpts = System.Threading.Tasks.TaskContinuationOptions.LongRunning;

                var scheduler = new LimitedConcurrencyLevelTaskScheduler(threadCount);

                var factory = new System.Threading.Tasks.TaskFactory(
                        cancellationToken,
                        creationOpts,
                        continuationOpts,
                        scheduler);

                var tasks = new Array<System.Threading.Tasks.Task>();
                foreach (var rank in graph.Reverse())
                {
                    foreach (var module in rank)
                    {
                        var context = new ExecutionContext(useEvaluation, explainRebuild, immediateOutput);
                        var task = factory.StartNew(() =>
                            {
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }
                                var depTasks = new Array<System.Threading.Tasks.Task>();
                                foreach (var dep in module.Dependents)
                                {
                                    if (null == dep.ExecutionTask)
                                    {
                                        continue;
                                    }
                                    depTasks.Add(dep.ExecutionTask);
                                }
                                foreach (var dep in module.Requirements)
                                {
                                    if (null == dep.ExecutionTask)
                                    {
                                        continue;
                                    }
                                    depTasks.Add(dep.ExecutionTask);
                                }
                                System.Threading.Tasks.Task.WaitAll(depTasks.ToArray());
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }

                                try
                                {
                                    (module as IModuleExecution).Execute(context);
                                }
                                catch (Exception ex)
                                {
                                    abortException = ex;
                                    cancellationSource.Cancel();
                                }
                                finally
                                {
                                    if (context.OutputStringBuilder != null && context.OutputStringBuilder.Length > 0)
                                    {
                                        Log.Info(context.OutputStringBuilder.ToString());
                                    }
                                    if (context.ErrorStringBuilder != null && context.ErrorStringBuilder.Length > 0)
                                    {
                                        Log.Info(context.ErrorStringBuilder.ToString());
                                    }
                                }
                            });
                        tasks.Add(task);
                        module.ExecutionTask = task;
                    }
                }
                try
                {
                    System.Threading.Tasks.Task.WaitAll(tasks.ToArray());
                }
                catch (System.AggregateException exception)
                {
                    if (!(exception.InnerException is System.Threading.Tasks.TaskCanceledException))
                    {
                        throw new Exception(exception, "Error during threaded build");
                    }
                }
            }
            else
            {
                foreach (var rank in graph.Reverse())
                {
                    if (null != abortException)
                    {
                        break;
                    }
                    foreach (IModuleExecution module in rank)
                    {
                        var context = new ExecutionContext(useEvaluation, explainRebuild, immediateOutput);
                        try
                        {
                            module.Execute(context);
                        }
                        catch (Exception ex)
                        {
                            abortException = ex;
                            break;
                        }
                        finally
                        {
                            if (context.OutputStringBuilder != null && context.OutputStringBuilder.Length > 0)
                            {
                                Log.Info(context.OutputStringBuilder.ToString());
                            }
                            if (context.ErrorStringBuilder != null && context.ErrorStringBuilder.Length > 0)
                            {
                                Log.Info(context.ErrorStringBuilder.ToString());
                            }
                        }
                    }
                }
            }

            if (null != abortException)
            {
                throw new Exception(abortException, "Error during {0}threaded build", (threadCount > 1) ? string.Empty : "non-");
            }

            ExecutePostBuild(metaDataType);
        }
示例#36
0
        CheckIfModulesNeedRebuilding(
            System.Type metaType)
        {
            // not all build modes need to determine if modules are up-to-date
            var evaluationRequiredAttr =
                metaType.GetCustomAttributes(typeof(EvaluationRequiredAttribute), false) as EvaluationRequiredAttribute[];
            if (0 == evaluationRequiredAttr.Length)
            {
                Log.DebugMessage("No Bam.Core.EvaluationRequired attribute on build mode metadata, assume rebuilds necessary");
                return false;
            }

            if (!evaluationRequiredAttr[0].Enabled)
            {
                Log.DebugMessage("Module evaluation disabled");
                return false;
            }

            Log.DebugMessage("Module evaluation enabled");

            var cancellationSource = new System.Threading.CancellationTokenSource();
            var cancellationToken = cancellationSource.Token;

            // LongRunning is absolutely necessary in order to achieve paralleism
            var creationOpts = System.Threading.Tasks.TaskCreationOptions.LongRunning;
            var continuationOpts = System.Threading.Tasks.TaskContinuationOptions.LongRunning;

            var threadCount = 1;
            var scheduler = new LimitedConcurrencyLevelTaskScheduler(threadCount);

            var factory = new System.Threading.Tasks.TaskFactory(
                    cancellationToken,
                    creationOpts,
                    continuationOpts,
                    scheduler);

            var graph = Graph.Instance;
            graph.MetaData = factory;

            foreach (var rank in graph.Reverse())
            {
                foreach (Module module in rank)
                {
                    module.Evaluate();
                }
            }

            return true;
        }