static void Main(string[] argv) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.ThreadException += Application_ThreadException; #if !DEBUG //if (!Util.VerifyKey()) //{ // using (var form = new RegisterForm()) // { // DialogResult res = form.ShowDialog(); // if (res == DialogResult.OK) // Application.Restart(); // } // return; //} #endif try { DevExpress.UserSkins.OfficeSkins.Register(); DevExpress.UserSkins.BonusSkins.Register(); DevExpress.Skins.SkinManager.EnableFormSkins(); DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle("Devexpress Style"); int count = 0; IDataStore dataStore = null; RETRY: try { dataStore = XpoDefault.GetConnectionProvider( MSSqlConnectionProvider.GetConnectionString(Properties.Settings.Default.SqlInstanceName, "FaceCapture"), AutoCreateOption.DatabaseAndSchema); } catch (Exception ex) { ++count; if (count == 3) { MessageBox.Show("无法连接数据库,请确认数据库已经正确安装。", "数据库", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { //让sqlserver有时间启动。 System.Threading.Thread.Sleep(3000); goto RETRY; } } using (SimpleDataLayer dataLayer = new SimpleDataLayer(dataStore)) { using (Session session = new Session(dataLayer)) { session.UpdateSchema(); session.CreateObjectTypeRecords( typeof(Damany.PortraitCapturer.DAL.DTO.CapturedImageObject), typeof(Damany.PortraitCapturer.DAL.DTO.Video), typeof(Damany.PortraitCapturer.DAL.DTO.Portrait), typeof(Damany.PortraitCapturer.DAL.DTO.Frame), typeof(Damany.PortraitCapturer.DAL.DTO.TargetPerson)); var cachNode = new DataCacheNode(new DataCacheRoot(dataStore)); XpoDefault.DataLayer = new ThreadSafeDataLayer(session.Dictionary, cachNode); } } try { #if !DEBUG //if (!Util.VerifyKey()) //{ // RegisterForm form = new RegisterForm(); // DialogResult res = form.ShowDialog(); // if (res == DialogResult.OK) // { // Application.Restart(); // } // return; //} #endif var modeCollection = new DevExpress.Xpo.XPCollection<WorkModeCamSetting>(); modeCollection.Load(); if (modeCollection.Count == 0) { var workingModeSettings = new WorkModeCamSetting(); workingModeSettings.ModeName = "室外模式"; workingModeSettings.ShutterSpeed = 3; workingModeSettings.IrisLevel = 40; workingModeSettings.Save(); workingModeSettings = new WorkModeCamSetting(); workingModeSettings.ShutterSpeed = 1; workingModeSettings.IrisLevel = 50; workingModeSettings.ModeName = "室内模式"; workingModeSettings.Save(); } foreach (var workModeCamSetting in modeCollection) { var dummy = workModeCamSetting; System.Diagnostics.Debug.WriteLine(dummy); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var strapper = new StartUp(); strapper.Start(); var mainForm = strapper.Container.Resolve<RemoteImaging.RealtimeDisplay.MainForm>(); var controller = strapper.Container.Resolve<MainController>(); mainForm.AttachController(controller); mainForm.ButtonsVisible = (ButtonsVisibleSectionHandler)System.Configuration.ConfigurationManager.GetSection("FaceDetector.ButtonsVisible"); try { //StartLicensePlateMonitor(strapper.Container); WireupNavigation(strapper.Container); //RegisterLicensePlateRepository(strapper); } catch (Exception e) { HandleException(e); } Application.Run(mainForm); } catch (Exception e) { HandleException(e); } } catch (Exception ex) { HandleException(ex); } }
int FindIdentityValue(QueryParameterCollection queryParameterCollection, SimpleDataLayer simpleDataLayer) { using (var session = new Session(simpleDataLayer) { IdentityMapBehavior = IdentityMapBehavior.Strong }) { var typeName = queryParameterCollection[0].Value.ToString(); var assemblyName = queryParameterCollection[1].Value.ToString(); return session.FindObject<XPObjectType>(type => type.TypeName == typeName && type.AssemblyName == assemblyName).Oid; } }
ParameterValue[] ModifyXPObjectTypeDataCore(SimpleDataLayer dataLayer, InsertStatement insertStatement) { if (TypeExists(dataLayer, insertStatement)) return null; if (!IsMainLayer(dataLayer.Connection)) { _xpoObjectHacker.CreateObjectTypeIndetifier(insertStatement,_dataStoreManager.SimpleDataLayers[DataStoreManager.STR_Default]); } return dataLayer.ModifyData(insertStatement).Identities; }
public override void UpdateOrCreateSchema(SchemaStatus SchemaStatus) { if (XpoDefault.DataLayer == null) { using (var updateDataLayer = new SimpleDataLayer(Dictionary, CreateUpdatingDataStore(true))) { //HACK you can use any of the following versions to pass persistent types or assemblies //updateDataLayer.UpdateSchema(false, dictionary.CollectClassInfos(GetPersistentTypes())); if (Assemblies != null) { updateDataLayer.UpdateSchema(false, Dictionary.CollectClassInfos(Assemblies)); new UnitOfWork(updateDataLayer).CreateObjectTypeRecords(); return; } if (PersistentTypes != null) { updateDataLayer.UpdateSchema(false, Dictionary.CollectClassInfos(PersistentTypes)); new UnitOfWork(updateDataLayer).CreateObjectTypeRecords(); return; } throw new Exception(Message); } } }
public App() { InitializeComponent(); RestApiAgnosticDataStoreImp.Register(); string connectionString = "XpoProvider=RestApiAgnosticDataStoreImp;EndPoint=http://192.168.1.64/XpoServer/api/DataStoreAgnosticMultiDb;Token=Empty;DataStoreId=ConnectionString"; var DataStore = DevExpress.Xpo.XpoDefault.GetConnectionProvider(connectionString, DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema); var dictionary = new ReflectionDictionary(); dictionary.GetDataStoreSchema(typeof(Item).Assembly); //Updating schema XPO way SimpleDataLayer UpdateSchemaDal = new SimpleDataLayer(dictionary, DataStore); UnitOfWork UpdateSchemaUoW = new UnitOfWork(UpdateSchemaDal); UpdateSchemaUoW.UpdateSchema(); UpdateSchemaUoW.CreateObjectTypeRecords(); //Finish updating schema XpoDefault.DataLayer = new SimpleDataLayer(dictionary, DataStore); DependencyService.Register <MockDataStore>(); MainPage = new MainPage(); }
public void AutoScript() { // Создание скрипта const string path = "autoscript.txt"; StreamWriter script = new StreamWriter(path); ReflectionDictionary dictionary = new ReflectionDictionary(); XPDictionaryInformer.Register(dictionary); SimpleDataLayer dataLayer = new SimpleDataLayer(dictionary, new OracleConnectionProviderEx( ODPConnectionProvider.CreateConnection(Properties.Settings.Default.ConnectionAdmin), AutoCreateOption.SchemaOnly, script, UpdateSchemaOptions.Default)); dataLayer.UpdateSchema(false, new Type[] { typeof(AutoIdClass), typeof(StringIdClass), typeof(ComplexIdClass), typeof(NoIdClass), typeof(NotNullClass), typeof(ReadOnlyClass), typeof(ConsistentPeriodClass), typeof(ConsistentPeriodClass2), typeof(ContinuousPeriodClass), typeof(HierarchyClass), typeof(SimpleConstraintClass), typeof(ConstraintClass), typeof(CategoryClass), typeof(SecurityClass), typeof(UniqueBaseClass), typeof(UniqueClass), typeof(DevExpress.Xpo.XPObjectType) }.Select(c => dictionary.GetClassInfo(c)).ToArray()); script.Close(); // Проверка непустого содержания файла FileStream file = new FileStream(path, FileMode.Open); Assert.IsFalse(file.Length == 0, "File of autoscript is empty."); file.Close(); // Проверка валидности скрипта Connection.ExecuteFile(path); dataLayer.Dispose(); }
public void TestTwoDataStores() { InMemoryDataStore dataStore1 = new InMemoryDataStore(AutoCreateOption.DatabaseAndSchema); InMemoryDataStore dataStore2 = new InMemoryDataStore(AutoCreateOption.DatabaseAndSchema); MixedDataStore mixedDataStore = new MixedDataStore(dataStore1, DataStoreMode.SchemaUpdate); mixedDataStore.AddDataStore(dataStore2, DataStoreMode.SchemaUpdate, "2_", true); using (var dataLayer = new SimpleDataLayer(mixedDataStore)) { using (var uow = new UnitOfWork(dataLayer)) { TestObject1 obj1 = new TestObject1(uow); obj1.Name = "Object 1"; TestObject2 obj2 = new TestObject2(uow); obj2.Name = "Object 2"; uow.CommitChanges(); var objects = uow.Query <TestObject1>().ToArray(); Assert.AreEqual(1, objects.Length); Assert.AreEqual("Object 1", objects[0].Name); var tables = dataStore1.GetStorageTablesList(false); Assert.AreEqual("TestObject1", tables.Single()); tables = dataStore2.GetStorageTablesList(false); Assert.AreEqual("TestObject2", tables.Single()); } } }
public override void Setup(ApplicationModulesManager moduleManager) { base.Setup(moduleManager); WCTypesInfo.Instance.Register(GetAdditionalClasses(moduleManager)); if (Application == null || GetPath() == null) { return; } Application.SettingUp += ApplicationOnSettingUp; if (FullConnectionString != null) { var xpoMultiDataStoreProxy = new MultiDataStoreProxy(FullConnectionString, GetReflectionDictionary()); using (var dataLayer = new SimpleDataLayer(xpoMultiDataStoreProxy)) { using (var session = new Session(dataLayer)) { using (var unitOfWork = new UnitOfWork(session.DataLayer)) { RunUpdaters(session); AddDynamicModules(moduleManager, unitOfWork); } } } } else { var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => assembly.ManifestModule.ScopeName.EndsWith(CompileEngine.XpandExtension)); foreach (var assembly1 in assemblies) { moduleManager.AddModule(assembly1.GetTypes().Single(type => typeof(ModuleBase).IsAssignableFrom(type))); } } Application.SetupComplete += ApplicationOnSetupComplete; }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { ConfigureFilters(Uno.Extensions.LogExtensionPoint.AmbientLoggerFactory); RestApiAgnosticDataStoreImp.Register(); string connectionString = "XpoProvider=RestApiAgnosticDataStoreImp;EndPoint=http://192.168.1.64/XpoServer/api/DataStoreAgnosticMultiDb;Token=Empty;DataStoreId=ConnectionString"; var DataStore = XpoDefault.GetConnectionProvider(connectionString, DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema); var dictionary = new ReflectionDictionary(); dictionary.GetDataStoreSchema(typeof(Item).Assembly); //Updating schema XPO way SimpleDataLayer UpdateSchemaDal = new SimpleDataLayer(dictionary, DataStore); UnitOfWork UpdateSchemaUoW = new UnitOfWork(UpdateSchemaDal); UpdateSchemaUoW.UpdateSchema(); UpdateSchemaUoW.CreateObjectTypeRecords(); //Finish updating schema XpoDefault.DataLayer = new SimpleDataLayer(dictionary, DataStore); this.InitializeComponent(); this.Suspending += OnSuspending; }
/// <summary> /// Opens the second storage. /// </summary> private void openSecondStorage() { if (!string.IsNullOrEmpty(secondStorageConnStr) && (secondStorageDataStore == null || secondStorageDataStore == appDataStore)) { try { secondStorageDataStore = XpoDefault.GetConnectionProvider(secondStorageConnStr, AutoCreateOption.DatabaseAndSchema); secondStorageDataLayer = new SimpleDataLayer(secondStorageDictionary, secondStorageDataStore); } catch (Exception exception) { var args = new GetPlatformArgs(); XafDeltaModule.Instance.OnGetPlatform(args); if (args.XafDeltaPlatform != null) { args.XafDeltaPlatform.OnShowError(new ErrorEventArgs(exception)); } secondStorageDataStore = appDataStore; secondStorageDataLayer = appDataLayer; } foreach (var packageUpdate in delayedPackageUpdates) { secondStorageDataStore.UpdateSchema(false, packageUpdate.ToArray()); } delayedPackageUpdates.Clear(); } return; }
public override void Setup(ApplicationModulesManager moduleManager) { base.Setup(moduleManager); var businessClassesList = GetAdditionalClasses(moduleManager); WCTypesInfo.Instance.Register(businessClassesList); if (Application == null || GetPath() == null) return; Application.SettingUp += ApplicationOnSettingUp; if (FullConnectionString != null) { var xpoMultiDataStoreProxy = new SqlMultiDataStoreProxy(FullConnectionString, GetReflectionDictionary()); using (var dataLayer = new SimpleDataLayer(xpoMultiDataStoreProxy)) { using (var session = new Session(dataLayer)) { using (var unitOfWork = new UnitOfWork(session.DataLayer)) { RunUpdaters(session); AddDynamicModules(moduleManager, unitOfWork); } } } } else { var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => assembly.ManifestModule.ScopeName.EndsWith(CompileEngine.XpandExtension)); foreach (var assembly1 in assemblies) { moduleManager.AddModule(assembly1.GetTypes().Where(type => typeof(ModuleBase).IsAssignableFrom(type)).Single()); } } Application.SetupComplete += ApplicationOnSetupComplete; }
void SynchronizeTypes(string connectionString, IEnumerable<XPObjectType> xpObjectTypes) { var sqlDataStoreProxy = new DataStoreProxy(connectionString); using (var simpleDataLayer = new SimpleDataLayer(sqlDataStoreProxy)) { using (var session = new Session(simpleDataLayer)) { var xpoObjectHacker = new XpoObjectHacker(); bool sync = false; int[] oid = { 0 }; sqlDataStoreProxy.DataStoreUpdateSchema += EnsureIsNotIdentity(xpoObjectHacker); sqlDataStoreProxy.DataStoreModifyData += (sender, args) => { var insertStatement = args.ModificationStatements.OfType<InsertStatement>().SingleOrDefault(statement => statement.TableName == typeof(XPObjectType).Name); if (insertStatement != null && !sync) { sync = true; xpoObjectHacker.CreateObjectTypeIndetifier(insertStatement, simpleDataLayer, oid[0]); var modificationResult = sqlDataStoreProxy.ModifyData(insertStatement); sync = false; args.ModificationResult = modificationResult; args.ModificationResult.Identities = new[] { new ParameterValue { Value = oid[0] } }; } }; foreach (var xpObjectType in xpObjectTypes) { oid[0] = xpObjectType.Oid; SynchronizeTypesCore(xpObjectType, session); } } } }
void SynchronizeTypes(string connectionString, IEnumerable <XPObjectType> xpObjectTypes) { var sqlDataStoreProxy = new DataStoreProxy(connectionString); using (var simpleDataLayer = new SimpleDataLayer(sqlDataStoreProxy)) { using (var session = new Session(simpleDataLayer)) { var xpoObjectHacker = new XpoObjectHacker(); bool sync = false; int[] oid = { 0 }; sqlDataStoreProxy.DataStoreUpdateSchema += EnsureIsNotIdentity(xpoObjectHacker); sqlDataStoreProxy.DataStoreModifyData += (sender, args) => { var insertStatement = args.ModificationStatements.OfType <InsertStatement>().SingleOrDefault(statement => statement.TableName == typeof(XPObjectType).Name); if (insertStatement != null && !sync) { sync = true; xpoObjectHacker.CreateObjectTypeIndetifier(insertStatement, simpleDataLayer, oid[0]); var modificationResult = sqlDataStoreProxy.ModifyData(insertStatement); sync = false; args.ModificationResult = modificationResult; args.ModificationResult.Identities = new[] { new ParameterValue { Value = oid[0] } }; } }; foreach (var xpObjectType in xpObjectTypes) { oid[0] = xpObjectType.Oid; SynchronizeTypesCore(xpObjectType, session); } } } }
public virtual void Setup() { DictionaryNode.ReaderWriterLockWrapperCreator = new ReaderWriterLockWrapper(); elDictionary = new Dictionary(new DictionaryXmlReader().ReadFromString(elClassXml), Schema.GetCommonSchema()); DefaultDictionary = new Dictionary(new DictionaryXmlReader().ReadFromString(DefaultClassXml), Schema.GetCommonSchema()); PersistentAppDictionary = new Dictionary(new DictionaryXmlReader().ReadFromString(PersistentAppClassXml), Schema.GetCommonSchema()); DefaultDictionary2 = new Dictionary(new DictionaryXmlReader().ReadFromString(DefaultClassXml2), Schema.GetCommonSchema()); Session.DefaultSession.Disconnect(); // dataSet = new DataSet(); XafTypesInfo.Reset(true); var dataStore = new InMemoryDataStore( AutoCreateOption.DatabaseAndSchema); dataLayer = new SimpleDataLayer(XafTypesInfo.XpoTypeInfoSource.XPDictionary, dataStore); XpoDefault.DataLayer = dataLayer; // Isolate.Fake.ISecurityComplex(); }
void SynchronizeTypes(UnitOfWork unitOfWork) { var xpObjectTypes = new XPCollection<XPObjectType>(unitOfWork); var dataStoreManager = new SqlMultiDataStoreProxy(ConnectionString); foreach (var xpObjectType in xpObjectTypes) { var type = ReflectionHelper.FindType(xpObjectType.TypeName); if (type != null) { var connectionString = dataStoreManager.DataStoreManager.GetConnectionString(type); var sqlDataStoreProxy = new SqlDataStoreProxy(connectionString); var xpoObjectHacker = new XpoObjectHacker(); XPObjectType type1 = xpObjectType; var simpleDataLayer = new SimpleDataLayer(sqlDataStoreProxy); var session = new Session(simpleDataLayer); bool sync = false; sqlDataStoreProxy.DataStoreModifyData += (sender, args) => { var insertStatement = args.ModificationStatements.OfType<InsertStatement>().Where(statement => statement.TableName == typeof(XPObjectType).Name).SingleOrDefault(); if (insertStatement != null && !sync) { sync = true; xpoObjectHacker.CreateObjectTypeIndetifier(insertStatement, simpleDataLayer, type1.Oid); ModificationResult modificationResult = sqlDataStoreProxy.ModifyData(insertStatement); args.ModificationResult = modificationResult; args.ModificationResult.Identities = new[] { new ParameterValue { Value = type1.Oid }, }; } }; if (session.FindObject<XPObjectType>(objectType => objectType.TypeName == type1.TypeName) == null) { var objectType = new XPObjectType(session, xpObjectType.AssemblyName, xpObjectType.TypeName); session.Save(objectType); } } } }
void BindProducts() { SimpleDataLayer dataLayer = (SimpleDataLayer)session1.DataLayer; ConnectionProviderSql provider = (ConnectionProviderSql)dataLayer.ConnectionProvider; DBTable[] tables = provider.GetStorageTables("Products"); gridControl2.DataSource = new XPCollection(session1, Program.AddClass(session1.Dictionary, tables[0])); }
bool TypeExists(SimpleDataLayer dataLayer, InsertStatement stm1) { if (IsMainLayer(dataLayer.Connection)) return false; var session = new Session(dataLayer) { IdentityMapBehavior = IdentityMapBehavior.Strong }; var value = stm1.Parameters.ToList()[0].Value as string; var xpObjectType = session.FindObject<XPObjectType>(type => type.TypeName == value); return xpObjectType != null; }
private static IDataLayer GetDataLayer() { XpoDefault.Session = null; InMemoryDataStore provider = new InMemoryDataStore(); IDataLayer dl = new SimpleDataLayer(provider); return(dl); }
private XpandUnitOfWork CreateUnitOfWork(IDataStore dataStore, IEnumerable<IDisposable> disposableObjects){ var disposableObjectsList = new List<IDisposable>(); if (disposableObjects != null){ disposableObjectsList.AddRange(disposableObjects); } var dataLayer = new SimpleDataLayer(XPDictionary, dataStore); disposableObjectsList.Add(dataLayer); return new XpandUnitOfWork(dataLayer, disposableObjectsList.ToArray()); }
public ParameterValue CreateObjectTypeIndetifier(InsertStatement insertStatement, SimpleDataLayer simpleDataLayer,int value) { var identityParameter = insertStatement.IdentityParameter; insertStatement.IdentityParameter = null; insertStatement.Parameters.Add(new ParameterValue(3) { Value = value }); var oidQueryOperand = insertStatement.Operands.OfType<QueryOperand>().Where(operand => operand.ColumnName == "Oid").FirstOrDefault(); if (ReferenceEquals(oidQueryOperand,null)) insertStatement.Operands.Add(new QueryOperand { ColumnName = "Oid", ColumnType = DBColumnType.Int32 }); return identityParameter; }
protected override IEnumerable<Type> GetDeclaredExportedTypes() { var existentTypesMemberCreator = new ExistentTypesMemberCreator(); if (FullConnectionString != null) { var xpoMultiDataStoreProxy = new SqlMultiDataStoreProxy(FullConnectionString, GetReflectionDictionary()); var simpleDataLayer = new SimpleDataLayer(xpoMultiDataStoreProxy); var session = new Session(simpleDataLayer); existentTypesMemberCreator.CreateMembers(session); } return base.GetDeclaredExportedTypes(); }
private static IDataLayer GetDataLayer() { XpoDefault.Session = null; InMemoryDataStore provider = new InMemoryDataStore(); // For demo purposes only! Create a ThreadSafeDataLayer in production! IDataLayer dl = new SimpleDataLayer(provider); return(dl); }
ReflectionDictionary GetDictionary(string key) { if (!_reflectionDictionaries.ContainsKey(key)) { var reflectionDictionary = new ReflectionDictionary(); _reflectionDictionaries.Add(key, reflectionDictionary); var simpleDataLayer = new SimpleDataLayer(reflectionDictionary,GetConnectionProvider(key)); _simpleDataLayers.Add(key, simpleDataLayer); _tables.Add(key,new List<string>()); } return _reflectionDictionaries[key]; }
//Scenario Result Expected public void CreateDataWithEncryptedConnectionReadDataWithNormalConnection_FileCantBeReaded_Fail() { SQLitePCL.Batteries_V2.Init(); EncriptedSQLiteConnectionProvider.Register(); if (File.Exists("CreateDataWithEncryptedConnectionReadDataWithNormalConnection.db")) { File.Delete("CreateDataWithEncryptedConnectionReadDataWithNormalConnection.db"); } System.IDisposable[] _discard; var CipherDataStore = EncriptedSQLiteConnectionProvider.CreateProviderFromString(@"XpoProvider=EncriptedSQLiteConnectionProvider;Data Source=CreateDataWithEncryptedConnectionReadDataWithNormalConnection.db", DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema, "abc123", out _discard); IDataLayer dl = new SimpleDataLayer(CipherDataStore); using (Session session = new Session(dl)) { System.Reflection.Assembly[] assemblies = new System.Reflection.Assembly[] { typeof(Customer).Assembly, }; session.UpdateSchema(assemblies); session.CreateObjectTypeRecords(assemblies); } UnitOfWork UoW = new UnitOfWork(dl); Customer Customer = new Customer(UoW); Customer.Name = "Jose Manuel Ojeda Melgar"; Customer.Address = "Saint Petersburg Russia"; Customer.Inactive = false; Customer.CreatedOn = new System.DateTime(2020, 5, 16); UoW.CommitChanges(); var NormalDataStore = SQLiteConnectionProvider.CreateProviderFromString(@"Data Source=CreateDataWithEncryptedConnectionReadDataWithNormalConnection.db", DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema, out _discard); UnitOfWork unitOfWork = new UnitOfWork(new SimpleDataLayer(NormalDataStore)); var Criteria = new DevExpress.Data.Filtering.BinaryOperator("Name", "Jose Manuel Ojeda Melgar"); Assert.Throws <DevExpress.Xpo.DB.Exceptions.SqlExecutionErrorException>(() => { var CustomerFromDatabase = unitOfWork.FindObject <Customer>(Criteria); Assert.AreEqual(CustomerFromDatabase.Name, Customer.Name); Assert.AreEqual(CustomerFromDatabase.Address, Customer.Address); Assert.AreEqual(CustomerFromDatabase.Inactive, Customer.Inactive); }); }
int FindIdentityValue(QueryParameterCollection queryParameterCollection, SimpleDataLayer simpleDataLayer) { using (var session = new Session(simpleDataLayer) { IdentityMapBehavior = IdentityMapBehavior.Strong }) { var typeName = queryParameterCollection[0].Value.ToString(); var assemblyName = queryParameterCollection[1].Value.ToString(); return(session.FindObject <XPObjectType>(type => type.TypeName == typeName && type.AssemblyName == assemblyName).Oid); } }
public override void CustomizeTypesInfo(DevExpress.ExpressApp.DC.ITypesInfo typesInfo) { base.CustomizeTypesInfo(typesInfo); if (_existentTypesMemberCreator == null && RuntimeMode) { _existentTypesMemberCreator = new ExistentTypesMemberCreator(); var reflectionDictionary = WorldCreatorModuleBase.GetReflectionDictionary(this); var xpoMultiDataStoreProxy = new MultiDataStoreProxy(ConnectionString, reflectionDictionary); var simpleDataLayer = new SimpleDataLayer(xpoMultiDataStoreProxy); var session = new Session(simpleDataLayer); _existentTypesMemberCreator.CreateMembers(session,typesInfo); } }
private static IDataLayer CreateDataLayer() { var dict = new DevExpress.Xpo.Metadata.ReflectionDictionary(); var classes = dict.CollectClassInfos(typeof(SampleObject).Assembly); var provider = XpoDefault.GetConnectionProvider(DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("localhost", "XpoImportHelperTest"), Xpo.DB.AutoCreateOption.DatabaseAndSchema); var dal = new SimpleDataLayer(dict, provider); ((IDataLayerForTests)dal).ClearDatabase(); dal.UpdateSchema(false, classes); return(dal); }
private static IDataLayer GetDataLayer() { XpoDefault.Session = null; string conn = MSSqlConnectionProvider.GetConnectionString(resources.api.cdsonline.co.za.Properties.Settings.Default.Server.ToString(), resources.api.cdsonline.co.za.Properties.Settings.Default.DB.ToString()); //XPDictionary dict = new ReflectionDictionary(); IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists); //dict.GetDataStoreSchema(typeof(PersistentObjects.Customer).Assembly); IDataLayer dl = new SimpleDataLayer(store); //new ThreadSafeDataLayer(dict, store); return(dl); }
private static IDataLayer GetDataLayer(string connectionName, XPDictionary databaseSchema) { IDataStore connectionProvider = GetConnectionProvider(connectionName); IDataLayer dataLayer = new SimpleDataLayer(databaseSchema, connectionProvider); if (DontLoadClassInfoFromDatabase) { ConfigureDataLayerNotToLoadClassInfoFromDatabase(dataLayer); } return(dataLayer); }
//Scenario Result Expected public void CreateDataStoreFromConnectionStringWithoutEncryptionKeyAndNullFunction_ExceptionIsThrown_Pass() { Assert.Throws <ArgumentNullException>(() => { SQLitePCL.Batteries_V2.Init(); EncriptedSQLiteConnectionProvider.Register(); if (File.Exists("CreateDataStoreFromConnectionStringWithoutEncryptionKeyAndNullFunction.db")) { File.Delete("CreateDataStoreFromConnectionStringWithoutEncryptionKeyAndNullFunction.db"); } //EncriptedSQLiteConnectionProvider.RequestPassword = new System.Func<string>(() => "abc123"); System.IDisposable[] _discard; var DataStore = EncriptedSQLiteConnectionProvider.CreateProviderFromString(@"XpoProvider=EncriptedSQLiteConnectionProvider;Data Source=CreateDataStoreFromConnectionStringWithoutEncryptionKeyAndNullFunction.db", DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema, string.Empty, out _discard); //ArgumentNullException IDataLayer dl = new SimpleDataLayer(DataStore); using (Session session = new Session(dl)) { System.Reflection.Assembly[] assemblies = new System.Reflection.Assembly[] { typeof(Customer).Assembly, }; session.UpdateSchema(assemblies); session.CreateObjectTypeRecords(assemblies); } UnitOfWork UoW = new UnitOfWork(dl); Customer Customer = new Customer(UoW); Customer.Name = "Jose Manuel Ojeda Melgar"; Customer.Address = "Saint Petersburg Russia"; Customer.Inactive = false; Customer.CreatedOn = new System.DateTime(2020, 5, 16); UoW.CommitChanges(); UnitOfWork unitOfWork = new UnitOfWork(dl); var Criteria = new DevExpress.Data.Filtering.BinaryOperator("Name", "Jose Manuel Ojeda Melgar"); var CustomerFromDatabase = unitOfWork.FindObject <Customer>(Criteria); Assert.AreEqual(CustomerFromDatabase.Name, Customer.Name); Assert.AreEqual(CustomerFromDatabase.Address, Customer.Address); Assert.AreEqual(CustomerFromDatabase.Inactive, Customer.Inactive); }); }
private XpandUnitOfWork CreateUnitOfWork(IDataStore dataStore, IEnumerable <IDisposable> disposableObjects) { var disposableObjectsList = new List <IDisposable>(); if (disposableObjects != null) { disposableObjectsList.AddRange(disposableObjects); } var dataLayer = new SimpleDataLayer(XPDictionary, dataStore); disposableObjectsList.Add(dataLayer); return(new XpandUnitOfWork(dataLayer, disposableObjectsList.ToArray())); }
protected override IEnumerable <Type> GetDeclaredExportedTypes() { var existentTypesMemberCreator = new ExistentTypesMemberCreator(); if (FullConnectionString != null) { var xpoMultiDataStoreProxy = new MultiDataStoreProxy(FullConnectionString, GetReflectionDictionary()); var simpleDataLayer = new SimpleDataLayer(xpoMultiDataStoreProxy); var session = new Session(simpleDataLayer); existentTypesMemberCreator.CreateMembers(session); } return(base.GetDeclaredExportedTypes()); }
private IDataLayer GetDataLayer() { XpoDefault.Session = null; // string conn = Properties.Settings.Default.ConnectionString; //string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; XPDictionary dict = new ReflectionDictionary(); IDataStore store = XpoDefault.GetConnectionProvider(this.connectionString, AutoCreateOption.DatabaseAndSchema); //IDataLayer dl = new ThreadSafeDataLayer(dict, store); IDataLayer dl = new SimpleDataLayer(dict, store); return(dl); }
private Session CreateSession(IDataStore dataStore, IDisposable[] disposableObjects) { var disposableObjectsList = new List <IDisposable>(); if (disposableObjects != null) { disposableObjectsList.AddRange(disposableObjects); } var dataLayer = new SimpleDataLayer(XPDictionary, dataStore); disposableObjectsList.Add(dataLayer); return(new Session(dataLayer, disposableObjectsList.ToArray())); }
public override void CustomizeTypesInfo(DevExpress.ExpressApp.DC.ITypesInfo typesInfo) { base.CustomizeTypesInfo(typesInfo); if (_existentTypesMemberCreator == null && RuntimeMode) { AddToAdditionalExportedTypes("Xpand.Persistent.BaseImpl.PersistentMetaData"); WCTypesInfo.Instance.Register(GetAdditionalClasses(ModuleManager)); _existentTypesMemberCreator = new ExistentTypesMemberCreator(); var reflectionDictionary = WorldCreatorModuleBase.GetReflectionDictionary(this); var xpoMultiDataStoreProxy = new MultiDataStoreProxy(ConnectionString, reflectionDictionary); var simpleDataLayer = new SimpleDataLayer(xpoMultiDataStoreProxy); var session = new Session(simpleDataLayer); _existentTypesMemberCreator.CreateMembers(session,typesInfo); } }
//public static T Execute<T>(string dataLayerName, Func<Session, T> work, bool transactional = true, bool commit = true) //{ //} #endregion private static IDataLayer createDataLayer(string connectionString, string datalayerName) { if (String.IsNullOrEmpty(connectionString)) { throw new ArgumentNullException("connectionString"); } // set XpoDefault.Session to null to prevent accidental use of XPO default session XpoDefault.Session = null; //ReflectionClassInfo.SuppressSuspiciousMemberInheritanceCheck = true; // Needed to run in Medium Trust Security Context XpoDefault.UseFastAccessors = false; XpoDefault.IdentityMapBehavior = IdentityMapBehavior.Strong; // autocreate option in connectionstring AutoCreateOption createOption = Conversion.GetConfigOption <AutoCreateOption>(connectionString, "AutoCreateOption", AutoCreateOption.DatabaseAndSchema); bool enableCachingNode = Conversion.GetConfigOption(connectionString, "EnableCachingNode", false); XPDictionary dataDictionary = new ReflectionDictionary(); IDataStore dataStore = XpoDefault.GetConnectionProvider(connectionString, createOption); // Initialize the XPO dictionary dataDictionary.GetDataStoreSchema(GetDataTypes(datalayerName)); // make sure everything exists in the db if (createOption == AutoCreateOption.DatabaseAndSchema) { using (SimpleDataLayer dataLayer = new SimpleDataLayer(dataStore)) { using (Session session = new Session(dataLayer)) { // place code here to patch metadata session.UpdateSchema(); session.CreateObjectTypeRecords(); XpoDefault.DataLayer = new ThreadSafeDataLayer(session.Dictionary, dataStore); } } } IDataLayer result; if (enableCachingNode) { result = new ThreadSafeDataLayer(dataDictionary, new DataCacheNode(new DataCacheRoot(dataStore))); } else { result = new ThreadSafeDataLayer(dataDictionary, dataStore); } return(result); }
private IDataLayer GetDataLayer() { XpoDefault.Session = null; string conn = ConnectionString; XPDictionary dict = new ReflectionDictionary(); IDataStore store; store = XpoDefault.GetConnectionProvider(conn, _AutoCreateOption); dict.GetDataStoreSchema(System.Reflection.Assembly.GetExecutingAssembly()); IDataLayer dl = new SimpleDataLayer(dict, store); XpoDefault.DataLayer = dl; //0.8 return(dl); }
public override void Init() { XpoDefault.DataLayer = null; XpoDefault.Session = null; var Args = new SchemaMismatchEventArgs(this, SchemaStatus.None); PrepareDictionary(); //Check if the schema requires update https://www.devexpress.com/Support/Center/Question/Details/Q245466/determining-if-schema-needs-to-be-updated if (XpoDefault.DataLayer == null) { try { using (var CheckSchemaDataLayer = new SimpleDataLayer(Dictionary, CreateSchemaCheckingDataStore())) { //HACK new way to compare schema https://www.devexpress.com/Support/Center/Question/Details/T562023/xpo-how-to-detect-of-chnage-structure-of-database-by-new-change-in-db-model var types = Dictionary.Classes.Cast <XPClassInfo>().Where(ci => ci.IsPersistent).ToArray(); var Result = CheckSchemaDataLayer.UpdateSchema(true, types); if (Result == UpdateSchemaResult.FirstTableNotExists) { OnSchemaMismatch(this, Args); } //HACK the old version of checking the schema https://www.devexpress.com/Support/Center/Question/Details/T189303/xpo-how-to-check-if-db-schema-needs-to-be-changed-without-changing-it //using (var session = new Session(CheckSchemaDataLayer)) //{ // session.UpdateSchema(); // //session.CreateObjectTypeRecords(); //} } Args.Handled = true; } catch (SchemaCorrectionNeededException) { OnSchemaMismatch(this, Args); } //catch (DevExpress.Xpo.DB.Exceptions.SchemaCorrectionNeededException) //{ // OnSchemaMismatch(this, Args); //} if (Args.Handled) { workingStore = XpoDefault.GetConnectionProvider(ConnectionString, AutoCreateOption.SchemaAlreadyExists); DataLayer = new ThreadSafeDataLayer(Dictionary, workingStore); } } }
protected void Init() { connection = new SqlConnection(connectionString); connectionProvider = new MSSqlConnectionProvider(connection, AutoCreateOption.None); IDataLayer dal = new SimpleDataLayer(connectionProvider); workSession = new Session(dal); string[] tablesList = connectionProvider.GetStorageTablesList(false); dynamicClasses = new Dictionary <string, DynamicDataTableClassInfo>(tablesList.Length); cmbTables.Properties.Items.AddRange(tablesList); cmbTables.SelectedIndexChanged += delegate(object sender, EventArgs args) { FillGrid(cmbTables.Text); }; }
private Session CreateSession() { IDataStore store = new InMemoryDataStore(); XPDictionary dictionary = new ReflectionDictionary(); new ReflectionClassInfo(typeof(BaseObject), dictionary); IDataLayer layer = new SimpleDataLayer(dictionary, store); Session session = new Session(layer); return(session); }
//Scenario Result Expected public void CreateDataStoreFromIDbConnection_DataIsConsistent_Pass() { SQLitePCL.Batteries_V2.Init(); EncriptedSQLiteConnectionProvider.Register(); if (File.Exists("CreateDataStoreFromIDbConnection.db")) { File.Delete("CreateDataStoreFromIDbConnection.db"); } var connection = new SqliteConnection("Data Source=CreateDataStoreFromIDbConnection.db"); System.IDisposable[] _discard; var DataStore = EncriptedSQLiteConnectionProvider.CreateProviderFromConnection(connection, DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema, "abc123"); IDataLayer dl = new SimpleDataLayer(DataStore); using (Session session = new Session(dl)) { System.Reflection.Assembly[] assemblies = new System.Reflection.Assembly[] { typeof(Customer).Assembly, }; session.UpdateSchema(assemblies); session.CreateObjectTypeRecords(assemblies); } UnitOfWork UoW = new UnitOfWork(dl); Customer Customer = new Customer(UoW); Customer.Name = "Jose Manuel Ojeda Melgar"; Customer.Address = "Saint Petersburg Russia"; Customer.Inactive = false; Customer.CreatedOn = new System.DateTime(2020, 5, 16); UoW.CommitChanges(); UnitOfWork unitOfWork = new UnitOfWork(dl); var Criteria = new DevExpress.Data.Filtering.BinaryOperator("Name", "Jose Manuel Ojeda Melgar"); var CustomerFromDatabase = unitOfWork.FindObject <Customer>(Criteria); Assert.AreEqual(CustomerFromDatabase.Name, Customer.Name); Assert.AreEqual(CustomerFromDatabase.Address, Customer.Address); Assert.AreEqual(CustomerFromDatabase.Inactive, Customer.Inactive); }
private UnitOfWork GetXmlUnitOfWork() { var reflectionDictionary = new ReflectionDictionary(); var appSetting = string.Format(ConfigurationManager.AppSettings["VideoRentLegacyPath"], AssemblyInfo.VersionShort); var fullPath = Environment.ExpandEnvironmentVariables(appSetting); var legacyAssembly = Assembly.LoadFrom(Path.Combine(fullPath + @"\bin", @"DevExpress.VideoRent.dll")); reflectionDictionary.CollectClassInfos(legacyAssembly); var inMemoryDataStore = new InMemoryDataStore(); inMemoryDataStore.ReadXml(Path.Combine(fullPath + @"\CS\DevExpress.VideoRent\Data", @"VideoRent.xml")); var simpleDataLayer = new SimpleDataLayer(reflectionDictionary, inMemoryDataStore); return(new UnitOfWork(simpleDataLayer)); }
public void DropLocalDables() { var dict = new ReflectionDictionary(); dict.CollectClassInfos(typeof(TemperatureValue).Assembly); using (var dl = new SimpleDataLayer(dict, localStore)) { using (var localUOW = new UnitOfWork(dl)) { var tables = ((ConnectionProviderSql)dl.ConnectionProvider).GetStorageTablesList(false); foreach (var tableName in tables) { localUOW.ExecuteScalar($"DROP TABLE {tableName};"); } localUOW.UpdateSchema(); } } }
static void Main(string[] args) { SafePostgreSqlConnectionProvider.Register(); SafePostgreSqlConnectionProvider dataStore = new SafePostgreSqlConnectionProvider( "user id=postgres;password=admin;server=donchakDBFarm;database=XpoUnitTests;port=5434", AutoCreateOption.DatabaseAndSchema ); IDataLayer dal = new SimpleDataLayer(dataStore); int id = CreateData(dal); Console.WriteLine("restart the database, and press any key to continue .."); Console.ReadKey(); new Session(dal).GetObjectByKey <Person>(id); ((IDisposable)dataStore).Dispose(); dal.Dispose(); Console.WriteLine("done\npress any key to exit .."); Console.ReadKey(); }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { ConfigureFilters(Uno.Extensions.LogExtensionPoint.AmbientLoggerFactory); this.InitializeComponent(); this.Suspending += OnSuspending; string connectionString = "XpoProvider = SQLite; Data Source = test.db"; var DataStore = XpoDefault.GetConnectionProvider(connectionString, DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema); var dictionary = new ReflectionDictionary(); dictionary.GetDataStoreSchema(typeof(Item).Assembly); SimpleDataLayer UpdateSchemaDal = new SimpleDataLayer(dictionary, DataStore); UnitOfWork UpdateSchemaUoW = new UnitOfWork(UpdateSchemaDal); UpdateSchemaUoW.UpdateSchema(); UpdateSchemaUoW.CreateObjectTypeRecords(); XpoDefault.DataLayer = new SimpleDataLayer(dictionary, DataStore); var uoW = new UnitOfWork(XpoDefault.DataLayer); if ((int)uoW.Evaluate(typeof(Item), CriteriaOperator.Parse("Count()"), CriteriaOperator.Parse("Active = true")) == 0) { Item item1 = new Item(uoW); item1.Name = "Item One"; item1.Description = "My first Xpo Object in Xamarin"; item1.Active = true; Item item2 = new Item(uoW); item2.Name = "Item Two"; item2.Description = "My second Xpo Object in Xamarin"; item2.Active = true; Item item3 = new Item(uoW); item3.Name = "Item Three"; item3.Description = "My third Xpo Object in Xamarin"; item3.Active = true; if (uoW.InTransaction) { uoW.CommitChanges(); } } }
private Session CreateSession(IDataStore dataStore, IDisposable[] disposableObjects) { var disposableObjectsList = new List<IDisposable>(); if (disposableObjects != null) { disposableObjectsList.AddRange(disposableObjects); } var dataLayer = new SimpleDataLayer(XPDictionary, dataStore); disposableObjectsList.Add(dataLayer); return new Session(dataLayer, disposableObjectsList.ToArray()); }
public void CreateObjectTypeIndetifier(InsertStatement insertStatement, SimpleDataLayer simpleDataLayer) { var identityValue = FindIdentityValue(insertStatement.Parameters, simpleDataLayer); CreateObjectTypeIndetifier(insertStatement, simpleDataLayer, identityValue); }
/// <summary> /// Initializes the proxy. /// </summary> /// <param name="dictionary">The dictionary.</param> /// <param name="appConnectionString">The app connection string.</param> /// <param name="secondStorageConnectionString">The replication storage connection string.</param> /// <param name="secondStorageClasses">The second storage classes.</param> public void Initialize(XPDictionary dictionary, string appConnectionString, string secondStorageConnectionString, IEnumerable<XPClassInfo> secondStorageClasses) { var appDictionary = new ReflectionDictionary(); secondStorageDictionary = new ReflectionDictionary(); secondStorageClasses.ToList().ForEach(x => secondStorageTableNames.Add(x.TableName)); foreach(XPClassInfo ci in dictionary.Classes) { if (secondStorageTableNames.Contains(ci.TableName)) secondStorageDictionary.QueryClassInfo(ci.ClassType); appDictionary.QueryClassInfo(ci.ClassType); } appDataStore = XpoDefault.GetConnectionProvider(appConnectionString, AutoCreateOption.DatabaseAndSchema); appDataLayer = new SimpleDataLayer(appDictionary, appDataStore); secondStorageConnStr = secondStorageConnectionString; }
public void InitializeTest() { dataLayer = null; InitializeTestCore(); }
/// <summary> /// Opens the second storage. /// </summary> private void openSecondStorage() { if (!string.IsNullOrEmpty(secondStorageConnStr) && (secondStorageDataStore == null || secondStorageDataStore == appDataStore)) { try { secondStorageDataStore = XpoDefault.GetConnectionProvider(secondStorageConnStr, AutoCreateOption.DatabaseAndSchema); secondStorageDataLayer = new SimpleDataLayer(secondStorageDictionary, secondStorageDataStore); } catch (Exception exception) { var args = new GetPlatformArgs(); XafDeltaModule.Instance.OnGetPlatform(args); if(args.XafDeltaPlatform != null) args.XafDeltaPlatform.OnShowError(new ErrorEventArgs(exception)); secondStorageDataStore = appDataStore; secondStorageDataLayer = appDataLayer; } foreach (var packageUpdate in delayedPackageUpdates) secondStorageDataStore.UpdateSchema(false, packageUpdate.ToArray()); delayedPackageUpdates.Clear(); } return; }
private UnitOfWork GetXmlUnitOfWork() { var reflectionDictionary = new ReflectionDictionary(); var appSetting = string.Format(ConfigurationManager.AppSettings["VideoRentLegacyPath"], AssemblyInfo.VersionShort); var fullPath = Environment.ExpandEnvironmentVariables(appSetting); var legacyAssembly = Assembly.LoadFrom(Path.Combine(fullPath + @"\bin", @"DevExpress.VideoRent.dll")); reflectionDictionary.CollectClassInfos(legacyAssembly); var inMemoryDataStore = new InMemoryDataStore(); inMemoryDataStore.ReadXml(Path.Combine(fullPath + @"\CS\DevExpress.VideoRent\Data", @"VideoRent.xml")); var simpleDataLayer = new SimpleDataLayer(reflectionDictionary, inMemoryDataStore); return new UnitOfWork(simpleDataLayer); }
protected override BusinessClassesList GetBusinessClassesCore() { var existentTypesMemberCreator = new ExistentTypesMemberCreator(); if (ConnectionString != null) { var xpoMultiDataStoreProxy = new SqlMultiDataStoreProxy(ConnectionString, GetReflectionDictionary()); var simpleDataLayer = new SimpleDataLayer(xpoMultiDataStoreProxy); var session = new Session(simpleDataLayer); existentTypesMemberCreator.CreateMembers(session); } return base.GetBusinessClassesCore(); }
/// <summary> /// Creates the unit of work for package data. /// </summary> /// <returns>Unit of work</returns> private UnitOfWork createUnitOfWork() { tempFileName = Path.GetTempFileName(); if (PackageData != null) File.WriteAllBytes(tempFileName, PackageData); else if (File.Exists(tempFileName)) File.Delete(tempFileName); var connStr = AccessConnectionProvider.GetConnectionString(tempFileName); // create unit of work based on temporary ms access database IDisposable[] disposables; var dataStore = XpoDefault.GetConnectionProvider(connStr, AutoCreateOption.DatabaseAndSchema, out disposables); var dataLayer = new SimpleDataLayer(XafTypesInfo.XpoTypeInfoSource.XPDictionary, dataStore); var result = new UnitOfWork(dataLayer, disposables); string errorText; if(!verifyMarker(result, out errorText)) { result.RollbackTransaction(); result.Dispose(); throw new InvalidPackageDataException(errorText); } // mark object changed if (PackageData == null) OnChanged(); return result; }