Ejemplo n.º 1
0
        public FileGenerator(string pConfigDir, pventitygeneratorconfig pConfig,
                             platformdefinition pPlatformDef, Hashtable phashDbPlatformDef,
                             dbdefinition pDbDefinition, projectsettings pProjectSettings,
                             projectsettingsPlatformsPlatform pCurrentPlatform,
                             IList pSelectedEntities, string pDbDefinitionFile,
                             StatusHandler pStatusHandler)
        {
            mConfigDir         = pConfigDir;
            mConfig            = pConfig;
            mPlatformDef       = pPlatformDef;
            mhashDbPlatformDef = phashDbPlatformDef;
            mDbDefinition      = pDbDefinition;
            mProjectSettings   = pProjectSettings;
            mCurrentPlatform   = pCurrentPlatform;
            mSelectedEntities  = pSelectedEntities;
            mStatusHandler     = pStatusHandler;

            // Combined XML Data Document generieren
            pventitygeneratordata data = new pventitygeneratordata();

            data.dbdefinition    = mDbDefinition;
            data.projectsettings = mProjectSettings;
            data.generatedon     = DateTime.Now;

            XmlSerializer serializer = new XmlSerializer(typeof(pventitygeneratordata));
            StringWriter  writer     = new StringWriter();

            serializer.Serialize(writer, data);

            mDataDocument = new XmlDocument();
            mDataDocument.LoadXml(writer.ToString());
            writer.Close();

            // Path to DB Definition file
            int intPos = pDbDefinitionFile.LastIndexOf("\\");

            if (intPos >= 0)
            {
                mRelRootPath = pDbDefinitionFile.Substring(0, intPos);
                Environment.CurrentDirectory = mRelRootPath;
            }
            else
            {
                mRelRootPath = Environment.CurrentDirectory;
            }

            // in debug mode: save combined xml to filesystem
            if (App.DebugMode)
            {
                mDataDocument.Save(mRelRootPath + "\\debug-data-document.xml");
            }
        }
 public DBDefinitionReader(StatusHandler pStatusHanlder)
 {
     mStatusHandler = pStatusHanlder;
     mXmlSerializer = new XmlSerializer(typeof(dbdefinition));
 }
Ejemplo n.º 3
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.");
            }
        }