Library method from On Application Start

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Library method from On Application Start

Doug Hall-6
I thought I had already posted this email, but apparently it didn't go
through. :-/

I'm trying to read a config file, as shown in the documentation, within
Active4D's "On Application Start" method:

  $path := join paths(default directory(*); "mail.ini")
  if(file exists($path))
    $config := a4d.utils.parseConfig($path)
    globals{"mail.host"}:=$config{"host"}
    log message("email host: "+$config{"host"})
    // a4d.utils.setSMTPHost($config{"host"})
    // log message('SMTP host set to $config{"host"}')
    globals{"mail.to"} := $config{"to"}
    log message("Mail.ini full path: "+$path)
  else
    log message('The email config file: $path does not exist.';true)
  end if

This didn't work. It errors out saying:

Active4D: [error] The specified method does not exist:
/Users/dhall/Documents/AIDTdb/Active4D/Active4D.a4l, method "Active4D.On
Application Start", line 43

Even if I refactor the above part into a Library method
(main.read_email_config) and call that from within On Application Start, it
gives a similar error:

Active4D: [error] The specified method does not exist:
/Users/dhall/Documents/AIDTdb/weblib/main.a4l, method
"main.read_email_config", line 438

Any help would be appreciated,
Doug Hall
_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/
Reply | Threaded
Open this post in threaded view
|

Re: Library method from On Application Start

Aparajita Fishman
Hi Doug,

Please provide complete environment/version info (OS, 4D, Active4D).

> On Jun 26, 2017, at 2:26 PM, Doug Hall <[hidden email]> wrote:
>
> I thought I had already posted this email, but apparently it didn't go
> through. :-/
>
> I'm trying to read a config file, as shown in the documentation, within
> Active4D's "On Application Start" method:
>
> $path := join paths(default directory(*); "mail.ini")
> if(file exists($path))
>   $config := a4d.utils.parseConfig($path)
>   globals{"mail.host"}:=$config{"host"}
>   log message("email host: "+$config{"host"})
>   // a4d.utils.setSMTPHost($config{"host"})
>   // log message('SMTP host set to $config{"host"}')
>   globals{"mail.to"} := $config{"to"}
>   log message("Mail.ini full path: "+$path)
> else
>   log message('The email config file: $path does not exist.';true)
> end if
>
> This didn't work. It errors out saying:
>
> Active4D: [error] The specified method does not exist:
> /Users/dhall/Documents/AIDTdb/Active4D/Active4D.a4l, method "Active4D.On
> Application Start", line 43
>
> Even if I refactor the above part into a Library method
> (main.read_email_config) and call that from within On Application Start, it
> gives a similar error:
>
> Active4D: [error] The specified method does not exist:
> /Users/dhall/Documents/AIDTdb/weblib/main.a4l, method
> "main.read_email_config", line 438
>
> Any help would be appreciated,
> Doug Hall
> _______________________________________________
> Active4D-dev mailing list
> [hidden email]
> http://list.aparajitaworld.com/listinfo/active4d-dev
> Archives: http://active4d-nabble.aparajitaworld.com/

_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/
Reply | Threaded
Open this post in threaded view
|

Re: Library method from On Application Start

Aparajita Fishman
In reply to this post by Doug Hall-6
The error message is exactly correct; a4d.utils.parseConfig doesn't exist! In fact, I can't find any trace of it in the source code. I have no idea what happened to it, or why I so thoroughly documented something that doesn't exist. My apologies!

