/// <summary>
        /// Sorts an array of SnapInDescriptors from least dependent first to most dependent last, or vice versa
        /// </summary>
        /// <param name="descriptors">The array of descriptors to sort</param>
        /// <param name="leastDependentFirst">The order in which to sort them</param>
        /// <returns></returns>
        public static bool Sort(SnapInDescriptor[] descriptors, bool leastDependentFirst)
        {
            try
            {
                // front to back - 1
                for (int i = 0; i < descriptors.Length - 1; i++)
                {
                    // front + 1 to back
                    for (int j = i + 1; j < descriptors.Length; j++)
                    {
                        bool dependsOn = descriptors[i].DependsOn(descriptors[j]);
                        if ((leastDependentFirst ? dependsOn : !dependsOn))
                        {
                            // swap i with j, where i=1 and j=2
                            SnapInDescriptor descriptor = descriptors[j];
                            descriptors[j] = descriptors[i];
                            descriptors[i] = descriptor;
                        }
                    }
                }
//				foreach(SnapInDescriptor descriptor in descriptors)
//					System.Diagnostics.Trace.WriteLine(descriptor.Type.Name);
                return(true);
            }
            catch (System.Exception systemException)
            {
                System.Diagnostics.Trace.WriteLine(systemException);
            }
            return(false);
        }
        private void DisplayDescriptor(SnapInDescriptor descriptor)
        {
//			using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
//			{
//				descriptor.MetaData.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Icon);
//				this.Icon = new Icon(ms, 16, 16);
//			}
//			_informationPanel.Image = descriptor.MetaData.Image;
            _informationPanel.Title       = descriptor.MetaData.Title;
            _informationPanel.Description = descriptor.MetaData.Description;

//			this.pictureBoxImage.Image = descriptor.MetaData.Image;
//			this.labelTitle.Text = descriptor.MetaData.Title;
//			this.labelDescription.Text = descriptor.MetaData.Description;
            this.labelCompany.Text = descriptor.MetaData.CompanyName;
            this.labelVersion.Text = descriptor.MetaData.Version.ToString();
            this.textBoxPath.Text  = descriptor.Type.Assembly.Location;

            foreach (string developer in descriptor.MetaData.Developers)
            {
                this.listBoxDevelopers.Items.Add(developer);
            }

            foreach (string productFamily in descriptor.MetaData.ProductFamilies)
            {
                this.listBoxProductFamilies.Items.Add(productFamily);
            }

            this.DisplayDependencyInformation();

            this.DisplayTroubleshootingInformation();
        }
 public static void AdviseOnActionsThatCanBeTaken(
     SnapInDescriptor descriptor,
     out bool canStart,
     out bool canStop,
     out bool canReinstall,
     out bool canUninstall)
 {
     // if there is a snapin selected
     if (descriptor != null)
     {
         if (descriptor.IsUninstalled)
         {
             canStart     = false;
             canStop      = false;
             canReinstall = true;
             canUninstall = false;
         }
         else
         {
             canStart     = !descriptor.IsStarted;
             canStop      = descriptor.IsStarted;
             canReinstall = false;
             canUninstall = true;
         }
     }
     else
     {
         // but you can't do anything without a snapin selected
         canStart     = false;
         canStop      = false;
         canReinstall = false;
         canUninstall = false;
     }
 }
Пример #4
0
 public void Remove(SnapInDescriptor descriptor)
 {
     if (this.Contains(descriptor))
     {
         base.InnerList.Remove(descriptor);
     }
 }
