/// <summary>
        /// Provides startup services
        /// </summary>
        protected override void StartMyServices()
        {
            base.StartMyServices();

            try
            {
                // assimilate the proprties of the starting executable
                this.MorphAttributesToReflectStartingExecutable();

                // use the window positioning engine to manage our state
                WindowPositioningEngine.WindowPositioningEngineSnapIn.Instance.Manage(this, WindowPositioningEngineKey);

                // wire up to previous instance events
                SnapInHostingEngine.GetExecutingInstance().InstanceManager.CommandLineReceivedFromAnotherInstance += new ApplicationInstanceManagerEventHandler(OnCommandLineReceivedFromAnotherInstance);

                // add ourself as a top level window to the hosting engine's application context
                SnapInHostingEngine.Instance.ApplicationContext.AddTopLevelWindow(this);

                // show ourself
                this.Show();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
        }
        /// <summary>
        /// Provides shutdown services
        /// </summary>
        protected override void StopMyServices()
        {
            base.StopMyServices();

            // wire up to previous instance events
            SnapInHostingEngine.GetExecutingInstance().InstanceManager.CommandLineReceivedFromAnotherInstance -= new ApplicationInstanceManagerEventHandler(OnCommandLineReceivedFromAnotherInstance);

            // close ourself
            this.Close();
        }
        public static void Main(string[] args)
        {
            bool tracedExceptionThrown = false;

            try
            {
                // define the data paths
                string subPath = @"CodeReflection\Razor";

                // safely use a hosting engine configured with an additional common data path and additional local user data path
                using (SnapInHostingEngine host = new SnapInHostingEngine(subPath, subPath))
                {
                    try
                    {
                        // run the hosting engine using the command line and the currently executing assembly (aka. the exe for the process)
                        host.Run(args, System.Reflection.Assembly.GetExecutingAssembly());
                    }
                    catch (System.Exception systemException)
                    {
                        // flag the fact that we are going to trace this exception and rethrow it
                        tracedExceptionThrown = true;

                        // give the loggers a chance to catch it if they have been successfully loaded before the
                        // host is disposed of and the logging sub system detached from the Trace and Debug output
                        System.Diagnostics.Trace.WriteLine(systemException);

                        // rethrow the exception so that it may be displayed for the user
                        throw systemException;
                    }
                }
            }
            catch (System.Exception systemException)
            {
                // if the exception hasn't already been traced
                if (!tracedExceptionThrown)
                {
                    tracedExceptionThrown = true;
                    // trace it now
                    System.Diagnostics.Trace.WriteLine(systemException);
                }

                // also, since it's more likely we'll not have a debugger attached, display the exception to the user
                string info = string.Format("The following exception was thrown by '{0}'.\n\nPlease refer to the log files for further information.\n\n{1}", Application.ProductName, systemException.ToString());

                System.Windows.Forms.MessageBox.Show(null, info, "Application Exception");

                // exit the current thread to force safe application shutdown
                Application.ExitThread();
            }
            finally
            {
                // one final trace to let everyone know we have shutdown completely
                System.Diagnostics.Trace.WriteLine("'" + Application.ProductName + "' has " + (tracedExceptionThrown ? "terminated because of an exception." : "exited gracefully."));
            }
        }
        public SnapInDescriptorsWindow(SnapInDescriptor[] descriptors)
        {
            this.InitializeComponent();
            this.InitializesSortManagers();
            this.DisplayDescriptors(descriptors);
//			this.SelectFirstItem();

            SnapInHostingEngine.GetExecutingInstance().SnapInStarted     += new SnapInDescriptorEventHandler(SnapInDescriptorsWindow_SnapInStarted);
            SnapInHostingEngine.GetExecutingInstance().SnapInStopped     += new SnapInDescriptorEventHandler(SnapInDescriptorsWindow_SnapInStopped);
            SnapInHostingEngine.GetExecutingInstance().SnapInInstalled   += new SnapInDescriptorEventHandler(SnapInDescriptorsWindow_SnapInInstalled);
            SnapInHostingEngine.GetExecutingInstance().SnapInUninstalled += new SnapInDescriptorEventHandler(SnapInDescriptorsWindow_SnapInUninstalled);
        }
Exemple #5
0
 /// <summary>
 /// Returns an instance of the ISnapIn that supports the Type specified by the SubClass of this SnapInProxy.
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="hostingEngine"></param>
 /// <returns></returns>
 public bool GetInstance(out object instance)
 {
     instance = null;
     try
     {
         SnapInDescriptor descriptor = SnapInHostingEngine.GetExecutingInstance().FindDescriptorByType(this.GetTypeForReferenceInternal());
         if (descriptor != null)
         {
             instance = descriptor.SnapIn;
             return(true);
         }
     }
     catch (System.Exception systemException)
     {
         _lastException = systemException;
     }
     return(false);
 }
 private void DisplayReferencesFor(TreeNodeCollection nodes, SnapInDescriptor descriptor)
 {
     foreach (Type t in descriptor.Dependencies)
     {
         SnapInDescriptor dependencyDescriptor = SnapInHostingEngine.GetExecutingInstance().FindDescriptorByType(t);
         if (dependencyDescriptor != null)
         {
             TreeNode node = new TreeNode(dependencyDescriptor.MetaData.Title);
             node.Tag = dependencyDescriptor;
             if (dependencyDescriptor.IsUninstalled)
             {
                 node.ForeColor = SystemColors.GrayText;
             }
             node.Nodes.Add(string.Empty);
             nodes.Add(node);
         }
     }
 }
        private void DisplayReferencesTo(TreeNodeCollection nodes, SnapInDescriptor descriptor)
        {
            SnapInDescriptor[] descriptors = SnapInHostingEngine.GetExecutingInstance().SnapInDescriptors;

            foreach (SnapInDescriptor otherDescriptor in descriptors)
            {
                foreach (Type t in otherDescriptor.Dependencies)
                {
                    if (t == descriptor.Type)
                    {
                        TreeNode node = new TreeNode(otherDescriptor.MetaData.Title);
                        node.Tag = otherDescriptor;
                        if (otherDescriptor.IsUninstalled)
                        {
                            node.ForeColor = SystemColors.GrayText;
                        }
                        node.Nodes.Add(string.Empty);
                        nodes.Add(node);
                    }
                }
            }
        }
        /// <summary>
        /// Reflect upon the starting executable and snag it's properties
        /// </summary>
        protected void MorphAttributesToReflectStartingExecutable()
        {
            try
            {
                Assembly assembly = SnapInHostingEngine.GetExecutingInstance().StartingExecutable;
                if (assembly != null)
                {
                    // snag the name of the file minus path and extention and set it as the heading
                    string filename = System.IO.Path.GetFileName(assembly.Location);
                    filename = filename.Replace(System.IO.Path.GetExtension(assembly.Location), null);

                    AssemblyAttributeReader reader = new AssemblyAttributeReader(assembly);

                    // snag the company that made the assembly, and set it in the title
                    System.Reflection.AssemblyCompanyAttribute[] companyAttributes = reader.GetAssemblyCompanyAttributes();
                    if (companyAttributes != null)
                    {
                        if (companyAttributes.Length > 0)
                        {
                            if (companyAttributes[0].Company != null && companyAttributes[0].Company != string.Empty)
                            {
                                this.Text = filename;                                 // companyAttributes[0].Company + " " + filename;
                            }
                        }
                    }
                    // snag the image from the assembly, it should be an executable so...
                    Icon icon = ShellInformation.GetIconFromPath(assembly.Location, IconSizes.SmallIconSize, IconStyles.NormalIconStyle, FileAttributes.Normal);
                    if (icon != null)
                    {
                        this.Icon = icon;
                    }
                }
            }
            catch (System.Exception systemException)
            {
                System.Diagnostics.Trace.WriteLine(systemException);
            }
        }
        private void OnMenuItemClick(object sender, System.EventArgs e)
        {
            SnapInDescriptor descriptor = null;

            try
            {
                ListViewItem item = _listView.SelectedItems[0];
                if (item != null)
                {
                    descriptor = item.Tag as SnapInDescriptor;
                }
            }
            catch (System.Exception systemException)
            {
                System.Diagnostics.Trace.WriteLine(systemException);
            }

            MenuItem menuItem = sender as MenuItem;

            if (menuItem != null)
            {
                if (menuItem == menuItemStart)
                {
                    if (descriptor != null)
                    {
                        SnapInHostingEngine.StartWithProgress(descriptor);
                    }
                }

                if (menuItem == menuItemStop)
                {
                    if (descriptor != null)
                    {
                        SnapInHostingEngine.StopWithProgress(descriptor);
                    }
                }

                if (menuItem == menuItemReinstall)
                {
                    if (descriptor != null)
                    {
                        SnapInHostingEngine.ReinstallWithProgress(descriptor);
                    }
                }

                if (menuItem == menuItemUninstall)
                {
                    if (descriptor != null)
                    {
                        SnapInHostingEngine.StopAndUninstallWithProgress(descriptor);
                    }
                }

                if (menuItem == menuItemProperties)
                {
                    if (descriptor != null)
                    {
                        SnapInDescriptorPropertyWindow window = new SnapInDescriptorPropertyWindow(descriptor);
                        window.ShowDialog(this);
                    }
                }
            }
        }
 /// <summary>
 /// Occurs when the Options menu item is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnOptionsClicked(object sender, EventArgs e)
 {
     SnapInHostingEngine.GetExecutingInstance().ShowConfigurationWindow(this);
 }
 /// <summary>
 /// Occurs when the SnapIns menu item is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnSnapInsClicked(object sender, EventArgs e)
 {
     SnapInHostingEngine.GetExecutingInstance().ShowSnapInsWindow(this);
 }
 /// <summary>
 /// Occurs when the Features menu item is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnFeaturesClicked(object sender, EventArgs e)
 {
     FeatureEngine.ShowFeatureWindow(this, SnapInHostingEngine.GetExecutingInstance());
 }
Exemple #13
0
 /// <summary>
 /// Occurs when a window position listener needs a configuration to read/write to/from
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnListenerNeedsConfiguration(object sender, XmlConfigurationEventArgs e)
 {
     /// save everything to the local user configuration
     e.Element = SnapInHostingEngine.GetExecutingInstance().LocalUserConfiguration;
 }
 private void buttonReInstall_Click(object sender, System.EventArgs e)
 {
     SnapInHostingEngine.ReinstallWithProgress(_descriptor);
     this.UpdateButtonsBasedOnAdvice();
 }