public void UpdatePoints1() { // Setup Data Model & Co string dbFilename = TestUtilities.CreateWorkingFileFrom(testContextInstance.TestDeploymentDir, @"1554MSBS.mdb"); Database db = new Database(); db.Connect(dbFilename); AppDataModel model = new AppDataModel(db); Race race = model.GetRace(0); // Import DSV Point List DSVImportReader dsvImportReader = new DSVImportReader(new DSVImportReaderZip(@"Punktelisten.zip", DSVImportReaderZipBase.EDSVListType.Pupils_U14U16)); // Check two prior Assert.AreEqual(148.86, race.GetParticipants().First(r => r.SvId == "24438").Points); Assert.AreEqual(129.12, race.GetParticipants().First(r => r.SvId == "25399").Points); UpdatePointsImport import = new UpdatePointsImport(race, dsvImportReader.Mapping); ImportResults impRes = import.DoImport(dsvImportReader.Data); Assert.AreEqual(125, impRes.SuccessCount); Assert.AreEqual(2, impRes.ErrorCount); Assert.AreEqual(110.96, race.GetParticipants().First(r => r.SvId == "24438").Points); Assert.AreEqual(100.33, race.GetParticipants().First(r => r.SvId == "25399").Points); }
public async Task <ImportResultsViewModel> CreateViewModelAsync(ImportResults model) { var item = new ImportResultsViewModel(model, this.targetsFactory, eventAggregator.Invoke(), logger, dialogCoordinator, shellExecuteProvider); await item.Initialization; return(item); }
public bool Import(ImportResults import) { this.ImportCount = 0; this.ShouldAttemptInsert = true; this.ImportSubhandler(import); return(this.ShouldAttemptInsert); }
internal override void ImportSubhandler(ImportResults import) { var fields = new List <Model.Field>(); string sheetName = GetFirstSheetName(import.ImportFileName); var connectionString = GetConnectionString(import.ImportFileName, import.Template.HasHeaders); int rowIndex = 1; using (OleDbConnection SQLConn = new OleDbConnection(connectionString)) { string selectStatement = $"SELECT * FROM [{sheetName}]"; using (OleDbCommand selectCommand = new OleDbCommand(selectStatement, SQLConn)) { SQLConn.Open(); using (var reader = selectCommand.ExecuteReader()) { ReadHeader(fields, reader); if (!import.Template.HasGoodColumnMatch(fields)) { import.Message = $"File formatting issue: file,{import.ImportFileName}, columns do not match the reference file,{import.Template.ReferenceFile}"; this.ShouldAttemptInsert = false; return; } while (reader.Read()) { fields.ForEach(f => f.Value = DBNull.Value); foreach (var field in fields) { var value = reader.GetValue(field.ColumnIndex).ToString(); SetFieldType(field, value); } this.Insert(fields, import, rowIndex); rowIndex++; } } } } }
void Insert(ImportResults import, List <Model.Field> fields) { var template = import.Template; using (SqlConnection conn = new SqlConnection(template.ConnectionString)) { var cmd = template.GetInsertCommand(); cmd.Connection = conn; cmd.Parameters["@ImportFileName"].Value = import.ImportFileName; cmd.Parameters["@ImportDate"].Value = import.ImportDate; cmd.Parameters["@Importer"].Value = import.Template.Importer(); foreach (var field in template.Fields) { var found = fields.FirstOrDefault(f => f.FieldName == field.FieldName); if (found != null) { if (found.FieldType == field.FieldType) { cmd.Parameters["@" + field.DataFieldName].Value = found.Value; } else { field.SetValue(found.Value.ToString()); cmd.Parameters["@" + field.DataFieldName].Value = field.Value; } } else { cmd.Parameters["@" + field.DataFieldName].Value = DBNull.Value; } } conn.Open(); cmd.ExecuteNonQuery(); this.ImportCount = this.ImportCount + 1; } }
private void ReadCells(ImportResults import, WorkbookPart workbookPart, CellFormats cellFormats, OpenXmlReader reader, bool needHeader, List <Model.Field> fields, int rowIndex) { do { if (reader.ElementType == typeof(Cell)) { Cell c = (Cell)reader.LoadCurrentElement(); var cellValue = GetCellValue(workbookPart, cellFormats, c); if (needHeader) { SetHeader(import.Template.HasHeaders, fields, c, cellValue); if (import.Template.HasHeaders) { continue; } } string excelColumnReference = Regex.Replace(c.CellReference, "\\d", ""); var field = fields.FirstOrDefault(f => f.ExcelColumnReference == excelColumnReference); SetFieldType(fields, cellValue, c); if (field != null) { field.SetValue(cellValue); } } } while (reader.ReadNextSibling()); }
public ImportResults <T> Import <T>(string[] Parameters) { string ImportFile = ""; var Source = Parameters[0]; if (File.Exists(Source)) { ImportFile = Source; } // else if (Directory.Exists(Source)) // { // var DirectoryInfo = new DirectoryInfo(Source); // foreach (var FileInfo in DirectoryInfo.EnumerateFiles()) // { // if (FileInfo.Extension == ".xml") // { // ImportFiles.Add(FileInfo.FullName); // } // } // } var ExtendedXmlSerializer = new ExtendedXmlSerializer(); string ImportXml = File.ReadAllText(ImportFile); var ImportResults = new ImportResults <T>(); ImportResults.Result = ExtendedXmlSerializer.Deserialize <T>(ImportXml); return(ImportResults); }
private void Import_PostExecute(ImportResults results) { if (!results.Loaded) { return; } ViewModel.Sounds[results.Target].CwavData = results.CWAV.CwavData; }
public ImportResults AddContent(ImportData data) { var results = new ImportResults(); results.SchemaResults = AddSchemas(data.Schemas); results.ModuleResults = AddModules(data.Modules); return(results); }
public Task <ImportResults> ImportTransactionsFromCSVAsync(string fileContent) { return(Task <ImportResults> .Run(async() => { ImportResults results = new ImportResults(); string[] lines = fileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { if (!await _transactionRepository.AlreadyImported(line.Trim())) { Transaction transaction = null; try { //Datum,"Naam / Omschrijving","Rekening","Tegenrekening","Code","Af Bij","Bedrag (EUR)","MutatieSoort","Mededelingen" string[] values = line.Split(new string[] { "," }, StringSplitOptions.None); transaction = new Transaction(); transaction.Date = DateTime.ParseExact(values[0], "dd-MM-yyyy", CultureInfo.InvariantCulture);//20170619 transaction.AccountNumberFrom = values[1]; transaction.AccountNumberTo = values[2]; transaction.Code = values[15]; transaction.Amount = double.Parse(values[10], CultureInfo.InvariantCulture);//- transaction.MutationType = values[7]; transaction.Statement = values[17].Trim('"').Trim('\''); if (!string.IsNullOrWhiteSpace(transaction.AccountNumberTo)) { transaction.Relation = await _relationRepository.FindRelationByAccountNumber(transaction.AccountNumberTo); } transaction.ImportLine = line.Trim(); string description = values[3].Trim(); if (string.IsNullOrWhiteSpace(description)) { var descriptionOfRelation = values[17].Trim('"').Trim('\''); var parts = descriptionOfRelation.Split('>'); if (parts.Length > 1) { description = parts[0].Trim(); } } await DetermineOrCreateRelation(transaction, results, description); await _transactionRepository.SynchronizeTransactionAndRelationCategoriesAsync(transaction.Relation.ID); transaction = await _transactionRepository.AddAsync(transaction); transaction = await _transactionRepository.GetItemByIdAsync(transaction.ID); results.ImportedTransactions.Add(transaction); } catch (Exception e) { } } else { results.AlreadyImported++; } } results.Success = true; return results; })); }
public ImportResults DoImport() { var result = new ImportResults(); result.Groups = this.GetGroups(); result.Modules = this.GetModules(); result.ModuleStudyActions = this.GetModuleStudyActionsDict(result.Modules, result.Groups); return(result); }
public ImportResultsViewModel(ImportResults results, ISecurityDescriptorTargetsViewModelFactory targetsFactory, IEventAggregator eventAggregator, ILogger <ImportResultsViewModel> logger, IDialogCoordinator dialogCoordinator, IShellExecuteProvider shellExecuteProvider) { this.results = results; this.logger = logger; this.dialogCoordinator = dialogCoordinator; this.shellExecuteProvider = shellExecuteProvider; this.targetsFactory = targetsFactory; this.eventAggregator = eventAggregator; this.Initialization = this.Initialize(); }
public ImportedRelationsPage(ImportWizardViewmodel wizardViewmodel, ImportResults importResult) : base(wizardViewmodel) { Content = new Views.ChildViews.ImportWizard.ImportedRelationsPage() { DataContext = this }; _importResult = importResult; NextText = "Afronden"; EditRelationCommand = new RelayCommand(EditRelation); }
internal override void ImportSubhandler(ImportResults import) { if (!string.IsNullOrEmpty(import.Template.WorksheetName)) { slowImport(import); } else { fastImport(import); } }
internal Row[] GetRows(WorkbookPart workBookPart, Sheet sheet, ImportResults import) { WorksheetPart wsPart = workBookPart.GetPartById(sheet.Id) as WorksheetPart; Row[] rows = wsPart.Worksheet.Descendants <Row>().ToArray(); if (import.Template.StartRow > 1) { //needs testing return(rows.Skip(import.Template.StartRow - 1).ToArray()); } return(rows); }
public Task <ImportResults> ImportTransactionsFromCSVAsync(string fileContent) { return(Task <ImportResults> .Run(async() => { ImportResults results = new ImportResults(); string[] lines = fileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines.Skip(1)) { if (!await _transactionRepository.AlreadyImported(line.Trim())) { Transaction transaction = null; try { //Datum,"Naam / Omschrijving","Rekening","Tegenrekening","Code","Af Bij","Bedrag (EUR)","MutatieSoort","Mededelingen" string[] values = line.Split(new string[] { "\",\"" }, StringSplitOptions.None); transaction = new Transaction(); transaction.Date = DateTime.ParseExact(values[0].Substring(1), "yyyyMMdd", CultureInfo.InvariantCulture);//20170619 transaction.AccountNumberFrom = values[2]; transaction.AccountNumberTo = values[3]; transaction.Code = values[4]; transaction.Amount = double.Parse(values[6]); if (values[5].Equals("Af", StringComparison.InvariantCultureIgnoreCase)) { transaction.Amount = -transaction.Amount; } transaction.MutationType = values[7]; transaction.Statement = values[8].Substring(0, values[8].Length - 1); if (!string.IsNullOrWhiteSpace(transaction.AccountNumberTo)) { transaction.Relation = await _relationRepository.FindRelationByAccountNumber(transaction.AccountNumberTo); } transaction.ImportLine = line.Trim(); await DetermineOrCreateRelation(transaction, results, values[1]); await _transactionRepository.SynchronizeTransactionAndRelationCategoriesAsync(transaction.Relation.ID); transaction = await _transactionRepository.AddAsync(transaction); transaction = await _transactionRepository.GetItemByIdAsync(transaction.ID); results.ImportedTransactions.Add(transaction); } catch (Exception e) { } } else { results.AlreadyImported++; } } results.Success = true; return results; })); }
protected async Task DetermineOrCreateRelation(Transaction transaction, ImportResults results, string description) { if (transaction.Relation == null && !string.IsNullOrWhiteSpace(transaction.AccountNumberFrom)) { transaction.Relation = await _relationRepository.FindRelationByAccountNumber(transaction.AccountNumberFrom); } if (transaction.Relation == null && !string.IsNullOrWhiteSpace(description)) { transaction.Relation = await _relationRepository.FindRelationByDescription(description); } if (transaction.Relation == null) { Relation relation = new Relation(); if (string.IsNullOrWhiteSpace(description)) { description = "Geen omschrijving"; } relation.Name = description; relation.Descriptions.Add(new RelationDescription() { Description = description, UserId = ServiceResolver.GetService <IUserProvider>().GetUserId() }); if (!string.IsNullOrWhiteSpace(transaction.AccountNumberFrom)) { relation.AccountNumbers.Add(new RelationAccountNumber() { AccountNumber = transaction.AccountNumberTo, UserId = ServiceResolver.GetService <IUserProvider>().GetUserId() }); } await _categoryRepository.FindCategoriesForRelation(transaction, relation); transaction.Relation = await _relationRepository.AddAsync(relation); transaction.Relation = await _relationRepository.GetItemByIdAsync(relation.ID); if (transaction.Relation.CategoryLinks.Where(b => b.Category != null).Count() == 0) { results.ImportedRelations.Insert(0, transaction.Relation); } else { results.ImportedRelations.Add(transaction.Relation); } } }
public void Insert(List <Model.Field> fields, ImportResults import, int rowIndex) { import.Template.CheckFieldTypes(fields, rowIndex, import.ShortName); this.ShouldAttemptInsert = import.Template.RowBehaviorOnFailure == Model.RowBehaviorOnFailure.Continue || (import.Template.RowBehaviorOnFailure == Model.RowBehaviorOnFailure.Break && import.Template.StartErrorId == 0); if (this.ShouldAttemptInsert) { try { this.Insert(import, fields); } catch (Exception ex) { //import.SuccessfulImportRun = false; import.Message = ex.Message; this.ShouldAttemptInsert = import.Template.RowBehaviorOnFailure == Model.RowBehaviorOnFailure.Continue; } } }
public void ImportResultsClass() { ImportResults ir1 = new ImportResults(); Assert.AreEqual(0, ir1.SuccessCount); Assert.AreEqual(0, ir1.ErrorCount); ir1.AddError(); Assert.AreEqual(0, ir1.SuccessCount); Assert.AreEqual(1, ir1.ErrorCount); ir1.AddSuccess(); Assert.AreEqual(1, ir1.SuccessCount); Assert.AreEqual(1, ir1.ErrorCount); ir1.AddError("message 1"); Assert.AreEqual(1, ir1.SuccessCount); Assert.AreEqual(2, ir1.ErrorCount); Assert.AreEqual(1, ir1.Errors.Count); Assert.AreEqual("message 1", ir1.Errors[0]); }
internal WorksheetPart GetWorksheetPart(WorkbookPart workbookPart, ImportResults import) { if (!string.IsNullOrEmpty(import.Template.WorksheetName)) { int sheetIndex = 0; foreach (WorksheetPart worksheetpart in workbookPart.WorksheetParts) { Worksheet worksheet = worksheetpart.Worksheet; string sheetName = workbookPart.Workbook.Descendants <Sheet>().ElementAt(sheetIndex).Name; if (sheetName == import.Template.WorksheetName) { return(worksheetpart); } sheetIndex++; } } var worksheetPart = workbookPart.WorksheetParts.FirstOrDefault(); return(worksheetPart); }
internal void fastImport(ImportResults import) { using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(import.ImportFileName, false)) { WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart; var cellFormats = workbookPart.WorkbookStylesPart.Stylesheet.CellFormats; var worksheetPart = GetWorksheetPart(workbookPart, import); OpenXmlReader reader = OpenXmlReader.Create(worksheetPart); var needHeader = true; List <Model.Field> fields = new List <Model.Field>(); int rowIndex = 1; while (reader.Read()) { if (reader.ElementType == typeof(Row)) { reader.ReadFirstChild(); fields.ForEach(f => f.Value = DBNull.Value); ReadCells(import, workbookPart, cellFormats, reader, needHeader, fields, rowIndex); if (needHeader) { needHeader = false; if (!import.Template.HasGoodColumnMatch(fields)) { import.Message = $"File formatting issue: file,{import.ImportFileName}, columns do not match the reference file,{import.Template.ReferenceFile}"; this.ShouldAttemptInsert = false; return; } if (import.Template.HasHeaders) { continue; } } this.Insert(fields, import, rowIndex); rowIndex++; } } } }
internal void slowImport(ImportResults import) { using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(import.ImportFileName, false)) { WorkbookPart workBookPart = spreadsheetDocument.WorkbookPart; var cellFormats = workBookPart.WorkbookStylesPart.Stylesheet.CellFormats; var sheet = GetSheet(workBookPart, import); if (sheet != null) { var needHeader = true; //its about establishing the fields first then if actually is a header it moves on List <Model.Field> fields = new List <Model.Field>(); var rows = GetRows(workBookPart, sheet, import); int rowIndex = 1; foreach (Row row in rows) { var cells = row.Elements <Cell>(); ReadCells(import, cells, cellFormats, workBookPart, needHeader, fields, rowIndex); if (needHeader) { needHeader = false; if (!import.Template.HasGoodColumnMatch(fields)) { import.Message = $"File formatting issue: file,{import.ImportFileName}, columns do not match the reference file,{import.Template.ReferenceFile}"; this.ShouldAttemptInsert = false; return; } if (import.Template.HasHeaders) { continue; } } this.Insert(fields, import, rowIndex); rowIndex++; } } } }
public void ImportRace() { var db = new RaceHorologyLib.Database(); string dbFilename = db.CreateDatabase("new.mdb"); db.Connect(dbFilename); //RaceHorologyLib.IAppDataModelDataBase db = new RaceHorologyLib.DatabaseDummy("./"); AppDataModel dm = new AppDataModel(db); // Create a Race dm.AddRace(new Race.RaceProperties { RaceType = Race.ERaceType.GiantSlalom, Runs = 2 }); ImportResults impRes = new ImportResults(); TimeSpan time = TestUtilities.Time(() => { var ir = new ImportReader(@"Teilnehmer_V1_202001301844.csv"); RaceMapping mapping = new RaceMapping(ir.Columns); RaceImport im = new RaceImport(dm.GetRace(0), mapping); impRes = im.DoImport(ir.Data); }); Assert.AreEqual(153, impRes.SuccessCount); Assert.AreEqual(0, impRes.ErrorCount); Assert.IsTrue(dm.GetParticipants().Count() == 153); Assert.IsTrue(dm.GetRace(0).GetParticipants().Count() == 153); TestContext.WriteLine(string.Format("Import took: {0:0.00} sec", time.TotalSeconds)); Assert.IsTrue(time.TotalSeconds < 4); //db.Close(); }
internal override void ImportSubhandler(ImportResults import) { var fields = new List <Model.Field>(); int rowIndex = 1; using (var sr = new StreamReader(import.ImportFileName)) { while (sr.Peek() > -1) { var line = sr.ReadLine(); if (line != "") { var row = GetSplit(import.Template.Delimiter, line); if (fields.Count == 0) { if (import.Template.HasHeaders) { CreateFieldsFromHeader(fields, row); continue; } else { CreateFieldsWithNoHeader(fields, row); } if (!import.Template.HasGoodColumnMatch(fields)) { import.Message = $"File formatting issue: file,{import.ImportFileName}, columns do not match the reference file,{import.Template.ReferenceFile}"; this.ShouldAttemptInsert = false; return; } } fields.ForEach(f => f.Value = DBNull.Value); SetFieldType(fields, row); this.Insert(fields, import, rowIndex); rowIndex++; } } } }
private void ReadCells(ImportResults import, IEnumerable <Cell> cells, CellFormats cellFormats, WorkbookPart workbookPart, bool needHeader, List <Model.Field> fields, int rowIndex) { foreach (Cell c in cells) { var cellValue = GetCellValue(workbookPart, cellFormats, c); if (needHeader) { SetHeader(import.Template.HasHeaders, fields, c, cellValue); if (import.Template.HasHeaders) { continue; } } string excelColumnReference = Regex.Replace(c.CellReference, "\\d", ""); var field = fields.FirstOrDefault(f => f.ExcelColumnReference == excelColumnReference); SetFieldType(fields, cellValue, c); if (field != null) { field.SetValue(cellValue); } } }
private void btnImport_Click(object sender, RoutedEventArgs e) { string messageTextDetails = ""; if (lbRaces.SelectedItems.Count > 0) { foreach (var r in lbRaces.SelectedItems) { Race race = r as Race; if (race != null) { RaceImport imp = new RaceImport(race, _importMapping, new ClassAssignment(_dm.GetParticipantClasses())); ImportResults results = imp.DoImport(_importReader.Data); messageTextDetails += string.Format( "Zusammenfassung für das Rennen {0}:\n" + "- Erfolgreich importierte Teilnehmer: {1}\n" + "- Nicht importierte Teilnehmer: {2}\n\n", race.ToString(), results.SuccessCount, results.ErrorCount); } } } else { ParticipantImport imp = new ParticipantImport(_dm.GetParticipants(), _importMapping, _dm.GetParticipantCategories(), new ClassAssignment(_dm.GetParticipantClasses())); ImportResults results = imp.DoImport(_importReader.Data); messageTextDetails += string.Format( "Zusammenfassung für den allgemeinen Teilnehmerimport:\n" + "- Erfolgreich importierte Teilnehmer: {0}\n" + "- Nicht importierte Teilnehmer: {1}\n\n", results.SuccessCount, results.ErrorCount); } MessageBox.Show("Der Importvorgang wurde abgeschlossen: \n\n" + messageTextDetails, "Importvorgang", MessageBoxButton.OK, MessageBoxImage.Information); DialogResult = true; }
public ImportResults <T> Import <T>(string[] Parameters) { string ImportFile = ""; var Source = Parameters[0]; FileInfo fileInfo; if (File.Exists(Source)) { ImportFile = Source; fileInfo = new FileInfo(Source); } else { throw new Exception("File not found: " + Source); } // else if (Directory.Exists(Source)) // { // var DirectoryInfo = new DirectoryInfo(Source); // foreach (var FileInfo in DirectoryInfo.EnumerateFiles()) // { // if (FileInfo.Extension == ".yaml") // { // ImportFiles.Add(FileInfo.FullName); // } // } // } var ImportResults = new ImportResults <T>(); var Deserializer = new DeserializerBuilder().Build(); ImportResults.Result = Deserializer.Deserialize <T>(File.ReadAllText(ImportFile)); ImportResults.FilePath = fileInfo.FullName; return(ImportResults); }
static private ImportResults ProcessImportedData(ExternalBankData import, ProcessThreadArguments args) { FinancialAccount assetAccount = args.Account; FinancialAccount autoDepositAccount = args.Organization.FinancialAccounts.IncomeDonations; int autoDepositLimit = 1000; // TODO: this.CurrentOrganization.Parameters.AutoDonationLimit; ImportResults result = new ImportResults(); int count = 0; int progressUpdateInterval = import.Records.Length/40; if (progressUpdateInterval > 100) { progressUpdateInterval = 100; } foreach (ExternalBankDataRecord row in import.Records) { // Update progress. count++; if (progressUpdateInterval < 2 || count % progressUpdateInterval == 0) { int percent = (count*99)/import.Records.Length; GuidCache.Set(args.Guid + "-Progress", percent); } // Update high- and low-water marks. if (row.DateTime < result.EarliestTransaction) { result.EarliestTransaction = row.DateTime; } if (row.DateTime > result.LatestTransaction) { result.LatestTransaction = row.DateTime; } string importKey = row.ImportHash; Int64 amountCents = row.TransactionNetCents; if (amountCents == 0) // defensive programming - these _should_ be duplicated in the interpreter if no "fee" field { amountCents = row.TransactionGrossCents; } if (args.Organization.Identity == 1 && assetAccount.Identity == 1 && PilotInstallationIds.IsPilot(PilotInstallationIds.PiratePartySE)) { // This is an ugly-as-f**k hack that sorts under the category "just bring our pilots the f**k back to operational // status right f*****g now". // This code can and should be safely removed once the pilot's books are closed for 2014, which should be some time mid-2015. if (row.DateTime < new DateTime(2014,03,22)) { result.DuplicateTransactions++; continue; } } FinancialTransaction transaction = FinancialTransaction.ImportWithStub(args.Organization.Identity, row.DateTime, assetAccount.Identity, amountCents, row.Description, importKey, args.CurrentUser.Identity); if (transaction != null) { // The transaction was created. Examine if the autobook criteria are true. result.TransactionsImported++; FinancialAccounts accounts = FinancialAccounts.FromBankTransactionTag(row.Description); if (accounts.Count == 1) { // This is a labelled local donation. Geography geography = accounts[0].AssignedGeography; FinancialAccount localAccount = accounts[0]; transaction.AddRow(args.Organization.FinancialAccounts.IncomeDonations, -amountCents, args.CurrentUser); transaction.AddRow(args.Organization.FinancialAccounts.CostsLocalDonationTransfers, amountCents, args.CurrentUser); transaction.AddRow(localAccount, -amountCents, args.CurrentUser); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.LocalDonationReceived, args.CurrentUser.Identity, args.Organization.Identity, geography.Identity, 0, transaction.Identity, localAccount.Identity.ToString()); } else if (row.Description.ToLowerInvariant().StartsWith(args.Organization.IncomingPaymentTag)) { // Check for previously imported payment group // TODO: MAKE FLEXIBLE - CALL PAYMENTREADERINTERFACE! // HACK HACK HACK HACK PaymentGroup group = PaymentGroup.FromTag(args.Organization, "SEBGM" + DateTime.Today.Year.ToString() + // TODO: Get tags from org row.Description.Substring(args.Organization.IncomingPaymentTag.Length).Trim()); if (group != null && group.Open) { // There was a previously imported and not yet closed payment group matching this transaction // Close the payment group and match the transaction against accounts receivable transaction.Dependency = group; group.Open = false; transaction.AddRow(args.Organization.FinancialAccounts.AssetsOutboundInvoices, -amountCents, args.CurrentUser); } } else if (amountCents < 0) { // Autowithdrawal mechanisms removed, condition kept because of downstream else-if conditions } else if (amountCents > 0) { if (row.FeeCents < 0) { // This is always an autodeposit, if there is a fee (which is never > 0.0) transaction.AddRow(args.Organization.FinancialAccounts.CostsBankFees, -row.FeeCents, args.CurrentUser); transaction.AddRow(autoDepositAccount, -row.TransactionGrossCents, args.CurrentUser); } else if (amountCents < autoDepositLimit * 100) { // Book against autoDeposit account. transaction.AddRow(autoDepositAccount, -amountCents, args.CurrentUser); } } } else { // Transaction was not imported; assume duplicate result.DuplicateTransactions++; } } // Import complete. Return true if the bookkeeping account matches the bank data. Int64 databaseAccountBalanceCents = assetAccount.BalanceTotalCents; // Subtract any transactions made after the most recent imported transaction. // This is necessary in case of Paypal and others which continuously feed the // bookkeeping account with new transactions; it will already have fed transactions // beyond the end-of-file. Int64 beyondEofCents = assetAccount.GetDeltaCents(result.LatestTransaction.AddSeconds(1), DateTime.Now.AddDays(2)); // Caution: the "AddSeconds(1)" is not foolproof, there may be other new txs on the same second. if (databaseAccountBalanceCents - beyondEofCents == import.LatestAccountBalanceCents) { Payouts.AutomatchAgainstUnbalancedTransactions(args.Organization); result.AccountBalanceMatchesBank = true; result.BalanceMismatchCents = 0; } else { result.AccountBalanceMatchesBank = false; result.BalanceMismatchCents = (databaseAccountBalanceCents - beyondEofCents) - import.LatestAccountBalanceCents; } result.CurrencyCode = args.Organization.Currency.Code; return result; }
ImportResults ImportFingerHints(bool standardPath) { ImportResults results = new ImportResults() { ProblemEncountered = true }; string FingerHintPath = Path.Combine(SynthesiaDataPath(standardPath), "fingers.xml"); FileInfo fingerHintFile = new FileInfo(FingerHintPath); if (!fingerHintFile.Exists) { f.ShowError("Couldn't find finger hint file in the Synthesia data directory. Aborting import.", "Missing fingers.xml"); return(results); } // Bulk pull the fingers out of the file Dictionary <string, string> allFingers = new Dictionary <string, string>(); try { XDocument doc = XDocument.Load(FingerHintPath); XElement topLevel = doc.Element("LocalFingerInfoList"); if (topLevel == null) { throw new InvalidDataException("Couldn't find top-level LocalFingerInfoList element."); } if (topLevel.AttributeOrDefault("version", "1") != "1") { f.ShowExclamation("Data in fingers.xml is in a newer format. Unable to import. (Check for a newer version of the metadata editor.)", "Fingers.xml too new!"); return(results); } var elements = topLevel.Elements("FingerInfo"); foreach (var fi in elements) { allFingers[fi.AttributeOrDefault("hash")] = fi.AttributeOrDefault("fingers"); } } catch (Exception ex) { f.ShowError($"Unable to read fingers.xml. Aborting import.\n\n{ex}", "Import error!"); return(results); } foreach (SongEntry s in Metadata.Songs.ToList()) { if (!allFingers.ContainsKey(s.UniqueId)) { continue; } results.Imported++; string oldHints = s.FingerHints; string newHints = allFingers[s.UniqueId]; if (oldHints == newHints) { results.Identical++; } else { s.FingerHints = newHints; Metadata.AddSong(s); results.Changed++; } } results.ProblemEncountered = false; return(results); }
private void Import_PostExecute(ImportResults results) { if (!results.Loaded) return; ViewModel.Sounds[results.Target].CwavData = results.CWAV.CwavData; }
private Task<ImportResults> Import_Execute(CwavKind cwavKind) { return Task<ImportResults>.Factory.StartNew(() => { var result = new ImportResults { Loaded = false, Target = cwavKind }; OpenFileDialog opfd = new OpenFileDialog { Filter = ThirdPartyTools.CtrWaveConveter.Present ? "Supported Files|*.wav;*.bcwav|DSP ADCPM Audio|*.bcwav|PCM Audio|*.wav" : "Supported Files|*.bcwav|DSP ADCPM Audio|*.bcwav" }; var dlg = opfd.ShowDialog(); if (dlg.HasValue && dlg.Value) { try { switch (opfd.FilterIndex) { case 1: { if (opfd.FileName.EndsWith(".bcwav", StringComparison.OrdinalIgnoreCase)) goto case 2; if (opfd.FileName.EndsWith(".wav", StringComparison.OrdinalIgnoreCase)) goto case 3; break; } case 2: { // Read CWAV var cwavData = File.ReadAllBytes(opfd.FileName); result.Loaded = true; result.CWAV = new CwavFile(cwavData); break; } case 3: { // Convert Wav var wavData = File.ReadAllBytes(opfd.FileName); byte[] cwavData = CwavFile.EncodeCwav(wavData); if (cwavData.Length == 3) { return result; } result.Loaded = true; result.CWAV = new CwavFile(cwavData); break; } } } catch { // Ignore } } return result; }); }
private void ImportCsv_Click(object sender, EventArgs e) { ImportResults results = new ImportResults(); var importCsvDialog = new OpenFileDialog(); importCsvDialog.Filter = "CSV Files | *.csv"; importCsvDialog.Title = "Select Csv File to import"; DialogResult result = importCsvDialog.ShowDialog(); if (result == DialogResult.OK) // Test result. { string csvText = System.IO.File.ReadAllText(importCsvDialog.FileName); csvText = csvText.Replace("\n", ""); var importLines = csvText.Split('\r'); var nonNullLineCount = 0; String[] headers; foreach (var importLine in importLines) { if (importLine != "") { results.NumberOfNewRecordsFound++; if (nonNullLineCount == 0) { headers = purgeCommasInTextFields(importLine).Split(','); results.NumberOfFieldsFound = headers.Length; } else { results.NumberOfRecordsImported++; var columns = purgeCommasInTextFields(importLine).Split(','); var context = new PersonalSpendingAnalysisRepo(); var id = sha256_hash(importLine); DateTime tDate; DateTime.TryParse(columns[0], out tDate); decimal tAmount; Decimal.TryParse(columns[3], out tAmount); var existingRowForThisSHA256 = context.Transaction.SingleOrDefault(x => x.SHA256 == id); if (existingRowForThisSHA256 == null) { results.NumberOfNewRecordsFound++; context.Transaction.Add(new Repo.Entities.Transaction { transactionDate = tDate, amount = tAmount, Notes = columns[2].Replace("\"", ""), SHA256 = id, }); context.SaveChanges(); } else { results.NumberOfDuplicatesFound++; } } nonNullLineCount++; } } MessageBox.Show("Import finished ( " + results.importId + " ) " + "\r" + "number of fields per row = " + results.NumberOfFieldsFound + "\r" + "number of records = " + results.NumberOfRecordsImported + "\r" + "number of duplicates found = " + results.NumberOfDuplicatesFound + "\r" + "number of new records = " + results.NumberOfNewRecordsFound ); } refresh(); } //end click
internal Sheet GetSheet(WorkbookPart workbookPart, ImportResults import) => !string.IsNullOrEmpty(import.Template.WorksheetName) ? workbookPart.Workbook.Descendants <Sheet>().FirstOrDefault(s => s.Name == import.Template.WorksheetName) : workbookPart.Workbook.Descendants <Sheet>().FirstOrDefault();