UI.Settings.UpgradeSelectionDlg : Upgrade pipes, ver. 3.1.1646

This commit is contained in:
Milan Hanajik
2021-05-14 13:41:10 +02:00
parent 0a1966d5f9
commit db3a40d817
3 changed files with 98 additions and 2 deletions
+2 -2
View File
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("3.1.1645.0")]
[assembly: AssemblyFileVersion("3.1.1645.0")]
[assembly: AssemblyVersion("3.1.1646.0")]
[assembly: AssemblyFileVersion("3.1.1646.0")]
+14
View File
@@ -48,6 +48,7 @@
this.errorFlagsComponentsTextBox = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.upgradeDb_225_226_Button = new System.Windows.Forms.Button();
this.upgradePipesButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// upgradeDb_215_216_Button
@@ -248,11 +249,23 @@
this.upgradeDb_225_226_Button.UseVisualStyleBackColor = true;
this.upgradeDb_225_226_Button.Click += new System.EventHandler(this.upgradeDb_225_226_Button_Click);
//
// upgradePipesButton
//
this.upgradePipesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.upgradePipesButton.Location = new System.Drawing.Point(206, 9);
this.upgradePipesButton.Name = "upgradePipesButton";
this.upgradePipesButton.Size = new System.Drawing.Size(65, 42);
this.upgradePipesButton.TabIndex = 20;
this.upgradePipesButton.Text = "Upgrade pipes";
this.upgradePipesButton.UseVisualStyleBackColor = true;
this.upgradePipesButton.Click += new System.EventHandler(this.upgradePipesButton_Click);
//
// UpgradeSelectionDlg
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 597);
this.Controls.Add(this.upgradePipesButton);
this.Controls.Add(this.upgradeDb_225_226_Button);
this.Controls.Add(this.label3);
this.Controls.Add(this.errorFlagsComponentsTextBox);
@@ -302,6 +315,7 @@
private System.Windows.Forms.TextBox errorFlagsComponentsTextBox;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button upgradeDb_225_226_Button;
private System.Windows.Forms.Button upgradePipesButton;
}
}
+82
View File
@@ -11,6 +11,7 @@ using NHibernate;
using Results;
using Results.Entities;
using TBF.Resources;
using System.Text;
namespace TBF.UI.Settings
{
@@ -1041,5 +1042,86 @@ namespace TBF.UI.Settings
"Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void upgradePipesButton_Click(object sender, EventArgs e)
{
ActivityStart();
try
{
var session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
var components = session.QueryOver<Config.Entities.Component>()
.List();
var allPipes = session.QueryOver<Config.Entities.Component>()
.Where(x => x.ClassName == "Various.Drawing.Pipes")
.List();
foreach (var pipes in allPipes)
{
pipes.Parameters = UpgradePipes(pipes.Parameters, components);
session.SaveOrUpdate(pipes);
}
session.Flush();
ActivityEnd();
MessageBox.Show("Upgrade completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception exc)
{
ActivityEnd();
MessageBox.Show(string.Format("Upgrade failed:\r\n{0}", exc.Message),
"Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
string UpgradePipes(string parameters, IList<Config.Entities.Component> components)
{
StringBuilder sb = new StringBuilder();
int startIx = 0;
int pos = parameters.IndexOf("<string>", startIx);
while (pos >= 0)
{
sb.Append(parameters.Substring(startIx, pos - startIx + "<string>".Length));
startIx = pos + "<string>".Length;
pos = parameters.IndexOf("</string>", startIx);
if (pos >= 0)
{
sb.Append(UpgradeOnePipe(parameters.Substring(startIx, pos - startIx), components));
sb.Append("</string>");
startIx = pos + "</string>".Length;
pos = parameters.IndexOf("<string>", startIx);
}
}
sb.Append(parameters.Substring(startIx));
return sb.ToString();
}
string UpgradeOnePipe(string edge, IList<Config.Entities.Component> components)
{
string[] items = edge.Split(new char[] { '~' });
int startId;
int endId;
if (items.Length != 4 ||
(startId = GetId(items[0], components)) == 0 ||
(endId = GetId(items[2], components)) == 0)
{
return edge;
}
return string.Format("{0}~{1}~{2}~{3}", startId, items[1], endId, items[3]);
}
int GetId(string name, IList<Config.Entities.Component> components)
{
foreach (var c in components) if (c.Name == name) return c.Id;
return 0;
}
}
}