コード例 #1
0
        /// <summary>
        ///     Initiates the startup routine and configures the runspace for use.
        /// </summary>
        public void Start(SnoopUI ui)
        {
            Invoke(string.Format("new-psdrive {0} {0} -root /", ShellConstants.DriveName));

            // synchronize selected and root tree elements
            ui.PropertyChanged += (sender, e) => {
                switch (e.PropertyName)
                {
                case "CurrentSelection":
                    SetVariable(ShellConstants.Selected, ui.CurrentSelection);
                    break;

                case "Root":
                    SetVariable(ShellConstants.Root, ui.Root);
                    break;
                }
            };

            // allow scripting of the host controls
            SetVariable("snoopui", ui);
            SetVariable("ui", this);

            // marshall back to the UI thread when the provider notifiers of a location change
            var action =
                new Action <VisualTreeItem>(
                    item => Dispatcher.BeginInvoke(new Action(() => ProviderLocationChanged(item))));

            SetVariable(ShellConstants.LocationChangedActionKey, action);

            var folder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Scripts");

            Invoke(string.Format("import-module \"{0}\"", Path.Combine(folder, ShellConstants.SnoopModule)));

            outputTextBox.Clear();
            Invoke("write-host 'Welcome to the Snoop PowerShell console!'");
            Invoke("write-host '----------------------------------------'");
            Invoke(string.Format("write-host 'To get started, try using the ${0} and ${1} variables.'",
                                 ShellConstants.Root, ShellConstants.Selected));

            FindAndLoadProfile(folder);
        }
コード例 #2
0
        /// <summary>
        /// Initiates the startup routine and configures the runspace for use.
        /// </summary>
        public void Start(SnoopUI ui)
        {
            Invoke(string.Format("new-psdrive {0} {0} -root /", ShellConstants.DriveName));

            // synchronize selected and root tree elements
            ui.PropertyChanged += (sender, e) =>
            {
                switch (e.PropertyName)
                {
                    case "CurrentSelection":
                        SetVariable(ShellConstants.Selected, ui.CurrentSelection);
                        break;
                    case "Root":
                        SetVariable(ShellConstants.Root, ui.Root);
                        break;
                }
            };

            // allow scripting of the host controls
            SetVariable("snoopui", ui);
            SetVariable("ui", this);

            // marshall back to the UI thread when the provider notifiers of a location change
            var action = new Action<VisualTreeItem>(item => this.Dispatcher.BeginInvoke(new Action(() => this.ProviderLocationChanged(item))));
            this.SetVariable(ShellConstants.LocationChangedActionKey, action);

            string folder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Scripts");
            Invoke(string.Format("import-module \"{0}\"", Path.Combine(folder, ShellConstants.SnoopModule)));

            this.outputTextBox.Clear();
            Invoke("write-host 'Welcome to the Snoop PowerShell console!'");
            Invoke("write-host '----------------------------------------'");
            Invoke(string.Format("write-host 'To get started, try using the ${0} and ${1} variables.'", ShellConstants.Root, ShellConstants.Selected));

            FindAndLoadProfile(folder);
        }
コード例 #3
0
        /// <summary>
        /// Initiates the startup routine and configures the runspace for use.
        /// </summary>
        private void Start(SnoopUI targetSnoopUi)
        {
            if (this.isStarted)
            {
                return;
            }

            if (ShellConstants.IsPowerShellInstalled == false)
            {
                return;
            }

            this.isStarted = true;

            this.snoopUi = targetSnoopUi;

            {
                // ignore execution-policy
                var iis = InitialSessionState.CreateDefault();
                iis.AuthorizationManager = new AuthorizationManager(Guid.NewGuid().ToString());
                iis.Providers.Add(new SessionStateProviderEntry(ShellConstants.DriveName, typeof(VisualTreeProvider), string.Empty));

                this.host     = new SnoopPSHost(this.outputTextBox, x => this.outputTextBox.AppendText(x));
                this.runspace = RunspaceFactory.CreateRunspace(this.host, iis);
                this.runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;

#if NET40
                this.runspace.ApartmentState = System.Threading.ApartmentState.STA;
#endif

                this.runspace.Open();
            }

            {
                targetSnoopUi.PropertyChanged += this.OnSnoopUiOnPropertyChanged;

                // allow scripting of the host controls
                this.SetVariable("snoopui", targetSnoopUi);
                this.SetVariable("ui", this);
                this.SetVariable(ShellConstants.Root, targetSnoopUi.Root);
                this.SetVariable(ShellConstants.Selected, targetSnoopUi.CurrentSelection);

                // marshall back to the UI thread when the provider notifiers of a location change
                var action = new Action <TreeItem>(item => this.RunInDispatcherAsync(() => this.ProviderLocationChanged?.Invoke(item)));
                this.SetVariable(ShellConstants.LocationChangedActionKey, action);

                var folder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "..", "Scripts");
                this.Invoke($"import-module \"{Path.Combine(folder, ShellConstants.SnoopModule)}\"");

                this.outputTextBox.Clear();

                this.Invoke("write-host 'Welcome to the Snoop PowerShell console!'");
                this.Invoke("write-host '----------------------------------------'");
                this.Invoke($"write-host 'To get started, try using the ${ShellConstants.Root} and ${ShellConstants.Selected} variables.'");

                this.FindAndLoadProfile(folder);

                this.NotifySelected(targetSnoopUi.CurrentSelection);
            }

            {
                // sync the current location
                targetSnoopUi.Tree.SelectedItemChanged += this.OnSnoopUiSelectedItemChanged;
                this.ProviderLocationChanged           += this.OnProviderLocationChanged;

                // clean up garbage!
                targetSnoopUi.Closed += this.OnSnoopUiClosed;
            }
        }
コード例 #4
0
 public MainWindow()
 {
     InitializeComponent();
     SnoopUI.SnoopApplication();
 }
コード例 #5
0
 public TreeListSource(SnoopUI ui) : base(new ObservableCollection <VisualTreeItem>())
 {
     this.ui             = ui;
     ProtectedMethods    = this.Wrap <ITreeListSource>();
     ui.PropertyChanged += OnUIPropertyChanged;
 }