Beispiel #1
0
        public static IDbConnection GetConnection(Hashtable phashDBPlatform, projectsettings pProjectSettings)
        {
            String strDbPlatform = pProjectSettings.dbplatforms.selected;
            dbplatformdefinition dbplatformdef = (dbplatformdefinition)phashDBPlatform[strDbPlatform];

            if (dbplatformdef == null)
            {
                throw new PVException("No db platform definition for dbplatform '" + strDbPlatform + "' found.");
            }

            projectsettingsDbplatformsDbplatform dbplatform = null;

            foreach (projectsettingsDbplatformsDbplatform p in pProjectSettings.dbplatforms.dbplatform)
            {
                if (p.name.Equals(strDbPlatform))
                {
                    dbplatform = p;
                    break;
                }
            }
            if (dbplatform == null)
            {
                throw new PVException("Db platform settings not found.");
            }

            return(GetConnection(dbplatformdef, dbplatform));
        }
Beispiel #2
0
        private string ExpandDbPlatformParameters(string pValue,
                                                  dbplatformdefinition pDbPlatformDef, projectsettingsDbplatformsDbplatform pDbPlatform)
        {
            string strValue = pValue;

            if (pDbPlatformDef.parameterdefinitions != null && pDbPlatform.parameters != null)
            {
                foreach (parameterdefinitionsParameterdefinition paramdef in pDbPlatformDef.parameterdefinitions)
                {
                    strValue = strValue.Replace("{$" + paramdef.name + "}", ParameterHelper.GetParameter(paramdef.name, paramdef, pDbPlatform.parameters));
                }
            }

            return(ExpandPlatformParameters(strValue, null));
        }
Beispiel #3
0
        private string GenerateScript(projectsettingsDbplatformsDbplatform pCurrentDbPlatform, string pFile)
        {
            dbplatformdefinition dbplatformdef = (dbplatformdefinition)mhashDbPlatformDef[pCurrentDbPlatform.name];

            string strDbPlatformDefPath = mConfigDir;

            foreach (pventitygeneratorconfigDbplatform p in mConfig.dbplatforms)
            {
                if (p.name.Equals(dbplatformdef.name))
                {
                    if (p.definitiondir != null && p.definitiondir.Length != 0)
                    {
                        strDbPlatformDefPath += p.definitiondir;
                    }
                    break;
                }
            }
            if (strDbPlatformDefPath.Length != 0)
            {
                strDbPlatformDefPath += "\\";
            }

            if (dbplatformdef.scriptgeneration != null && dbplatformdef.scriptgeneration.generateglobal != null &&
                dbplatformdef.scriptgeneration.generateglobal.generatefile != null)
            {
                foreach (generatefile file in dbplatformdef.scriptgeneration.generateglobal.generatefile)
                {
                    if (file.name.Equals(pFile))
                    {
                        XslCompiledTransform transform = GetTransform(strDbPlatformDefPath + file.transform);
                        string strPath = ExpandDbPlatformParameters(file.path, dbplatformdef, pCurrentDbPlatform);
                        if (strPath.Length != 0 && !strPath.EndsWith("\\"))
                        {
                            strPath = strPath += "\\";
                        }

                        return(DoTransform(transform, null, generatefileEncoding.ISO88591));
                    }
                }
            }

            throw new Exception("No transformation defined for '" + pFile + "' in db platform '" + pCurrentDbPlatform.name + "'.");
        }
Beispiel #4
0
        public fdlgTransferData(bool pfExport, string pDBFile, projectsettings pProjectSettings,
                                Hashtable phashDBPlatform, projectsettingsDbplatformsDbplatform pDbPlatform,
                                dbdefinition pDBDefinition)
        {
            InitializeComponent();

            mfExport         = pfExport;
            mDbPlatform      = pDbPlatform;
            mDBFile          = pDBFile;
            mProjectSettings = pProjectSettings;
            mhashDBPlatform  = phashDBPlatform;
            mDBDefinition    = pDBDefinition;

            mDbPlatformDef = (dbplatformdefinition)mhashDBPlatform[mProjectSettings.dbplatforms.selected];

            //Wait a bit before starting
            tmrMain.Interval = 10;
            tmrMain.Tick    += new EventHandler(tmrMain_Tick);
        }
