public DbContext Resolve(DBSelector dbSelector = DBSelector.Master)
        {
            DbContext dbContext = null;

            if (dbSelector.Equals(DBSelector.Master))
            {
                _cacheDbContext.TryGetValue(dbSelector, out dbContext);
            }
            //ISSUE:A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe
            //We do it in temprary, we must optimzie the Framewrok to resolve the multiple thread to call DbContext.
            else
            {
                _slaveCacheDbContext.TryGetValue(Thread.CurrentThread.ManagedThreadId, out dbContext);
            }
            if (dbContext != null)
            {
                return(dbContext);
            }
            var configurer = new AbpDbContextConfiguration <TDbContext>(_dbOptions.DbConnections[dbSelector]);

            _dbContextConfigurer.Configure(configurer);
            var actualContext = typeof(TDbContext);

            dbContext = (DbContext)Activator.CreateInstance(actualContext, configurer.DbContextOptions.Options);
            if (dbSelector.Equals(DBSelector.Master))
            {
                _cacheDbContext.Add(dbSelector, dbContext);
            }
            else
            {
                _slaveCacheDbContext.Add(Thread.CurrentThread.ManagedThreadId, dbContext);
            }

            return(dbContext);
        }
        public static ISession DBSession(DBSelector db = DBSelector.DEFAULT)
        {
            switch (db)
            {
            case DBSelector.CUSTOM:
            {
                var cfgFile = string.Empty;
                cfgFile = $"{AppDomain.CurrentDomain.BaseDirectory}\\mypath\\custom.cfg.xml";        //replace the [mypath] with your path
                Configuration configuration = new Configuration()
                                              .AddAssembly("NHibernateCustomCfgFile")
                                              .Configure(cfgFile);
                ISessionFactory sessionFactory = configuration.BuildSessionFactory();
                session = sessionFactory.OpenSession();
            }

            break;

            default:
            case DBSelector.DEFAULT:
            {
                Configuration configuration = new Configuration()
                                              .AddAssembly("NHibernateCustomCfgFile")
                                              .Configure();//by default it reads hibernate.cfg.xml
                ISessionFactory sessionFactory = configuration.BuildSessionFactory();
                session = sessionFactory.OpenSession();
                break;
            }
            }
            return(session);
        }
Exemple #3
0
 public override IQueryable <EFEntity> GetAll()
 {
     //Have to set the slave database, it should be work for this.
     //NOTE:need to be optimzied
     _dbSelector = DBSelector.Slave;
     return(Table);
 }
Exemple #4
0
        public int saveOrder(Order theOrder)
        {
            DBSelector selector = new DBSelector();

            return(selector.getRow <int>("INSERT INTO \"Order\" (\"ConfirmationNumber\", \"OrderDateTime\", \"TotalPrice\", \"UserID\") VALUES ('" +
                                         theOrder.ConfirmationNumber + "','" + theOrder.OrderDateTime + "','" + theOrder.TotalPrice + "','" + theOrder.UserID + "')" +
                                         "RETURNING \"OrderID\""));
        }
Exemple #5
0
        /// <summary>
        /// Load network's memory from database
        /// </summary>
        /// <param name="dbConfig"></param>
        /// <param name="networkID"></param>
        /// <param name="destinationMemoryFilePath"></param>
        public void DBMemoryLoad(DatabaseConfig dbConfig, Guid networkID, string destinationMemoryFilePath)
        {
            try
            {
                DBSelector dbSelector = new DBSelector(dbConfig);

                // Creating the general string list of memory:
                List <string> memoryInTextList = new List <string>();

                // Getting all layers ids' ordered by own number in network:
                List <Guid> layersIDList = dbSelector.GetLayerIDList(networkID);

                // As parallel fill the metadata of network:
                NetworkStructure networkStructure = new NetworkStructure();
                networkStructure.NeuronsByLayers = new int[layersIDList.Count];

                for (int i = 0; i < layersIDList.Count; i++)
                {
                    List <Guid> neuronsIDList = dbSelector.GetNeuronsIDList(layersIDList[i]);

                    // Fillin the metadata of count of neurons on current layer:
                    networkStructure.NeuronsByLayers[i] = neuronsIDList.Count;

                    for (int k = 0; k < neuronsIDList.Count; k++)
                    {
                        List <double> weightList = dbSelector.GetWeightsList(neuronsIDList[k]);

                        // Adding memory neuron data to text list:
                        string neuronDataText = $"layer_{i} neuron_{k} ";

                        for (int j = 0; j < weightList.Count; j++)
                        {
                            neuronDataText += weightList[j];
                        }

                        memoryInTextList.Add(neuronDataText);

                        // Fillin metadata of inputVectorLength of network:
                        if (i == 0 && k == 0)
                        {
                            networkStructure.InputVectorLength = weightList.Count;
                        }
                    }
                }

                // Saving memory from textList:
                FileManager.SaveMemoryFromModel(networkStructure, memoryInTextList, destinationMemoryFilePath);
            }
            catch (Exception ex)
            {
                Logger.LogError(ErrorType.DBMemoryLoadError, "DB Memory loading error!\n" + ex);
                Console.WriteLine($" {DateTime.Now } DB Memory loading error!\n {ex}");
            }
        }
