Exemplo n.º 1
0
        /// <summary>
        /// 创建 XPO 的 ThreadSafeDataLayer
        /// </summary>
        /// <param name="assemblies"></param>
        /// <returns></returns>
        static IDataLayer GetDataLayer(params Assembly[] assemblies)
        {
            ReflectionDictionary dict = new ReflectionDictionary();

            dict.CollectClassInfos(assemblies);

            IDataLayer dataLayer;

            int maxConnections = GetMaxConnections();

            if (maxConnections > 1)
            {
                IDataStore[] stores = new IDataStore[maxConnections];
                for (int i = 0; i < maxConnections; i++)
                {
                    stores[i] = GetDataStore();
                }
                dataLayer = new ThreadSafeDataLayer(dict, new DataStoreFork(stores));
            }
            else
            {
                dataLayer = new ThreadSafeDataLayer(dict, GetDataStore());
            }

            return(dataLayer);
        }
Exemplo n.º 2
0
    private static IDataLayer GetDataLayer()
    {
        // set XpoDefault.Session to null to prevent accidental use of XPO default session
        XpoDefault.Session = null;

        string       conn = MSSqlConnectionProvider.GetConnectionString("(local)", "XpoWebTest");
        XPDictionary dict = new ReflectionDictionary();

        /* Note: The database schema must exactly match your persistent classes' definition. ASP.NET applications
         * should not update the database schema themselves; moreover, they often don't have enough permission
         * to read the database schema.  You may need to create a separate tool which manages your database.
         * On the one hand, we recommend using AutoCreateOption.SchemaAlreadyExists for the XPO data layer of your
         * Web site.  On the other hand, the ThreadSafeDataLayer intensively uses data which is stored in the XPO's
         * XPObjectType service table.  This sample project maps to the XpoWebTest database on your MS SQL Server.
         * This database is created via the DatabaseUpdater project, which must be launched before this Site is
         * published. */

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

        // initialize the XPO dictionary
        dict.GetDataStoreSchema(typeof(PersistentObjects.Customer).Assembly);

        // create a ThreadSafeDataLayer
        IDataLayer dl = new ThreadSafeDataLayer(dict, store);

        return(dl);
    }
Exemplo n.º 3
0
        private IDataLayer ConfigureConnection(params Type[] types)
        {
            XpoDefault.Session = null;
            var          store      = XpoDefault.GetConnectionProvider(_settings.ConnectionString, _settings.CreateOption, out var objectsToRelase);
            XPDictionary dictionary = new ReflectionDictionary();

            if (types != null)
            {
                dictionary.GetDataStoreSchema(types);
            }

            IDataLayer dataLayer = new ThreadSafeDataLayer(dictionary, store);

            // DATABASE MIGRATION CODE
            if (_settings.CreateOption == AutoCreateOption.SchemaOnly &&
                types != null)
            {
                // Prepare database structure
                using (DevExpress.Xpo.UnitOfWork session = new DevExpress.Xpo.UnitOfWork(dataLayer))
                {
                    session.UpdateSchema(types);
                    session.CreateObjectTypeRecords(types);
                }
            }

            return(dataLayer);
        }
Exemplo n.º 4
0
 protected override ISecuredSerializableObjectLayer CreateDefaultSecuredSerializableObjectLayer(IDataLayer dataLayer,
     RequestSecurityStrategyProvider securityStrategyProvider, EventHandler<DataServiceOperationEventArgs> committingDelegate,
     bool allowICommandChannelDoWithSecurityContext) {
     string connectionString = ((ConnectionProviderSql)((BaseDataLayer)dataLayer).ConnectionProvider).ConnectionString;
     var threadSafeDataLayer = new ThreadSafeDataLayer(dataLayer.Dictionary, new MultiDataStoreProxy(connectionString));
     return new SecuredSerializableObjectLayer(threadSafeDataLayer, securityStrategyProvider, allowICommandChannelDoWithSecurityContext);
 }