Пример #5
0
 public int Add(SnapInDescriptor descriptor)
 {
     if (!this.Contains(descriptor))
     {
         int index = base.InnerList.Add(descriptor);
         return(index);
     }
     return(-1);
 }
		public int Add(SnapInDescriptor descriptor)
		{
			if (!this.Contains(descriptor))
			{
				int index = base.InnerList.Add(descriptor);
				return index;
			}
			return -1;
		}
		/// <summary>
		/// Determines if this descriptor depends upon the Type described by the specified descriptor
		/// </summary>
		/// <param name="descriptor"></param>
		/// <returns></returns>
		public bool DependsOn(SnapInDescriptor descriptor)
		{
//			string info = string.Format("Determining if Type '{0}' depends on Type '{1}'", _type.Name, descriptor.Type.Name);
//			System.Diagnostics.Trace.WriteLine(info);

			foreach(Type t in _dependencies)
				if (Type.Equals(t, descriptor.Type))
					return true;
			return false;
		}
 /// <summary>
 /// Determines if one descriptor is a direct dependency of another descriptor
 /// </summary>
 /// <param name="descriptorA">The Type to look for in B's dependencies</param>
 /// <param name="descriptorB">The descriptor in whose dependencies to look for A</param>
 /// <returns></returns>
 public static bool IsDirectDependencyOf(SnapInDescriptor descriptorA, SnapInDescriptor descriptorB)
 {
     foreach (Type type in descriptorB.Dependencies)
     {
         if (descriptorA.Type == type)
         {
             return(true);
         }
     }
     return(false);
 }
		public SnapInDescriptorPropertyWindow(SnapInDescriptor descriptor)
		{
			this.InitializeComponent();
			
			// save a reference to the descriptors
			_descriptor = descriptor;
			
			// display all of the information about the descriptor
			this.DisplayDescriptor(descriptor);

			this.UpdateButtonsBasedOnAdvice();			
		}
        public SnapInDescriptorPropertyWindow(SnapInDescriptor descriptor)
        {
            this.InitializeComponent();

            // save a reference to the descriptors
            _descriptor = descriptor;

            // display all of the information about the descriptor
            this.DisplayDescriptor(descriptor);

            this.UpdateButtonsBasedOnAdvice();
        }
		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);
		}
 private void SnapInDescriptorsWindow_SnapInUninstalled(object sender, SnapInDescriptorEventArgs e)
 {
     foreach (ListViewItem item in _listView.Items)
     {
         SnapInDescriptor descriptor = item.Tag as SnapInDescriptor;
         if (descriptor != null)
         {
             if (descriptor == e.Descriptor)
             {
                 item.ForeColor = SystemColors.GrayText;
             }
         }
     }
 }
        /// <summary>
        /// Determines if this descriptor depends upon the Type described by the specified descriptor
        /// </summary>
        /// <param name="descriptor"></param>
        /// <returns></returns>
        public bool DependsOn(SnapInDescriptor descriptor)
        {
//			string info = string.Format("Determining if Type '{0}' depends on Type '{1}'", _type.Name, descriptor.Type.Name);
//			System.Diagnostics.Trace.WriteLine(info);

            foreach (Type t in _dependencies)
            {
                if (Type.Equals(t, descriptor.Type))
                {
                    return(true);
                }
            }
            return(false);
        }
 private void UpdateStatus(SnapInDescriptor descriptor)
 {
     foreach (ListViewItem item in _listView.Items)
     {
         SnapInDescriptor d = item.Tag as SnapInDescriptor;
         if (d != null)
         {
             if (d == descriptor)
             {
                 item.SubItems[2].Text = (descriptor.IsStarted ? "Started" : null);
             }
         }
     }
 }
        private void UpdateContextMenu(SnapInDescriptor descriptor)
        {
            bool canStart;
            bool canStop;
            bool canReinstall;
            bool canUninstall;

            SnapInDescriptor.AdviseOnActionsThatCanBeTaken(descriptor, out canStart, out canStop, out canReinstall, out canUninstall);

            this.menuItemStart.Enabled     = canStart;
            this.menuItemStop.Enabled      = canStop;
            this.menuItemReinstall.Enabled = canReinstall;
            this.menuItemUninstall.Enabled = canUninstall;
        }
 private void OnListViewMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         ListViewItem item = _listView.GetItemAt(e.X, e.Y);
         if (item != null)
         {
             SnapInDescriptor descriptor = item.Tag as SnapInDescriptor;
             if (descriptor != null)
             {
                 this.UpdateContextMenu(descriptor);
                 _contextMenu.Show(_listView, new Point(e.X, e.Y));
             }
         }
     }
 }
