Exemplo n.º 1
0
        private static void ConnectToDatabase()
        {
            // generazione sequenziale dei GUID
            XpoDefault.GuidGenerationMode = GuidGenerationMode.UuidCreateSequential;

            string conn = string.Empty;

            if (StaticInfo.NoSync())
            {
                string[] info = StaticInfo.NoSyncInfo();
                conn = MSSqlConnectionProvider.GetConnectionString(info[0], info[1], info[2], info[3]);
            }
            else
            {
                conn = MSSqlConnectionProvider.GetConnectionString("(local)\\SQLEXPRESS", "MuseiXafRev1locale");
            }

            if (StaticInfo.UpdateSchema())
            {
                // update schema:
                try
                {
                    IDataLayer dl = XpoDefault.GetDataLayer(conn, DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema);
                    using (Session session = new Session(dl))
                    {
                        System.Reflection.Assembly[] assemblies = new System.Reflection.Assembly[] {
                            typeof(Ingresso).Assembly
                        };

                        session.UpdateSchema(assemblies);
                        session.CreateObjectTypeRecords(assemblies);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Unable to update database schema: {0}", ex.Message));
                }
            }

            IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.None);

            if (conn.EndsWith(".asmx"))
            {
                store = new DevExpress.Xpo.DB.DataCacheNode(new DevExpress.Xpo.DB.DataCacheRoot(store));
            }

            XpoDefault.DataLayer = new SimpleDataLayer(store);

            XpoDefault.Session = null;
        }
Exemplo n.º 2
0
        public static void SetThreadSafeDataLayer(out ThreadSafeDataLayer Tsdl, string conn)
        {
            // Code that runs on application startup
            DevExpress.Xpo.Metadata.XPDictionary dict =
                new DevExpress.Xpo.Metadata.ReflectionDictionary();
            dict.GetDataStoreSchema(typeof(NewNetServicesModule).Assembly);
            DevExpress.Xpo.DB.IDataStore store =
                DevExpress.Xpo.XpoDefault
                .GetConnectionProvider(conn,
                                       DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists);
            store = new DevExpress.Xpo.DB.DataCacheNode(new DevExpress.Xpo.DB.DataCacheRoot(store));
            var layer = new DevExpress.Xpo.ThreadSafeDataLayer(dict, store);

            Tsdl = layer;
        }