Exemplo n.º 5
0
 private void EnsureNorthwindDataLayer()
 {
     if (northwindDataLayer == null)
     {
         northwindDataStore = XpoDefault.GetConnectionProvider(northwindConnectionString, AutoCreateOption.DatabaseAndSchema);
         northwindDataLayer = new ThreadSafeDataLayer(northwindDictionary, northwindDataStore);
     }
 }
Exemplo n.º 6
0
        static IDataLayer GetThreadSafeDataLayer(SqlConnection conn)
        {
            IDataStore   dataStore = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.DatabaseAndSchema);
            XPDictionary dict      = new ReflectionDictionary();

            IDataLayer dataLayer = new ThreadSafeDataLayer(dict, dataStore);

            return(dataLayer);
        }
Exemplo n.º 7
0
        protected override ISecuredSerializableObjectLayer CreateDefaultSecuredSerializableObjectLayer(IDataLayer dataLayer,
                                                                                                       RequestSecurityStrategyProvider securityStrategyProvider, EventHandler <DataServiceOperationEventArgs> committingDelegate,
                                                                                                       bool allowICommandChannelDoWithSecurityContext)
        {
            string connectionString    = ((ConnectionProviderSql)((BaseDataLayer)dataLayer).ConnectionProvider).ConnectionString;
            var    threadSafeDataLayer = new ThreadSafeDataLayer(dataLayer.Dictionary, new MultiDataStoreProxy(connectionString));

            return(new SecuredSerializableObjectLayer(threadSafeDataLayer, securityStrategyProvider, allowICommandChannelDoWithSecurityContext));
        }
 static IDataLayer CreateDataLayer()
 {
     DevExpress.Xpo.Metadata.XPDictionary dict = new DevExpress.Xpo.Metadata.ReflectionDictionary();
     dict.GetDataStoreSchema(typeof(AnungooODataServiceService).Assembly);
     IDataLayer dataLayer = new ThreadSafeDataLayer(dict, global::AnungooODataService.Anungoo.ConnectionHelper.GetConnectionProvider(DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists));
     XpoDefault.DataLayer = dataLayer;
     XpoDefault.Session = null;
     return dataLayer;
 }
Exemplo n.º 9
0
        private static IDataLayer CreateDataLayer()
        {
            DevExpress.Xpo.Metadata.XPDictionary dict = new DevExpress.Xpo.Metadata.ReflectionDictionary();
            dict.GetDataStoreSchema(typeof(ODataService4Service).Assembly);
            IDataLayer dataLayer = new ThreadSafeDataLayer(dict, global::ODataService4.WebDemo1.ConnectionHelper.GetConnectionProvider(DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists));

            XpoDefault.DataLayer = dataLayer;
            XpoDefault.Session   = null;
            return(dataLayer);
        }
Exemplo n.º 10
0
    static IDataLayer CreateDataLayer()
    {
        XpoDefault.Session = null;
        XPDictionary dict  = new ReflectionDictionary();
        IDataStore   store = XpoDefault.GetConnectionProvider(GetConnectionString(), AutoCreateOption.SchemaAlreadyExists);

        dict.GetDataStoreSchema(typeof(XpoEmailEntity), typeof(XpoPersonEntity));
        IDataLayer dl = new ThreadSafeDataLayer(dict, store);

        return(dl);
    }
Exemplo n.º 11
0
        private static IDataLayer GetDataLayer()
        {
            XpoDefault.Session = null;
            string       conn  = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            XPDictionary dict  = new ReflectionDictionary();
            IDataStore   store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.DatabaseAndSchema);

            IDataLayer dl = new ThreadSafeDataLayer(dict, store);

            return(dl);
        }
