Exemplo n.º 1
0
        private void WriteConfigFileToDB(string serverpath, bool cleanExistingData = true)
        {
            try
            {
                string[] files = Directory.GetFiles(serverpath, string.Format("*{0}", CommonConst.CONFIG_FILE_EXTENSION));

                foreach (var filePath in files)
                {
                    _logger.Debug(string.Format("Installer.WriteConfigFileToDB filePath: {0}", filePath));

                    try
                    {
                        _logger.Info(string.Format("Installing {0} collection", filePath));

                        var fi             = new FileInfo(filePath);
                        var collectionName = fi.Name.Replace(fi.Extension, "");
                        if (collectionName.Contains("."))
                        {
                            continue;
                        }
                        JArray arrData = JObjectHelper.GetJArrayFromFile(fi.FullName);

                        if (cleanExistingData)
                        {
                            _dbProxy.Delete(collectionName, CommonConst.EMPTY_JSON_OBJECT);
                        }
                        WriteInstallData(arrData, collectionName);
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(string.Format("Error in installing {0} collection. Error {1}", filePath, ex.Message), ex);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Error in installing Error: {0}", ex.Message), ex);
            }
        }
Exemplo n.º 2
0
        private void InstallCollections(string moduleDir, string moduleName, JArray moduleCollections)
        {
            var collectionsPath = string.Format("{0}\\Content\\{1}", moduleDir, CommonConst.MODULE_INSTALL_COLLECTIONS_FOLDER);

            if (Directory.Exists(collectionsPath))
            {
                DirectoryInfo di    = new DirectoryInfo(collectionsPath);
                FileInfo[]    files = di.GetFiles(string.Format("*{0}", CommonConst.CONFIG_FILE_EXTENSION));
                foreach (var item in files)
                {
                    FileInfo fi             = new FileInfo(item.FullName);
                    var      collectionName = fi.Name.Replace(fi.Extension, "");
                    //Find collection in config

                    var collectionConfig = moduleCollections.FirstOrDefault(f => f[CommonConst.CommonField.NAME].ToString() == collectionName);
                    if (collectionConfig != null)
                    {
                        if (collectionName.Contains("."))
                        {
                            continue;
                        }

                        CleanDBCollection(moduleName, collectionName);
                        _logger.Debug(string.Format("InstallCollections File:{0}", fi.FullName));

                        foreach (JObject joData in JObjectHelper.GetJArrayFromFile(fi.FullName))
                        {
                            joData[CommonConst.CommonField.DISPLAY_ID]             = CommonUtility.GetNewID();
                            joData[CommonConst.CommonField.CREATED_DATA_DATE_TIME] = DateTime.Now;
                            joData[CommonConst.CommonField.MODULE_NAME]            = moduleName;
                            joData[CommonConst.CommonField.ÌS_OVERRIDE]            = false;
                            joData[CommonConst.CommonField.OVERRIDE_BY]            = CommonConst.CommonValue.NONE;
                            WriteToDB(joData, moduleName, collectionName, CommonConst.CommonField.DATA_KEY);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void RunInstallScripts()
        {
            _logger.Debug("START RunInstallScripts");

            //_dbProxy.DropDB();
            var serverpath  = string.Format("{0}\\..\\InstallScripts\\Collections", ApplicationConfig.AppBinPath);
            var environment = CommonUtility.GetAppConfigValue(CommonConst.ENVIRONMENT_SETTING_KEY);

            environment = environment == null ? string.Empty : environment;
            string envExtension = string.Format(".{0}{1}", environment, CommonConst.CONFIG_FILE_EXTENSION);

            _logger.Debug(string.Format("Installer.RunInstallScripts WriteConfigFileToDB, path: {0}", serverpath));

            WriteConfigFileToDB(serverpath);

            _logger.Debug(string.Format("Installer.RunInstallScripts  Install Env specific files"));

            /// Install Env specific files.
            if (!string.IsNullOrEmpty(environment))
            {
                string[] envFiles = Directory.GetFiles(serverpath, string.Format("*{0}{1}", environment, CommonConst.CONFIG_FILE_EXTENSION));

                foreach (var filePath in envFiles)
                {
                    var    fi             = new FileInfo(filePath);
                    var    collectionName = fi.Name.Replace(fi.Extension, "").Replace(string.Format(".{0}", environment), "");
                    JArray arrData        = JObjectHelper.GetJArrayFromFile(fi.FullName);
                    WriteInstallData(arrData, collectionName);
                }
            }
            _logger.Debug(string.Format("Installer.RunInstallScripts Install custom configs"));

            // Install custom configs
            WriteConfigFileToDB(GetCustomConfigDirectoryPath(), false);
            _logger.Debug("END RunInstallScripts");
        }