using Disco.Data.Repository; using Disco.Models.BI.Interop.Community; using System; using System.IO; namespace Disco.Data.Configuration { public class SystemConfiguration : ConfigurationBase { public SystemConfiguration(DiscoDataContext Database) : base(Database) { // Init Modules this.moduleBootstrapperConfiguration = new Lazy(() => new Modules.BootstrapperConfiguration(Database)); this.moduleDeviceProfilesConfiguration = new Lazy(() => new Modules.DeviceProfilesConfiguration(Database)); this.moduleOrganisationAddressesConfiguration = new Lazy(() => new Modules.OrganisationAddressesConfiguration(Database)); this.moduleJobPreferencesConfiguration = new Lazy(() => new Modules.JobPreferencesConfiguration(Database)); this.moduleActiveDirectoryConfiguration = new Lazy(() => new Modules.ActiveDirectoryConfiguration(Database)); this.moduleDevicesConfiguration = new Lazy(() => new Modules.DevicesConfiguration(Database)); } #region Configuration Modules private Lazy moduleBootstrapperConfiguration; private Lazy moduleDeviceProfilesConfiguration; private Lazy moduleOrganisationAddressesConfiguration; private Lazy moduleJobPreferencesConfiguration; private Lazy moduleActiveDirectoryConfiguration; private Lazy moduleDevicesConfiguration; public Modules.BootstrapperConfiguration Bootstrapper { get { return moduleBootstrapperConfiguration.Value; } } public Modules.DeviceProfilesConfiguration DeviceProfiles { get { return moduleDeviceProfilesConfiguration.Value; } } public Modules.OrganisationAddressesConfiguration OrganisationAddresses { get { return moduleOrganisationAddressesConfiguration.Value; } } public Modules.JobPreferencesConfiguration JobPreferences { get { return moduleJobPreferencesConfiguration.Value; } } public Modules.ActiveDirectoryConfiguration ActiveDirectory { get { return moduleActiveDirectoryConfiguration.Value; } } public Modules.DevicesConfiguration Devices { get { return moduleDevicesConfiguration.Value; } } #endregion public override string Scope { get { return "System"; } } public string DataStoreLocation { get { var result = this.Get(null); if (result == null) { var appDataPath = System.Web.HttpContext.Current.Server.MapPath("~/App_Data"); if (appDataPath.EndsWith("\\")) return appDataPath; else return string.Concat(appDataPath, '\\'); } else return result; } set { if (value == null) throw new ArgumentNullException("value"); if (!System.IO.Directory.Exists(value)) throw new System.IO.DirectoryNotFoundException(string.Format("DataStoreLocation: '{0}' could not be found", value)); string storePath; if (value.EndsWith("\\")) storePath = value; else storePath = string.Concat(value, '\\'); this.Set(storePath); } } public string Administrators { get { return this.Get("Domain Admins,Disco Admins"); } set { Set(value); } } #region Plugin Locations public string PluginsLocation { get { return System.IO.Path.Combine(this.DataStoreLocation, @"Plugins\"); } } public string PluginStorageLocation { get { return System.IO.Path.Combine(this.DataStoreLocation, @"PluginStorage\"); } } public string PluginPackagesLocation { get { return System.IO.Path.Combine(this.DataStoreLocation, @"PluginPackages\"); } } #endregion #region Organisation Details #region Organisation Logo private string OrganisationLogoPath { get { return System.IO.Path.Combine(DataStoreLocation, "OrganisationLogo.png"); } } public string OrganisationLogoHash { get { var path = this.OrganisationLogoPath; if (File.Exists(path)) return File.GetLastWriteTimeUtc(path).ToBinary().ToString(); else return "-1"; } } public Stream OrganisationLogo { get { var path = this.OrganisationLogoPath; if (File.Exists(path)) return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); else return new MemoryStream(Disco.Data.Properties.Resources.EmptyLogo); } set { string organisationLogoPath = this.OrganisationLogoPath; if (value == null) { if (System.IO.File.Exists(organisationLogoPath)) System.IO.File.Delete(organisationLogoPath); } else { using (FileStream fs = new FileStream(organisationLogoPath, FileMode.Create, FileAccess.Write, FileShare.None)) { value.CopyTo(fs); } } } } #endregion public string OrganisationName { get { return this.Get(null); } set { this.Set(value); } } public bool MultiSiteMode { get { return this.Get(false); } set { this.Set(value); } } #endregion #region Proxy Configuration public string ProxyAddress { get { return this.Get(null); } set { this.Set(value); } } public int ProxyPort { get { return this.Get(8080); } set { this.Set(value); } } public string ProxyUsername { get { return this.Get(null); } set { this.Set(value); } } public string ProxyPassword { get { return this.GetDeobsfucated(null); } set { this.SetObsfucated(value); } } #endregion #region UpdateCheck public string DeploymentId { get { return this.Get(null); } } public UpdateResponse UpdateLastCheck { get { return this.Get(null); } set { this.Set(value); } } public bool UpdateBetaDeployment { get { return this.Get(false); } } public Version InstalledDatabaseVersion { get { var versionString = this.Get(null); if (string.IsNullOrEmpty(versionString)) return null; else return Version.Parse(versionString); } set { this.Set(value.ToString(4)); } } #endregion } }