Exemplo n.º 12
0
        private static IDataLayer GetDataLayer()
        {
            XpoDefault.Session = null;
            string       conn  = Conexion.ObternerConexion();
            XPDictionary dict  = new ReflectionDictionary();
            IDataStore   store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.DatabaseAndSchema);

            dict.GetDataStoreSchema(typeof(HistorialDeLogueo).Assembly);
            IDataLayer dl = new ThreadSafeDataLayer(dict, store);

            return(dl);
        }
    private static IDataLayer GetDataLayer()
    {
        XpoDefault.Session = null;

        string       conn  = AccessConnectionProvider.GetConnectionString(@"|DataDirectory|\db.mdb");
        XPDictionary dict  = new DevExpress.Xpo.Metadata.ReflectionDictionary();
        IDataStore   store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists);

        dict.GetDataStoreSchema(typeof(Order).Assembly);  // <<< initialize the XPO dictionary
        IDataLayer dl = new ThreadSafeDataLayer(dict, store);

        return(dl);
    }
    private static IDataLayer GetDataLayer()
    {
        XpoDefault.Session = null;

        string       conn  = MSSqlConnectionProvider.GetConnectionString("(local)", "Northwind");
        XPDictionary dict  = new ReflectionDictionary();
        IDataStore   store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists);

        dict.GetDataStoreSchema(typeof(Northwind.Customer).Assembly);

        IDataLayer dl = new ThreadSafeDataLayer(dict, store);

        return(dl);
    }
        private IDataLayer GetDataLayerMultiThread()
        {
            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 ThreadSafeDataLayer(dict, store);

            XpoDefault.DataLayer = dl; //0.8
            return(dl);
        }
Exemplo n.º 16
0
        public static ThreadSafeDataLayer CreatePooledDataLayer(string connectionString)
        {
            var dictionary = PrepareDictionary();

            using (var updateDataLayer = XpoDefault.GetDataLayer(connectionString, dictionary, AutoCreateOption.DatabaseAndSchema)) {
                updateDataLayer.UpdateSchema(false, dictionary.CollectClassInfos(entityTypes));
            }

            string pooledConnectionString = XpoDefault.GetConnectionPoolString(connectionString);
            var    dataStore = XpoDefault.GetConnectionProvider(pooledConnectionString, AutoCreateOption.SchemaAlreadyExists);
            var    dataLayer = new ThreadSafeDataLayer(dictionary, dataStore);;

            return(dataLayer);
        }
Exemplo n.º 17
0
        private static IDataLayer GetDataLayer()
        {
            //XpoDefault.Session = null;
            string conn = ConfigurationManager.ConnectionStrings["ETTPotocnik"].ConnectionString;

            conn = XpoDefault.GetConnectionPoolString(conn);
            XPDictionary dict  = new ReflectionDictionary();
            IDataStore   store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists);

            dict.GetDataStoreSchema(System.Reflection.Assembly.GetExecutingAssembly());
            IDataLayer dl = new ThreadSafeDataLayer(dict, store);

            return(dl);
        }
Exemplo n.º 18
0
        //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);
        }
Exemplo n.º 19
0
    private static IDataLayer GetDataLayer()
    {
        // set XpoDefault.Session to null to prevent accidental use of XPO default session
        XpoDefault.Session = null;

        string       conn  = MSSqlConnectionProvider.GetConnectionString("(local)", "AdventureWorks");
        XPDictionary dict  = new ReflectionDictionary();
        IDataStore   store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists);

        dict.GetDataStoreSchema(typeof(AdventureWorks.Customer).Assembly);
        IDataLayer dl = new ThreadSafeDataLayer(dict, store);

        return(dl);
    }
Exemplo n.º 20
0
    public static IDataLayer GetDataLayer(string connectionStringName)
    {
        ConnectionStringName = connectionStringName;
        XpoDefault.Session   = null;
        string conn = ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString;

        conn = XpoDefault.GetConnectionPoolString(conn);
        XPDictionary dict  = new ReflectionDictionary();
        IDataStore   store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.DatabaseAndSchema);

        dict.GetDataStoreSchema(System.Reflection.Assembly.GetExecutingAssembly());
        IDataLayer dl = new ThreadSafeDataLayer(dict, store);

        return(dl);
    }
Exemplo n.º 21
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;
        }
