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))
|
if (!string.IsNullOrEmpty(warnings))
|
||||||
{
|
{
|
||||||
string message = string.Format("{0}{1}{2}", warnings, Environment.NewLine,
|
string message = string.Format("{0}{1}{2}", warnings, Environment.NewLine,
|
||||||
@@ -188,20 +189,40 @@ namespace TBF
|
|||||||
}
|
}
|
||||||
else if (dr == DialogResult.Yes)
|
else if (dr == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
Cursor.Current = Cursors.WaitCursor;
|
updateRelatedItems = true;
|
||||||
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;
|
Cursor.Current = Cursors.WaitCursor;
|
||||||
|
|
||||||
foreach (TabPage tab in pathsTabControl.TabPages)
|
using (var transaction = Session.BeginTransaction())
|
||||||
{
|
{
|
||||||
(tab.Tag as ITabWithListViewEx).OkBtnClicked();
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
Cursor.Current = Cursors.Default;
|
||||||
|
|||||||
+3
-3
@@ -88,11 +88,11 @@ namespace TBF.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </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 {
|
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">
|
<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>
|
<value>{0} path '{1}' used by {2} tests will be removed.{3}</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="_0_path_1_used_by_2_tests_will_be_renamed_3" xml:space="preserve">
|
<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.{3}</value>
|
<value>{0} path '{1}' used by {2} tests will be renamed to '{3}'.{4}</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Do_you_want_to_update_related_tests_and_procedures" xml:space="preserve">
|
<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>
|
<value>Do you want to update related tests and procedures?</value>
|
||||||
|
|||||||
@@ -422,38 +422,43 @@ namespace TBF
|
|||||||
{
|
{
|
||||||
if (updateRelatedItems)
|
if (updateRelatedItems)
|
||||||
{
|
{
|
||||||
foreach (var item in tests)
|
foreach (var ri in renameInfo)
|
||||||
{
|
{
|
||||||
bool updated = false;
|
var tests = Session.QueryOver<Config.Entities.Test>()
|
||||||
string newSeqName;
|
.Where(x => (x.RelTransBefore == ri.Key))
|
||||||
if (!string.IsNullOrEmpty(item.RelTransBefore) && renameInfo.TryGetValue(item.RelTransBefore, out newSeqName))
|
.List();
|
||||||
|
foreach (var t in tests)
|
||||||
{
|
{
|
||||||
item.RelTransBefore = newSeqName;
|
t.RelTransBefore = ri.Value;
|
||||||
updated = true;
|
Session.Update(t);
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(item.TransitionAfter) && renameInfo.TryGetValue(item.TransitionAfter, out newSeqName))
|
|
||||||
{
|
|
||||||
item.TransitionAfter = newSeqName;
|
|
||||||
updated = true;
|
|
||||||
}
|
|
||||||
if (updated) Session.SaveOrUpdate(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var item in procedures)
|
tests = Session.QueryOver<Config.Entities.Test>()
|
||||||
{
|
.Where(x => (x.TransitionAfter == ri.Key))
|
||||||
bool updated = false;
|
.List();
|
||||||
string newSeqName;
|
foreach (var t in tests)
|
||||||
if (!string.IsNullOrEmpty(item.TransitionStart) && renameInfo.TryGetValue(item.TransitionStart, out newSeqName))
|
|
||||||
{
|
{
|
||||||
item.TransitionStart = newSeqName;
|
t.TransitionAfter = ri.Value;
|
||||||
updated = true;
|
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;
|
p.TransitionStart = ri.Value;
|
||||||
updated = true;
|
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)
|
catch (Exception e2)
|
||||||
{
|
{
|
||||||
|
transaction.Rollback();
|
||||||
Cursor.Current = Cursors.Default;
|
Cursor.Current = Cursors.Default;
|
||||||
|
|
||||||
MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
log.ErrorFormat("Update of sequences in the database failed: {0}", e2.Message);
|
log.ErrorFormat("Update of sequences in the database failed: {0}", e2.Message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ namespace TBF.UiControls
|
|||||||
|
|
||||||
if (occurances > 0)
|
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);
|
renmInfo.Add(entity.OriName, entity.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -351,15 +351,18 @@ namespace TBF.UiControls
|
|||||||
|
|
||||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||||
{
|
{
|
||||||
foreach (var tst in parent.Tests)
|
foreach (var ri in renameInfo)
|
||||||
{
|
{
|
||||||
string newPathName;
|
var tests = parent.Session.QueryOver<Config.Entities.Test>()
|
||||||
if (!string.IsNullOrEmpty(tst.BenchPath) && renameInfo.TryGetValue(tst.BenchPath, out newPathName))
|
.Where(x => x.BenchPath == ri.Key)
|
||||||
{
|
.List();
|
||||||
tst.BenchPath = newPathName;
|
|
||||||
Config.FluentCommon.SaveToDb(parent.Session, tst);
|
foreach (var t in tests)
|
||||||
}
|
{
|
||||||
}
|
t.BenchPath = ri.Value;
|
||||||
|
parent.Session.Update(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -372,11 +375,11 @@ namespace TBF.UiControls
|
|||||||
/// Update the database
|
/// Update the database
|
||||||
foreach (var entity in ToBeRemovedItems)
|
foreach (var entity in ToBeRemovedItems)
|
||||||
{
|
{
|
||||||
Config.FluentCommon.DeleteFromDb(parent.Session, entity);
|
parent.Session.Delete(entity);
|
||||||
}
|
}
|
||||||
foreach (var entity in MyItems)
|
foreach (var entity in MyItems)
|
||||||
{
|
{
|
||||||
Config.FluentCommon.SaveToDb(parent.Session, entity);
|
parent.Session.SaveOrUpdate(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the column widths
|
/// Update the column widths
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ namespace TBF.UiControls
|
|||||||
|
|
||||||
if (occurances > 0)
|
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);
|
renmInfo.Add(entity.OriName, entity.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,13 +359,16 @@ namespace TBF.UiControls
|
|||||||
|
|
||||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||||
{
|
{
|
||||||
foreach (var tst in parent.Tests)
|
foreach (var ri in renameInfo)
|
||||||
{
|
{
|
||||||
string newPathName;
|
var tests = parent.Session.QueryOver<Config.Entities.Test>()
|
||||||
if (!string.IsNullOrEmpty(tst.FeedingPath) && renameInfo.TryGetValue(tst.FeedingPath, out newPathName))
|
.Where(x => x.FeedingPath == ri.Key)
|
||||||
|
.List();
|
||||||
|
|
||||||
|
foreach (var t in tests)
|
||||||
{
|
{
|
||||||
tst.FeedingPath = newPathName;
|
t.FeedingPath = ri.Value;
|
||||||
Config.FluentCommon.SaveToDb(parent.Session, tst);
|
parent.Session.Update(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -380,13 +383,12 @@ namespace TBF.UiControls
|
|||||||
/// Update the database
|
/// Update the database
|
||||||
foreach (var entity in ToBeRemovedItems)
|
foreach (var entity in ToBeRemovedItems)
|
||||||
{
|
{
|
||||||
Config.FluentCommon.DeleteFromDb(parent.Session, entity);
|
parent.Session.Delete(entity);
|
||||||
}
|
}
|
||||||
foreach (var entity in MyItems)
|
foreach (var entity in MyItems)
|
||||||
{
|
{
|
||||||
Config.FluentCommon.SaveToDb(parent.Session, entity);
|
parent.Session.SaveOrUpdate(entity);
|
||||||
}
|
}
|
||||||
parent.Session.Flush();
|
|
||||||
|
|
||||||
/// Update the column widths
|
/// Update the column widths
|
||||||
Program.LocalSettings.FeedingColumnWidths = new int[Columns.Count];
|
Program.LocalSettings.FeedingColumnWidths = new int[Columns.Count];
|
||||||
|
|||||||
@@ -280,27 +280,30 @@ namespace TBF.UiControls
|
|||||||
|
|
||||||
if (occurances > 0)
|
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);
|
renmInfo.Add(entity.OriName, entity.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return warnings;
|
return warnings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||||
{
|
{
|
||||||
#if HEAT_METERS
|
#if HEAT_METERS
|
||||||
foreach (var tst in parent.Tests)
|
foreach (var ri in renameInfo)
|
||||||
{
|
{
|
||||||
string newPathName;
|
var tests = parent.Session.QueryOver<Config.Entities.Test>()
|
||||||
if (!string.IsNullOrEmpty(tst.HeatMetersPath) && renameInfo.TryGetValue(tst.HeatMetersPath, out newPathName))
|
.Where(x => x.HeatMetersPath == ri.Key)
|
||||||
{
|
.List();
|
||||||
tst.HeatMetersPath = newPathName;
|
|
||||||
Config.FluentCommon.SaveToDb(parent.Session, tst);
|
foreach (var t in tests)
|
||||||
}
|
{
|
||||||
}
|
t.HeatMetersPath = ri.Value;
|
||||||
|
parent.Session.Update(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,11 +318,11 @@ namespace TBF.UiControls
|
|||||||
/// Update the database
|
/// Update the database
|
||||||
foreach (var entity in ToBeRemovedItems)
|
foreach (var entity in ToBeRemovedItems)
|
||||||
{
|
{
|
||||||
Config.FluentCommon.DeleteFromDb(parent.Session, entity);
|
parent.Session.Delete(entity);
|
||||||
}
|
}
|
||||||
foreach (var entity in MyItems)
|
foreach (var entity in MyItems)
|
||||||
{
|
{
|
||||||
Config.FluentCommon.SaveToDb(parent.Session, entity);
|
parent.Session.SaveOrUpdate(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the column widths
|
/// Update the column widths
|
||||||
@@ -330,6 +333,6 @@ namespace TBF.UiControls
|
|||||||
}
|
}
|
||||||
Program.LocalSettings.Save();
|
Program.LocalSettings.Save();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ namespace TBF.UiControls
|
|||||||
|
|
||||||
if (occurances > 0)
|
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);
|
renmInfo.Add(entity.OriName, entity.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,13 +227,16 @@ namespace TBF.UiControls
|
|||||||
|
|
||||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||||
{
|
{
|
||||||
foreach (var tst in parent.Tests)
|
foreach (var ri in renameInfo)
|
||||||
{
|
{
|
||||||
string newPathName;
|
var tests = parent.Session.QueryOver<Config.Entities.Test>()
|
||||||
if (!string.IsNullOrEmpty(tst.MetersPath) && renameInfo.TryGetValue(tst.MetersPath, out newPathName))
|
.Where(x => x.MetersPath == ri.Key)
|
||||||
|
.List();
|
||||||
|
|
||||||
|
foreach (var t in tests)
|
||||||
{
|
{
|
||||||
tst.MetersPath = newPathName;
|
t.MetersPath = ri.Value;
|
||||||
Config.FluentCommon.SaveToDb(parent.Session, tst);
|
parent.Session.Update(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,12 +251,12 @@ namespace TBF.UiControls
|
|||||||
/// Update the database
|
/// Update the database
|
||||||
foreach (var entity in ToBeRemovedItems)
|
foreach (var entity in ToBeRemovedItems)
|
||||||
{
|
{
|
||||||
Config.FluentCommon.DeleteFromDb(parent.Session, entity);
|
parent.Session.Delete(entity);
|
||||||
}
|
}
|
||||||
foreach (var entity in MyItems)
|
foreach (var entity in MyItems)
|
||||||
{
|
{
|
||||||
Config.FluentCommon.SaveToDb(parent.Session, entity);
|
parent.Session.SaveOrUpdate(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the column widths
|
/// Update the column widths
|
||||||
Program.LocalSettings.MetersColumnWidths = new int[Columns.Count];
|
Program.LocalSettings.MetersColumnWidths = new int[Columns.Count];
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ namespace TBF.UiControls
|
|||||||
|
|
||||||
if (occurances > 0)
|
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);
|
renmInfo.Add(entity.OriName, entity.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -358,13 +358,16 @@ namespace TBF.UiControls
|
|||||||
|
|
||||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||||
{
|
{
|
||||||
foreach (var tst in parent.Tests)
|
foreach (var ri in renameInfo)
|
||||||
{
|
{
|
||||||
string newPathName;
|
var tests = parent.Session.QueryOver<Config.Entities.Test>()
|
||||||
if (!string.IsNullOrEmpty(tst.OutputPath) && renameInfo.TryGetValue(tst.OutputPath, out newPathName))
|
.Where(x => x.OutputPath == ri.Key)
|
||||||
|
.List();
|
||||||
|
|
||||||
|
foreach (var t in tests)
|
||||||
{
|
{
|
||||||
tst.OutputPath = newPathName;
|
t.OutputPath = ri.Value;
|
||||||
Config.FluentCommon.SaveToDb(parent.Session, tst);
|
parent.Session.Update(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,12 +382,12 @@ namespace TBF.UiControls
|
|||||||
/// Update the database
|
/// Update the database
|
||||||
foreach (var entity in ToBeRemovedItems)
|
foreach (var entity in ToBeRemovedItems)
|
||||||
{
|
{
|
||||||
Config.FluentCommon.DeleteFromDb(parent.Session, entity);
|
parent.Session.Delete(entity);
|
||||||
}
|
}
|
||||||
foreach (var entity in MyItems)
|
foreach (var entity in MyItems)
|
||||||
{
|
{
|
||||||
Config.FluentCommon.SaveToDb(parent.Session, entity);
|
parent.Session.SaveOrUpdate(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the column widths
|
/// Update the column widths
|
||||||
Program.LocalSettings.OutputColumnWidths = new int[Columns.Count];
|
Program.LocalSettings.OutputColumnWidths = new int[Columns.Count];
|
||||||
|
|||||||
Reference in New Issue
Block a user