From db3a40d817ff76e06cda52687cbb526ad25aa4fc Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Fri, 14 May 2021 13:41:10 +0200 Subject: [PATCH] UI.Settings.UpgradeSelectionDlg : Upgrade pipes, ver. 3.1.1646 --- TBF/Properties/AssemblyInfo.cs | 4 +- .../Settings/UpgradeSelectionDlg.Designer.cs | 14 ++++ TBF/UI/Settings/UpgradeSelectionDlg.cs | 82 +++++++++++++++++++ 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index e2df73a8f..af743ec9b 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -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")] diff --git a/TBF/UI/Settings/UpgradeSelectionDlg.Designer.cs b/TBF/UI/Settings/UpgradeSelectionDlg.Designer.cs index 266c53c19..d8f291930 100644 --- a/TBF/UI/Settings/UpgradeSelectionDlg.Designer.cs +++ b/TBF/UI/Settings/UpgradeSelectionDlg.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/TBF/UI/Settings/UpgradeSelectionDlg.cs b/TBF/UI/Settings/UpgradeSelectionDlg.cs index 2335db716..df4c2af70 100644 --- a/TBF/UI/Settings/UpgradeSelectionDlg.cs +++ b/TBF/UI/Settings/UpgradeSelectionDlg.cs @@ -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() + .List(); + + var allPipes = session.QueryOver() + .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 components) + { + StringBuilder sb = new StringBuilder(); + + int startIx = 0; + int pos = parameters.IndexOf("", startIx); + + while (pos >= 0) + { + sb.Append(parameters.Substring(startIx, pos - startIx + "".Length)); + startIx = pos + "".Length; + pos = parameters.IndexOf("", startIx); + if (pos >= 0) + { + sb.Append(UpgradeOnePipe(parameters.Substring(startIx, pos - startIx), components)); + sb.Append(""); + startIx = pos + "".Length; + pos = parameters.IndexOf("", startIx); + } + } + + sb.Append(parameters.Substring(startIx)); + + return sb.ToString(); + } + + string UpgradeOnePipe(string edge, IList 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 components) + { + foreach (var c in components) if (c.Name == name) return c.Id; + return 0; + } } }