Exemplo n.º 22
0
        private static IDataLayer GetDataLayerINTF()
        {
            // set XpoDefault.Session to null to prevent accidental use of XPO default session
            XpoDefault.Session             = null;
            XpoDefault.UseFastAccessors    = false;
            XpoDefault.IdentityMapBehavior = IdentityMapBehavior.Strong;

            XPDictionary dict  = new ReflectionDictionary();
            IDataStore   store = XpoDefault.GetConnectionProvider(GetConnectionString(ConnectionString), AutoCreateOption.SchemaAlreadyExists);

            dict.GetDataStoreSchema(typeof(CardApprovalEntity).Assembly);
            IDataLayer dl = new ThreadSafeDataLayer(dict, store);

            return(dl);
        }
 private static IDataLayer GetDataLayer()
 {
     try
     {
         XpoDefault.Session = null;
         String       conn  = ConfigurationManager.ConnectionStrings["AuditConnectionString"].ConnectionString;
         XPDictionary dict  = new ReflectionDictionary();
         IDataStore   store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.DatabaseAndSchema);
         dict.GetDataStoreSchema(typeof(Calls).Assembly);
         IDataLayer dl = new ThreadSafeDataLayer(dict, store);
         return(dl);
     }
     catch (Exception)
     {
         throw;
     }
 }
 private static IDataLayer GetDataLayer()
 {
     try
     {
         XpoDefault.Session = null;
         String conn = ConfigurationManager.ConnectionStrings["AuditConnectionString"].ConnectionString;
         XPDictionary dict = new ReflectionDictionary();
         IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.DatabaseAndSchema);
         dict.GetDataStoreSchema(typeof(Calls).Assembly);
         IDataLayer dl = new ThreadSafeDataLayer(dict, store);
         return dl;
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 25
0
    public static IDataLayer GetDataLayer()
    {
        XpoDefault.Session = null;
        //string conn = MySqlConnectionProvider.GetConnectionString("localhost", "root", "", "CUFE");
        string       conn  = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
        XPDictionary dict  = new ReflectionDictionary();
        IDataStore   store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.DatabaseAndSchema);

        DevExpress.Xpo.Metadata.ReflectionClassInfo.SuppressSuspiciousMemberInheritanceCheck = true;
        //dict.GetDataStoreSchema(typeof(Inscripcion).Assembly);
        IDataLayer dl = new ThreadSafeDataLayer(dict, store);

        //XpoDefault.DataLayer = XpoDefault.GetDataLayer(conn, AutoCreateOption.DatabaseAndSchema);
        //using (UnitOfWork uow = new UnitOfWork(dl))
        //{
        //    int cnt = (int)uow.Evaluate<CUFE.Models.XpoApplicationRole>(CriteriaOperator.Parse("count"), null);
        //    if (cnt == 0)
        //    {
        //        new XpoApplicationRole(uow)
        //        {
        //            Name = "SuperAdmin"
        //        };
        //        new XpoApplicationRole(uow)
        //        {
        //            Name = "Admin"
        //        };
        //        new XpoApplicationRole(uow)
        //        {
        //            Name = "User"
        //        };
        //        uow.CommitChanges();
        //    }
        //    cnt = (int)uow.Evaluate<CUFE.Models.XpoApplicationUser>(CriteriaOperator.Parse("count"), null);
        //    if (cnt == 0)
        //    {
        //        var user = new XpoApplicationUser(uow)
        //        {
        //            Email = "*****@*****.**",
        //            EmailConfirmed = true
        //        };
        //        uow.CommitChanges();
        //    }
        //}
        return(dl);
    }
Exemplo n.º 26
0
        private static IDataLayer GetDataLayer()
        {
            XpoDefault.Session = null;

            AppSettingsReader config = new AppSettingsReader();

            string conn = (string)(config.GetValue("ConectionString", typeof(string)));

            XPDictionary dict = new ReflectionDictionary();

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

            dict.GetDataStoreSchema(typeof(ContinenteXPO).Assembly);

            IDataLayer dl = new ThreadSafeDataLayer(dict, store);

            return dl;
        }
        static IDataLayer CreateDataLayer()
        {
            DevExpress.Xpo.Metadata.XPDictionary dict = new DevExpress.Xpo.Metadata.ReflectionDictionary();
            // Initialize the XPO dictionary.
            dict.GetDataStoreSchema(typeof(Orders).Assembly);
            InMemoryDataStore store      = new InMemoryDataStore(AutoCreateOption.SchemaOnly);
            string            DBFileName = DevExpress.Utils.FilesHelper.FindingFileName(HttpRuntime.AppDomainAppPath, "App_Data\\nwind.xml");

            if (DBFileName != "")
            {
                store.ReadXml(DBFileName);
            }
            IDataLayer dataLayer = new ThreadSafeDataLayer(dict, store);

            XpoDefault.DataLayer = dataLayer;
            XpoDefault.Session   = null;
            return(dataLayer);
        }
