This project is read-only.

Program doesn't work if no start script.

Topics: Bug Report, Development Help
Aug 4, 2007 at 5:06 PM
I've download the latest source code (2518) and try to compile it myself. Everything works fine except program won't start if no startup scripts exists.

After some debugging I found that:
- The key press event handler won't work only if commandStart is initialized
- commandStart is only initialized in SetPrompt()
- SetPrompt() is only called by PoshHost::Prompt()
- This is only called in OnPipelineStateChanged(), which means some scripts/cmd have been executed
- But if I don't have any startup scripts, nothing is executed...

So the question is if there is other way to trigger the prompt. Like a default action if no script is executed?

P.S. It's not easy to debug with so many event handlers, delegates, and Invoke...

Coordinator
Aug 8, 2007 at 6:11 PM

cookiez wrote:
- SetPrompt() is only called by PoshHost::Prompt()
- This is only called in OnPipelineStateChanged(), which means some scripts/cmd have been executed


Actually, in ExecuteStartupProfile() if there are no scripts found, then we call Prompt() directly ... is that not working properly?


P.S. It's not easy to debug with so many event handlers, delegates, and Invoke...


Yeah, tell me about it. The checkins I've been making recently are to attempt to clean that up some: to get rid of the extra delegates that I created. However, ultimately a huge portion of the API for PoSh is calls from the Pipeline to the GUI, that has to cross thread boundries.

I've been thinking about that recently ... the biggest problem seems to stem from the fact that the RichTextBox I used as an underlying control doesn't have any separation of model from view, so any calls which attempt to change the data or read the data have to execute on the view thread. Maybe I'll have to layer that underneath somehow.
Aug 11, 2007 at 1:03 PM
{quote}
Jaykul wrote:

Actually, in ExecuteStartupProfile() if there are no scripts found, then we call Prompt() directly ... is that not working properly?


Don't see that Prompt() in ExecuteStartupProfile()...

I've to change ExecuteStartupProfile() like this,
if (script.Length > 0)
{
ExecutePipeline(new Command(script.ToString(), true, true), result => ExecutePromptFunction());
}
else
{
ExecutePipeline(new Command("", true, true), result => ExecutePromptFunction());
}

Btw, it seems the input focus is not in the RichTextConsole which could be annoying...

Yes, I've a lot of bugs waiting for you. I'm a test engineer...
Coordinator
Aug 12, 2007 at 4:27 AM

cookiez wrote:

Don't see that Prompt() in ExecuteStartupProfile()...


You're clearly looking at the .Net 3.5 version not the 2.0 one. I don't know if that one even worked in 2518 (and you'll really have to bug Jachymko about it, because I haven't even tried compiling it yet).


This is what it looks like in my version of checkin 2518...
       /// <summary>
       /// Executes the startup profile(s).
       /// </summary>
       internal void ExecuteStartupProfile()
       {
           //* %windir%\system32\WindowsPowerShell\v1.0\profile.ps1
           //  This profile applies to all users and all shells.
           //* %windir%\system32\WindowsPowerShell\v1.0\Huddled.PoshConsole_profile.ps1
           //  This profile applies to all users, but only to the Microsoft.PowerShell shell.
           //* %UserProfile%\My Documents\WindowsPowerShell\profile.ps1
           //  This profile applies only to the current user, but affects all shells.
           //* %UserProfile%\My Documents\WindowsPowerShell\Huddled.PoshConsole_profile.ps1
           //  This profile applies only to the current user and the Microsoft.PowerShell shell.
 
           StringBuilder cmd = new StringBuilder();
           foreach (string path in
                new string[4] {
                   System.IO.Path.GetFullPath(System.IO.Path.Combine(Environment.SystemDirectory , @"WindowsPowerShell\v1.0\profile.ps1")),
                   System.IO.Path.GetFullPath(System.IO.Path.Combine(Environment.SystemDirectory , @"WindowsPowerShell\v1.0\Huddled.PoshConsole_profile.ps1")),
                   System.IO.Path.GetFullPath(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"WindowsPowerShell\profile.ps1")),
                   System.IO.Path.GetFullPath(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"WindowsPowerShell\Huddled.PoshConsole_profile.ps1")),
               })
           {
               if (File.Exists(path))
               {
                   cmd.AppendFormat(". \"{0}\";", path);
               }
           }
           if (cmd.Length > 0)
           {
               try
               {
                   ExecuteHelper(cmd.ToString(), null, false);
               }
               catch (RuntimeException rte)
               {
                   // An exception occurred that we want to display ...
                   // We have to run another pipeline, and pass in the error record.
                   // The runtime will bind the input to the $input variable
                   ExecuteHelper("write-host ($input | out-string) -fore darkyellow", rte.ErrorRecord, false);
               }
           }
           else
           {
               Prompt();
           }
       }
Aug 12, 2007 at 4:00 PM
o yes i'm using the trunk-3.5 one. You mean these are actually different projects? gosh...
Coordinator
Aug 12, 2007 at 10:52 PM
Well, no, not exactly, it's just that the 'trunk 3.5' started as a port to Visual Studio 2008 and .Net 3.5, but it's also gone through a lot of refactoring, and it's where Jachymko's been working on adding WCF remoting, etc.

Basically we currently have parallel development on two trunks which keeps them somewhat out of sync with each other. :)
Aug 13, 2007 at 8:59 AM
I see... So which one is the main branch or the "leading" branch?
Coordinator
Aug 13, 2007 at 10:43 PM
The 'trunk' is where all releases have come from.

The 'trunk 3.5' is where the experimental stuff like remoting and LINQ and such are going in.