public void RunWorker(BackgroundWorker worker, DoWorkEventArgs args) { var getProgress = args.Argument as Func <ProgressState> ?? new Func <ProgressState>(() => ProgressState.Empty); CurrentProgress = getProgress() ?? ProgressState.Empty; ImportStarted(this, EventArgs.Empty); var type = Type.GetType(DataContextObject.SelectedDataType.Target.ClrType); var sessionFactory = DataContextObject.ShellContext.SessionFactoryHolder.GetSessionFactory(); CurrentProgress = new ProgressState(0, DataContextObject.TargetsToImport.Count); using (NHibernate.ISession session = sessionFactory.OpenSession()) { var current = 0; var total = DataContextObject.TargetsToImport.Count; int batchSize = Settings.Default.BatchSize; using (var tx = session.BeginTransaction()) { while (current < total && !args.Cancel && !Cancelled) { if (worker.CancellationPending) { args.Cancel = true; } else { var target = DataContextObject.TargetsToImport[current]; (target as ContentPartRecord).ContentItemRecord = DataContextObject.CurrentContentItem; try { session.Save(DataContextObject.TargetsToImport[current]); } catch (Exception ex) { GuardError(current, ex); } finally { if (current % batchSize == 0) { //20, same as the ADO batch size session.Flush(); session.Clear(); } current++; var progress = new ProgressState(current, total); worker.ReportProgress((int)Math.Floor(progress.Ratio * 100d), progress); if (current % 1000 == 0) { Application.Current.DoEvents(); } } } } session.Flush(); session.Clear(); tx.Commit(); } session.Close(); } }
public static Riferimento Riferimento_Create( String Nominativo, String Telefono, String EMail ) { try { Riferimento aRiferimento = new Riferimento(); NHibernate.ISession aNHibernateSession = NHibernateHelper.GetOrCreateCurrentSession(); aRiferimento.Nominativo = Nominativo; aRiferimento.Telefono = Telefono; aRiferimento.EMail = EMail; aNHibernateSession.Save(aRiferimento); aNHibernateSession.Flush(); return(aRiferimento); } catch (Exception) { return(null); } }
public static Recapito Recapito_Create( String Indirizzo, String Localita, String Provincia ) { try { Recapito aRecapito = new Recapito(); NHibernate.ISession aNHibernateSession = NHibernateHelper.GetOrCreateCurrentSession(); aRecapito.Indirizzo = Indirizzo; aRecapito.Localita = Localita; aRecapito.Provincia = Provincia; aNHibernateSession.Save(aRecapito); aNHibernateSession.Flush(); return(aRecapito); } catch (Exception) { return(null); } }
private void BatchSaveInTransaction(IList <AppAuditLog> logs) { logger.LogInformation($"Batch save {logs.Count} audit logs to db ..."); session.SetBatchSize(logs.Count); using (var tx = session.BeginTransaction()) { try { session.SetBatchSize(logs.Count); foreach (var log in logs) { session.Save(log); } session.Flush(); session.Clear(); tx.Commit(); } catch (Exception ex) { tx?.Rollback(); logger.LogError(ex, "Can not save audit logs with transactions."); foreach (var log in logs) { logger.LogError(log.ToJson()); } } } }
public static SegnalazionePreliminareDanno SegnalazionePreliminareDanno_Create( Recapito Recapito, OggettoSegnalazionePreliminareDanno Oggetto ) { try { SegnalazionePreliminareDanno aSegnalazionePreliminareDanno = new SegnalazionePreliminareDanno(); NHibernate.ISession aNHibernateSession = NHibernateHelper.GetOrCreateCurrentSession(); aSegnalazionePreliminareDanno.Recapito = Recapito; aSegnalazionePreliminareDanno.Oggetto = Oggetto; aSegnalazionePreliminareDanno.DataCreazione = DateTime.Now; aSegnalazionePreliminareDanno.Definitivo = false; aNHibernateSession.Save(aSegnalazionePreliminareDanno); aNHibernateSession.Flush(); return(aSegnalazionePreliminareDanno); } catch (Exception) { return(null); } }
private void context_EndRequest(object sender, EventArgs e) { System.Web.HttpApplication aHttpApplication = (System.Web.HttpApplication)sender; System.Web.HttpContext aHttpContext = aHttpApplication.Context; NHibernate.ISession aNHibernateSession = NHibernateHelper.GetCurrentSession(aHttpContext); if (aNHibernateSession != null) { aNHibernateSession.Flush(); aNHibernateSession.Close(); } NHibernateHelper.DisposeCurrentSession(aHttpContext); }
private void OnCellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = ownersView.Rows[e.RowIndex]; object currentValue = row.Cells[e.ColumnIndex].Value; int id = (int)row.Tag; NHibernate.ISession session = obj_lib.Module.OpenSession(); SEPO_TP_WORKSHOP_OWNER dbRow = session.Get <SEPO_TP_WORKSHOP_OWNER>(id); dbRow.OWNER = (int?)currentValue; session.Update(dbRow); session.Flush(); }
private void OnCellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = operationsView.Rows[e.RowIndex]; object currentValue = row.Cells[e.ColumnIndex].Value; int id = (int)row.Tag; NHibernate.ISession session = obj_lib.Module.OpenSession(); SEPO_TECH_OPER_LINKS dbRow = session.Get <SEPO_TECH_OPER_LINKS>(id); dbRow.OMPID = (int?)currentValue; session.Update(dbRow); session.Flush(); }
public static void SegnalazionePreliminareDanno_AddRiferimento( SegnalazionePreliminareDanno SegnalazionePreliminareDanno, Riferimento Riferimento ) { try { NHibernate.ISession aNHibernateSession = NHibernateHelper.GetOrCreateCurrentSession(); SegnalazionePreliminareDanno.Riferimento = Riferimento; aNHibernateSession.Flush(); } catch (Exception) { } }
public List <ContatoEntitis> List() { try { List <ContatoEntitis> retorno = new List <ContatoEntitis>(); using (NHibernate.ISessionFactory sessionFactory = SessionFactoryBuilder.BuildSessionFactory()) { using (NHibernate.ISession session = sessionFactory.OpenSession()) { retorno = session.Query <ContatoEntitis>().ToList(); session.Flush(); } } return(retorno); } catch (Exception ex) { throw; } }
protected override void Scan() { NHibernate.ISession session = DatabaseInterface.DataSession; try { // Try to pull out links for Guid art SaveWMPLibraryData(session); } catch { }// Ignore this. IList <AlbumArtPath> artPaths = session. CreateCriteria(typeof(AlbumArtPath)) .AddOrder(new Order("Album", true)) .List <AlbumArtPath>(); foreach (AlbumArtPath path in artPaths) { foreach (FileInfo file in FileSystem.GetFiles(path.Path, new List <string> { "JPG", "JPEG" })) { switch (file.Name.Substring(0, file.Name.Length - file.Extension.Length).ToUpper()) { case "FOLDER": CreateAndSaveLargeArt(path.Artist, path.Album, file.FullName, session); break; case "ALBUMARTSMALL": CreateAndSaveLargeArt(path.Artist, path.Album, file.FullName, session); break; case "COVER": CreateAndSaveLargeArt(path.Artist, path.Album, file.FullName, session); break; } } } session.Flush(); }
public ContatoEntitis Get(int id) { try { ContatoEntitis retorno = new ContatoEntitis(); using (NHibernate.ISessionFactory sessionFactory = SessionFactoryBuilder.BuildSessionFactory()) { using (NHibernate.ISession session = sessionFactory.OpenSession()) { retorno = session.Get <ContatoEntitis>(id); session.Flush(); } } return(retorno); } catch (Exception exs) { throw; } }
public List <ToolStripItem> LoadLayoutMenu() { var noDatabase = _session == null; var currentMenuLevel = new List <ToolStripItem>(); ToolStripMenuItem saveMenu; ToolStripMenuItem loadMenu; ToolStripMenuItem deleteMenu = null; var menuList = new List <ToolStripItem>(); #region Load Options //set up user load options foreach (var item in _userLayoutList) { var tempItem = item; var newOption = new ToolStripMenuItem { Text = item.Name + (CurrentLayout.Name == item.Name ? " (current)" : "") }; newOption.Click += (s, e) => CurrentLayout = tempItem; currentMenuLevel.Add(newOption); } //check if more needs to be done if (noDatabase) { loadMenu = new ToolStripMenuItem("Load", null, currentMenuLevel.ToArray()); } else { currentMenuLevel.Add(new ToolStripSeparator()); IList <LayoutProperty> databaseLayouts; lock (_session) databaseLayouts = _session.QueryOver <LayoutProperty>().List(); foreach (var item in databaseLayouts) { var tempItem = item; var newOption = new ToolStripMenuItem { Text = item.Name + (CurrentLayout.Name == item.Name ? " (current)" : "") }; newOption.Click += (s, e) => CurrentLayout = tempItem; currentMenuLevel.Add(newOption); } loadMenu = new ToolStripMenuItem("Load", null, currentMenuLevel.ToArray()); } #endregion #region Save Options //create user save list currentMenuLevel = new List <ToolStripItem>(); foreach (var item in _userLayoutList) { var tempItem = item; var newOption = new ToolStripMenuItem { Text = item.Name + (CurrentLayout.Name == item.Name ? " (current)" : "") }; newOption.Click += (s, e) => { var saveColumns = false; var formProperties = new Dictionary <string, FormProperty>(); if (MessageBox.Show("Save column settings as well?", "Save", MessageBoxButtons.YesNo) == DialogResult.Yes) { saveColumns = true; foreach (var form in _persistentForms) { formProperties[form.Name] = form.GetCurrentProperties(false); } } updateLayout(tempItem, saveColumns, false, formProperties); }; currentMenuLevel.Add(newOption); } //replace system default (not editable) with new layout option { var newLayout = new ToolStripMenuItem("New Local Layout"); newLayout.Click += (s, e) => { var textInput = new TextInputPrompt("Layout Name", true, string.Empty); if (textInput.ShowDialog() == DialogResult.OK) { var formProperties = new Dictionary <string, FormProperty>(); if (textInput.GetCheckState()) { foreach (var form in _persistentForms) { formProperties[form.Name] = form.GetCurrentProperties(false); } } saveNewLayout(textInput.GetText(), textInput.GetCheckState(), false, formProperties); } }; currentMenuLevel.RemoveAt(0); currentMenuLevel.Insert(0, newLayout); } //check if more needs to be done if (noDatabase) { saveMenu = new ToolStripMenuItem("Save", null, currentMenuLevel.ToArray()); } else { var currentDatabaseMenuLevel = new List <ToolStripItem>(); currentMenuLevel.Add(new ToolStripSeparator()); IList <LayoutProperty> databaseLayouts; lock (_session) databaseLayouts = _session.QueryOver <LayoutProperty>().List(); foreach (var item in databaseLayouts) { var newOption = new ToolStripMenuItem { Text = item.Name + (CurrentLayout.Name == item.Name ? " (current)" : "") }; LayoutProperty tempItem = item; newOption.Click += (s, e) => { var saveColumns = false; var formProperties = new Dictionary <string, FormProperty>(); if (MessageBox.Show("Save column settings as well?", "Save", MessageBoxButtons.YesNo) == DialogResult.Yes) { saveColumns = true; foreach (var form in _persistentForms) { formProperties[form.Name] = form.GetCurrentProperties(false); } } updateLayout(tempItem, saveColumns, true, formProperties); }; currentDatabaseMenuLevel.Add(newOption); } //Add new layout option { var newLayout = new ToolStripMenuItem("New Database Layout"); newLayout.Click += (s, e) => { var textInput = new TextInputPrompt("Layout Name", true, string.Empty); if (textInput.ShowDialog() == DialogResult.OK) { var formProperties = new Dictionary <string, FormProperty>(); if (textInput.GetCheckState()) { foreach (var form in _persistentForms) { formProperties[form.Name] = form.GetCurrentProperties(false); } } saveNewLayout(textInput.GetText(), textInput.GetCheckState(), true, formProperties); } }; currentDatabaseMenuLevel.Insert(0, newLayout); } currentMenuLevel.AddRange(currentDatabaseMenuLevel); saveMenu = new ToolStripMenuItem("Save", null, currentMenuLevel.ToArray()); } #endregion #region Delete Options //set up user delete options currentMenuLevel = new List <ToolStripItem>(); foreach (var item in _userLayoutList) { var tempItem = item; var newOption = new ToolStripMenuItem { Text = item.Name }; newOption.Click += (s, e) => { if (MessageBox.Show(string.Format("Are you sure you want to delete '{0}'?", tempItem.Name), "Delete", MessageBoxButtons.YesNo) == DialogResult.Yes) { _userLayoutList.Remove(tempItem); SaveUserLayoutList(); } }; currentMenuLevel.Add(newOption); } //Dont allow user to delete defaults currentMenuLevel.RemoveRange(0, 2); //dont delete if nothing to delete, but check for database first if (noDatabase) { deleteMenu = currentMenuLevel.Count > 0 ? new ToolStripMenuItem("Delete", null, currentMenuLevel.ToArray()) : null; } else { var currentDatabaseMenuLevel = new List <ToolStripItem>(); if (currentMenuLevel.Count > 0) { currentMenuLevel.Add(new ToolStripSeparator()); } IList <LayoutProperty> databaseLayouts; lock (_session) databaseLayouts = _session.QueryOver <LayoutProperty>().List(); foreach (var item in databaseLayouts) { var tempItem = item; var newOption = new ToolStripMenuItem { Text = item.Name }; newOption.Click += (s, e) => { if (MessageBox.Show(string.Format("Are you sure you want to delete '{0}'?", tempItem.Name), "Delete", MessageBoxButtons.YesNo) == DialogResult.Yes) { _session.Delete(tempItem); _session.Flush(); } }; currentDatabaseMenuLevel.Add(newOption); } currentDatabaseMenuLevel.RemoveAt(0); currentMenuLevel.AddRange(currentDatabaseMenuLevel); if (currentMenuLevel.Count > 0) { deleteMenu = new ToolStripMenuItem("Delete", null, currentMenuLevel.ToArray()); } } #endregion menuList.Add(saveMenu); menuList.Add(loadMenu); if (deleteMenu != null) { menuList.Add(deleteMenu); } return(menuList); }
static void Main(string[] args) { using (NHibernate.ISessionFactory sessionFactory = SessionFactoryBuilder.BuildSessionFactory()) { using (NHibernate.ISession session = sessionFactory.OpenSession()) { ///session.FlushMode = NHibernate.FlushMode. //============================================================================================= //using (NHibernate.ITransaction transaction = session.BeginTransaction()) //{ // Language languageEN = new Language() { LanguageId = "EN", Name = "English" }; // Language languageES = new Language() { LanguageId = "ES", Name = "Spanish" }; // Classroom classroom1 = new Classroom() { Name = "Class 1" }; // Classroom classroom2 = new Classroom() { Name = "Class 2" }; // Do(session.Save, languageEN, languageES, classroom1, classroom2); // transaction.Commit(); //} //============================================================================================= //============================================================================================= //var EN = session.Get<Language>("EN"); //============================================================================================= //============================================================================================= Classroom classroom3 = new Classroom() { Name = "Class 3" }; Language languagePT = new Language() { LanguageId = "PT", Name = "Portuguese" }; Student studentLuiz = new Student() { FullName = "Luis Carlos Faria", Language = languagePT, Classrooms = new List <Classroom>() { classroom3 } }; Student studentTatiana = new Student() { FullName = "Tatiana", Language = languagePT, }; Classroom classroom4 = new Classroom() { Name = "Class 4", Students = new List <Student> { studentTatiana } }; Do(session.Save, classroom3, classroom4, languagePT, studentLuiz, studentTatiana); session.Flush(); //============================================================================================= Console.WriteLine("Hello World!"); } } }
protected SegnalazionePreliminareDanno AddDanno() { SegnalazionePreliminareDanno aSegnalazionePreliminareDanno = new SegnalazionePreliminareDanno(); NHibernate.ISession aNHibernateISession = NHibernateHelper.GetOrCreateCurrentSession(); aSegnalazionePreliminareDanno.Oggetto = Manager.OggettiSegnalazionePreliminareDanno_GetAll()[rbList.SelectedIndex]; aSegnalazionePreliminareDanno.DataCreazione = DateTime.Now; aSegnalazionePreliminareDanno.Definitivo = true; // false se si vuole gestire la pratica successivamente aNHibernateISession.Save(aSegnalazionePreliminareDanno); //RECAPITO Recapito aRecapito = new Recapito(); aRecapito.Indirizzo = txtIndi.Text; aRecapito.Localita = txtLocal.Text; aRecapito.Provincia = txtProv.Text; aNHibernateISession.Save(aRecapito); aSegnalazionePreliminareDanno.Recapito = aRecapito; //aNHibernateISession.Flush(); //DETTAGLIO DettaglioSegnalazionePreliminareDanno aDettaglio = new DettaglioSegnalazionePreliminareDanno(); aDettaglio.Corpo = txtDexDanno.Text; aDettaglio.DataCreazione = DateTime.Now; aSegnalazionePreliminareDanno.Dettagli.Add(aDettaglio); aDettaglio.SegnalazionePreliminareDanno = aSegnalazionePreliminareDanno; aNHibernateISession.Save(aDettaglio); //FILE IMMAGINE if (FileUpload1.HasFile) { Random r = new Random(); string sFilename = r.Next(10001, 99999) + "_" + FileUpload1.FileName.Trim(); FileUpload1.SaveAs(Server.MapPath("public/" + sFilename)); Hackathon.Need2.Model.File aFile = new Hackathon.Need2.Model.File(); aFile.Nome = sFilename; aFile.Estensione = ""; aDettaglio.File = aFile; aNHibernateISession.Save(aFile); aDettaglio.File = aFile; } ; //RIFERIMENTO PERSONALE Riferimento aRiferimento = new Riferimento(); aRiferimento.Nominativo = txtNominativo.Text; aRiferimento.EMail = txtEmail.Text; aRiferimento.Telefono = txtTel.Text; aNHibernateISession.Save(aRiferimento); aSegnalazionePreliminareDanno.Riferimento = aRiferimento; aNHibernateISession.Flush(); return(aSegnalazionePreliminareDanno); }
public static SegnalazionePreliminareDanno Test() { SegnalazionePreliminareDanno aSegnalazionePreliminareDanno = new SegnalazionePreliminareDanno(); NHibernate.ISession aNHibernateISession = NHibernateHelper.GetOrCreateCurrentSession(); aSegnalazionePreliminareDanno.Oggetto = Manager.OggettiSegnalazionePreliminareDanno_GetAll()[0]; aSegnalazionePreliminareDanno.DataCreazione = DateTime.Now; aSegnalazionePreliminareDanno.Definitivo = true; aNHibernateISession.Save(aSegnalazionePreliminareDanno); Recapito aRecapito = new Recapito(); aRecapito.Indirizzo = "Indirizzo"; aRecapito.Localita = "Città"; aRecapito.Provincia = "Provincia"; aNHibernateISession.Save(aRecapito); aSegnalazionePreliminareDanno.Recapito = aRecapito; //aNHibernateISession.Flush(); DettaglioSegnalazionePreliminareDanno aDettaglio = new DettaglioSegnalazionePreliminareDanno(); aDettaglio.Corpo = "Commento danni da segnalare..."; aDettaglio.DataCreazione = DateTime.Now; aSegnalazionePreliminareDanno.Dettagli.Add(aDettaglio); aDettaglio.SegnalazionePreliminareDanno = aSegnalazionePreliminareDanno; aNHibernateISession.Save(aDettaglio); File aFile = new File(); aFile.Nome = "Crepa.jpg"; aFile.Estensione = ".jpg"; aNHibernateISession.Save(aFile); aDettaglio.File = aFile; Riferimento aRiferimento = new Riferimento(); aRiferimento.Nominativo = "Nome Cognome"; aRiferimento.EMail = "*****@*****.**"; aRiferimento.Telefono = "123456789"; aNHibernateISession.Save(aRiferimento); aSegnalazionePreliminareDanno.Riferimento = aRiferimento; aNHibernateISession.Flush(); return(aSegnalazionePreliminareDanno); }