Exemplo n.º 28
0
        private static 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(conn, AutoCreateOption.DatabaseAndSchema);


            //dict.GetDataStoreSchema(typeof(GIS_ERP_Basis.Module.BusinessObjects.AppSystem.GISLIC).Assembly);
            //dict.GetDataStoreSchema(typeof(GIS_ERP_Basis.Module.BusinessObjects.AppSystem.GISLIC_Modules).Assembly);


            IDataLayer dl = new ThreadSafeDataLayer(dict, store);

            return(dl);
        }
Exemplo n.º 29
0
        private void btnConvert_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                tbOracleConnectionStringText = TbOracleConnectionString.Text;
                TbCmsConnectionStringText    = TbCmsConnectionString.Text;
                string conn = TbCmsConnectionStringText;
                //get thread safe klayer
                if (conn != null)
                {
                    // 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;
                }
                if (Tsdl == null)
                {
                    //DevExpress.XtraEditors.XtraMessageBox.Show($"Couldn't create dl");
                    return;
                }
                //   MAINWorker.Connect(tsdl);
            }
            catch (Exception ex)
            {
                NewNetServices.Module.Core.StaticHelperMethods.WriteOut($"{ex}");
            }

            BtnConvert.IsEnabled = false;
            Task.Factory
            .StartNew(() =>
            {
                Task.WhenAll(BeginWork());
                Dispatcher.Invoke(() => BtnConvert.IsEnabled = true);
            });
        }
Exemplo n.º 30
0
        public static Session GetSessionThreadSafeDataLayer(string connectionString = null)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                var fullPathDataBase = Path.GetFullPath(StringSQLiteConnection);
                connectionString = SQLiteConnectionProvider.GetConnectionString(fullPathDataBase);
            }

            var xpoTypeInfoSource  = XpoTypesInfoHelper.GetXpoTypeInfoSource().XPDictionary;
            var connectionProvider = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.DatabaseAndSchema);

            var dl      = new ThreadSafeDataLayer(xpoTypeInfoSource, connectionProvider);
            var session = new Session(dl, null)
            {
                LockingOption = LockingOption.None,
                TrackPropertiesModifications = true
            };

            return(session);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Инициализация подключения
        /// </summary>
        public void Init()
        {
            lock (_lockObject) {
                if (Initialized)
                {
                    return;
                }

                var dataStore  = XpoDefault.GetConnectionProvider(ConnectionString, AutoCreateOption);
                var dictionary = new ReflectionDictionary();
                var dataLayer  = new ThreadSafeDataLayer(dictionary, dataStore, Assemblies);

                XpoDefault.Dictionary = dataLayer.Dictionary;
                XpoDefault.DataLayer  = dataLayer;
                XpoDefault.DataLayer.UpdateSchema(false);
                XpoDefault.Session = new UnitOfWork(dataLayer);

                Initialized = true;
            }
        }
Exemplo n.º 32
0
        void CreateDataLayer()
        {
            TbCmsConnectionStringText = TbCmsConnectionString.Text;
            string conn = TbCmsConnectionStringText;

            //get thread safe klayer
            if (conn != null)
            {
                // 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;
            }
        }
        static void Main(string[] args)
        {
            XPDictionary dictionary = new ReflectionDictionary();
            dictionary.GetDataStoreSchema(typeof(Person).Assembly);

            Console.WriteLine("Opening service host...");

            ThreadSafeDataLayer dataLayer = new ThreadSafeDataLayer(dictionary, XpoDefault.GetConnectionProvider(Constants.DatabaseConnectionString, AutoCreateOption.SchemaAlreadyExists));
            SerializableObjectLayer objectlayer = new SerializableObjectLayer(new UnitOfWork(new SimpleObjectLayer(dataLayer)));
            ServiceHost host = new ServiceHost(new SerializableObjectLayerSingletonService(objectlayer));
            host.AddServiceEndpoint(typeof(ISerializableObjectLayerService), new BasicHttpBinding(), Constants.WCF_Server_Uri);
            host.Open();

            Console.WriteLine("Service host is opened.");
            Console.WriteLine("Press Enter to close");
            Console.ReadLine();

            Console.WriteLine("Closing service host...");
            host.Close();
            Console.WriteLine("Service host is closed.");
        }