Пример #17
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 OnListViewDoubleClick(object sender, System.EventArgs e)
 {
     try
     {
         ListViewItem item = _listView.SelectedItems[0];
         if (item != null)
         {
             SnapInDescriptor descriptor = item.Tag as SnapInDescriptor;
             if (descriptor != null)
             {
                 SnapInDescriptorPropertyWindow window = new SnapInDescriptorPropertyWindow(descriptor);
                 window.ShowDialog(this);
             }
         }
     }
     catch (System.Exception systemException)
     {
         System.Diagnostics.Trace.WriteLine(systemException);
     }
 }
        private void UpdateButtonsBasedOnAdvice()
        {
            bool canStart;
            bool canStop;
            bool canReinstall;
            bool canUninstall;

            SnapInDescriptor.AdviseOnActionsThatCanBeTaken(_descriptor, out canStart, out canStop, out canReinstall, out canUninstall);

            this.buttonStart.Enabled     = canStart;
            this.buttonStop.Enabled      = canStop;
            this.buttonReInstall.Enabled = canReinstall;
            this.buttonUninstall.Enabled = canUninstall;

//			/// if there is a snapin selected
//			if (_descriptor != null)
//			{
//				if (_descriptor.IsUninstalled)
//				{
//					this.buttonStart.Enabled = false;
//					this.buttonStop.Enabled  = false;
//					this.buttonReInstall.Enabled = true;
//					this.buttonUninstall.Enabled = false;
//				}
//				else
//				{
//					this.buttonStart.Enabled = !_descriptor.IsStarted;
//					this.buttonStop.Enabled  = _descriptor.IsStarted;
//					this.buttonReInstall.Enabled = false;
//					this.buttonUninstall.Enabled = true;
//				}
//			}
//			else
//			{
//				/// but you can't do anything without a snapin selected
//				this.buttonStart.Enabled = false;
//				this.buttonStop.Enabled = false;
//				this.buttonReInstall.Enabled = false;
//				this.buttonUninstall.Enabled = false;
//			}
        }
        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);
                    }
                }
            }
        }
		public SnapInDescriptorCollection(SnapInDescriptor[] descriptors)
		{
			foreach(SnapInDescriptor descriptor in descriptors)
				this.Add(descriptor);
		}
		/// <summary>
		/// Determines if one descriptor is a direct dependency of another descriptor 
		/// </summary>
		/// <param name="descriptorA">The Type to look for in B's dependencies</param>
		/// <param name="descriptorB">The descriptor in whose dependencies to look for A</param>
		/// <returns></returns>
		public static bool IsDirectDependencyOf(SnapInDescriptor descriptorA, SnapInDescriptor descriptorB)
		{
			foreach(Type type in descriptorB.Dependencies)
				if (descriptorA.Type == type)
					return true;
			return false;
		}
		/// <summary>
		/// Initializes a new instance of the SnapInDescriptorLink class
		/// </summary>
		public SnapInDescriptorLink(SnapInDescriptor descriptor)
		{
			_descriptor = descriptor;			
			_links = new ArrayList();
		}
		public static void AdviseOnActionsThatCanBeTaken(
			SnapInDescriptor descriptor, 
			out bool canStart, 
			out bool canStop, 
			out bool canReinstall, 
			out bool canUninstall)
		{			
			// if there is a snapin selected
			if (descriptor != null)
			{			
				if (descriptor.IsUninstalled)
				{
					canStart = false;
					canStop  = false;
					canReinstall = true;
					canUninstall = false;
				}
				else
				{
					canStart = !descriptor.IsStarted;
					canStop  = descriptor.IsStarted;
					canReinstall = false;
					canUninstall = true;
				}
			}
			else
			{
				// but you can't do anything without a snapin selected
				canStart = false;
				canStop = false;
				canReinstall = false;
				canUninstall = false;
			}		
		}
		/// <summary>
		/// Flags all descriptors that have dependencies that are missing dependencies
		/// </summary>
		/// <param name="descriptors"></param>
		public static void MarkDescriptorsThatHaveDependenciesThatAreMissingADependency(SnapInDescriptor[] descriptors)
		{
			foreach(SnapInDescriptor descriptor in descriptors)
			{
				foreach(Type a in descriptor.Dependencies)
				{
					foreach(SnapInDescriptor otherDescriptor in descriptors)
					{
						if (otherDescriptor.Type == a)
						{
							if (otherDescriptor.IsMissingDependency)
							{
								descriptor._isDependentOnTypeThatIsMissingDependency = true;							
							}

							// stop looking at the other descriptors
							if (descriptor.IsDependentOnTypeThatIsMissingDependency)
								break;
						}
					}

					// stop looking at the dependencies, it's already done
					if (descriptor.IsDependentOnTypeThatIsMissingDependency)
						break;
				}
			}
		}
		public void Remove(SnapInDescriptor descriptor)
		{
			if (this.Contains(descriptor))
				base.InnerList.Remove(descriptor);
		}
		/// <summary>
		/// Sorts an array of SnapInDescriptors from least dependent first to most dependent last, or vice versa
		/// </summary>
		/// <param name="descriptors">The array of descriptors to sort</param>
		/// <param name="leastDependentFirst">The order in which to sort them</param>
		/// <returns></returns>
		public static bool Sort(SnapInDescriptor[] descriptors, bool leastDependentFirst)
		{	
			try
			{
				// front to back - 1 
				for(int i = 0; i < descriptors.Length - 1; i++)
				{
					// front + 1 to back
					for(int j = i + 1; j < descriptors.Length; j++)
					{				
						bool dependsOn = descriptors[i].DependsOn(descriptors[j]);
						if ((leastDependentFirst ? dependsOn : !dependsOn))
						{											 
							// swap i with j, where i=1 and j=2
							SnapInDescriptor descriptor = descriptors[j];
							descriptors[j] = descriptors[i];
							descriptors[i] = descriptor;
						}													
					}
				}
//				foreach(SnapInDescriptor descriptor in descriptors)
//					System.Diagnostics.Trace.WriteLine(descriptor.Type.Name);
				return true;
			}
			catch(System.Exception systemException)
			{	
				System.Diagnostics.Trace.WriteLine(systemException);
			}
			return false;
		}
		public static void ReinstallWithProgress(SnapInDescriptor descriptor)
		{
			try
			{
				using (ProgressWindowThread thread = new ProgressWindowThread())
				{
					thread.ShowAsynchronously();
					ProgressViewer.SetTitle(thread.Window, "SnapIn Hosting Engine Progress...");
					ProgressViewer.SetHeading(thread.Window, "Installing " + descriptor.MetaData.Title);
					ProgressViewer.SetDescription(thread.Window, "This operation may take several seconds.");	
				
					System.Threading.Thread.Sleep(1000);
					SnapInHostingEngine.Install(descriptor, false, thread.Window);
					System.Threading.Thread.Sleep(1000);
				}
			}
			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);
                    }
                }
            }
        }
		public static bool StopWithProgress(SnapInDescriptor descriptor)
		{
			bool result = false;
			try
			{
				using (ProgressWindowThread thread = new ProgressWindowThread())
				{
					thread.ShowAsynchronously();
					ProgressViewer.SetTitle(thread.Window, "SnapIn Hosting Engine Progress...");
					ProgressViewer.SetHeading(thread.Window, "Stopping " + descriptor.MetaData.Title);
					ProgressViewer.SetDescription(thread.Window, "This operation may take several seconds.");					
					
					System.Threading.Thread.Sleep(1000);
					result = SnapInHostingEngine.Stop(descriptor, true, thread.Window);
					System.Threading.Thread.Sleep(1000);
				}
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}
			return result;
		}
		/// <summary>
		/// (Downwards) Creates a chain of descriptors for all of the snapins that depend on the specified snapin, this is recursive and will graph the entire tree
		/// </summary>
		/// <param name="descriptor"></param>
		/// <param name="descriptors"></param>
		/// <returns></returns>
		public static SnapInDescriptorLink CreateDependencyChainForSnapInsThatDependOnThisSnapIn(SnapInDescriptor descriptor, SnapInDescriptor[] descriptors)
		{
			// create a new link for the descriptor specified
			SnapInDescriptorLink link = new SnapInDescriptorLink(descriptor);

			// find any other descriptors that depend on the specified descriptor passed in
			foreach(SnapInDescriptor otherDescriptor in descriptors)
			{
				foreach(Type dependency in otherDescriptor.Dependencies)
				{
					if (Type.Equals(descriptor.Type, dependency))
					{
						// find all of that dependency's chain, and do it recursively (Downwards)
						SnapInDescriptorLink nextLink = SnapInHostingEngine.CreateDependencyChainForSnapInsThatDependOnThisSnapIn(otherDescriptor, descriptors);							
						link.Links.Add(nextLink);
					}
				}
			}
			return link;
		}
		/// <summary>
		/// Stops the SnapIn specified by the descriptor (Handles stopping dependents first optionally, and the writing of options)
		/// </summary>
		/// <param name="descriptor"></param>
		/// <param name="progressViewer"></param>
		public static bool Stop(SnapInDescriptor descriptor, bool stopDependentsFirst, IProgressViewer progressViewer)
		{
			try
			{			
				if (descriptor.IsStarted)
				{
					bool linksStopped = true;
					if (stopDependentsFirst)
					{
						// create the chain
						SnapInDescriptorLink link = SnapInHostingEngine.CreateDependencyChainForSnapInsThatDependOnThisSnapIn(descriptor, SnapInHostingEngine.GetExecutingInstance().SnapInDescriptors);
						
						// stop each link in the chain, this method will walk the chain recursively until all links have been stopped
						linksStopped = SnapInHostingEngine.StopLink(link, progressViewer);

						if (!linksStopped)
						{
							// something f****d up, one the snapins that depends on us did not stop
							// so we cannot stop
						}
					}
							
					if (linksStopped && descriptor.IsStarted)
					{
						ProgressViewer.SetExtendedDescription(progressViewer, "Stopping the '" + descriptor.MetaData.Title + "' SnapIn...");

						// stop the snapin
						System.Diagnostics.Trace.WriteLineIf(_verbose, string.Format("Stopping SnapIn '{0}'", descriptor.Type.FullName));
						descriptor.SnapIn.OnStop(null, System.EventArgs.Empty);				
						descriptor._isStarted = false;

						// raise the stop event
						SnapInHostingEngine.GetExecutingInstance().OnSnapInStopped(SnapInHostingEngine.GetExecutingInstance(), new SnapInDescriptorEventArgs(descriptor));

						// force the snapin to write it's options
						SnapInHostingEngine.TriggerWriteOptions(descriptor, progressViewer);

						ProgressViewer.SetExtendedDescription(progressViewer, descriptor.MetaData.Title + " stopped successfully.");

						return true;
					}
				}
				// it's already stopped
				return true;
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}
			return false;
		}
		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);
					}
				}
			}			
		}	
		private void DisplayDescriptor(SnapInDescriptor descriptor)
		{
//			using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
//			{
//				descriptor.MetaData.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Icon);
//				this.Icon = new Icon(ms, 16, 16);
//			}
//			_informationPanel.Image = descriptor.MetaData.Image;
			_informationPanel.Title = descriptor.MetaData.Title;
			_informationPanel.Description = descriptor.MetaData.Description;

//			this.pictureBoxImage.Image = descriptor.MetaData.Image;						
//			this.labelTitle.Text = descriptor.MetaData.Title;
//			this.labelDescription.Text = descriptor.MetaData.Description;
			this.labelCompany.Text = descriptor.MetaData.CompanyName;
			this.labelVersion.Text = descriptor.MetaData.Version.ToString();
			this.textBoxPath.Text = descriptor.Type.Assembly.Location;

			foreach(string developer in descriptor.MetaData.Developers)
				this.listBoxDevelopers.Items.Add(developer);

			foreach(string productFamily in descriptor.MetaData.ProductFamilies)
				this.listBoxProductFamilies.Items.Add(productFamily);

			this.DisplayDependencyInformation();

			this.DisplayTroubleshootingInformation();
		}
		/// <summary>
		/// (Upwards) Creates a chain of descriptors for all of the snapins that this snapin depends upon, this is recursive and will graph the entire tree
		/// </summary>
		/// <param name="descriptor"></param>
		/// <param name="descriptors"></param>
		/// <returns></returns>
		public static SnapInDescriptorLink CreateDependencyChainForSnapInsThatThisSnapInDependsOn(SnapInDescriptor descriptor, SnapInDescriptor[] descriptors)
		{
			// create a new link for the descriptor specified
			SnapInDescriptorLink link = new SnapInDescriptorLink(descriptor);

			// find any descriptors that this descriptor depends on
			foreach(Type dependency in descriptor.Dependencies)
			{
				foreach(SnapInDescriptor otherDescriptor in descriptors)
				{
					if (Type.Equals(otherDescriptor.Type, dependency))
					{
						// find all of the dependency's chain, and do it resursiviely (Upwards)
						SnapInDescriptorLink nextLink = SnapInHostingEngine.CreateDependencyChainForSnapInsThatThisSnapInDependsOn(otherDescriptor, descriptors);
						link.Links.Add(nextLink);
					}	
				}
			}
			return link;
		}
		/// <summary>
		/// Flags all descriptors that are missing dependencies
		/// </summary>
		/// <param name="descriptors"></param>
		public static void MarkDescriptorsThatAreMissingDependencies(SnapInDescriptor[] descriptors)
		{
			// allow each descriptor to determine if any dependencies are missing
			foreach(SnapInDescriptor descriptor in descriptors)
				descriptor.DetermineIfAnyDependenciesAreMissing(descriptors);
		}
		public void AddRange(SnapInDescriptor[] descriptors)
		{
			foreach(SnapInDescriptor descriptor in descriptors)
				this.Add(descriptor);
		}
		private void DisplayDescriptors(SnapInDescriptor[] descriptors)
		{
			try
			{
				_listView.BeginUpdate();
				_listView.Items.Clear();
				_listView.Sorting = SortOrder.Ascending;

				foreach(SnapInDescriptor descriptor in descriptors)
				{
					ListViewItem item = new ListViewItem(descriptor.MetaData.Title);
					item.SubItems.Add(descriptor.MetaData.Description);
					item.SubItems.Add((descriptor.IsStarted ? "Started" : null));
					item.Tag = descriptor;
					
					// use the descriptors image if we can
					item.ImageIndex = _smallImageList.Images.Count;
					_smallImageList.Images.Add(descriptor.MetaData.Image);					
					
					// mark those that are uninstalled
					if (descriptor.IsUninstalled)
						item.ForeColor = SystemColors.GrayText;

					_listView.Items.Add(item);
				}

				_listView.EndUpdate();
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}
		}        
		public bool Contains(SnapInDescriptor descriptor)
		{
			return false;
		}
		private void UpdateStatus(SnapInDescriptor descriptor)
		{
			foreach(ListViewItem item in _listView.Items)
			{
				SnapInDescriptor d = item.Tag as SnapInDescriptor;
				if (d != null)
				{
					if (d == descriptor)
					{
						item.SubItems[2].Text = (descriptor.IsStarted ? "Started" : null);
					}
				}
			}
		}
		/// <summary>
		/// Determines if any depdencies are missing
		/// </summary>
		/// <param name="dependencies">The array of Types that are the dependencies</param>
		/// <param name="snapIns">The list of SnapIns to confirm against</param>
		/// <returns></returns>
		private bool DetermineIfAnyDependenciesAreMissing(Type[] dependencies, SnapInDescriptor[] descriptors)
		{
			// if any type is missing, that means that it's assembly wasn't loaded, and therefore the type
			// cannot be created. 
			foreach(Type type in dependencies)
			{
				if ((object)type == Type.Missing)
					return true;
			}
			
			// now that we know no types are missing, they are all loaded, we need to make sure that all of the 
			// classes that were snapins are loaded, if one of our dependencies isn't in the list of snapins
			// we can't load because a dependency is still missing
			foreach(Type type in dependencies)
			{
				bool found = false;
				foreach(SnapInDescriptor descriptor in descriptors)
				{
					if (!descriptor.IsUninstalled)
					{
						if (descriptor.Type == type)
						{
							found = true;
							break;
						}
					}
				}
				
				if (!found)
					return true;
			}

			return false;
		}
		private void UpdateContextMenu(SnapInDescriptor descriptor)
		{
			bool canStart;
			bool canStop;
			bool canReinstall;
			bool canUninstall;

			SnapInDescriptor.AdviseOnActionsThatCanBeTaken(descriptor, out canStart, out canStop, out canReinstall, out canUninstall);

			this.menuItemStart.Enabled = canStart;
			this.menuItemStop.Enabled  = canStop;
			this.menuItemReinstall.Enabled = canReinstall;
			this.menuItemUninstall.Enabled = canUninstall;
		}
 /// <summary>
 /// Initializes a new instance of the SnapInDescriptorLink class
 /// </summary>
 public SnapInDescriptorLink(SnapInDescriptor descriptor)
 {
     _descriptor = descriptor;
     _links      = new ArrayList();
 }
		/// <summary>
		/// Flags all descriptors that are circularly dependent
		/// </summary>
		/// <param name="descriptors"></param>
		public static void MarkDescriptorsThatAreCircularlyDependent(SnapInDescriptor[] descriptors)
		{
			// check each descriptor's dependencies
			foreach(SnapInDescriptor descriptor in descriptors)
			{
				// check each dependency in that descriptor
				foreach(Type a in descriptor.Dependencies)
				{
					// against all the other descriptors
					foreach(SnapInDescriptor otherDescriptor in descriptors)
					{
						// if the descriptor describes the type that is the dependency of the descriptor in question
						if (otherDescriptor.Type == a)
						{
							// that the other descriptor does not contain a direct dependency of the first descriptor
							foreach(Type b in otherDescriptor.Dependencies)
							{
								// if the two descriptors, have a dependency that point to one another, then it is considered circularly dependent
								if (Type.Equals(descriptor.Type, b))
								{
									// mark the descriptor as circularly dependent, and stop looking at this particular other descriptor
									descriptor._isCircularlyDependent = true;
									break;
								}
							}
							
							// if the descriptor is circularly dependent, then we can stop comparing it to the other descriptors
							if (descriptor.IsCircularlyDependent)
								break;
						}
					}
				}
			}
		}
