public static int AddImportLog(ChannelLogEnum type, int channelId, int tryed, int success) { ImportLog log = new ImportLog(); log.ChannelId = channelId; log.LogDate = DateTime.Now; log.LogType = (int)type; log.Tryed = tryed; log.Success = success; CanonDataContext db = Cdb.Instance; db.ImportLogs.InsertOnSubmit(log); db.SubmitChanges(); return log.LogId; }
public static Guid AddImportLog() { var importLogId = Guid.NewGuid(); var importLog = new ImportLog { Id = importLogId, ImportDate = DateTime.UtcNow }; _unitOfWork.ImportLogRepository.Add(importLog); _unitOfWork.ImportLogRepository.Save(); return importLogId; }
public ImportAssets(Guid organizationId, int departmentId, string fileName) : this(organizationId, departmentId) { _file_name = fileName; _oledb = null; if (File.Exists(_file_name)) _oledb = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + _file_name + ";Extended Properties=\"Excel 12.0;HDR=No;IMEX=1\""); _importTables = new ImportTables(); import_log = new ImportLog(); }
public ImportAssets(Guid organizationId, int departmentId) { _organizationId = organizationId; _departmentId = departmentId; _file_name = string.Empty; _oledb = null; _importTables = new ImportTables(); import_log = new ImportLog(); }
public static void ThrowCriticalImportError(string error, string processingFileName, ImportLog importLog, StringBuilder importLogNotes) { ThrowCriticalImportError(error, null, processingFileName, importLog, importLogNotes); }
public static bool ProcessRecord <RecordType, RecordLogType>(this DCDContext dc, Record record, ImportLog importLog) where RecordType : IDCD, new() where RecordLogType : IDCDRecordImportLog, new() { //First see if the record already exists IDCD entry = dc.GetRecord <RecordType>(record.Identification.RecordId); //Process delete if (record.Command == CommandType.Delete) { if (entry == null) { dc.CreateRecordLogEntry <RecordLogType>(record.Identification.RecordId, importLog, RecordImportResult.Skipped, RecordImportOperation.Delete, "Cannot delete. Record doesn't exist."); return(true); } else { try { entry.DeleteRecordOnSubmit(dc); dc.SubmitChanges(); } catch (Exception e) { dc.CreateRecordLogEntry <RecordLogType>(record.Identification.RecordId, importLog, RecordImportResult.Failure, RecordImportOperation.Delete, "Error deleting record.", e); return(false); } dc.CreateRecordLogEntry <RecordLogType>(record.Identification.RecordId, importLog, RecordImportResult.Success, RecordImportOperation.Delete, string.Empty); return(true); } } //Upsert else { RecordImportOperation op = RecordImportOperation.Insert; IDCD processingRecord; try { //If the record already exists if (entry != null) { op = RecordImportOperation.Update; //Only records that are newer than the records in the feed will be skipped if (entry.LastModified > record.Identification.LastModified) { dc.CreateRecordLogEntry <RecordLogType>(record.Identification.RecordId, importLog, RecordImportResult.Skipped, op, "Existing record has a newer Last Modified Date."); return(true); } else if (record.Content == null || string.IsNullOrEmpty(record.Content.InnerXml)) { dc.CreateRecordLogEntry <RecordLogType>(record.Identification.RecordId, importLog, RecordImportResult.Skipped, op, "Record does not have any content."); return(true); } else { entry.RecordNumber = record.Identification.RecordNumber; entry.Title = XMLFileUtilities.RemoveBrackets(record.Identification.Title); entry.LastModified = record.Identification.LastModified; entry.Created = record.Identification.Created; entry.Published = record.Identification.Created; if (!record.Identification.Published.ToString().Equals(DateTime.MinValue.ToString())) { entry.Published = record.Identification.Published; } entry.Content = record.Content.InnerXml; } } else { op = RecordImportOperation.Insert; processingRecord = new RecordType(); processingRecord.RecordId = record.Identification.RecordId; processingRecord.RecordNumber = record.Identification.RecordNumber; processingRecord.Title = XMLFileUtilities.RemoveBrackets(record.Identification.Title); processingRecord.LastModified = record.Identification.LastModified; processingRecord.Created = record.Identification.Created; processingRecord.Published = record.Identification.Created; if (!record.Identification.Published.ToString().Equals(DateTime.MinValue.ToString())) { processingRecord.Published = record.Identification.Published; } processingRecord.Content = record.Content.InnerXml; processingRecord.InsertRecordOnSubmit(dc); } dc.SubmitChanges(); } catch (Exception e) { dc.CreateRecordLogEntry <RecordLogType>(record.Identification.RecordId, importLog, RecordImportResult.Failure, op, "Error inserting/updating record.", e); return(false); } dc.CreateRecordLogEntry <RecordLogType>(record.Identification.RecordId, importLog, RecordImportResult.Success, op, string.Empty); return(true); } }
public static void CreateRecordLogEntry <RecordLogType>(this DCDContext dc, int recordId, ImportLog importLog, RecordImportResult result, RecordImportOperation operation, string notes) where RecordLogType : IDCDRecordImportLog, new() { dc.CreateRecordLogEntry <RecordLogType>(recordId, importLog, result, operation, notes, null); }
public static void CreateRecordLogEntry <RecordLogType>(this DCDContext dc, int recordId, ImportLog importLog, RecordImportResult result, RecordImportOperation operation, string notes, Exception e) where RecordLogType : IDCDRecordImportLog, new() { try { RecordLogType log = new RecordLogType(); log.RecordId = recordId; log.ImportLog = dc.ImportLogs.FirstOrDefault(w => w.Id == importLog.Id); log.Result = result.ToString(); log.Operation = operation.ToString(); log.Notes = notes + (e != null ? $"[{e.ToString()}]" : string.Empty); log.TimeStamp = DateTime.Now; log.InsertRecordOnSubmit(dc); dc.SubmitChanges(); } catch (Exception ex) { DCDImportLogger.Error("Error writing log message to database", ex); } if (result == RecordImportResult.Failure) { if (e != null) { DCDImportLogger.Error("Error processing record " + recordId + ". " + notes, e); } else { DCDImportLogger.Error("Error processing record " + recordId + ". " + notes); } } else { DCDImportLogger.Info("Successfully processed record " + recordId + "."); } }
public int Log(ImportLog action) { return(_application.Log((short)action)); }
void IPresenter.UpdateView(ImportNLogPage.ISelectedLayout layout, ImportLog importLog) { var layoutTextBoxValue = new StringBuilder(); var linksOffsets = new Dictionary <string, int>(); if (layout is ImportNLogPage.ISimpleLayout) { layoutTextBoxValue.Append(((ImportNLogPage.ISimpleLayout)layout).Value); linksOffsets.Add("", 0); } else if (layout is ImportNLogPage.ICSVLayout) { var csv = layout as ImportNLogPage.ICSVLayout; foreach (var col in csv.Params.ColumnLayouts) { if (layoutTextBoxValue.Length > 0) { layoutTextBoxValue.Append(" "); } linksOffsets.Add(col.Key, layoutTextBoxValue.Length); layoutTextBoxValue.Append(col.Value); } } else if (layout is ImportNLogPage.IJsonLayout) { Action <JsonParams.Layout> handleLayout = null; handleLayout = jsonLayout => { foreach (var attr in jsonLayout.Attrs.Values) { if (attr.SimpleLayout != null) { if (layoutTextBoxValue.Length > 0) { layoutTextBoxValue.Append(" "); } linksOffsets.Add(attr.Id, layoutTextBoxValue.Length); layoutTextBoxValue.Append(attr.SimpleLayout); } else if (attr.JsonLayout != null) { handleLayout(attr.JsonLayout); } } }; handleLayout(((ImportNLogPage.IJsonLayout)layout).Params.Root); } string headerLabelValue; IconType headerIcon; if (importLog.HasErrors) { headerLabelValue = "LogJoint can not import your NLog layout. Check messages below."; headerIcon = IconType.ErrorIcon; } else if (importLog.HasWarnings) { headerLabelValue = "LogJoint imported your NLog layout with warnings. Check messages below."; headerIcon = IconType.WarningIcon; } else { headerLabelValue = null; headerIcon = IconType.None; } var messagesList = new List <MessagesListItem>(); foreach (var message in importLog.Messages) { var linkLabel = new MessagesListItem() { Links = new List <Tuple <int, int, Action> >() }; int linksBaseIdx; linksOffsets.TryGetValue(message.LayoutId ?? "", out linksBaseIdx); StringBuilder messageText = new StringBuilder(); foreach (var fragment in message.Fragments) { if (messageText.Length > 0) { messageText.Append(' '); } var layoutSliceFragment = fragment as NLog.ImportLog.Message.LayoutSliceLink; if (layoutSliceFragment != null) { linkLabel.Links.Add(Tuple.Create(messageText.Length, layoutSliceFragment.Value.Length, (Action)(() => { view.SelectLayoutTextRange(linksBaseIdx + layoutSliceFragment.LayoutSliceStart, layoutSliceFragment.LayoutSliceEnd - layoutSliceFragment.LayoutSliceStart); }))); } messageText.Append(fragment.Value); } linkLabel.Text = messageText.ToString(); if (message.Severity == NLog.ImportLog.MessageSeverity.Error) { linkLabel.Icon = IconType.ErrorIcon; } else if (message.Severity == NLog.ImportLog.MessageSeverity.Warn) { linkLabel.Icon = IconType.WarningIcon; } else { linkLabel.Icon = IconType.NeutralIcon; } messagesList.Add(linkLabel); } view.Update(layoutTextBoxValue.ToString(), headerLabelValue, headerIcon, messagesList.ToArray()); }
protected void Page_Load(object sender, EventArgs e) { startDate = Request[startDateParam]; endDate = Request[endDateParam]; sortType = Request[sortParam]; sortDirection = Request[sortDirectionParam]; report = Request[reportParam]; backUrl = Request[backParam]; DCDContext dc = new DCDContext(); if (!IsPostBack) { DCDManager dcdMgr = new DCDManager(); //if there is a report parameter, show just that import if (!string.IsNullOrEmpty(report)) { ImportLog import = dcdMgr.GetImportLogById(int.Parse(report)); if (import != null) { litSingleImportTitle.Text = "Import: " + import.Id + ", " + import.FileName + "(" + import.ImportStart.ToShortDateString() + " " + import.ImportStart.ToShortTimeString() + ")"; phImports.Visible = false; phSingleImport.Visible = true; if (!string.IsNullOrEmpty(backUrl)) { hlBack.NavigateUrl = backUrl; } else { hlBack.Visible = false; } DataTable results = new DataTable(); results.Columns.Add("Type"); results.Columns.Add("RecordId"); results.Columns.Add("RecordNumber"); results.Columns["RecordId"].DataType = typeof(int); results.Columns.Add("Time"); results.Columns.Add("Operation"); results.Columns.Add("Result"); results.Columns.Add("Notes"); results.Columns["Time"].DataType = typeof(DateTime); List <IDCDRecordImportLog> records = dcdMgr.GetRecordsForImport(int.Parse(report)); foreach (IDCDRecordImportLog log in records) { DataRow row = results.NewRow(); if (log is DealRecordImportLog) { row["Type"] = "Deal"; Deal record = dcdMgr.GetDealByRecordId(log.RecordId.Value); if (record != null) { row["RecordNumber"] = record.RecordNumber; } } else if (log is CompanyRecordImportLog) { row["Type"] = "Company"; Company record = dcdMgr.GetCompanyByRecordId(log.RecordId.Value); if (record != null) { row["RecordNumber"] = record.RecordNumber; } } else if (log is DrugRecordImportLog) { row["Type"] = "Drug"; Drug record = dcdMgr.GetDrugByRecordId(log.RecordId.Value); if (record != null) { row["RecordNumber"] = record.RecordNumber; } } row["RecordId"] = log.RecordId; row["Time"] = log.TimeStamp.ToShortDateString() + " " + log.TimeStamp.ToShortTimeString(); row["Operation"] = log.Operation; row["Result"] = log.Result; row["Notes"] = log.Notes; results.Rows.Add(row); } //set default sort if (string.IsNullOrEmpty(sortType)) { sortType = "Time"; } if (string.IsNullOrEmpty(sortDirection)) { sortDirection = "desc"; } DataView view = new DataView(results); view.Sort = sortType + " " + sortDirection; dgSingleImport.ShowHeader = true; dgSingleImport.DataSource = view; dgSingleImport.DataBind(); } } else { if (string.IsNullOrEmpty(startDate) || string.IsNullOrEmpty(endDate)) { txtDateEnd.Text = DateTime.Today.ToShortDateString(); txtDateStart.Text = DateTime.Today.Subtract(new TimeSpan(7, 0, 0, 0)).ToShortDateString(); return; } else { txtDateStart.Text = startDate; txtDateEnd.Text = endDate; } DateTime start; DateTime end; if (!DateTime.TryParse(startDate, out start)) { dgResults.Visible = false; return; } if (!DateTime.TryParse(endDate, out end)) { dgResults.Visible = false; return; } List <ImportLog> logs = dcdMgr.GetImports(start, end); DataTable results = new DataTable(); results.Columns.Add("Id"); results.Columns["Id"].DataType = typeof(int); results.Columns.Add("Start Date"); results.Columns.Add("End Date"); results.Columns.Add("File Name"); results.Columns.Add("Result"); results.Columns.Add("Total"); results.Columns.Add("Succeeded"); results.Columns.Add("Skipped"); results.Columns.Add("Failed"); results.Columns["Start Date"].DataType = typeof(DateTime); results.Columns["End Date"].DataType = typeof(DateTime); results.Columns["Total"].DataType = typeof(int); results.Columns["Succeeded"].DataType = typeof(int); results.Columns["Skipped"].DataType = typeof(int); results.Columns["Failed"].DataType = typeof(int); foreach (ImportLog log in logs) { DataRow row = results.NewRow(); row["Id"] = log.Id; row["Start Date"] = log.ImportStart.ToShortDateString() + " " + log.ImportStart.ToShortTimeString(); row["End Date"] = log.ImportEnd.ToShortDateString() + " " + log.ImportEnd.ToShortTimeString(); row["File Name"] = log.FileName; row["Result"] = log.Result; row["Total"] = dcdMgr.GetTotalRecords(log); row["Succeeded"] = dcdMgr.GetTotalSuccess(log); row["Skipped"] = dcdMgr.GetTotalSkipped(log); row["Failed"] = dcdMgr.GetTotalFailed(log); results.Rows.Add(row); } //set default sort if (string.IsNullOrEmpty(sortType)) { sortType = "Start Date"; } if (string.IsNullOrEmpty(sortDirection)) { sortDirection = "desc"; } DataView view = new DataView(results); view.Sort = sortType + " " + sortDirection; dgResults.ShowHeader = true; dgResults.DataSource = view; dgResults.DataBind(); } } }
public async Task <ActionResult> Import(ImportViewModel model) { var stopwatch = new Stopwatch(); stopwatch.Start(); try { if (string.IsNullOrEmpty(model.Username) || string.IsNullOrEmpty(model.Password)) { return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, "Username or password empty.")); } var signInStatus = await SignInManager.PasswordSignInAsync(model.Username, model.Password, false, false); switch (signInStatus) { case SignInStatus.Success: break; case SignInStatus.LockedOut: return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, "User locked.")); default: return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, "Username or password invalid.")); } var currentUser = await Db.Users.FirstAsync(x => x.UserName == model.Username); var currentClient = currentUser.Client; var account = await Db.Accounts.FirstOrDefaultAsync(x => x.ClientId == currentClient.Id && x.Name == model.Account); if (account == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Invalid account.")); } ImporterType importer; if (!Enum.TryParse(model.Importer, true, out importer)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Invalid importer.")); } if (model.File == null || model.File.Length <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Empty file.")); } var result = new ImportResultViewModel(); var importLog = new ImportLog { AccountId = account.Id, UserId = currentUser.Id, Date = DateTime.UtcNow, Type = ImportLogType.AutomaticOnClient }; try { using (var stream = new MemoryStream(model.File)) { using (var reader = new StreamReader(stream, Encoding.UTF8)) { var concreteImporter = new ImporterFactory().GetImporter(reader, importer); var importResult = await concreteImporter.LoadFileAndImport(Db, currentClient.Id, account.Id, new RulesApplier()); result.IgnoredCount = importResult.DuplicateLinesCount; result.ImportedCount = importResult.NewLinesCount; importLog.LinesDuplicatesCount = importResult.DuplicateLinesCount; importLog.LinesFoundCount = importResult.DuplicateLinesCount + importResult.NewLinesCount; importLog.LinesImportedCount = importResult.NewLinesCount; } } } catch (Exception ex) { importLog.Log = ex.Message; return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Import failed: " + ex.Message)); } finally { // save to import log stopwatch.Stop(); importLog.Milliseconds = (int)stopwatch.ElapsedMilliseconds; Db.ImportLog.Add(importLog); await Db.SaveChangesAsync(); } return(Json(result)); } catch (Exception ex) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message)); } }
public int AddLog(ImportLog log) { return((int)DbConnection.Insert(log)); }
public ImportTable(string sheet_name, Guid organizationId, int departmentId, ref ImportLog import_log, ref ImportCustomProperty import_custom_property, IDataReaderAdapter dataReaderAdapter) { _organizationId = organizationId; _departmentId = departmentId; _require_column_list = new ImportColumns(); _require_column_list_all = new ImportColumns(); _available_column_list = new ImportColumns(); _custom_column_list = new ImportColumns(); _reader = dataReaderAdapter; _log = import_log; _import_custom_property = import_custom_property; _sheet_name = sheet_name; _table = new DataTable(); }
public static void CreateImportLogEntry(this DCDContext dc, DateTime start, string fileName, out ImportLog log) { try { log = new ImportLog(); log.ImportStart = start; log.ImportEnd = start; log.Result = ImportResult.InProgress.ToString(); log.FileName = fileName; dc.ImportLogs.InsertOnSubmit(log); dc.SubmitChanges(); //return log; } catch (Exception ex) { DCDImportLogger.Error("Error writing log message to database", ex); log = null; } //return null; }
public bool AddTable(Guid organizationId, int departmentId, string tableName, ref ImportLog importLog, ref ImportCustomProperty importCustomProperty, IDataReaderAdapter tableReader) { bool result = false; if (_tables != null) { if (!_tables.Contains(tableName)) { ImportTable _table = new ImportTable(tableName, organizationId, departmentId, ref importLog, ref importCustomProperty, tableReader); if (_table != null) { _tables.Add(tableName, _table); result = true; } } } return result; }
} // btnxBrowseFolder_Click private void btnxImport_Click(object sender, EventArgs e) // OK5 { if (!IsImporting) // mai: OK { // mai: Start "registerManager.ImportDBF_Phase1()/ImportTXT_Phase1()": //================================================================== ImportLog.deleteImportLog(); //================================================================== bool updatePendingApprovedTransaction = false; // mai: init with "false" if (RegisterManager.chkPendingApprovedTransaction()) // OK { using (FormAlertUpdatePendingApprovedTransaction formAlertUpdatePendingApprovedTransaction = new FormAlertUpdatePendingApprovedTransaction()) { DialogResult dialogResult = formAlertUpdatePendingApprovedTransaction.ShowDialog(); if (dialogResult == DialogResult.OK) { updatePendingApprovedTransaction = formAlertUpdatePendingApprovedTransaction.UpdatePendingApprovedTransaction; // mai: values preserved after close! } } } // if (RegisterManager.chkPendingApprovedTransaction()) //--------------------------------- if (updatePendingApprovedTransaction) { IsImporting = false; // mai: reset this.Close(); // will calling "FormClosing()" return; } //================================================================== if (fileTypes == Import_Const.FileTypes.DBF) { lblxMsg.Text = $@"║сея╖╢сЮ╧т╧║рц╧сЮ╒Ир╒Имаые╗р║Д©еЛ DBF"; } else if (fileTypes == Import_Const.FileTypes.TXT) { lblxMsg.Text = $@"║сея╖╢сЮ╧т╧║рц╧сЮ╒Ир╒Имаые╗р║Д©еЛ TXT"; } pgbImport.Value = 0; //------------------------------------------------------------------ picBxLoading.Visible = true; //--------------------------------- btnxBrowseFolder.Enabled = false; //--------------------------------- btnxImport.Text = $@"б║Юет║"; btnxImport.Enabled = true; //--------------------------------- btnxClose.Enabled = true; //--------------------------------- btnxExportLog.Enabled = false; //================================================================== IsImporting = true; // mai: telling that going to do "registerManager.ImportDBF()/ImportText()" and telling that thread is running for importing and use to stop thread when press import-btn again, before start thread set this to true!!! //------------------------------------------------------------------ // mai: share with "registerManager.ImportDBF_Phase1()/ImportTXT_Phase1()--btnxImport_Click()" and "_frmImportSummary.RegisterManager--importFinished()" registerManager = new RegisterManager(); // Clear old value // org // mai: reset by create new instance. // mai: OK registerManager.CallBackForm = this; // mai: use to call member of this Form from other Form, e.g. _frmImportEclaim.Import!!! registerManager.FolderPath = txtBxxBrowseFolder.Text; if (fileTypes == Import_Const.FileTypes.DBF) { new Thread(new ThreadStart(registerManager.importDBF_Phase1)).Start(); } else if (fileTypes == Import_Const.FileTypes.TXT) { new Thread(new ThreadStart(registerManager.importTXT_Phase1)).Start(); } } // if (!IsImporting) else { // mai: Cancel thread "registerManager.ImportDBF_Phase1()/ImportTXT_Phase1()" with "IsImporting = false": // mai: added: //DialogResult dialogResult = FormMyMessageBox.Show("╥Хр╧╣Им╖║рцб║Юет║║рц╧сЮ╒Ир╒ИмаыеЦ╙ХкцвмДаХ", MyConst.APP_NAME, MessageBoxButtons.YesNo); //if (dialogResult == DialogResult.Yes) { //================================================================== lblxMsg.Text = $@"║сея╖б║Юет║║рц╧сЮ╒Ир╒Имаые"; //pgbImport.Value = 0; //------------------------------------------------------------------ picBxLoading.Visible = true; //--------------------------------- btnxBrowseFolder.Enabled = false; //--------------------------------- btnxImport.Text = $@"╧сЮ╒Ир╒Имаые"; btnxImport.Enabled = false; //--------------------------------- btnxClose.Enabled = false; //--------------------------------- btnxExportLog.Enabled = false; //================================================================== IsImporting = false; // mai: reset, and also use this var to stop thread of "registerManager.ImportDBF_Phase1()/ImportTXT_Phase1()". } // if--dialogResult-confirm-cancel } // else // if (!IsImporting) } // btnxImport_Click