public void SetUp() { _mockOfficeHoursProvider = new Mock <IOfficeHoursProvider>(); _batchProcessor = new BatchProcessor(); }
public void ProcessInterfaceDirector(ResourceActivationContext context, InterfaceDirector director) { if (context.IsClosed) { return; } context.Open(); if (director.Commands == null || director.Commands.Length == 0) { context.Close(); return; } BatchProcessor iter = new BatchProcessor(director.Commands.Length, context.Close); foreach (var command in director.Commands) { IInterfaceCommandHandler handler = null; if (m_handlers.TryGetValue(command.Type, out handler)) { handler.ProcessInterfaceCommand(context, command, () => iter++); } else { throw new NotSupportedException("Unsupported interface command type " + command.Type); } } }
private HttpResponseMessage PrvUpdateNews(int maxPages, string age, int updateProgressInDatabase) { var operationId = Guid.NewGuid().ToString(); var operation = new OperationInfo { Id = operationId, Status = OperationStatus.Pending, CancellationTokenSource = new CancellationTokenSource() }; if (!Operations.TryAdd(operationId, operation)) { return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Cannot start operation")); } var processor = new BatchProcessor(updateProgressInDatabase == 1); processor.ProcessTorrentNews(maxPages, age, operation); var cancellationUrl = Url.Link("DefaultApi", new { controller = "TorrentNews", action = "CancelOperation", id = operationId, secret = "secret_here" }); var statusUrl = Url.Link("DefaultApi", new { controller = "TorrentNews", action = "RetrieveOperationStatus", id = operationId, secret = "secret_here" }); var res = new OperationAcceptedResult { OperationId = operationId, CancellationUrl = cancellationUrl, StatusUrl = statusUrl }; return(this.Request.CreateResponse(HttpStatusCode.Accepted, res)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 10_000) public void shouldProcessAllBatchesOnSingleCoreSystems() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldProcessAllBatchesOnSingleCoreSystems() { // GIVEN StageControl control = mock(typeof(StageControl)); int processors = 1; int batches = 10; BatchProcessor step = new BatchProcessor(control, processors); TrackingStep downstream = new TrackingStep(); step.Downstream = downstream; // WHEN step.Start(0); for (int i = 1; i <= batches; i++) { step.Receive(i, new Batch(processors)); } step.EndOfUpstream(); step.AwaitCompleted(); step.Close(); // THEN assertEquals(batches, downstream.Received.get()); }
void IDisposable.Dispose() { if (_batchProcessorLazy.IsValueCreated) { BatchProcessor.Dispose(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void mustNotDetachProcessorsFromBatchChains() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MustNotDetachProcessorsFromBatchChains() { // GIVEN StageControl control = mock(typeof(StageControl)); int processors = 1; int batches = 10; BatchProcessor step = new BatchProcessor(control, processors); TrackingStep downstream = new TrackingStep(); step.Downstream = downstream; int delta = processors - step.Processors(0); step.Processors(delta); // WHEN step.Start(0); for (int i = 1; i <= batches; i++) { step.Receive(i, new Batch(processors)); } step.EndOfUpstream(); step.AwaitCompleted(); step.Close(); // THEN assertEquals(batches, downstream.Received.get()); }
public void SupportedJobTypes(FundingLineCsvGeneratorJobType jobType, bool expectedIsSupportedFlag) { BatchProcessor.IsForJobType(jobType) .Should() .Be(expectedIsSupportedFlag); }
public async Task <IActionResult> PostBatch(BatchIpsModel iPs) { try { BatchProcessor br = new BatchProcessor(_mapper, _repository, _repositoryDB); Guid batchid = await br.ProccessIps(iPs); var batchAdded = await _batchProcessingChannel.AddBatchAsync(batchid); if (batchAdded) { var link = _linkGenerator.GetPathByAction( HttpContext, "Get", values: new { id = batchid }); var fullLink = $" { HttpContext.Request.Scheme }://{ HttpContext.Request.Host}{link}"; return(Created(link, fullLink)); } return(this.StatusCode(StatusCodes.Status500InternalServerError)); } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task RecentTracksTest() { var batch = new BatchProcessor(); int i = await Task.Run(() => batch.ProcessRecentTracks()); Console.WriteLine("Processed " + i); Assert.Inconclusive(); }
public async Task ProcessLibrary() { var batch = new BatchProcessor(); int i = await Task.Run(() => batch.ProcessLibrary()); Console.WriteLine("Processed " + i); Assert.Inconclusive(); }
public void TestCleanup() { //Generic cleanup if (processor != null) { processor.ShutdownAsync().Wait(); processor = null; } }
static void Main(string[] args) { Params arguments = Params.ParseParams(args); if(arguments.IsValid) { BatchProcessor processor = new BatchProcessor(arguments); processor.Run(); } }
protected void InitializeBlocks( CancellationToken token, int size = 50, int interval = 1, int degree = 5, bool isWaiting = true) { WriteDirectly = new DataWriteDirectlyService(); this.Processor = new BatchProcessor <IDataEntity>(WriteDirectly.Save, size, interval, degree, isWaiting); this.Processor.Initialize(token); }
/// <summary>Initializes a batcher.</summary> /// <remarks>Initializes a batcher.</remarks> /// <param name="workExecutor">the work executor that performs actual work</param> /// <param name="capacity">The maximum number of objects to batch up. If the queue reaches this size, the queued objects will be sent to the processor immediately. /// </param> /// <param name="delay">The maximum waiting time to collect objects before processing them. In some circumstances objects will be processed sooner. /// </param> /// <param name="processor">The callback/block that will be called to process the objects. /// </param> public Batcher(ScheduledExecutorService workExecutor, int capacity, int delay, BatchProcessor <T> processor) { processNowRunnable = new _Runnable_31(this); this.workExecutor = workExecutor; this.capacity = capacity; this.delay = delay; this.processor = processor; }
public RecoveryActor(ImportProcessor importProcessor, BatchProcessor batchProcessor, TaskProcessor taskProcessor, List <TaskActor> taskActors) { _importProcessor = importProcessor; _batchProcessor = batchProcessor; _taskProcessor = taskProcessor; _taskActors = taskActors; }
public void StopAllProcessors(Action onComplete) { var running = m_runningProcessors.Values.ToArray(); m_runningProcessors.Clear(); BatchProcessor.Process(running, (proc, onStop) => { proc.StopRunning(onStop); }, onComplete); }
public BrokerActor(ImportProcessor importProcessor, BrokerTransactionScraper brokerTransactionScraper, BatchProcessor batchProcessor, TaskProcessor taskProcessor, IConfiguration configuration) { _importProcessor = importProcessor; _brokerTransactionScraper = brokerTransactionScraper; _configuration = configuration; _batchProcessor = batchProcessor; _taskProcessor = taskProcessor; }
protected virtual void Dispose(bool disposing) { if (!disposing) { return; } if (_batchProcessorLazy.IsValueCreated) { BatchProcessor.Dispose(); } }
public IActionResult Get(Guid id) { try { BatchProcessor br = new BatchProcessor(_mapper, _repository, _repositoryDB); return(Ok(br.ProgressReport(id))); } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError)); } }
private static void Main(string[] args) { { Params arguments = new Params(args); if (arguments.IsValid) { BatchProcessor processor = new BatchProcessor(arguments); processor.Run(); } arguments = null; } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldProcessAllMultiThreadedAndWithChangingProcessorCount() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldProcessAllMultiThreadedAndWithChangingProcessorCount() { // GIVEN StageControl control = mock(typeof(StageControl)); int availableProcessors = Runtime.Runtime.availableProcessors(); BatchProcessor step = new BatchProcessor(control, availableProcessors); TrackingStep downstream = new TrackingStep(); step.Downstream = downstream; // WHEN step.Start(0); AtomicLong nextTicket = new AtomicLong(); Thread[] submitters = new Thread[3]; AtomicBoolean end = new AtomicBoolean(); for (int i = 0; i < submitters.Length; i++) { submitters[i] = new Thread(() => { ThreadLocalRandom random = ThreadLocalRandom.current(); while (!end.get()) { lock ( nextTicket ) { if (random.nextFloat() < 0.1) { step.Processors(random.Next(-2, 4)); } long ticket = nextTicket.incrementAndGet(); Batch batch = new Batch(step.Processors(0)); step.Receive(ticket, batch); } } }); submitters[i].Start(); } while (downstream.Received.get() < 200) { Thread.Sleep(10); } end.set(true); foreach (Thread submitter in submitters) { submitter.Join(); } step.EndOfUpstream(); step.Close(); }
public async Task TestSimpleSetup(BatchHandler<object, object> batchHandler, double minimumTimeIntervalMs = 1000, double maximumTimeIntervalMs = -1, int maximumCount = -1, UnprocessedItemAction unprocessedItemAction = UnprocessedItemAction.ReturnDefaultValue) { //Add an item to the queue, and then wait the minimum amount of time specified on the batch processor and check that our //item was processed processor = new BatchProcessor<object, object>(); processor.UnprocessedItemAction = unprocessedItemAction; if (!await processor.StartupAsync( batchHandler, TimeSpan.FromMilliseconds(minimumTimeIntervalMs), (maximumTimeIntervalMs == -1 ? TimeSpan.MaxValue : TimeSpan.FromMilliseconds(maximumTimeIntervalMs)), maximumCount)) { Assert.Inconclusive("Failed to startup batch processor"); } }
private static void Main(string[] args) { // ContextTesting is a class that has been temporarily created to test multiple files // ContextTesting.Run(); // return; var arguments = new Params(args); if (!arguments.IsValid) { return; } var processor = new BatchProcessor(arguments); processor.Run(); }
private void Start() { if (!IsPaired) { var message = $"{ToString()} - Connection cannot be started without pairing first."; throw new InvalidOperationException(message); } lock (stateLock) { EnsureCorrectState(CnxState.Created); var batchProcessor = new BatchProcessor(this, serviceHost, transport, logger); Task.Run(() => batchProcessor.ProcessAsync(cancelTokenSource.Token)); state = CnxState.Connected; } }
/// <summary> /// Initialize the components and start the timer /// </summary> /// <param name="sender">Sender</param> /// <param name="e">EventArgs</param> private void FrmMain_Load(object sender, EventArgs e) { try { batchProcessor = new BatchProcessor(); sessionManager = new SessionManager(); batchManager = new BatchManager(batchProcessor, sessionManager); UpdateUI(); timerBatchPolling.Enabled = true; } catch (Exception exception) { throw exception; } }
// POST api/values public IHttpActionResult Post(BatchCommand command) { var filepath = HttpContext.Current.Server.MapPath("~/"); if (command == null) { return(BadRequest("Post value is null")); } if (!ModelState.IsValid) { return(new InvalidModelStateResult(ModelState, this)); } BatchProcessor batch = new BatchProcessor(command); batch.StartNewAndWriteToFile(filepath); return(Ok(filepath)); }
protected ChangeFeedProcessorBase( BatchProcessor batchProcessor, DbSerializerBase serializer, Container databaseContainer, Container leaseContainer, string processorName, int maxItemsPerBatch = DefaultMaxItemsPerBatch, TimeSpan?pollInterval = null, DateTime?startTime = null) { if (string.IsNullOrWhiteSpace(processorName)) { throw new ArgumentNullException(nameof(processorName)); } if (maxItemsPerBatch < 1) { throw new ArgumentOutOfRangeException(nameof(maxItemsPerBatch)); } if (maxItemsPerBatch > MaxMaxItemsPerBatch) { maxItemsPerBatch = MaxMaxItemsPerBatch; } MaxItemsPerBatch = maxItemsPerBatch; Serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); PollInterval = pollInterval ?? DefaultPollInterval; if (PollInterval < TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(pollInterval)); } if (PollInterval < MinPollInterval) { PollInterval = MinPollInterval; } else if (PollInterval > MaxPollInterval) { PollInterval = MaxPollInterval; } StartTime = startTime ?? IsoDateCheater.MinValue; BatchProcessor = batchProcessor ?? throw new ArgumentNullException(nameof(batchProcessor)); ProcessorName = processorName; DatabaseContainer = databaseContainer ?? throw new ArgumentNullException(nameof(databaseContainer)); LeaseContainer = leaseContainer ?? throw new ArgumentNullException(nameof(leaseContainer)); }
// This function holds the batch process. // The contents are currently a placeholder for demonstration private void batchProcess() { BatchProcessor batch = new BatchProcessor(session); batchTestLabel.Text = "Starting..."; Refresh(); if (batch.run()) { picBatch.Image = Resources.check; batchTestLabel.Text = "Finished Successfully!"; } else { picBatch.Image = Resources.error; batchTestLabel.Text = "Errors Encountered, See Log.txt For More Information."; } }
public void StopAll(Action onComplete = null, bool reset = false) { if (m_runningItems.Count == 0) { if (onComplete != null) { onComplete(); } } else { var iter = new BatchProcessor(m_runningItems.Count, onComplete); foreach (var q in m_runningItems.ToArray()) { Stop(q, () => { iter++; }, reset); } } }
public IHttpActionResult Get() { BatchCommand command = new BatchCommand(); command.Title = "TEST TITLE"; command.Description = "TEST DESCRIPTION"; command.Actions = new GroupAction[2]; command.Actions[0] = new GroupAction() { CategoryName = "Creator", GroupBy = "creator" }; command.Actions[1] = new GroupAction() { CategoryName = "material", GroupBy = "material" }; command.Mappings = new XmlMappings(); command.Mappings.Title = "title"; command.Mappings.Description = "description"; command.Mappings.Begindate = "production.date.start"; command.Mappings.Enddate = "production.date.end"; command.Mappings.Id = "priref"; command.Mappings.Images = "reproduction.reference"; command.BaseUrl = "http://amdata.adlibsoft.com/"; command.Database = "AMCollect"; command.ImagesLocation = "http://ahm.adlibsoft.com/ahmimages/"; var filepath = HttpContext.Current.Server.MapPath("~/"); if (command == null) { return(BadRequest("Post value is null")); } if (!ModelState.IsValid) { return(new InvalidModelStateResult(ModelState, this)); } BatchProcessor batch = new BatchProcessor(command); batch.StartNewAndWriteToFile(filepath); return(Ok(filepath)); }
public virtual async Task <TDbEntity?> Get(TKey key, CancellationToken cancellationToken = default) => await BatchProcessor.Process(key, cancellationToken).ConfigureAwait(false);
public void SetUp() { _repository = new Repository(); _sut = new BatchProcessor(_repository); }
public void ReloadFromServer(Action onSuccess, Action <string> onFail) { MediaDownloadManager.Reset(); m_completeSuccessHandler = onSuccess; m_completeFailHandler = onFail; foreach (var call in m_preloadActions.ToArray()) { call(); } SetDownloadState(WebServicesDownloadState.Resolving); Action configLoadComplete = () => { ThreadHelper.Instance.CallOnMainThread(() => { foreach (var obj in ScriptObjectDirectory.Instance.AllObjects) { if (obj is IMediaItemProvider) { MediaDownloadManager.AddMediaItemProvider((IMediaItemProvider)obj); } } if (m_catalogLoadActions.Count > 0) { BatchProcessor iter = new BatchProcessor(m_catalogLoadActions.Count, DownloadMedia); foreach (var call in m_catalogLoadActions) { call(() => { iter++; }); } } else { DownloadMedia(); } }); }; if (!string.IsNullOrEmpty(ConfigName)) { var cfgManager = StorageManager.GetAppStorageManager().GetManager("downloads", SpaceName, "config"); if (InternetReachability == NetworkReachability.NotReachable) { bool result = false; if (!RequireNetworkConnection) { result = ProjectConfigService.Instance.LoadFromCache(cfgManager, ConfigName, ShouldUseDevCatalogs); } if (result) { configLoadComplete(); } else { SetDownloadError(ServiceCallLoadStatus.ServiceCallFail); } } else { ProjectConfigService.Instance.Load(cfgManager, MotiveUrl, SpaceName, ConfigName, ShouldUseDevCatalogs, (status) => { if (status == ServiceCallLoadStatus.Success) { configLoadComplete(); } else { SetDownloadError(status); } }); } } else { configLoadComplete(); } }
public async Task <TEntity> TryGetAsync(TKey key, CancellationToken cancellationToken = default) => await BatchProcessor.ProcessAsync(key, cancellationToken).ConfigureAwait(false);