Exemplo n.º 34
0
    public static IDataLayer GetDataLayer()
    {
        XpoDefault.Session = null;
        //string conn = MySqlConnectionProvider.GetConnectionString("localhost", "root", "", "CUFE");
        string       conn  = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
        XPDictionary dict  = new ReflectionDictionary();
        IDataStore   store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.DatabaseAndSchema);
        //DevExpress.Xpo.Metadata.ReflectionClassInfo.SuppressSuspiciousMemberInheritanceCheck = true;
        //dict.GetDataStoreSchema(typeof(Inscripcion).Assembly);
        IDataLayer dl = new ThreadSafeDataLayer(dict, store);

        //using (UnitOfWork uow = new UnitOfWork(dl))
        //{
        //    int cnt = (int)uow.Evaluate<CUFE.Models.Country>(CriteriaOperator.Parse("count"), null);
        //    if (cnt == 0)
        //    {
        //        new CUFE.Models.Country(uow) { CountryName = "Germany" };
        //        uow.CommitChanges();
        //    }
        //}
        return(dl);
    }
Exemplo n.º 35
0
        private static IDataLayer GetDataLayer()
        {
            //Utility.LogWriter.Instance.WriteToLog("---START: DAL.Purchasing.GetDataLayer()---");
            try
            {
                XpoDefault.Session = null;
                //string conn = DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("192.168.1.150", "ERPCORE_LocalSite");
                //string conn = DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("192.168.1.150", "ERPCORETai");
                //string conn = DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("192.168.1.150", "ERPCORE_TESTGiaodien");
                //string conn = ConnectionHelper.ConnectionString;
                //string conn = DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("192.168.1.22", "ngoclinhadmin", "Na12345678", "ngoclinhdb");
                //Utility.LogWriter.Instance.WriteToLog("Get active database congfiguration...");
                DbConfig dbConfig = new DbConfig();
                string   conn     = DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("192.168.1.133", "sa", "123456", "ERPCore");//"XpoProvider=MSSqlServer;data source=192.168.1.133;integrated security=SSPI;initial catalog=ERPCore"; //dbConfig.getActiveDbConfig().ConnectionString;//"XpoProvider=MSSqlServer;data source=192.168.1.133;integrated security=SSPI;initial catalog=ERPCORE";//
                //Utility.LogWriter.Instance.WriteToLog("Connection string: " + conn);

                XPDictionary dict = new ReflectionDictionary();
                //IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.DatabaseAndSchema);
                IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.DatabaseAndSchema);

                dict.GetDataStoreSchema(
                    typeof(InventoryCommandDim).Assembly,
                    typeof(CorrespondFinancialAccountDim).Assembly,
                    typeof(FinancialSupplierLiabilityDetail).Assembly,
                    typeof(FinancialCustomerLiabilityDetail).Assembly,
                    typeof(FinancialOnTheWayBuyingGoodDetail).Assembly,
                    typeof(DiaryJournal_Detail).Assembly,
                    typeof(FinancialPrepaidExpenseSummary_Fact).Assembly,
                    typeof(FinancialPrepaidExpenseDetail).Assembly,

                    //NAS.DAL.Accounting.Currency
                    typeof(Currency).Assembly,
                    typeof(CurrencyType).Assembly,

                    //NAS.DAL.AccountingPeriod
                    typeof(AccountingPeriodType).Assembly,

                    ////NAS.DAL.System.Resource
                    typeof(App).Assembly,
                    typeof(AppComponent).Assembly,
                    typeof(AppComponentContent).Assembly,
                    typeof(AppComponentContentType).Assembly,
                    typeof(AppComponentData).Assembly,
                    typeof(AppComponentOperation).Assembly,
                    typeof(AppOperation).Assembly,

                    ////NAS.DAL.System.Privilege
                    typeof(PrivilegeDepartment).Assembly,
                    typeof(SpecialPrivilege).Assembly,

                    ////NAS.DAL.CMS.ObjectDocument
                    typeof(CustomField).Assembly,
                    typeof(CustomFieldData).Assembly,
                    typeof(CustomFieldDataDateTime).Assembly,
                    typeof(CustomFieldDataFloat).Assembly,
                    typeof(CustomFieldDataImage).Assembly,
                    typeof(CustomFieldDataInt).Assembly,
                    typeof(CustomFieldDataPeriod).Assembly,
                    typeof(CustomFieldDataRichText).Assembly,
                    typeof(CustomFieldDataString).Assembly,
                    typeof(CustomFieldType).Assembly,
                    typeof(NAS.DAL.CMS.ObjectDocument.Object).Assembly,
                    typeof(ObjectCustomField).Assembly,
                    typeof(ObjectCustomFieldData).Assembly,
                    typeof(ObjectType).Assembly,
                    typeof(ObjectTypeCustomField).Assembly,

                    ////NAS.DAL.Inventory.Item
                    typeof(InventoryItem).Assembly,
                    typeof(RecordedType).Assembly,

                    ////NAS.DAL.Inventory.Operation
                    typeof(CommanderStockCart).Assembly,
                    typeof(CommanderStockCartItem).Assembly,
                    typeof(CommanderStockCartStatus).Assembly,
                    typeof(CommanderStockCartType).Assembly,
                    typeof(MovingStockCart).Assembly,
                    typeof(PickingStockCart).Assembly,
                    typeof(PuttingStockCart).Assembly,

                    ////NAS.DAL.Inventory.StockCart
                    typeof(StockCartActor).Assembly,
                    typeof(StockCartActorType).Assembly,
                    typeof(StockCart).Assembly,
                    typeof(StockCartItem).Assembly,
                    ////NAS.DAL.Inventory.Ledger
                    typeof(InventoryLedger).Assembly,
                    typeof(InventoryJournalBalanceForward).Assembly,
                    typeof(InventoryTransactionBalanceForward).Assembly,
                    ////NAS.DAL.Invoice
                    typeof(BillActor).Assembly,
                    typeof(Bill).Assembly,
                    typeof(BillItem).Assembly,
                    typeof(BillPromotion).Assembly,
                    typeof(BillTax).Assembly,
                    typeof(BillType).Assembly,
                    typeof(PromotionType).Assembly,
                    typeof(SaleInvoiceArtiface).Assembly,
                    typeof(PurchaseInvoice).Assembly,
                    typeof(SalesInvoice).Assembly,
                    typeof(TaxType).Assembly,

                    ////NAS.DAL.Sales.PickingStockCart
                    typeof(SalesInvoicePickingStockCart).Assembly,

                    ////NAS.DAL.Buy.StockCart
                    typeof(PurchaseInvoicePuttingStockCart).Assembly,

                    ////NAS.DAL.Nomenclature.Inventory
                    typeof(NAS.DAL.Nomenclature.Inventory.Inventory).Assembly,
                    typeof(NAS.DAL.Nomenclature.Inventory.InventoryUnit).Assembly,

                    ////NAS.DAL.Nomenclature.Item
                    typeof(Item).Assembly,
                    typeof(ItemCustomType).Assembly,
                    typeof(ItemObject).Assembly,
                    typeof(ItemSupplier).Assembly,
                    typeof(ItemTradingType).Assembly,
                    typeof(ItemUnit).Assembly,
                    typeof(ItemUnitRelationType).Assembly,
                    typeof(Unit).Assembly,

                    ////NAS.DAL.Nomenclature.Organization
                    typeof(AuthenticationProvider).Assembly,
                    typeof(Department).Assembly,
                    typeof(DepartmentPerson).Assembly,
                    typeof(DepartmentType).Assembly,
                    typeof(LoginAccount).Assembly,
                    typeof(ManufacturerOrg).Assembly,
                    typeof(Organization).Assembly,
                    typeof(OrganizationType).Assembly,
                    typeof(OwnerOrg).Assembly,
                    typeof(Person).Assembly,
                    typeof(ServiceOrg).Assembly,
                    typeof(SupplierOrg).Assembly,
                    typeof(TradingOrg).Assembly,


                    ////NAS.DAL.Nomenclature.Bank
                    typeof(NAS.DAL.Nomenclature.Bank.Bank).Assembly,
                    typeof(NAS.DAL.Nomenclature.Bank.BankBranch).Assembly,

                    ////NAS.DAL.Vouches
                    typeof(NAS.DAL.Vouches.Vouches).Assembly,
                    typeof(VouchesType).Assembly,
                    typeof(VouchesActor).Assembly,
                    typeof(VouchesActorType).Assembly,
                    typeof(VouchesAmount).Assembly,
                    typeof(PaymentVouches).Assembly,
                    typeof(PaymentVouchesType).Assembly,
                    typeof(ReceiptVouches).Assembly,
                    typeof(ReceiptVouchesType).Assembly,
                    typeof(ForeignCurrency).Assembly,
                    typeof(ExchangeRate).Assembly,

                    //Price
                    typeof(PricePolicyType).Assembly,
                    typeof(PricePolicy).Assembly,
                    typeof(PricePolicyCondition).Assembly,
                    typeof(PricePolicyItemUnitCondition).Assembly,
                    typeof(PricePolicyManufacturerCondition).Assembly,
                    typeof(PricePolicySupplierCondition).Assembly
                    );

                IDataLayer dl = new ThreadSafeDataLayer(dict, store);
                return(dl);
            }
            catch (Exception)
            {
                //Utility.LogWriter.Instance.WriteToLog("Exception: " + ex.Message);
                throw;
            }
            finally
            {
                //Utility.LogWriter.Instance.WriteToLog("---END: DAL.Purchasing.GetDataLayer()---");
            }
        }
