private IList <T> InnerDoQuery(RestrictionBuilderBase restrictionBuilder, OrderByBuilder orderByBuilder, int max, int skip) { ArchiveExecutionContext executionContext = _archiveExecutionContextProvider.Get(); if (executionContext == null) { throw new InvalidOperationException(nameof(executionContext) + " not set, cannot be null"); } ArchiveQueryParameters context = new ArchiveQueryParameters(); context.ArchiveName = executionContext.ArchiveName; context.Entities = executionContext.Entities; context.RequestedColumns = DynamicPropertyHelper.GetAllDbColumnsPrefixed <T>(); int page = 0; if (skip > 0) { page = SetPageSizeAndGetPage(skip, max, context); } if (restrictionBuilder != null) { context.Restrictions = restrictionBuilder.GetRestrictions(); } if (orderByBuilder != null) { context.OrderBy = orderByBuilder.Get(); } return(_resultParser.Parse <T>(executionContext, _executor.GetItems(context, max, page))); }
public void Parse <T>(IResultParser <T> parser, T reader) where T : IReader { long offset = reader.Position; IResultNodeBuilder resultNodeBuilder = _createResultNodeBuilder(); IResultNodeState resultState = _createResultNodeReaderState(this, resultNodeBuilder); IState previousState = _activeState.ChangeState(resultState); try { parser.Parse(reader, resultState); } finally { _activeState.ChangeState(previousState); } if (Valid && (reader.Position > offset)) { resultNodeBuilder.DataPacket = reader.GetDataPacket(offset, (reader.Position - offset)); resultNodeBuilder.Metadata = _resultMetadata; if (!resultState.Valid) { resultNodeBuilder.Invalidate(); } _resultNodeCallback.AddNode(_rootResultNode, resultNodeBuilder.Build(), resultState); } }
public void ForceUpdate(string filepath) { try { var points = parser.Parse( filepath, input => input.Split(new[] { Environment.NewLine }, StringSplitOptions.None), row => { var cols = row.Split(new[] { ';', ',' }, StringSplitOptions.None); var x = double.Parse(cols[0]); var y = double.Parse(cols[1]); return(new DataPoint(x, y)); }); OnResultsChanged(this, new GraphUpdateEvent { ResultAction = ResultAction.Update, New = points, Tag = filepath }); } catch (Exception e) { OnErrorOccured(this, e.Message); } }
private OperationMessage DeserializeSubscriptionResultMessage( GraphQLSocketMessage parsedMessage) { if (parsedMessage.Id is null || !parsedMessage.HasPayload) { // TODO : resources throw new InvalidOperationException("Invalid message structure."); } if (_subscriptionManager.TryGetSubscription( parsedMessage.Id, out ISubscription? subscription)) { IResultParser parser = subscription !.ResultParser; OperationResultBuilder resultBuilder = OperationResultBuilder.New(parser.ResultType); parser.Parse(parsedMessage.Payload, resultBuilder); return(new DataResultMessage(parsedMessage.Id, resultBuilder)); } return(KeepConnectionAliveMessage.Default); }
public void PollforUploadCompleteResultArchives() { var tempLogger = _logManager.GetLogger("jobs"); var resultArchives = _resultArchiveUploadRepository.Get(ResultArchiveUploadStatus.Uploaded); resultArchives = resultArchives.Where(r => r.FileId.HasValue).OrderBy(r => r.UploadEndTime); if (resultArchives.Count() > 0) { tempLogger.Info("Got the uploaded files list."); } foreach (var resultArchive in resultArchives) { var logFileName = "File_" + resultArchive.Id; ILogger logger = new NLogLogManager().GetLogger(logFileName); var theEvent = new LogEventInfo(LogLevel.Off, "", logFileName); theEvent.Properties["LogFileName"] = logFileName; string extractedFilePath = ""; string zipFilePath = ""; logger.Info( "\n\n****************************************************************************************************************** "); try { // ReSharper disable PossibleInvalidOperationException var file = _fileRepository.GetById(resultArchive.FileId.Value); // ReSharper restore PossibleInvalidOperationException if (file == null) { logger.Info(String.Format("\nFile Information not found for Result Archive Id: {0}, uploaded on {1}, for the Event Id: {2} ", resultArchive.Id, resultArchive.UploadEndTime.Value, resultArchive.EventId)); resultArchive.Status = ResultArchiveUploadStatus.FileNotFound; _resultArchiveUploadRepository.Save(resultArchive); continue; } var mediaLocation = _mediaRepository.GetResultArchiveMediaFileLocation(resultArchive.EventId); if (!System.IO.File.Exists(mediaLocation.PhysicalPath + file.Path)) { logger.Info(String.Format("\nInvalid File Path for Result Archive Id: {0}, uploaded on {1}, for the Event Id: {2} ", resultArchive.Id, resultArchive.UploadEndTime.Value, resultArchive.EventId)); resultArchive.Status = ResultArchiveUploadStatus.FileNotFound; _resultArchiveUploadRepository.Save(resultArchive); continue; } zipFilePath = mediaLocation.PhysicalPath + file.Path; } catch (Exception ex) { logger.Info(String.Format("\nSystem Failure, while fetching File Info for Result Archive Id: {0}, uploaded on {1}, for the Event Id: {2}. \nMessage:{3} \n\t {4}", resultArchive.Id, resultArchive.UploadEndTime.Value, resultArchive.EventId, ex.Message, ex.StackTrace)); resultArchive.Status = ResultArchiveUploadStatus.FileNotFound; _resultArchiveUploadRepository.Save(resultArchive); continue; } try { resultArchive.ParseStartTime = DateTime.Now; resultArchive.Status = ResultArchiveUploadStatus.Parsing; _resultArchiveUploadRepository.Save(resultArchive); } catch (Exception ex) { logger.Info("\nSystem Failure, while saving 'Parsing Start Time'! Message: " + ex.Message + "\n\t" + ex.StackTrace); continue; } try { extractedFilePath = _zipHelper.ExtractZipFiles(zipFilePath); } catch (Exception ex) { logger.Info(String.Format("\nSystem Failure, Invalid File Format for Result Archive Id: {0}, uploaded on {1}, for the Event Id: {2}. \nMessage:{3} \n\t {4}", resultArchive.Id, resultArchive.UploadEndTime.Value, resultArchive.EventId, ex.Message, ex.StackTrace)); resultArchive.Status = ResultArchiveUploadStatus.InvalidFileFormat; _resultArchiveUploadRepository.Save(resultArchive); continue; } try { logger.Info(String.Format("\nParsing Started for Result Archive Id: {0}, uploaded on {1}, for the Event Id: {2} ", resultArchive.Id, resultArchive.UploadEndTime.Value, resultArchive.EventId)); _resultParser = new ResultParser(resultArchive.Id, extractedFilePath, _corporateAccountRepository, _mediaRepository, _resultArchiveUploadRepository, _resultArchiveUploadLogRepository, logger, _settings, _customerRepository, _zipHelper, _basicBiometricRepository, _eventCustomerRepository, _lipidParserHelper, _endofDayService, _customerService, _eventRepository); _resultParser.Parse(); logger.Info("\nParsing completed without any system Failure."); resultArchive.ParseEndTime = DateTime.Now; //Directory.Delete(extractedFilePath, true); } catch (IOException ex) { logger.Info("\nParsing Failed! Message: " + ex.Message + "\n\t" + ex.StackTrace); resultArchive.ParseEndTime = DateTime.Now; resultArchive.Status = ResultArchiveUploadStatus.ParseFailed; _resultArchiveUploadRepository.Save(resultArchive); } catch (Exception ex) { logger.Info("\nParsing Failed! Message: " + ex.Message + "\n\t" + ex.StackTrace); resultArchive.ParseEndTime = DateTime.Now; resultArchive.Status = ResultArchiveUploadStatus.ParseFailed; _resultArchiveUploadRepository.Save(resultArchive); Directory.Delete(extractedFilePath, true); } finally { var ecs = _eventCustomerResultRepository.GetByEventId(resultArchive.EventId); if (ecs != null && ecs.Count() > 0) { foreach (var eventCustomerResult in ecs) { _eventCustomerResultRepository.SetEventCustomerResultState(eventCustomerResult.EventId, eventCustomerResult.CustomerId); } } // GC.Collect(); //logger.Info("Calling gc collect"); Thread.Sleep(2000); } try { var resultArchiveLogs = _resultArchiveUploadLogRepository.GetbyResultArchiveId(resultArchive.Id); var succesFulRecords = resultArchiveLogs != null?resultArchiveLogs.Where(rl => rl.IsSuccessful).Count() : 0; if (succesFulRecords > 0) { resultArchive.Status = ResultArchiveUploadStatus.Parsed; } else { resultArchive.Status = ResultArchiveUploadStatus.ParseFailed; } var customerCount = resultArchiveLogs != null?resultArchiveLogs.Select(rl => rl.CustomerId).Distinct().Count() : 0; resultArchive.CustomerRecordsFound = customerCount; _resultArchiveUploadRepository.Save(resultArchive); } catch (Exception ex) { logger.Info("/Saving Parse End Data Failed! Message: " + ex.Message + "\n\t" + ex.StackTrace); } } }