> On Jun 26, 2017, at 2:26 PM, Doug Hall <[hidden email]> wrote:
>
> I thought I had already posted this email, but apparently it didn't go
> through. :-/
>
> I'm trying to read a config file, as shown in the documentation, within
> Active4D's "On Application Start" method:
>
> $path := join paths(default directory(*); "mail.ini")
> if(file exists($path))
>   $config := a4d.utils.parseConfig($path)
>   globals{"mail.host"}:=$config{"host"}
>   log message("email host: "+$config{"host"})
>   // a4d.utils.setSMTPHost($config{"host"})
>   // log message('SMTP host set to $config{"host"}')
>   globals{"mail.to"} := $config{"to"}
>   log message("Mail.ini full path: "+$path)
> else
>   log message('The email config file: $path does not exist.';true)
> end if
>
> This didn't work. It errors out saying:
>
> Active4D: [error] The specified method does not exist:
> /Users/dhall/Documents/AIDTdb/Active4D/Active4D.a4l, method "Active4D.On
> Application Start", line 43
>
> Even if I refactor the above part into a Library method
> (main.read_email_config) and call that from within On Application Start, it
> gives a similar error:
>
> Active4D: [error] The specified method does not exist:
> /Users/dhall/Documents/AIDTdb/weblib/main.a4l, method
> "main.read_email_config", line 438
>
> Any help would be appreciated,
> Doug Hall
> _______________________________________________
> Active4D-dev mailing list
> [hidden email]
> http://list.aparajitaworld.com/listinfo/active4d-dev
> Archives: http://active4d-nabble.aparajitaworld.com/

_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/
Reply | Threaded
Open this post in threaded view
|

Re: Library method from On Application Start

Doug Hall-6
No problem. I think it's a good idea to have, so that you can have a text
file outside of source control, that maintains different settings between
your test and production servers. Right now, I'm doing a very hackish
condition on the current machine name.

Doug

On Tue, Jun 27, 2017 at 3:16 PM, Aparajita Fishman <[hidden email]>
wrote:

> The error message is exactly correct; a4d.utils.parseConfig doesn't exist!
> In fact, I can't find any trace of it in the source code. I have no idea
> what happened to it, or why I so thoroughly documented something that
> doesn't exist. My apologies!
>
> > On Jun 26, 2017, at 2:26 PM, Doug Hall <[hidden email]> wrote:
> >
> > I thought I had already posted this email, but apparently it didn't go
> > through. :-/
> >
> > I'm trying to read a config file, as shown in the documentation, within
> > Active4D's "On Application Start" method:
> >
> > $path := join paths(default directory(*); "mail.ini")
> > if(file exists($path))
> >   $config := a4d.utils.parseConfig($path)
> >   globals{"mail.host"}:=$config{"host"}
> >   log message("email host: "+$config{"host"})
> >   // a4d.utils.setSMTPHost($config{"host"})
> >   // log message('SMTP host set to $config{"host"}')
> >   globals{"mail.to"} := $config{"to"}
> >   log message("Mail.ini full path: "+$path)
> > else
> >   log message('The email config file: $path does not exist.';true)
> > end if
> >
> > This didn't work. It errors out saying:
> >
> > Active4D: [error] The specified method does not exist:
> > /Users/dhall/Documents/AIDTdb/Active4D/Active4D.a4l, method "Active4D.On
> > Application Start", line 43
> >
> > Even if I refactor the above part into a Library method
> > (main.read_email_config) and call that from within On Application Start,
> it
> > gives a similar error:
> >
> > Active4D: [error] The specified method does not exist:
> > /Users/dhall/Documents/AIDTdb/weblib/main.a4l, method
> > "main.read_email_config", line 438
> >
> > Any help would be appreciated,
> > Doug Hall
> > _______________________________________________
> > Active4D-dev mailing list
> > [hidden email]
> > http://list.aparajitaworld.com/listinfo/active4d-dev
> > Archives: http://active4d-nabble.aparajitaworld.com/
>
> _______________________________________________
> Active4D-dev mailing list
> [hidden email]
> http://list.aparajitaworld.com/listinfo/active4d-dev
> Archives: http://active4d-nabble.aparajitaworld.com/
>
_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/
Reply | Threaded
Open this post in threaded view
|

Re: Library method from On Application Start

Doug Hall-6
I have to comment, here. You have FABULOUS documentation, Aparajita. I have
dealt with other vendors who release new and improved versions of their
software, but haven't touched the documentation for several versions. THAT
pisses me off. Having such thorough documentation for a nonexistent method
might be a little embarrassing to you, but it impresses the hell out of me.
Keep up the good work. In the future, you might want to specifically
indicate those methods that don't exist yet. Hahaha!

Doug