Exemplo n.º 36
0
    private static IDataLayer GetDataLayer()
    {
        try
        {
            SqlConnection connection;
            MSSqlConnectionProvider connectionProvider;
            //Session workSession;
            connection = new SqlConnection(connectionString);
            connectionProvider = new MSSqlConnectionProvider(connection, AutoCreateOption.None);
            XpoDefault.Session = null;
            XPDictionary dict = new ReflectionDictionary();

            IDataStore store = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.SchemaAlreadyExists);

            string[] tablesList = connectionProvider.GetStorageTablesList(true);
            dynamicClasses = new Dictionary<string, DynamicDataTableClassInfo>(tablesList.Length);
            for (int i = 0; i < tablesList.Length; i++)
            {
                string tableName = tablesList[i];
                SqlDataAdapter adapter = new SqlDataAdapter(string.Format("SELECT TOP 1 * FROM [{0}]", tableName), connection);
                DataTable dataTable = new DataTable(tableName);
                adapter.FillSchema(dataTable, SchemaType.Source);
                if (dataTable.PrimaryKey.Length == 0)
                {
                    if (dataTable.Columns[0].DataType != typeof(Int32))
                    {
                        DataColumn dc = new DataColumn(tableName + "_idgen");
                        dc.AutoIncrement = true;
                        dc.AutoIncrementSeed = 1;
                        dc.AutoIncrementStep = 1;
                        dc.DataType = typeof(Int32);
                        dataTable.Columns.Add(dc);
                        DataColumn[] key = new DataColumn[1];
                        key[0] = dc;
                        dataTable.PrimaryKey = key;

                    }
                    else
                    {
                        DataColumn[] key = new DataColumn[1];
                        key[0] = dataTable.Columns[0];
                        dataTable.PrimaryKey = key;

                    }

                }

                dynamicClasses.Add(tableName, new DynamicDataTableClassInfo(dict, dataTable));

            }

            IDataLayer dl = new ThreadSafeDataLayer(dict, store);

            return dl;
        }
        catch (Exception ex)
        {
            SiAuto.Main.LogColored(Color.Red, "Loi BindData:" + ex.ToString());
            throw ex;
        }
    }