Пример #46
0
 public bool Contains(SnapInDescriptor descriptor)
 {
     return(false);
 }
		public SnapInDescriptorEventArgs(SnapInDescriptor descriptor)
		{
			_descriptor = descriptor;
		}
		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);
				}
			}
		}
		/// <summary>
		/// Allows the descriptor to determine if any of it's dependencies are missing, whether it be the assembly that is missing, or just the Type not being listed as another SnapIn
		/// </summary>
		/// <param name="snapInDescriptors">The descriptors to check against</param>
		public void DetermineIfAnyDependenciesAreMissing(SnapInDescriptor[] descriptors)
		{
			_isMissingDependency = this.DetermineIfAnyDependenciesAreMissing(_dependencies, descriptors);
		}
 public SnapInDescriptorEventArgs(SnapInDescriptor descriptor)
 {
     _descriptor = descriptor;
 }
		/// <summary>
		/// Starts the SnapIn specified by the descriptor (Handles installation, upgrades, and reading options)
		/// </summary>
		/// <param name="descriptor"></param>
		/// <param name="progressViewer"></param>
		public static bool Start(SnapInDescriptor descriptor, bool startDependenciesFirst, IProgressViewer progressViewer)
		{
			try
			{
				if (descriptor != null)
				{
					// if the snapin is not missing a dependency, cicularly referencing another snapin, or the same for it's dependencies
					if (!descriptor.IsUninstalled &&
						!descriptor.IsMissingDependency &&
						!descriptor.IsCircularlyDependent &&
						!descriptor.IsDependentOnTypeThatIsMissingDependency &&
						!descriptor.IsDependentOnTypeThatIsCircularlyDependent)
					{
						if (!descriptor.IsStarted)
						{
							bool linksStarted = true;
							if (startDependenciesFirst)
							{
								// create the chain
								SnapInDescriptorLink link = SnapInHostingEngine.CreateDependencyChainForSnapInsThatThisSnapInDependsOn(descriptor, SnapInHostingEngine.GetExecutingInstance().SnapInDescriptors);

								// start the link
								linksStarted = SnapInHostingEngine.StartLink(link, progressViewer);

								if (!linksStarted)
								{
									// something f****d up, one the snapins we depend on did not start
									// so we cannot start
								}
							}

							if (linksStarted && !descriptor.IsStarted)
							{
								ProgressViewer.SetExtendedDescription(progressViewer, "Starting the '" + descriptor.MetaData.Title + "' SnapIn...");

								// install the snapin, which will cover upgrades, and run counting
								SnapInHostingEngine.Install(descriptor, false, progressViewer);

								// trigger read options
								SnapInHostingEngine.TriggerReadOptions(descriptor, progressViewer);

								// start the snapin
								System.Diagnostics.Trace.WriteLineIf(_verbose, string.Format("Starting SnapIn '{0}'", descriptor.Type.FullName));
								descriptor.SnapIn.OnStart(null, System.EventArgs.Empty);								
								descriptor._isStarted = true;	
					
								// raise the start event
								SnapInHostingEngine.GetExecutingInstance().OnSnapInStarted(SnapInHostingEngine.GetExecutingInstance(), new SnapInDescriptorEventArgs(descriptor));

								ProgressViewer.SetExtendedDescription(progressViewer, descriptor.MetaData.Title + " started successfully.");

								return true;
							}
						}
						// it's already started
						return true;
					}
				}
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}
			return false;
		}