예제 #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));
        }
예제 #2
0
        public static string GetDBPlatformParam(projectsettingsDbplatformsDbplatform pDbPlatform, string pName)
        {
            foreach (parametersParameter param in pDbPlatform.parameters)
            {
                if (param.name.Equals(pName))
                {
                    return(param.Value);
                }
            }

            return("");
        }
 private bool SetDBPlatformParameter(projectsettingsDbplatformsDbplatform pDbPlatform,
                                     string pParam, string pValue)
 {
     foreach (parametersParameter p in pDbPlatform.parameters)
     {
         if (p.name.Equals(pParam))
         {
             p.Value = pValue;
             return(true);
         }
     }
     return(false);
 }
        public void ImportTable_PVEntityGenerator()
        {
            if (malImportParms == null)
            {
                this.FetchOldParameters();
            }

            //Get the selected platform
            projectsettingsPlatformsPlatform platform = null;

            foreach (projectsettingsPlatformsPlatform pl in mProjectSettings.platforms.platform)
            {
                if (pl.name.Equals(mProjectSettings.platforms.selected))
                {
                    platform = pl;
                    break;
                }
            }

            //Get the selected dbplatform
            projectsettingsDbplatformsDbplatform dbplatform = null;

            foreach (projectsettingsDbplatformsDbplatform pl in mProjectSettings.dbplatforms.dbplatform)
            {
                if (pl.name.Equals(mProjectSettings.dbplatforms.selected))
                {
                    dbplatform = pl;
                    break;
                }
            }

            if (platform == null || dbplatform == null)
            {
                throw new Exception("DBImportSettings.ImportTable_PVEntityGenerator: No platform or dbplatform found in projectsettings.");
            }

            //Write the parameter values dependend on the platform/dbplatform
            for (int i = malImportParms.Count - 1; i >= 0; i--)
            {
                OldParameterInfo param = (OldParameterInfo)malImportParms[i];
                if (param.Entity.ToLower().Equals("_pventitygenerator"))
                {
                    ProcessGlobalParameter(param, platform, dbplatform);
                    malImportParms.RemoveAt(i);
                    continue;
                }
            }

            //Entity generation parameters
            ProcessEntityParameters(platform, dbplatform);
        }
예제 #5
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 + "'.");
        }