On Thu, Jun 29, 2017 at 8:59 AM, Doug Hall <[hidden email]> wrote:

> No problem. I think it's a good idea to have, so that you can have a text
> file outside of source control, that maintains different settings between
> your test and production servers. Right now, I'm doing a very hackish
> condition on the current machine name.
>
> Doug
>
> On Tue, Jun 27, 2017 at 3:16 PM, Aparajita Fishman <
> [hidden email]> wrote:
>
>> The error message is exactly correct; a4d.utils.parseConfig doesn't
>> exist! In fact, I can't find any trace of it in the source code. I have no
>> idea what happened to it, or why I so thoroughly documented something that
>> doesn't exist. My apologies!
>>
>> > On Jun 26, 2017, at 2:26 PM, Doug Hall <[hidden email]> wrote:
>> >
>> > I thought I had already posted this email, but apparently it didn't go
>> > through. :-/
>> >
>> > I'm trying to read a config file, as shown in the documentation, within
>> > Active4D's "On Application Start" method:
>> >
>> > $path := join paths(default directory(*); "mail.ini")
>> > if(file exists($path))
>> >   $config := a4d.utils.parseConfig($path)
>> >   globals{"mail.host"}:=$config{"host"}
>> >   log message("email host: "+$config{"host"})
>> >   // a4d.utils.setSMTPHost($config{"host"})
>> >   // log message('SMTP host set to $config{"host"}')
>> >   globals{"mail.to"} := $config{"to"}
>> >   log message("Mail.ini full path: "+$path)
>> > else
>> >   log message('The email config file: $path does not exist.';true)
>> > end if
>> >
>> > This didn't work. It errors out saying:
>> >
>> > Active4D: [error] The specified method does not exist:
>> > /Users/dhall/Documents/AIDTdb/Active4D/Active4D.a4l, method
>> "Active4D.On
>> > Application Start", line 43
>> >
>> > Even if I refactor the above part into a Library method
>> > (main.read_email_config) and call that from within On Application
>> Start, it
>> > gives a similar error:
>> >
>> > Active4D: [error] The specified method does not exist:
>> > /Users/dhall/Documents/AIDTdb/weblib/main.a4l, method
>> > "main.read_email_config", line 438
>> >
>> > Any help would be appreciated,
>> > Doug Hall
>> > _______________________________________________
>> > Active4D-dev mailing list
>> > [hidden email]
>> > http://list.aparajitaworld.com/listinfo/active4d-dev
>> > Archives: http://active4d-nabble.aparajitaworld.com/
>>
>> _______________________________________________
>> Active4D-dev mailing list
>> [hidden email]
>> http://list.aparajitaworld.com/listinfo/active4d-dev
>> Archives: http://active4d-nabble.aparajitaworld.com/
>>
>
>
_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/
Reply | Threaded
Open this post in threaded view
|

Re: Library method from On Application Start

Aparajita Fishman
In reply to this post by Doug Hall-6
I'm sure I must have written it at one point, it was pretty simple to rewrite:

/***********************************************************************************
        parseConfig

        $inPathOrDocRef -> File to parse
        $inEOL -> EOL used by config file
        RESULT <- Collection with key/value pairs read from file
***********************************************************************************/

