Performance improvement of automated renaming of paths and sequences.
This commit is contained in:
@@ -176,6 +176,7 @@ namespace TBF
|
||||
}
|
||||
}
|
||||
|
||||
bool updateRelatedItems = false;
|
||||
if (!string.IsNullOrEmpty(warnings))
|
||||
{
|
||||
string message = string.Format("{0}{1}{2}", warnings, Environment.NewLine,
|
||||
@@ -188,22 +189,42 @@ namespace TBF
|
||||
}
|
||||
else if (dr == DialogResult.Yes)
|
||||
{
|
||||
updateRelatedItems = true;
|
||||
}
|
||||
}
|
||||
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
using (var transaction = Session.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (updateRelatedItems)
|
||||
{
|
||||
for (int i = 0; i < pathsTabControl.TabPages.Count; i++)
|
||||
{
|
||||
TabPage tab = pathsTabControl.TabPages[i];
|
||||
if (tab.Tag is ITabWithListViewEx) (tab.Tag as ITabWithListViewEx).UpdateRelatedItems(renameInfo[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
foreach (TabPage tab in pathsTabControl.TabPages)
|
||||
{
|
||||
(tab.Tag as ITabWithListViewEx).OkBtnClicked();
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
transaction.Rollback();
|
||||
Cursor.Current = Cursors.Default;
|
||||
|
||||
MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
log.ErrorFormat("Update of paths in the database failed: {0}", exc.Message);
|
||||
}
|
||||
}
|
||||
|
||||
Cursor.Current = Cursors.Default;
|
||||
|
||||
Program.LocalSettings.PathsDlgLeft = Location.X;
|
||||
|
||||
+3
-3
@@ -88,11 +88,11 @@ namespace TBF.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {0} path '{1}' used by {2} tests will be renamed.{3}.
|
||||
/// Looks up a localized string similar to {0} path '{1}' used by {2} tests will be renamed to '{3}'.{4}.
|
||||
/// </summary>
|
||||
internal static string _0_path_1_used_by_2_tests_will_be_renamed_3 {
|
||||
internal static string _0_path_1_used_by_2_tests_will_be_renamed_to_3_4 {
|
||||
get {
|
||||
return ResourceManager.GetString("_0_path_1_used_by_2_tests_will_be_renamed_3", resourceCulture);
|
||||
return ResourceManager.GetString("_0_path_1_used_by_2_tests_will_be_renamed_to_3_4", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1768,8 +1768,8 @@
|
||||
<data name="_0_path_1_used_by_2_tests_will_be_removed_3" xml:space="preserve">
|
||||
<value>{0} path '{1}' used by {2} tests will be removed.{3}</value>
|
||||
</data>
|
||||
<data name="_0_path_1_used_by_2_tests_will_be_renamed_3" xml:space="preserve">
|
||||
<value>{0} path '{1}' used by {2} tests will be renamed.{3}</value>
|
||||
<data name="_0_path_1_used_by_2_tests_will_be_renamed_to_3_4" xml:space="preserve">
|
||||
<value>{0} path '{1}' used by {2} tests will be renamed to '{3}'.{4}</value>
|
||||
</data>
|
||||
<data name="Do_you_want_to_update_related_tests_and_procedures" xml:space="preserve">
|
||||
<value>Do you want to update related tests and procedures?</value>
|
||||
|
||||
@@ -422,38 +422,43 @@ namespace TBF
|
||||
{
|
||||
if (updateRelatedItems)
|
||||
{
|
||||
foreach (var item in tests)
|
||||
foreach (var ri in renameInfo)
|
||||
{
|
||||
bool updated = false;
|
||||
string newSeqName;
|
||||
if (!string.IsNullOrEmpty(item.RelTransBefore) && renameInfo.TryGetValue(item.RelTransBefore, out newSeqName))
|
||||
var tests = Session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => (x.RelTransBefore == ri.Key))
|
||||
.List();
|
||||
foreach (var t in tests)
|
||||
{
|
||||
item.RelTransBefore = newSeqName;
|
||||
updated = true;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(item.TransitionAfter) && renameInfo.TryGetValue(item.TransitionAfter, out newSeqName))
|
||||
{
|
||||
item.TransitionAfter = newSeqName;
|
||||
updated = true;
|
||||
}
|
||||
if (updated) Session.SaveOrUpdate(item);
|
||||
t.RelTransBefore = ri.Value;
|
||||
Session.Update(t);
|
||||
}
|
||||
|
||||
foreach (var item in procedures)
|
||||
tests = Session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => (x.TransitionAfter == ri.Key))
|
||||
.List();
|
||||
foreach (var t in tests)
|
||||
{
|
||||
bool updated = false;
|
||||
string newSeqName;
|
||||
if (!string.IsNullOrEmpty(item.TransitionStart) && renameInfo.TryGetValue(item.TransitionStart, out newSeqName))
|
||||
{
|
||||
item.TransitionStart = newSeqName;
|
||||
updated = true;
|
||||
t.TransitionAfter = ri.Value;
|
||||
Session.Update(t);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(item.TransitionEnd) && renameInfo.TryGetValue(item.TransitionEnd, out newSeqName))
|
||||
|
||||
var procedures = Session.QueryOver<Config.Entities.Procedure>()
|
||||
.Where(x => (x.TransitionStart == ri.Key))
|
||||
.List();
|
||||
foreach (var p in procedures)
|
||||
{
|
||||
item.TransitionEnd = newSeqName;
|
||||
updated = true;
|
||||
p.TransitionStart = ri.Value;
|
||||
Session.Update(p);
|
||||
}
|
||||
|
||||
procedures = Session.QueryOver<Config.Entities.Procedure>()
|
||||
.Where(x => (x.TransitionEnd == ri.Key))
|
||||
.List();
|
||||
foreach (var p in procedures)
|
||||
{
|
||||
p.TransitionEnd = ri.Value;
|
||||
Session.Update(p);
|
||||
}
|
||||
if (updated) Session.SaveOrUpdate(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,7 +490,9 @@ namespace TBF
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
transaction.Rollback();
|
||||
Cursor.Current = Cursors.Default;
|
||||
|
||||
MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
log.ErrorFormat("Update of sequences in the database failed: {0}", e2.Message);
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ namespace TBF.UiControls
|
||||
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_renamed_3, Strings.BenchTabPageTitle, entity.Name, occurances, Environment.NewLine);
|
||||
warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_renamed_to_3_4, Strings.BenchTabPageTitle, entity.OriName, occurances, entity.Name, Environment.NewLine);
|
||||
renmInfo.Add(entity.OriName, entity.Name);
|
||||
}
|
||||
}
|
||||
@@ -351,13 +351,16 @@ namespace TBF.UiControls
|
||||
|
||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||
{
|
||||
foreach (var tst in parent.Tests)
|
||||
foreach (var ri in renameInfo)
|
||||
{
|
||||
string newPathName;
|
||||
if (!string.IsNullOrEmpty(tst.BenchPath) && renameInfo.TryGetValue(tst.BenchPath, out newPathName))
|
||||
var tests = parent.Session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => x.BenchPath == ri.Key)
|
||||
.List();
|
||||
|
||||
foreach (var t in tests)
|
||||
{
|
||||
tst.BenchPath = newPathName;
|
||||
Config.FluentCommon.SaveToDb(parent.Session, tst);
|
||||
t.BenchPath = ri.Value;
|
||||
parent.Session.Update(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,11 +375,11 @@ namespace TBF.UiControls
|
||||
/// Update the database
|
||||
foreach (var entity in ToBeRemovedItems)
|
||||
{
|
||||
Config.FluentCommon.DeleteFromDb(parent.Session, entity);
|
||||
parent.Session.Delete(entity);
|
||||
}
|
||||
foreach (var entity in MyItems)
|
||||
{
|
||||
Config.FluentCommon.SaveToDb(parent.Session, entity);
|
||||
parent.Session.SaveOrUpdate(entity);
|
||||
}
|
||||
|
||||
/// Update the column widths
|
||||
|
||||
@@ -348,7 +348,7 @@ namespace TBF.UiControls
|
||||
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_renamed_3, Strings.FeedingTabPageTitle, entity.Name, occurances, Environment.NewLine);
|
||||
warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_renamed_to_3_4, Strings.FeedingTabPageTitle, entity.OriName, occurances, entity.Name, Environment.NewLine);
|
||||
renmInfo.Add(entity.OriName, entity.Name);
|
||||
}
|
||||
}
|
||||
@@ -359,13 +359,16 @@ namespace TBF.UiControls
|
||||
|
||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||
{
|
||||
foreach (var tst in parent.Tests)
|
||||
foreach (var ri in renameInfo)
|
||||
{
|
||||
string newPathName;
|
||||
if (!string.IsNullOrEmpty(tst.FeedingPath) && renameInfo.TryGetValue(tst.FeedingPath, out newPathName))
|
||||
var tests = parent.Session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => x.FeedingPath == ri.Key)
|
||||
.List();
|
||||
|
||||
foreach (var t in tests)
|
||||
{
|
||||
tst.FeedingPath = newPathName;
|
||||
Config.FluentCommon.SaveToDb(parent.Session, tst);
|
||||
t.FeedingPath = ri.Value;
|
||||
parent.Session.Update(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,13 +383,12 @@ namespace TBF.UiControls
|
||||
/// Update the database
|
||||
foreach (var entity in ToBeRemovedItems)
|
||||
{
|
||||
Config.FluentCommon.DeleteFromDb(parent.Session, entity);
|
||||
parent.Session.Delete(entity);
|
||||
}
|
||||
foreach (var entity in MyItems)
|
||||
{
|
||||
Config.FluentCommon.SaveToDb(parent.Session, entity);
|
||||
parent.Session.SaveOrUpdate(entity);
|
||||
}
|
||||
parent.Session.Flush();
|
||||
|
||||
/// Update the column widths
|
||||
Program.LocalSettings.FeedingColumnWidths = new int[Columns.Count];
|
||||
|
||||
@@ -280,7 +280,7 @@ namespace TBF.UiControls
|
||||
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_renamed_3, Strings.Heat_meter_sensors, entity.Name, occurances, Environment.NewLine);
|
||||
warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_renamed_to_3_4, Strings.Heat_meter_sensors, entity.OriName, occurances, entity.Name, Environment.NewLine);
|
||||
renmInfo.Add(entity.OriName, entity.Name);
|
||||
}
|
||||
}
|
||||
@@ -292,13 +292,16 @@ namespace TBF.UiControls
|
||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||
{
|
||||
#if HEAT_METERS
|
||||
foreach (var tst in parent.Tests)
|
||||
foreach (var ri in renameInfo)
|
||||
{
|
||||
string newPathName;
|
||||
if (!string.IsNullOrEmpty(tst.HeatMetersPath) && renameInfo.TryGetValue(tst.HeatMetersPath, out newPathName))
|
||||
var tests = parent.Session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => x.HeatMetersPath == ri.Key)
|
||||
.List();
|
||||
|
||||
foreach (var t in tests)
|
||||
{
|
||||
tst.HeatMetersPath = newPathName;
|
||||
Config.FluentCommon.SaveToDb(parent.Session, tst);
|
||||
t.HeatMetersPath = ri.Value;
|
||||
parent.Session.Update(t);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -315,11 +318,11 @@ namespace TBF.UiControls
|
||||
/// Update the database
|
||||
foreach (var entity in ToBeRemovedItems)
|
||||
{
|
||||
Config.FluentCommon.DeleteFromDb(parent.Session, entity);
|
||||
parent.Session.Delete(entity);
|
||||
}
|
||||
foreach (var entity in MyItems)
|
||||
{
|
||||
Config.FluentCommon.SaveToDb(parent.Session, entity);
|
||||
parent.Session.SaveOrUpdate(entity);
|
||||
}
|
||||
|
||||
/// Update the column widths
|
||||
|
||||
@@ -216,7 +216,7 @@ namespace TBF.UiControls
|
||||
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_renamed_3, Strings.MetersTabPageTitle, entity.Name, occurances, Environment.NewLine);
|
||||
warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_renamed_to_3_4, Strings.MetersTabPageTitle, entity.OriName, occurances, entity.Name, Environment.NewLine);
|
||||
renmInfo.Add(entity.OriName, entity.Name);
|
||||
}
|
||||
}
|
||||
@@ -227,13 +227,16 @@ namespace TBF.UiControls
|
||||
|
||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||
{
|
||||
foreach (var tst in parent.Tests)
|
||||
foreach (var ri in renameInfo)
|
||||
{
|
||||
string newPathName;
|
||||
if (!string.IsNullOrEmpty(tst.MetersPath) && renameInfo.TryGetValue(tst.MetersPath, out newPathName))
|
||||
var tests = parent.Session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => x.MetersPath == ri.Key)
|
||||
.List();
|
||||
|
||||
foreach (var t in tests)
|
||||
{
|
||||
tst.MetersPath = newPathName;
|
||||
Config.FluentCommon.SaveToDb(parent.Session, tst);
|
||||
t.MetersPath = ri.Value;
|
||||
parent.Session.Update(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,11 +251,11 @@ namespace TBF.UiControls
|
||||
/// Update the database
|
||||
foreach (var entity in ToBeRemovedItems)
|
||||
{
|
||||
Config.FluentCommon.DeleteFromDb(parent.Session, entity);
|
||||
parent.Session.Delete(entity);
|
||||
}
|
||||
foreach (var entity in MyItems)
|
||||
{
|
||||
Config.FluentCommon.SaveToDb(parent.Session, entity);
|
||||
parent.Session.SaveOrUpdate(entity);
|
||||
}
|
||||
|
||||
/// Update the column widths
|
||||
|
||||
@@ -347,7 +347,7 @@ namespace TBF.UiControls
|
||||
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_renamed_3, Strings.OutputTabPageTitle, entity.Name, occurances, Environment.NewLine);
|
||||
warnings += string.Format(Strings._0_path_1_used_by_2_tests_will_be_renamed_to_3_4, Strings.OutputTabPageTitle, entity.OriName, occurances, entity.Name, Environment.NewLine);
|
||||
renmInfo.Add(entity.OriName, entity.Name);
|
||||
}
|
||||
}
|
||||
@@ -358,13 +358,16 @@ namespace TBF.UiControls
|
||||
|
||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||
{
|
||||
foreach (var tst in parent.Tests)
|
||||
foreach (var ri in renameInfo)
|
||||
{
|
||||
string newPathName;
|
||||
if (!string.IsNullOrEmpty(tst.OutputPath) && renameInfo.TryGetValue(tst.OutputPath, out newPathName))
|
||||
var tests = parent.Session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => x.OutputPath == ri.Key)
|
||||
.List();
|
||||
|
||||
foreach (var t in tests)
|
||||
{
|
||||
tst.OutputPath = newPathName;
|
||||
Config.FluentCommon.SaveToDb(parent.Session, tst);
|
||||
t.OutputPath = ri.Value;
|
||||
parent.Session.Update(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -379,11 +382,11 @@ namespace TBF.UiControls
|
||||
/// Update the database
|
||||
foreach (var entity in ToBeRemovedItems)
|
||||
{
|
||||
Config.FluentCommon.DeleteFromDb(parent.Session, entity);
|
||||
parent.Session.Delete(entity);
|
||||
}
|
||||
foreach (var entity in MyItems)
|
||||
{
|
||||
Config.FluentCommon.SaveToDb(parent.Session, entity);
|
||||
parent.Session.SaveOrUpdate(entity);
|
||||
}
|
||||
|
||||
/// Update the column widths
|
||||
|
||||
Reference in New Issue
Block a user