예제 #6
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);
        }
        private void ProcessEntityParameters(projectsettingsPlatformsPlatform pPlatform,
                                             projectsettingsDbplatformsDbplatform pDBPlatform)
        {
            if (malImportParms == null || malImportParms.Count <= 0)
            {
                return;
            }

            foreach (type_generationGenerateentity e in mProjectSettings.entitygeneration.generateentity)
            {
                bool fGenEnum = false;
                UpdateEntityGenerationParameters(e, ref fGenEnum);

                if (fGenEnum)
                {
                    //enum generation on

                    //load enum defs from mdb
                    bool fDefChanged = false;
                    GridHelper.GetEnumeration(e, mMDBFilename, ref fDefChanged);

                    //update enum defs with the ones found in the old _PVEntityGenerator table
                    foreach (type_generationGenerateentityEnumerationentry enumAttr in e.enumerationentries)
                    {
                        enumAttr.description = GetEntityGenerationOldParamValue
                                                   (e.entity, "Enumeration_Comment_" + enumAttr.id);

                        enumAttr.generate = GetEntityGenerationOldParamValue
                                                (e.entity, "Enumeration_Generate_" + enumAttr.id).Equals("1");

                        enumAttr.identifier = GetEntityGenerationOldParamValue
                                                  (e.entity, "Enumeration_Constant_" + enumAttr.id);

                        enumAttr.name = GetEntityGenerationOldParamValue
                                            (e.entity, "Enumeration_Name_" + enumAttr.id);
                    }
                }
                else
                {
                    //enum generation off
                    e.enumerationentries = null;
                }

                //get count of custom create/findby methods
                int intCustomFindBy = 0;
                try { intCustomFindBy = int.Parse(GetEntityGenerationOldParamValue
                                                      (e.entity, "findCustom_Count")); } catch {}
                int intCustomCreate = 0;
                try { intCustomCreate = int.Parse(GetEntityGenerationOldParamValue
                                                      (e.entity, "createCustom_Count")); } catch {}

                //Custom create methods
                if (intCustomCreate > 0)
                {
                    ArrayList alMethods = new ArrayList();

                    for (int i = 0; i < intCustomCreate; i++)
                    {
                        string strVal = GetEntityGenerationOldParamValue
                                            (e.entity, "createCustom_" + i.ToString());

                        if (strVal == null || strVal.Length <= 0)
                        {
                            continue;
                        }

                        alMethods.Add(CreateCreateMethod(strVal));
                    }

                    e.customcreatemethods = (type_generationGenerateentityCustomcreatemethod[])
                                            alMethods.ToArray(typeof(type_generationGenerateentityCustomcreatemethod));
                }
                else
                {
                    e.customcreatemethods = null;
                }


                //Custom FindBy methods
                if (intCustomFindBy > 0)
                {
                    ArrayList alMethods = new ArrayList();

                    for (int i = 0; i < intCustomFindBy; i++)
                    {
                        string strVal = GetEntityGenerationOldParamValue(e.entity, "findCustom_" + i.ToString());
                        if (strVal == null || strVal.Length <= 0)
                        {
                            continue;
                        }

                        alMethods.Add(CreateFindByMethod(strVal));
                    }

                    e.customfindmethods = (type_generationGenerateentityCustomfindmethod[])
                                          alMethods.ToArray(typeof(type_generationGenerateentityCustomfindmethod));
                }
                else
                {
                    e.customfindmethods = null;
                }

                //Constraint messages
                ArrayList alConstraintMsg = new ArrayList();
                string    strConstrPrefix = "Constraint_";
                foreach (OldParameterInfo param in malImportParms)
                {
                    //Get all params that start with "Constraint_"
                    if (param.Entity.Equals(e.entity) && param.Param.StartsWith(strConstrPrefix))
                    {
                        string strForeignEntity = param.Param.Substring(strConstrPrefix.Length, param.Param.Length - strConstrPrefix.Length);

                        //check if foreign entity exists
                        foreach (dbdefinitionEntity eToCheck in mDBDefinition.entities)
                        {
                            if (eToCheck.name.Equals(strForeignEntity))
                            {
                                //yes, store the constraint message
                                type_generationGenerateentityRemoveconstraintmessage msg = new type_generationGenerateentityRemoveconstraintmessage();
                                msg.foreignentity = strForeignEntity;
                                msg.Value         = param.Value;
                                alConstraintMsg.Add(msg);
                                break;
                            }
                        }
                    }
                }
                if (alConstraintMsg.Count > 0)
                {
                    e.removeconstraintmessages = (type_generationGenerateentityRemoveconstraintmessage[])
                                                 alConstraintMsg.ToArray(typeof(type_generationGenerateentityRemoveconstraintmessage));
                }
                else
                {
                    e.removeconstraintmessages = null;
                }
            }
        }
        private void ProcessGlobalParameter(OldParameterInfo pParam, projectsettingsPlatformsPlatform pPlatform,
                                            projectsettingsDbplatformsDbplatform pDBPlatform)
        {
            switch (pParam.Param)
            {
            //Platform parameters
            case ("OutputDir"):
                SetPlatformParameter(pPlatform, "path-entity", pParam.Value);
                break;

            case ("Package"):
                if (pPlatform.name.Equals("NET"))
                {
                    SetPlatformParameter(pPlatform, "entity-namespace", pParam.Value);
                }
                else
                {
                    SetPlatformParameter(pPlatform, "entity-package", pParam.Value);
                }
                break;

            case ("ClassHeader"):
                SetPlatformParameter(pPlatform, "file-header", pParam.Value);
                break;

            case ("GenerateJavaDoc"):
                SetPlatformParameter(pPlatform, "generate-comments", pParam.Value);
                break;

            case ("JUnitGenerateClasses"):
                SetPlatformParameter(pPlatform, "generate-unittest-suite", pParam.Value);
                break;

            case ("JUnitGenerateAllTests"):
                if (pPlatform.name.Equals("Java2"))
                {
                    SetPlatformParameter(pPlatform, "generate-unittest", pParam.Value);
                }
                break;

            case ("JUnitOutputDir"):
                SetPlatformParameter(pPlatform, "path-unittest", pParam.Value);
                break;

            case ("JUnitBaseClass"):
                SetPlatformParameter(pPlatform, "unittest-baseclass", pParam.Value);
                break;

            case ("AttributeGetterSetter"):
                if (pPlatform.name.Equals("NET"))
                {
                    SetPlatformParameter(pPlatform, "getsetmethods", pParam.Value);
                }
                break;

            //DBPlatform parameters
            case ("GenerateStoredProc"):
                //ignore (for now)
                break;

            case ("Unicode"):
                SetDBPlatformParameter(pDBPlatform, "unicode", pParam.Value);
                break;

            case ("StoredProcOutputDir"):
                SetDBPlatformParameter(pDBPlatform, "script-path", pParam.Value);
                break;

            case ("StoredProcGrantTo"):
                SetDBPlatformParameter(pDBPlatform, "grant-to", pParam.Value);
                break;

            case ("CheckEntityNameLength"):
                if (pDBPlatform.name.Equals("Oracle"))
                {
                    SetDBPlatformParameter(pDBPlatform, "name-max-length", pParam.Value);
                }
                break;
            }
        }
예제 #9
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));
        }
예제 #10
0
 public string GenerateScript_PatchEntities(projectsettingsDbplatformsDbplatform pCurrentDbPlatform)
 {
     return(GenerateScript(pCurrentDbPlatform, "entity-patch"));
 }
예제 #11
0
 public string GenerateScript_CreateEntities(projectsettingsDbplatformsDbplatform pCurrentDbPlatform)
 {
     return(GenerateScript(pCurrentDbPlatform, "entity-create"));
 }
예제 #12
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);
        }
예제 #13
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.");
            }
        }