method "parseConfig"($inPathOrDocRef; $inEOL = "\n")

        $config := new collection
        c_time($doc)

        if (type($inPathOrDocRef) = is text)
                $doc := open document($inPathOrDocRef)
        else
                $doc := $inPathOrDocRef
        end if

        if ($doc # ?00:00:00?)
                c_text($text)
                receive packet($doc; $text; maxlong)

                if (type($inPathOrDocRef) = is text)
                        close document($doc)
                end if

                array text($lines; 0)
                split string($text; $inEOL; $lines; false)
                array text($matches; 0)

                for each ($lines; $line)
                        if (left trim($line) # "//@")
                                if (regex match("/^(.+?)=(.*)$/"; $line; $matches))
                                        $key := trim($matches{1})

                                        if ($key)
                                                $config{$key} := trim($matches{2})
                                        end if
                                end if
                        end if
                end for each

        end if

        return ($config)

end method

This is exactly as documented with the exception that the old style 4D comments are not recognized, only // comments.

> On Jun 29, 2017, at 6:59 AM, Doug Hall <[hidden email]> wrote:
>
> No problem. I think it's a good idea to have, so that you can have a text
> file outside of source control, that maintains different settings between
> your test and production servers. Right now, I'm doing a very hackish
> condition on the current machine name.
>
> Doug
>
> On Tue, Jun 27, 2017 at 3:16 PM, Aparajita Fishman <[hidden email]>
> wrote:
>
>> The error message is exactly correct; a4d.utils.parseConfig doesn't exist!
>> In fact, I can't find any trace of it in the source code. I have no idea
>> what happened to it, or why I so thoroughly documented something that
>> doesn't exist. My apologies!
>>
>>> On Jun 26, 2017, at 2:26 PM, Doug Hall <[hidden email]> wrote:
>>>
>>> I thought I had already posted this email, but apparently it didn't go
>>> through. :-/
>>>
>>> I'm trying to read a config file, as shown in the documentation, within
>>> Active4D's "On Application Start" method:
>>>
>>> $path := join paths(default directory(*); "mail.ini")
>>> if(file exists($path))
>>>  $config := a4d.utils.parseConfig($path)
>>>  globals{"mail.host"}:=$config{"host"}
>>>  log message("email host: "+$config{"host"})
>>>  // a4d.utils.setSMTPHost($config{"host"})
>>>  // log message('SMTP host set to $config{"host"}')
>>>  globals{"mail.to"} := $config{"to"}
>>>  log message("Mail.ini full path: "+$path)
>>> else
>>>  log message('The email config file: $path does not exist.';true)
>>> end if
>>>
>>> This didn't work. It errors out saying:
>>>
>>> Active4D: [error] The specified method does not exist:
>>> /Users/dhall/Documents/AIDTdb/Active4D/Active4D.a4l, method "Active4D.On
>>> Application Start", line 43
>>>
>>> Even if I refactor the above part into a Library method
>>> (main.read_email_config) and call that from within On Application Start,
>> it
>>> gives a similar error:
>>>
>>> Active4D: [error] The specified method does not exist:
>>> /Users/dhall/Documents/AIDTdb/weblib/main.a4l, method
>>> "main.read_email_config", line 438
>>>
>>> Any help would be appreciated,
>>> Doug Hall
>>> _______________________________________________
>>> Active4D-dev mailing list
>>> [hidden email]
>>> http://list.aparajitaworld.com/listinfo/active4d-dev
>>> Archives: http://active4d-nabble.aparajitaworld.com/
>>
>> _______________________________________________
>> Active4D-dev mailing list
>> [hidden email]
>> http://list.aparajitaworld.com/listinfo/active4d-dev
>> Archives: http://active4d-nabble.aparajitaworld.com/
>>
> _______________________________________________
> Active4D-dev mailing list
> [hidden email]
> http://list.aparajitaworld.com/listinfo/active4d-dev
> Archives: http://active4d-nabble.aparajitaworld.com/

_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/
Reply | Threaded
Open this post in threaded view
|

Re: Library method from On Application Start

Doug Hall-6
Thanks!

On Thu, Jun 29, 2017 at 12:54 PM, Aparajita Fishman <[hidden email]
> wrote:

> I'm sure I must have written it at one point, it was pretty simple to
> rewrite:
>
> /***********************************************************
> ************************
>         parseConfig
>
>         $inPathOrDocRef         ->      File to parse
>         $inEOL                          ->      EOL used by config file
>         RESULT                          <-      Collection with key/value
> pairs read from file
> ************************************************************
> ***********************/
>
> method "parseConfig"($inPathOrDocRef; $inEOL = "\n")
>
>         $config := new collection
>         c_time($doc)
>
>         if (type($inPathOrDocRef) = is text)
>                 $doc := open document($inPathOrDocRef)
>         else
>                 $doc := $inPathOrDocRef
>         end if
>
>         if ($doc # ?00:00:00?)
>                 c_text($text)
>                 receive packet($doc; $text; maxlong)
>
>                 if (type($inPathOrDocRef) = is text)
>                         close document($doc)
>                 end if
>
>                 array text($lines; 0)
>                 split string($text; $inEOL; $lines; false)
>                 array text($matches; 0)
>
>                 for each ($lines; $line)
>                         if (left trim($line) # "//@")
>                                 if (regex match("/^(.+?)=(.*)$/"; $line;
> $matches))
>                                         $key := trim($matches{1})
>
>                                         if ($key)
>                                                 $config{$key} :=
> trim($matches{2})
>                                         end if
>                                 end if
>                         end if
>                 end for each
>
>         end if
>
>         return ($config)
>
> end method
>
> This is exactly as documented with the exception that the old style 4D
> comments are not recognized, only // comments.
>
> > On Jun 29, 2017, at 6:59 AM, Doug Hall <[hidden email]> wrote:
> >
> > No problem. I think it's a good idea to have, so that you can have a text
> > file outside of source control, that maintains different settings between
> > your test and production servers. Right now, I'm doing a very hackish
> > condition on the current machine name.
> >
> > Doug
> >
> > On Tue, Jun 27, 2017 at 3:16 PM, Aparajita Fishman <
> [hidden email]>
> > wrote:
> >
> >> The error message is exactly correct; a4d.utils.parseConfig doesn't
> exist!
> >> In fact, I can't find any trace of it in the source code. I have no idea
> >> what happened to it, or why I so thoroughly documented something that
> >> doesn't exist. My apologies!
> >>
> >>> On Jun 26, 2017, at 2:26 PM, Doug Hall <[hidden email]> wrote:
> >>>
> >>> I thought I had already posted this email, but apparently it didn't go
> >>> through. :-/
> >>>
> >>> I'm trying to read a config file, as shown in the documentation, within
> >>> Active4D's "On Application Start" method:
> >>>
> >>> $path := join paths(default directory(*); "mail.ini")
> >>> if(file exists($path))
> >>>  $config := a4d.utils.parseConfig($path)
> >>>  globals{"mail.host"}:=$config{"host"}
> >>>  log message("email host: "+$config{"host"})
> >>>  // a4d.utils.setSMTPHost($config{"host"})
> >>>  // log message('SMTP host set to $config{"host"}')
> >>>  globals{"mail.to"} := $config{"to"}
> >>>  log message("Mail.ini full path: "+$path)
> >>> else
> >>>  log message('The email config file: $path does not exist.';true)
> >>> end if
> >>>
> >>> This didn't work. It errors out saying:
> >>>
> >>> Active4D: [error] The specified method does not exist:
> >>> /Users/dhall/Documents/AIDTdb/Active4D/Active4D.a4l, method
> "Active4D.On
> >>> Application Start", line 43
> >>>
> >>> Even if I refactor the above part into a Library method
> >>> (main.read_email_config) and call that from within On Application
> Start,
> >> it
> >>> gives a similar error:
> >>>
> >>> Active4D: [error] The specified method does not exist:
> >>> /Users/dhall/Documents/AIDTdb/weblib/main.a4l, method
> >>> "main.read_email_config", line 438
> >>>
> >>> Any help would be appreciated,
> >>> Doug Hall
> >>> _______________________________________________
> >>> Active4D-dev mailing list
> >>> [hidden email]
> >>> http://list.aparajitaworld.com/listinfo/active4d-dev
> >>> Archives: http://active4d-nabble.aparajitaworld.com/
> >>
> >> _______________________________________________
> >> Active4D-dev mailing list
> >> [hidden email]
> >> http://list.aparajitaworld.com/listinfo/active4d-dev
> >> Archives: http://active4d-nabble.aparajitaworld.com/
> >>
> > _______________________________________________
> > Active4D-dev mailing list
> > [hidden email]
> > http://list.aparajitaworld.com/listinfo/active4d-dev
> > Archives: http://active4d-nabble.aparajitaworld.com/
>
> _______________________________________________
> Active4D-dev mailing list
> [hidden email]
> http://list.aparajitaworld.com/listinfo/active4d-dev
> Archives: http://active4d-nabble.aparajitaworld.com/
>
_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/