ApplicationModulesManager GetApplicationModulesManager(PathInfo pathInfo) { string assemblyPath = Path.GetDirectoryName(pathInfo.AssemblyPath); var designerModelFactory = new DesignerModelFactory(); ReflectionHelper.Reset(); XafTypesInfo.HardReset(); XpoTypesInfoHelper.ForceInitialize(); if (pathInfo.IsApplicationModel) { _currentDomainOnAssemblyResolvePathInfo = pathInfo; AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += CurrentDomainOnAssemblyResolve; AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve; var applicationInstance = Activator.CreateInstance(Assembly.Load(pathInfo.AssemblyPath).GetTypes().First(type => typeof(XafApplication).IsAssignableFrom(type))); AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= CurrentDomainOnAssemblyResolve; AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomainOnAssemblyResolve; _currentDomainOnAssemblyResolvePathInfo = null; var configFileName = applicationInstance is WinApplication? pathInfo.AssemblyPath + ".config":Path.Combine(pathInfo.FullPath, "web.config"); return(designerModelFactory.CreateModulesManager((XafApplication)applicationInstance, configFileName, Path.GetDirectoryName(pathInfo.AssemblyPath))); } var moduleFromFile = designerModelFactory.CreateModuleFromFile(pathInfo.AssemblyPath, assemblyPath); return(designerModelFactory.CreateModulesManager(moduleFromFile, pathInfo.AssemblyPath)); }
IModelApplication GetModelApplication(XafApplication application, ApplicationModulesManager modulesManager) { var modelApplicationCreator = XpandModuleBase.ModelApplicationCreator; XpandModuleBase.ModelApplicationCreator = null; var modelApplication = new DesignerModelFactory().CreateApplicationModel(application, modulesManager, null, null); AddAfterSetupLayer(modelApplication); XpandModuleBase.ModelApplicationCreator = modelApplicationCreator; return modelApplication; }
ApplicationModulesManager GetApplicationModulesManager(PathInfo pathInfo) { string assemblyPath = Path.GetDirectoryName(pathInfo.AssemblyPath); var designerModelFactory = new DesignerModelFactory(); var moduleFromFile = designerModelFactory.CreateModuleFromFile(pathInfo.AssemblyPath, assemblyPath); return(designerModelFactory.CreateModulesManager(moduleFromFile, pathInfo.AssemblyPath)); }
ApplicationModulesManager GetApplicationModulesManager(PathInfo pathInfo) { string assemblyPath = Path.GetDirectoryName(pathInfo.AssemblyPath); var designerModelFactory = new DesignerModelFactory(); var moduleFromFile = designerModelFactory.CreateModuleFromFile(pathInfo.AssemblyPath, assemblyPath); ReflectionHelper.Reset(); XafTypesInfo.HardReset(); XpoTypesInfoHelper.ForceInitialize(); return designerModelFactory.CreateModulesManager(moduleFromFile, pathInfo.AssemblyPath); }
ApplicationModulesManager GetApplicationModulesManager(PathInfo pathInfo) { string assemblyPath = Path.GetDirectoryName(pathInfo.AssemblyPath); var designerModelFactory = new DesignerModelFactory(); var moduleFromFile = designerModelFactory.CreateModuleFromFile(pathInfo.AssemblyPath, assemblyPath); ReflectionHelper.Reset(); XafTypesInfo.HardReset(); XpoTypesInfoHelper.ForceInitialize(); return(designerModelFactory.CreateModulesManager(moduleFromFile, pathInfo.AssemblyPath)); }
ModelApplicationBase GetModelApplication(XafApplication application, ApplicationModulesManager modulesManager) { var modelApplicationCreator = XpandModuleBase.ModelApplicationCreator; XpandModuleBase.ModelApplicationCreator = null; var modelApplication = new DesignerModelFactory().CreateApplicationModel(application, modulesManager, null, null); // ReSharper disable SuspiciousTypeConversion.Global var modelApplicationBase = (ModelApplicationBase)modelApplication; // ReSharper restore SuspiciousTypeConversion.Global AddAfterSetupLayer(modelApplicationBase); XpandModuleBase.ModelApplicationCreator = modelApplicationCreator; return modelApplicationBase; }
IModelApplication GetModelApplication(XafApplication application, ApplicationModulesManager modulesManager) { var modelApplicationCreator = XpandModuleBase.ModelApplicationCreator; XpandModuleBase.ModelApplicationCreator = null; var modelApplication = new DesignerModelFactory().CreateApplicationModel(application, modulesManager, null, null); AddAfterSetupLayer(modelApplication); XpandModuleBase.ModelApplicationCreator = modelApplicationCreator; return(modelApplication); }
ApplicationModulesManager GetApplicationModulesManager(PathInfo pathInfo) { var designerModelFactory = new DesignerModelFactory(); ReflectionHelper.Reset(); XafTypesInfo.HardReset(); XpoTypesInfoHelper.ForceInitialize(); if (pathInfo.IsApplicationModel) { var assembliesPath = Path.GetDirectoryName(pathInfo.AssemblyPath); var application = designerModelFactory.CreateApplicationFromFile(pathInfo.AssemblyPath, assembliesPath); InitializeTypeInfoSources(application.Modules, assembliesPath); var applicationModulesManager = designerModelFactory.CreateModulesManager(application, null, assembliesPath); return(applicationModulesManager); } var moduleFromFile = designerModelFactory.CreateModuleFromFile(pathInfo.AssemblyPath, Path.GetDirectoryName(pathInfo.AssemblyPath)); return(designerModelFactory.CreateModulesManager(moduleFromFile, pathInfo.AssemblyPath)); }
public SchemaProvider ReadApplication(string ApplicationName, string ApplicationFolder, string exeName, string XPOConnectionString, string DBConnectionString) { IList<string> moduleList = new List<string>(){ "Para.Core.Modules.SystemModule.Win.dll", "Para.Model.Definition.dll", "Para.Modules.WorkflowLight.dll", "Para.Core.Modules.SpellCheckerModule.dll", "Para.Modules.App.dll", "Para.Modules.App.Win.dll", "Para.Modules.ABF.dll", "Para.Modules.BH.dll", "Para.Modules.RA.dll", "Para.Modules.FV.dll", "Para.Modules.Workflow.dll", "Para.Modules.Document.Activities.dll", "Para.Modules.Intern.Win.dll", "Para.Modules.MV.dll" }; IList<Assembly> assemblies = new List<Assembly>(); foreach (var file in moduleList) assemblies.Add(Assembly.LoadFile(ApplicationFolder + file)); ControllersManager controllerManager = new ControllersManager(); ApplicationModulesManager man = new ApplicationModulesManager(controllerManager, ApplicationFolder); man.AddModuleFromAssemblies(assemblies.Select(ass => ass.FullName).ToArray()); var sec = new SecurityDummy(); SAConnection conn = new SAConnection(DBConnectionString); conn.Open(); XpoDefault.DataLayer = XpoDefault.GetDataLayer("XpoProvider=Asa;DataSourceName='paradat'", new ReflectionDictionary(), AutoCreateOption.None); XPObjectSpaceProvider provider = new XPObjectSpaceProvider(new ConnectionStringDataStoreProvider(XPOConnectionString)); DesignerModelFactory dmf = new DesignerModelFactory(); string ApplicationFileName = ApplicationFolder + exeName; string ApplicationConfigFileName = String.Format("{0}{1}.config", ApplicationFolder, exeName); var app = dmf.CreateApplicationByConfigFile(ApplicationConfigFileName, ApplicationFileName, ref ApplicationFolder); app.DatabaseVersionMismatch += app_DatabaseVersionMismatch; app.Setup("paraOffice", provider, man, sec); var dict = (app.CreateObjectSpace() as XPObjectSpace).Session.Dictionary; SchemaProvider schemaProvider = new SchemaProvider(); foreach (var classinfo in dict.Classes.Cast<XPClassInfo>().Where(c => c.IsPersistent)) { if (classinfo.Table.IsView) { schemaProvider.Views.Add(new FastSchemaProvider.View() { Name = classinfo.Table.Name }); continue; } var table = new Table(); table.ActualName = classinfo.Table.Name; foreach (var column in classinfo.Table.Columns) table.Columns.Add(new Column() { ActualName = column.Name, DataType = column.ColumnType.ToSchemaDbType(), MaxLength = column.Size, IsPrimaryKeyColumn = column.IsKey, IsIdentity = column.IsIdentity }); table.BuildPrimaryKey(); foreach (var index in classinfo.Table.Indexes) { var schemaIndex = new Index() { IndexName = index.Name, IndexType = index.IsUnique ? IndexTypes.Unqiue : IndexTypes.NonUnqiue }; int i = 1; foreach (var col in index.Columns) { var indexCol = new IndexColumn(); indexCol.ColumnName = col; indexCol.Sequence = i; indexCol.Order = Ordering.Ascending; i++; schemaIndex.Columns.Add(indexCol); } table.Indizes.Add(schemaIndex); } foreach (var fk in classinfo.Table.ForeignKeys) { var foreignKey = new ForeignKey(); foreignKey.Name = fk.Name; foreignKey.Columns.AddRange(fk.Columns.Cast<string>()); foreignKey.DetailTable = classinfo.TableName; foreignKey.MasterTable = fk.PrimaryKeyTable; foreignKey.UniqueColumns.AddRange(fk.PrimaryKeyTableKeyColumns.Cast<string>()); table.ForeignKeys.Add(foreignKey); } schemaProvider.Tables.Add(table); } return schemaProvider; }
ApplicationModulesManager GetApplicationModulesManager(PathInfo pathInfo) { string assemblyPath = Path.GetDirectoryName(pathInfo.AssemblyPath); var designerModelFactory = new DesignerModelFactory(); var moduleFromFile = designerModelFactory.CreateModuleFromFile(pathInfo.AssemblyPath, assemblyPath); return designerModelFactory.CreateModulesManager(moduleFromFile, pathInfo.AssemblyPath); }
static void Main(string[] args) { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.ThreadException += new ThreadExceptionEventHandler(OnException); if (args.Length == 0 ||args.Length > 2) { MessageBox.Show(string.Format("Usage: {0}'{1}' <Path_to_app_config_file> {0} '{1}' <Path_to_dll_file> <Path_to_diff_file>", Environment.NewLine, Environment.GetCommandLineArgs()[0]), ModelEditorForm.Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { args[0] = args[0].TrimStart('"').TrimEnd('"'); args[1] = args[1].TrimStart('"').TrimEnd('"'); string targetPath = args[0]; string diffsPath = (args.Length == 2 ? args[1] : string.Empty); if (Path.GetExtension(targetPath).ToLower() != ".config" && Path.GetExtension(targetPath).ToLower() != ".dll") { throw new Exception("This file can be executed with a configuration or an assebly file as a parameter."); } if(!File.Exists(targetPath)) { targetPath = Path.Combine(System.Environment.CurrentDirectory, targetPath); if(!File.Exists(targetPath)) { throw new Exception(String.Format("The config file '{0}' couldn't be found.", targetPath)); } } if (diffsPath == string.Empty) { diffsPath = Path.GetDirectoryName(targetPath); } if(diffsPath == string.Empty) { diffsPath = System.Environment.CurrentDirectory; } DesignerModelFactory dmf = new DesignerModelFactory(); ApplicationModulesManager mgr = dmf.CreateModelManager(targetPath, diffsPath); mgr.Load(); var controller = new ModelEditorController(mgr.Model, mgr.LastDiffsStore, mgr.Modules); modelEditorForm = new ModelEditorForm(controller, new SettingsStorageOnRegistry(@"Software\Developer Express\eXpressApp Framework\Model Editor")); modelEditorForm.SetCaption(Path.GetFileName(targetPath)); Application.Run(modelEditorForm); } catch(Exception exception) { HandleException(exception); } } }
private static int Main(string[] args) { ExitCode exitCode = ExitCode.UpdateError; WriteHeader(); if(args.Length == 0) { Console.WriteLine("Usage: {0}", usage); Console.WriteLine("Exit codes: 0 - " + updateCompleted + "."); Console.WriteLine(" 1 - " + updateError + "."); Console.WriteLine(" 2 - " + updateNotNeeded + "."); } else { try { string configFileName = null; bool silent = false; string applicationFileName = null; string customConnectionString = null; if(args[0] == STR_Silent) { silent = true; Console.WriteLine("Silent mode ON"); if(args.Length > 1) { configFileName = args[1]; if((args.Length > 2) && (args[2] != STR_ConnectionString)) { applicationFileName = args[2]; } } else { throw new Exception("The application configuration file parameter couldn't be found."); } } else { Console.WriteLine("Silent mode OFF"); configFileName = args[0]; if((args.Length > 1) && (args[1] != STR_ConnectionString)) { applicationFileName = args[1]; } } if(!File.Exists(configFileName)) { Exception e = null; try { configFileName = Path.Combine(System.Environment.CurrentDirectory, configFileName); configFileName = Path.GetFullPath(configFileName); } catch(Exception ex) { e = ex; } if(!File.Exists(configFileName) || (e != null)) { throw new Exception(String.Format("The application configuration file '{0}' couldn't be found.", configFileName), e); } } if(!string.IsNullOrEmpty(applicationFileName)) { Exception e = null; try { applicationFileName = Path.GetFullPath(applicationFileName); } catch(Exception ex) { e = ex; } if(!File.Exists(applicationFileName) || (e != null)) { throw new Exception(String.Format("The application assembly file '{0}' couldn't be found.", applicationFileName), e); } } for(int i = 0; i < args.Length; i++) { if(args[i] == STR_ConnectionString) { if((i + 1) == (args.Length - 1)) { customConnectionString = args[i + 1]; if(string.IsNullOrEmpty(customConnectionString)) { throw new Exception("The specified connection string parameter value is empty."); } break; } else { throw new Exception("The connection string parameter couldn't be found. Ensure that it is enclosed in double quotes."); } } } string connectionString; string modules; string tablePrefixes; GetDBUpdaterParameters(configFileName, out connectionString, out modules, out tablePrefixes); if(!string.IsNullOrEmpty(customConnectionString)) { connectionString = customConnectionString; } string diffsPath = Path.GetDirectoryName(configFileName); if(configFileName.ToLower().IndexOf("web.config") == -1) { diffsPath = Path.Combine(diffsPath, @"..\..\"); } DesignerModelFactory dmf = new DesignerModelFactory(); string assembliesPath = string.Empty; try { dmf.GetFileContainingApplicationType(configFileName, applicationFileName, ref assembliesPath); } catch(DesignerModelFactory_FindApplicationAssemblyException e) { throw new Exception(e.Message + Environment.NewLine + "To avoid ambiguity, specify assembly file name as the third parameter." + Environment.NewLine + usage); } XafApplication application = dmf.CreateApplicationByConfigFile(configFileName, applicationFileName, ref assembliesPath); ISupportSplashScreen temp = application as ISupportSplashScreen; if(temp != null) { temp.RemoveSplash(); } if(!string.IsNullOrEmpty(connectionString)) { application.ConnectionString = connectionString; } else { Console.WriteLine("ConnectionString is not found in the configuration file. DBUpdater will use the ConnectionString specified in the Application designer."); } if(tablePrefixes != null) { application.TablePrefixes = tablePrefixes; } application.Setup(application.ApplicationName, application.ConnectionString, modules.Split(';')); DatabaseUpdater dbUpdater = application.CreateDatabaseUpdater(); ApplicationStatusUpdater.UpdateStatus += new EventHandler<UpdateStatusEventArgs>(ApplicationStatusUpdater_UpdateStatus); Console.WriteLine("Updating database via the following connection string:"); Console.WriteLine(application.ObjectSpaceProvider.ConnectionString); Console.WriteLine(); CompatibilityError error = dbUpdater.CheckCompatibility(); if(error != null) { exitCode = UpdateDataBase(error, dbUpdater, silent); } else { Console.WriteLine(updateNotNeeded + "."); exitCode = ExitCode.UpdateNotNeeded; } application.Dispose(); ApplicationStatusUpdater.UpdateStatus -= new EventHandler<UpdateStatusEventArgs>(ApplicationStatusUpdater_UpdateStatus); } catch(Exception e) { Tracing.Tracer.LogError(e); exitCode = ExitCode.UpdateError; Console.WriteLine(updateError + "."); string exceptionReport = Tracing.Tracer.FormatExceptionReport(e); Console.WriteLine(exceptionReport); } } return (int)exitCode; }