Exemple #6
0
        public int saveLoginInfo(string username, string password)
        {
            DBModifier modder = new DBModifier();

            modder.modifyRows("INSERT INTO \"Login\" (\"UserName\", \"Password\") VALUES ('" + username + "','" + password + "')");

            DBSelector selector = new DBSelector();

            Login newLogin = selector.getRow <Login>("SELECT * FROM \"Login\" WHERE " +
                                                     "\"UserName\" = '" + username + "' AND \"Password\" = '" + password + "'");

            return(newLogin.ID);
        }
Exemple #7
0
        public DbContext Resolve(DBSelector dbSelector = DBSelector.Master)
        {
            DbContext dbContext;

            CacheDbContext.TryGetValue(dbSelector, out dbContext);
            if (dbContext != null)
            {
                return(dbContext);
            }
            var configurer = new AbpDbContextConfiguration <TDbContext>(dbOptions.DbConnections[dbSelector]);

            dbContextConfigurer.Configure(configurer);
            var actualContext = typeof(TDbContext);

            dbContext = (DbContext)Activator.CreateInstance(actualContext, configurer.DbContextOptions.Options);
            CacheDbContext.Add(dbSelector, dbContext);
            return(dbContext);
        }
Exemple #8
0
        public void addItem(Item theItem, Vendor theVendor)
        {
            DBModifier modder   = new DBModifier();
            DBSelector selector = new DBSelector();

            //put the item in the DB
            modder.modifyRows("INSERT INTO \"Item\"(\"RetailPrice\",\"StockQuantity\",\"ItemName\",\"CostPrice\",\"Category\") VALUES(" +
                              theItem.RetailPrice + "," + theItem.StockQuantity + ",'" + theItem.ItemName + "'," + theItem.CostPrice + ",'" +
                              theItem.Category + "')");

            Item newitem = selector.getRow <Item>("SELECT * FROM \"Item\" WHERE \"RetailPrice\" = " + theItem.RetailPrice +
                                                  " AND \"StockQuantity\" = " + theItem.StockQuantity +
                                                  " AND \"ItemName\" = '" + theItem.ItemName +
                                                  "' AND \"CostPrice\" = " + theItem.CostPrice +
                                                  " AND \"Category\" = '" + theItem.Category + "'");

            //add it to the vedor
            modder.modifyRows("INSERT INTO \"Vendor_Items\"(\"VendorID\",\"ItemID\") VALUES( " +
                              theVendor.VendorID + "," + newitem.ItemID + ")");
        }
Exemple #9
0
        public List <Item> getOrderItems(int orderID)
        {
            DBSelector selector = new DBSelector();

            List <ItemList> itemList = selector.getRows <ItemList>("SELECT * FROM \"ItemList\" WHERE \"OrderID\"= '" + orderID + "'");

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < itemList.Count; ++i)
            {
                sb.Append("'");
                sb.Append(itemList[i].ItemID);
                sb.Append("'");

                //add a comma if it's not the last id
                if (i < (itemList.Count - 1))
                {
                    sb.Append(",");
                }
            }

            return(selector.getRows <Item>("SELECT * FROM \"Item\" WHERE \"ItemID\" IN (" + sb.ToString() + ")"));
        }
