public static void Main() { Database.SetInitializer(new DropCreateDatabaseAlways <StationsContext>()); StationsContext context = new StationsContext(); QueryHelper queryHelper = new QueryHelper(context); ImportHandler importHandler = new ImportHandler(queryHelper); // Import JSON. importHandler.ImportStations(File.ReadAllText("../../Datasets/stations.json")); importHandler.ImportClasses(File.ReadAllText("../../Datasets/classes.json")); importHandler.ImportTrains(File.ReadAllText("../../Datasets/trains.json")); importHandler.ImportTrips(File.ReadAllText("../../Datasets/trips.json")); // Import XML. importHandler.ImportCards(File.ReadAllText("../../Datasets/cards.xml")); importHandler.ImportTickets(File.ReadAllText("../../Datasets/tickets.xml")); ExportHandler exportHandler = new ExportHandler(queryHelper); // Export JSON. exportHandler.ExportDelayedTrains("../../Datasets/", "01/01/2017"); exportHandler.ExportCardsTicket("../../Datasets/", "Elder"); }
/// <summary> /// Executes the handler for an options object /// </summary> /// <param name="options"></param> /// <returns></returns> private static ExitCode ExecuteHandler(object options) { ExitCode code = ExitCode.Unset; switch (options) { case PrintOptions printOptions: var printHandler = new PrintHandler(ProjectService); code = printHandler.TryExecute(printOptions); break; case ExportOptions exportOptions: var exportHandler = new ExportHandler(ProjectService); code = exportHandler.TryExecute(exportOptions); break; case ExportAllOptions exportAllOptions: var exportAllHandler = new ExportAllHandler(ProjectService); code = exportAllHandler.TryExecute(exportAllOptions); break; case ImportOptions importOptions: var importHandler = new ImportHandler(ProjectService); code = importHandler.TryExecute(importOptions); break; case ImportAllOptions importAllOptions: var importAllHandler = new ImportAllHandler(ProjectService); code = importAllHandler.TryExecute(importAllOptions); break; } return(code); }
private void SplitFile(string filePath, IEnumerable <string> lines, TripleSegment tripleSegment) { Log.LogDebug("SplitFile: {0}", filePath); _splitDirPath = filePath.Substring(0, filePath.IndexOf('.')); if (!Directory.Exists(Path.Combine(_baseDirectory.FullName, _splitDirPath))) { Directory.CreateDirectory(Path.Combine(_baseDirectory.FullName, _splitDirPath)); var prefixString = _splitDirPath.Replace(Path.DirectorySeparatorChar.ToString(), "") .Replace(Path.AltDirectorySeparatorChar.ToString(), ""); _directoryMap.Add(prefixString, _splitDirPath); } var handler = new ImportHandler(this, tripleSegment); _lineReader.Load(handler, new StringReader(string.Join("\n", lines))); // Drop the old file _cache.Remove(filePath); var deletePath = Path.Combine(_baseDirectory.FullName, filePath); if (File.Exists(deletePath)) { File.Delete(deletePath); } }
public HandlerProvider() { ImportHandler = new ImportHandler(); SearchHandler = new SearchHandler(); AutoCompleteHandler = new AutoCompleteHandler(); DeleteHandler = new DeleteHandler(); }
public ActionResult Upload(List <Prescription> updateList, bool isRecall = false) { if (updateList != null) { ImportHandler.Update(updateList, isRecall); } return(Redirect("/Pharmacy")); }
private void ProcessClassBody() { // Class is handled in a specific order rather than in the order of // the statement appearance. This is because we need all members // properly declared and added to the class type so when we process // methods, the class variables are all declared and constructors // are evaluated. // Process bases. foreach (var b in _class.Bases.Select(b => b.GetPythonType <IPythonClassType>()).ExcludeDefault()) { SymbolTable.Evaluate(b.ClassDefinition); } // Process imports foreach (var s in GetStatements <FromImportStatement>(_classDef)) { ImportHandler.HandleFromImport(s); } foreach (var s in GetStatements <ImportStatement>(_classDef)) { ImportHandler.HandleImport(s); } UpdateClassMembers(); // Process assignments so we get class variables declared. // Note that annotated definitions and assignments can be intermixed // and must be processed in order. Consider // class A: // x: int // x = 1 foreach (var s in GetStatements <Statement>(_classDef)) { switch (s) { case AssignmentStatement assignment: AssignmentHandler.HandleAssignment(assignment); break; case ExpressionStatement e: AssignmentHandler.HandleAnnotatedExpression(e.Expression as ExpressionWithAnnotation, null); break; } } UpdateClassMembers(); // Ensure constructors are processed so class members are initialized. EvaluateConstructors(_classDef); UpdateClassMembers(); // Process remaining methods. SymbolTable.EvaluateScope(_classDef); UpdateClassMembers(); }
protected AnalysisWalker(ExpressionEval eval) { Eval = eval; ImportHandler = new ImportHandler(this); AssignmentHandler = new AssignmentHandler(this); LoopHandler = new LoopHandler(this); ConditionalHandler = new ConditionalHandler(this); WithHandler = new WithHandler(this); TryExceptHandler = new TryExceptHandler(this); NonLocalHandler = new NonLocalHandler(this); }
static void Main(string[] args) { try { logger.Info("MarketR import service has been started -->" + DateTime.Now); ImportHandler handler = new ImportHandler(logger); handler.ProcessFiles(); logger.Info("MarketR import service has been completed -->" + DateTime.Now); } catch (Exception ex) { logger.Error(ex.Message); } }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { try { logger.Info("import process has been started -->" + DateTime.Now); ImportHandler handler = new ImportHandler(logger); handler.ProcessFiles(); logger.Info("import process has been completed -->" + DateTime.Now); timer.Enabled = true; } catch (Exception ex) { logger.Error(ex.Message); this.Stop(); } }
/// <summary> /// Loads the document by using the specified importer. /// </summary> /// <param name="file">The the file.</param> public void Load(string file) { this._isLoadedFile = true; this.Styles = new StyleCollection(); this._fields = new FieldsCollection(); this.Content = new ContentCollection(); this._xmldoc = new XmlDocument(); this._xmldoc.LoadXml(TextDocumentHelper.GetBlankDocument()); this.NamespaceManager = TextDocumentHelper.NameSpace(this._xmldoc.NameTable); ImportHandler importHandler = new ImportHandler(); m_importer = importHandler.GetFirstImporter(DocumentTypes.TextDocument, file); m_dirInfo = m_importer.DirInfo; if (m_importer != null) { if (m_importer.NeedNewOpenDocument) { this.New(); } m_importer.Import(this, file); if (m_importer.ImportError != null) { if (m_importer.ImportError.Count > 0) { foreach (object ob in m_importer.ImportError) { if (ob is AODLWarning) { if (((AODLWarning)ob).Message != null) { Console.WriteLine("Err: {0}", ((AODLWarning)ob).Message); } if (((AODLWarning)ob).Node != null) { XmlTextWriter writer = new XmlTextWriter(Console.Out); writer.Formatting = Formatting.Indented; ((AODLWarning)ob).Node.WriteContentTo(writer); } } } } } } this._formCollection.Clearing += FormsCollection_Clear; this._formCollection.Removed += FormsCollection_Removed; }
/// <summary> /// Load the given file. /// </summary> /// <param name="file"></param> public void Load(string file) { try { this._isLoadedFile = true; this.LoadBlankContent(); this.NamespaceManager = TextDocumentHelper.NameSpace(this._xmldoc.NameTable); ImportHandler importHandler = new ImportHandler(); IImporter importer = importHandler.GetFirstImporter(DocumentTypes.SpreadsheetDocument, file); if (importer != null) { if (importer.NeedNewOpenDocument) { this.New(); } importer.Import(this, file); if (importer.ImportError != null) { if (importer.ImportError.Count > 0) { foreach (object ob in importer.ImportError) { if (ob is AODLWarning) { if (((AODLWarning)ob).Message != null) { Console.WriteLine("Err: {0}", ((AODLWarning)ob).Message); } if (((AODLWarning)ob).Node != null) { XmlTextWriter writer = new XmlTextWriter(Console.Out); writer.Formatting = Formatting.Indented; ((AODLWarning)ob).Node.WriteContentTo(writer); } } } } } } } catch (Exception ex) { throw; } }
public ActionResult <GenericCommandResult> Create(IFormFile file, [FromServices] ImportHandler handler) { var command = new CreateImportCommand { FileExtension = FileExtension.Xlsx, Items = FileHandler.Excel(file) }; var result = (GenericCommandResult)handler.Handle(command); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <ImportModel> CreateImportPreview(Stream fileStream, ImportModel model) { var userId = await _authenticationService.GetCurrentUserId(); var importCacheKey = CreateImportCacheKey(userId); SinanceCacheHandler.ClearCache(importCacheKey); using var unitOfWork = _unitOfWork(); var bankAccount = await unitOfWork.BankAccountRepository.FindSingle(x => x.Id == model.BankAccountId); if (bankAccount == null) { throw new NotFoundException(nameof(BankAccountEntity)); } var importBank = await unitOfWork.ImportBankRepository.FindSingle(item => item.Id == model.ImportBankId); if (importBank == null) { throw new NotFoundException(nameof(ImportBankEntity)); } var importMappings = await unitOfWork.ImportMappingRepository.FindAll(item => item.ImportBankId == importBank.Id); try { model.ImportRows = await ImportHandler.CreateImportRowsFromFile( unitOfWork, fileInputStream : fileStream, userId : bankAccount.UserId, importMappings : importMappings, importBank : importBank, bankAccountId : bankAccount.Id); // Place the import model in the cache for easy acces later SinanceCacheHandler.Cache(key: importCacheKey, contentAction: () => model, slidingExpiration: false, expirationTimeSpan: new TimeSpan(0, 0, 15, 0)); return(model); } catch (Exception exc) { throw new ImportFileException("Unexpected error while importing", exc); } }
private async Task ProcessClassBody(CancellationToken cancellationToken = default) { // Class is handled in a specific order rather than in the order of // the statement appearance. This is because we need all members // properly declared and added to the class type so when we process // methods, the class variables are all declared and constructors // are evaluated. // Process bases. foreach (var b in _class.Bases.Select(b => b.GetPythonType <IPythonClassType>()).ExcludeDefault()) { await SymbolTable.EvaluateAsync(b.ClassDefinition, cancellationToken); } // Process imports foreach (var s in GetStatements <FromImportStatement>(_classDef)) { await FromImportHandler.HandleFromImportAsync(s, cancellationToken); } foreach (var s in GetStatements <ImportStatement>(_classDef)) { await ImportHandler.HandleImportAsync(s, cancellationToken); } UpdateClassMembers(); // Process assignments so we get class variables declared. foreach (var s in GetStatements <AssignmentStatement>(_classDef)) { await AssignmentHandler.HandleAssignmentAsync(s, cancellationToken); } foreach (var s in GetStatements <ExpressionStatement>(_classDef)) { await AssignmentHandler.HandleAnnotatedExpressionAsync(s.Expression as ExpressionWithAnnotation, null, cancellationToken); } UpdateClassMembers(); // Ensure constructors are processed so class members are initialized. await EvaluateConstructorsAsync(_classDef, cancellationToken); UpdateClassMembers(); // Process remaining methods. await SymbolTable.EvaluateScopeAsync(_classDef, cancellationToken); UpdateClassMembers(); }
public ActionResult Index(HttpPostedFileBase file) { var updateList = new List <Prescription>(); if (file.ContentLength > 0) { var isRecall = ImportHandler.IsRecallFile(file); updateList = ImportHandler.Handle(file, User.Store.store_id, isRecall); ViewBag.IsRecall = isRecall; } else { ViewBag.IsRecall = null; } return(PartialView(updateList)); }
public void testCsv() { // test file string fileName = "../../../../PPOK_System/PPOK_System/data/scrubbed_data.csv"; StreamReader reader = new StreamReader(fileName); var result = ImportHandler.Csv(reader); // check size of result Assert.AreEqual(result.Count, 979); // check zeroth row Assert.AreEqual(result[0].customer.first_name, "STEPHNIE"); Assert.AreEqual(result[0].customer.last_name, "EIDSNESS"); Assert.AreEqual(result[0].customer.date_of_birth.Year, 2004); Assert.AreEqual(result[0].customer.date_of_birth.Month, 10); Assert.AreEqual(result[0].customer.date_of_birth.Day, 12); Assert.AreEqual(result[0].customer.zip, "98008"); Assert.AreEqual(result[0].days_supply, 30); Assert.AreEqual(result[0].date_filled.Year, 2008); Assert.AreEqual(result[0].date_filled.Month, 05); Assert.AreEqual(result[0].date_filled.Day, 06); Assert.AreEqual(result[0].drug.drug_id, "60505006501"); Assert.AreEqual(result[0].drug.drug_name, "Omeprazole Cap Delayed Release 20 MG"); // check fourth row Assert.AreEqual(result[4].customer.first_name, "Nina"); Assert.AreEqual(result[4].customer.last_name, "Paege Dp30"); Assert.AreEqual(result[4].customer.date_of_birth.Year, 1923); Assert.AreEqual(result[4].customer.date_of_birth.Month, 01); Assert.AreEqual(result[4].customer.date_of_birth.Day, 26); Assert.AreEqual(result[4].customer.zip, ""); Assert.AreEqual(result[4].days_supply, 25); Assert.AreEqual(result[4].date_filled.Year, 2008); Assert.AreEqual(result[4].date_filled.Month, 05); Assert.AreEqual(result[4].date_filled.Day, 06); Assert.AreEqual(result[4].drug.drug_id, "65027225"); Assert.AreEqual(result[4].drug.drug_name, "Olopatadine HCl Ophth Soln 0.2% (Base Equivalent)"); reader.Close(); }
public async Task HandleRequestAsync_ValidRequest_InvokesVehicleDataServiceImportVehicleDataAsyncWithExpectedArgs() { // Arrange const int expectedCustomerId = 1; const string expectedVIN = "VIN"; var fakeValidateVIN = A.Fake <IValidateVIN>(); A.CallTo(() => fakeValidateVIN.IsValid(expectedVIN)).Returns(true); var fakeVehicleDataService = A.Fake <IVehicleDataService>(); IServiceProvider sp = new ServiceCollection() .AddSingleton(fakeValidateVIN) .AddSingleton(fakeVehicleDataService) .BuildServiceProvider(); var context = A.Fake <ILambdaContext>(); A.CallTo(() => context.Logger).Returns(A.Fake <ILambdaLogger>()); var importRequest = new ImportRequest { CustomerId = expectedCustomerId, VIN = expectedVIN }; APIGatewayProxyRequest dummyRequestEvent = new APIGatewayProxyRequest { Body = JsonConvert.SerializeObject(importRequest) }; var sut = new ImportHandler(sp); // Act await sut.HandleRequestAsync(dummyRequestEvent, context); // Assert A.CallTo(() => fakeVehicleDataService.ImportVehicleDataAsync(expectedCustomerId, expectedVIN)).MustHaveHappenedOnceExactly(); }
public async Task HandleRequestAsync_VINValidationFails_ReturnsBadRequestResponse() { // Arrange const string vin = "VIN"; var fakeValidateVIN = A.Fake <IValidateVIN>(); A.CallTo(() => fakeValidateVIN.IsValid(vin)).Returns(false); var fakeVehicleDataService = A.Fake <IVehicleDataService>(); IServiceProvider sp = new ServiceCollection() .AddSingleton(fakeValidateVIN) .AddSingleton(fakeVehicleDataService) .BuildServiceProvider(); var context = A.Fake <ILambdaContext>(); A.CallTo(() => context.Logger).Returns(A.Fake <ILambdaLogger>()); var importRequest = new ImportRequest { CustomerId = 1, VIN = vin }; APIGatewayProxyRequest dummyRequestEvent = new APIGatewayProxyRequest { Body = JsonConvert.SerializeObject(importRequest) }; var sut = new ImportHandler(sp); // Act APIGatewayProxyResponse response = await sut.HandleRequestAsync(dummyRequestEvent, context); // Assert Assert.Equal((int)HttpStatusCode.BadRequest, response.StatusCode); }
public async Task <(int skippedTransactions, int savedTransactions)> SaveImport(ImportModel model) { var userId = await _authenticationService.GetCurrentUserId(); var importCacheKey = CreateImportCacheKey(userId); var cachedModel = SinanceCacheHandler.RetrieveCache <ImportModel>(importCacheKey); if (cachedModel == null) { throw new NotFoundException(nameof(ImportModel)); } using var unitOfWork = _unitOfWork(); var bankAccount = await unitOfWork.BankAccountRepository.FindSingleTracked(x => x.Id == model.BankAccountId && x.UserId == userId); if (bankAccount == null) { throw new NotFoundException(nameof(BankAccountEntity)); } var skippedTransactions = model.ImportRows.Count(item => item.ExistsInDatabase || !item.Import); var savedTransactions = await ImportHandler.SaveImportResultToDatabase(unitOfWork, bankAccountId : bankAccount.Id, importRows : model.ImportRows, cachedImportRows : cachedModel.ImportRows, userId : bankAccount.UserId); // Update the current balance of bank account and refresh them bankAccount.CurrentBalance = await TransactionHandler.CalculateCurrentBalanceForBankAccount(unitOfWork, bankAccount); await unitOfWork.SaveAsync(); // Clear the cache entry SinanceCacheHandler.ClearCache(importCacheKey); return(skippedTransactions, savedTransactions); }
public static string TypeToStr(ImportHandler type) { return(type.ToString()); }
public override Task <bool> WalkAsync(ImportStatement node, CancellationToken cancellationToken = default) => ImportHandler.HandleImportAsync(node, cancellationToken);
public HandlerLayer() { handler = ImportHandler.NONE; layer = LayerMask.NameToLayer("Default"); }
public HandlerLayer(ImportHandler h, int l) { handler = h; layer = l; }
/// <summary> /// Initialize a KeywordHandler Object /// </summary> public KSIKeywordHandler() { keyword = ""; handler = ImportHandler.NONE; }
/// <summary> /// Initialize a KeywordHandler Object /// </summary> /// <param name="word">The Keyword</param> /// <param name="t">The Handler Type</param> public KSIKeywordHandler(string word, ImportHandler t) { keyword = word; handler = t; }
public override bool Walk(FromImportStatement node) => ImportHandler.HandleFromImport(node);
public HandlerLayer(ImportHandler h) { handler = h; layer = LayerMask.NameToLayer("Default"); }