206 lines
9.9 KiB
C#
206 lines
9.9 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Windows.Forms;
|
|
|
|
namespace LocalSynchronizationSetup
|
|
{
|
|
public partial class DlgLocalSynchronizationSetup : Form
|
|
{
|
|
#region Version und Copyright
|
|
// Version und Copyright
|
|
string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen
|
|
string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
|
string copyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
|
string icon = Application.StartupPath + "\\Info.bmp";
|
|
//Assembly Datum und Zeit
|
|
static DateTime value = AssemblyDateTime();
|
|
string date = value.ToShortDateString();
|
|
string time = value.ToLongTimeString();
|
|
private static DateTime AssemblyDateTime()
|
|
{
|
|
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
|
var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision));
|
|
//Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original)
|
|
return buildDateTime;
|
|
}
|
|
#endregion
|
|
|
|
private string strPraefix = "Sync_";
|
|
private string strBatchSuffix = ".bat";
|
|
private string strShortcutSuffix = ".lnk";
|
|
private string strModul3D = "Modul_3D";
|
|
private string strNxEnvironment = "NX_Environment";
|
|
private string strNxMachineryLibrary = "NX_MACHINERY_LIBRARY";
|
|
private string strNxPortal = "NX-Portal";
|
|
private string strSyncDirectory = "C:\\Data\\NX";
|
|
private string strAppStartup;
|
|
private Synchronization sy;
|
|
|
|
private void bnCreateRemoveSynchronisation_Click(object sender, EventArgs e)
|
|
{
|
|
string summary = "";
|
|
if (!this.sy.CreateRemoveSynchronisation(this.rBCreateNxEnvironmentSync.Checked, this.rBRemoveNxEnvironmentSync.Checked, this.rBCreateModul3DSync.Checked, this.rBRemoveModul3DSync.Checked, this.rBCreateNxMachineryLibrarySync.Checked, this.rBRemoveNxMachineryLibrarySync.Checked, this.rBCreateNxPortalSync.Checked, this.rBRemoveNxPortalSync.Checked, true, out summary))
|
|
{
|
|
return;
|
|
}
|
|
this.SetStatusText(this.lbModul3DSyncStatus, this.strModul3D);
|
|
this.SetStatusText(this.lbNxEnvironmentSyncStatus, this.strNxEnvironment);
|
|
this.SetStatusText(this.lbNxMachineryLibrarySyncStatus, this.strNxMachineryLibrary);
|
|
this.SetStatusText(this.lbNxPortalSyncStatus, this.strNxPortal);
|
|
int num = (int)MessageBox.Show(summary, "Summary - Synchronisation Setup", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
|
}
|
|
|
|
private void bnRunSynchronization_Click(object sender, EventArgs e)
|
|
{
|
|
string str1 = "Summary: \n";
|
|
string str2;
|
|
if (File.Exists(this.sy.BatchFileName(this.strNxEnvironment)))
|
|
{
|
|
new Process()
|
|
{
|
|
StartInfo = { FileName = this.sy.BatchFileName(this.strNxEnvironment) }
|
|
}.Start();
|
|
str2 = str1 + "\nSynchronization for " + this.strNxEnvironment + " started successfully";
|
|
}
|
|
else
|
|
{
|
|
str2 = str1 + "\nCannot find synchronization process for " + this.strNxEnvironment + ". Create process before run.";
|
|
}
|
|
string str3;
|
|
if (File.Exists(this.sy.BatchFileName(this.strModul3D)))
|
|
{
|
|
new Process()
|
|
{
|
|
StartInfo = { FileName = this.sy.BatchFileName(this.strModul3D) }
|
|
}.Start();
|
|
str3 = str2 + "\nSynchronization for " + this.strModul3D + " started successfully";
|
|
}
|
|
else
|
|
{
|
|
str3 = str2 + "\nCannot find synchronization process for " + this.strModul3D + ". Create process before run.";
|
|
}
|
|
string str4;
|
|
if (File.Exists(this.sy.BatchFileName(this.strNxMachineryLibrary)))
|
|
{
|
|
new Process()
|
|
{
|
|
StartInfo = { FileName = this.sy.BatchFileName(this.strNxMachineryLibrary) }
|
|
}.Start();
|
|
str4 = str3 + "\nSynchronization for " + this.strNxMachineryLibrary + " started successfully";
|
|
}
|
|
else
|
|
{
|
|
str4 = str3 + "\nCannot find synchronization process for " + this.strNxMachineryLibrary + ". Create process before run.";
|
|
}
|
|
string text;
|
|
if (File.Exists(this.sy.BatchFileName(this.strNxPortal)))
|
|
{
|
|
new Process()
|
|
{
|
|
StartInfo = { FileName = this.sy.BatchFileName(this.strNxPortal) }
|
|
}.Start();
|
|
text = str4 + "\nSynchronization for " + this.strNxPortal + " started successfully";
|
|
}
|
|
else
|
|
{
|
|
text = str4 + "\nCannot find synchronization process for " + this.strNxPortal + ". Create process before run.";
|
|
}
|
|
int num = (int)MessageBox.Show(text, "Summary - Run Synchronization", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
|
}
|
|
|
|
private void bnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void showSynchronizationInfoToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
string text = "Local Synchronization Setup Info:\n";
|
|
string[] strArray = new string[4]
|
|
{
|
|
this.strNxEnvironment,
|
|
this.strModul3D,
|
|
this.strNxMachineryLibrary,
|
|
this.strNxPortal
|
|
};
|
|
foreach (string SyncName in strArray)
|
|
{
|
|
string str1 = text + "\n" + SyncName + ":";
|
|
string str2 = !File.Exists(this.sy.ShortcutFileName(SyncName)) ? str1 + "\nShortcut does not exist!" : str1 + "\nShortcut:\t\t" + this.sy.ShortcutFileName(SyncName);
|
|
text = (!File.Exists(this.sy.BatchFileName(SyncName)) ? str2 + "\nBatch does not exist!" : str2 + "\nBatch:\t\t" + this.sy.BatchFileName(SyncName) + "\nSource:\t\t" + this.GetSyncBatchVarValue(this.sy.BatchFileName(SyncName), "SYNC_SOURCE") + "\nDestination:\t" + this.GetSyncBatchVarValue(this.sy.BatchFileName(SyncName), "SYNC_DESTINATION")) + "\n";
|
|
}
|
|
int num = (int)MessageBox.Show(text, "Info", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
|
}
|
|
|
|
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
int num = (int)MessageBox.Show("About \"Local Synchronization Setup\":\n\nCreates or removes synchronization process for NX_Environment, Modul_3D, NX_Machinery_Library and NX-Portal." + "\nAdditionally environment variables NX_SERVER_DIR and UGII_ENV_FILE will be set." + "\n\nVersion " + version + "\n" + copyright + "\nCreated by Eugen Höglinger, 2010/03/26" + "\nNo warranty! Use program at your own risk!" + "\n\nStart with command line: LocalSynchronizationSetup.exe [startup directory]", "About", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
|
}
|
|
|
|
public DlgLocalSynchronizationSetup()
|
|
{
|
|
this.strAppStartup = Application.StartupPath.ToString();
|
|
this.sy = new Synchronization(this.strPraefix, this.strBatchSuffix, this.strShortcutSuffix, this.strModul3D, this.strNxEnvironment, this.strSyncDirectory, this.strAppStartup);
|
|
|
|
InitializeComponent();
|
|
}
|
|
|
|
public DlgLocalSynchronizationSetup(string ApplicationStartup)
|
|
{
|
|
this.strAppStartup = ApplicationStartup;
|
|
this.sy = new Synchronization(this.strPraefix, this.strBatchSuffix, this.strShortcutSuffix, this.strModul3D, this.strNxEnvironment, this.strSyncDirectory, this.strAppStartup);
|
|
InitializeComponent();
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
this.lbStartuppath.Text = this.strAppStartup;
|
|
this.SetStatusText(this.lbModul3DSyncStatus, this.strModul3D);
|
|
this.SetStatusText(this.lbNxEnvironmentSyncStatus, this.strNxEnvironment);
|
|
this.SetStatusText(this.lbNxMachineryLibrarySyncStatus, this.strNxMachineryLibrary);
|
|
this.SetStatusText(this.lbNxPortalSyncStatus, this.strNxPortal);
|
|
}
|
|
|
|
private void SetStatusText(Label StatusLabel, string SyncName)
|
|
{
|
|
if (this.SynchronizationExists(SyncName))
|
|
{
|
|
StatusLabel.Text = "Sync. Proc. EXISTS";
|
|
StatusLabel.BackColor = Color.Yellow;
|
|
}
|
|
else
|
|
{
|
|
StatusLabel.Text = "Sync. Proc. NOT EXISTS";
|
|
StatusLabel.BackColor = Color.Transparent;
|
|
}
|
|
}
|
|
|
|
private bool SynchronizationExists(string SyncName)
|
|
{
|
|
return File.Exists(this.sy.ShortcutFileName(SyncName)) && File.Exists(this.sy.BatchFileName(SyncName));
|
|
}
|
|
|
|
private string GetSyncBatchVarValue(string SyncBatchfilename, string VarName)
|
|
{
|
|
string str1 = "";
|
|
StreamReader streamReader = new StreamReader(SyncBatchfilename);
|
|
while (!streamReader.EndOfStream && str1 == "")
|
|
{
|
|
string str2 = streamReader.ReadLine();
|
|
if (str2.Contains("SET " + VarName + "="))
|
|
{
|
|
string[] strArray = str2.Split('=');
|
|
str1 = strArray[strArray.Length - 1];
|
|
}
|
|
}
|
|
streamReader.Close();
|
|
return str1;
|
|
}
|
|
}
|
|
}
|