Exemple #10
0
        public List <Login> getAllLogins()
        {
            DBSelector selector = new DBSelector();

            return(selector.getRows <Login>("SELECT * FROM \"Login\""));
        }
Exemple #11
0
 public override void Delete(EFEntity entity)
 {
     _dbSelector = DBSelector.Master;
     Table.Remove(entity);
 }
Exemple #12
0
 public override EFEntity Update(EFEntity entity)
 {
     _dbSelector = DBSelector.Master;
     return(Table.Update(entity).Entity);
 }
Exemple #13
0
 public override EFEntity Insert(EFEntity entity)
 {
     _dbSelector = DBSelector.Master;
     return(Table.Add(entity).Entity);
 }
Exemple #14
0
        public List <Vendor> getAllVendors()
        {
            DBSelector selector = new DBSelector();

            return(selector.getRows <Vendor>("SELECT * FROM \"Vendor\""));
        }
Exemple #15
0
 public override IQueryable <TEntity> GetAll()
 {
     dbSelector = DBSelector.Slave;
     throw new NotImplementedException();
 }
Exemple #16
0
        public List <User> getAllUsers()
        {
            DBSelector selector = new DBSelector();

            return(selector.getRows <User>("SELECT * FROM \"User\""));
        }
Exemple #17
0
        public User getUserByID(int ID)
        {
            DBSelector selector = new DBSelector();

            return(selector.getRow <User>("SELECT * FROM \"User\" WHERE \"ID\"= '" + ID + "'"));
        }
Exemple #18
0
 public override IQueryable <EFEntity> GetAll()
 {
     //Must Have the slave database, it should be work for this.
     dbSelector = DBSelector.Slave;
     return(Table);
 }
Exemple #19
0
        public Vendor getVendorByID(int id)
        {
            DBSelector selector = new DBSelector();

            return(selector.getRow <Vendor>("SELECT * FROM \"Vendor\" WHERE \"VendorName\"='" + id + "'"));
        }
Exemple #20
0
        public List <Order> getOrdersByUser(int userID)
        {
            DBSelector selector = new DBSelector();

            return(selector.getRows <Order>("SELECT * FROM \"Order\" WHERE \"UserID\"= '" + userID + "'"));
        }
Exemple #21
0
        public Item getItemByID(int ID)
        {
            DBSelector selector = new DBSelector();

            return(selector.getRow <Item>("SELECT * FROM \"Item\" WHERE \"ItemID\"= '" + ID + "'"));
        }
Exemple #22
0
        public List <Item> geItemsByCategory(string category)
        {
            DBSelector selector = new DBSelector();

            return(selector.getRows <Item>("SELECT * FROM \"Item\" WHERE \"Category\" = '" + category + "'"));
        }
Exemple #23
0
        public List <ItemList> getOrderLineItems(int orderID)
        {
            DBSelector selector = new DBSelector();

            return(selector.getRows <ItemList>("SELECT * FROM \"ItemList\" WHERE \"OrderID\" = '" + orderID + "'"));
        }
Exemple #24
0
        public Order getOrderByID(int ID)
        {
            DBSelector selector = new DBSelector();

            return(selector.getRow <Order>("SELECT * FROM \"Order\" WHERE \"OrderID\"= '" + ID + "'"));
        }
Exemple #25
0
        public Login getLoginByUserID(int userID)
        {
            DBSelector selector = new DBSelector();

            return(selector.getRow <Login>("SELECT * FROM \"Public.Login\" WHERE \"ID\" = '" + userID + "'"));
        }
Exemple #26
0
        public List <String> getItemCategories()
        {
            DBSelector selector = new DBSelector();

            return(selector.getRows <String>("SELECT DISTINCT \"Category\" FROM \"Item\""));
        }
Exemple #27
0
 private void DBandTableControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if ((bool)e.NewValue == true)
     {
         Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate() { DBSelector.Focus(); }));
     }
 }
Exemple #28
0
        public Vendor getVendorByName(string name)
        {
            DBSelector selector = new DBSelector();

            return(selector.getRow <Vendor>("SELECT * FROM \"Vendor\" WHERE \"VendorName\"='" + name + "'"));
        }