Beispiel #1
0
                                 public void UT_SomeTest()
                                 {
                                     string    _parsedOutput;
                                     Hashtable _hash = new Hashtable();

                                     _hash.Add("Lines", 3);

                                     ParserASPX.Parse(
                                         template_dir_,
                                         template_file_,
                                         _hash,
                                         out _parsedOutput
                                         );

                                     Assert.AreEqual(
                                         "1#2#3#",
                                         _parsedOutput,
                                         "Expected \"1#2#3#\" output, not: {0}",
                                         _parsedOutput
                                         );
                                 }
Beispiel #2
0
        private void notifyme(
            string message_in
            )
        {
            // ToDos: here!
//			cDBConnection _con = null;

            #region int _verifiedConditions = ...;
            int _verifiedConditions = 0;
            for (int c = 0; c < templates_.TemplateCollection[template_].Conditions.ConditionCollection.Count; c++)
            {
                if (
                    translate(
                        templates_.TemplateCollection[template_].Conditions.ConditionCollection[c].Eval,
                        message_in
                        )
                    ==
                    templates_.TemplateCollection[template_].Conditions.ConditionCollection[c].To
                    )
                {
                    _verifiedConditions++;
                }
            }
            #endregion
            if (_verifiedConditions == templates_.TemplateCollection[template_].Conditions.ConditionCollection.Count)
            {
                #region Hashtable _args = ...;
                Hashtable _args = new Hashtable(templates_.TemplateCollection[template_].Arguments.ArgumentCollection.Count);
                for (int a = 0; a < templates_.TemplateCollection[template_].Arguments.ArgumentCollection.Count; a++)
                {
                    _args.Add(
                        templates_.TemplateCollection[template_].Arguments.ArgumentCollection[a].Name,
                        //System.Web.HttpUtility.UrlEncode(
                        translateFully(
                            templates_.TemplateCollection[template_].Arguments.ArgumentCollection[a].Value,
                            message_in
                            )
                        //)
                        );
                }
                #endregion
                for (int o = 0; o < templates_.TemplateCollection[template_].Outputs.OutputCollection.Count; o++)
                {
                    #region if (!dbconnectionstrings_.Contains(DBServerTypes. ...)) continue;
                    switch (templates_.TemplateCollection[template_].Outputs.OutputCollection[o].Type)
                    {
                        #region case XS_OutputEnumeration.someDBServer_whatever: ... break;
#if PostgreSQL
                    case XS_OutputEnumeration.PostgreSQL_Function:
                    case XS_OutputEnumeration.PostgreSQL_StoredProcedure:
                    case XS_OutputEnumeration.PostgreSQL_View: {
                        if (!dbconnectionstrings_.Contains_disableIfNot(DBServerTypes.PostgreSQL))
                        {
                            continue;
                        }
//							_con = (cDBConnection)connection_[DBServerTypes.PostgreSQL];
                        break;
                    }
#endif
#if MySQL
                    case XS_OutputEnumeration.MySQL_Function:
                    case XS_OutputEnumeration.MySQL_StoredProcedure:
                    case XS_OutputEnumeration.MySQL_View: {
                        if (!dbconnectionstrings_.Contains_disableIfNot(DBServerTypes.MySQL))
                        {
                            continue;
                        }
//							_con = (cDBConnection)connection_[DBServerTypes.MySQL];
                        break;
                    }
#endif
                    case XS_OutputEnumeration.SQLServer_Function:
                    case XS_OutputEnumeration.SQLServer_StoredProcedure:
                    case XS_OutputEnumeration.SQLServer_View: {
                        if (!dbconnectionstrings_.Contains_disableIfNot(DBServerTypes.SQLServer))
                        {
                            continue;
                        }
//							_con = (cDBConnection)connection_[DBServerTypes.SQLServer];
                        break;
                    }
                        #endregion
                    }
                    #endregion
                    string _ouputTo = translateFully(
                        templates_.TemplateCollection[template_].Outputs.OutputCollection[o].To,
                        message_in
                        );
//					#region bool _exists = ...;
                    bool _exists_aux = false;
                    for (int d = 0; d < dbconnectionstrings_.Count; d++)
                    {
                        dbconnectionstrings_[d].exists_aux__ = false;
                    }
                    switch (templates_.TemplateCollection[template_].Outputs.OutputCollection[o].Type)
                    {
                    case XS_OutputEnumeration.File: {
                        _exists_aux = File.Exists(_ouputTo);
                        break;
                    }

                        #region case XS_OutputEnumeration.someDBServer_whatever: ... break;
                    case XS_OutputEnumeration.MySQL_Function:
                    case XS_OutputEnumeration.PostgreSQL_Function:
                    case XS_OutputEnumeration.SQLServer_Function: {
//_exists = _con.SQLFunction_exists(_ouputTo);
                        for (int d = 0; d < dbconnectionstrings_.Count; d++)
                        {
                            if (!dbconnectionstrings_[d].enabled_aux__)
                            {
                                continue;
                            }

                            dbconnectionstrings_[d].exists_aux__
                                = dbconnectionstrings_[d].Connection.SQLFunction_exists(_ouputTo);

                            if (!_exists_aux && dbconnectionstrings_[d].exists_aux__)
                            {
                                _exists_aux = true;
                            }
                        }
                        break;
                    }

                    case XS_OutputEnumeration.MySQL_StoredProcedure:
                    case XS_OutputEnumeration.PostgreSQL_StoredProcedure:
                    case XS_OutputEnumeration.SQLServer_StoredProcedure: {
//_exists = _con.SQLStoredProcedure_exists(_ouputTo);
                        for (int d = 0; d < dbconnectionstrings_.Count; d++)
                        {
                            if (!dbconnectionstrings_[d].enabled_aux__)
                            {
                                continue;
                            }

                            dbconnectionstrings_[d].exists_aux__
                                = dbconnectionstrings_[d].Connection.SQLStoredProcedure_exists(_ouputTo);

                            if (!_exists_aux && dbconnectionstrings_[d].exists_aux__)
                            {
                                _exists_aux = true;
                            }
                        }
                        break;
                    }

                    case XS_OutputEnumeration.MySQL_View:
                    case XS_OutputEnumeration.PostgreSQL_View:
                    case XS_OutputEnumeration.SQLServer_View: {
//_exists = _con.SQLView_exists(_ouputTo);
                        for (int d = 0; d < dbconnectionstrings_.Count; d++)
                        {
                            if (!dbconnectionstrings_[d].enabled_aux__)
                            {
                                continue;
                            }

                            dbconnectionstrings_[d].exists_aux__
                                = dbconnectionstrings_[d].Connection.SQLView_exists(_ouputTo);

                            if (!_exists_aux && dbconnectionstrings_[d].exists_aux__)
                            {
                                _exists_aux = true;
                            }
                        }
                        break;
                    }
                        #endregion

                    default: {
                        throw notifyme_Exception;
                    }
                    }
//					#endregion

                    if (
                        !_exists_aux
                        ||
                        (templates_.TemplateCollection[template_].Outputs.OutputCollection[o].Mode == XS_OutputModeEnumeration.Replace)
                        ||
                        (templates_.TemplateCollection[template_].Outputs.OutputCollection[o].Mode == XS_OutputModeEnumeration.Append)
                        )
                    {
                        #region string _parsedOutput = ...;
                        string _parsedOutput;
                        if (templates_.TemplateCollection[template_].ParserType == XS_ParserEnumeration.xslt)
                        {
                            System.Text.StringBuilder _stringbuilder = new System.Text.StringBuilder();
                            StringWriter _stringwriter = new StringWriter(_stringbuilder);

                            string _xmltemplatesfile
                                = xmltemplatesdir_
                                  + (xmltemplatesfileuri_.IsFile
                                                                        ? Path.DirectorySeparatorChar.ToString()
                                                                        : "/")
                                  + templates_.TemplateCollection[template_].Name;
                            ParserXSLT.Parse(
//xmlmetadatafile_,
                                metafiles_[
                                    utils.MetaFile_find(
                                        metafiles_,
                                        message_in.Split('.')[1]
                                        )
                                ].Path,
                                _xmltemplatesfile,
                                _args,
                                _stringwriter
                                );

                            _parsedOutput = _stringbuilder.ToString();
                        }
                        else
                        {
                            if (xmltemplatesfileuri_.IsFile)
                            {
                                switch (templates_.TemplateCollection[template_].ParserType)
                                {
                                case XS_ParserEnumeration.aspx: {
                                    ParserASPX.Parse(
                                        xmltemplatesdir_,
                                        templates_.TemplateCollection[template_].Name,
                                        _args,
                                        out _parsedOutput
                                        );
                                    break;
                                }

                                case XS_ParserEnumeration.none: {
                                    if (templates_.TemplateCollection[template_].Outputs.OutputCollection[o].Type == XS_OutputEnumeration.File)
                                    {
                                        _parsedOutput = null; // will be copied
                                    }
                                    else
                                    {
                                        // needs to be read
                                        _parsedOutput = new StreamReader(
                                            Path.Combine(
                                                xmltemplatesdir_,
                                                templates_.TemplateCollection[template_].Name
                                                )
                                            ).ReadToEnd();
                                    }

                                    break;
                                }

                                default: {
                                    // ToDos: here!
                                    throw new Exception("ToDos: here!");
                                }
                                }
                            }
                            else
                            {
                                switch (templates_.TemplateCollection[template_].ParserType)
                                {
                                case XS_ParserEnumeration.aspx:
                                case XS_ParserEnumeration.none: {
                                    _parsedOutput = OGen.lib.presentationlayer.webforms.utils.ReadURL_ToString(
                                        xmltemplatesdir_ + "/" + templates_.TemplateCollection[template_].Name,
                                        _args
                                        );
                                    break;
                                }

                                default: {
                                    // ToDos: here!
                                    throw new Exception("ToDos: here!");
                                }
                                }
                            }
                        }
                        #endregion

                        switch (templates_.TemplateCollection[template_].Outputs.OutputCollection[o].Type)
                        {
                        case XS_OutputEnumeration.File: {
                            if (
                                (_ouputTo == string.Empty)
                                ||
                                (Directory.Exists(_ouputTo))
                                )
                            {
                                break;
                            }

                            #region Directory.CreateDirectory(_ouputTo);
                            string _directory = System.IO.Path.GetDirectoryName(_ouputTo);
                            if (!System.IO.Directory.Exists(_directory))
                            {
                                System.IO.Directory.CreateDirectory(
                                    _directory
                                    );
                            }
                            #endregion
                            if (
                                (templates_.TemplateCollection[template_].ParserType == XS_ParserEnumeration.none)
                                &&
                                (xmltemplatesfileuri_.IsFile)
                                )
                            {
//									#region File.Copy(...);
// ToDos: here!
                                if (
                                    (templates_.TemplateCollection[template_].Outputs.OutputCollection[o].Mode == XS_OutputModeEnumeration.Append)
                                    )
                                {
                                    throw new Exception(string.Format("not implemented (at template: {0})", templates_.TemplateCollection[template_].Name));
                                }
                                File.Copy(
                                    Path.Combine(
                                        xmltemplatesdir_,
                                        templates_.TemplateCollection[template_].Name
                                        ),
                                    _ouputTo,
                                    true                                             // (!_exists || templates_.TemplateCollection[template_].Outputs.OutputCollection[o].Replace)
                                    );
//									#endregion
                            }
                            else
                            {
                                #region new StreamWriter(_ouputTo).Write(_parsedOutput);
                                StreamWriter _writer = new StreamWriter(
                                    _ouputTo,
                                    (templates_.TemplateCollection[template_].Outputs.OutputCollection[o].Mode == XS_OutputModeEnumeration.Append)
                                    );
                                _writer.Write(_parsedOutput);
                                _writer.Close();
                                #endregion
                            }
                            break;
                        }

                            #region case XS_OutputEnumeration.someDBServer_whatever: ... break;
                        case XS_OutputEnumeration.MySQL_Function:
                        case XS_OutputEnumeration.MySQL_StoredProcedure:
                        case XS_OutputEnumeration.MySQL_View:
                        case XS_OutputEnumeration.PostgreSQL_Function:
                        case XS_OutputEnumeration.PostgreSQL_StoredProcedure:
                        case XS_OutputEnumeration.PostgreSQL_View:
                        case XS_OutputEnumeration.SQLServer_Function:
                        case XS_OutputEnumeration.SQLServer_StoredProcedure:
                        case XS_OutputEnumeration.SQLServer_View: {
                            if (templates_.TemplateCollection[template_].Outputs.OutputCollection[o].Mode == XS_OutputModeEnumeration.Append)
                            {
                                throw new Exception("can't handle append over a db function");
                            }

//								#region if (_exists_aux) connection_.Function_delete(_ouputTo);
                            if (_exists_aux)
                            {
                                switch (templates_.TemplateCollection[template_].Outputs.OutputCollection[o].Type)
                                {
                                case XS_OutputEnumeration.MySQL_Function:
                                case XS_OutputEnumeration.SQLServer_Function: {
//_con.SQLFunction_delete(_ouputTo);
                                    for (int d = 0; d < dbconnectionstrings_.Count; d++)
                                    {
                                        if (!dbconnectionstrings_[d].enabled_aux__)
                                        {
                                            continue;
                                        }

                                        switch (dbconnectionstrings_[d].DBServerType)
                                        {
#if MySQL
                                        case DBServerTypes.MySQL:
#endif
                                        case DBServerTypes.SQLServer: {
                                            if (dbconnectionstrings_[d].exists_aux__)
                                            {
                                                dbconnectionstrings_[d].Connection.SQLFunction_delete(_ouputTo);
                                            }
                                            break;
                                        }
                                        }
                                    }
                                    break;
                                }

                                case XS_OutputEnumeration.MySQL_StoredProcedure:
                                case XS_OutputEnumeration.SQLServer_StoredProcedure: {
//_con.SQLStoredProcedure_delete(_ouputTo);
                                    for (int d = 0; d < dbconnectionstrings_.Count; d++)
                                    {
                                        if (!dbconnectionstrings_[d].enabled_aux__)
                                        {
                                            continue;
                                        }

                                        switch (dbconnectionstrings_[d].DBServerType)
                                        {
#if MySQL
                                        case DBServerTypes.MySQL:
#endif
                                        case DBServerTypes.SQLServer: {
                                            if (dbconnectionstrings_[d].exists_aux__)
                                            {
                                                dbconnectionstrings_[d].Connection.SQLStoredProcedure_delete(_ouputTo);
                                            }
                                            break;
                                        }
                                        }
                                    }
                                    break;
                                }

                                case XS_OutputEnumeration.MySQL_View:
                                case XS_OutputEnumeration.SQLServer_View: {
//_con.SQLView_delete(_ouputTo);
                                    for (int d = 0; d < dbconnectionstrings_.Count; d++)
                                    {
                                        if (!dbconnectionstrings_[d].enabled_aux__)
                                        {
                                            continue;
                                        }

                                        switch (dbconnectionstrings_[d].DBServerType)
                                        {
#if MySQL
                                        case DBServerTypes.MySQL:
#endif
                                        case DBServerTypes.SQLServer: {
                                            if (dbconnectionstrings_[d].exists_aux__)
                                            {
                                                dbconnectionstrings_[d].Connection.SQLView_delete(_ouputTo);
                                            }
                                            break;
                                        }
                                        }
                                    }
                                    break;
                                }

                                case XS_OutputEnumeration.PostgreSQL_Function:
                                case XS_OutputEnumeration.PostgreSQL_StoredProcedure:
                                case XS_OutputEnumeration.PostgreSQL_View:
                                    // No Need! unlike SQL Server and MySQL,
                                    // PostgreSQL allows:
                                    // "CREATE OR REPLACE FUNCTION/VIEW" :)
                                    break;

                                default: {
                                    break;
                                }
                                }
                            }
//								#endregion
//_con.Execute_SQLQuery(_parsedOutput);
                            for (int d = 0; d < dbconnectionstrings_.Count; d++)
                            {
                                if (!dbconnectionstrings_[d].enabled_aux__)
                                {
                                    continue;
                                }
                                try {
                                    dbconnectionstrings_[d].Connection.Execute_SQLQuery(_parsedOutput);
                                } catch (Exception _ex) {
                                    throw new Exception(string.Format(
                                                            "---\nTEMPLATE: {0}\n---\nQUERY:\n\n{1}\n---\nDBServerType:\n\n{2}\n---\nEXCEPTION:\n\n{3}\n---\nINNER-EXCEPTION:\n\n{4}\n---\n",
                                                            templates_.TemplateCollection[template_].Name,
                                                            _parsedOutput,
                                                            dbconnectionstrings_[d].DBServerType.ToString(),
                                                            _ex.Message,
                                                            _ex.InnerException
                                                            ));
                                }
                            }
                            break;
                        }

                            #endregion
                        default: {
                            throw notifyme_Exception;
                        }
                        }
                    }
                }
            }
        }