UI.Settings.UpgradeSelectionDlg : Upgrade pipes, ver. 3.1.1646
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user