// Copyright (C) Stichting Deltares 2023. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Drawing;
using System.Text;
using Deltares.Dam.Data.License;
using Deltares.Dam.Forms;
using Deltares.Geometry.Forms;
using Deltares.Geotechnics.Forms;
using Deltares.Standard;
using Deltares.Standard.Forms.DExpress;
using Deltares.Standard.Language;
using Deltares.Standard.Reflection;
using DevExpress.UserSkins;
namespace Deltares.Dam.Application
{
internal class Program : IProgramInfo
{
private const string dAuthFeature = "DGS_26_00";
private const string BetaString = "(BETA)";
// ReSharper disable ConvertToConstant.Local
// ReSharper disable RedundantDefaultFieldInitializer
private static readonly bool IsReleaseVersion = true;
// ReSharper restore RedundantDefaultFieldInitializer
// ReSharper restore ConvertToConstant.Local
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
#if DEBUG
RunInDebugMode();
#else
RunInReleaseMode();
#endif
}
private static void Start()
{
DamLicense.CheckoutLicense(dAuthFeature, info.AssemblyVersion);
// Parameters are used for splash screen
var mainForm = new MainForm(typeof(Program),
new Bitmap(typeof(DamPlugin).Assembly.GetManifestResourceStream("Deltares.Dam.Forms.Resources.DAMSplash.jpg")), false);
if (!IsReleaseVersion)
{
mainForm.TextChanged += MainFormTextChanged;
mainForm.Disposed += (s, o) => mainForm.TextChanged -= MainFormTextChanged;
}
// register plugins
mainForm.Register(new GeometryPlugin());
mainForm.Register(new GeotechnicsPlugin());
mainForm.Register(new DamPlugin());
// run
System.Windows.Forms.Application.Run(mainForm);
DamLicense.CheckinLicense();
}
private static void MainFormTextChanged(object sender, EventArgs eventArgs)
{
var mainForm = sender as MainForm;
if (mainForm == null || mainForm.Text.Contains(BetaString) || IsReleaseVersion)
{
return;
}
mainForm.TextChanged -= MainFormTextChanged;
mainForm.Text = mainForm.Text + " " + BetaString;
mainForm.TextChanged += MainFormTextChanged;
}
private static void Initialize()
{
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
BonusSkins.Register();
}
#if DEBUG
private static void RunInDebugMode()
{
Initialize();
Start();
}
#else
private static void RunInReleaseMode()
{
AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
Initialize();
try
{
Start();
}
catch (Exception ex)
{
HandleException(ex);
}
}
#endif
private static void AppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
HandleException(e.ExceptionObject as Exception);
}
private static void HandleException(Exception ex)
{
if (ex == null)
{
return;
}
// Show message box
var exceptionMessage = new StringBuilder();
if (ex.InnerException != null)
{
exceptionMessage.Append(ex.InnerException.Message);
exceptionMessage.AppendLine();
}
exceptionMessage.Append(LocalizationManager.GetTranslatedText(null, "UnhandledExceptionMessage"));
LocalizedMessageBox.ShowException(String.Concat(exceptionMessage.ToString(), ": ", ex.Message, ex.StackTrace));
System.Windows.Forms.Application.Exit();
}
#region IProgramInfo
readonly static AssemblyInfoHelper info = new AssemblyInfoHelper(typeof(Program));
public string LicenseType
{
get
{
return DamLicense.DamLicenseType.ToString();
}
}
bool IProgramInfo.IsReleaseVersion
{
get
{
return IsReleaseVersion;
}
}
string IProgramInfo.Company
{
get
{
return info.Company;
}
}
public string Phone
{
get
{
return info.Phone;
}
}
public string Email
{
get
{
return info.Email;
}
}
string IProgramInfo.Copyright
{
get
{
return info.Copyright;
}
}
string IProgramInfo.Product
{
get
{
return info.Product + (!IsReleaseVersion ? " " + BetaString : string.Empty);
}
}
string IProgramInfo.Title
{
get
{
return info.Title;
}
}
string IProgramInfo.AssemblyVersion
{
get
{
return info.AssemblyVersion;
}
}
#endregion
}
}