Beispiel #5
0
        public void GenerateFiles_EntityGeneration()
        {
            string strPlatformDefPath = mConfigDir;

            foreach (pventitygeneratorconfigPlatform p in mConfig.platforms)
            {
                if (p.name.Equals(mPlatformDef.name))
                {
                    if (p.definitiondir != null && p.definitiondir.Length != 0)
                    {
                        strPlatformDefPath += p.definitiondir;
                    }
                    break;
                }
            }
            if (strPlatformDefPath.Length != 0)
            {
                strPlatformDefPath += "\\";
            }

            int intSelectedEntityCount = mSelectedEntities.Count;

            if (mSelectedEntities.Contains(GLOBAL_ITEMS))
            {
                intSelectedEntityCount--;
            }

            // Gesamtzahl der Schritte ermitteln
            int intStepsTotal = 0;

            if (mPlatformDef.entitygeneration != null && mPlatformDef.entitygeneration.generateentity != null &&
                mPlatformDef.entitygeneration.generateentity.generatefile != null)
            {
                intStepsTotal += mPlatformDef.entitygeneration.generateentity.generatefile.Length * intSelectedEntityCount;
            }
            if (mSelectedEntities.Contains(GLOBAL_ITEMS))
            {
                if (mPlatformDef.entitygeneration != null && mPlatformDef.entitygeneration.generateglobal != null &&
                    mPlatformDef.entitygeneration.generateglobal.generatefile != null)
                {
                    intStepsTotal += mPlatformDef.entitygeneration.generateglobal.generatefile.Length;
                }
            }
            if (mProjectSettings.dbplatforms != null && mProjectSettings.dbplatforms.dbplatform != null)
            {
                foreach (projectsettingsDbplatformsDbplatform dbplatform in mProjectSettings.dbplatforms.dbplatform)
                {
                    dbplatformdefinition dbplatformdef = (dbplatformdefinition)mhashDbPlatformDef[dbplatform.name];
                    if (dbplatformdef != null &&
                        dbplatformdef.scriptgeneration != null &&
                        dbplatformdef.scriptgeneration.generateglobal != null &&
                        dbplatformdef.scriptgeneration.generateglobal.generatefile != null)
                    {
                        foreach (generatefile file in dbplatformdef.scriptgeneration.generateglobal.generatefile)
                        {
                            if (!file.name.Equals("entity-create") && !file.name.Equals("entity-patch"))
                            {
                                intStepsTotal++;
                            }
                        }
                    }
                }
            }
            mStatusHandler.InitStatus("Generating files...", intStepsTotal);
            int intStep = 0;

            // Generate entity files
            if (mPlatformDef.entitygeneration != null && mPlatformDef.entitygeneration.generateentity != null &&
                mPlatformDef.entitygeneration.generateentity.generatefile != null)
            {
                foreach (generatefile file in mPlatformDef.entitygeneration.generateentity.generatefile)
                {
                    XslCompiledTransform transform = GetTransform(strPlatformDefPath + file.transform);
                    string strPath = ExpandPlatformParameters(file.path);
                    if (strPath.Length != 0 && !strPath.EndsWith("\\"))
                    {
                        strPath = strPath += "\\";
                    }

                    foreach (dbdefinitionEntity entity in mDbDefinition.entities)
                    {
                        if (mSelectedEntities.Contains(entity.name))
                        {
                            string strFilename = ExpandPlatformParameters(strPath + file.filename, entity.name);

                            GenerateFile(transform, strFilename, mPlatformDef.parameterdefinitions, entity.name, file.encoding);
                            mStatusHandler.SetStatus("Generated: " + strFilename, ++intStep);
                        }
                    }
                }
            }

            // Generate global
            if (mSelectedEntities.Contains(GLOBAL_ITEMS))
            {
                // Generate global files
                if (mPlatformDef.entitygeneration != null && mPlatformDef.entitygeneration.generateglobal != null &&
                    mPlatformDef.entitygeneration.generateglobal.generatefile != null)
                {
                    foreach (generatefile file in mPlatformDef.entitygeneration.generateglobal.generatefile)
                    {
                        XslCompiledTransform transform = GetTransform(strPlatformDefPath + file.transform);
                        string strPath = ExpandPlatformParameters(file.path);
                        if (strPath.Length != 0 && !strPath.EndsWith("\\"))
                        {
                            strPath = strPath += "\\";
                        }
                        string strFilename = ExpandPlatformParameters(strPath + file.filename);

                        GenerateFile(transform, strFilename, mPlatformDef.parameterdefinitions, file.encoding);
                        mStatusHandler.SetStatus("Generated: " + strFilename, ++intStep);
                    }
                }

                // Generate global scripts
                if (mProjectSettings.dbplatforms != null && mProjectSettings.dbplatforms.dbplatform != null)
                {
                    foreach (projectsettingsDbplatformsDbplatform dbplatform in mProjectSettings.dbplatforms.dbplatform)
                    {
                        dbplatformdefinition dbplatformdef = (dbplatformdefinition)mhashDbPlatformDef[dbplatform.name];
                        if (dbplatformdef != null && dbplatform != null)
                        {
                            string strDbPlatformDefPath = mConfigDir;
                            foreach (pventitygeneratorconfigDbplatform p in mConfig.dbplatforms)
                            {
                                if (p.name.Equals(dbplatformdef.name))
                                {
                                    if (p.definitiondir != null && p.definitiondir.Length != 0)
                                    {
                                        strDbPlatformDefPath += p.definitiondir;
                                    }
                                    break;
                                }
                            }
                            if (strDbPlatformDefPath.Length != 0)
                            {
                                strDbPlatformDefPath += "\\";
                            }

                            if (dbplatformdef.scriptgeneration != null && dbplatformdef.scriptgeneration.generateglobal != null &&
                                dbplatformdef.scriptgeneration.generateglobal.generatefile != null)
                            {
                                foreach (generatefile file in dbplatformdef.scriptgeneration.generateglobal.generatefile)
                                {
                                    if (!file.name.Equals("entity-create") && !file.name.Equals("entity-patch"))
                                    {
                                        XslCompiledTransform transform = GetTransform(strDbPlatformDefPath + file.transform);
                                        string strPath = ExpandDbPlatformParameters(file.path, dbplatformdef, dbplatform);
                                        if (strPath.Length != 0 && !strPath.EndsWith("\\"))
                                        {
                                            strPath = strPath += "\\";
                                        }
                                        string strFilename = ExpandDbPlatformParameters(strPath + file.filename, dbplatformdef, dbplatform);

                                        GenerateFile(transform, strFilename, dbplatformdef.parameterdefinitions, file.encoding);
                                        mStatusHandler.SetStatus("Generated: " + strFilename, ++intStep);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            mStatusHandler.ClearStatus("Generated " + intStep + " file(s).");
        }
Beispiel #6
0
        public static IDbConnection GetConnection(dbplatformdefinition pDbPlatformDef, projectsettingsDbplatformsDbplatform pDbPlatform)
        {
            // Aktuellen provider+providerdef ermitteln
            projectsettingsDbplatformsDbplatformDbprovidersDbprovider provider = null;

            foreach (projectsettingsDbplatformsDbplatformDbprovidersDbprovider p in pDbPlatform.dbproviders.dbprovider)
            {
                if (p.name.Equals(pDbPlatform.dbproviders.selected))
                {
                    provider = p;
                    break;
                }
            }
            if (provider == null)
            {
                throw new PVException("No or invalid db provider selected.");
            }
            dbplatformdefinitionDbproviderdefinition providerdef = null;

            foreach (dbplatformdefinitionDbproviderdefinition pd in pDbPlatformDef.dbproviderdefinitions)
            {
                if (pd.name.Equals(provider.name))
                {
                    providerdef = pd;
                    break;
                }
            }
            if (providerdef == null)
            {
                throw new PVException("No provider definition found for provider '" + provider.name + "'.");
            }

            string strConnect = providerdef.connectionstring;

            if (provider.parameters != null)
            {
                foreach (parametersParameter param in provider.parameters)
                {
                    string strValue = param.Value;
                    if (param.name.Equals("password"))
                    {
                        try {
                            strValue = PasswordHelper.DecryptPassword(strValue);
                        }
                        catch (Exception) {}
                    }
                    strConnect = strConnect.Replace("{" + param.name + "}", strValue);
                }
            }

            Assembly asm = null;

            try {
                asm = Assembly.Load(providerdef.providerassembly);
            }
            catch (Exception ex) {
                try {
                    asm = Assembly.LoadWithPartialName(providerdef.providerassembly);
                }
                catch (Exception) {
                    throw ex;
                }
            }
            IDbConnection con = (IDbConnection)asm.CreateInstance(providerdef.providerclass);

            con.ConnectionString = strConnect;
            con.Open();
            return(con);
        }
Beispiel #7
0
        public static void ExecuteScript(dbplatformdefinition pDbPlatformDef,
                                         projectsettingsDbplatformsDbplatform pDbPlatform, string pScript, StatusHandler pStatusHandler)
        {
            bool fInComment     = false;
            bool fSimpleComment = false;
            bool fInString      = false;
            int  intStartPos    = 0;

            if (pScript == null || pScript.Length <= 0)
            {
                pStatusHandler.InitStatus("Empty script.", 0);
                return;
            }

            pScript = pScript.Replace("\r\n", "\n");
            string strDelim = GetDelimiter(pDbPlatformDef, pScript);

            ArrayList aSQL = new ArrayList();

            for (int i = 0; i < pScript.Length; i++)
            {
                char ch = pScript[i];

                if (fInComment)
                {
                    if (fSimpleComment && ch == '\n')
                    {
                        fInComment  = false;
                        intStartPos = ++i;
                        continue;
                    }
                    else
                    if (!fSimpleComment && ch == '*' && (i + 1) < pScript.Length && pScript[i + 1] == '/')
                    {
                        fInComment = false;
                        i++;
                        intStartPos = ++i;
                        continue;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    if (ch == '/' && (i + 1) < pScript.Length && pScript[i + 1] == '*')
                    {
                        fInComment     = true;
                        fSimpleComment = false;
                        continue;
                    }
                    else
                    if (ch == '-' && (i + 1) < pScript.Length && pScript[i + 1] == '-')
                    {
                        fInComment     = true;
                        fSimpleComment = true;
                        continue;
                    }
                }

                if (ch == '\'')
                {
                    fInString = !fInString;
                    continue;
                }

                int intLenDelim = strDelim.Length;

                if (!fInComment && !fInString)
                {
                    if (i + intLenDelim >= pScript.Length)
                    {
                        string strSQL = pScript.Substring(intStartPos, pScript.Length - intStartPos - intLenDelim).
                                        Trim(new char[] { ' ', '\n' });
                        if (strSQL != null && strSQL.Length > 0)
                        {
                            aSQL.Add(strSQL);
                        }
                        break;
                    }
                    else
                    if (pScript.Substring(i, intLenDelim + 1).ToLower().Equals(strDelim.ToLower() + "\n"))
                    {
                        string strSQL = pScript.Substring(intStartPos, i - intStartPos).Trim(new char[] { ' ', '\n' });
                        if (strSQL != null && strSQL.Length > 0)
                        {
                            aSQL.Add(strSQL);
                        }
                        intStartPos = i + intLenDelim;
                        i          += intLenDelim;
                    }
                }
            }

            int intStep = 0;

            pStatusHandler.InitStatus("Executing SQL...", aSQL.Count);

            IDbConnection con = GetConnection(pDbPlatformDef, pDbPlatform);

            bool       fError     = false;
            int        intCounter = 0;
            IDbCommand cmd        = con.CreateCommand();

            cmd.CommandType = CommandType.Text;

            while (true)
            {
                if (intCounter >= aSQL.Count)
                {
                    break;
                }

                pStatusHandler.SetStatus("Executing SQL...", ++intStep);

                string strSQL = (string)aSQL[intCounter];
                try {
                    cmd.CommandText = strSQL;
                    cmd.ExecuteNonQuery();

                    intCounter++;
                }
                catch (Exception pex) {
                    string strMsg = pex.Message + "\n\n";
                    // append first 1000 chars of sql string to error message
                    if (strSQL.Length > 1000)
                    {
                        strMsg += strSQL.Substring(0, 1000) + "...";
                    }
                    else
                    {
                        strMsg += strSQL;
                    }
                    // ask if user wants to retry, ignore and continue or cancel
                    DialogResult res = pStatusHandler.OnError(strMsg);
                    if (res == DialogResult.Ignore)
                    {
                        intCounter++;
                    }
                    else if (res != DialogResult.Retry)
                    {
                        pStatusHandler.ClearStatus("Execution aborted with errors.");
                        fError = true;
                        break;
                    }
                }
            }

            con.Close();
            if (!fError)
            {
                pStatusHandler.ClearStatus("Execution completed sucessfully.");
            }
        }
Beispiel #8
0
        private static string GetDelimiter(dbplatformdefinition pDbPlatformDef, string pScript)
        {
            if (pDbPlatformDef.alternativescriptdelimiter == null || pDbPlatformDef.alternativescriptdelimiter.Length <= 0)
            {
                return(pDbPlatformDef.scriptdelimiter);
            }

            bool fInComment     = false;
            bool fSimpleComment = false;
            bool fInString      = false;

            //Nach alternativ-delimiter suchen
            for (int i = 0; i < pScript.Length; i++)
            {
                char ch = pScript[i];

                if (fInComment)
                {
                    if (fSimpleComment && ch == '\n')
                    {
                        fInComment = false;
                        continue;
                    }
                    else
                    if (!fSimpleComment && ch == '*' && pScript[i + 1] == '/')
                    {
                        i++;
                        fInComment = false;
                        continue;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    if (ch == '/' && pScript[i + 1] == '*')
                    {
                        fInComment     = true;
                        fSimpleComment = false;
                        i++;
                        continue;
                    }
                    else
                    if (ch == '-' && pScript[i + 1] == '-')
                    {
                        fInComment     = true;
                        fSimpleComment = true;
                        i++;
                        continue;
                    }
                }

                if (ch == '\'')
                {
                    fInString = !fInString;
                    continue;
                }

                int intLenDelim = pDbPlatformDef.alternativescriptdelimiter.Length;
                if (!fInComment && !fInString)
                {
                    if (i + intLenDelim >= pScript.Length)
                    {
                        return(pDbPlatformDef.scriptdelimiter);
                    }
                    else
                    if (pScript.Substring(i, intLenDelim).ToLower().
                        Equals(pDbPlatformDef.alternativescriptdelimiter.ToLower()))
                    {
                        return(pDbPlatformDef.alternativescriptdelimiter);
                    }
                }
            }

            return(pDbPlatformDef.scriptdelimiter);
        }