public static void InitializeDatabase(string conectionString)
        {
            CreateDatabase(conectionString);

            IDbContext context = EngineContext.Current.Resolve<IDbContext>();

            List<string> tableNamesToValidate = new List<string> { "ProductType", "Product" };
            List<string> existingTableNames = context
                .QueryFromSql<StringQueryType>("SELECT table_name AS Value FROM INFORMATION_SCHEMA.TABLES WHERE table_type = 'BASE TABLE'")
                .Select(stringValue => stringValue.Value).ToList();
            bool createTables = !existingTableNames.Intersect(tableNamesToValidate, StringComparer.InvariantCultureIgnoreCase).Any();
            if (createTables)
            {

                IVerivoxFileProvider fileProvider = EngineContext.Current.Resolve<IVerivoxFileProvider>();

                //create tables
                //EngineContext.Current.Resolve<IRelationalDatabaseCreator>().CreateTables();
                //(context as DbContext).Database.EnsureCreated();
                context.ExecuteSqlScript(context.GenerateCreateScript());

                //create indexes
                context.ExecuteSeedFromJsonFile(fileProvider.MapPath(DataDefaults.JsonFilePath));
            }
        }
Example #2
0
        /// <summary>
        /// Get system names of installed plugins from obsolete file
        /// </summary>
        /// <returns>List of plugin system names</returns>
        protected virtual IList <string> GetObsoleteInstalledPluginNames()
        {
            //check whether file exists
            string filePath = _fileProvider.MapPath(VerivoxPluginDefaults.InstalledPluginsFilePath);

            if (!_fileProvider.FileExists(filePath))
            {
                //if not, try to parse the file that was used in previous nopCommerce versions
                filePath = _fileProvider.MapPath(VerivoxPluginDefaults.ObsoleteInstalledPluginsFilePath);
                if (!_fileProvider.FileExists(filePath))
                {
                    return(new List <string>());
                }

                //get plugin system names from the old txt file
                List <string> pluginSystemNames = new List <string>();
                using (StringReader reader = new StringReader(_fileProvider.ReadAllText(filePath, Encoding.UTF8)))
                {
                    string pluginName;
                    while ((pluginName = reader.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(pluginName))
                        {
                            pluginSystemNames.Add(pluginName.Trim());
                        }
                    }
                }

                //and delete the old one
                _fileProvider.DeleteFile(filePath);

                return(pluginSystemNames);
            }

            string text = _fileProvider.ReadAllText(filePath, Encoding.UTF8);

            if (string.IsNullOrEmpty(text))
            {
                return(new List <string>());
            }

            //delete the old file
            _fileProvider.DeleteFile(filePath);

            //get plugin system names from the JSON file
            return(JsonConvert.DeserializeObject <IList <string> >(text));
        }