/// <summary> /// Convert excel items to List of earnings and deductions /// </summary> /// <param name="filePath">The file path</param> /// <returns>Collection of earnings and deductions</returns> private List <EarningsAndDeductionItem> ExcelToList(string filePath) { BlockingCollection <EarningsAndDeductionItem> earningsAndDeductionItems = new BlockingCollection <EarningsAndDeductionItem>(); FileInfo fileInfo = new FileInfo(filePath); using (var package = new ExcelPackage(fileInfo)) { ExcelWorksheet worksheet = package.Workbook.Worksheets[0]; var rowCount = worksheet.Dimension.Rows; Parallel.For(2, rowCount, row => { var request = new EarningsAndDeductionItem { EmployeeId = worksheet.Cells[row, 1].Value.ToString().Trim(), PayCode = worksheet.Cells[row, 2].Value.ToString().Trim(), PayDateFrom = DateTime.FromOADate((double)worksheet.Cells[row, 3].Value), PayDateTo = DateTime.FromOADate((double)worksheet.Cells[row, 4].Value), CoverageDateFrom = DateTime.FromOADate((double)worksheet.Cells[row, 5].Value), CoverageDateTo = DateTime.FromOADate((double)worksheet.Cells[row, 6].Value), Amount = worksheet.Cells[row, 7].Value.ToString().Trim(), Remarks = worksheet.Cells[row, 8].Value != null ? worksheet.Cells[row, 8].Value.ToString().Trim() : string.Empty, Action = worksheet.Cells[row, 9].Value.ToString().Trim(), TransactionId = worksheet.Cells[row, 10].Value != null ? worksheet.Cells[row, 10].Value.ToString().Trim() : string.Empty, SequenceNumber = row }; earningsAndDeductionItems.Add(request); }); } return(earningsAndDeductionItems.OrderBy(x => x.SequenceNumber).ToList()); }
public IActionResult CreatePresignedUrl([FromBody] PresignedUrlRequest request) { var requests = request.PartNumbers.Select(partNumber => new GetPreSignedUrlRequest { BucketName = request.BucketName, Key = request.Key, Verb = HttpVerb.PUT, UploadId = request.UploadId, PartNumber = partNumber, ContentType = request.ContentType, Expires = DateTime.UtcNow.AddMinutes(30), }); var responses = new BlockingCollection <CreatePresignedUrlsResponse>(); Parallel.ForEach(requests, (request) => { responses.Add(new CreatePresignedUrlsResponse { PartNumber = request.PartNumber, PresignedUrl = _s3.GetPreSignedURL(request) }); }); return(new OkObjectResult(responses.OrderBy(x => x.PartNumber))); }
/// <summary> /// Faster proximity between this and othe Polyline. Intersections added, Using Parallel Threading /// </summary> /// <param name="other">Other polyline to compute proximity with</param> /// <param name="parameters">Tuple -> distance, param t on this curve, param t on other curve</param> /// <returns>Tuple -> point on this, point on other</returns> public Tuple <Point3d, Point3d> Proximity(Polyline other, out Tuple <double, double, double> parameters) { int roudInt = 9; BlockingCollection <Tuple <double, double, double> > result = new BlockingCollection <Tuple <double, double, double> >(); BlockingCollection <Tuple <double, double, double> > resultIntersecting = new BlockingCollection <Tuple <double, double, double> >(); Parallel.For(0, this.SegmentCount, i => { Line LineA = this.SegmentAt(i); List <Tuple <double, double, double> > localResult = new List <Tuple <double, double, double> >(); for (int j = 0; j < other.SegmentCount; j++) { Line LineB = other.SegmentAt(j); double a; double b; double distance = LineA.MinimumDistanceTo(LineB, out a, out b); localResult.Add(Tuple.Create(distance, Math.Round(a + i, roudInt), Math.Round(b + j, roudInt))); } result.Add(localResult.OrderBy(data => data.Item1).First()); }); result.CompleteAdding(); parameters = result.OrderBy(data => data.Item1).First(); return(Tuple.Create(this.PointAt(parameters.Item2), other.PointAt(parameters.Item3))); }
/// <inheritdoc/> public IList <CreatePresignedUrlResponse> CreatePresignedUrl(PresignedUrlRequest request, ILambdaContext context) { context.Logger.Log(_environment.GetEnvironmentVariable("BUCKET_NAME")); var presignedUrlRequests = request.PartNumbers.Select(partNumber => new GetPreSignedUrlRequest { BucketName = _environment.GetEnvironmentVariable("BUCKET_NAME"), Key = ConstructFileKey(request.FileName, request.FolderName), Verb = HttpVerb.PUT, UploadId = request.UploadId, PartNumber = partNumber, ContentType = request.ContentType, Expires = DateTime.UtcNow.AddMinutes(30), }); var responseCollection = new BlockingCollection <CreatePresignedUrlResponse>(); Parallel.ForEach(presignedUrlRequests, (request) => { responseCollection.Add(new CreatePresignedUrlResponse { PartNumber = request.PartNumber, PresignedUrl = _s3.GetPreSignedURL(request) }); }); return(responseCollection.OrderBy(x => x.PartNumber).ToList()); }
public IEnumerable <string> BufferBlockUsageWithFilters(int numberOfIteration, int valueToFilterForSub1, int valueToFilterForSub2) { Console.WriteLine($"Inside {nameof(TplDataflow2BufferingBlocksController)} - {nameof(BufferBlockUsageWithFilters)}"); // Convert input int into char var charToFilterForSub1 = (char)(valueToFilterForSub1 % 10 + 0x30); var char1ToFilterForSub2 = (char)(valueToFilterForSub2 % 10 + 0x30); var char2ToFilterForSub2 = (char)(valueToFilterForSub2 % 10 + 0x31); var char3ToFilterForSub2 = (char)(valueToFilterForSub2 % 10 + 0x32); var strings = new BlockingCollection <string> { $"Sub 1 - Will filter and keep only input containing '{charToFilterForSub1}'", $"Sub 2 - Will filter and keep only input containing '{char1ToFilterForSub2}' and '{char2ToFilterForSub2}' and '{char3ToFilterForSub2}'", $"Sub 3 - Will keep all other values, without filters" }; // Create the members of the pipeline. var bufferBlockGivenInputToSubscribers = new BufferBlock <string>(); var actionBlockSubscriber1 = new ActionBlock <string>(stringInput => Functions.AddInputIntoTheGivenList(strings, stringInput, "Sub 1 abc") ); var actionBlockSubscriber2 = new ActionBlock <string>(stringInput => Functions.AddInputIntoTheGivenList(strings, stringInput, "Sub 2 def") ); var actionBlockSubscriber3 = new ActionBlock <string>(stringInput => Functions.AddInputIntoTheGivenList(strings, stringInput, "Sub 3 ghi") ); // Connect the dataflow blocks to form a pipeline. bufferBlockGivenInputToSubscribers.LinkTo(actionBlockSubscriber1, DataflowOptions.LinkOptions, s => s.Contains(charToFilterForSub1) ); bufferBlockGivenInputToSubscribers.LinkTo(actionBlockSubscriber2, DataflowOptions.LinkOptions, s => s.IndexOfAny(new[] { char1ToFilterForSub2, char2ToFilterForSub2, char3ToFilterForSub2 }) > 0 ); bufferBlockGivenInputToSubscribers.LinkTo(actionBlockSubscriber3, DataflowOptions.LinkOptions); // Start BufferBlockUsageWithFilters pipeline with the input values. for (var i = 1; i <= numberOfIteration; i++) { bufferBlockGivenInputToSubscribers.Post($"Value = {i}"); } // Mark the head of the pipeline as complete. bufferBlockGivenInputToSubscribers.Complete(); // Waiting block to receive all post input. Task.WaitAll(actionBlockSubscriber1.Completion, actionBlockSubscriber2.Completion, actionBlockSubscriber3.Completion); return(strings.OrderBy(s => s)); }
public async override Task <Message> OnGetMessage(MessageOperation message, CancellationToken cancellationToken) { Message outMessage = default(Message); int countCalls = await CheckDailyLimit(message); if (countCalls >= configuration.MaxCallTimes) { return(new MaxLimitMessage(countCalls)); } else if (message.Operation == "slug") { SlugCollection slugCollection = await _ebayService.GetSlugsAsync(message.Data); outMessage = new Message <SlugCollection> { Data = slugCollection }; } else if (message.Operation == "product") { var result = await _ebayService.GetProductAsync(message.Data); outMessage = new Message <Product> { Data = result }; } else if (message.Operation == "complete") { SlugCollection slugCollection = await _ebayService.GetSlugsAsync(message.Data); string[] slugArray = slugCollection.Distinct().ToArray(); BlockingCollection <Product> productCollection = new BlockingCollection <Product>(slugArray.Length); for (int i = 0; i < slugArray.Length; i++) { productCollection.Add(await _ebayService.GetProductAsync(slugArray[i])); } var orderedProductCollection = productCollection.OrderBy(p => p.Name).ToArray(); outMessage = new Message <Product[]> { Data = orderedProductCollection }; } await AddSearchToLog(message); if (outMessage != null) { return(outMessage); } return(await base.OnGetMessage(message, cancellationToken)); }
public List <StockSZ> GetStockSZList() { BlockingCollection <StockSZ> lst = new BlockingCollection <StockSZ>(); int pageCount = this.GetStockSZListCount(); Parallel.For(0, pageCount, (i) => { var stocks = this.GetSZStocksByPage(string.Concat(this.baseUrl, i + 1)); foreach (var stock in stocks) { lst.Add(stock); } }); return(lst.OrderBy(o => o.zqdm).ToList()); }
public void Finish() { if (_stream == null) { return; } _scaledFrame.CompleteAdding(); _task.Wait(); foreach (var frame in _resultingFrame.OrderBy(f => f.Sequence)) { AddFrame(frame.Gif, frame.Rectangle, frame.Delay); } _stream.Write((byte)0x3b); _stream.Close(); }
public void loadVhHistoricalInfo() { string[] file_rows_data = File.ReadAllLines(@"C:\LogFiles\OHxC\VehicleHistoricalInfo.log", System.Text.Encoding.Default); BlockingCollection <Vo.VehicleHistoricalInfo> listTemp = new BlockingCollection <Vo.VehicleHistoricalInfo>(); Parallel.For(0, file_rows_data.Count(), rowCount => { Vo.VehicleHistoricalInfo Historyinfo = new Vo.VehicleHistoricalInfo(); MatchCollection matches = Regex.Matches(file_rows_data[rowCount], pattern); string sTime = matches.Count > 0 ? matches[0].Value.Replace("[", "").Replace("]", "") : string.Empty; string sVh_ID = matches.Count > 1 ? matches[1].Value.Replace("[", "").Replace("]", "") : string.Empty; string sRaw_data = matches.Count > 2 ? matches[2].Value.Replace("[", "").Replace("]", "") : string.Empty; DateTime parseDateTime = default(DateTime); if (!DateTime.TryParseExact (sTime, sc.App.SCAppConstants.DateTimeFormat_23, CultureInfo.InvariantCulture, DateTimeStyles.None, out parseDateTime)) { logger.Warn($"{nameof(sTime)} parse fail. value{sTime}"); } byte[] vh_info_bytes = Common.WinFromUtility.unCompressString(sRaw_data); sc.ProtocolFormat.OHTMessage.VEHICLE_INFO vh_info = sc.BLL.VehicleBLL.Convert2Object_VehicleInfo(vh_info_bytes); Historyinfo.Time = parseDateTime; Historyinfo.ID = sVh_ID; Historyinfo.VhInfo = vh_info; listTemp.Add(Historyinfo); // 每處理幾筆就停止5ms if (rowCount != 0 && rowCount % 20000 == 0) { System.Threading.SpinWait.SpinUntil(() => false, 5); } }); vh_historical_infos = listTemp.OrderBy(info => info.Time).ToList(); StartPlayTime = vh_historical_infos.First().Time; var groupResult = from vh_historical_info in vh_historical_infos group vh_historical_info by vh_historical_info.Time; Vh_Historical_Info_GroupByTime = groupResult.OrderBy(infos => infos.Key).ToDictionary (infos => infos.Key, infos => infos.ToList()); currentPlayIndex = 0; //foreach (var info in vh_historical_infos) //{ // Console.WriteLine(info.VhInfo.ToString()); //} }
private async Task TestEPub() { var chapters = JsonConvert.DeserializeObject <List <ChapterInfo> >( File.ReadAllText(_cfg.ChapterJson)) .Select((o, i) => { o.Idx = i; return(o); }).ToList(); BlockingCollection <ChapterContent> processedData = new BlockingCollection <ChapterContent>(); BufferBlock <ChapterInfo> bufferBlock = new BufferBlock <ChapterInfo>(new DataflowBlockOptions() { BoundedCapacity = 100 }); int bl = 0; int total = chapters.Count; int len = total.ToString().Length; ActionBlock <ChapterInfo> processContent = new ActionBlock <ChapterInfo>(chapterInfo => { processedData.Add(_driver.GetChapterContent(chapterInfo)); _cfg.LogQueue.Enqueue($"Parsed: {chapterInfo.Idx} - {chapterInfo.Title} - {chapterInfo.Link}"); }, new ExecutionDataflowBlockOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }); bufferBlock.LinkTo(processContent, new DataflowLinkOptions() { PropagateCompletion = true }); chapters.ForEach((chap) => { bufferBlock.SendAsync(chap).Wait(); }); bufferBlock.Complete(); bufferBlock.Completion.Wait(); processContent.Complete(); processContent.Completion.Wait(); var ePubStream = File.Create($"{_dir}.epub"); using (var writer = await EPubWriter.CreateWriterAsync( ePubStream, Regex.Replace(Regex.Replace($"{_dir}", "[^a-zA-Z0-9]", " "), "\\s+", " "), "tntdb", "08915002", new CultureInfo("vi-VN"))) { // Optional parameter writer.Publisher = "tntdb"; bl = 0; foreach (var chapterContent in processedData.OrderBy(o => o.Idx).ToList()) { Interlocked.Increment(ref bl); _cfg.LogQueue.Enqueue($"Creating chapter {bl.ToString().PadLeft(len, ' ')} / {(total-bl).ToString().PadLeft(len, ' ')} : {chapterContent.FileName}"); // var idx = chapters.IndexOf(chap); writer.AddChapterAsync( chapterContent.FileName, chapterContent.Title, chapterContent.Content).Wait(); } // Add a chapter with string content as x-html await writer.WriteEndOfPackageAsync(); } _cfg.LogQueue.Enqueue("Process done!"); _cfg.Done = true; }
public void loadVhHistoricalInfo(DateTime start_time, DateTime end_time) { var node = new Uri($"http://{Common.ElasticSearchManager.ELASTIC_URL}:9200"); // var node = new Uri("http://192.168.9.211:9200"); var settings = new ConnectionSettings(node).DefaultIndex("default"); settings.DisableDirectStreaming(); var client = new ElasticClient(settings); //SearchRequest sr = new SearchRequest("ohtc-test-objecthistoricalinfo*"); SearchRequest sr = new SearchRequest("mfoht100-ohtc1-objecthistoricalinfo*"); DateRangeQuery dq = new DateRangeQuery { Field = "@timestamp", GreaterThan = start_time, LessThan = end_time, }; //TermsQuery tsq = new TermsQuery //{ //}; int startIndex = 0; int eachSearchSize = 9999; List <ObjectHistricalInfo> object_infos = new List <ObjectHistricalInfo>(); do { sr.From = startIndex; sr.Size = eachSearchSize; dq = new DateRangeQuery { Field = "@timestamp", GreaterThan = start_time, LessThan = end_time, }; sr.Query = dq; sr.Source = new SourceFilter() { Includes = new string[] { "@timestamp", "OBJECT_ID", "RAWDATA" }, }; var result = client.Search <ObjectHistricalInfo>(sr); if (result.Documents.Count == 0) { break; } var result_info = result.Documents.OrderBy(info => info.timestamp); object_infos.AddRange(result_info.ToList()); // if (object_infos.Count >= result.Total) break; //startIndex += eachSearchSize; if (result.Documents.Count < eachSearchSize) { break; } start_time = result_info.Last().timestamp.AddMilliseconds(1); }while (true); if (object_infos.Count == 0) { return; } BlockingCollection <Vo.VehicleHistoricalInfo> listTemp = new BlockingCollection <Vo.VehicleHistoricalInfo>(); Parallel.For(0, object_infos.Count(), rowCount => { Vo.VehicleHistoricalInfo Historyinfo = new Vo.VehicleHistoricalInfo(); DateTime Time = object_infos[rowCount].timestamp; string sVh_ID = object_infos[rowCount].OBJECT_ID; string sRaw_data = object_infos[rowCount].RAWDATA; byte[] vh_info_bytes = Common.WinFromUtility.unCompressString(sRaw_data); sc.ProtocolFormat.OHTMessage.VEHICLE_INFO vh_info = sc.BLL.VehicleBLL.Convert2Object_VehicleInfo(vh_info_bytes); Historyinfo.Time = Time.ToLocalTime(); Historyinfo.ID = sVh_ID; Historyinfo.VhInfo = vh_info; listTemp.Add(Historyinfo); // 每處理幾筆就停止5ms if (rowCount != 0 && rowCount % 20000 == 0) { System.Threading.SpinWait.SpinUntil(() => false, 5); } }); vh_historical_infos = listTemp.OrderBy(info => info.Time).ToList(); StartPlayTime = vh_historical_infos.First().Time; var groupResult = from vh_historical_info in vh_historical_infos group vh_historical_info by vh_historical_info.Time; Vh_Historical_Info_GroupByTime = groupResult.OrderBy(infos => infos.Key).ToDictionary (infos => infos.Key, infos => infos.ToList()); startIndex = 0; LoadComplete?.Invoke(this, Vh_Historical_Info_GroupByTime); //foreach (var info in vh_historical_infos) //{ // Console.WriteLine(info.VhInfo.ToString()); //} }
public static Order ToOrder(this EF.OrderHistoryHeader entity) { Order order = new Order(); //retVal.OrderNumber = value.InvoiceNumber; order.OrderNumber = entity.ControlNumber; switch (entity.OrderStatus.Trim()) { case "": order.Status = "Ordered"; break; case "I": order.Status = "Invoiced"; break; case "P": order.Status = "Processing"; break; case "D": order.Status = "Deleted"; break; default: break; } order.CreatedDate = DateTime.SpecifyKind(entity.CreatedUtc.ToLocalTime(), DateTimeKind.Unspecified); if (string.IsNullOrWhiteSpace(entity.OrderDateTime) == false) { var orderDateTime = entity.OrderDateTime.ToDateTime(); if (orderDateTime.HasValue) { order.CreatedDate = orderDateTime.Value; } } order.DeliveryDate = entity.DeliveryDate.ToDateTime().Value.ToLongDateFormat(); order.InvoiceNumber = entity.InvoiceNumber.Trim(); order.InvoiceStatus = "N/A"; order.ItemCount = entity.OrderDetails == null ? 0 : entity.OrderDetails.Count; order.RequestedShipDate = entity.DeliveryDate.ToDateTime().Value.ToLongDateFormat(); order.IsChangeOrderAllowed = false; order.CommerceId = Guid.Empty; FillEtaInformation(entity, order); order.PONumber = entity.PONumber; order.IsSpecialOrder = entity.IsSpecialOrder; order.OrderTotal = (double)entity.OrderSubtotal; order.OrderSystem = new OrderSource().Parse(entity.OrderSystem).ToString(); if (entity.OrderDetails != null && entity.OrderDetails.Count > 0) { var lineItems = new BlockingCollection <OrderLine>(); Parallel.ForEach(entity.OrderDetails, d => { lineItems.Add(d.ToOrderLine(entity.OrderStatus)); }); order.Items = lineItems.OrderBy(i => i.LineNumber).ToList(); } return(order); }